Exemplo n.º 1
0
function KunenaParseRoute($segments)
{
    // If Kunena Forum isn't installed do nothing
    if (!class_exists('KunenaForum') || !KunenaForum::isCompatible('3.0') || !KunenaForum::installed()) {
        return array();
    }
    $profiler = JProfiler::getInstance('Application');
    KUNENA_PROFILER ? $profiler->mark('kunenaRoute') : null;
    $starttime = $profiler->getmicrotime();
    // Get current menu item and get query variables from it
    $active = JFactory::getApplication()->getMenu()->getActive();
    $vars = isset($active->query) ? $active->query : array('view' => 'home');
    if (empty($vars['view']) || $vars['view'] == 'home' || $vars['view'] == 'entrypage') {
        $vars['view'] = '';
    }
    // Use category SEF feature?
    $sefcats = isset(KunenaRoute::$sefviews[$vars['view']]) && empty($vars['id']);
    // Handle all segments
    while (($segment = array_shift($segments)) !== null) {
        // Skip //
        if (!$segment) {
            continue;
        }
        if ($sefcats && class_exists('KunenaRoute') && method_exists('KunenaRoute', 'resolveAlias')) {
            // Find out if we have SEF alias (category, view or layout)
            $alias = strtr($segment, ':', '-');
            $variables = KunenaRoute::resolveAlias($alias);
            if ($variables) {
                $sefcats = false;
                $vars = $variables + $vars;
                continue;
            }
        }
        $sefcats = false;
        // Generate variable and value
        $seg = explode(':', $segment);
        $var = array_shift($seg);
        $value = array_shift($seg);
        if (empty($var) && empty($value)) {
            // Skip /-/
            continue;
        }
        if (is_numeric($var)) {
            // Handle variables starting by number
            $value = (int) $var;
            if ($vars['view'] == 'user') {
                // Special case: User view
                $var = 'userid';
            } elseif (empty($vars['catid'])) {
                // First number is always category
                $var = 'catid';
                $vars['view'] = 'category';
            } elseif (empty($vars['id'])) {
                // Second number is always topic
                $var = 'id';
                $vars['view'] = 'topic';
                $sefcats = false;
            } elseif (empty($vars['mesid'])) {
                // Third number is always message
                $var = 'mesid';
                $vars['view'] = 'topic';
            } else {
                // Invalid parameter, skip it
                continue;
            }
        } elseif ($value === null) {
            // Simple variable without value is always either view or layout
            $value = $var;
            if (empty($vars['view']) || $value == 'topic' && $vars['view'] == 'category') {
                // View
                $var = 'view';
            } elseif (empty($vars['layout'])) {
                // Layout
                $var = 'layout';
            } elseif (!empty($vars['view'])) {
                // Unknown parameter: skip
                if (!empty($vars['view'])) {
                    continue;
                }
            } else {
                // Unknown view or non-existing category
                $var = 'view';
            }
        }
        $vars[$var] = $value;
    }
    if (empty($vars['layout'])) {
        $vars['layout'] = 'default';
    }
    KunenaRoute::$time = $profiler->getmicrotime() - $starttime;
    foreach ($vars as $var => $value) {
        KunenaRoute::$current->setVar($var, $value);
    }
    return $vars;
}