示例#1
0
 /**
  * Method to set the simplelist alias
  *
  * @access public
  * @param string Simplelist category-alias
  */
 public function setIdByAlias($alias)
 {
     if (empty($this->_id)) {
         require_once JPATH_ADMINISTRATOR . '/components/com_simplelists/helpers/category.php';
         $this->setId(SimplelistsCategoryHelper::getId($alias));
     }
 }
示例#2
0
function SimplelistsBuildRoute(&$query)
{
    // Initialize the segments
    $segments = array();
    // Temporarily extract the Itemid
    if (isset($query['Itemid'])) {
        $Itemid = $query['Itemid'];
        unset($query['Itemid']);
    } else {
        $Itemid = null;
    }
    // If this is an item view and we have to hide it
    if (!empty($query['view']) && $query['view'] == 'item' && !empty($query['task']) && $query['task'] == 'hidden') {
        $segments[] = 'id,' . $query['id'];
        unset($query['view']);
        unset($query['task']);
        unset($query['tmpl']);
        unset($query['id']);
        return $segments;
    }
    // Get the menu items for this component
    $items = SimplelistsHelperRouter::getMenuItems();
    $params =& JComponentHelper::getParams('com_simplelists');
    // Break up the slug into numeric and alias values
    if (!empty($query['category_id'])) {
        $query['slug'] = $query['category_id'];
        if (strpos($query['category_id'], ':')) {
            list($query['category_id'], $query['alias']) = explode(':', $query['category_id'], 2);
        }
    }
    // If this is an item view
    if (!empty($query['view']) && $query['view'] == 'item') {
        $segments[] = 'item';
        $segments[] = $query['id'];
        if (isset($query['category_id'])) {
            foreach ($items as $item) {
                if (isset($item->query['view']) && isset($item->query['category_id']) && $item->query['view'] == 'items' && $query['category_id'] == $item->query['category_id']) {
                    $query['Itemid'] = $item->id;
                }
            }
        }
        unset($query['view']);
        unset($query['task']);
        unset($query['tmpl']);
        unset($query['id']);
        unset($query['slug']);
        unset($query['alias']);
        unset($query['category_id']);
        return $segments;
    }
    // Search for an appropriate menu item
    if (!empty($items) && isset($query['view'])) {
        foreach ($items as $item) {
            // Matching menu-items only makes sense if there is a "view" and an "id"
            if ($params->get('use_parent_url', 0) == 1) {
                if (isset($item->query['view']) && isset($item->query['category_id']) && isset($query['view']) && isset($query['category_id'])) {
                    // Whoever knows how to rewrite the following into something readable, wins my respect
                    if ($query['view'] == $item->query['view'] && $query['category_id'] == $item->query['category_id']) {
                        if (empty($query['layout'])) {
                            $query['Itemid'] = $item->id;
                            break;
                        } elseif (empty($query['layout']) && empty($item->query['layout'])) {
                            $query['Itemid'] = $item->id;
                            break;
                        } elseif (!empty($query['layout']) && !empty($item->query['layout']) && $query['layout'] == $item->query['layout']) {
                            $query['Itemid'] = $item->id;
                            break;
                        }
                    }
                }
            }
        }
    }
    // Set the alias if it is not present
    if (!empty($query['category_id']) && empty($query['alias'])) {
        require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_simplelists' . DS . 'helpers' . DS . 'category.php';
        $query['alias'] = SimplelistsCategoryHelper::getAlias($query['category_id']);
    }
    // Check if the router found an appropriate Itemid
    if (!isset($query['Itemid']) || !$query['Itemid'] > 0) {
        if ($params->get('sef_url') == 'slug' && !empty($query['slug'])) {
            $segments[] = $query['slug'];
        } elseif (!empty($query['alias'])) {
            $segments[] = $query['alias'];
        }
    }
    // Re-add the router if not existing yet
    if (!isset($query['Itemid']) && !empty($Itemid)) {
        $query['Itemid'] = $Itemid;
    }
    // Set the limitstart if needed
    if (isset($query['start'])) {
        $segments[] = (int) $query['start'];
        unset($query['start']);
    }
    // Unset all unneeded query-parts because they should be now either segmented or referenced from the Itemid
    unset($query['view']);
    unset($query['category_id']);
    unset($query['alias']);
    unset($query['slug']);
    unset($query['layout']);
    // Return the segments
    return $segments;
}
示例#3
0
 public function getUrl($needles = array())
 {
     // Construct the base-URL
     if (empty($needles['view'])) {
         $needles['view'] = 'items';
     }
     $url = 'index.php?option=com_simplelists&view=' . $needles['view'];
     // Determine the layout
     if (!empty($needles['layout'])) {
         $layout = $needles['layout'];
     } else {
         $layout = JRequest::getCmd('layout');
     }
     // Add the layout to the URL
     if (!empty($layout)) {
         $url .= '&layout=' . $layout;
     }
     // Determine the category alias
     if (!empty($needles['category_id'])) {
         if (!empty($needles['category_alias'])) {
             $category_alias = $needles['category_alias'];
         } else {
             require_once dirname(__FILE__) . DS . 'category.php';
             $category_alias = SimplelistsCategoryHelper::getAlias($category_id);
         }
         // Append the category ID (and optionally the category alias) to the URL
         if (!empty($category_alias)) {
             $url .= '&category_id=' . (int) $needles['category_id'] . ':' . $category_alias;
         } else {
             $url .= '&category_id=' . (int) $needles['category_id'];
         }
     }
     // Append the Itemid to the URL
     $Itemid = null;
     if (!empty($needles['menu_id']) && $needles['menu_id'] > 0) {
         $Itemid = $needles['menu_id'];
     }
     if (!empty($needles['Itemid']) && $needles['Itemid'] > 0) {
         $Itemid = $needles['Itemid'];
     }
     if ($Itemid > 0) {
         // Check whether this Itemid is valid
         include_once JPATH_SITE . DS . DS . 'components' . DS . 'com_simplelists' . DS . 'helpers' . DS . 'router.php';
         $menu_items = SimplelistsHelperRouter::getMenuItems();
         $match = false;
         foreach ($menu_items as $menu_item) {
             if ($menu_item->id == $Itemid && $menu_item->query['view'] == $needles['view']) {
                 $match = true;
                 break;
             }
         }
         // Only if the Itemid is valid, add it to the URL
         if ($match == true) {
             $url .= '&Itemid=' . $Itemid;
         }
     }
     // Convert the system URL into a SEF URL
     $url = JRoute::_($url);
     // Append the anchor-name for the item
     if (!empty($needles['item_alias'])) {
         $url .= '#' . $needles['item_alias'];
     } elseif (!empty($needles['item_id']) && $needles['item_id'] > 0) {
         $url .= '#item' . (int) $needles['item_id'];
     }
     return $url;
 }