PageRenderTime 227ms CodeModel.GetById 13ms RepoModel.GetById 0ms 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. require_once(dirname(__FILE__).'/defines.inc.php');
  27. $start_time = microtime(true);
  28. /* SSL configuration */
  29. define('_PS_SSL_PORT_', 443);
  30. /* Improve PHP configuration to prevent issues */
  31. ini_set('upload_max_filesize', '100M');
  32. ini_set('default_charset', 'utf-8');
  33. ini_set('magic_quotes_runtime', 0);
  34. ini_set('magic_quotes_sybase', 0);
  35. /* correct Apache charset (except if it's too late */
  36. if (!headers_sent())
  37. header('Content-Type: text/html; charset=utf-8');
  38. /* No settings file? goto installer... */
  39. if (!file_exists(_PS_ROOT_DIR_.'/config/settings.inc.php'))
  40. {
  41. if (file_exists(dirname(__FILE__).'/../install'))
  42. header('Location: install/');
  43. elseif (file_exists(dirname(__FILE__).'/../install-dev'))
  44. header('Location: install-dev/');
  45. else
  46. die('Error: "install" directory is missing');
  47. exit;
  48. }
  49. //include settings file only if we are not in multi-tenancy mode
  50. require_once(_PS_ROOT_DIR_.'/config/settings.inc.php');
  51. require_once(_PS_CONFIG_DIR_.'autoload.php');
  52. if (_PS_DEBUG_PROFILING_)
  53. {
  54. include_once(_PS_TOOL_DIR_.'profiling/Controller.php');
  55. include_once(_PS_TOOL_DIR_.'profiling/ObjectModel.php');
  56. include_once(_PS_TOOL_DIR_.'profiling/Hook.php');
  57. include_once(_PS_TOOL_DIR_.'profiling/Db.php');
  58. include_once(_PS_TOOL_DIR_.'profiling/Tools.php');
  59. }
  60. if (Tools::isPHPCLI() && isset($argc) && isset($argv))
  61. Tools::argvToGET($argc, $argv);
  62. /* Redefine REQUEST_URI if empty (on some webservers...) */
  63. if (!isset($_SERVER['REQUEST_URI']) || empty($_SERVER['REQUEST_URI']))
  64. {
  65. if (!isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['SCRIPT_FILENAME']))
  66. $_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_FILENAME'];
  67. if (isset($_SERVER['SCRIPT_NAME']))
  68. {
  69. if (basename($_SERVER['SCRIPT_NAME']) == 'index.php' && empty($_SERVER['QUERY_STRING']))
  70. $_SERVER['REQUEST_URI'] = dirname($_SERVER['SCRIPT_NAME']).'/';
  71. else
  72. {
  73. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
  74. if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
  75. $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
  76. }
  77. }
  78. }
  79. /* Trying to redefine HTTP_HOST if empty (on some webservers...) */
  80. if (!isset($_SERVER['HTTP_HOST']) || empty($_SERVER['HTTP_HOST']))
  81. $_SERVER['HTTP_HOST'] = @getenv('HTTP_HOST');
  82. $context = Context::getContext();
  83. /* Initialize the current Shop */
  84. try
  85. {
  86. $context->shop = Shop::initialize();
  87. $context->theme = new Theme((int)$context->shop->id_theme);
  88. if ((Tools::isEmpty($theme_name = $context->shop->getTheme()) || !Validate::isLoadedObject($context->theme)) && !defined('_PS_ADMIN_DIR_'))
  89. throw new PrestaShopException(Tools::displayError('Current theme unselected. Please check your theme configuration.'));
  90. }
  91. catch (PrestaShopException $e)
  92. {
  93. $e->displayMessage();
  94. }
  95. define('_THEME_NAME_', $theme_name);
  96. define('__PS_BASE_URI__', $context->shop->getBaseURI());
  97. /* Include all defines related to base uri and theme name */
  98. require_once(dirname(__FILE__).'/defines_uri.inc.php');
  99. global $_MODULES;
  100. $_MODULES = array();
  101. /* Load configuration */
  102. Configuration::loadConfiguration();
  103. if (Configuration::get('PS_USE_HTMLPURIFIER'))
  104. require_once (_PS_TOOL_DIR_.'htmlpurifier/HTMLPurifier.standalone.php');
  105. /* Load all languages */
  106. Language::loadLanguages();
  107. /* Loading default country */
  108. $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
  109. $context->country = $defaultCountry;
  110. /* It is not safe to rely on the system's timezone settings, and this would generate a PHP Strict Standards notice. */
  111. @date_default_timezone_set(Configuration::get('PS_TIMEZONE'));
  112. /* Set locales */
  113. $locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')).'_'.strtoupper(Configuration::get('PS_LOCALE_COUNTRY'));
  114. /* Please do not use LC_ALL here http://www.php.net/manual/fr/function.setlocale.php#25041 */
  115. setlocale(LC_COLLATE, $locale.'.UTF-8', $locale.'.utf8');
  116. setlocale(LC_CTYPE, $locale.'.UTF-8', $locale.'.utf8');
  117. setlocale(LC_TIME, $locale.'.UTF-8', $locale.'.utf8');
  118. setlocale(LC_NUMERIC, 'en_US.UTF-8', 'en_US.utf8');
  119. /* Instantiate cookie */
  120. $cookie_lifetime = (int)(defined('_PS_ADMIN_DIR_') ? Configuration::get('PS_COOKIE_LIFETIME_BO') : Configuration::get('PS_COOKIE_LIFETIME_FO'));
  121. if ($cookie_lifetime > 0)
  122. $cookie_lifetime = time() + (max($cookie_lifetime, 1) * 3600);
  123. if (defined('_PS_ADMIN_DIR_'))
  124. $cookie = new Cookie('psAdmin', '', $cookie_lifetime);
  125. else
  126. {
  127. $force_ssl = Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE');
  128. if ($context->shop->getGroup()->share_order)
  129. $cookie = new Cookie('ps-sg'.$context->shop->getGroup()->id, '', $cookie_lifetime, $context->shop->getUrlsSharedCart(), false, $force_ssl);
  130. else
  131. {
  132. $domains = null;
  133. if ($context->shop->domain != $context->shop->domain_ssl)
  134. $domains = array($context->shop->domain_ssl, $context->shop->domain);
  135. $cookie = new Cookie('ps-s'.$context->shop->id, '', $cookie_lifetime, $domains, false, $force_ssl);
  136. }
  137. }
  138. $context->cookie = $cookie;
  139. /* Create employee if in BO, customer else */
  140. if (defined('_PS_ADMIN_DIR_'))
  141. {
  142. $employee = new Employee($cookie->id_employee);
  143. $context->employee = $employee;
  144. /* Auth on shops are recached after employee assignation */
  145. if ($employee->id_profile != _PS_ADMIN_PROFILE_)
  146. Shop::cacheShops(true);
  147. $cookie->id_lang = (int)$employee->id_lang;
  148. }
  149. /* if the language stored in the cookie is not available language, use default language */
  150. if (isset($cookie->id_lang) && $cookie->id_lang)
  151. $language = new Language($cookie->id_lang);
  152. if (!isset($language) || !Validate::isLoadedObject($language))
  153. $language = new Language(Configuration::get('PS_LANG_DEFAULT'));
  154. $context->language = $language;
  155. if (!defined('_PS_ADMIN_DIR_'))
  156. {
  157. if (isset($cookie->id_customer) && (int)$cookie->id_customer)
  158. {
  159. $customer = new Customer($cookie->id_customer);
  160. if (!Validate::isLoadedObject($customer))
  161. $context->cookie->logout();
  162. else
  163. {
  164. $customer->logged = true;
  165. if ($customer->id_lang != $context->language->id)
  166. {
  167. $customer->id_lang = $context->language->id;
  168. $customer->update();
  169. }
  170. }
  171. }
  172. if (!isset($customer) || !Validate::isLoadedObject($customer))
  173. {
  174. $customer = new Customer();
  175. // Change the default group
  176. if (Group::isFeatureActive())
  177. $customer->id_default_group = (int)Configuration::get('PS_UNIDENTIFIED_GROUP');
  178. }
  179. $customer->id_guest = $cookie->id_guest;
  180. $context->customer = $customer;
  181. }
  182. /* Link should also be initialized in the context here for retrocompatibility */
  183. $https_link = (Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
  184. $context->link = new Link($https_link, $https_link);
  185. /**
  186. * @deprecated : these defines are going to be deleted on 1.6 version of Prestashop
  187. * USE : Configuration::get() method in order to getting the id of order status
  188. */
  189. define('_PS_OS_CHEQUE_', Configuration::get('PS_OS_CHEQUE'));
  190. define('_PS_OS_PAYMENT_', Configuration::get('PS_OS_PAYMENT'));
  191. define('_PS_OS_PREPARATION_', Configuration::get('PS_OS_PREPARATION'));
  192. define('_PS_OS_SHIPPING_', Configuration::get('PS_OS_SHIPPING'));
  193. define('_PS_OS_DELIVERED_', Configuration::get('PS_OS_DELIVERED'));
  194. define('_PS_OS_CANCELED_', Configuration::get('PS_OS_CANCELED'));
  195. define('_PS_OS_REFUND_', Configuration::get('PS_OS_REFUND'));
  196. define('_PS_OS_ERROR_', Configuration::get('PS_OS_ERROR'));
  197. define('_PS_OS_OUTOFSTOCK_', Configuration::get('PS_OS_OUTOFSTOCK'));
  198. define('_PS_OS_OUTOFSTOCK_PAID_', Configuration::get('PS_OS_OUTOFSTOCK_PAID'));
  199. define('_PS_OS_OUTOFSTOCK_UNPAID_', Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'));
  200. define('_PS_OS_BANKWIRE_', Configuration::get('PS_OS_BANKWIRE'));
  201. define('_PS_OS_PAYPAL_', Configuration::get('PS_OS_PAYPAL'));
  202. define('_PS_OS_WS_PAYMENT_', Configuration::get('PS_OS_WS_PAYMENT'));
  203. /* Get smarty */
  204. require_once(dirname(__FILE__).'/smarty.config.inc.php');
  205. $context->smarty = $smarty;