PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/config/config.inc.php

https://gitlab.com/Tavousi/PrestaShop
PHP | 238 lines | 155 code | 33 blank | 50 comment | 46 complexity | 7932dbb0795184d0bb5f23d910ec5499 MD5 | raw file
  1<?php
  2/*
  3* 2007-2014 PrestaShop
  4*
  5* NOTICE OF LICENSE
  6*
  7* This source file is subject to the Open Software License (OSL 3.0)
  8* that is bundled with this package in the file LICENSE.txt.
  9* It is also available through the world-wide-web at this URL:
 10* http://opensource.org/licenses/osl-3.0.php
 11* If you did not receive a copy of the license and are unable to
 12* obtain it through the world-wide-web, please send an email
 13* to license@prestashop.com so we can send you a copy immediately.
 14*
 15* DISCLAIMER
 16*
 17* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 18* versions in the future. If you wish to customize PrestaShop for your
 19* needs please refer to http://www.prestashop.com for more information.
 20*
 21*  @author PrestaShop SA <contact@prestashop.com>
 22*  @copyright  2007-2014 PrestaShop SA
 23*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 24*  International Registered Trademark & Property of PrestaShop SA
 25*/
 26
 27require_once(dirname(__FILE__).'/defines.inc.php');
 28$start_time = microtime(true);
 29
 30/* SSL configuration */
 31define('_PS_SSL_PORT_', 443);
 32
 33/* Improve PHP configuration to prevent issues */
 34ini_set('upload_max_filesize', '100M');
 35ini_set('default_charset', 'utf-8');
 36ini_set('magic_quotes_runtime', 0);
 37ini_set('magic_quotes_sybase', 0);
 38
 39/* correct Apache charset (except if it's too late */
 40if (!headers_sent())
 41	header('Content-Type: text/html; charset=utf-8');
 42
 43/* No settings file? goto installer... */
 44if (!file_exists(_PS_ROOT_DIR_.'/config/settings.inc.php'))
 45{
 46	if (file_exists(dirname(__FILE__).'/../install'))
 47		header('Location: install/');
 48	elseif (file_exists(dirname(__FILE__).'/../install-dev'))
 49		header('Location: install-dev/');
 50	else
 51		die('Error: "install" directory is missing');
 52	exit;
 53}
 54//include settings file only if we are not in multi-tenancy mode 
 55require_once(_PS_ROOT_DIR_.'/config/settings.inc.php');
 56require_once(_PS_CONFIG_DIR_.'autoload.php');
 57
 58if (_PS_DEBUG_PROFILING_)
 59{
 60	include_once(_PS_TOOL_DIR_.'profiling/Controller.php');
 61	include_once(_PS_TOOL_DIR_.'profiling/ObjectModel.php');
 62	include_once(_PS_TOOL_DIR_.'profiling/Hook.php');
 63	include_once(_PS_TOOL_DIR_.'profiling/Db.php');
 64	include_once(_PS_TOOL_DIR_.'profiling/Tools.php');
 65}
 66
 67if (Tools::isPHPCLI() && isset($argc) && isset($argv))
 68	Tools::argvToGET($argc, $argv);
 69
 70/* Redefine REQUEST_URI if empty (on some webservers...) */
 71if (!isset($_SERVER['REQUEST_URI']) || empty($_SERVER['REQUEST_URI']))
 72{
 73	if (!isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['SCRIPT_FILENAME']))
 74		$_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_FILENAME'];
 75	if (isset($_SERVER['SCRIPT_NAME']))
 76	{
 77		if (basename($_SERVER['SCRIPT_NAME']) == 'index.php' && empty($_SERVER['QUERY_STRING']))
 78			$_SERVER['REQUEST_URI'] = dirname($_SERVER['SCRIPT_NAME']).'/';
 79		else
 80		{
 81			$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
 82			if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
 83				$_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
 84		}
 85	}
 86}
 87
 88/* Trying to redefine HTTP_HOST if empty (on some webservers...) */
 89if (!isset($_SERVER['HTTP_HOST']) || empty($_SERVER['HTTP_HOST']))
 90	$_SERVER['HTTP_HOST'] = @getenv('HTTP_HOST');
 91	
 92$context = Context::getContext();
 93
 94/* Initialize the current Shop */
 95try 
 96{
 97	$context->shop = Shop::initialize();
 98	$context->theme = new Theme((int)$context->shop->id_theme);
 99	if ((Tools::isEmpty($theme_name = $context->shop->getTheme()) || !Validate::isLoadedObject($context->theme)) && !defined('_PS_ADMIN_DIR_'))
100		throw new PrestaShopException(Tools::displayError('Current theme unselected. Please check your theme configuration.'));
101}
102catch (PrestaShopException $e)
103{
104	$e->displayMessage();
105}
106define('_THEME_NAME_', $theme_name);
107define('__PS_BASE_URI__', $context->shop->getBaseURI());
108
109/* Include all defines related to base uri and theme name */
110require_once(dirname(__FILE__).'/defines_uri.inc.php');
111
112global $_MODULES;
113$_MODULES = array();
114
115/* Load configuration */
116Configuration::loadConfiguration();
117
118if (Configuration::get('PS_USE_HTMLPURIFIER'))
119	require_once (_PS_TOOL_DIR_.'htmlpurifier/HTMLPurifier.standalone.php');
120
121/* Load all languages */
122Language::loadLanguages();
123
124/* Loading default country */
125$defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
126$context->country = $defaultCountry;
127
128/* It is not safe to rely on the system's timezone settings, and this would generate a PHP Strict Standards notice. */
129@date_default_timezone_set(Configuration::get('PS_TIMEZONE'));
130
131/* Set locales */
132$locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')).'_'.strtoupper(Configuration::get('PS_LOCALE_COUNTRY'));
133/* Please do not use LC_ALL here http://www.php.net/manual/fr/function.setlocale.php#25041 */
134setlocale(LC_COLLATE, $locale.'.UTF-8', $locale.'.utf8');
135setlocale(LC_CTYPE, $locale.'.UTF-8', $locale.'.utf8');
136setlocale(LC_TIME, $locale.'.UTF-8', $locale.'.utf8');
137setlocale(LC_NUMERIC, 'en_US.UTF-8', 'en_US.utf8');
138
139/* Instantiate cookie */
140$cookie_lifetime = (int)(defined('_PS_ADMIN_DIR_') ? Configuration::get('PS_COOKIE_LIFETIME_BO') : Configuration::get('PS_COOKIE_LIFETIME_FO'));
141if ($cookie_lifetime > 0)
142	$cookie_lifetime = time() + (max($cookie_lifetime, 1) * 3600);
143
144if (defined('_PS_ADMIN_DIR_'))
145	$cookie = new Cookie('psAdmin', '', $cookie_lifetime);
146else
147{
148	$force_ssl = Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE');
149	if ($context->shop->getGroup()->share_order)
150		$cookie = new Cookie('ps-sg'.$context->shop->getGroup()->id, '', $cookie_lifetime, $context->shop->getUrlsSharedCart(), false, $force_ssl);
151	else
152	{
153		$domains = null;
154		if ($context->shop->domain != $context->shop->domain_ssl)
155		  $domains = array($context->shop->domain_ssl, $context->shop->domain);
156		
157		$cookie = new Cookie('ps-s'.$context->shop->id, '', $cookie_lifetime, $domains, false, $force_ssl);
158	}
159}
160
161$context->cookie = $cookie;
162
163/* Create employee if in BO, customer else */
164if (defined('_PS_ADMIN_DIR_'))
165{
166	$employee = new Employee($cookie->id_employee);
167	$context->employee = $employee;
168
169	/* Auth on shops are recached after employee assignation */
170	if ($employee->id_profile != _PS_ADMIN_PROFILE_)
171		Shop::cacheShops(true);
172
173	$cookie->id_lang = (int)$employee->id_lang;
174}
175
176/* if the language stored in the cookie is not available language, use default language */
177if (isset($cookie->id_lang) && $cookie->id_lang)
178	$language = new Language($cookie->id_lang);
179if (!isset($language) || !Validate::isLoadedObject($language))
180	$language = new Language(Configuration::get('PS_LANG_DEFAULT'));
181$context->language = $language;
182
183if (!defined('_PS_ADMIN_DIR_'))
184{
185	if (isset($cookie->id_customer) && (int)$cookie->id_customer)
186	{
187		$customer = new Customer($cookie->id_customer);
188		if (!Validate::isLoadedObject($customer))
189			$context->cookie->logout();
190		else
191		{
192			$customer->logged = true;
193			if ($customer->id_lang != $context->language->id)
194			{
195				$customer->id_lang = $context->language->id;
196				$customer->update();
197			}
198		}
199	}
200
201	if (!isset($customer) || !Validate::isLoadedObject($customer))
202	{
203		$customer = new Customer();
204		
205		// Change the default group
206		if (Group::isFeatureActive())
207			$customer->id_default_group = (int)Configuration::get('PS_UNIDENTIFIED_GROUP');
208	}
209	$customer->id_guest = $cookie->id_guest;
210	$context->customer = $customer;
211}
212
213/* Link should also be initialized in the context here for retrocompatibility */
214$https_link = (Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
215$context->link = new Link($https_link, $https_link);
216
217/**
218 * @deprecated : these defines are going to be deleted on 1.6 version of Prestashop
219 * USE : Configuration::get() method in order to getting the id of order status
220 */
221define('_PS_OS_CHEQUE_',      Configuration::get('PS_OS_CHEQUE'));
222define('_PS_OS_PAYMENT_',     Configuration::get('PS_OS_PAYMENT'));
223define('_PS_OS_PREPARATION_', Configuration::get('PS_OS_PREPARATION'));
224define('_PS_OS_SHIPPING_',    Configuration::get('PS_OS_SHIPPING'));
225define('_PS_OS_DELIVERED_',   Configuration::get('PS_OS_DELIVERED'));
226define('_PS_OS_CANCELED_',    Configuration::get('PS_OS_CANCELED'));
227define('_PS_OS_REFUND_',      Configuration::get('PS_OS_REFUND'));
228define('_PS_OS_ERROR_',       Configuration::get('PS_OS_ERROR'));
229define('_PS_OS_OUTOFSTOCK_',  Configuration::get('PS_OS_OUTOFSTOCK'));
230define('_PS_OS_OUTOFSTOCK_PAID_',  Configuration::get('PS_OS_OUTOFSTOCK_PAID'));
231define('_PS_OS_OUTOFSTOCK_UNPAID_',  Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'));
232define('_PS_OS_BANKWIRE_',    Configuration::get('PS_OS_BANKWIRE'));
233define('_PS_OS_PAYPAL_',      Configuration::get('PS_OS_PAYPAL'));
234define('_PS_OS_WS_PAYMENT_', Configuration::get('PS_OS_WS_PAYMENT'));
235
236/* Get smarty */
237require_once(dirname(__FILE__).'/smarty.config.inc.php');
238$context->smarty = $smarty;