function getObjectInfo($id, $language = null)
 {
     $info = new JCommentsObjectInfo();
     $routerHelper = JPATH_ROOT . '/components/com_ars/router.php';
     if (is_file($routerHelper)) {
         require_once $routerHelper;
         $db = JFactory::getDBO();
         $query = 'SELECT id, title, alias, access, created_by' . ' FROM #__ars_categories' . ' WHERE id = ' . $id;
         $db->setQuery($query);
         $row = $db->loadObject();
         if (!empty($row)) {
             $options = array('option' => 'com_ars', 'view' => 'browses', 'language' => $language);
             $menu = ArsRouterHelper::findMenu($options);
             $Itemid = $menu->id;
             $Itemid = $Itemid > 0 ? '&Itemid=' . $Itemid : '';
             $info->title = $row->title;
             $info->access = $row->access;
             $info->userid = $row->created_by;
             $info->link = JRoute::_('index.php?option=com_ars&view=category&id=' . $id . $Itemid);
         }
     }
     return $info;
 }
Пример #2
0
function arsBuildRouteIni(&$query)
{
    $segments = array();
    $view = ArsRouterHelper::getAndPop($query, 'view', 'update');
    $Itemid = ArsRouterHelper::getAndPop($query, 'Itemid', null);
    $local_id = ArsRouterHelper::getAndPop($query, 'id', 'components');
    $task = 'ini';
    $id = '';
    if (!in_array($view, ['Update', 'updates', 'update'])) {
        return $segments;
    }
    // Analyze the current Itemid
    if (!empty($Itemid)) {
        // Get the specified menu
        $menus = JMenu::getInstance('site');
        $menuitem = $menus->getItem($Itemid);
        // Analyze URL
        $uri = new JUri($menuitem->link);
        $option = $uri->getVar('option');
        // Sanity check
        if ($option != 'com_ars') {
            $Itemid = null;
        } else {
            $task = $uri->getVar('task');
            $layout = $uri->getVar('layout');
            $format = $uri->getVar('format', 'ini');
            $id = $uri->getVar('id', null);
            if (empty($task) && !empty($layout)) {
                $task = $layout;
            }
            if (empty($task)) {
                if ($format == 'ini') {
                    $task = 'ini';
                } else {
                    $task = 'all';
                }
            }
            // make sure we can grab the ID specified in menu item options
            if (empty($id)) {
                switch ($task) {
                    case 'category':
                        $params = $menuitem->params instanceof JRegistry ? $menuitem->params : new JRegistry($menuitem->params);
                        $id = $params->get('category', 'components');
                        break;
                    case 'ini':
                    case 'stream':
                        $params = $menuitem->params instanceof JRegistry ? $menuitem->params : new JRegistry($menuitem->params);
                        $id = $params->get('streamid', 0);
                        break;
                }
            }
        }
    }
    // TODO cache this?
    $db = JFactory::getDBO();
    $dbquery = $db->getQuery(true)->select(array($db->qn('type'), $db->qn('alias')))->from($db->qn('#__ars_updatestreams'))->where($db->qn('id') . ' = ' . $db->q($local_id));
    $db->setQuery($dbquery, 0, 1);
    $stream = $db->loadObject();
    if (empty($stream)) {
        die;
    }
    if (empty($Itemid)) {
        // Try to find an Itemid with the same properties
        $otherMenuItem = ArsRouterHelper::findMenu(array('view' => 'updates', 'layout' => 'ini', 'option' => 'com_ars'), array('streamid' => $local_id));
        if (!empty($otherMenuItem)) {
            // Exact match
            $query['Itemid'] = $otherMenuItem->id;
        } else {
            $segments[] = 'updates';
            $segments[] = $stream->type;
            $segments[] = $stream->alias;
        }
    } else {
        // menu item id exists in the query
        if ($task == 'ini' && $id == $local_id) {
            $query['Itemid'] = $Itemid;
        } else {
            $segments[] = 'updates';
            $segments[] = $stream->type;
            $segments[] = $stream->alias;
        }
    }
    return $segments;
}