예제 #1
0
 public function doCanonicalRedirect($pageUrl)
 {
     $this->_redirector->setCode(301);
     if (Tools_System_Tools::getUrlHost($_SERVER['HTTP_HOST']) != Tools_System_Tools::getUrlHost($this->_website->getUrl())) {
         $this->_redirector->gotoUrl($this->_website->getUrl() . $pageUrl);
     }
     if (in_array($pageUrl, $this->_canonicMap)) {
         $this->_redirector->gotoUrl($this->_website->getUrl());
     }
 }
예제 #2
0
 public function redirectsAction()
 {
     $redirectForm = new Application_Form_Redirect();
     $pageMapper = Application_Model_Mappers_PageMapper::getInstance();
     $redirectMapper = Application_Model_Mappers_RedirectMapper::getInstance();
     $redirectForm->setToasterPages($pageMapper->fetchIdUrlPairs());
     $redirectForm->setDefault('fromUrl', 'http://');
     if (!$this->getRequest()->isPost()) {
         $this->view->redirects = $redirectMapper->fetchRedirectMap();
     } else {
         if ($redirectForm->isValid($this->getRequest()->getParams())) {
             $data = $redirectForm->getValues();
             $redirect = new Application_Model_Models_Redirect();
             $fromUrlPath = Tools_System_Tools::getUrlPath($data['fromUrl']);
             $inDbValidator = new Zend_Validate_Db_NoRecordExists(array('table' => 'redirect', 'field' => 'from_url'));
             if (!$inDbValidator->isValid($fromUrlPath)) {
                 $this->_helper->response->fail(implode('<br />', $inDbValidator->getMessages()));
                 exit;
             }
             $redirect->setFromUrl(Tools_System_Tools::getUrlPath($data['fromUrl']));
             $redirect->setDomainFrom(Tools_System_Tools::getUrlScheme($data['fromUrl']) . '://' . Tools_System_Tools::getUrlHost($data['fromUrl']) . '/');
             if (intval($data['toUrl'])) {
                 $page = $pageMapper->find($data['toUrl']);
                 $redirect->setDomainTo($this->_helper->website->getUrl());
                 $redirect->setToUrl($page->getUrl());
                 $redirect->setPageId($page->getId());
             } else {
                 $urlValidator = new Validators_UrlRegex();
                 if (!$urlValidator->isValid($data['toUrl'])) {
                     $this->_helper->response->fail('External url <br />' . implode('<br />', $urlValidator->getMessages()));
                     exit;
                 }
                 $redirect->setDomainTo(Tools_System_Tools::getUrlScheme($data['toUrl']) . '://' . Tools_System_Tools::getUrlHost($data['toUrl']) . '/');
                 $redirect->setToUrl(Tools_System_Tools::getUrlPath($data['toUrl']));
                 $redirect->setPageId(null);
             }
             $redirectMapper->save($redirect);
             $this->_helper->cache->clean('toaster_301redirects', '301redirects');
             $this->_helper->response->success('Redirect saved');
         } else {
             $this->_helper->response->fail(Tools_Content_Tools::proccessFormMessagesIntoHtml($redirectForm->getMessages(), get_class($redirectForm)));
             exit;
         }
     }
     $this->view->helpSection = '301s';
     $this->view->form = $redirectForm;
 }