/**
  * Parses $token->getTextToBeParsed() according to the following syntax rule:
  *      UrlPath ::= ["/"][PageUrlKey][QuerySeparator Parameters][Suffix]["/"] .
  *
  * Uses $this->_schema URL settings (m_seo_schema_XXX tables), puts all found matches into $this->_parsedUrls.
  *
  * @param Mana_Seo_Model_ParsedUrl $token
  * @return bool
  */
 protected function _parseUrlPath($token)
 {
     $pageToken = clone $token->setSlash(substr($token->getTextToBeParsed(), -1) == '/' ? '/' : '')->setTextToBeParsed(rtrim($token->getTextToBeParsed(), '/'));
     /* @var $mbstring Mana_Core_Helper_Mbstring */
     $mbstring = Mage::helper('mana_core/mbstring');
     // split by "/", split suffix
     $separator = $this->_schema->getQuerySeparator();
     $suffixes = $this->_scanSuffixes($pageToken, $this->_getAllSuffixes($pageToken));
     $tokens = $this->_scanUntilSeparatorOrSuffix($suffixes, $separator);
     // get all valid page URL key and suffix combinations (including home page) based on given URL path
     if ($tokens = $this->_getPageUrlKeysAndRemoveSuffixes($tokens)) {
         foreach ($tokens as $token) {
             $this->_setPage($token);
             if ($this->_parseParameters($token)) {
                 return true;
             }
         }
     }
     // home page
     if ($mbstring->startsWith($separator, '/') && $mbstring->strlen($separator) > 1 && $mbstring->startsWith($pageToken->getTextToBeParsed(), $mbstring->substr($separator, 1))) {
         $pageToken->setTextToBeParsed($mbstring->substr($pageToken->getTextToBeParsed(), $mbstring->strlen($separator) - 1));
     }
     if ($tokens = $this->_scanSuffixes($pageToken, $this->_getSuffixesByType($token, 'home_page'))) {
         foreach ($tokens as $token) {
             $this->_setHomePage($token);
             if ($this->_parseParameters($token)) {
                 return true;
             }
         }
     }
     return false;
 }
示例#2
0
 public function getRoutePath($routeParams = array())
 {
     if ($this->_pageUrlKey === null) {
         if ($this->_query) {
             $this->setData('query_params', $this->_query);
         }
         return parent::getRoutePath($routeParams);
     }
     /* @var $core Mana_Core_Helper_Data */
     $core = Mage::helper('mana_core');
     if (!$this->hasData('route_path')) {
         $query = $this->_query;
         if ($query !== null) {
             if (is_string($query)) {
                 $this->setQuery($query);
             } elseif (is_array($query)) {
                 $this->setQueryParams($query, !empty($routeParams['_current']));
             }
             if ($query === false) {
                 $this->setQueryParams(array());
             }
         }
         $queryParams = $this->getQueryParams();
         $seoParams = array();
         foreach ($this->getQueryParams() as $key => $value) {
             $path = false;
             if ($key == 'p' && $value == 1) {
                 unset($queryParams[$key]);
                 continue;
             }
             if ($value !== null) {
                 if ($url = $this->_getParameterUrl($key)) {
                     $position = $url->getPosition();
                     $attribute_id = $url->getAttributeId();
                     $category_id = null;
                     switch ($url->getType()) {
                         case Mana_Seo_Model_ParsedUrl::PARAMETER_ATTRIBUTE:
                             $path = $this->_generateAttributeParameter($url, $value);
                             break;
                         case Mana_Seo_Model_ParsedUrl::PARAMETER_CATEGORY:
                             list($path, $category_id) = $this->_generateCategoryParameter($url, $value);
                             break;
                         case Mana_Seo_Model_ParsedUrl::PARAMETER_PRICE:
                             $path = $this->_generatePriceParameter($url, $value);
                             break;
                         case Mana_Seo_Model_ParsedUrl::PARAMETER_TOOLBAR:
                             $path = $this->_generateToolbarParameter($url, $value);
                             break;
                         default:
                             throw new Exception('Not implemented');
                     }
                 }
             }
             if ($path) {
                 $seoParams[$key] = compact('path', 'position', 'attribute_id', 'category_id');
                 unset($queryParams[$key]);
             }
         }
         $this->_redirectToSubcategory($seoParams);
         uasort($seoParams, array($this, '_compareSeoParams'));
         $routePath = $this->_encode($this->_pageUrlKey);
         $first = true;
         foreach ($seoParams as $path) {
             if ($first) {
                 if ($routePath) {
                     $routePath .= $this->_schema->getQuerySeparator();
                 }
                 $first = false;
             } else {
                 $routePath .= $this->_schema->getParamSeparator();
             }
             $routePath .= $path['path'];
         }
         if ($routePath) {
             $routePath .= $core->addDotToSuffix($this->_suffix);
         }
         $this->setData('query_params', $queryParams);
         $this->setData('route_path', $routePath);
     }
     return $this->_getData('route_path');
 }