/** * The main code of the Dispatcher. It spawns the necessary controller and * runs it. * * @throws Exception * * @return null */ public function dispatch() { $platform = FOFPlatform::getInstance(); if (!$platform->authorizeAdmin($this->input->getCmd('option', 'com_foobar'))) { return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } $this->transparentAuthentication(); // Merge English and local translations $platform->loadTranslations($this->component); $canDispatch = true; if ($platform->isCli()) { $canDispatch = $canDispatch && $this->onBeforeDispatchCLI(); } $canDispatch = $canDispatch && $this->onBeforeDispatch(); if (!$canDispatch) { $platform->setHeader('Status', '403 Forbidden', true); return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } // Get and execute the controller $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', $this->defaultView); $task = $this->input->getCmd('task', null); if (empty($task)) { $task = $this->getTask($view); } // Pluralise/sungularise the view name for typical tasks if (in_array($task, array('edit', 'add', 'read'))) { $view = FOFInflector::singularize($view); } elseif (in_array($task, array('browse'))) { $view = FOFInflector::pluralize($view); } $this->input->set('view', $view); $this->input->set('task', $task); $config = $this->config; $config['input'] = $this->input; $controller = FOFController::getTmpInstance($option, $view, $config); $status = $controller->execute($task); if (!$this->onAfterDispatch()) { $platform->setHeader('Status', '403 Forbidden', true); return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } $format = $this->input->get('format', 'html', 'cmd'); $format = empty($format) ? 'html' : $format; if ($format == 'html') { // In HTML views perform a redirection if ($controller->redirect()) { return; } } else { // In non-HTML views just exit the application with the proper HTTP headers if ($controller->hasRedirect()) { $headers = $platform->sendHeaders(); jexit(); } } }
/** * The main code of the Dispatcher. It spawns the necessary controller and * runs it. * * @return null|Exception */ public function dispatch() { // Timezone fix; avoids errors printed out by PHP 5.3.3+ list($isCli, $isAdmin) = self::isCliAdmin(); if ($isAdmin) { // Master access check for the back-end, Joomla! 1.6 style. $user = JFactory::getUser(); if (!$user->authorise('core.manage', $this->input->getCmd('option', 'com_foobar')) && !$user->authorise('core.admin', $this->input->getCmd('option', 'com_foobar'))) { if (version_compare(JVERSION, '3.0', 'ge')) { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } else { return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } } } elseif (!$isCli) { // Perform transparent authentication for front-end requests $this->transparentAuthentication(); } // Merge English and local translations if ($isAdmin) { $paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR); } else { $paths = array(JPATH_ADMINISTRATOR, JPATH_ROOT); } $jlang = JFactory::getLanguage(); $jlang->load($this->component, $paths[0], 'en-GB', true); $jlang->load($this->component, $paths[0], null, true); $jlang->load($this->component, $paths[1], 'en-GB', true); $jlang->load($this->component, $paths[1], null, true); $canDispatch = true; if ($isCli) { $canDispatch = $canDispatch && $this->onBeforeDispatchCLI(); } $canDispatch = $canDispatch && $this->onBeforeDispatch(); if (!$canDispatch) { JResponse::setHeader('Status', '403 Forbidden', true); if (version_compare(JVERSION, '3.0', 'ge')) { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } else { return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } } // Get and execute the controller $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', $this->defaultView); $task = $this->input->getCmd('task', ''); if (empty($task)) { $task = $this->getTask($view); } // Pluralise/sungularise the view name for typical tasks if (in_array($task, array('edit', 'add', 'read'))) { $view = FOFInflector::singularize($view); } elseif (in_array($task, array('browse'))) { $view = FOFInflector::pluralize($view); } $this->input->set('view', $view); $this->input->set('task', $task); $config = $this->config; $config['input'] = $this->input; $controller = FOFController::getTmpInstance($option, $view, $config); $status = $controller->execute($task); if (!$this->onAfterDispatch()) { JResponse::setHeader('Status', '403 Forbidden', true); if (version_compare(JVERSION, '3.0', 'ge')) { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } else { return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } } $format = $this->input->get('format', 'html', 'cmd'); $format = empty($format) ? 'html' : $format; if ($format == 'html') { // In HTML views perform a redirection if ($controller->redirect()) { return; } } else { // In non-HTML views just exit the application with the proper HTTP headers if ($controller->hasRedirect()) { $headers = JResponse::sendHeaders(); jexit(); } } }