blob: 9abaedd124cbd30713564b1ee723f36b8534c8b1 [file] [log] [blame]
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00001<?php
Solomon Peachya0eef362020-04-02 10:05:23 -04002/************************************************************************
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * Copyright (C) 2010 Jonas Häggqvist
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 **************************************************************************/
20error_reporting(E_ALL);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000021require_once('common.php');
22
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000023 function langsort($a, $b) {
Solomon Peachybe29be12020-04-10 16:39:41 -040024 // English is always on top
25 if ($a['name'] == 'English')
26 return -1;
27 if ($b['name'] == 'English')
28 return 1;
29
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000030 // Sort by Name
Solomon Peachybe29be12020-04-10 16:39:41 -040031 $an = $a['name'];
32 $bn = $b['name'];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000033 // Sort by last update revision
Solomon Peachybe29be12020-04-10 16:39:41 -040034 $au = $a['last_update_rev'];
35 $bu = $b['last_update_rev'];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000036 // Sort by status
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000037 $ap = $a['percentage'];
Solomon Peachya0eef362020-04-02 10:05:23 -040038 $bp = $b['percentage'];
39
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000040 $ac = $a['desc'] + $a['source'];
41 $bc = $b['desc'] + $b['source'];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000042 if ($ap == $bp) {
43 if ($ac != $bc) {
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000044 return $ac > $bc ? -1 : 1;
Solomon Peachybe29be12020-04-10 16:39:41 -040045 } else {
46 return $an > $bn ? -1 : 1;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000047 }
48 }
Solomon Peachya0eef362020-04-02 10:05:23 -040049 return $ap < $bp ? 1 : -1;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000050 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000051
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000052function get_stats() {
53 $languageinfo = languageinfo();
54 $stats['langstats'] = (file_exists(STATS) ? unserialize(file_get_contents(STATS)) : array());
Solomon Peachy16cceb52023-08-08 09:37:28 -040055 $stats['summary'] = array('complete' => -1, 'good' => 0, 'normal' => 0, 'bad' => 0);
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000056 foreach($stats['langstats'] as $name => &$info) {
57 if ($name == 'summary') continue;
58 $info['percentage'] = ($info['total'] - $info['missing']) / $info['total'] * 100;
59 if (isset($languageinfo[$name])) {
60 $info = array_merge($info, $languageinfo[$name]);
61 }
62 // Set some defaults
63 else {
64 $info = array_merge($info, array(
65 'name' => ucfirst($info['name']),
66 'flag' => 'unknown',
67 'code' => 'xx',
68 'rtl' => 0,
69 ));
70 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000071
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000072 /* Count this language into the summary */
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000073 switch(true) {
Solomon Peachya0eef362020-04-02 10:05:23 -040074 case $info['percentage'] == 100
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000075 && $info['source'] == 0
76 && $info['desc'] == 0:
77 $stats['summary']['complete']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000078 break;
Solomon Peachyaa276702021-12-15 22:46:05 -050079 case $info['percentage'] > 90;
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000080 $stats['summary']['good']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000081 break;
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000082 case $info['percentage'] > 50;
83 $stats['summary']['normal']++;
Solomon Peachya0eef362020-04-02 10:05:23 -040084 break;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000085 default:
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000086 $stats['summary']['bad']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000087 break;
88 }
89 }
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000090 uasort($stats['langstats'], 'langsort');
91 return $stats;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000092}
Solomon Peachya0eef362020-04-02 10:05:23 -040093
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000094
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000095$stats = get_stats();
96$smarty->render('frontpage.tpl', $stats);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000097?>