1 |
4
|
ryan
|
<?php
|
2 |
|
|
|
3 |
99
|
stefan
|
// $Id$
|
4 |
4
|
ryan
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
519
|
Ruebenwurz
|
Copyright (C) 2004-2008, Ryan Djurovich
|
9 |
4
|
ryan
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
// Check if user uploaded a file
|
27 |
|
|
if(!isset($_FILES['userfile'])) {
|
28 |
|
|
header("Location: index.php");
|
29 |
286
|
stefan
|
exit(0);
|
30 |
4
|
ryan
|
}
|
31 |
|
|
|
32 |
|
|
// Setup admin object
|
33 |
|
|
require('../../config.php');
|
34 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
35 |
|
|
$admin = new admin('Addons', 'languages_install');
|
36 |
|
|
|
37 |
|
|
// Include the WB functions file
|
38 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
39 |
|
|
|
40 |
|
|
// Create temp string
|
41 |
|
|
$temp_string = '';
|
42 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
43 |
|
|
srand((double)microtime()*1000000);
|
44 |
|
|
$i = 0;
|
45 |
|
|
while ($i <= 7) {
|
46 |
|
|
$num = rand() % 33;
|
47 |
|
|
$tmp = substr($salt, $num, 1);
|
48 |
|
|
$temp_string = $temp_string . $tmp;
|
49 |
|
|
$i++;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
// Set temp vars
|
53 |
|
|
$temp_dir = WB_PATH.'/temp/';
|
54 |
|
|
$temp_file = $temp_dir . 'language'.$temp_string;
|
55 |
|
|
|
56 |
|
|
// Check if language dir is writable
|
57 |
|
|
if(!is_writable(WB_PATH.'/languages/')) {
|
58 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
59 |
|
|
$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
// Try to upload the file to the temp dir
|
63 |
|
|
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
|
64 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
65 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
// Remove any vars with name "language_code"
|
69 |
|
|
unset($language_code);
|
70 |
|
|
|
71 |
|
|
// Read the temp file and look for a language code
|
72 |
99
|
stefan
|
require($temp_file);
|
73 |
|
|
$new_language_version=$language_version;
|
74 |
4
|
ryan
|
|
75 |
|
|
// Check if the file is valid
|
76 |
|
|
if(!isset($language_code)) {
|
77 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
78 |
|
|
// Restore to correct language
|
79 |
|
|
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
|
80 |
|
|
$admin->print_error($MESSAGE['GENERIC']['INVALID']);
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
// Set destination for language file
|
84 |
|
|
$language_file = WB_PATH.'/languages/'.$language_code.'.php';
|
85 |
|
|
|
86 |
|
|
// Move to new location
|
87 |
99
|
stefan
|
if (file_exists($language_file)) {
|
88 |
|
|
require($language_file);
|
89 |
|
|
if ($language_version>$new_language_version) {
|
90 |
|
|
$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
|
91 |
|
|
}
|
92 |
|
|
unlink($language_file);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
4
|
ryan
|
rename($temp_file, $language_file);
|
96 |
|
|
|
97 |
|
|
// Chmod the file
|
98 |
|
|
change_mode($language_file, 'file');
|
99 |
|
|
|
100 |
170
|
ryan
|
// Load language info into DB
|
101 |
211
|
stefan
|
load_language($language_file);
|
102 |
170
|
ryan
|
|
103 |
4
|
ryan
|
// Restore to correct language
|
104 |
|
|
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
|
105 |
|
|
|
106 |
|
|
// Print success message
|
107 |
|
|
$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
|
108 |
|
|
|
109 |
|
|
// Print admin footer
|
110 |
|
|
$admin->print_footer();
|
111 |
|
|
|
112 |
|
|
?>
|