1 |
4
|
ryan
|
<?php
|
2 |
1467
|
Luisehahne
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package languages
|
6 |
|
|
* @author WebsiteBaker Project
|
7 |
|
|
* @copyright 2004-2009, Ryan Djurovich
|
8 |
|
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9 |
|
|
* @link http://www.websitebaker2.org/
|
10 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
11 |
|
|
* @platform WebsiteBaker 2.8.x
|
12 |
|
|
* @requirements PHP 5.2.2 and higher
|
13 |
|
|
* @version $Id$
|
14 |
|
|
* @filesource $HeadURL$
|
15 |
|
|
* @lastmodified $Date$
|
16 |
|
|
* @description
|
17 |
|
|
*
|
18 |
|
|
*/
|
19 |
4
|
ryan
|
|
20 |
925
|
doc
|
// do not display notices and warnings during installation
|
21 |
|
|
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
|
22 |
|
|
|
23 |
4
|
ryan
|
// Setup admin object
|
24 |
|
|
require('../../config.php');
|
25 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
26 |
1457
|
Luisehahne
|
$admin = new admin('Addons', 'languages_install', false);
|
27 |
|
|
if( !$admin->checkFTAN() )
|
28 |
|
|
{
|
29 |
1467
|
Luisehahne
|
$admin->print_header();
|
30 |
1457
|
Luisehahne
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
|
31 |
|
|
}
|
32 |
|
|
// After check print the header
|
33 |
|
|
$admin->print_header();
|
34 |
4
|
ryan
|
|
35 |
1457
|
Luisehahne
|
// Check if user uploaded a file
|
36 |
|
|
if(!isset($_FILES['userfile'])) {
|
37 |
|
|
header("Location: index.php");
|
38 |
|
|
exit(0);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
4
|
ryan
|
// Include the WB functions file
|
42 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
43 |
|
|
|
44 |
|
|
// Create temp string
|
45 |
|
|
$temp_string = '';
|
46 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
47 |
|
|
srand((double)microtime()*1000000);
|
48 |
|
|
$i = 0;
|
49 |
|
|
while ($i <= 7) {
|
50 |
|
|
$num = rand() % 33;
|
51 |
|
|
$tmp = substr($salt, $num, 1);
|
52 |
|
|
$temp_string = $temp_string . $tmp;
|
53 |
|
|
$i++;
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
// Set temp vars
|
57 |
|
|
$temp_dir = WB_PATH.'/temp/';
|
58 |
|
|
$temp_file = $temp_dir . 'language'.$temp_string;
|
59 |
|
|
|
60 |
|
|
// Check if language dir is writable
|
61 |
|
|
if(!is_writable(WB_PATH.'/languages/')) {
|
62 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
63 |
|
|
$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
// Try to upload the file to the temp dir
|
67 |
|
|
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
|
68 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
69 |
|
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
|
70 |
|
|
}
|
71 |
|
|
|
72 |
925
|
doc
|
// Check if uploaded file is a valid language file (no binary file etc.)
|
73 |
|
|
$content = file_get_contents($temp_file);
|
74 |
|
|
if (strpos($content, '<?php') === false) $admin->print_error($MESSAGE['GENERIC']['INVALID_LANGUAGE_FILE']);
|
75 |
|
|
|
76 |
4
|
ryan
|
// Remove any vars with name "language_code"
|
77 |
|
|
unset($language_code);
|
78 |
|
|
|
79 |
925
|
doc
|
// Include precheck files for versionCompare routine
|
80 |
|
|
require(WB_PATH . '/framework/addon.precheck.inc.php');
|
81 |
|
|
|
82 |
4
|
ryan
|
// Read the temp file and look for a language code
|
83 |
99
|
stefan
|
require($temp_file);
|
84 |
|
|
$new_language_version=$language_version;
|
85 |
4
|
ryan
|
|
86 |
|
|
// Check if the file is valid
|
87 |
|
|
if(!isset($language_code)) {
|
88 |
|
|
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
89 |
|
|
// Restore to correct language
|
90 |
|
|
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
|
91 |
925
|
doc
|
$admin->print_error($MESSAGE['GENERIC']['INVALID_LANGUAGE_FILE']);
|
92 |
4
|
ryan
|
}
|
93 |
|
|
|
94 |
|
|
// Set destination for language file
|
95 |
|
|
$language_file = WB_PATH.'/languages/'.$language_code.'.php';
|
96 |
925
|
doc
|
$action="install";
|
97 |
4
|
ryan
|
|
98 |
|
|
// Move to new location
|
99 |
99
|
stefan
|
if (file_exists($language_file)) {
|
100 |
|
|
require($language_file);
|
101 |
925
|
doc
|
if (versionCompare($language_version, $new_language_version, '>=')) {
|
102 |
|
|
// Restore to correct language
|
103 |
|
|
require(WB_PATH . '/languages/' . LANGUAGE . '.php');
|
104 |
99
|
stefan
|
$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
|
105 |
|
|
}
|
106 |
925
|
doc
|
$action="upgrade";
|
107 |
99
|
stefan
|
unlink($language_file);
|
108 |
|
|
}
|
109 |
|
|
|
110 |
4
|
ryan
|
rename($temp_file, $language_file);
|
111 |
|
|
|
112 |
|
|
// Chmod the file
|
113 |
|
|
change_mode($language_file, 'file');
|
114 |
|
|
|
115 |
170
|
ryan
|
// Load language info into DB
|
116 |
211
|
stefan
|
load_language($language_file);
|
117 |
170
|
ryan
|
|
118 |
4
|
ryan
|
// Restore to correct language
|
119 |
|
|
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
|
120 |
|
|
|
121 |
|
|
// Print success message
|
122 |
925
|
doc
|
if ($action=="install") {
|
123 |
|
|
$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
|
124 |
|
|
} else {
|
125 |
|
|
$admin->print_success($MESSAGE['GENERIC']['UPGRADED']);
|
126 |
|
|
}
|
127 |
4
|
ryan
|
|
128 |
|
|
// Print admin footer
|
129 |
|
|
$admin->print_footer();
|
130 |
|
|
|
131 |
|
|
?>
|