Standard News Modul: Frage zur query 'order by'

Gesperrt
mvf
Beiträge: 1758
Registriert: Mo 1. Aug 2005, 00:35
Wohnort: in der schönen Hallertau, mitten im Hopfen
Kontaktdaten:

Standard News Modul: Frage zur query 'order by'

Beitrag von mvf »

hallo community

ich möchte mit dem standard news modul 4.6.2 eine teaserbox realisieren, die mir eine preview eines einzelnen 'zufälligen' artikels aus eine kategorie ausgibt.

das problem ist die sortorder. im standard news modul wir diese ja über eingabefelder im modul-input gesteuert. dies zu umgehen ist kein problem, vielmehr im output-modul die sortorder auf

Code: Alles auswählen

ORDER BY RAND() LIMIT 1
zu bringen. die query wird über einen oprtions array gebildet, wenn ich das recht verstehe, aber im endeffekt kann ich nirgendwo erkennen, wo das

Code: Alles auswählen

ORDER BY a.
wirklich gebildet wird, denn wenn ich dieses verd... aus dem querystring hreaus bekäme würde es sicher laufen. (getestet mit artikelliste, aber dort wird die query anders gebildet)

wäre doch ein nettes feature, bei jedem pagerequest ein neuer teaser mit heeadline text und image ;)

aber wie gesagt/gefragt, wie kommt das a. in den string
hier mal der standard input und output code des news moduls

Code: Alles auswählen

?><?php
/***********************************************
* CONTENIDO MODUL - INPUT
*
* Modulname  :      News
* Author(s)   :     Andreas Lindner, 4fb
* Copyright   :     Contenido - four for business, Andreas Lindner
* Created     :     12.08.2005
************************************************/

#Select category
$cms_idcat = "CMS_VALUE[1]";

echo '<table cellpadding="0" cellspacing="0" border="0">';

echo '
		<tr><td class="text_medium" style="padding:5px">Kategorie wählen: </td></tr>
		<tr><td class="text_medium" style="padding:5px">';

echo buildCategorySelect("CMS_VAR[1]", "CMS_VALUE[1]");
echo '&nbsp;<input type="image" src="images/submit.gif">';

echo '</td></tr>';

#Select sort field and sort order
$sortdate = 'checked';
$cms_imgsize = "CMS_VALUE[14]";
$cms_limit_articles = "CMS_VALUE[15]";
$cms_sort_direction = "CMS_VALUE[16]";
if ("CMS_VALUE[17]" != '') {
	$cms_include_start_article = ' checked';
} else {
	$cms_include_start_article = '';
}

if ("CMS_VALUE[3]" == 'sortdate') {
	$sortdate = 'checked';
	$sortnum = '';
}
elseif ("CMS_VALUE[3]" == 'sortnum') {
	$sortdate = '';
	$sortnum = 'checked';
}

echo '
        <tr>
          <td class="text_medium" style="padding:5px;">'.mi18n("Sortierung nach Datum").':</td>
          <td style="padding:5px;"><input type="radio" name="CMS_VAR[3]" value="sortdate" '.$sortdate.'></td>
        </tr>
        <tr>
          <td class="text_medium" style="padding:5px;">'.mi18n("Sortierung nach Nummer").':</td>
          <td style="padding:5px;"><input type="radio" name="CMS_VAR[3]" value="sortnum" '.$sortnum.'></td>
        </tr>
        <tr>
          <td class="text_medium" style="padding:5px;">'.mi18n("Sortierung aufsteigend").':</td>
          <td style="padding:5px;">';
if (strtolower($cms_sort_direction) == 'desc') {
	echo '<input type="radio" name="CMS_VAR[16]" value="asc"/>';
} else {
	echo '<input type="radio" name="CMS_VAR[16]" value="asc" checked/>';
}
echo '</td>
        </tr>
        <tr>
          <td class="text_medium" style="padding:5px;">'.mi18n("Sortierung absteigend").':</td>
          <td style="padding:5px;">';
if (strtolower($cms_sort_direction) == 'desc') {
	echo '<input type="radio" name="CMS_VAR[16]" value="desc" checked/>';
} else {
	echo '<input type="radio" name="CMS_VAR[16]" value="desc"/>';
}
echo '</td>
        </tr>';

$noimg = '';
if ("CMS_VALUE[13]" == 'true') {
	$noimg = 'checked';
}

#Headline
echo '
	  	<tr><td class="text_medium" style="padding:5px;">'.mi18n("Überschrift").': </td></tr>
	  	<tr><td style="padding:5px;"><input type="text" name="CMS_VAR[4]" value="CMS_VALUE[4]"></td></tr>
        <tr>
          <td colspan="2" class="text_medium" style="padding:5px;"><b><u>'.mi18n("Bild für Teaser").':</u></b></td>
        </tr>
        <tr>
          <td colspan="2" class="text_medium" style="padding:5px;">'.mi18n("Es wird das erste Bild des Artikels angezeigt.").'</td>
        </tr>';
