PageRenderTime 40ms CodeModel.GetById 23ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/config/config.inc.php

https://gitlab.com/mtellezgalindo/PrestaShop
PHP | 250 lines | 164 code | 37 blank | 49 comment | 50 complexity | 4190d79d21d9482ffd204dbd9b26c6aa 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('default_charset', 'utf-8');
 35ini_set('magic_quotes_runtime', 0);
 36ini_set('magic_quotes_sybase', 0);
 37
 38/* correct Apache charset (except if it's too late */
 39if (!headers_sent())
 40	header('Content-Type: text/html; charset=utf-8');
 41
 42/* No settings file? goto installer... */
 43if (!file_exists(_PS_ROOT_DIR_.'/config/settings.inc.php'))
 44{
 45	if (file_exists(dirname(__FILE__).'/../install'))
 46		header('Location: install/');
 47	elseif (file_exists(dirname(__FILE__).'/../install-dev'))
 48		header('Location: install-dev/');
 49	else
 50		die('Error: "install" directory is missing');
 51	exit;
 52}
 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::convertBytes(ini_get('upload_max_filesize')) < Tools::convertBytes('100M'))
 68	ini_set('upload_max_filesize', '100M');
 69
 70if (Tools::isPHPCLI() && isset($argc) && isset($argv))
 71	Tools::argvToGET($argc, $argv);
 72
 73/* Redefine REQUEST_URI if empty (on some webservers...) */
 74if (!isset($_SERVER['REQUEST_URI']) || empty($_SERVER['REQUEST_URI']))
 75{
 76	if (!isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['SCRIPT_FILENAME']))
 77		$_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_FILENAME'];
 78	if (isset($_SERVER['SCRIPT_NAME']))
 79	{
 80		if (basename($_SERVER['SCRIPT_NAME']) == 'index.php' && empty($_SERVER['QUERY_STRING']))
 81			$_SERVER['REQUEST_URI'] = dirname($_SERVER['SCRIPT_NAME']).'/';
 82		else
 83		{
 84			$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
 85			if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
 86				$_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
 87		}
 88	}
 89}
 90
 91/* Trying to redefine HTTP_HOST if empty (on some webservers...) */
 92if (!isset($_SERVER['HTTP_HOST']) || empty($_SERVER['HTTP_HOST']))
 93	$_SERVER['HTTP_HOST'] = @getenv('HTTP_HOST');
 94
 95$context = Context::getContext();
 96
 97/* Initialize the current Shop */
 98try
 99{
100	$context->shop = Shop::initialize();
101	$context->theme = new Theme((int)$context->shop->id_theme);
102	if ((Tools::isEmpty($theme_name = $context->shop->getTheme()) || !Validate::isLoadedObject($context->theme)) && !defined('_PS_ADMIN_DIR_'))
103		throw new PrestaShopException(Tools::displayError('Current theme unselected. Please check your theme configuration.'));
104}
105catch (PrestaShopException $e)
106{
107	$e->displayMessage();
108}
109define('_THEME_NAME_', $theme_name);
110define('__PS_BASE_URI__', $context->shop->getBaseURI());
111
112/* Include all defines related to base uri and theme name */
113require_once(dirname(__FILE__).'/defines_uri.inc.php');
114
115global $_MODULES;
116$_MODULES = array();
117
118define('_PS_PRICE_DISPLAY_PRECISION_', Configuration::get('PS_PRICE_DISPLAY_PRECISION'));
119define('_PS_PRICE_COMPUTE_PRECISION_', _PS_PRICE_DISPLAY_PRECISION_);
120
121if (Configuration::get('PS_USE_HTMLPURIFIER'))
122	require_once (_PS_TOOL_DIR_.'htmlpurifier/HTMLPurifier.standalone.php');
123
124/* Load all languages */
125Language::loadLanguages();
126
127/* Loading default country */
128$default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
129$context->country = $default_country;
130
131/* It is not safe to rely on the system's timezone settings, and this would generate a PHP Strict Standards notice. */
132@date_default_timezone_set(Configuration::get('PS_TIMEZONE'));
133
134/* Set locales */
135$locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')).'_'.strtoupper(Configuration::get('PS_LOCALE_COUNTRY'));
136/* Please do not use LC_ALL here http://www.php.net/manual/fr/function.setlocale.php#25041 */
137setlocale(LC_COLLATE, $locale.'.UTF-8', $locale.'.utf8');
138setlocale(LC_CTYPE, $locale.'.UTF-8', $locale.'.utf8');
139setlocale(LC_TIME, $locale.'.UTF-8', $locale.'.utf8');
140setlocale(LC_NUMERIC, 'en_US.UTF-8', 'en_US.utf8');
141
142/* Instantiate cookie */
143$cookie_lifetime = defined('_PS_ADMIN_DIR_') ? (int)Configuration::get('PS_COOKIE_LIFETIME_BO') : (int)Configuration::get('PS_COOKIE_LIFETIME_FO');
144if ($cookie_lifetime > 0)
145	$cookie_lifetime = time() + (max($cookie_lifetime, 1) * 3600);
146
147if (defined('_PS_ADMIN_DIR_'))
148	$cookie = new Cookie('psAdmin', '', $cookie_lifetime);
149else
150{
151	$force_ssl = Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE');
152	if ($context->shop->getGroup()->share_order)
153		$cookie = new Cookie('ps-sg'.$context->shop->getGroup()->id, '', $cookie_lifetime, $context->shop->getUrlsSharedCart(), false, $force_ssl);
154	else
155	{
156		$domains = null;
157		if ($context->shop->domain != $context->shop->domain_ssl)
158		  $domains = array($context->shop->domain_ssl, $context->shop->domain);
159
160		$cookie = new Cookie('ps-s'.$context->shop->id, '', $cookie_lifetime, $domains, false, $force_ssl);
161	}
162}
163
164$context->cookie = $cookie;
165
166/* Create employee if in BO, customer else */
167if (defined('_PS_ADMIN_DIR_'))
168{
169	$employee = new Employee($cookie->id_employee);
170	$context->employee = $employee;
171
172	/* Auth on shops are recached after employee assignation */
173	if ($employee->id_profile != _PS_ADMIN_PROFILE_)
174		Shop::cacheShops(true);
175
176	$cookie->id_lang = (int)$employee->id_lang;
177}
178
179/* if the language stored in the cookie is not available language, use default language */
180if (isset($cookie->id_lang) && $cookie->id_lang)
181	$language = new Language($cookie->id_lang);
182if (!isset($language) || !Validate::isLoadedObject($language))
183	$language = new Language(Configuration::get('PS_LANG_DEFAULT'));
184$context->language = $language;
185
186if (!defined('_PS_ADMIN_DIR_'))
187{
188	if (isset($cookie->id_customer) && (int)$cookie->id_customer)
189	{
190		$customer = new Customer($cookie->id_customer);
191		if (!Validate::isLoadedObject($customer))
192			$context->cookie->logout();
193		else
194		{
195			$customer->logged = true;
196			if ($customer->id_lang != $context->language->id)
197			{
198				$customer->id_lang = $context->language->id;
199				$customer->update();
200			}
201		}
202	}
203
204	if (!isset($customer) || !Validate::isLoadedObject($customer))
205	{
206		$customer = new Customer();
207
208		/* Change the default group */
209		if (Group::isFeatureActive())
210			$customer->id_default_group = (int)Configuration::get('PS_UNIDENTIFIED_GROUP');
211	}
212	$customer->id_guest = $cookie->id_guest;
213	$context->customer = $customer;
214}
215
216/* Link should also be initialized in the context here for retrocompatibility */
217$https_link = (Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
218$context->link = new Link($https_link, $https_link);
219
220/**
221 * @deprecated
222 * USE : Configuration::get() method in order to getting the id of order status
223 */
224
225define('_PS_OS_CHEQUE_', Configuration::get('PS_OS_CHEQUE'));
226define('_PS_OS_PAYMENT_', Configuration::get('PS_OS_PAYMENT'));
227define('_PS_OS_PREPARATION_', Configuration::get('PS_OS_PREPARATION'));
228define('_PS_OS_SHIPPING_', Configuration::get('PS_OS_SHIPPING'));
229define('_PS_OS_DELIVERED_', Configuration::get('PS_OS_DELIVERED'));
230define('_PS_OS_CANCELED_', Configuration::get('PS_OS_CANCELED'));
231define('_PS_OS_REFUND_', Configuration::get('PS_OS_REFUND'));
232define('_PS_OS_ERROR_', Configuration::get('PS_OS_ERROR'));
233define('_PS_OS_OUTOFSTOCK_', Configuration::get('PS_OS_OUTOFSTOCK'));
234define('_PS_OS_OUTOFSTOCK_PAID_', Configuration::get('PS_OS_OUTOFSTOCK_PAID'));
235define('_PS_OS_OUTOFSTOCK_UNPAID_', Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'));
236define('_PS_OS_BANKWIRE_', Configuration::get('PS_OS_BANKWIRE'));
237define('_PS_OS_PAYPAL_', Configuration::get('PS_OS_PAYPAL'));
238define('_PS_OS_WS_PAYMENT_', Configuration::get('PS_OS_WS_PAYMENT'));
239define('_PS_OS_COD_VALIDATION_', Configuration::get('PS_OS_COD_VALIDATION'));
240
241if (!defined('_MEDIA_SERVER_1_'))
242	define('_MEDIA_SERVER_1_', Configuration::get('PS_MEDIA_SERVER_1'));
243if (!defined('_MEDIA_SERVER_2_'))
244	define('_MEDIA_SERVER_2_', Configuration::get('PS_MEDIA_SERVER_2'));
245if (!defined('_MEDIA_SERVER_3_'))
246	define('_MEDIA_SERVER_3_', Configuration::get('PS_MEDIA_SERVER_3'));
247
248/* Get smarty */
249require_once(dirname(__FILE__).'/smarty.config.inc.php');
250$context->smarty = $smarty;