Page 1 of 2

MOST_READ : front end code to add

Posted: Mon 20. Dec 2004, 17:31
by erwanpia
I created this new tag : MOST_READ, works like NEWS

code to add in front.func.inc.php :

Code: Select all


function get_most_read_articles($template_default, $max_cnt_links=0, $dbcon) {
	// find all new articles

	$max_cnt_links = intval($max_cnt_links);
	$limit = ($max_cnt_links) ? " LIMIT ".$max_cnt_links : "";
	
	$sql ="SELECT article_id, count( article_id ) c
FROM ".DB_PREPEND."article_read_count
GROUP BY article_id
ORDER BY c DESC, date_read desc  
$limit ";
	$arr_id=array();
	$arr_count=array();
	if($result = mysql_query($sql, $dbcon)) {
		$count_results = mysql_num_rows($result); $count = 0;
		while ($row = mysql_fetch_row($result)) 
			{
			array_push($arr_id, $row[0]);
			$arr_count[$row[0]]= $row[1];
			}
reset($arr_id);
	$new_links = "";
	$count_results = count($arr_id); $count = 0;
while (list($k,$v)=each($arr_id))
{
	$sql =	"SELECT article_id, article_title, article_cid, UNIX_TIMESTAMP(article_tstamp) AS article_date ".
			"FROM ".DB_PREPEND."phpwcms_article WHERE ".
			"article_public=1 AND article_aktiv=1 AND article_deleted=0 AND ".
			"article_begin < NOW() AND article_end > NOW()  and article_id = ". $v ;

	// new articles list

	$target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : "";
	if($result = mysql_query($sql, $dbcon)) {
	
		while ($row = mysql_fetch_row($result)) {
			$count++;
			if($template_default["link_length"] && strlen($row[1]) > $template_default["link_length"]) {
				$article_title = substr($row[1], 0, $template_default["link_length"]).$template_default["cut_title_add"];
			} else {
				$article_title = $row[1];
			}
			/*if(trim($template_default["date_format"])) {
				$article_title = international_date_format(
									$template_default["date_language"], 
									$template_default["date_format"], 
									$row[3]).$article_title;
			}*/
			$article_title = "&#149; " . $article_title ;
			$show_count = $arr_count[$row[0]] . " readers";
			$new_links .= $template_default["link_before"].$template_default["link_symbol"];
			$new_links .= '<a href="index.php?id='.$row[2].','.$row[0].',0,0,1,0"';
			$new_links .= $target." title='$show_count' alt='$show_count'>".html_specialchars($article_title)."</a>";
			
			//try to remove possible unwanted after - if not enclosed before.link.after
			if($new_links && !$template_default["link_before"] && $count < $count_results) {
				$new_links .= $template_default["link_after"];
			}
		}
		mysql_free_result($result);
	}
}
}
	//enclose whole
	if($new_links) $new_links = $template_default["before"].$new_links.$template_default["after"];
	
	return $new_links;
}
code to add in content.func.inc.php

Code: Select all

// most read article sorted by popularity
if( ! ( strpos($content["all"],'{MOST_READ:')===false ) ) {
	$content["all"] = preg_replace('/\{MOST_READ:(\d+)\}/e','get_most_read_articles($template_default["news"],$1,$db);',$content["all"]);
}
sample on http://ecolopop.free.Fr on the left menu at the bottom

the template for that one is :
(place in left field in template admin)

Code: Select all

<br>
<img src="img/leer.gif" width="1" height="5">
<table cellspacing=0 cellpadding=0 border=0><tr><td><table bgcolor=cccccc cellpadding=0 cellspacing=0 width=100%><tr><td bgcolor=cccccc><img src="img/leer.gif" width="1" height="1"></td></table></td><tr><Th bgcolor=#faffea height=20>Most popular</th><tr><td><img src="img/leer.gif" width="1" height="1"></td><tr><td><table bgcolor=cccccc cellpadding=0 cellspacing=0 width=100%><tr><td bgcolor=cccccc><img src="img/leer.gif" width="1" height="1"></td></table></td><tr><td><table><tr><td>{MOST_READ:5}</td></table></td><tr><td><img src="img/leer.gif" width="1" height="1"></td><tr><td><table bgcolor=cccccc cellpadding=0 cellspacing=0 width=100%><tr><td bgcolor=cccccc><img src="img/leer.gif" width="1" height="1"></td></table></td></table>

