PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_akeeba/dispatcher.php

https://bitbucket.org/kraymitchell/apex
PHP | 136 lines | 90 code | 21 blank | 25 comment | 16 complexity | 5cdda66b2df5d5cd1abba351704995e1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * @package AkeebaBackup
  4. * @copyright Copyright (c)2009-2012 Nicholas K. Dionysopoulos
  5. * @license GNU General Public License version 3, or later
  6. * @since 3.5
  7. */
  8. // Protect from unauthorized access
  9. defined('_JEXEC') or die();
  10. class AkeebaDispatcher extends FOFDispatcher
  11. {
  12. public function onBeforeDispatch() {
  13. $result = parent::onBeforeDispatch();
  14. if($result) {
  15. // Load Akeeba Strapper
  16. include_once JPATH_ROOT.'/media/akeeba_strapper/strapper.php';
  17. AkeebaStrapper::$tag = AKEEBAMEDIATAG;
  18. AkeebaStrapper::bootstrap();
  19. AkeebaStrapper::jQueryUI();
  20. AkeebaStrapper::addJSfile('media://com_akeeba/js/gui-helpers.js');
  21. AkeebaStrapper::addJSfile('media://com_akeeba/js/akeebaui.js');
  22. AkeebaStrapper::addJSfile('media://com_akeeba/plugins/js/akeebaui.js');
  23. AkeebaStrapper::addCSSfile('media://com_akeeba/theme/akeebaui.css');
  24. }
  25. return $result;
  26. }
  27. public function dispatch() {
  28. // Merge the language overrides
  29. $paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR);
  30. $jlang = JFactory::getLanguage();
  31. $jlang->load($this->component, $paths[0], 'en-GB', true);
  32. $jlang->load($this->component, $paths[0], null, true);
  33. $jlang->load($this->component, $paths[1], 'en-GB', true);
  34. $jlang->load($this->component, $paths[1], null, true);
  35. $jlang->load($this->component.'.override', $paths[0], 'en-GB', true);
  36. $jlang->load($this->component.'.override', $paths[0], null, true);
  37. $jlang->load($this->component.'.override', $paths[1], 'en-GB', true);
  38. $jlang->load($this->component.'.override', $paths[1], null, true);
  39. // Live Update translation
  40. $jlang->load('liveupdate', JPATH_COMPONENT_ADMINISTRATOR.'/liveupdate', 'en-GB', true);
  41. $jlang->load('liveupdate', JPATH_COMPONENT_ADMINISTRATOR.'/liveupdate', $jlang->getDefault(), true);
  42. $jlang->load('liveupdate', JPATH_COMPONENT_ADMINISTRATOR.'/liveupdate', null, true);
  43. // Timezone fix; avoids errors printed out by PHP 5.3.3+ (thanks Yannick!)
  44. if(function_exists('date_default_timezone_get') && function_exists('date_default_timezone_set')) {
  45. if(function_exists('error_reporting')) {
  46. $oldLevel = error_reporting(0);
  47. }
  48. $serverTimezone = @date_default_timezone_get();
  49. if(empty($serverTimezone) || !is_string($serverTimezone)) $serverTimezone = 'UTC';
  50. if(function_exists('error_reporting')) {
  51. error_reporting($oldLevel);
  52. }
  53. @date_default_timezone_set( $serverTimezone);
  54. }
  55. // Necessary defines for Akeeba Engine
  56. if(!defined('AKEEBAENGINE')) {
  57. define('AKEEBAENGINE', 1); // Required for accessing Akeeba Engine's factory class
  58. define('AKEEBAROOT', dirname(__FILE__).'/akeeba');
  59. }
  60. // Setup Akeeba's ACLs, honoring laxed permissions in component's parameters, if set
  61. // Access check, Joomla! 1.6 style.
  62. $user = JFactory::getUser();
  63. if (!$user->authorise('core.manage', 'com_akeeba')) {
  64. return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
  65. }
  66. // Make sure we have a profile set throughout the component's lifetime
  67. $session = JFactory::getSession();
  68. $profile_id = $session->get('profile', null, 'akeeba');
  69. if(is_null($profile_id))
  70. {
  71. // No profile is set in the session; use default profile
  72. $session->set('profile', 1, 'akeeba');
  73. }
  74. // Load the factory
  75. require_once JPATH_COMPONENT_ADMINISTRATOR.'/akeeba/factory.php';
  76. // Load the Akeeba Backup configuration and check user access permission
  77. $aeconfig = AEFactory::getConfiguration();
  78. AEPlatform::getInstance()->load_configuration();
  79. unset($aeconfig);
  80. // Preload helpers
  81. require_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/includes.php';
  82. require_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/escape.php';
  83. // Load the utils helper library
  84. AEPlatform::getInstance()->load_version_defines();
  85. // Create a versioning tag for our static files
  86. $staticFilesVersioningTag = md5(AKEEBA_VERSION.AKEEBA_DATE);
  87. define('AKEEBAMEDIATAG', $staticFilesVersioningTag);
  88. // If JSON functions don't exist, load our compatibility layer
  89. if( (!function_exists('json_encode')) || (!function_exists('json_decode')) )
  90. {
  91. require_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/jsonlib.php';
  92. }
  93. // Handle Live Update requests
  94. if(!class_exists('LiveUpdate')) {
  95. require_once JPATH_ADMINISTRATOR.'/components/com_akeeba/liveupdate/liveupdate.php';
  96. if((FOFInput::getCmd('view','',$this->input) == 'liveupdate')) {
  97. LiveUpdate::handleRequest();
  98. return true;
  99. }
  100. }
  101. // Look for controllers in the plugins folder
  102. $option = FOFInput::getCmd('option','com_foobar',$this->input);
  103. $view = FOFInput::getCmd('view',$this->defaultView, $this->input);
  104. $c = FOFInflector::singularize($view);
  105. $alt_path = JPATH_ADMINISTRATOR.'/components/'.$option.'/plugins/controllers/'.$c.'.php';
  106. jimport('joomla.filesystem.file');
  107. if(JFile::exists($alt_path))
  108. {
  109. // The requested controller exists and there you load it...
  110. require_once($alt_path);
  111. }
  112. FOFInput::setVar('view', $this->view, $this->input);
  113. parent::dispatch();
  114. }
  115. }