PageRenderTime 64ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/osCommerce/OM/Core/Site/Admin/Controller.php

https://github.com/bodi000/oscommerce
PHP | 122 lines | 105 code | 11 blank | 6 comment | 1 complexity | 4d8bb737b14d4f0feb15fd9d59b90751 MD5 | raw file
  1. <?php
  2. /**
  3. * osCommerce Online Merchant
  4. *
  5. * @copyright Copyright (c) 2011 osCommerce; http://www.oscommerce.com
  6. * @license BSD License; http://www.oscommerce.com/bsdlicense.txt
  7. */
  8. namespace osCommerce\OM\Core\Site\Admin;
  9. use osCommerce\OM\Core\Access;
  10. use osCommerce\OM\Core\Cache;
  11. use osCommerce\OM\Core\PDO;
  12. use osCommerce\OM\Core\OSCOM;
  13. use osCommerce\OM\Core\Registry;
  14. use osCommerce\OM\Core\Session;
  15. class Controller implements \osCommerce\OM\Core\SiteInterface {
  16. protected static $_default_application = 'Dashboard';
  17. protected static $_guest_applications = array('Dashboard', 'Login');
  18. public static function initialize() {
  19. Registry::set('MessageStack', new MessageStack());
  20. Registry::set('Cache', new Cache());
  21. Registry::set('PDO', PDO::initialize());
  22. foreach ( OSCOM::callDB('Shop\GetConfiguration', null, 'Site') as $param ) {
  23. define($param['cfgKey'], $param['cfgValue']);
  24. }
  25. Registry::set('Session', Session::load('adminSid'));
  26. Registry::get('Session')->start();
  27. Registry::get('MessageStack')->loadFromSession();
  28. Registry::set('Language', new Language());
  29. if ( !self::hasAccess(OSCOM::getSiteApplication()) ) {
  30. Registry::get('MessageStack')->add('header', 'No access.', 'error');
  31. OSCOM::redirect(OSCOM::getLink(null, OSCOM::getDefaultSiteApplication()));
  32. }
  33. $application = 'osCommerce\\OM\\Core\\Site\\Admin\\Application\\' . OSCOM::getSiteApplication() . '\\Controller';
  34. Registry::set('Application', new $application());
  35. Registry::set('Template', new Template());
  36. Registry::get('Template')->setApplication(Registry::get('Application'));
  37. // HPDL move following checks elsewhere
  38. // check if a default currency is set
  39. if (!defined('DEFAULT_CURRENCY')) {
  40. Registry::get('MessageStack')->add('header', OSCOM::getDef('ms_error_no_default_currency'), 'error');
  41. }
  42. // check if a default language is set
  43. if (!defined('DEFAULT_LANGUAGE')) {
  44. Registry::get('MessageStack')->add('header', ERROR_NO_DEFAULT_LANGUAGE_DEFINED, 'error');
  45. }
  46. if (function_exists('ini_get') && ((bool)ini_get('file_uploads') == false) ) {
  47. Registry::get('MessageStack')->add('header', OSCOM::getDef('ms_warning_uploads_disabled'), 'warning');
  48. }
  49. // check if Work directories are writable
  50. $work_dirs = array();
  51. foreach ( array('Cache', 'CoreUpdate', 'Database', 'Logs', 'Session', 'Temp') as $w ) {
  52. if ( !is_writable(OSCOM::BASE_DIRECTORY . 'Work/' . $w) ) {
  53. $work_dirs[] = $w;
  54. }
  55. }
  56. if ( !empty($work_dirs) ) {
  57. Registry::get('MessageStack')->add('header', sprintf(OSCOM::getDef('ms_error_work_directories_not_writable'), OSCOM::BASE_DIRECTORY . 'Work/', implode(', ', $work_dirs)), 'error');
  58. }
  59. if ( !OSCOM::configExists('time_zone', 'OSCOM') ) {
  60. Registry::get('MessageStack')->add('header', OSCOM::getDef('ms_warning_time_zone_not_defined'), 'warning');
  61. }
  62. if ( !OSCOM::configExists('dir_fs_public', 'OSCOM') || !file_exists(OSCOM::getConfig('dir_fs_public', 'OSCOM')) ) {
  63. Registry::get('MessageStack')->add('header', OSCOM::getDef('ms_warning_dir_fs_public_not_defined'), 'warning');
  64. }
  65. // check if the upload directory exists
  66. if ( is_dir(OSCOM::getConfig('dir_fs_public', 'OSCOM') . 'upload') ) {
  67. if ( !is_writeable(OSCOM::getConfig('dir_fs_public', 'OSCOM') . 'upload') ) {
  68. Registry::get('MessageStack')->add('header', sprintf(OSCOM::getDef('ms_error_upload_directory_not_writable'), OSCOM::getConfig('dir_fs_public', 'OSCOM') . 'upload'), 'error');
  69. }
  70. } else {
  71. Registry::get('MessageStack')->add('header', sprintf(OSCOM::getDef('ms_error_upload_directory_non_existant'), OSCOM::getConfig('dir_fs_public', 'OSCOM') . 'upload'), 'error');
  72. }
  73. }
  74. public static function getDefaultApplication() {
  75. return self::$_default_application;
  76. }
  77. public static function hasAccess($application) {
  78. if ( !isset($_SESSION[OSCOM::getSite()]['id']) ) {
  79. $redirect = false;
  80. if ( $application != 'Login' ) {
  81. $_SESSION[OSCOM::getSite()]['redirect_origin'] = $application;
  82. $redirect = true;
  83. }
  84. if ( $redirect === true ) {
  85. OSCOM::redirect(OSCOM::getLink(null, 'Login'));
  86. }
  87. }
  88. return Access::hasAccess(OSCOM::getSite(), $application);
  89. }
  90. public static function getGuestApplications() {
  91. return self::$_guest_applications;
  92. }
  93. }
  94. ?>