summaryrefslogtreecommitdiffstats
path: root/index.php
blob: 7445c6325cfaaad8e4bd2d877130d85dcc3c037c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * Copyright (C) 2010 Jonas Häggqvist
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 **************************************************************************/
error_reporting(E_ALL);
require_once('common.php');

    function langsort($a, $b) {
	// English is always on top
	if ($a['name'] == 'English')
		return -1;
	if ($b['name'] == 'English')
		return 1;

        // Sort by Name
        $an = $a['name'];
        $bn = $b['name'];
        // Sort by last update revision
        $au = $a['last_update_rev'];
        $bu = $b['last_update_rev'];
        // Sort by status
        $ap = $a['percentage'];
        $bp = $b['percentage'];

        $ac = $a['desc'] + $a['source'];
        $bc = $b['desc'] + $b['source'];
        if ($ap == $bp) {
            if ($ac != $bc) {
                return $ac > $bc ? -1 : 1;
            } else {
                return $an > $bn ? -1 : 1;
            }
        }
        return $ap < $bp ? 1 : -1;
    }

function get_stats() {
    $languageinfo = languageinfo();
    $stats['langstats'] = (file_exists(STATS) ? unserialize(file_get_contents(STATS)) : array());
    $stats['summary'] = array('complete' => 0, 'good' => 0, 'normal' => 0, 'bad' => 0);
    foreach($stats['langstats'] as $name => &$info) {
        if ($name == 'summary') continue;
        $info['percentage'] = ($info['total'] - $info['missing']) / $info['total'] * 100;
        if (isset($languageinfo[$name])) {
            $info = array_merge($info, $languageinfo[$name]);
        }
        // Set some defaults
        else {
            $info = array_merge($info, array(
                'name' => ucfirst($info['name']),
                'flag' => 'unknown',
                'code' => 'xx',
                'rtl' => 0,
            ));
        }

        /* Count this language into the summary */
        switch(true) {
            case $info['percentage'] == 100
                   && $info['source'] == 0
                   && $info['desc'] == 0:
                $stats['summary']['complete']++;
                break;
            case $info['percentage'] > 95;
                $stats['summary']['good']++;
                break;
            case $info['percentage'] > 50;
                $stats['summary']['normal']++;
                break;
            default:
                $stats['summary']['bad']++;
                break;
        }
    }
    uasort($stats['langstats'], 'langsort');
    return $stats;
}


$stats = get_stats();
$smarty->render('frontpage.tpl', $stats);
?>