你的位置:LAMP之窗 >> 资讯 >> SupeSite >> 详细内容 在线投稿

supesite自动更新html静态化文件

热度135票  浏览156次 【共0条评论】【我要评论 时间:2010年3月20日 23:49
         蘑菇发现SupeSite中关于html静态化更新的时间设置不太稳定,经常没有更新,所以蘑菇自己实现一个自动更新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.'&amp;lastmodified=\' + Modified.getTime() + \'" type="text\/javascript" language="javascript"><\/script>\');
            //-->
            </script>';*/

TAG: html HTML supesite 文件 自动 静态
顶:12 踩:11
对本文中的事件或人物打分:
当前平均分:-0.42 (43次打分)
对本篇资讯内容的质量打分:
当前平均分:0.56 (34次打分)
【已经有35人表态】
4票
感动
8票
路过
5票
高兴
4票
难过
3票
搞笑
3票
愤怒
6票
无聊
2票
同情
上一篇 下一篇
发表评论

网友评论仅供网友表达个人看法,并不表明本网同意其观点或证实其描述。

查看全部回复【已有0位网友发表了看法】
       

网络资源