Optimierung des Standard-News-Modul

Gesperrt
Kurby
Beiträge: 23
Registriert: Di 1. Sep 2009, 18:14
Kontaktdaten:

Optimierung des Standard-News-Modul

Beitrag von Kurby » Di 24. Nov 2009, 09:11

Hi!

Ich optimiere derzeit das News-Modul aus dem Demo Mandanten.

Im Code des Moduls ist bereits erstellt, dass jeder Artikel, der i der Liste als News auftaucht, eine Headline hat. Diese taucht allerdings in nicht auf, wenn ich einen neuen Artikel erstelle. Evtl. lege ich die auch gar nicht fest, wo müsste ich diese festlegen?

Außerdem möchte ich gerne, dass hinter jeder Headline das Erstellungsdatum des Artikels erscheint. Das Template habe ich schon bearbeitet. Leider funktioniert das noch nicht.
Ich denke, im Code ist noch ein Fehler drin.

Hier die Ausgabe:

Code: Alles auswählen

<?php
/**
* $RCSfile$
*
* Description: Newslist / ArticleList. Module "Output".
*
* @version 1.1.0
* @author Andreas Lindner
* @copyright four for business AG <www.4fb.de>
*
* {@internal
* created 2005-08-12
* modified 2009-01-16 Rudi Bieller Added new Contenido_Url for creating URLs
* }}
*
* $Id$
*/

cInclude('classes', 'class.article.php');
cInclude('includes', 'functions.api.string.php');
cInclude('includes', 'functions.api.images.php');

if (!isset($tpl) || !is_object($tpl)) {
    $tpl = new Template();
}

$tpl->reset();

$sql = "SELECT
            htmlpath, frontendpath
        FROM
            ".$cfg["tab"]["clients"]." 
        WHERE
            idclient = ".$client." ";

$db->query($sql);

if ($db->next_record()) {
    $htmlpath = $db->f('htmlpath');
    $frontendpath = $db->f('frontendpath');
}

// selected category
$selcat = "CMS_VALUE[1]";
$template = "teaser-standard.html";
// anzahl der zeichen text
$mxtext = 200;

$limit = "CMS_VALUE[15]";

$cms_sort_direction = "CMS_VALUE[16]";
if ($cms_sort_direction == '') {
    $cms_sort_direction = 'desc';
}

if ("CMS_VALUE[3]" == "sortdate") {
    $order = 'lastmodified';
} else {
    $order = 'artsort';
}

if ("CMS_VALUE[17]" != '') {
    $with_start = true;
} else {
    $with_start = false;
}

$newsheadline = "CMS_VALUE[4]";

$tpl->set('s', 'TITLE', $newsheadline);

