PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/config/config.inc.php

https://github.com/netplayer/PrestaShop
PHP | 235 lines | 152 code | 33 blank | 50 comment | 47 complexity | e7510eabd87afa7cec2362f35fdf13ac MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, LGPL-3.0
  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. /* correct Apache charset (except if it's too late */
  35. if (!headers_sent())
  36. header('Content-Type: text/html; charset=utf-8');
  37. /* No settings file? goto installer... */
  38. if (!file_exists(_PS_ROOT_DIR_.'/config/settings.inc.php'))
  39. {
  40. $dir = ((substr($_SERVER['REQUEST_URI'], -1) == '/' || is_dir($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : dirname($_SERVER['REQUEST_URI']).'/');
  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. if ($context->shop->getGroup()->share_order)
  128. $cookie = new Cookie('ps-sg'.$context->shop->getGroup()->id, '', $cookie_lifetime, $context->shop->getUrlsSharedCart());
  129. else
  130. {
  131. $domains = null;
  132. if ($context->shop->domain != $context->shop->domain_ssl)
  133. $domains = array($context->shop->domain_ssl, $context->shop->domain);
  134. $cookie = new Cookie('ps-s'.$context->shop->id, '', $cookie_lifetime, $domains);
  135. }
  136. }
  137. $context->cookie = $cookie;
  138. /* Create employee if in BO, customer else */
  139. if (defined('_PS_ADMIN_DIR_'))
  140. {
  141. $employee = new Employee($cookie->id_employee);
  142. $context->employee = $employee;
  143. /* Auth on shops are recached after employee assignation */
  144. if ($employee->id_profile != _PS_ADMIN_PROFILE_)
  145. Shop::cacheShops(true);
  146. $cookie->id_lang = (int)$employee->id_lang;
  147. }
  148. /* if the language stored in the cookie is not available language, use default language */
  149. if (isset($cookie->id_lang) && $cookie->id_lang)
  150. $language = new Language($cookie->id_lang);
  151. if (!isset($language) || !Validate::isLoadedObject($language))
  152. $language = new Language(Configuration::get('PS_LANG_DEFAULT'));
  153. $context->language = $language;
  154. if (!defined('_PS_ADMIN_DIR_'))
  155. {
  156. if (isset($cookie->id_customer) && (int)$cookie->id_customer)
  157. {
  158. $customer = new Customer($cookie->id_customer);
  159. if (!Validate::isLoadedObject($customer))
  160. $context->cookie->logout();
  161. else
  162. {
  163. $customer->logged = true;
  164. if ($customer->id_lang != $context->language->id)
  165. {
  166. $customer->id_lang = $context->language->id;
  167. $customer->update();
  168. }
  169. }
  170. }
  171. if (!isset($customer) || !Validate::isLoadedObject($customer))
  172. {
  173. $customer = new Customer();
  174. // Change the default group
  175. if (Group::isFeatureActive())
  176. $customer->id_default_group = (int)Configuration::get('PS_UNIDENTIFIED_GROUP');
  177. }
  178. $customer->id_guest = $cookie->id_guest;
  179. $context->customer = $customer;
  180. }
  181. /* Link should also be initialized in the context here for retrocompatibility */
  182. $https_link = (Tools::usingSecureMode() && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
  183. $context->link = new Link($https_link, $https_link);
  184. /**
  185. * @deprecated : these defines are going to be deleted on 1.6 version of Prestashop
  186. * USE : Configuration::get() method in order to getting the id of order status
  187. */
  188. define('_PS_OS_CHEQUE_', Configuration::get('PS_OS_CHEQUE'));
  189. define('_PS_OS_PAYMENT_', Configuration::get('PS_OS_PAYMENT'));
  190. define('_PS_OS_PREPARATION_', Configuration::get('PS_OS_PREPARATION'));
  191. define('_PS_OS_SHIPPING_', Configuration::get('PS_OS_SHIPPING'));
  192. define('_PS_OS_DELIVERED_', Configuration::get('PS_OS_DELIVERED'));
  193. define('_PS_OS_CANCELED_', Configuration::get('PS_OS_CANCELED'));
  194. define('_PS_OS_REFUND_', Configuration::get('PS_OS_REFUND'));
  195. define('_PS_OS_ERROR_', Configuration::get('PS_OS_ERROR'));
  196. define('_PS_OS_OUTOFSTOCK_', Configuration::get('PS_OS_OUTOFSTOCK'));
  197. define('_PS_OS_BANKWIRE_', Configuration::get('PS_OS_BANKWIRE'));
  198. define('_PS_OS_PAYPAL_', Configuration::get('PS_OS_PAYPAL'));
  199. define('_PS_OS_WS_PAYMENT_', Configuration::get('PS_OS_WS_PAYMENT'));
  200. /* Get smarty */
  201. require_once(dirname(__FILE__).'/smarty.config.inc.php');
  202. $context->smarty = $smarty;