Beispiel #1
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  *
  * @param UrlManager $manager the URL manager
  * @param Request    $request the request component
  *
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     echo '<pre>==== BeeUrlRule ===<br>';
     print_r('PathInfo = ' . $request->getPathInfo());
     echo '<br>';
     print_r('Url = ' . $request->getUrl());
     echo '<br>======================</pre>';
     $items = Yii::$app->getSiteMenu()->getMenu();
     // Parse SEF URL
     if (Yii::$app->urlManager->enablePrettyUrl == TRUE) {
         $route = $request->getPathInfo();
         /*
          *  Пошаговый парсинг меню
          *  Последне найденный записывается в переменную $found
          */
         $found = null;
         foreach ($items as $item) {
             if ($item->path && BeeString::strpos($route, $item->path) === 0) {
                 // Exact route match. We can break iteration because exact item was found.
                 if ($item->path == $route) {
                     $found = $item;
                     break;
                 }
                 // Partial route match. Item with highest level takes priority.
                 if (!$found || $found->level < $item->level) {
                     $found = $item;
                 }
             }
         }
         /*
          * Если мы нашли конечный пункт меню и его адрес полностью собпадает,
          * то формируем и возвращаем ссылку на этот пункт меню
          * иначе берем компонент в @found и продолжаем поиск уже по этому компоненту.
          */
         if (BeeString::strpos($route, $found->path) === 0) {
             $extAction = $found->query[0];
             // site/index
             $url = ['path' => $found->query['path'], 'id' => $found->query['id']];
             return [$extAction, $url];
         } else {
             echo '<pre>';
             print_r('------------------- Еще не все распарсил -------------------');
             echo '</pre>';
         }
         //echo '<br><br><br><pre>';
         //print_r($found);
         //echo '</pre><br><br><br>';
         echo '<br><pre>Сделать парсинг для страниц, отсутствующих в меню';
         echo '<br>======================</pre>';
     } else {
         // Parse RAW URL
         return FALSE;
     }
     echo '<pre><<< Стандартный парсино Yii >>></pre>';
     return FALSE;
     //return ['site/about', []];
 }
Beispiel #2
0
 /**
  * Function to convert a sef route to an internal URI
  *
  * @param   JUri &$uri The sef URI
  *
  * @return  string  Internal URI
  *
  * @since   3.2
  */
 protected function parseSefRoute(&$uri)
 {
     if (!class_exists(Menu)) {
         $menu = new Menu();
     }
     $items = $menu->getMenu();
     // Get menu items
     $route = Yii::$app->getRequest()->pathInfo;
     // $uri->getPath(); // Get path link
     $vars = $uri->getQuery(TRUE);
     // Get the variables from the uri
     $found = FALSE;
     $lang_tag = Yii::$app->language;
     // Remove the suffix
     if (Yii::$app->urlManager->enablePrettyUrl == TRUE) {
         if (Yii::$app->urlManager->suffix) {
             $suffix = Yii::$app->urlManager->suffix;
             $route = str_replace($suffix, '', $route);
         }
     }
     // Handle an empty URL (special case)
     if (empty($route)) {
         // If route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately
         if (isset($vars['option']) || isset($vars['Itemid'])) {
             return $this->parseRawRoute($uri);
         }
         $item = $menu->getHomeID();
         // If user not allowed to see default menu item then avoid notices
         if (is_object($item)) {
             // Set the information in the request
             $vars = $item->query;
             // Get the itemid
             $vars['Itemid'] = $item->menu_id;
             // Set the active menu item
             $menu->setActive($vars['Itemid']);
         }
         return $vars;
     }
     // Iterate through all items and check route matches.
     foreach ($items as $item) {
         if ($item->path && BeeString::strpos($route . '/', $item->path . '/') === 0 && $item->menutype_name != 'menulink') {
             // Usual method for non-multilingual site.
             if (Yii::$app->language === Yii::$app->sourceLanguage) {
                 // Exact route match. We can break iteration because exact item was found.
                 if ($item->path == $route) {
                     $found = $item;
                     break;
                 }
                 // Partial route match. Item with highest level takes priority.
                 if (!$found || $found->level < $item->level) {
                     $found = $item;
                 }
             } else {
                 // Exact route match.
                 if ($item->path == $route) {
                     $found = $item;
                     // Break iteration only if language is matched.
                     if ($item->language_local == $lang_tag) {
                         break;
                     }
                 }
                 // Partial route match. Item with highest level or same language takes priority.
                 if (!$found || $found->level < $item->level || $item->language_local == $lang_tag) {
                     $found = $item;
                 }
             }
         }
     }
     if (!$found) {
         if (empty($route)) {
             $found = $menu->getHomeID();
         } else {
             return [];
         }
     } else {
         $route = substr($route, strlen($found->path));
         if ($route) {
             $route = substr($route, 1);
         }
     }
     $vars['Itemid'] = $found->menu_id;
     $vars['option'] = $found->ext_name;
     // Set the active menu item
     if (isset($vars['Itemid'])) {
         $menu->setActive($vars['Itemid']);
     }
     // Set the variables
     $this->setVars($vars);
     // Parse the component route
     if (!empty($route) && isset($this->_vars['option'])) {
         $segments = explode('/', $route);
         // Parse the application route
         if (empty($segments[0])) {
             array_shift($segments);
         }
         // Handle component	route
         $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->_vars['option']);
         if (count($segments)) {
             $crouter = $this->getComponentRouter($component);
             echo '<br><br><br><pre>';
             print_r($crouter);
             echo '</pre>';
             return [];
             $vars = $crouter->parse($segments);
             $this->setVars($vars);
         }
     } else {
         // Set active menu item
         if ($item = $menu->getActive()) {
             $vars = $item->query;
         }
     }
     return $vars;
 }