<?php

global $storyhome;

$filetemplate = "archive.tpl";
$fp = fopen($filetemplate, "r"); 
$filecontent= fread($fp, filesize($filetemplate)); 
fclose($fp); 

preg_match_all( '/\{.*?\}/', $filecontent, $topiclist ); 

//get last topic number
//$xstroy = $storyhome-1;
//$result = mysql_query ("select sid from " . $prefix . "_stories where order by sid desc limit $xstroy,1");
//list ($laststory) = mysql_fetch_row($result);
//mysql_free_result ($result);


foreach ($topiclist[0] as $onetopic) { 

	$thisnews="";
	$splittopic = split (",",$onetopic);
	$topicno = $splittopic[0];
	$topiclimit = $splittopic[1];
	$topicno=str_replace(array('{', '}'), "", $topicno);
	$topiclimit=str_replace(array('{', '}'), "", $topiclimit);

//	$result = mysql_query ("select sid,title from " . $prefix . "_stories where topic='$topicno' and sid<$laststory order by sid desc limit $topiclimit");
	$result = mysql_query ("select sid,title from " . $prefix . "_stories where topic='$topicno' order by sid desc limit $topiclimit");
	if (mysql_num_rows($result)>0) {
		while (list($artid,$arttitle) = mysql_fetch_row ($result)) {
			$thisnews .= "<li><a class=\"arch\" href=\"modules.php?name=News&file=article&sid=$artid\">$arttitle</a><br>";
		}
	} else {
		$thisnews = "";
	}

	$pattern = "{" . $topicno ."," . $topiclimit . "}";
	$filecontent=str_replace($pattern, $thisnews, $filecontent);		

} 

echo $filecontent;

?>