Project

General

Profile

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