Page 1 of 1

how images are placed into articles?

Posted: Mon 13. Feb 2006, 02:45
by ramone
hello i created a custom tag and a custom function to handle it, it is very similar to the {NEW} tag, but this tag includes the summary and date in the article list, so far i've had no problems but now i want to display the image of each article too, but i'm not sure how phpwcms works with the image configured for each article, here is my function:

Code: Select all

function r_get_new_articles($template_default, $max_cnt_links=0, $cat, $dbcon) {
	// find all new articles
	
	$max_cnt_links = intval($max_cnt_links);
	$limit = ($max_cnt_links) ? " LIMIT ".$max_cnt_links : "";
	$cat = trim($cat);
	$cat = (intval($cat) || $cat == '0') ? 'article_cid='.intval($cat).' AND ' : '';

	if(isset($template_default["sort_by"]) && $template_default["sort_by"] == 'cdate') {
		//use real creation date
		$sql  =	"SELECT ar.article_id, ar.article_title, ar.article_cid, ar.article_created AS article_date, ar.article_summary, ac.acat_alias, ac.acat_name  ";
		$sorting = 'ar.article_created';
	} else {
		$sql  =	"SELECT ar.article_id, ar.article_title, ar.article_cid, UNIX_TIMESTAMP(ar.article_tstamp) AS article_date, ar.article_summary, ac.acat_alias, ac.acat_name  ";
		$sorting = 'ar.article_tstamp';
	}
	$sql .=	"FROM ".DB_PREPEND."phpwcms_article ar join ".DB_PREPEND."phpwcms_articlecat ac on ar.article_cid=ac.acat_id WHERE ".$cat;
	// VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
	switch(VISIBLE_MODE) {
		case 0: $sql .=	"ar.article_public=1 AND ar.article_aktiv=1 AND ";
				break;
		case 1: $sql .= "ar.article_uid=".$_SESSION["wcs_user_id"]." AND ";
				break;
		//case 2: admin mode no additional neccessary
	}
	$sql .= "ar.article_deleted=0 AND ar.article_begin < NOW() AND ar.article_end > NOW() ";
	$sql .= "ORDER BY ".$sorting." DESC".$limit;

	// new articles list
	$new_links = "";
	$target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : "";
	if($result = mysql_query($sql, $dbcon)) {
		$count_results = mysql_num_rows($result); $count = 0;
		while ($row = mysql_fetch_array($result)) {
			$count++;
			$seccionUrl='index.php';
			$seccionT='Inicio';
			if(intval($row['article_cid'])>0){
				
				$seccionT=html_specialchars($row['acat_name']);
				$seccionUrl=($row['acat_alias']=='')?'index.php?id='.$row['article_cid'].',0,0,1,0,0':$row['acat_alias'].'.phtml';
			}
			

				$new_links.="
					<h3 class='lista_titulo'><a href='".$row['article_cid'].'.'.$row['article_id'].".0.0.1.0.phtml'>".html_specialchars($row['article_title'])."</a></h3>
					<span class='lista_info'>".international_date_format("EN","Y/m/d h:i",$row['article_date'])."</span>
					<p class='lista_previo'><!--a href='".$seccionUrl."'>(".$seccionT.")</a--> ".$row['article_summary']."
					<a href='".$row['article_cid'].'.'.$row['article_id'].".0.0.1.0.phtml'>Leer m&aacute;s <img border='0' src='layout/leermas.jpg' /></a>
					</p>
					<!--hr-->
					";

		}
		mysql_free_result($result);
	}

	//enclose whole
	if($new_links) $new_links = $new_links;

	return $new_links;
}
could you tell me how to include in the listing the image for each article??

thank you

Posted: Mon 13. Feb 2006, 04:13
by Pappnase
hello

this is nice!

but maybe you can get it work as external php file for the frontend_init folder :-)
is much more better than to change the source!

Posted: Mon 13. Feb 2006, 19:46
by ramone
yeah in fact all my functions are inside an included file so i have less problems when updating, but i want to know how to retrieve the image for each article, that way i can place a <img> tag in each article in the listing

could you explain me how article's image work please?

thank you

Posted: Sun 23. Jul 2006, 13:10
by jsw_nz
Hi Ramone,

I just came across your post while serching the forums for another (related) topic. I have not taken a close look at your code, but to point you in the right direction with regards to getting the image that is used in article summaries, it is derived from a unserialising OliG's hash method of storing the info..... Just posting this snippet of code for now, hopefully you will make sense of it:

Code: Select all

//get the wcms article image data - need to extract this data from hash

	$specific_article = mysql_query("SELECT * FROM phpwcms_article WHERE article_id = '$this_article_id'"); 
	$article = mysql_fetch_assoc($specific_article);
	$article_image=$article['article_image'];
	if ($article_image){
		$image_array=unserialize($article_image); 
		$thumb_image = get_cached_image(array(
			"ext" =>$image_array['ext'],
			"hash" =>$image_array['hash'].'.'.$image_array['ext'],
			"width"=>$image_array['width'],
			"height" =>$image_array['height'],
			"thumb_name"=>md5($image_array['hash'].$image_array['width'].$image_array['height'].$GLOBALS['phpwcms']["sharpen_level"])));
		$this_article_thumbnail = $thumb_image[0];
		$this_image_size = $thumb_image[3];
		$this_image_size = str_replace('width="','',$this_image_size);
		$this_image_size = str_replace('" height="',',',$this_image_size);
		$this_article_image_size = str_replace('"','',$this_image_size);
	}else{
		$this_article_thumbnail = 'NULL';
		$this_article_image_size = 'NULL';
	} //end if article_image
This code was used in a separate context, so you may have to disregard the str_replace functions that strip out width and height values. Will return to your code and study later. Looks promising.

Cheers,
:D -john-