Project

General

Profile

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