Exemplo n.º 1
0
 public static function noControllerResponse(XenForo_RouteMatch $routeMatch, Zend_Controller_Request_Http $request)
 {
     self::sendErrorPageHeaders();
     if (XenForo_Application::debugMode()) {
         echo 'Failed to get controller response and reroute to error handler (' . $routeMatch->getControllerName() . '::action' . $routeMatch->getAction() . ')';
         if ($request->getParam('_exception')) {
             echo self::getExceptionTrace($request->getParam('_exception'));
         }
     } else {
         echo self::_getPhrasedTextIfPossible('An unexpected error occurred. Please try again later.', 'unexpected_error_occurred');
     }
 }
 /**
  * Executes the controller dispatch loop.
  *
  * @param XenForo_RouteMatch $routeMatch
  *
  * @return XenForo_ControllerResponse_Abstract|null Null will only occur if error handling is broken
  */
 public function dispatch(XenForo_RouteMatch &$routeMatch)
 {
     $reroute = array('controllerName' => $routeMatch->getControllerName(), 'action' => $routeMatch->getAction());
     $allowReroute = true;
     do {
         if (isset($reroute['path'])) {
             $routeMatch = $this->route($reroute['path']);
             $reroute = array('controllerName' => $routeMatch->getControllerName(), 'action' => $routeMatch->getAction());
         }
         $controllerResponse = null;
         $controllerName = $reroute['controllerName'];
         $action = str_replace(array('-', '/'), ' ', strtolower($reroute['action']));
         $action = str_replace(' ', '', ucwords($action));
         if ($action === '') {
             $action = 'Index';
         }
         $reroute = false;
         $controller = $this->_getValidatedController($controllerName, $action, $routeMatch);
         if ($controller) {
             try {
                 try {
                     $controller->preDispatch($action, $controllerName);
                     $controllerResponse = $controller->{'action' . $action}();
                 } catch (XenForo_ControllerResponse_Exception $e) {
                     $controllerResponse = $e->getControllerResponse();
                 }
                 $controller->postDispatch($controllerResponse, $controllerName, $action);
                 $reroute = $this->_handleControllerResponse($controllerResponse, $controllerName, $action);
             } catch (Exception $e) {
                 // this is a bit hacky, but it's a selective catch so it's a strange case
                 if ($e instanceof XenForo_Exception && $e->isUserPrintable()) {
                     $controllerResponse = $this->_getErrorResponseFromException($e);
                     $controller->postDispatch($controllerResponse, $controllerName, $action);
                 } else {
                     if (!$allowReroute) {
                         break;
                     }
                     $reroute = $this->_rerouteServerError($e);
                     $allowReroute = false;
                     XenForo_Error::logException($e);
                 }
             }
             $responseType = $controller->getResponseType();
             $this->_dependencies->mergeViewStateChanges($controller->getViewStateChanges());
         } else {
             if (!$allowReroute) {
                 break;
             }
             $reroute = $this->_rerouteNotFound($controllerName, $action);
             $allowReroute = false;
         }
     } while ($reroute);
     if ($controllerResponse instanceof XenForo_ControllerResponse_Abstract) {
         $controllerResponse->controllerName = $controllerName;
         $controllerResponse->controllerAction = $action;
     }
     return $controllerResponse;
 }
