blob: ec96e0457103d089b2d7974351e699d23a23c550 [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) {
24 // Sort by Name
25 $ap = $a['name'];
26 $bp = $b['name'];
27 // Sort by last update revision
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000028 $ap = $a['last_update_rev'];
29 $bp = $b['last_update_rev'];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000030 // Sort by status
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000031 $ap = $a['percentage'];
Solomon Peachya0eef362020-04-02 10:05:23 -040032 $bp = $b['percentage'];
33
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000034 $ac = $a['desc'] + $a['source'];
35 $bc = $b['desc'] + $b['source'];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000036 if ($ap == $bp) {
37 if ($ac != $bc) {
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000038 return $ac > $bc ? -1 : 1;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000039 }
40 else {
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000041 return $a['name'] > $b['name'] ? -1 : 1;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000042 }
43 }
Solomon Peachya0eef362020-04-02 10:05:23 -040044 return $ap < $bp ? 1 : -1;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000045 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000046
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000047function get_stats() {
48 $languageinfo = languageinfo();
49 $stats['langstats'] = (file_exists(STATS) ? unserialize(file_get_contents(STATS)) : array());
50 $stats['summary'] = array('complete' => 0, 'good' => 0, 'normal' => 0, 'bad' => 0);
51 foreach($stats['langstats'] as $name => &$info) {
52 if ($name == 'summary') continue;
53 $info['percentage'] = ($info['total'] - $info['missing']) / $info['total'] * 100;
54 if (isset($languageinfo[$name])) {
55 $info = array_merge($info, $languageinfo[$name]);
56 }
57 // Set some defaults
58 else {
59 $info = array_merge($info, array(
60 'name' => ucfirst($info['name']),
61 'flag' => 'unknown',
62 'code' => 'xx',
63 'rtl' => 0,
64 ));
65 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000066
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000067 /* Count this language into the summary */
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000068 switch(true) {
Solomon Peachya0eef362020-04-02 10:05:23 -040069 case $info['percentage'] == 100
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000070 && $info['source'] == 0
71 && $info['desc'] == 0:
72 $stats['summary']['complete']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000073 break;
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000074 case $info['percentage'] > 95;
75 $stats['summary']['good']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000076 break;
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000077 case $info['percentage'] > 50;
78 $stats['summary']['normal']++;
Solomon Peachya0eef362020-04-02 10:05:23 -040079 break;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000080 default:
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000081 $stats['summary']['bad']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000082 break;
83 }
84 }
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000085 uasort($stats['langstats'], 'langsort');
86 return $stats;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000087}
Solomon Peachya0eef362020-04-02 10:05:23 -040088
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000089
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000090$stats = get_stats();
91$smarty->render('frontpage.tpl', $stats);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000092?>