Example #1
0
/**
 * Gibt eine Url zu einem Artikel zurück.
 *
 * @param string       $_id
 * @param int|string   $_clang  SprachId des Artikels
 * @param array|string $_params Array von Parametern
 * @param bool         $escape  Flag whether the argument separator "&" should be escaped (&)
 *
 * @return string
 *
 * @package redaxo\structure
 */
function rex_getUrl($_id = '', $_clang = '', $_params = '', $escape = true)
{
    $id = (int) $_id;
    $clang = (int) $_clang;
    // ----- get id
    if ($id == 0) {
        $id = rex::getProperty('article_id');
    }
    // ----- get clang
    // Wenn eine rexExtension vorhanden ist, immer die clang mitgeben!
    // Die rexExtension muss selbst entscheiden was sie damit macht
    if ($_clang === '' && (rex_clang::count() > 1 || rex_extension::isRegistered('URL_REWRITE'))) {
        $clang = rex_clang::getCurrentId();
    }
    // ----- get params
    $param_string = rex_param_string($_params, $escape ? '&' : '&');
    $name = 'NoName';
    if ($id != 0) {
        $ooa = rex_article::get($id, $clang);
        if ($ooa) {
            $name = rex_parse_article_name($ooa->getName());
        }
    }
    // ----- EXTENSION POINT
    $url = rex_extension::registerPoint(new rex_extension_point('URL_REWRITE', '', ['id' => $id, 'name' => $name, 'clang' => $clang, 'params' => $param_string, 'escape' => $escape]));
    if ($url == '') {
        $_clang = '';
        if (rex_clang::count() > 1) {
            $_clang .= ($escape ? '&' : '&') . 'clang=' . $clang;
        }
        $url = rex_url::frontendController() . '?article_id=' . $id . $_clang . $param_string;
    }
    return $url;
}
/**
 * Gibt eine Url zu einem Artikel zurück
 *
 * @param [$id] ArtikelId des Artikels
 * @param [$clang] SprachId des Artikels
 * @param [$params] Array von Parametern
 * @param [$divider] Trennzeichen für Parameter
 * (z.B. & für HTML, & für Javascript)
 */
function rex_getUrl($id = '', $clang = '', $params = '', $divider = '&')
{
    global $REX, $article_id;
    $id = (int) $id;
    $clang = (int) $clang;
    // ----- get id
    if (strlen($id) == 0 || $id == 0) {
        $id = $article_id;
    }
    // ----- get clang
    // Wenn eine rexExtension vorhanden ist, immer die clang mitgeben!
    // Die rexExtension muss selbst entscheiden was sie damit macht
    if (strlen($clang) == 0 && (count($REX['CLANG']) > 1 || rex_extension_is_registered('URL_REWRITE'))) {
        $clang = $REX['CUR_CLANG'];
    }
    // ----- get params
    $param_string = rex_param_string($params, $divider);
    // ----- get article name
    $id = (int) $id;
    if ($id != 0) {
        $ooa = OOArticle::getArticleById($id, $clang);
        if ($ooa) {
            $name = rex_parse_article_name($ooa->getName());
        }
    }
    if (!isset($name) or $name == '') {
        $name = 'NoName';
    }
    // ----- EXTENSION POINT
    $url = rex_register_extension_point('URL_REWRITE', '', array('id' => $id, 'name' => $name, 'clang' => $clang, 'params' => $param_string));
    if ($url == '') {
        // ----- get rewrite function
        if ($REX['MOD_REWRITE'] === true || $REX['MOD_REWRITE'] == 'true') {
            $rewrite_fn = 'rex_apache_rewrite';
        } else {
            $rewrite_fn = 'rex_no_rewrite';
        }
        $url = call_user_func($rewrite_fn, $id, $name, $clang, $param_string);
    }
    return $url;
}
/**
 * Helper function, die den Subtitle generiert
 */
function rex_get_subtitle($subline, $attr = '')
{
    global $REX_USER;
    if (empty($subline)) {
        return '';
    }
    $subtitle_str = $subline;
    $subtitle = $subline;
    $cur_subpage = rex_request('subpage', 'string');
    $cur_page = rex_request('page', 'string');
    if (is_array($subline) && count($subline) > 0) {
        $subtitle = array();
        $numPages = count($subline);
        foreach ($subline as $subpage) {
            if (!is_array($subpage)) {
                continue;
            }
            $link = $subpage[0];
            $label = $subpage[1];
            $perm = !empty($subpage[2]) ? $subpage[2] : '';
            $params = !empty($subpage[3]) ? rex_param_string($subpage[3]) : '';
            // Berechtigung prüfen
            if ($perm != '') {
                // Hat der User das Recht für die aktuelle Subpage?
                if (!$REX_USER->hasPerm('admin[]') && !$REX_USER->hasPerm($perm)) {
                    // Wenn der User kein Recht hat, und diese Seite öffnen will -> Fehler
                    if ($cur_subpage == $link) {
                        exit('You have no permission to this area!');
                    } else {
                        continue;
                    }
                }
            }
            // Falls im Link parameter enthalten sind, diese Abschneiden
            if (($pos = strpos($link, '&')) !== false) {
                $link = substr($link, 0, $pos);
            }
            $active = empty($cur_subpage) && $link == '' || !empty($cur_subpage) && $cur_subpage == $link;
            // Auf der aktiven Seite den Link nicht anzeigen
            if ($active) {
                // $format = '%s';
                // $subtitle[] = sprintf($format, $label);
                $format = '<a href="?page=' . $cur_page . '&amp;subpage=%s%s"%s' . rex_tabindex() . ' class="rex-subpage-active">%s</a>';
                $subtitle[] = sprintf($format, $link, $params, $attr, $label);
            } elseif ($link == '') {
                $format = '<a href="?page=' . $cur_page . '%s"%s' . rex_tabindex() . '>%s</a>';
                $subtitle[] = sprintf($format, $params, $attr, $label);
            } else {
                $format = '<a href="?page=' . $cur_page . '&amp;subpage=%s%s"%s' . rex_tabindex() . '>%s</a>';
                $subtitle[] = sprintf($format, $link, $params, $attr, $label);
            }
        }
        if (!empty($subtitle)) {
            $items = '';
            $num_parts = count($subtitle);
            $i = 1;
            foreach ($subtitle as $part) {
                if ($i != $num_parts) {
                    $part .= ' | ';
                }
                $items .= '<li>' . $part . '</li>
        ';
                $i++;
            }
            $subtitle_str = '
      <ul>
        ' . $items . '
      </ul>
      ';
        }
    }
    // \n aus Quellcode formatierungsgründen
    return $subtitle_str;
}
/**
 * Leitet auf einen anderen Artikel weiter
 */
