PageRenderTime 23ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/install-dev/init.php

https://gitlab.com/goolic/PrestaShop
PHP | 124 lines | 71 code | 22 blank | 31 comment | 13 complexity | c6af330adb4c89c01ad423bd240f11c4 MD5 | raw file
  1. <?php
  2. /**
  3. * 2007-2015 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-2015 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. ob_start();
  27. // Check PHP version
  28. if (version_compare(preg_replace('/[^0-9.]/', '', PHP_VERSION), '5.2', '<')) {
  29. die('You need at least PHP 5.2 to run PrestaShop. Your current PHP version is '.PHP_VERSION);
  30. }
  31. // we check if theses constants are defined
  32. // in order to use init.php in upgrade.php script
  33. if (!defined('__PS_BASE_URI__')) {
  34. 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))));
  35. }
  36. if (!defined('_PS_CORE_DIR_')) {
  37. define('_PS_CORE_DIR_', realpath(dirname(__FILE__).'/..'));
  38. }
  39. $themes = glob(dirname(dirname(__FILE__)).'/themes/*/config/theme.yml');
  40. if (!defined('_THEME_NAME_')) {
  41. define('_THEME_NAME_', basename(substr($themes[0], 0, -strlen('/config/theme.yml'))));
  42. }
  43. require_once(_PS_CORE_DIR_.'/config/defines.inc.php');
  44. require_once(_PS_CORE_DIR_.'/config/autoload.php');
  45. require_once(_PS_CORE_DIR_.'/config/bootstrap.php');
  46. require_once(_PS_CORE_DIR_.'/config/defines_uri.inc.php');
  47. // Generate common constants
  48. define('PS_INSTALLATION_IN_PROGRESS', true);
  49. define('_PS_INSTALL_PATH_', dirname(__FILE__).'/');
  50. define('_PS_INSTALL_DATA_PATH_', _PS_INSTALL_PATH_.'data/');
  51. define('_PS_INSTALL_CONTROLLERS_PATH_', _PS_INSTALL_PATH_.'controllers/');
  52. define('_PS_INSTALL_MODELS_PATH_', _PS_INSTALL_PATH_.'models/');
  53. define('_PS_INSTALL_LANGS_PATH_', _PS_INSTALL_PATH_.'langs/');
  54. define('_PS_INSTALL_FIXTURES_PATH_', _PS_INSTALL_PATH_.'fixtures/');
  55. require_once(_PS_INSTALL_PATH_.'install_version.php');
  56. // PrestaShop autoload is used to load some helpfull classes like Tools.
  57. // Add classes used by installer bellow.
  58. require_once(_PS_CORE_DIR_.'/config/alias.php');
  59. require_once(_PS_INSTALL_PATH_.'classes/exception.php');
  60. require_once(_PS_INSTALL_PATH_.'classes/languages.php');
  61. require_once(_PS_INSTALL_PATH_.'classes/language.php');
  62. require_once(_PS_INSTALL_PATH_.'classes/model.php');
  63. require_once(_PS_INSTALL_PATH_.'classes/session.php');
  64. require_once(_PS_INSTALL_PATH_.'classes/sqlLoader.php');
  65. require_once(_PS_INSTALL_PATH_.'classes/xmlLoader.php');
  66. require_once(_PS_INSTALL_PATH_.'classes/simplexml.php');
  67. @set_time_limit(0);
  68. if (!@ini_get('date.timezone')) {
  69. @date_default_timezone_set('Europe/Paris');
  70. }
  71. // Try to improve memory limit if it's under 64M
  72. $current_memory_limit = psinstall_get_memory_limit();
  73. if ($current_memory_limit > 0 && $current_memory_limit < psinstall_get_octets('64M')) {
  74. ini_set('memory_limit', '64M');
  75. }
  76. function psinstall_get_octets($option)
  77. {
  78. if (preg_match('/[0-9]+k/i', $option)) {
  79. return 1024 * (int)$option;
  80. }
  81. if (preg_match('/[0-9]+m/i', $option)) {
  82. return 1024 * 1024 * (int)$option;
  83. }
  84. if (preg_match('/[0-9]+g/i', $option)) {
  85. return 1024 * 1024 * 1024 * (int)$option;
  86. }
  87. return $option;
  88. }
  89. function psinstall_get_memory_limit()
  90. {
  91. $memory_limit = @ini_get('memory_limit');
  92. if (preg_match('/[0-9]+k/i', $memory_limit)) {
  93. return 1024 * (int)$memory_limit;
  94. }
  95. if (preg_match('/[0-9]+m/i', $memory_limit)) {
  96. return 1024 * 1024 * (int)$memory_limit;
  97. }
  98. if (preg_match('/[0-9]+g/i', $memory_limit)) {
  99. return 1024 * 1024 * 1024 * (int)$memory_limit;
  100. }
  101. return $memory_limit;
  102. }