Skip to content

Instantly share code, notes, and snippets.

@tbaddade
Last active July 30, 2020 14:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbaddade/7466757 to your computer and use it in GitHub Desktop.
Save tbaddade/7466757 to your computer and use it in GitHub Desktop.
REDAXO - Ctypes sortieren
<?php
/*
REDAXO 4.5 - Ctypes sortieren
Sortierung erfolgt mit vorangestellter Zahl beim Ctypenamen im Template.
Bspl:
01 - Inhalt
02 - rechte Spalte
Dazu in der Datei /redaxo/include/pages/content.inc.php in Zeile 624 folgenden Code einfügen
*/
$ctypes_digit = array();
$ctypes_alpha = array();
foreach ($REX['CTYPE'] as $key => $val)
{
if (preg_match('/^[0-9]+\s[-]\s/', $val)) {
$ctypes_digit[$key] = $val;
} else {
$ctypes_alpha[$key] = $val;
}
}
asort($ctypes_digit);
foreach ($ctypes_digit as $key => $val) {
$ctypes_digit[$key] = preg_replace('/^[0-9]+\s[-]\s/', '', $val);
}
$REX['CTYPE'] = $ctypes_digit + $ctypes_alpha;
?>
<?php
// in die boot.php des project AddOns
if (rex::isBackend() && rex::getUser() && rex_addon::get('structure')->isAvailable() && rex_be_controller::getCurrentPage() == 'content/edit') {
rex_extension::register('OUTPUT_FILTER', function (rex_extension_point $ep) {
$subject = $ep->getSubject();
$page = rex_be_controller::getPageObject('content/edit');
$subpages = $page->getSubpages();
$ctypesDigit = [];
$ctypesAlpha = [];
foreach ($subpages as $key => $subpage) {
preg_match('@<li[^>]*><a[^>]*'.preg_quote(trim(rex_string::buildAttributes(['href' => $subpage->getHref()]))).'>'.preg_quote($subpage->getTitle()).'<\/a><\/li>@m', $subject, $match);
if (isset($match[0]) && $match[0] != '') {
if (preg_match('/^[0-9]+\s[-]\s/', $subpage->getTitle())) {
$ctypesDigit[$key] = $subpage->getTitle();
} else {
$ctypesAlpha[$key] = $subpage->getTitle();
}
}
}
asort($ctypesDigit);
foreach ($ctypesDigit as $key => $val) {
$ctypesDigit[$key] = preg_replace('/^[0-9]+\s[-]\s/', '', $val);
}
$ctypes = $ctypesDigit + $ctypesAlpha;
$listItems = [];
foreach ($ctypes as $key => $title) {
if (isset($subpages[$key])) {
$subpage = $subpages[$key];
$attributes = [];
if ($subpage->isActive()) {
$attributes['class'] = 'active';
}
$listItems[] = '<li'.rex_string::buildAttributes($attributes).'><a'.rex_string::buildAttributes(['href' => $subpage->getHref()]).'>'.$subpage->getTitle().'</a></li>';
}
}
$subject = preg_replace('@(<div id="rex-js-structure-content-nav" class="nav rex-page-nav">.*?<nav class="navbar navbar-default"><ul class="nav navbar-nav">).*?(</ul></nav>.*?</div>)@m', '$1'.implode($listItems).'$2', $subject);
$ep->setSubject($subject);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment