示例#1
0
 public static function preExecute($actions)
 {
     $request = $actions->getRequest();
     // Figure out where we are all over again, because there seems to be no clean way
     // to get the same controller-free URL that the routing engine gets. TODO:
     // ask Fabien how we can do that.
     $uri = $actions->getRequest()->getUri();
     $uriPrefix = $actions->getRequest()->getUriPrefix();
     $uri = substr($uri, strlen($uriPrefix));
     if (preg_match("/^\\/[^\\/]+\\.php(.*)\$/", $uri, $matches)) {
         $uri = $matches[1];
     }
     // This will quickly fetch a result that was already cached when we
     // ran through the routing table (unless we hit the routing table cache,
     // in which case we're looking it up for the first time, also OK)
     $page = aPageTable::getMatchingEnginePage($uri, $remainder);
     if (!$page) {
         throw new sfException('Attempt to access engine action without a page');
     }
     $page = aPageTable::retrieveByIdWithSlots($page->id);
     // We want to do these things the same way executeShow would
     aTools::validatePageAccess($actions, $page);
     aTools::setPageEnvironment($actions, $page);
     // Convenient access to the current page for the subclass
     $actions->page = $page;
 }
示例#2
0
 public function executeShow(sfWebRequest $request)
 {
     $slug = $this->getRequestParameter('slug');
     if (substr($slug, 0, 1) !== '/') {
         $slug = "/{$slug}";
     }
     $page = aPageTable::retrieveBySlugWithSlots($slug);
     aTools::validatePageAccess($this, $page);
     aTools::setPageEnvironment($this, $page);
     $this->page = $page;
     $this->setTemplate($page->template);
     return 'Template';
 }
示例#3
0
 /**
  * Poor man's multiple inheritance. This allows us to subclass an existing
  * actions class in order to create an engine version of it. See aEngineActions
  * for the call to add to your own preExecute method
  * @param mixed $actions
  */
 public static function preExecute($actions)
 {
     $request = $actions->getRequest();
     // Figure out where we are all over again, because there seems to be no clean way
     // to get the same controller-free URL that the routing engine gets. TODO:
     // ask Fabien how we can do that.
     $uri = urldecode($actions->getRequest()->getUri());
     $rr = preg_quote(sfContext::getInstance()->getRequest()->getRelativeUrlRoot(), '/');
     if (preg_match("/^(?:https?:\\/\\/[^\\/]+)?{$rr}(?:\\/[^\\/]+\\.php)?(.*)\$/", $uri, $matches)) {
         $uri = $matches[1];
     } else {
         throw new sfException("Unable to parse engine URL {$uri}");
     }
     // This will quickly fetch a result that was already cached when we
     // ran through the routing table (unless we hit the routing table cache,
     // in which case we're looking it up for the first time, also OK)
     $page = aPageTable::getMatchingEnginePageInfo($uri, $remainder);
     if (!$page) {
         throw new sfException('Attempt to access engine action without a page');
     }
     $page = aPageTable::retrieveByIdWithSlots($page['id']);
     // We want to do these things the same way executeShow would
     aTools::validatePageAccess($actions, $page);
     aTools::setPageEnvironment($actions, $page);
     // Convenient access to the current page for the subclass
     $actions->page = $page;
     // If your engine supports allowing the user to choose from several page types
     // to distinguish different ways of using your engine, then you'll need to
     // return the template name from your show and index actions (and perhaps
     // others as appropriate). You can pull that information straight from
     // $this->page->template, or you can take advantage of $this->pageTemplate which
     // is ready to return as the result of an action (default has been changed
     // to Success, other values have their first letter capitalized)
     $templates = aTools::getTemplates();
     // originalTemplate is what's in the template field of the page, except that
     // nulls and empty strings from pre-1.5 Apostrophe have been converted to 'default'
     // for consistency
     $actions->originalTemplate = $page->template;
     if (!strlen($actions->originalTemplate)) {
         // Compatibility with 1.4 templates and reasonable Symfony expectations
         $actions->originalTemplate = 'default';
     }
     // pageTemplate is suitable to return from an action. 'default' becomes 'Success'
     // (the Symfony standard for a "normal" template's suffix) and other values have
     // their first letter capitalized
     if ($actions->originalTemplate === 'default') {
         $actions->pageTemplate = 'Success';
     } else {
         $actions->pageTemplate = ucfirst($actions->originalTemplate);
     }
 }
 public function executeShow(sfWebRequest $request)
 {
     $slug = $this->getRequestParameter('slug');
     if (substr($slug, 0, 1) !== '/') {
         $slug = "/{$slug}";
     }
     $page = aPageTable::retrieveBySlugWithSlots($slug);
     if (!$page) {
         $redirect = Doctrine::getTable('aRedirect')->findOneBySlug($slug);
         if ($redirect) {
             $page = aPageTable::retrieveByIdWithSlots($redirect->page_id);
             return $this->redirect($page->getUrl(), 301);
         }
     }
     aTools::validatePageAccess($this, $page);
     aTools::setPageEnvironment($this, $page);
     $this->page = $page;
     $this->setTemplate($page->template);
     return 'Template';
 }
示例#5
0
 /**
  * DOCUMENT ME
  * @param sfWebRequest $request
  * @return mixed
  */
 public function executeShow(sfWebRequest $request)
 {
     $slug = $this->getRequestParameter('slug');
     // remove trailing slashes from $slug
     $pattern = '/\\/$/';
     if (preg_match($pattern, $slug) && $slug != '/') {
         sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
         $new_slug = preg_replace($pattern, '', $slug);
         $slug = addcslashes($slug, '/');
         $new_uri = preg_replace('/' . $slug . '/', $new_slug, $request->getUri());
         $this->redirect($new_uri);
     }
     if (substr($slug, 0, 1) !== '/') {
         $slug = "/{$slug}";
     }
     $page = aPageTable::retrieveBySlugWithSlots($slug);
     if (!$page) {
         $redirect = Doctrine::getTable('aRedirect')->findOneBySlug($slug);
         if ($redirect) {
             $page = aPageTable::retrieveByIdWithSlots($redirect->page_id);
             return $this->redirect($page->getUrl(), 301);
         }
     }
     aTools::validatePageAccess($this, $page);
     aTools::setPageEnvironment($this, $page);
     $this->page = $page;
     $this->setTemplate($page->template);
     $tagstring = implode(',', $page->getTags());
     if (strlen($tagstring)) {
         $this->getResponse()->addMeta('keywords', htmlspecialchars($tagstring));
     }
     if (strlen($page->getMetaDescription())) {
         $this->getResponse()->addMeta('description', $page->getMetaDescription());
     }
     return 'Template';
 }