| 1 | 4 | ryan | <?php
 | 
      
        | 2 | 1467 | Luisehahne | /**
 | 
      
        | 3 |  |  |  *
 | 
      
        | 4 |  |  |  * @category        admin
 | 
      
        | 5 |  |  |  * @package         languages
 | 
      
        | 6 | 1712 | Luisehahne |  * @author          Ryan Djurovich, WebsiteBaker Project
 | 
      
        | 7 |  |  |  * @copyright       2009-2012, WebsiteBaker Org. e.V.
 | 
      
        | 8 | 1467 | Luisehahne |  * @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$
 | 
      
        | 13 |  |  |  * @filesource      $HeadURL$
 | 
      
        | 14 |  |  |  * @lastmodified    $Date$
 | 
      
        | 15 |  |  |  * @description
 | 
      
        | 16 |  |  |  *
 | 
      
        | 17 |  |  |  */
 | 
      
        | 18 | 4 | ryan | 
 | 
      
        | 19 | 925 | doc | // do not display notices and warnings during installation
 | 
      
        | 20 |  |  | error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
 | 
      
        | 21 |  |  | 
 | 
      
        | 22 | 4 | ryan | // Setup admin object
 | 
      
        | 23 |  |  | require('../../config.php');
 | 
      
        | 24 |  |  | require_once(WB_PATH.'/framework/class.admin.php');
 | 
      
        | 25 | 1457 | Luisehahne | $admin = new admin('Addons', 'languages_install', false);
 | 
      
        | 26 |  |  | if( !$admin->checkFTAN() )
 | 
      
        | 27 |  |  | {
 | 
      
        | 28 | 1467 | Luisehahne | 	$admin->print_header();
 | 
      
        | 29 | 1457 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
 | 
      
        | 30 |  |  | }
 | 
      
        | 31 |  |  | // After check print the header
 | 
      
        | 32 |  |  | $admin->print_header();
 | 
      
        | 33 | 4 | ryan | 
 | 
      
        | 34 | 1457 | Luisehahne | // Check if user uploaded a file
 | 
      
        | 35 |  |  | if(!isset($_FILES['userfile'])) {
 | 
      
        | 36 |  |  | 	header("Location: index.php");
 | 
      
        | 37 |  |  | 	exit(0);
 | 
      
        | 38 |  |  | }
 | 
      
        | 39 |  |  | 
 | 
      
        | 40 | 4 | ryan | // 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 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_BAD_PERMISSIONS']);
 | 
      
        | 63 | 4 | ryan | }
 | 
      
        | 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 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_CANNOT_UPLOAD']);
 | 
      
        | 69 | 4 | ryan | }
 | 
      
        | 70 |  |  | 
 | 
      
        | 71 | 925 | doc | // Check if uploaded file is a valid language file (no binary file etc.)
 | 
      
        | 72 |  |  | $content = file_get_contents($temp_file);
 | 
      
        | 73 | 1712 | Luisehahne | if (strpos($content, '<?php') === false) $admin->print_error($MESSAGE['GENERIC_INVALID_LANGUAGE_FILE']);
 | 
      
        | 74 | 925 | doc | 
 | 
      
        | 75 | 4 | ryan | // Remove any vars with name "language_code"
 | 
      
        | 76 |  |  | unset($language_code);
 | 
      
        | 77 |  |  | 
 | 
      
        | 78 | 925 | doc | // Include precheck files for versionCompare routine
 | 
      
        | 79 |  |  | require(WB_PATH . '/framework/addon.precheck.inc.php');
 | 
      
        | 80 |  |  | 
 | 
      
        | 81 | 4 | ryan | // Read the temp file and look for a language code
 | 
      
        | 82 | 99 | stefan | require($temp_file);
 | 
      
        | 83 |  |  | $new_language_version=$language_version;
 | 
      
        | 84 | 4 | ryan | 
 | 
      
        | 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 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_INVALID_LANGUAGE_FILE']);
 | 
      
        | 91 | 4 | ryan | }
 | 
      
        | 92 |  |  | 
 | 
      
        | 93 |  |  | // Set destination for language file
 | 
      
        | 94 |  |  | $language_file = WB_PATH.'/languages/'.$language_code.'.php';
 | 
      
        | 95 | 925 | doc | $action="install";
 | 
      
        | 96 | 4 | ryan | 
 | 
      
        | 97 |  |  | // Move to new location
 | 
      
        | 98 | 99 | stefan | if (file_exists($language_file)) {
 | 
      
        | 99 |  |  | 	require($language_file);
 | 
      
        | 100 | 925 | doc | 	if (versionCompare($language_version, $new_language_version, '>=')) {
 | 
      
        | 101 |  |  | 		// Restore to correct language
 | 
      
        | 102 |  |  | 		require(WB_PATH . '/languages/' . LANGUAGE . '.php');
 | 
      
        | 103 | 1712 | Luisehahne | 		$admin->print_error($MESSAGE['GENERIC_ALREADY_INSTALLED']);
 | 
      
        | 104 | 99 | stefan | 	}
 | 
      
        | 105 | 925 | doc | 	$action="upgrade";
 | 
      
        | 106 | 99 | stefan | 	unlink($language_file);
 | 
      
        | 107 |  |  | }
 | 
      
        | 108 |  |  | 
 | 
      
        | 109 | 4 | ryan | rename($temp_file, $language_file);
 | 
      
        | 110 |  |  | 
 | 
      
        | 111 |  |  | // Chmod the file
 | 
      
        | 112 |  |  | change_mode($language_file, 'file');
 | 
      
        | 113 |  |  | 
 | 
      
        | 114 | 170 | ryan | // Load language info into DB
 | 
      
        | 115 | 211 | stefan | load_language($language_file);
 | 
      
        | 116 | 170 | ryan | 
 | 
      
        | 117 | 4 | ryan | // Restore to correct language
 | 
      
        | 118 |  |  | require(WB_PATH.'/languages/'.LANGUAGE.'.php');
 | 
      
        | 119 |  |  | 
 | 
      
        | 120 |  |  | // Print success message
 | 
      
        | 121 | 925 | doc | if ($action=="install") {
 | 
      
        | 122 | 1712 | Luisehahne | 	$admin->print_success($MESSAGE['GENERIC_INSTALLED']);
 | 
      
        | 123 | 925 | doc | } else {
 | 
      
        | 124 | 1712 | Luisehahne | 	$admin->print_success($MESSAGE['GENERIC_UPGRADED']);
 | 
      
        | 125 | 925 | doc | }
 | 
      
        | 126 | 4 | ryan | 
 | 
      
        | 127 |  |  | // Print admin footer
 | 
      
        | 128 |  |  | $admin->print_footer();
 |