Exemplo n.º 1
0
 /**
  * Converts the non sef links to SEF links when necessary
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public static function _($url, $xhtml = true, $ssl = null, $search = false, $isCanonical = false)
 {
     static $cache = array();
     static $itemIds = array();
     // Cache index
     $key = $url . (int) $xhtml . (int) $isCanonical;
     // If the url has already loaded previously, do not need to load it again.
     if (isset($cache[$key])) {
         return $cache[$key];
     }
     $config = EB::config();
     $app = JFactory::getApplication();
     $input = $app->input;
     // Parse the url
     parse_str($url, $query);
     // Get the view portion from the query string
     $view = isset($query['view']) ? $query['view'] : 'latest';
     $layout = isset($query['layout']) ? $query['layout'] : null;
     $itemId = isset($query['Itemid']) ? $query['Itemid'] : '';
     $task = isset($query['task']) ? $query['task'] : '';
     $id = isset($query['id']) ? $query['id'] : null;
     // Get routing behavior
     $behavior = $config->get('main_routing', 'default');
     $dropSegment = false;
     // Legacy settings for "use current active menu"
     if ($behavior == 'currentactive' && !$isCanonical) {
         // Get the current active menu
         $active = $app->getMenu()->getActive();
         if ($active) {
             $itemId = $active->id;
         }
     }
     // Legacy settings for "use menu id"
     if ($behavior == 'menuitemid' && !$isCanonical) {
         // Get the menu id from the settings
         $itemId = $config->get('main_routing_itemid');
     }
     // Default routing behavior
     if ($behavior == 'default') {
         // The default menu in the event we can't find anything for the url
         $defaultMenu = EBR::getMenus('latest');
         // Entry view needs to be treated differently.
         if ($view == 'entry') {
             // Respect which settings the user configured
             $respectView = $config->get('main_routing_entry');
             // Entry view has higher precedence over all
             $menu = EBR::getMenus('entry', 'entry', $id);
             if ($menu) {
                 $dropSegment = true;
             } else {
                 // Get the post data from the cache
                 $postCache = EB::cache();
                 $post = $postCache->get($id, 'post');
                 // Get the category the post is created in
                 if ($respectView == 'categories') {
                     $menu = EBR::getMenus('categories', 'listings', $post->category_id);
                 }
                 if ($respectView == 'blogger') {
                     $menu = EBR::getMenus('blogger', 'listings', $post->created_by);
                 }
                 if ($respectView == 'teamblog' && $post->source_type == EASYBLOG_POST_SOURCE_TEAM) {
                     $menu = EBR::getMenus('teamblog', 'listings', $post->source_id);
                 }
             }
         }
         // Get the default menu that the current view should use
         if ($view != 'entry') {
             $menu = EBR::getMenus($view);
             // If there's a layout an id accompanying the view, we should search for a menu to a single item layout.
             if ($layout && $id) {
                 $itemMenu = EBR::getMenus($view, $layout, $id);
                 // If there's a menu item created on the site associated with this item, we need to drop the segment
                 // to avoid redundant duplicate urls.
                 // E.g:
                 // menu alias = test
                 // post alias = test
                 // result = /test/test
                 if ($itemMenu) {
                     $menu = $itemMenu;
                     $dropSegment = true;
                 }
             } else {
                 if ($layout) {
                     // this section here is to cater a view + layout page.
                     // e.g dashboard/entries
                     $itemMenu = EBR::getMenus($view, $layout);
                     if ($itemMenu) {
                         $menu = $itemMenu;
                         $dropSegment = true;
                     }
                 }
             }
             // If there is a menu created for the view, we just drop the segment
             if (!$layout && !$id && $menu) {
                 $dropSegment = true;
             }
         }
         // If we still cannot find any menu, use the default menu :(
         if (!isset($menu) || !$menu) {
             $menu = $defaultMenu;
         }
         // Only proceed when there is at least 1 menu created on the site for EasyBlog
         if (isset($menu) && $menu) {
             $itemId = $menu->id;
         }
         // If this is a task, we shouldn't drop any segments at all
         if ($task) {
             $dropSegment = false;
         }
     }
     // If there's an item id located for the url, we need to intelligently apply it into the url.
     if ($itemId) {
         // We need to respect dropSegment to avoid duplicated menu and view name.
         // For instance, if a menu is called "categories" which links to the categories page, it would be /categories/categories
         if ($dropSegment && EBR::isSefEnabled()) {
             $url = 'index.php?Itemid=' . $itemId;
         } else {
             $url = EBR::appendItemIdToQueryString($url, $itemId);
         }
     }
     $cache[$key] = JRoute::_($url, $xhtml, $ssl);
     return $cache[$key];
 }