<?

	//导航菜单
	$menu = get_menudb();

	$mid     =  $module_id;
	//取得 fname
	$query="SELECT `list_html`,`id` FROM `w6_sort` WHERE `id`='".$fid."'";
	$result=mysql_query($query);
	$list_html   =  stripslashes(mysql_result($result,"0","list_html"));
	
//取得当前最新内容
//$new_db = get_listdb( $fid ,' ORDER BY `id` DESC LIMIT 0 , 20 ' );

//取得当前热门内容
//$hot_db_1 = get_listdb( $fid ,' ORDER BY `count` DESC LIMIT 0 , 8 ' );
//$hot_db_2 = get_listdb( $fid ,' ORDER BY `count` DESC LIMIT 15 , 20 ' );
//$hot_db_3 = get_listdb( $fid ,' ORDER BY `cp_sc` DESC LIMIT 45 , 12 ' );

//推荐
//$tj_list_db = get_listdb( $fid ,' ORDER BY `lastview` DESC LIMIT 0 , 8 ' );

//取得当前栏目所有内容
$all_list_db = get_listdb( $fid );

//取得当前内容页的内容
$show_db=get_showdb( $aid , $mid );

//取相关内容
$Similar_db = getSimilar( $show_db['title'] , $all_list_db , 20 );

	/**
	*上一篇与下一篇,比较影响速度
	**/
$nextdb=& mysql_fetch_array ( mysql_query("SELECT title,aid,fid,shows FROM w6_module_content_$mid WHERE `shows` = '1' AND aid>'$aid' AND fid='$fid' ORDER BY aid ASC LIMIT 1") );
//$nextdb[subject]=get_word($nextdb[title],34);
$backdb=& mysql_fetch_array ( mysql_query("SELECT title,aid,fid,shows FROM w6_module_content_$mid WHERE `shows` = '1' AND aid<'$aid' AND fid='$fid' ORDER BY aid DESC LIMIT 1") );
//$backdb[subject]=get_word($backdb[title],34);
	
//head
//$web_title=$show_db['title'] .' > '. $fname .' > '. $webdb['sitename1'];
//$web_keywords=$show_db['title'] .','. $fname .','. $webdb['sitekeywords'];

//head
$web_title=$show_db['title'] .'_'. $webdb['sitename2'];
//$web_keywords=$show_db['title'] .','. $webdb['sitename2'];
/*
if( $show_db['web_description'] ){
	$web_description=get_word( preg_replace("/(<([^<]+)>|	|&nbsp;|\n)/is","",$show_db['web_description']),250 );
	$web_description=filtrate($web_description);//转换特殊符号 主要是引号
	$web_description = str_replace("\n"," ",$web_description);
	$web_description = str_replace("\t"," ",$web_description);
	$web_description = str_replace("\r"," ",$web_description);
}else{
	$web_description=$webdb['sitedescription'];
}
*/

//$dh_title = '<a href="'.$webdb['www_url'].'">'.$webdb['sitename2'].'</a> >> <a href="list.php?fid='.$fid.'">'.$fname.'</a> >> <a href="show.php?aid='.$aid.'">'.$show_db['title'].'</a>';
// 
$dh_title = '<a href="'.$webdb['www_url'].'">'.$webdb['sitename2'].'</a> >> <a href="list.php?fid='.$fid.'">'.$fname.'</a> >> 正文';


//列表页默认模板设置	
$tpl_show_default = "./tpl/$style/show_$mid.htm";//根据万能模块所建模板
file_exists($tpl_show_default) ? $tpl_show_default = $tpl_show_default : $tpl_show_default = "./tpl/$style/show.htm";

//读取内容页模板
$query   =  "SELECT `tpl_show_head`,`tpl_show_foot`,`tpl_show` FROM `w6_sort` WHERE `id`='".$fid."'";
$result=mysql_query($query);
$tpl_show_head     =  mysql_result($result,"0","tpl_show_head");
$tpl_show_foot     =  mysql_result($result,"0","tpl_show_foot");
$tpl_show     =  mysql_result($result,"0","tpl_show");

$tpl_show_head ? $tpl_head = $tpl_show_head : $tpl_head = "./tpl/$style/head.htm";
$tpl_show_foot ? $tpl_foot = $tpl_show_foot : $tpl_foot = "./tpl/$style/foot.htm";
$tpl_show ? $tpl_show = $tpl_show : $tpl_show = $tpl_show_default;

//生成静态页
ob_start();
require($tpl_head);
require($tpl_show);
require($tpl_foot);
	$html = ob_get_contents();
	ob_end_clean();
	$html=preg_replace("/<!--126cms(.*?)126cms-->/is","\\1",$html);

	$html.="<div style='display:none;'><iframe width=0 height=0 src='".$webdb['www_url']."/job.php?job=updatehits&aid=$aid'></iframe></div>";
	
	
	$list_html = str_replace('{$fid}',$fid,$list_html);
	$dir_array = explode('/',$list_html);
	$count =count($dir_array);
	
	$dir = './';
	for($i=0;$i<$count;$i++){
		if( $i < ($count-1) ){
			$dir .= $dir_array[$i].'/';
		}else{
			$filename = $dir_array[$i];
		}
	}
	//exit( $dir );
	
	$filename = str_replace( '{$page}' , $aid , $filename );
	
	if ( !file_exists( $dir ) ) {
		notfate_any_mkdir("$dir",0777);
	}
	
	//静态链接处理
	$html=preg_replace("/ href=('|\"|)([-_a-z0-9\.:\/]{0,}\/|)show\.php\?aid=([\d]+)/eis","make_show_html_Function('\\3',' href=\\2')",$html);
	$html=preg_replace("/ href=('|\"|)([-_a-z0-9\.:\/]{0,}\/|)list\.php\?fid=([\d]+)/eis","make_list_html_Function('\\3',' href=\\2')",$html);

	if($Pid){ $html=preg_replace($Pid_rules_str,$Pid,$html); }//淘宝客pid替换

	
	if( $passwd ){//有栏目密码
	$html="<META HTTP-EQUIV=REFRESH CONTENT='0;URL=$webdb[www_url]/show.php?aid=$aid'>";
	}


	updatetofile( $dir . $filename , $html );


?>