summaryrefslogtreecommitdiffstats
path: root/submit.php
blob: 26b83c69d477213af1dbcb986fbc07e7a5b9b9ea (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
<?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 submit() {
    header("Content-type: text/plain;charset=UTF-8");
    header(sprintf("Content-Disposition: attachment; filename=%s.diff", $_REQUEST['lang']));
    $langs = array();
    if (file_exists(VERSIONS)) {
        foreach(file(VERSIONS) as $line) {
            list($lang, $version) = explode(":", trim($line));
            $langs[$lang] = $version;
        }
    }

    $i = 0;
    do {
        $filename = sprintf("/tmp/%s.lang%s.new", $_REQUEST['lang'], $i == 0 ? '' : '.'.$i);
        $i++;
    } while (file_exists($filename));

    $fp = fopen($filename, 'w');
    if ($fp === false) {
	header("HTTP/1.1 500 Internal Server Error");
	print "\nUnable to write tmpfile\n";
	exit(1);
    }

    // Write a header if one exists
    $original_lines = file(sprintf("rockbox/apps/lang/%s.lang", $_REQUEST['lang']));
    foreach($original_lines as $i => $line) {
        if (substr($line, 0, 1) == "<") { break; }
        fwrite($fp, $line);
    }

    $original = parselangfile(sprintf("scratch/%s.lang.update", $_REQUEST['lang']));
    $english = parselangfile("scratch/english.lang");
    print("Copyright by individual Rockbox contributors\n");
    printf("See\nhttps://git.rockbox.org/cgit/rockbox.git/log/apps/lang/%s.lang\nfor details.\n", $_REQUEST['lang']);
    print("May be distributed under the terms of the GNU GPL version 2 or later\n");
    print("This file generated by http://translate.rockbox.org/\n\n");
    printf("This translation was based on git hash %s of the original.\n\n", $langs[$_REQUEST['lang']]);

    foreach($original as $id => $phrase) {
        foreach(array('dest', 'voice') as $type) {
            if (isset($_POST['phrases'][$id])) {
                if (isset($_POST['phrases'][$id][$type]))
                    $phrase[$type] = $_POST['phrases'][$id][$type];
                else
                    unset($phrase[$type]);
            }
        }
        if (strtolower($english[$id]['phrase']['desc']) == "deprecated") {
            $phrase = $english[$id];
        }
        fwrite($fp, printphrase($phrase));
    }
    fclose($fp);
    $cmd = sprintf("/usr/bin/diff -u -B -w rockbox/apps/lang/%s.lang %s", escapeshellarg($_REQUEST['lang']), $filename);
    print(shell_exec($cmd));
}

submit();
?>