Project

General

Profile

1
<?php
2

    
3
// $Id: install.php 10 2005-09-04 08:59:31Z ryan $
4

    
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
$file_contents = file_get_contents($temp_file);
72
$search_for_code = strstr($file_contents, '$language_code');
73
if($search_for_code != '') {
74
	if(strstr($search_for_code, "'")) {
75
		$search_for_code2 = strstr($search_for_code, "'");
76
	} else {
77
		$search_for_code2 = strstr($search_for_code, '"');
78
	}
79
	$language_code = substr($search_for_code2, 1, 2);
80
}
81

    
82
// Check if the file is valid
83
if(!isset($language_code)) {
84
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
85
	// Restore to correct language
86
	require(WB_PATH.'/languages/'.LANGUAGE.'.php');
87
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
88
}
89

    
90
// Set destination for language file
91
$language_file = WB_PATH.'/languages/'.$language_code.'.php';
92

    
93
// Move to new location
94
rename($temp_file, $language_file);
95

    
96
// Chmod the file
97
change_mode($language_file, 'file');
98

    
99
// Restore to correct language
100
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
101

    
102
// Print success message
103
$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
104

    
105
// Print admin footer
106
$admin->print_footer();
107

    
108
?>
(4-4/6)