[phpBB Debug] PHP Warning: in file [ROOT]/ext/tas2580/seourls/event/listener.php on line 213: Undefined array key "FORUM_NAME"
Modul "05 - Kategorienliste": Fehler bei html-Erzeugung - REDAXO Forum
Hallo,

Wir haben in letzter Zeit festgestellt, dass die Kommunikation via Slack viel schneller und zielführender ist als ein Beitrag im Forum. Aufgrund der neuen und besseren Möglichkeiten der Kommunikation haben wir uns entschlossen das Forum nur noch als Archiv zur Verfügung zu stellen. Somit bleibt es weiterhin möglich hier nach Lösungen zu suchen. Neue Beiträge können nicht mehr erstellt werden.

Wir empfehlen, für deine Fragen/Probleme Slack zu nutzen. Dort sind viele kompetente Benutzer aktiv und beantworten jegliche Fragen, gerne auch von REDAXO-Anfängern! Slack wird von uns sehr intensiv und meistens "rund um die Uhr" benutzt :-)
Selbst einladen kannst Du dich hier: https://redaxo.org/slack/
LucHamers
Beiträge: 1
Registriert: 1. Jan 2014, 19:09

Modul "05 - Kategorienliste": Fehler bei html-Erzeugung

1. Jan 2014, 21:01

Hallo,

ich habe versucht, das Modul "05 - Kategorienliste" zu verwenden. Leider funktioniert das weder mit Textile- noch mit Fließtext (tinyMCE)-Artikeln, wenn man die Anzahl der Wörter einschränkt. Das Problem ist, dass diese Artikel mit </p></div> abgeschlossen werden, was inkorrekt eingefügt wird, wenn nicht alle Wörter das Artikels angezeigt werden sollen. Dadurch wird ungültiger html-Code erzeugt.

Ich habe den Code der Ausgabe modifiziert, sodass er jetzt funktioniert:

Code: Alles auswählen

<?php

$cat = OOCategory :: getCategoryById($this->getValue('category_id'));
$cats = $cat->getChildren();

$itemsPerSide = "REX_VALUE[1]";
$wordsPerArticle = "REX_VALUE[2]";

if (is_array($cats))
{
  $i = 0;
  foreach ($cats as $cat)
  {
    $i += 1;
    if ($i <= $itemsPerSide)
    {
      if ($cat->isOnline())
      {

        $catId = $cat->getId();
        $catName = $cat->getName();
        $article = $cat->getArticles();

        if (is_array($article))
        {
          foreach ($article as $var)
          {
            $articleId = $var->getId();
            $articleName = $var->getName();
            $art = new rex_article($articleId);
            $articleContent = $art->getArticle();

            $articleContent = trim($articleContent);
            // Ensure that any on these tags are in seperate words in the array by adding a space
            $articleContent = str_replace('</p>', ' </p>', $articleContent);
            $articleContent = str_replace('<br />', ' <br />', $articleContent);
            $articleContent = str_replace('</div>', ' </div>', $articleContent);

            $output = '';
            $words = explode(' ', $articleContent);
            $wordsCount = count($words);

            // Find the last real word before any html end character. After this, only end tags like </p> and </div>
            // are found. They have to be added to the resulting string after the number of words is reduced.
            for ($i=$wordsCount-1; $i>0; --$i)
            {
              // Find any ending html tag (e.g. </div>), or spaces or empty words
              if (preg_match("{</(.*?)>|\s|^$}", $words[$i])==1)
              {
                --$wordsCount;
              }
              else
              {
                break;
              }
            }
            
            if ($wordsCount < $wordsPerArticle)
              $wEnd = $wordsCount;
            else
              $wEnd = $wordsPerArticle;

            for ($w = 0; $w < $wEnd; $w++)
            {
              $output .= $words[$w] . ' ';
            }

            // Output "more" in the used languages, in this case is 0 German and 1 is Dutch.
            $clang = rex_get('clang', 'int', REX_CLANG_ID);
            if ($clang == 0)
            {
              $more = "Mehr";
            }
            else 
            {
              $more = "Meer";
            }
 
            $output .= '<a href="' . rex_getUrl($articleId) . '" class="more"> ...'.$more.'</a>';
 
            // Add finishing thml tags, which were cut off previously.
            $no_ending_words = count($words) - $wordsCount;
            for ($i = 0; $i < $no_ending_words; ++$i)
            {
              $output .= $words[$wordsCount + $i]." ";
            }
            
            print '<div class="txt-img">' . $output . '</div>';
          }
        }
      }
    }
  }
}
?>
Vielleicht ist diese Änderung interessant für andere. Falls ja, dann könnte das in einer zukünftigen Version übernommen werden.

Lilly
Beiträge: 1
Registriert: 13. Jan 2014, 12:24

Re: Modul "05 - Kategorienliste": Fehler bei html-Erzeugung

13. Jan 2014, 12:31

Hab schon lange nach einer Möglichkeit gesucht um das Problem in den Griff zu bekommen... Danke für den Beitrag.

Zurück zu „Sonstiges“