Sorry, natürlich gern
Ich habe wie beschrieben den php-Code für die Sortierfunktion in einer Datei "sortieren.php" abgespeichert und diese dann in der Modulausgabe ganz am Anfang inkludiert:
Code: Alles auswählen
<? include('files/sortieren.php'); ?>
<?php
if (!function_exists('ep_checkOnlineDate'))
{
function ep_checkOnlineDate($date, $article_date)
{
if ($date > 0 && $article_date == '')
return false;
elseif ($date > 0 && $article_date < $date)
return false;
return true;
}
}
$out = '';
$article_total = 'REX_VALUE[6]';
$article_per_page = 'REX_VALUE[2]';
$mode = 'REX_VALUE[3]';
$sort = 'REX_VALUE[5]';
$date_start = 'REX_VALUE[8]';
$hdl_tag = 'REX_VALUE[7]';
if ($hdl_tag == '')
$hdl_tag = 'h3';
$cat_id = 0;
if ($mode == 't' || $mode == 'tf')
$cat_id = REX_CATEGORY_ID;
elseif ($mode == 'c' || $mode == 'cf')
$cat_id = 'REX_VALUE[4]';
$date_start_time = 0;
if ($date_start != '')
{
$date_start_arr = explode('|', $date_start);
$date_start_time = mktime('0', '0', '0', date('m'), date('d'), date('Y'));
$date_seconds = $date_start_arr[1] * 24 * 60 * 60;
switch ($date_start_arr)
{
case '-':
$date_start_time = $date_start_time - $date_seconds;
break;
case '+':
$date_start_time = $date_start_time + $date_seconds;
break;
}
// echo date('d.m.Y - H:i:s', $date_start_time);
}
$page = rex_request('page', 'int', '1');
$month_abbr = array();
$month_abbr[0][1] = 'Jan';
$month_abbr[0][2] = 'Feb';
$month_abbr[0][3] = 'Mrz';
$month_abbr[0][4] = 'Apr';
$month_abbr[0][5] = 'Mai';
$month_abbr[0][6] = 'Jun';
$month_abbr[0][7] = 'Jul';
$month_abbr[0][8] = 'Aug';
$month_abbr[0][9] = 'Sep';
$month_abbr[0][10] = 'Okt';
$month_abbr[0][11] = 'Nov';
$month_abbr[0][12] = 'Dez';
// OOArticel werden gespeichert
$article_list = array();
// Artikel holen fuer Modus
// -> seitenuebergreifend
if ($mode == 'p')
{
$sql = new rex_sql();
// $sql->debugsql = true;
$sql->setQuery('SELECT id FROM rex_article WHERE art_teaser = "|true|" AND status = "1" AND id != "REX_ARTICLE_ID"');
$rows = $sql->getRows();
if ($rows >= 1)
{
for ($i = 1; $i <= $rows; $i++, $sql->next())
{
$ooarticle = OOArticle::getArticleById($sql->getValue('id'));
if (ep_checkOnlineDate($date_start_time, $ooarticle->getValue('art_online_from')) )
$article_list[] = $ooarticle;
}
}
}
// Artikel holen fuer Modus
// -> Aktuelle Kategorie
// -> Kategorie wählen
if (($mode == 't' || $mode == 'c') && $cat_id > 0)
{
$articles = OOArticle::getArticlesOfCategory($cat_id, true);
foreach ($articles as $ooarticle)
{
if ($ooarticle->isStartArticle())
continue;
/*
if ($ooarticle->getValue('art_teaser') != '|true|')
continue;
*/
// Endlosschleife vermeiden
if ($ooarticle->getId() == REX_ARTICLE_ID)
continue;
if (ep_checkOnlineDate($date_start_time, $ooarticle->getValue('art_online_from')) )
$article_list[] = $ooarticle;
}
}
// Artikel holen fuer Modus
// -> Aktuelle Kategorie und alle darunter
// -> Kategorie wählen und alle darunter
if (($mode == 'tf' || $mode == 'cf') && $cat_id > 0)
{
$sql = new rex_sql();
// $sql->debugsql = true;
$sql->setQuery('SELECT id FROM rex_article WHERE art_teaser = "|true|" AND status = "1" AND id != "REX_ARTICLE_ID" AND path LIKE "%|'.$cat_id.'|%" ');
$rows = $sql->getRows();
if ($rows >= 1)
{
for ($i = 1; $i <= $rows; $i++, $sql->next())
{
$ooarticle = OOArticle::getArticleById($sql->getValue('id'));
if (ep_checkOnlineDate($date_start_time, $ooarticle->getValue('art_online_from')) )
$article_list[] = $ooarticle;
}
}
}
// Sortierung
if (count($article_list) > 0)
{
$sort_arr = explode('|', $sort);
$sort_f = strtolower($sort_arr[0]); // Feld
$sort_c = strtolower($sort_arr[1]); // Kriterium (ASC / DESC)
if ($sort_f == 'prior' AND $sort_c == 'asc')
usort($article_list, "sortArticlesByPrio");
elseif ($sort_f == 'prior' AND $sort_c == 'desc')
usort($article_list, "sortArticlesByPrioDesc");
elseif ($sort_f == 'date' AND $sort_c == 'asc')
usort($article_list, "sortArticlesByOnlineFromDate");
elseif ($sort_f == 'date' AND $sort_c == 'desc')
usort($article_list, "sortArticlesByOnlineFromDateDesc");
}
if ($article_total > 0)
{
$article_list = array_slice($article_list, 0, $article_total);
}
$navi_pag = '';
if ($article_per_page > 0)
{
$articles_length = count($article_list);
$pages = ceil($articles_length / $article_per_page);
//$offset = $page - 1;
$offset = ($page * $article_per_page) - $article_per_page;
$article_list = array_slice($article_list, $offset, $article_per_page);
// Pagination
for ($i = 1; $i <= $pages; $i++)
{
$param = '';
if ($page == $i)
$param .= ' active';
if ($i == 1)
$param .= ' first';
if ($param != '')
$param = ' class="'.trim($param).'"';
$navi_pag .= '<a'.$param.' href="'.rex_getUrl('', '', array('page' => $i)).'">'.$i.'</a>';
}
}
if (count($article_list) > 0)
{
$c = 0;
foreach ($article_list as $article)
{
$c++;
$name = '';
$name = $article->getValue('art_teaser_hdl');
if ($name == '')
$name = $article->getName();
$desc = $article->getValue('art_teaser_text');
$file = $article->getValue('art_teaser_file');
$teaser_link = $article->getValue('art_teaser_link_intern');
$link_id = '';
if ($teaser_link != '' && $teaser_link > 0)
$link_id = $teaser_link;
else
$link_id = $article->getId();
$link = '';
// Link nur anzeigen, wenn Checkbox deaktiviert ist
if ($article->getValue('art_teaser_link_more') != '|true|')
$link = '<a class="lk1" href="'.rex_getUrl($link_id).'">REX_VALUE[1]</a>';
$hdl = '';
$hdl .= '<'.$hdl_tag.' class="hl hl4">';
// nur verlinken, wenn weiterlesen link vorhanden ist
if ($link != '')
$hdl .= '<a href="'.rex_getUrl($link_id).'">';
$hdl .= $name;
if ($link != '')
$hdl .= '</a>';
$hdl .= '</'.$hdl_tag.'>';
$from = '';
if ($article->getValue('art_online_from') != '')
{
$date = $article->getValue('art_online_from');
$d = date('d', $date);
$m = date('n', $date);
$from = '<span class="date"><span class="day">'.$d.'</span><span class="month">'.$month_abbr[$REX['CUR_CLANG']][$m].'</span></span>';
// $from = '<p class="tx1 tsr-date">'.date('d.m.Y', $article->getValue('art_online_from')).'</p>';
}
$class = '';
$file_out = '';
if ($file != "")
{
$class = ' ti-bl';
$src = '';
$srcWidth = 1;
$imageWidth = 150;
$s = getimagesize($REX['HTDOCS_PATH'].'files/'.$file);
if ($s[0] > $imageWidth)
{
$src = '/index.php?rex_img_type=ws_typt1&rex_img_file='.$file;
$srcWidth = $imageWidth;
}
else
{
$src = $REX['HTDOCS_PATH'].'files/'.$file;
$srcWidth = $s[0];
}
$factor = $s[0] / $srcWidth;
$srcHeight = round($s[1] / $factor);
$media = OOMedia::getMediaByName($file);
$title = $media->getTitle();
$file_out = '<p class="img fl-lft"><span class="img shdw">';
// nur verlinken, wenn weiterlesen link vorhanden ist
if ($link != '')
$file_out .= '<img src="'.$src.'" title="'.$title.'" alt="'.$title.'" width="'.$srcWidth.'" height="'.$srcHeight.'" />'.$from;
$file_out .= '</span></p>';
}
$text_out = '';
if($desc != '')
{
$textile = htmlspecialchars_decode($desc);
$textile = str_replace("<br />", "", $textile);
$textile = rex_a79_textile($textile);
$srch = array();
$rplc = array();
$srch[] = 'href="#fn';
$rplc[] = 'href="'.rex_getUrl().'#fn';
$srch[] = 'href="http://';
$rplc[] = 'class="lk4" href="http://';
$srch[] = 'href="/';
$rplc[] = 'class="lk1" href="/';
$textile = str_replace($srch, $rplc, $textile);
if (substr($textile, -4) == '</p>')
$textile = substr($textile, 0, -4).' '.$link.'</p>';
else
$textile .= '<p class="tsr-lk">'.$link.'</p>';
$text_out = '<div class="content">'.$hdl.$textile.'</div>';
}
$tsr_class = '';
if ($c == 1)
$tsr_class = ' tsr-first';
$out .= '<div class="tsr'.$tsr_class.'">';
$out .= '<div class="slice ti'.$class.'">';
// $out .= $from.$name;
$out .= $file_out.$text_out;
$out .= '<div class="clearer"> </div>';
$out .= '</div></div>';
}
}
if ($navi_pag != '')
$out .= '<br><br><div class="pagination">Seite '.$navi_pag.'</div>';
echo $out;
?>
Ich weiß zwar nicht, ob das der beste Weg ist, aber es funktioniert bei mir auf jeden Fall.