Пример #1
0
 public function parse()
 {
     // Stop if SEO is disabled
     if (!$this->config->get('config_seo_url')) {
         return;
     }
     // Attach the URL builder
     $this->url->addRewrite($this);
     $query_string = $this->uri->getQuery();
     $route = str_replace($this->url->getFullUrl(), '', rawurldecode($this->uri->toString()));
     $route = str_replace('?' . $query_string, '', $route);
     // Don't parse if home page
     if (empty($route)) {
         $this->request->get['route'] = 'common/home';
         return;
     }
     // Don't parse if route is already set
     if (!empty($this->request->get['route'])) {
         // non-SEO to SEO URLs Redirection
         if ($this->config->get('config_seo_nonseo_red')) {
             $this->checkNonseoRedirection($this->request->get['route']);
         }
         return;
     }
     // www Redirection
     if ($this->config->get('config_seo_www_red')) {
         $this->checkWwwRedirection();
     }
     // non-SEO variables
     if (!empty($query_string)) {
         $query_array = $this->uri->getQuery(true);
         $this->parseNonSeoVariables($query_array);
         if ($this->config->get('config_seo_canonical')) {
             $this->document->addLink($this->url->getDomain() . $route, 'canonical');
         }
     }
     $seo_url = str_replace('index.php/', '', $route);
     // Add language code to URL
     $is_lang_home = false;
     if ($this->config->get('config_seo_lang_code')) {
         $seo_url = ltrim($seo_url, '/');
         if ($seo_url == $this->session->data['language']) {
             $is_lang_home = true;
         }
         $seo_url = ltrim($seo_url, $this->session->data['language']);
         $seo_url = ltrim($seo_url, '/');
     }
     // URLs are stored without suffix in database
     if ($this->config->get('config_seo_suffix')) {
         $seo_url = rtrim($seo_url, '.html');
     }
     $parts = explode('/', $seo_url);
     // remove any empty arrays from trailing
     if (utf8_strlen(end($parts)) == 0) {
         array_pop($parts);
     }
     $seo = new Seo($this->registry);
     foreach ($parts as $part) {
         $query = $seo->getAliasQuery($part);
         if (!empty($query)) {
             $url = explode('=', $query);
             switch ($url[0]) {
                 case 'product_id':
                     $this->request->get['product_id'] = $url[1];
                     if (!$this->config->get('config_seo_category')) {
                         $categories = array();
                         $category_id = $seo->getCategoryIdBySortOrder($url[1]);
                         if (!is_null($category_id)) {
                             $categories = $seo->getParentCategoriesIds($category_id);
                             $categories[] = $category_id;
                         }
                         if (!empty($categories)) {
                             $this->request->get['path'] = implode('_', $categories);
                         }
                     }
                     break;
                 case 'category_id':
                     if ($this->config->get('config_seo_category') == 'last') {
                         $categories = $seo->getParentCategoriesIds($url[1]);
                         $categories[] = $url[1];
                         if (!empty($categories)) {
                             $this->request->get['path'] = implode('_', $categories);
                         }
                     } else {
                         if (!isset($this->request->get['path'])) {
                             $this->request->get['path'] = $url[1];
                         } else {
                             $this->request->get['path'] .= '_' . $url[1];
                         }
                     }
                     break;
                 case 'manufacturer_id':
                     $this->request->get['manufacturer_id'] = $url[1];
                     break;
                 case 'information_id':
                     $this->request->get['information_id'] = $url[1];
                     break;
                 default:
                     $this->request->get['route'] = $query;
                     break;
             }
         } else {
             if ($is_lang_home) {
                 $this->request->get['route'] = 'common/home';
                 break;
             } else {
                 if (in_array($seo_url, $this->getSeoRouteList())) {
                     $this->request->get['route'] = $seo_url;
                     break;
                 } else {
                     $this->request->get['route'] = 'error/not_found';
                     break;
                 }
             }
         }
     }
     if (!isset($this->request->get['route'])) {
         if (isset($this->request->get['product_id'])) {
             $this->request->get['route'] = 'product/product';
         } elseif (isset($this->request->get['path'])) {
             $this->request->get['route'] = 'product/category';
         } elseif (isset($this->request->get['manufacturer_id'])) {
             $this->request->get['route'] = 'product/manufacturer/info';
         } elseif (isset($this->request->get['information_id'])) {
             $this->request->get['route'] = 'information/information';
         }
     }
     unset($this->request->get['_route_']);
     // For B/C purpose
 }