Very cool replacement tag, and the latest version seems to work well on my 1.2.3 install. Definite plus for PHPwcms.
However, I have one request for the next version. Can you possibly incorporate another variable into the tag that allows the us to specify a summary list template to use for the teaser list being formed?
Basically a big shortcoming of PHPwcms right now is that you can only specify a single summary list for a given article across the site. For example, I have news pieces that appear one way in the home page, another in the news main page, and yet another in the news archive page. However, I can only specify one summary format in the article page of the news pieces at present.
What would be great is if, in the TEASER_EX tag I use on each of those pages I could specify the summary list .TMPL file to be used. This would let me just create a new TMPL for a certain type of display.
I would do it myself but my PHP isn't that solid, and I had a little trouble figuring out how the variables get parsed from the tag to grab the setting and use it to set the template name.
I hadn't really looked to closely at this... just a little lazy I guess. I added this into my teaser ex RT. Basically you just add on a digit in the RT parser, give it a name in the function init, and then put in some logic in the template parser down below. I basically had mine use the default logic if the variable is blank, but use the specified TMPL if its present.
Code: Select all
<?php
// TEASER_EX replacementtag (by Erich Munz, 2005)
//
// Version 1.06
//
// Tested with phpwcms ver 1.2.3 DEV
//
// copy this file to phpwcms_template\inc_script\frontend_render
//
// Syntax: {TEASER_EX:category_alias|count[;category_aliasx|countx]:articles_per_page:sortfield|sortdir:show_cat_name:pagelink_text:columns:exclude_articles}
//
// category_alias Name of the category to get the articles from
// count Number of articles to show from this category, -1 for all articles
// ------------------
// articles_per_page Number of articles on one page, -1 all articles on one page
// ------------------
// sortfield VALUES default, article_created, article_tstamp, article_begin, article_end, article_title
// sortdir sort direction VALUES - ASC (ascending) or DESC (descending)
// ------------------
// show_cat_name Show the categroy name VALUES - 0 = no, 1= Yes
// ------------------
// pagelink_text Pagelinktext e.g. Page or Seite
// ------------------
// columns Number of columns VALUES >= 1
// To format the Table and the Tablecells you can use the CSS-Values teaserTable, teaserTableLeftCell and teaserTableRightCell
// in the "default css"-section of the backend
// e.g.
// #teaserTable {border:1px solid #FFFFFF; border-collapse:collapse;}
// #teaserTableLeftCell {border-left:1px solid #C4C4C4; padding:4px;}
// #teaserTableRightCell {border-left:1px solid #C4C4C4; padding:4px;}
// ------------------
// exclude_articles List of article id's
// VALUES e.g. 10,15,23 or empty
// These articles are not visible in the result list
// useful if your "TEASER_EX Article" is in the same category as the articles
//
// example: {TEASER_EX:en_general|3;en_fairs|-1;en_jobs|-1:3:article_begin|DESC:1:Page:1:10,15,23}
// {TEASER_EX:en_general|3:6:default:0:Seite:2:}
//----------------------------------------------
// Mainpart
//
//----------------------------------------------
function get_teaser_ex_content2 ($c_reqdata, $c_displaycount = -1, $c_sort, $c_showcat_name = 0 , $c_pagelinktext, $c_columns = 1, $c_article_id, $c_listemp_id, $db)
{
global $template_default, $phpwcms;
if ($c_reqdata)
{
$c_displaycount = intval($c_displaycount);
if ($c_displaycount <= 0) $c_displaycount = 100000; // All news on one page
$c_columns = intval($c_columns);
if ($c_columns <= 0) $c_columns = 1;
$articles_per_column = round($c_displaycount/$c_columns);
$colwidth = round(100/$c_columns);
$recordcount = 0;
$array_sort = explode("|", $c_sort);
$show_news_from = intval($_GET['f']);
$catalias = $GLOBALS['content']['struct'][$GLOBALS['content']['cat_id']]['acat_alias'];
if(!$phpwcms["rewrite_url"])
$refurl = $_SERVER['PHP_SELF']."?".$catalias;
else
$refurl = $catalias;
$array_alias = explode(";", $c_reqdata);
$sqlwhere = "";
for ($i = 0; $i <= count($array_alias)-1; $i++)
{
$aliasdata = explode("|", $array_alias[$i]);
$alias[$i] = array('cat_alias' => $aliasdata[0],
'topcount' => $aliasdata[1],
'acat_id' => '',
'acat_name' => '');
$sqlwhere .= "'".aporeplace($alias[$i]['cat_alias'])."',";
}
$sqlwhere = substr($sqlwhere, 0, -1);
$sql = "SELECT acat_id, acat_name FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_alias IN (".$sqlwhere.");";
if ($result = mysql_query($sql, $db))
{
for ($i = 0; $i <= mysql_num_rows($result)-1; $i++)
{
mysql_data_seek($result, $i);
$row = mysql_fetch_array ($result);
$alias[$i]['acat_id'] = $row[0];
$alias[$i]['acat_name'] = $row[1];
}
mysql_free_result($result);
$article_list = array();
// VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
switch(VISIBLE_MODE)
{
case 0:
$sql_VISIBLE_MODE = " AND article_public=1 AND article_aktiv=1";
break;
case 1:
$sql_VISIBLE_MODE = " AND article_uid=".$_SESSION["wcs_user_id"];
break;
//case 2: admin mode no additional neccessary
default:
$sql_VISIBLE_MODE = "";
}
$sql = "";
if (!$array_sort[0] or $array_sort[0] == 'default') $array_sort[0] = 'article_sort ';
$sqlorder = " ORDER BY ".$array_sort[0]." ".$array_sort[1];
if (count($array_alias) == 1)
{
$sql .= "SELECT *, '".$alias[0]['acat_name']."' AS catname, UNIX_TIMESTAMP(article_tstamp) AS article_date FROM ".DB_PREPEND."phpwcms_article ";
$sql .= " WHERE article_cid = '".$alias[0]['acat_id']."'";
$sql .= $sql_VISIBLE_MODE;
$sql .= " AND article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ";
if ($c_article_id) $sql .= " AND article_id NOT IN ($c_article_id) ";
$sql .= $sqlorder;
if ($alias[0]['topcount'] >= 1) $sql .= " LIMIT ".$alias[0]['topcount'];
}
else
{
for ($i = 0; $i <= count($array_alias)-1; $i++)
{
$sql .= "( SELECT *, '".$alias[$i]['acat_name']."' AS catname, UNIX_TIMESTAMP(article_tstamp) AS article_date FROM ".DB_PREPEND."phpwcms_article ";
$sql .= " WHERE article_cid = '".$alias[$i]['acat_id']."'";
$sql .= $sql_VISIBLE_MODE;
$sql .= " AND article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ";
if ($c_article_id) $sql .= " AND article_id NOT IN ($c_article_id) ";
if ($alias[$i]['topcount'] >= 1) $sql .= " LIMIT ".$alias[$i]['topcount'];
$sql .= " ) ";
$sql .= " UNION ";
}
$sql = substr($sql, 0, -6);
$sql .= $sqlorder;
}
$result = mysql_query($sql, $db);
$recordcount = mysql_num_rows($result);
#PageLinks
$pages = ceil($recordcount/$c_displaycount);
if ($pages > 1)
{
$pagelinks = '<div id="teaserPageNav">'.$c_pagelinktext." ";
for ($i = 1; $i <= $pages; $i++)
{
$nextitem = $i * $c_displaycount-$c_displaycount;
$page = $show_news_from/$c_displaycount+1;
if ($i == $page)
{
$pagelinks = $pagelinks." <span id=\"teaserPageNavItems\">".$i."</span> ";
}
else
{
if(!$phpwcms["rewrite_url"])
{
$pagelinks = $pagelinks.' <a id="teaserPageNavItems" href="'.$refurl.'&f='.$nextitem.'">'.$i.'</a> ';
}
else
{
if (strpos($refurl, '&f=') === true)
{
$a_refurl = explode("&", $refurl);
$refurl = $a_refurl[0];
}
else
{
$a_refurl = explode(".", $refurl);
$refurl = $a_refurl[0];
}
$pagelinks = $pagelinks.' <a id="teaserPageNavItems" href="'.$refurl.'&f='.$nextitem.'.phtml">'.$i.'</a> ';
}
}
}
$pagelinks .= '</div>';
}
else
{
$pagelinks = '';
}
if ($show_news_from + $c_displaycount > $recordcount )
{
$lastrow = $recordcount;
}
else
{
$lastrow = $show_news_from+$c_displaycount;
}
if ($result)
{
for ($i = $show_news_from; $i <= $lastrow-1; $i++)
{
mysql_data_seek($result, $i);
$row = mysql_fetch_array ($result);
$article_list[$row["article_id"]] = array(
"article_id" => $row["article_id"],
"article_cid" => $row["article_cid"],
"article_title" => $row["article_title"],
"article_subtitle" => $row["article_subtitle"],
"article_keyword" => $row["article_keyword"],
"article_summary" => $row["article_summary"],
"article_redirect" => $row["article_redirect"],
"article_date" => $row["article_date"],
"article_username" => $row["article_username"],
"article_sort" => $row["article_sort"],
"article_notitle" => $row["article_notitle"],
"article_created" => $row["article_created"],
"article_image" => unserialize($row["article_image"]),
"article_timeout" => $row["article_cache"],
"article_nosearch" => $row["article_nosearch"],
"article_nositemap" => $row["article_nositemap"],
"article_catname" => $row["catname"] );
}
mysql_free_result($result);
}
//print_r ($article_list);
$listing = '';
if ($template_default["space_top"]) //start with space at top
$listing .= '<img src="img/leer.gif" border="0" width="20" height="'.$template_default["space_top"].'" alt="" /><br>';
$listing .= "\n<!-- START NEWS TABLE -->\n<table id=\"teaserTable\"><tr><td id=\"teaserTableLeftCell\" valign=\"top\" width=\"$colwidth%\">";
$tmpllist = array(); //temporary array for storing templates to minimize load
$articlecount = 0;
foreach($article_list as $key => $value)
{
if ($articlecount >= $articles_per_column)
{
$listing .= "</td><td id=\"teaserTableRightCell\" valign=\"top\" width=\"$colwidth%\">";
$articlecount = 0;
}
//$article_link = $link_to."?id=".$cat_id.",".$article_list[$key]["article_id"].",0,0,1,0";
$article_link = "index.php?id=".$article_list[$key]["article_cid"].",".$article_list[$key]["article_id"].",0,0,1,0";
//add available keywords to page wide keyword field
$GLOBALS['content']['all_keywords'] .= $article_list[$key]["article_keyword"].',';
// build image/image link
$article_list[$key]["article_image"]["poplink"] = '';
$thumb_image = false;
$thumb_img = '';
if (!empty($article_list[$key]["article_image"]["caption"]))
{
$caption = explode('|', $article_list[$key]["article_image"]["caption"]);
}
else
{
$caption[0] = '';
}
$article_list[$key]["article_image"]["caption"] = $caption[0]; //$caption[0]
if (!empty($article_list[$key]["article_image"]["hash"]))
{
$thumb_image = get_cached_image(array("target_ext" => $article_list[$key]["article_image"]['ext'],
"image_name" => $article_list[$key]["article_image"]['hash'] . '.' . $article_list[$key]["article_image"]['ext'],
"max_width" => $article_list[$key]["article_image"]['width'],
"max_height" => $article_list[$key]["article_image"]['height'],
"thumb_name" => md5($article_list[$key]["article_image"]['hash'].$article_list[$key]["article_image"]['width'].$article_list[$key]["article_image"]['height'].$GLOBALS['phpwcms']["sharpen_level"])
));
if ($thumb_image != false)
{
$caption[1] = (!isset($caption[1])) ? '' :
html_specialchars($caption[1]);
if (!isset($caption[2]))
{
$caption[2] = array('', ' target="_blank"');
}
else
{
//proof target of link
$caption[2] = explode(' ', trim($caption[2]));
$caption[2][1] = (!isset($caption[2][1])) ? '' :
' target="'.$caption[2][1].'"';
}
$thumb_img = '<img src="'.PHPWCMS_IMAGES . $thumb_image[0] .'" border="0" '.$thumb_image[3].' alt="'.$caption[1].'" title="'.$caption[1].'">';
if ($article_list[$key]["article_image"]["zoom"])
{
$zoominfo = get_cached_image(array("target_ext" => $article_list[$key]["article_image"]['ext'],
"image_name" => $article_list[$key]["article_image"]['hash'] . '.' . $article_list[$key]["article_image"]['ext'],
"max_width" => $GLOBALS['phpwcms']["img_prev_width"],
"max_height" => $GLOBALS['phpwcms']["img_prev_height"],
"thumb_name" => md5($article_list[$key]["article_image"]['hash'].$GLOBALS['phpwcms']["img_prev_width"].$GLOBALS['phpwcms']["img_prev_height"].$GLOBALS['phpwcms']["sharpen_level"])
)
);
if ($zoominfo != false)
{
$article_list[$key]["article_image"]["poplink"] = 'image_zoom.php?show='.base64_encode($zoominfo[0].'?'.$zoominfo[3]);
if (!empty($caption[2][0]))
{
$open_link = $caption[2][0];
$return_false = '';
}
else
{
$open_link = $article_list[$key]["article_image"]["poplink"];
$return_false = 'return false;';
}
$article_list[$key]["article_image"]["poplink"] = '<a href="'.$article_list[$key]["article_image"]["poplink"].'" '. 'onClick="window.open(\''.$open_link. "','previewpic','width=".$zoominfo[1]. ",height=".$zoominfo[2]."');".$return_false. '"'.$caption[2][1].'>'.$thumb_img.'</a>';
}
unset($caption);
}
}
}
// article list based template check
if (!empty($article_list[$key]["article_image"]['tmpllist']) && $article_list[$key]["article_image"]['tmpllist'] != 'default')
{
// try to read the template files
// 1. try to check if template was read
if (!isset($tmpllist[ $article_list[$key]["article_image"]['tmpllist'] ]))
{
[color=red]// RT EDIT: added template variable
if ($c_listemp_id == '') {
$tmpllist[ $article_list[$key]["article_image"]['tmpllist'] ] = include_ext_php(PHPWCMS_ROOT.$GLOBALS['phpwcms']['templates'].'inc_cntpart/articlesummary/list/'.$article_list[$key]["article_image"]['tmpllist'], 1);
}
else {
$tmpllist[ $article_list[$key]["article_image"]['tmpllist'] ] = include_ext_php(PHPWCMS_ROOT.$GLOBALS['phpwcms']['templates'].'inc_cntpart/articlesummary/list/'.$c_listemp_id, 1);[/color]
}
}
if ($tmpllist[ $article_list[$key]["article_image"]['tmpllist'] ])
{
//rendering
$tmpl = $tmpllist[ $article_list[$key]["article_image"]['tmpllist'] ];
if ($c_showcat_name == 1)
{
$tmpl = render_cnt_template($tmpl, 'TITLE', html_specialchars($article_list[$key]["article_catname"]." - ".$article_list[$key]["article_title"]));
}
else
{
$tmpl = render_cnt_template($tmpl, 'TITLE', html_specialchars($article_list[$key]["article_title"]));
}
$tmpl = render_cnt_template($tmpl, 'SUB', html_specialchars($article_list[$key]["article_subtitle"]));
$tmpl = render_cnt_template($tmpl, 'SUMMARY', $article_list[$key]["article_summary"]);
$tmpl = render_cnt_template($tmpl, 'IMAGE', $thumb_img);
$tmpl = render_cnt_template($tmpl, 'ZOOMIMAGE', $article_list[$key]["article_image"]["poplink"]);
$tmpl = render_cnt_template($tmpl, 'CAPTION', nl2br(html_specialchars($article_list[$key]["article_image"]["caption"])));
$tmpl = render_cnt_template($tmpl, 'ARTICLELINK', $article_link);
$tmpl = render_cnt_template($tmpl, 'EDITOR', $article_list[$key]["article_username"]);
$tmpl = render_cnt_template($tmpl, 'ARTICLEID', $article_list[$key]["article_id"]);
$tmpl = render_cnt_template($tmpl, 'MORE', $template_default["top_readmore_link"]);
$tmpl = render_cnt_template($tmpl, 'BEFORE', '<!--before//-->');
$tmpl = render_cnt_template($tmpl, 'AFTER', '<!--after//-->');
$tmpl = render_cnt_date($tmpl, $article_list[$key]["article_date"]);
if ($articlecount > 0)
{
$tmpl = render_cnt_template($tmpl, 'SPACE', '<!--space//-->');
}
else
{
$tmpl = render_cnt_template($tmpl, 'SPACE', '');
}
$listing .= $tmpl;
$article_list[$key]["article_image"]['tmpllist'] = 1;
}
else
{
$article_list[$key]["article_image"]['tmpllist'] = 0;
}
}
else // do the standard template redering
{
$listing .= $template_default["top_listentry_before"];
// space between summary listings
if ($articlecount > 0)
{
$listing .= $template_default["space_between_sum"];
}
if ($article_list[$key]["article_title"] && !$article_list[$key]["article_notitle"])
{
//$listing .= get_html_part($article_list[$key]["article_title"], $template_default["top_headline_class"], $article_link);
$listing .= $template_default["top_headline_before"];
$listing .= '<a href="'.$article_link.'">';
if ($c_showcat_name == 1)
{
$listing .= html_specialchars($article_list[$key]["article_catname"]." - ".$article_list[$key]["article_title"]);
}
else
{
$listing .= html_specialchars($article_list[$key]["article_title"]);
}
$listing .= '</a>';
$listing .= $template_default["top_headline_after"];
$listing .= $template_default["top_headline_space"];
}
if ($article_list[$key]["article_subtitle"])
{
//$listing .= get_html_part($article_list[$key]["article_subtitle"], $template_default["top_subheadline_class"], $article_link);
$listing .= $template_default["top_subheadline_before"];
$listing .= '<a href="'.$article_link.'">';
$listing .= html_specialchars($article_list[$key]["article_subtitle"]);
$listing .= '</a>';
$listing .= $template_default["top_subheadline_after"];
$listing .= $template_default["top_subheadline_space"];
}
if ($article_list[$key]["article_summary"] || !empty($article_list[$key]["article_image"]['cname']))
{
//$listing .= "<span class=\"".$template_default["top_text_class"]."\">";
$listing .= $template_default["top_text_before"];
//build image table when image available
if (!empty($thumb_img))
{
$listing .= '<table width="1%" cellspacing="0" border="0" cellpadding="0" align="left" ';
if ($template_default["article"]["image_table_bgcolor"])
{
$listing .= 'bgcolor="'.$template_default["article"]["image_table_bgcolor"].'" ';
}
$listing .= 'style="float:left;margin:2px 5px 3px 0;">';
$listing .= "\n<tr><td>".'<a href="'.$article_link.'">';
$listing .= $thumb_img."</a></td></tr>\n";
if ($article_list[$key]["article_image"]["caption"])
{
$listing .= '<tr><td><img src="img/leer.gif" alt="" width="1" height="3"></td></tr>';
$listing .= "\n<tr><td";
if ($template_default["article"]["image_caption_class"])
{
$listing .= ' class="'.$template_default["article"]["image_caption_class"].'"';
}
if ($template_default["article"]["image_caption_bgcolor"])
{
$listing .= ' bgcolor="'.$template_default["article"]["image_caption_bgcolor"].'"';
}
if ($template_default["article"]["image_caption_valign"])
{
$listing .= ' valign="'.$template_default["article"]["image_caption_valign"].'"';
}
if ($template_default["article"]["image_caption_align"])
{
$listing .= ' align="'.$template_default["article"]["image_caption_align"].'"';
}
$listing .= '>';
$listing .= $template_default["article"]["image_caption_before"];
$listing .= nl2br(html_specialchars($article_list[$key]["article_image"]["caption"]));
$listing .= $template_default["article"]["image_caption_after"];
$listing .= "</td></tr>\n";
}
$listing .= '</table>';
}
$listing .= $article_list[$key]["article_summary"];
$listing .= $template_default["top_readmore_before"];
$listing .= '<a href="'.$article_link.'">';
$listing .= $template_default["top_readmore_link"];
//$listing .= "</a>".$template_default["top_readmore_after"]."</span>";
$listing .= '</a>'.$template_default["top_readmore_after"];
$listing .= $template_default["top_text_after"];
}
$listing .= $template_default["top_listentry_after"];
}
$articlecount++;
}
$listing .= "</td></tr></table>\n<!-- END NEWS TABLE -->\n";
if ($c_displaycount < 100000) $listing .= "<p>$pagelinks</p>\n";
if ($template_default["space_bottom"]) //ends with space at bottom
$listing .= '<img src="img/leer.gif" border="0" width="20" height="'.$template_default["space_bottom"].'" alt="" /><br>';
return str_replace("<br /><br />", "<br />", $listing);
}
return '';
}
return '';
}
// -------------------------------------------------------------
$content["all"] = preg_replace('/\{TEASER_EX2:(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?)\}/ie', 'get_teaser_ex_content2("$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", $db);', $content["all"]);
// -------------------------------------------------------------
?>