init.php 3.96 KB
Newer Older
1 2
<?php
/*
3
* 2007-2015 PrestaShop
4 5 6
*
* NOTICE OF LICENSE
*
7
* This source file is subject to the Open Software License (OSL 3.0)
8 9
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
10
* http://opensource.org/licenses/osl-3.0.php
11 12 13 14 15 16 17 18 19 20 21
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
22
*  @copyright  2007-2015 PrestaShop SA
23
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
24 25 26
*  International Registered Trademark & Property of PrestaShop SA
*/

27 28
ob_start();

29
// Check PHP version
Rémi Gaillard's avatar
Rémi Gaillard committed
30
if (version_compare(preg_replace('/[^0-9.]/', '', PHP_VERSION), '5.1.3', '<'))
31
	die('You need at least PHP 5.1.3 to run PrestaShop. Your current PHP version is '.PHP_VERSION);
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46
// we check if theses constants are defined
// in order to use init.php in upgrade.php script
if (!defined('__PS_BASE_URI__'))
        define('__PS_BASE_URI__', substr($_SERVER['REQUEST_URI'], 0, -1 * (strlen($_SERVER['REQUEST_URI']) - strrpos($_SERVER['REQUEST_URI'], '/')) - strlen(substr(dirname($_SERVER['REQUEST_URI']), strrpos(dirname($_SERVER['REQUEST_URI']), '/') + 1))));

if (!defined('_PS_CORE_DIR_'))
	define('_PS_CORE_DIR_', realpath(dirname(__FILE__).'/..'));

if (!defined('_THEME_NAME_'))
        define('_THEME_NAME_', 'default-bootstrap');

require_once(_PS_CORE_DIR_.'/config/defines.inc.php');
require_once(_PS_CORE_DIR_.'/config/defines_uri.inc.php');

47
// Generate common constants
48
define('PS_INSTALLATION_IN_PROGRESS', true);
49 50 51 52 53 54
define('_PS_INSTALL_PATH_', dirname(__FILE__).'/');
define('_PS_INSTALL_DATA_PATH_', _PS_INSTALL_PATH_.'data/');
define('_PS_INSTALL_CONTROLLERS_PATH_', _PS_INSTALL_PATH_.'controllers/');
define('_PS_INSTALL_MODELS_PATH_', _PS_INSTALL_PATH_.'models/');
define('_PS_INSTALL_LANGS_PATH_', _PS_INSTALL_PATH_.'langs/');
define('_PS_INSTALL_FIXTURES_PATH_', _PS_INSTALL_PATH_.'fixtures/');
55

56
require_once(_PS_INSTALL_PATH_.'install_version.php');
57

58 59
// PrestaShop autoload is used to load some helpfull classes like Tools.
// Add classes used by installer bellow.
60 61
require_once(_PS_CORE_DIR_.'/config/autoload.php');
require_once(_PS_CORE_DIR_.'/config/alias.php');
62 63 64 65 66 67 68 69
require_once(_PS_INSTALL_PATH_.'classes/exception.php');
require_once(_PS_INSTALL_PATH_.'classes/languages.php');
require_once(_PS_INSTALL_PATH_.'classes/language.php');
require_once(_PS_INSTALL_PATH_.'classes/model.php');
require_once(_PS_INSTALL_PATH_.'classes/session.php');
require_once(_PS_INSTALL_PATH_.'classes/sqlLoader.php');
require_once(_PS_INSTALL_PATH_.'classes/xmlLoader.php');
require_once(_PS_INSTALL_PATH_.'classes/simplexml.php');
rMalie's avatar
rMalie committed
70

71
@set_time_limit(0);
72 73
if (!@ini_get('date.timezone'))
	@date_default_timezone_set('UTC');
74

75 76 77
// Some hosting still have magic_quotes_runtime configured
ini_set('magic_quotes_runtime', 0);

78
// Try to improve memory limit if it's under 32M
79 80
if (psinstall_get_memory_limit() < psinstall_get_octets('64M'))
	ini_set('memory_limit', '64M');
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

function psinstall_get_octets($option)
{
	if (preg_match('/[0-9]+k/i', $option))
		return 1024 * (int)$option;

	if (preg_match('/[0-9]+m/i', $option))
		return 1024 * 1024 * (int)$option;

	if (preg_match('/[0-9]+g/i', $option))
		return 1024 * 1024 * 1024 * (int)$option;

	return $option;
}

function psinstall_get_memory_limit()
{
	$memory_limit = @ini_get('memory_limit');
	
	if (preg_match('/[0-9]+k/i', $memory_limit))
		return 1024 * (int)$memory_limit;
	
	if (preg_match('/[0-9]+m/i', $memory_limit))
		return 1024 * 1024 * (int)$memory_limit;
	
	if (preg_match('/[0-9]+g/i', $memory_limit))
		return 1024 * 1024 * 1024 * (int)$memory_limit;
	
	return $memory_limit;
}