#Image width
echo '
		<tr><td class="text_medium" style="padding:5px;">'.mi18n("Bildbreite").': </td></tr>
	  	<tr><td style="padding:5px;"><input type="text" name="CMS_VAR[14]" value="'.$cms_imgsize.'" maxlength="3"></td></tr>';
#Disable images
echo '
        <tr>
          <td class="text_medium" style="padding:5px;">'.mi18n("Kein Bild anzeigen").':</td>
          <td style="padding:5px;"><input type="checkbox" name="CMS_VAR[13]" value="true" '.$noimg.'></td>
        </tr>';
#Number of articles
echo '
        <tr>
          <td class="text_medium" style="padding:5px;">'.mi18n("Anzahl Artikel begrenzen").':</td>
          <td style="padding:5px;"><input type="text" name="CMS_VAR[15]" value="'.$cms_limit_articles.'"></td>
        </tr>';
#Include start article
echo '
        <tr>
          <td class="text_medium" style="padding:5px;">'.mi18n("Startartikel in Liste einbeziehen").':</td>
          <td style="padding:5px;"><input type="text" name="CMS_VAR[17]" value="yes"'.$cms_include_start_article.'></td>
        </tr>';

echo '</table>';
?><?php

Code: Alles auswählen

<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname  :      News
* Author(s)   :     Andreas Lindner, 4fb
* Copyright   :     Contenido - four for business, Andreas Lindner
* Created     :     12.08.2005
************************************************/

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

if (!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]";
//echo "sel $selcat<br>";
$template = "art_prev_img.html";
//echo "tpl $template<br>";
// anzahl der zeichen text
$mxtext = 150;



$newsheadline = "CMS_VALUE[4]";

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

if (strlen($selcat) > 0 AND $selcat != '0') {
	$options = array ('idcat' => $selcat, "start" => false, "order" => $order);

	$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;
			$href = $sess->url("front_content.php?idcat=$selcat&idart=$article_id");
			$teasertext = $article->getField('summary');
			$dauer = $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.= '...';
				}
			}
				
			if (strlen(trim($dauer)) == 0) {
				$dauer = strip_tags($article->getContent('CMS_HTML', 2));
				$dauer2 = $dauer;
				$dauer = capiStrTrimAfterWord($dauer, $mxtext);
				if ($dauer!=$dauer2) {
					$teasertext.= '...';
				}				
				
			} // end if   			

			$teasertext = $teasertext."&nbsp;".$next;
			$dauer = $dauer."&nbsp;".$next;
			
			$tpl->set('d', 'HEADLINE', $teaserheadline);
			$tpl->set('d', 'TEXT', $teasertext);
			$tpl->set('d', 'DAUER', $dauer);
			$tpl->set('d', 'HREF', $href);
			$tpl->set('d', 'IMG', $teaser_img);
			$tpl->set('d', 'MORE', mi18n("mehr"));

			$tpl->next();

		} // end for

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

	}
}
?>
Grüsse, Guido

"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."
Mostly Harmless - Douglas Adams
HerrB
Beiträge: 6935
Registriert: Do 22. Mai 2003, 12:44
Wohnort: Berlin
Kontaktdaten:

Beitrag von HerrB »

Da haste Trauer. Du arbeitest mit einer Klasse (ArticleCollection), die Abfrage steht in contenido/classes/class.article.php.

Dieser Code im Output übergibt die notwendigen Parameter:

Code: Alles auswählen

$options = array ('idcat' => $selcat, "start" => false, "order" => $order); 

   $list = new ArticleCollection($options); 
Daraus wird in der Klasse:

Code: Alles auswählen

$sql .= ' ORDER BY a.'.$this->order.' '.$this->direction.'';
Und da kommt Dein a. her. Du musst für Deinen Zweck das Modul komplett umprogrammieren, die Klasse kannst Du nicht für Deinen Zweck verwenden...

Gruß
HerrB
Bitte keine unaufgeforderten PMs oder E-Mails -> use da Forum!

Newsletter: V4.4.x | V4.6.0-15 (Module, Backend) | V4.6.22+
Standardartikelliste: V4.4.x | V4.6.x
http://www.contenido.org/forum/search.php | http://faq.contenido.org | http://www.communido.net
mvf
Beiträge: 1758
Registriert: Mo 1. Aug 2005, 00:35
Wohnort: in der schönen Hallertau, mitten im Hopfen
Kontaktdaten:

Beitrag von mvf »

na supi ;) da hätte ich lange suchen können

aber wieder was gelernt!

gibt es denn ähnliches 'artikel-preview' modul, dass headline und content , eventuell noch image ausgibt, und bei dem man einfacher das ORDER BY auf RAND() bringen kann?
Grüsse, Guido

"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."
Mostly Harmless - Douglas Adams
Gesperrt