Exemplo n.º 3
0
 /**
  * @return bdSocialShare_Shareable_Abstract
  */
 public function getShareableForRouteMatchAndRequest(XenForo_RouteMatch $routeMatch, Zend_Controller_Request_Http $request)
 {
     $shareable = null;
     switch ($routeMatch->getControllerName()) {
         case 'NFLJ_Showcase_ControllerPublic_Index':
         case 'NFLJ_Showcase_ControllerPublic_Showcase':
             $itemId = $request->getParam('item_id');
             if (!empty($itemId)) {
                 $shareable = bdSocialShare_Shareable_NFLJ_Showcase_Item::createFromId($itemId);
             }
             break;
         case 'sonnb_XenGallery_ControllerPublic_XenGallery_Photo':
             $contentId = $request->getParam('content_id');
             if (!empty($contentId)) {
                 $shareable = bdSocialShare_Shareable_sonnb_XenGallery_Photo::createFromId($contentId);
             }
             break;
         case 'sonnb_XenGallery_ControllerPublic_XenGallery_Video':
             $contentId = $request->getParam('content_id');
             if (!empty($contentId)) {
                 $shareable = bdSocialShare_Shareable_sonnb_XenGallery_Video::createFromId($contentId);
             }
             break;
         case 'XenForo_ControllerPublic_Post':
             $postId = $request->getParam('post_id');
             if (!empty($postId)) {
                 $shareable = bdSocialShare_Shareable_Post::createFromId($postId);
             }
             break;
         case 'XenForo_ControllerPublic_ProfilePost':
             $profilePostId = $request->getParam('profile_post_id');
             if (!empty($profilePostId)) {
                 $shareable = bdSocialShare_Shareable_ProfilePost::createFromId($profilePostId);
             }
             break;
         case 'XenForo_ControllerPublic_Thread':
             $threadId = $request->getParam('thread_id');
             if (!empty($threadId)) {
                 $thread = $this->getModelFromCache('XenForo_Model_Thread')->getThreadById($threadId);
                 if (!empty($thread)) {
                     $shareable = bdSocialShare_Shareable_Post::createFromId($thread['first_post_id']);
                 }
             }
             break;
         case 'XenGallery_ControllerPublic_Media':
             $mediaId = $request->getParam('media_id');
             if (!empty($mediaId)) {
                 $shareable = bdSocialShare_Shareable_XenGallery_Media::createFromId($mediaId);
             }
             break;
         case 'XenResource_ControllerPublic_Resource':
             $resourceId = $request->getParam('resource_id');
             if (!empty($resourceId)) {
                 $shareable = bdSocialShare_Shareable_XenResource_Resource::createFromId($resourceId);
             }
             break;
     }
     return $shareable;
 }
Exemplo n.º 4
0
 protected function _actionGetParseLink_getControllerResponse($link, Zend_Controller_Request_Http $request, XenForo_RouteMatch $routeMatch)
 {
     switch ($routeMatch->getControllerName()) {
         case 'XenForo_ControllerPublic_Forum':
             $nodeId = $request->getParam('node_id');
             if (empty($nodeId)) {
                 $nodeName = $request->getParam('node_name');
                 if (!empty($nodeName)) {
                     /* @var $nodeModel XenForo_Model_Node */
                     $nodeModel = $this->getModelFromCache('XenForo_Model_Node');
                     $node = $nodeModel->getNodeByName($nodeName, 'Forum');
                     if (!empty($node)) {
                         $nodeId = $node['node_id'];
                     }
                 }
             }
             if (!empty($nodeId)) {
                 $this->_request->setParam('forum_id', $nodeId);
             }
             return $this->responseReroute('bdApi_ControllerApi_Thread', 'get-index');
         case 'XenForo_ControllerPublic_Thread':
             $threadId = $request->getParam('thread_id');
             if (!empty($threadId)) {
                 $this->_request->setParam('thread_id', $threadId);
                 $linkFragment = parse_url($link, PHP_URL_FRAGMENT);
                 if (!empty($linkFragment) and preg_match('#^post-(?<post_id>\\d+)$#', $linkFragment, $fragment)) {
                     $this->_request->setParam('page_of_post_id', $fragment['post_id']);
                 }
                 return $this->responseReroute('bdApi_ControllerApi_Post', 'get-index');
             }
             break;
         case 'XenForo_ControllerPublic_Post':
             $postId = $request->getParam('post_id');
             if (!empty($postId)) {
                 $this->_request->setParam('page_of_post_id', $postId);
                 return $this->responseReroute('bdApi_ControllerApi_Post', 'get-index');
             }
             break;
     }
     return null;
 }