Project

General

Profile

1
<?php
2

    
3
// $Id: install.php 925 2009-02-13 15:35:05Z doc $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, 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
	exit(0);
30
}
31

    
32
// do not display notices and warnings during installation
33
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
34

    
35
// Setup admin object
36
require('../../config.php');
37
require_once(WB_PATH.'/framework/class.admin.php');
38
$admin = new admin('Addons', 'languages_install');
39

    
40
// Include the WB functions file
41
require_once(WB_PATH.'/framework/functions.php');
42

    
43
// Create temp string
44
$temp_string = '';
45
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
46
srand((double)microtime()*1000000);
47
$i = 0;
48
while ($i <= 7) {
49
	$num = rand() % 33;
50
	$tmp = substr($salt, $num, 1);
51
	$temp_string = $temp_string . $tmp;
52
	$i++;
53
}
54

    
55
// Set temp vars
56
$temp_dir = WB_PATH.'/temp/';
57
$temp_file = $temp_dir . 'language'.$temp_string;
58

    
59
// Check if language dir is writable
60
if(!is_writable(WB_PATH.'/languages/')) {
61
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
62
	$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
63
}
64

    
65
// Try to upload the file to the temp dir
66
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
67
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
68
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
69
}
70

    
71
// Check if uploaded file is a valid language file (no binary file etc.)
72
$content = file_get_contents($temp_file);
73
if (strpos($content, '<?php') === false) $admin->print_error($MESSAGE['GENERIC']['INVALID_LANGUAGE_FILE']);
74

    
75
// Remove any vars with name "language_code"
76
unset($language_code);
77

    
78
// Include precheck files for versionCompare routine
79
require(WB_PATH . '/framework/addon.precheck.inc.php');
80

    
81
// Read the temp file and look for a language code
82
require($temp_file);
83
$new_language_version=$language_version;
84

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

    
93
// Set destination for language file
94
$language_file = WB_PATH.'/languages/'.$language_code.'.php';
95
$action="install";
96

    
97
// Move to new location
98
if (file_exists($language_file)) {
99
	require($language_file);
100
	if (versionCompare($language_version, $new_language_version, '>=')) {
101
		// Restore to correct language
102
		require(WB_PATH . '/languages/' . LANGUAGE . '.php');
103
		$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
104
	}
105
	$action="upgrade";
106
	unlink($language_file);
107
}
108

    
109
rename($temp_file, $language_file);
110

    
111
// Chmod the file
112
change_mode($language_file, 'file');
113

    
114
// Load language info into DB
115
load_language($language_file);
116

    
117
// Restore to correct language
118
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
119

    
120
// Print success message
121
if ($action=="install") {
122
	$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
123
} else {
124
	$admin->print_success($MESSAGE['GENERIC']['UPGRADED']);
125
}
126

    
127
// Print admin footer
128
$admin->print_footer();
129

    
130
?>
(3-3/4)