Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 1 | <?php |
| 2 | error_reporting(E_ALL); |
| 3 | require_once('common.php'); |
| 4 | |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 5 | function langsort($a, $b) { |
| 6 | // Sort by Name |
| 7 | $ap = $a['name']; |
| 8 | $bp = $b['name']; |
| 9 | // Sort by last update revision |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 10 | $ap = $a['last_update_rev']; |
| 11 | $bp = $b['last_update_rev']; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 12 | // Sort by status |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 13 | $ap = $a['percentage']; |
| 14 | $bp = $b['percentage']; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 15 | |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 16 | $ac = $a['desc'] + $a['source']; |
| 17 | $bc = $b['desc'] + $b['source']; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 18 | if ($ap == $bp) { |
| 19 | if ($ac != $bc) { |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 20 | return $ac > $bc ? -1 : 1; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 21 | } |
| 22 | else { |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 23 | return $a['name'] > $b['name'] ? -1 : 1; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 24 | } |
| 25 | } |
| 26 | return $ap < $bp ? 1 : -1; |
| 27 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 28 | |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 29 | function get_stats() { |
| 30 | $languageinfo = languageinfo(); |
| 31 | $stats['langstats'] = (file_exists(STATS) ? unserialize(file_get_contents(STATS)) : array()); |
| 32 | $stats['summary'] = array('complete' => 0, 'good' => 0, 'normal' => 0, 'bad' => 0); |
| 33 | foreach($stats['langstats'] as $name => &$info) { |
| 34 | if ($name == 'summary') continue; |
| 35 | $info['percentage'] = ($info['total'] - $info['missing']) / $info['total'] * 100; |
| 36 | if (isset($languageinfo[$name])) { |
| 37 | $info = array_merge($info, $languageinfo[$name]); |
| 38 | } |
| 39 | // Set some defaults |
| 40 | else { |
| 41 | $info = array_merge($info, array( |
| 42 | 'name' => ucfirst($info['name']), |
| 43 | 'flag' => 'unknown', |
| 44 | 'code' => 'xx', |
| 45 | 'rtl' => 0, |
| 46 | )); |
| 47 | } |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 48 | |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 49 | /* Count this language into the summary */ |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 50 | switch(true) { |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 51 | case $info['percentage'] == 100 |
| 52 | && $info['source'] == 0 |
| 53 | && $info['desc'] == 0: |
| 54 | $stats['summary']['complete']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 55 | break; |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 56 | case $info['percentage'] > 95; |
| 57 | $stats['summary']['good']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 58 | break; |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 59 | case $info['percentage'] > 50; |
| 60 | $stats['summary']['normal']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 61 | break; |
| 62 | default: |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 63 | $stats['summary']['bad']++; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 64 | break; |
| 65 | } |
| 66 | } |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 67 | uasort($stats['langstats'], 'langsort'); |
| 68 | return $stats; |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 69 | } |
Jonas Häggqvist | 31ca70b | 2010-01-31 00:44:07 +0000 | [diff] [blame] | 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 | $stats = get_stats(); |
| 73 | $smarty->render('frontpage.tpl', $stats); |
Jonas Häggqvist | b632ed1 | 2010-01-30 02:04:47 +0000 | [diff] [blame] | 74 | ?> |