Ejemplo n.º 1
0
 /**
  * Parse SEO URI for setRouteByPathInfo.
  *
  * @param uri
  * return string
  */
 public static function parseURI($uri)
 {
     global $config;
     if (!helper::inSeoMode()) {
         return $uri;
     }
     $categoryAlias = $config->seo->alias->category;
     $pageAlias = $config->seo->alias->page;
     $forumAlias = isset($config->seo->alias->forum) ? $config->seo->alias->forum : array();
     $methodAlias = $config->seo->alias->method;
     $params = array();
     if (strpos($uri, '_') !== false) {
         $uri = substr($uri, 0, strpos($uri, '_'));
     }
     /* Is there a pageID variable in the url?  */
     $pageID = 0;
     if (preg_match('/\\/p\\d+$/', $uri, $matches)) {
         $pageID = str_replace('/p', '', $matches[0]);
         // Get pageID thus the flowing logic can use it.
         $uri = str_replace($matches[0], '', $uri);
         // Remove the pageID part from the url.
     }
     /* Split uri to items and try to get module and params from it. */
     $items = explode('/', $uri);
     $module = $items[0];
     /* Use book instead of help. */
     if ($module == 'help') {
         $module = $items[0] = 'book';
     }
     /* There's no '/' in uri. */
     if (strpos($uri, '/') === false) {
         /* Use book instead of help. */
         if ($uri == 'help') {
             $uri = 'book';
         }
         if ($pageID and $module == 'blog' and count($items) == 1) {
             $params['category'] = 0;
             return seo::convertURI($module, 'index', $params, $pageID);
         }
         /* Not an alias, return directly. */
         if (empty($categoryAlias[$uri])) {
             return $uri;
         }
         /* The module is an alias of a category. */
         $module = $categoryAlias[$uri]->module;
         $params['category'] = $categoryAlias[$uri]->category;
         return seo::convertURI($module, 'browse', $params, $pageID);
     }
     /* Is the module an alias of a category? */
     if (isset($categoryAlias[$module])) {
         $category = $categoryAlias[$module]->category;
         // Get the category.
         $module = $categoryAlias[$module]->module;
         // Get the module of the alias category.
         /* If the first param is number, like article/123.html, should call view method. */
         if (is_numeric($items[1])) {
             $params['id'] = $items[1];
             return seo::convertURI($module, 'view', $params, $pageID);
         } else {
             if (!empty($items[1])) {
                 $viewparams = explode('-', $items[1]);
                 $id = end($viewparams);
             }
             if (is_numeric($id)) {
                 $params['id'] = $id;
                 return seo::convertURI($module, 'view', $params, $pageID);
             }
         }
         $params['category'] = $category;
         return seo::convertURI($module, 'browse', $params, $pageID);
     }
     //------------- The module is an system module-------------- */
     /* Is the module an alias of a page. */
     if ($module == 'page' && isset($pageAlias[$items[1]])) {
         $params['page'] = $items[1];
         return seo::convertURI($module, 'view', $params, $pageID);
     }
     if ($module == 'page' && !isset($pageAlias[$items[1]])) {
         $params['page'] = $items[1];
         return seo::convertURI($module, 'view', $params, $pageID);
     }
     if ($module == 'book' && count($items) > 2) {
         $uri = str_replace('/' . $items[1], '', $uri);
         $items[1] = $items[2];
     }
     if ($module == 'forum' && isset($pageAlias[$items[1]])) {
         $method = $methodAlias[$module]['browse'];
         return seo::convertURI($module, $method, $params, $pageID);
     }
     /*  If the first param is a category id, like news/c123.html. */
     if (preg_match('/^c\\d+$/', $items[1])) {
         $params['category'] = str_replace('c', '', $items[1]);
         $method = $methodAlias[$module]['browse'];
         return seo::convertURI($module, $method, $params, $pageID);
     }
     /* The first param is an object id. */
     if (is_numeric($items[1])) {
         $params['id'] = $items[1];
         $method = $methodAlias[$module]['view'];
         return seo::convertURI($module, $method, $params, $pageID);
     }
     $viewparams = explode('-', $items[1]);
     if (count($viewparams) > 1) {
         $id = end($viewparams);
         if (is_numeric($id)) {
             $params['id'] = $id;
             $method = $methodAlias[$module]['view'];
             return seo::convertURI($module, $method, $params, $pageID);
         }
     } else {
         /* The first param is a category alias. */
         $params['category'] = $items[1];
     }
     $method = isset($methodAlias[$module]['browse']) ? $methodAlias[$module]['browse'] : 'browse';
     return seo::convertURI($module, $method, $params, $pageID);
 }