Пример #1
0
 /**
  * Returns link to category view  
  * @param JCategoryNode $catid
  * @param number $language
  * @return string
  */
 public static function getCategoryRoute($catid, $language = 0)
 {
     if ($catid instanceof JCategoryNode) {
         $id = $catid->id;
         $category = $catid;
     } else {
         throw new Exception('First parameter must be JCategoryNode');
     }
     $catviews = PfmobileappwsHelper::getCategoryViews();
     $extensionviews = array_flip($catviews);
     $view = $extensionviews[$category->extension];
     if ($id < 1) {
         $link = '';
     } else {
         //Create the link
         $link = 'index.php?option=com_pfmobileappws&view=' . $view . '&category=' . $category->slug;
         $needles = array($view => array($id), 'category' => array($id));
         if ($language && $language != "*" && JLanguageMultilang::isEnabled()) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true)->select('a.sef AS sef')->select('a.lang_code AS lang_code')->from('#__languages AS a');
             $db->setQuery($query);
             $langs = $db->loadObjectList();
             foreach ($langs as $lang) {
                 if ($language == $lang->lang_code) {
                     $link .= '&lang=' . $lang->sef;
                     $needles['language'] = $language;
                 }
             }
         }
         if ($item = self::_findItem($needles, 'category')) {
             $link .= '&Itemid=' . $item;
         } else {
             if ($category) {
                 $catids = array_reverse($category->getPath());
                 $needles = array('category' => $catids);
                 if ($item = self::_findItem($needles, 'category')) {
                     $link .= '&Itemid=' . $item;
                 } elseif ($item = self::_findItem(null, 'category')) {
                     $link .= '&Itemid=' . $item;
                 }
             }
         }
     }
     return $link;
 }
Пример #2
0
function PfmobileappwsParseRoute($segments)
{
    $vars = array();
    $catviews = PfmobileappwsHelper::getCategoryViews();
    $extensionviews = array_flip($catviews);
    $listviews = array_keys($catviews);
    //Get the active menu item.
    $app = JFactory::getApplication();
    $params = JComponentHelper::getParams('com_pfmobileappws');
    $advanced = $params->get('sef_advanced_link', 0);
    $menu = $app->getMenu();
    $item = $menu->getActive();
    // Count route segments
    $count = count($segments);
    // Standard routing
    if (!isset($item)) {
        $vars['view'] = $segments[0];
        $isList = in_array($vars['view'], $listviews);
        if ($isList && $count > 1) {
            $vars['category'] = $segments[$count - 1];
        } elseif (!$isList && $count > 1) {
            $vars['id'] = $segments[$count - 1];
        }
        return $vars;
    }
    if (count($segments > 0)) {
        $vars['view'] = $segments[0];
        switch ($vars['view']) {
            case 'note':
                $id = explode(':', $segments[1]);
                $vars['id'] = (int) $id[0];
                break;
            case 'oauthaccess':
                $id = explode(':', $segments[1]);
                $vars['id'] = (int) $id[0];
                break;
            case 'oauthaccesslist':
                $id = explode(':', $segments[1]);
                $vars['id'] = (int) $id[0];
                break;
            case 'productlist':
                $id = explode(':', $segments[1]);
                $vars['id'] = (int) $id[0];
                break;
            case 'products':
                $id = explode(':', $segments[1]);
                $vars['id'] = (int) $id[0];
                break;
            case 'tasks':
                $id = explode(':', $segments[1]);
                $vars['id'] = (int) $id[0];
                break;
        }
    } else {
        $vars['view'] = $segments[0];
    }
    // End count(segments) statement
    return $vars;
}