blob: a3968fa7db40689f72176fe224eec9aaf4931ca8 [file] [log] [blame]
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00001<?php
2error_reporting(E_ALL);
3require_once('common.php');
4
Jonas Häggqvistb632ed12010-01-30 02:04:47 +00005 function langsort($a, $b) {
6 // Sort by Name
7 $ap = $a['name'];
8 $bp = $b['name'];
9 // Sort by last update revision
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000010 $ap = $a['last_update_rev'];
11 $bp = $b['last_update_rev'];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000012 // Sort by status
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000013 $ap = $a['percentage'];
14 $bp = $b['percentage'];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000015
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000016 $ac = $a['desc'] + $a['source'];
17 $bc = $b['desc'] + $b['source'];
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000018 if ($ap == $bp) {
19 if ($ac != $bc) {
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000020 return $ac > $bc ? -1 : 1;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000021 }
22 else {
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000023 return $a['name'] > $b['name'] ? -1 : 1;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000024 }
25 }
26 return $ap < $bp ? 1 : -1;
27 }
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000028
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000029function 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äggqvistb632ed12010-01-30 02:04:47 +000048
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000049 /* Count this language into the summary */
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000050 switch(true) {
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000051 case $info['percentage'] == 100
52 && $info['source'] == 0
53 && $info['desc'] == 0:
54 $stats['summary']['complete']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000055 break;
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000056 case $info['percentage'] > 95;
57 $stats['summary']['good']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000058 break;
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000059 case $info['percentage'] > 50;
60 $stats['summary']['normal']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000061 break;
62 default:
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000063 $stats['summary']['bad']++;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000064 break;
65 }
66 }
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000067 uasort($stats['langstats'], 'langsort');
68 return $stats;
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000069}
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000070
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000071
Jonas Häggqvist31ca70b2010-01-31 00:44:07 +000072$stats = get_stats();
73$smarty->render('frontpage.tpl', $stats);
Jonas Häggqvistb632ed12010-01-30 02:04:47 +000074?>