function rex_redirect($article_id, $clang, $params = array())
{
    global $REX;
    // Alle OBs schließen
    while (@ob_end_clean()) {
    }
    $divider = '&';
    $url = rex_no_rewrite($article_id, $clang, '', rex_param_string($params, $divider), $divider);
    header('Location: ' . $url);
    exit;
}
/**
 * Leitet auf einen anderen Artikel weiter
 */
function rex_redirect($article_id, $clang, $params = array())
{
    global $REX;
    // Alle OBs schließen
    while (@ob_end_clean()) {
    }
    $url = rex_no_rewrite($article_id, $clang, '', rex_param_string($params));
    // Redirects nur im Frontend folgen
    // Und nur wenn FOLLOW_REDIRECT auf true steht
    // Somit können Addons wie search_index die Seite indizieren
    // ohne dass der Indizierungsprozess durch weiterleitungen unterbrochen wird
    if (!$REX['REDAXO'] && $REX['FOLLOW_REDIRECTS']) {
        header('Location: ' . $url);
    } else {
        echo 'Disabled redirect to ' . $url;
    }
    exit;
}
/**
 * Helper function, die den Subtitle generiert
 */
function rex_get_subtitle($subline)
{
    global $REX;
    if (empty($subline)) {
        return '';
    }
    $subtitle_str = $subline;
    $subtitle = $subline;
    $cur_subpage = rex_request('subpage', 'string');
    $cur_page = rex_request('page', 'string');
    if (is_array($subline) && count($subline) > 0) {
        $subtitle = array();
        $numPages = count($subline);
        foreach ($subline as $subpage) {
            if (!is_array($subpage)) {
                continue;
            }
            $link = $subpage[0];
            $label = $subpage[1];
            $perm = !empty($subpage[2]) ? $subpage[2] : '';
            $params = !empty($subpage[3]) ? rex_param_string($subpage[3]) : '';
            // Berechtigung prüfen
            if ($perm != '') {
                // Hat der User das Recht für die aktuelle Subpage?
                if (!$REX['USER']->isAdmin() && !$REX['USER']->hasPerm($perm)) {
                    // Wenn der User kein Recht hat, und diese Seite öffnen will -> Fehler
                    if ($cur_subpage == $link) {
                        exit('You have no permission to this area!');
                    } else {
                        continue;
                    }
                }
            }
            // Falls im Link parameter enthalten sind, diese Abschneiden
            if (($pos = strpos($link, '&')) !== false) {
                $link = substr($link, 0, $pos);
            }
            $active = empty($cur_subpage) && $link == '' || !empty($cur_subpage) && $cur_subpage == $link;
            // restliche attribute direkt in den link-tag schreiben
            $attr = '';
            $add_class = '';
            if (!empty($subpage[4]) && is_array($subpage[4])) {
                foreach ($subpage[4] as $attr_name => $attr_value) {
                    if ($active && $attr_name == 'class') {
                        $add_class = ' ' . $attr_value;
                        break;
                    }
                    $attr .= ' ' . $attr_name . '="' . $attr_value . '"';
                }
            }
            // Auf der aktiven Seite den Link nicht anzeigen
            if ($active) {
                // $format = '%s';
                // $subtitle[] = sprintf($format, $label);
                $format = '<a href="?page=' . $cur_page . '&amp;subpage=%s%s"%s' . rex_tabindex() . ' class="rex-active%s">%s</a>';
                $subtitle[] = sprintf($format, $link, $params, $attr, $add_class, $label);
            } elseif ($link == '') {
                $format = '<a href="?page=' . $cur_page . '%s"%s' . rex_tabindex() . '>%s</a>';
                $subtitle[] = sprintf($format, $params, $attr, $label);
            } else {
                $format = '<a href="?page=' . $cur_page . '&amp;subpage=%s%s"%s' . rex_tabindex() . '>%s</a>';
                $subtitle[] = sprintf($format, $link, $params, $attr, $label);
            }
        }
        if (!empty($subtitle)) {
            $items = '';
            $i = 1;
            foreach ($subtitle as $part) {
                if ($i == 1) {
                    $items .= '<li class="rex-navi-first">' . $part . '</li>';
                } else {
                    $items .= '<li>' . $part . '</li>';
                }
                $i++;
            }
            $subtitle_str = '
            <div id="rex-navi-page">
            <ul>
                ' . $items . '
            </ul>
            </div>
            ';
        }
    }
    // \n aus Quellcode formatierungsgründen
    return $subtitle_str;
}