Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         languages
6
 * @author          WebsiteBaker Project
7
 * @copyright       Ryan Djurovich
8
 * @copyright       WebsiteBaker Org. e.V.
9
 * @link            http://websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.3
12
 * @requirements    PHP 5.3.6 and higher
13
 * @version         $Id: install.php 2 2017-07-02 15:14:29Z Manuela $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/admin/languages/install.php $
15
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
16
 * @description
17
 *
18
 */
19

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

    
23
// Include config file and admin class file
24
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
25
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
26

    
27
$admin = new admin('Addons', 'languages_install', false);
28

    
29
$js_back = ADMIN_URL.'/languages/index.php';
30

    
31
if( !$admin->checkFTAN() )
32
{
33
    $admin->print_header();
34
    $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
35
}
36
// After check print the header
37
$admin->print_header();
38

    
39
// Check if user uploaded a file
40
if(!isset($_FILES['userfile'])) {
41
    $admin->print_error($MESSAGE['GENERIC_ERROR_OPENING_FILE'], $js_back );
42
}
43

    
44
// Include the WB functions file
45
require_once(WB_PATH.'/framework/functions.php');
46

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

    
59
// Set temp vars
60
$temp_dir = WB_PATH.'/temp/';
61
$temp_file = $temp_dir . 'language'.$temp_string;
62

    
63
// Check if language dir is writable
64
if(!is_writable(WB_PATH.'/languages/')) {
65
    if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
66
    $admin->print_error($MESSAGE['GENERIC_BAD_PERMISSIONS']);
67
}
68

    
69
// Try to upload the file to the temp dir
70
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) {
71
    if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
72
    $admin->print_error($MESSAGE['GENERIC_CANNOT_UPLOAD']);
73
}
74

    
75
// Check if uploaded file is a valid language file (no binary file etc.)
76
$content = file_get_contents($temp_file);
77
if (strpos($content, '<?php') === false) $admin->print_error($MESSAGE['GENERIC_INVALID_LANGUAGE_FILE']);
78
// Remove any vars with name "language_code"
79
if (isset($language_code)){unset($language_code);}
80

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

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

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

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

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

    
112
rename($temp_file, $language_file);
113

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

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

    
120
// Restore to correct language
121
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
122
rm_full_dir(WB_PATH.'/temp', true);
123
// Print success message
124
if ($action=="install") {
125
    $admin->print_success($MESSAGE['GENERIC_INSTALLED']);
126
} else {
127
    $admin->print_success($MESSAGE['GENERIC_UPGRADED']);
128
}
129

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