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
 Copyright (C) 2004-2005, Ryan Djurovich
9
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
}
30
31
// Setup admin object
32
require('../../config.php');
33
require_once(WB_PATH.'/framework/class.admin.php');
34
$admin = new admin('Addons', 'languages_install');
35
36
// Include the WB functions file
37
require_once(WB_PATH.'/framework/functions.php');
38
39
// Create temp string
40
$temp_string = '';
41
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
42
srand((double)microtime()*1000000);
43
$i = 0;
44
while ($i <= 7) {
45
	$num = rand() % 33;
46
	$tmp = substr($salt, $num, 1);
47
	$temp_string = $temp_string . $tmp;
48
	$i++;
49
}
50
51
// Set temp vars
52
$temp_dir = WB_PATH.'/temp/';
53
$temp_file = $temp_dir . 'language'.$temp_string;
54
55
// Check if language dir is writable
56
if(!is_writable(WB_PATH.'/languages/')) {
57
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
58
	$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
59
}
60
61
// Try to upload the file to the temp dir
62
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
63
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
64
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
65
}
66
67
// Remove any vars with name "language_code"
68
unset($language_code);
69
70
// Read the temp file and look for a language code
71 99 stefan
require($temp_file);
72
$new_language_version=$language_version;
73 4 ryan
74
// Check if the file is valid
75
if(!isset($language_code)) {
76
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
77
	// Restore to correct language
78
	require(WB_PATH.'/languages/'.LANGUAGE.'.php');
79
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
80
}
81
82
// Set destination for language file
83
$language_file = WB_PATH.'/languages/'.$language_code.'.php';
84
85
// Move to new location
86 99 stefan
if (file_exists($language_file)) {
87
	require($language_file);
88
	if ($language_version>$new_language_version) {
89
		$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
90
	}
91
	unlink($language_file);
92
}
93
94 4 ryan
rename($temp_file, $language_file);
95
96
// Chmod the file
97
change_mode($language_file, 'file');
98
99 170 ryan
// Load language info into DB
100
load_module(WB_PATH.'/languages/'.$language_file);
101
102 4 ryan
// Restore to correct language
103
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
104
105
// Print success message
106
$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
107
108
// Print admin footer
109
$admin->print_footer();
110
111
?>