supesite自动更新html静态化文件
1,修改function/cache.func.php
添加函数
| function updatehtmlcache($dir) { if(!$dir) $dir = S_ROOT.'html'; if (rmdir($dir)==false && is_dir($dir)) { if ($dp = opendir($dir)) { while (($file=readdir($dp)) != false) { if (is_dir($dir.'/'.$file) && $file!='.' && $file!='..') { updatehtmlcache($dir.'/'.$file); }else { unlink($dir.'/'.$file); } } closedir($dp); } else { exit('Not permission'); } } } |
2,新建include/cron/updatedelhtml.php
| if(!defined('IN_SUPESITE')) { exit('Access Denied'); } include_once(S_ROOT.'./function/cache.func.php'); updatehtmlcache(); |
3,由于清除HTML后,会导致/htm/*/*访问404错误,所以在虚机中设置ErrorDocument
ErrorDocument 404 /error.php
蘑菇习惯开启其他错误一起到/error.php,在此不再讨论,同学们可以自行设置。
修改完成后重启apache
4,在网站根目录添加error.php
| <?php $url = $_SERVER["REQUEST_URI"]; //新闻最终页 preg_match('/\/html\/\d+\/n-(.*?)-(.*?)\.html(.*)/',$url,$out); if($out[1]&&$out[2]){ header('Location:/?action-viewnews-itemid-'.intval($out[1]).'-page-'.intval($out[2])); exit(); } preg_match('/\/html\/\d+\/n-(.*?)\.html(.*)/',$url,$out); if($out[1]){ header('Location:/?action-viewnews-itemid-'.intval($out[1])); exit(); } //分类列表页 preg_match('/\/html\/\d+\/category\-catid\-(.*?)\-page\-(.*?)\.html(.*)/',$url,$out); if($catid = intval($out[1])){ header('Location:/?action-category-catid-'.$out[1].'-page-'.$out[2]); exit(); } preg_match('/\/html\/\d+\/category\-catid\-(.*?)\.html(.*)/',$url,$out); if($catid = intval($out[1])){ header('Location:/?action-category-catid-'.$out[1]); exit(); } //首页 preg_match('/\/html\/index\.html(.*)/',$url,$out); if($out[0]){ header('Location:/'); exit; } //频道首页 preg_match('/\/html\/(.*?)\.html(.*)/',$url,$out); if($out[1]){ header('Location:/?action-'.$out[1]); exit(); } include($_SERVER['DOCUMENT_ROOT'].'/error.html'); ?> |
5,在计划任务中添加此任务
6,ok,测试一下吧
ps:补充一点,去掉ss自动判断时间的js代码,在function/common.func.php中,隐藏下面代码
| /* $theurl = S_URL_ALL.'/index.php?'.arraytostring($_SHTML); $codearr = array( 'url' => rawurlencode($theurl), 'maketime' => $_SGLOBAL['timestamp'], 'updatetime' => $_SGLOBAL['htmlfile']['updatetime'], 'uid' => empty($_SHTML['uid'])?0:$_SHTML['uid'], 'itemid' => empty($_SHTML['itemid'])?0:$_SHTML['itemid'], 'action' => $_SHTML['action'] ); $code = rawurlencode(implode('/', $codearr)); $content .= ' <script language="javascript"> <!-- var Modified = new Date(document.lastModified); var copyright = document.getElementById("xspace-copyright"); if(copyright) { copyright.innerHTML += "Last update: <a href=\"'.$theurl.'/php/1\" title=\"'.$lang['the_page_can_be_updated_immediately_hits'].'\">"+(Modified.getYear()<200?(Modified.getYear()+1900):Modified.getYear())+"-"+(Modified.getMonth()+1)+"-"+Modified.getDate()+" "+Modified.getHours()+":"+Modified.getMinutes()+":"+Modified.getSeconds() + "</a><br>"; } document.write(\'<script src="'.S_URL.'/batch.html.php?code='.$code.'&lastmodified=\' + Modified.getTime() + \'" type="text\/javascript" language="javascript"><\/script>\'); //--> </script>';*/ |



