Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         languages
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @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: install.php 2098 2014-02-11 01:37:03Z darkviper $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/languages/install.php $
14
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
15
 * @description
16
 *
17
 */
18

    
19
// do not display notices and warnings during installation
20
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
21

    
22
// Setup admin object
23
require('../../config.php');
24
require_once(WB_PATH.'/framework/class.admin.php');
25
$admin = new admin('Addons', 'languages_install', false);
26
if( !$admin->checkFTAN() )
27
{
28
	$admin->print_header();
29
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
30
}
31
// After check print the header
32
$admin->print_header();
33

    
34
// Check if user uploaded a file
35
if(!isset($_FILES['userfile'])) {
36
	header("Location: index.php");
37
	exit(0);
38
}
39
$oLang = Translate::getInstance();
40
$oLang->enableAddon('admin\\languages');
41

    
42
// 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
	$admin->print_error($oLang->MESSAGE_GENERIC_BAD_PERMISSIONS);
65
}
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
	$admin->print_error($oLang->MESSAGE_GENERIC_CANNOT_UPLOAD);
71
}
72

    
73
// Check if uploaded file is a valid language file (no binary file etc.)
74
$content = file_get_contents($temp_file);
75
if (strpos($content, '<?php') === false) $admin->print_error($oLang->MESSAGE_GENERIC_INVALID_LANGUAGE_FILE);
76

    
77
// Remove any vars with name "language_code"
78
unset($language_code);
79

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

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

    
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
	$admin->print_error($oLang->MESSAGE_GENERIC_INVALID_LANGUAGE_FILE);
93
}
94

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

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

    
111
rename($temp_file, $language_file);
112

    
113
// Chmod the file
114
change_mode($language_file, 'file');
115

    
116
// Load language info into DB
117
load_language($language_file);
118

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

    
122
// Print success message
123
if ($action=="install") {
124
	$admin->print_success($oLang->MESSAGE_GENERIC_INSTALLED);
125
} else {
126
	$admin->print_success($oLang->MESSAGE_GENERIC_UPGRADED);
127
}
128

    
129
// Print admin footer
130
$admin->print_footer();
(3-3/4)