Exemple #1
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;
}