Posted: Mon 20. Dec 2004, 18:29
by brans
ouhm maybe you should better use the frontend init and render Folder for creating new replacement tags instead of changing core files ?!?

see the changelog.txt for hints on render and init folder or search this forum for init folder and author brans ... there you will find some hints on how to use it!

Posted: Tue 21. Dec 2004, 21:15
by Pappnase
hello

if you would get this replacement tag as a php script like brans discribe.
and other also create new replacement tags send it to me an i will open an replacement tag download area at the docu site!!

Posted: Tue 21. Dec 2004, 22:06
by frold
Pappnase wrote:hello

if you would get this replacement tag as a php script like brans discribe.
and other also create new replacement tags send it to me an i will open an replacement tag download area at the docu site!!
Good idea, maybe you also could make a mod section when v1.2 is out - a v1.2 valid mod section - so we only have to visit one site to find mods and info

what about a template database... :?:

Posted: Tue 21. Dec 2004, 22:28
by Pappnase
hello

a template database is an good idea! i also write in this case a few month ago an thread. but it cames no response.

but i will not make an mod database as long as there so many source code editing is needed. :!:

Posted: Tue 21. Dec 2004, 22:41
by frold
Pappnase wrote: but i will not make an mod database as long as there so many source code editing is needed. :!:
Ofcouse you need to edit the sourcecode - there is no plugin function yet

Posted: Tue 21. Dec 2004, 22:47
by Pappnase
hello

yes thats true. but i hope that this function will come!

Posted: Wed 22. Dec 2004, 08:45
by brans
öhm mates I guess that most mods could be realized through using the init and render folder! Maybe you would have to increase the size of your scripts a little bit but if this is the condition for not editing the core code anymore, why not ?

Posted: Wed 22. Dec 2004, 10:01
by Pappnase
brans wrote:öhm mates I guess that most mods could be realized through using the init and render folder! Maybe you would have to increase the size of your scripts a little bit but if this is the condition for not editing the core code anymore, why not ?
hello brans

i have thought that too. but son't write cos i'm a php dummy. :oops: :wink:

Posted: Wed 22. Dec 2004, 10:32
by brans
so am I ;-)

so maybe the mod coding guidelines should be updated... I think they have their roots in a time when the init and render folder hadn't been created...

Posted: Tue 28. Dec 2004, 19:31
by creep
Sorry, where is the table article_read_count ? :shock:

Code: Select all

   $sql ="SELECT article_id, count( article_id ) c 
FROM ".DB_PREPEND."article_read_count 
GROUP BY article_id 
ORDER BY c DESC, date_read desc  
$limit "; 

Posted: Tue 4. Jan 2005, 09:53
by erwanpia
table article_read_count is in a previous post :

http://phpwcms.de/forum/viewtopic.php?t=4816

little prob with article count - HELP NEEDED

Posted: Thu 27. Jan 2005, 10:32
by lady_witchcraft
hy guys - got a little problem with your hack - this is the failure the page reports - what does it mean? i followed every step in your old and this post to implement the code - please help me!? thx in advance :oops:

failure: "sql error : count_sql - insert into article_read_count values(now() , 17,3) "

Posted: Thu 27. Jan 2005, 11:28
by marcus@localhorst
hi,

i've tried to put that script in the frontend_render but I see there are many variables not available.
is there a solution?

marcus

Posted: Wed 16. Feb 2005, 16:25
by brans
hi marcus, what variables are not available ?