Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 1 | <?php |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 2 | /************************************************************************ |
| 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 | **************************************************************************/ |
| 20 | error_reporting(E_ALL); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 21 | require_once('common.php'); |
| 22 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 23 | function langsort($a, $b) { |
Solomon Peachy | be29be1 | 2020-04-10 16:39:41 -0400 | [diff] [blame] | 24 | // English is always on top |
| 25 | if ($a['name'] == 'English') |
| 26 | return -1; |
| 27 | if ($b['name'] == 'English') |
| 28 | return 1; |
| 29 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 30 | // Sort by Name |
Solomon Peachy | be29be1 | 2020-04-10 16:39:41 -0400 | [diff] [blame] | 31 | $an = $a['name']; |
| 32 | $bn = $b['name']; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 33 | // Sort by last update revision |
Solomon Peachy | be29be1 | 2020-04-10 16:39:41 -0400 | [diff] [blame] | 34 | $au = $a['last_update_rev']; |
| 35 | $bu = $b['last_update_rev']; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 36 | // Sort by status |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 37 | $ap = $a['percentage']; |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 38 | $bp = $b['percentage']; |
| 39 | |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 40 | $ac = $a['desc'] + $a['source']; |
| 41 | $bc = $b['desc'] + $b['source']; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 42 | if ($ap == $bp) { |
| 43 | if ($ac != $bc) { |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 44 | return $ac > $bc ? -1 : 1; |
Solomon Peachy | be29be1 | 2020-04-10 16:39:41 -0400 | [diff] [blame] | 45 | } else { |
| 46 | return $an > $bn ? -1 : 1; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 47 | } |
| 48 | } |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 49 | return $ap < $bp ? 1 : -1; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 50 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 51 | |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 52 | function get_stats() { |
| 53 | $languageinfo = languageinfo(); |
| 54 | $stats['langstats'] = (file_exists(STATS) ? unserialize(file_get_contents(STATS)) : array()); |
| 55 | $stats['summary'] = array('complete' => 0, 'good' => 0, 'normal' => 0, 'bad' => 0); |
| 56 | 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äggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 71 | |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 72 | /* Count this language into the summary */ |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 73 | switch(true) { |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 74 | case $info['percentage'] == 100 |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 75 | && $info['source'] == 0 |
| 76 | && $info['desc'] == 0: |
| 77 | $stats['summary']['complete']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 78 | break; |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 79 | case $info['percentage'] > 95; |
| 80 | $stats['summary']['good']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 81 | break; |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 82 | case $info['percentage'] > 50; |
| 83 | $stats['summary']['normal']++; |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 84 | break; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 85 | default: |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 86 | $stats['summary']['bad']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 87 | break; |
| 88 | } |
| 89 | } |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 90 | uasort($stats['langstats'], 'langsort'); |
| 91 | return $stats; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 92 | } |
Solomon Peachy | a0eef36 | 2020-04-02 10:05:23 -0400 | [diff] [blame] | 93 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 94 | |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 95 | $stats = get_stats(); |
| 96 | $smarty->render('frontpage.tpl', $stats); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 97 | ?> |