if (strlen($selcat) > 0 && $selcat != '0') {
    $options = array ('idcat' => $selcat, "start" => $with_start, "order" => $order, "direction" => $cms_sort_direction);

    $list = new ArticleCollection($options);

    $count = $list->count;

    if ($count > 0) {
        if (is_numeric($limit) AND strlen($limit) > 0) {
            if ($limit < $list->count) {
                $limit_art = $limit;
            } else {
                $limit_art = $list->count;
            }
        } else {
            $limit_art = $list->count;
        }

        for ($i = 0; $i < $limit_art; $i ++) {

            $article = $list->nextArticle();

            $article_id = $article->getField('idart');

            $teaser_img = '';
            if ($noimg != 'true') {
                $text_html = $article->getContent('CMS_HTML', 1);

                $regEx = "/<img[^>]*?>.*?/i";
                $match = array ();
                preg_match($regEx, $text_html, $match);

                $regEx = "/(src)(=)(['\"]?)([^\"']*)(['\"]?)/i";
                $img = array ();
                preg_match($regEx, $match[0], $img);
                $img_src = preg_split("/\//", $img[0]);

                $img_name = $img_src[count($img_src) - 1];
                $img_name = preg_replace("/\"/", "", $img_name);
                $img_split = preg_split("/\./", $img_name);
                $img_type = $img_split[count($img_split) - 1];

                $img_split2 = preg_split("/_/", $img_split[0]);

                $name = $img_name;

                if (count($img_split2) > 1) {
                    $img_x = $img_split2[count($img_split2) - 1];
                    $img_y = $img_split2[count($img_split2) - 2];

                    if (is_numeric($img_x) AND is_numeric($img_y)) {
                        $suffix = "_".$img_x."_".$img_y.".".$img_type;
                        $name = preg_replace("/$suffix/", "", $img_name);
                        $name = $name.".[a-zA-Z]{3}";
                    }
                }

                $img_teaser = '';

                if (strlen($name) > 0) {
                    $sql = "SELECT
                                                    *
                                                FROM
                                                    ".$cfg["tab"]["upl"]." 
                                                WHERE
                                                    filename REGEXP '$name' ";

                    //echo "<pre>"; print_r($sql); echo "</pre>";

                    $db->query($sql);

                    if ($db->next_record()) {
                        $filename = $db->f('filename');
                        $dirname = $db->f('dirname');
                    }

                    $img_path = $cfgClient[$client]["upl"]["path"].$dirname.$filename;

                    $img_size = "CMS_VALUE[14]";

                    $img_teaser = capiImgScale($img_path, $img_size, $img_size, $crop = false, $expand = false, $cacheTime = 1000, $wantHQ = false);
                } // end if strlen

                if (strlen($img_teaser) > 0) {
                    $teaser_img = '<img src="'.$img_teaser.'" class="teaser_img">';
                } else {
                    $teaser_img = '';
                }

            } // end if noimg       

            $headline = strip_tags($article->getContent('CMS_HTMLHEAD', 1));
            $headline = str_replace($replace, " ", $headline);

            /*          $subheadline = strip_tags($article->getContent('CMS_HTMLHEAD', 2));
                        $subheadline = str_replace($replace, " ", $subheadline);*/

            $teaserheadline = /*$subheadline."&nbsp;-&nbsp;".*/
            $headline;
            // this is just for sample client - modify to your needs!
            if ($cfg['url_builder']['name'] == 'front_content') {
                $aParams = array('lang' => $lang, 'idcat' => $selcat, 'idart' => $article_id);
            } else {
                $aParams = array('b' => array('lang' => $lang, 'idcat' => $selcat, 'idart' => $article_id), 
                                'idcat' => $selcat, // needed to build category path
                                'lang' => $lang, // needed to build category path
                                'level' => 1); // needed to build category path
            }
            try {
                $href = Contenido_Url::getInstance()->build($aParams);
            } catch (InvalidArgumentException $e) {
                $href = $sess->url("front_content.php?idcat=$selcat&idart=$article_id");
            }
            $teasertext = $article->getField('summary');

            if (strlen(trim($teasertext)) == 0) {
                $teasertext = strip_tags($article->getContent('CMS_HTML', 1));
                $teasertext2 = $teasertext;
                $teasertext = capiStrTrimAfterWord($teasertext, $mxtext);
                if ($teasertext!=$teasertext2) {
                    $teasertext.= '...';
                }
                
            } // end if             

            $teasertext = $teasertext."&nbsp;";
            
            $lastmodified = strtotime($db->f("lastmodified"));

            $tpl->set('d', 'HEADLINE', $teaserheadline);
            $tpl->set('d', 'TEXT', $teasertext);
            $tpl->set('d', 'HREF', $href);
            $tpl->set('d', 'IMG', $teaser_img);
            $tpl->set('d', 'MORE', mi18n("mehr"));
            $tpl->set('d', 'DATE', $lastmodified);

            $tpl->next();

        } // end for

        $tpl->generate('templates/'.$template);

    }
}
?>

Vielen Dank für die Hilfe!

PS: Die Artikelliste Advanced, die es hier im Forum gibt, funktioniert bei mir leider nicht. Ich glaube auch, dass diese für mein Vorhaben schon zu umfangreich ist ;)

Kurby
Beiträge: 23
Registriert: Di 1. Sep 2009, 18:14
Kontaktdaten:

Re: Optimierung des Standard-News-Modul

Beitrag von Kurby » Sa 28. Nov 2009, 12:01

Niemand eine Idee?

BagHira
Beiträge: 486
Registriert: Do 23. Feb 2006, 19:42
Wohnort: Tirschenreuth / Oberpfalz / Bayern
Kontaktdaten:

Re: Optimierung des Standard-News-Modul

Beitrag von BagHira » Mo 30. Nov 2009, 08:50

Servus Kurby,

ich arbeite nicht mir diesem Modul, deshalb nur einige Vorschläge:

Ist den $lastmodified überhaupt in deinem Array $list vorhanden? Um das abzuchecken nach:

Code: Alles auswählen

$list = new ArticleCollection($options);
folgendes:

Code: Alles auswählen

echo '<pre>Artikelliste'.print_r($list, true).'</pre>';
Deine Angabe zur Templategenerierung für $teaserheadline kann gar keine Ausgabe erzeugen:
Du gibst hier an:

Code: Alles auswählen

$tpl->set('d', 'HEADLINE', $teaserheadline);
Weiter oben kommentierst du aber $teaserheadline aus, somit gibt es die Variable gar nicht:

Code: Alles auswählen

$teaserheadline = /*$subheadline."&nbsp;-&nbsp;".*/
Edit:
hab zu $lastmodified noch folgendes gefunden, das könnte dir helfen:
http://forum.contenido.org/viewtopic.ph ... 8&p=117448
Gruß Holger

Träumer haben vielleicht keinen Plan, aber Realisten haben keine Vision.

Handgewickelte Glasperlen Facebook Google+

Gesperrt