PHPCMS 详情页静态化

<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
class game extends admin {
    public function __construct() {
	parent::__construct();
        $this->game = pc_base::load_model('game_model');
        $this->db = pc_base::load_model('gamedown_model');
        $this->html_root = 'D:\wamp\www\record\/html/game/';
    }
    /**-- 首页的每日推荐 --**/
    public function game_list(){
        if($_POST['submit']){
            $id = $_POST['id'];
            if($id){
              $this->game->update(array('content'=>$id),array('id'=>1));
              showmessage('修改成功');
            }            
        }else{
            $arr = $this->game->get_one(array('id'=>1));
            $id = $arr['content'];
            include $this->admin_tpl('lists');  
        }
    }
    /**-- 游戏分类 静态化 --**/
    public function static_lists(){
        $url = APP_PATH."index.php?m=game&c=index&a=lists";
        $path = $this->html_root.'game/single/lists.html';
        $this->php_to_html($path,$url);
    }
    /**-- 越狱专享 静态化 --**/
    public function static_yueyu(){
        $url = APP_PATH."index.php?m=game&c=index&a=yueyu";
        $path = $this->html_root.'game/single/yueyu.html';
        $this->php_to_html($path,$url); 
    }
    /**-- 详情页 静态化 --**/
    public function static_show(){
        if($_GET['submit']){
                      
        }else{
           
            include $this->admin_tpl('static');  
        }
    }
    /**-- 去检查更新 --**/
    function static_now(){
        $type = isset($_GET['type']) ? intval($_GET['type']) : $_GET['type'];
        $num = isset($_GET['num']) ? intval($_GET['num']) : $_GET['num'];
        $page = isset($_GET['page']) ? $_GET['page'] : 0;

        if(!$type && !$num){
            exit('<h1>参数错误!</h1>');
        }	
        // 根据类型 确定要更新的范围
        if(isset($type) && $type == 2){  //更新全部
            $total = $this->db->count();
            $order = 'id';
        }else{
            $total = $num;
            $order = 'id desc';
        }
        $total_page = ceil($total/10);
        $limit = (10*$page).',10';
        $data = $this->db->select('','id,catid', $limit,$order);
        foreach ($data as $k => $v) {
            $path = $this->html_root.$v['catid'].'/'.$v['id'].'.html';
            $url = APP_PATH."index.php?m=game&c=index&a=show&catid=".$v['catid']."&id=".$v['id'];
            $this->php_to_html($path,$url);
        }
        if ($total_page > $page) {			
            showmessage('正在更新'.($page*10).'/'.$total.'<script type="text/javascript">location.href="?m=game&c=game&a=static_now&page='.($page+1).'&num='.$num.'&type='.$type.'&pc_hash='.$_SESSION['pc_hash'].'"</script>', '?m=game&c=game&a=static_now&page='.($page+1).'&total='.$total);
        } else {
            showmessage("更新完成!");	
        }
    }
    /**-- 生成 HTML 静态页面 --**/
    private function php_to_html($path,$url){ 
        //D:\wamp\www\record\/html/2014/dongzuogame_0717/109.html
        //$path = 'D:\wamp\www\record/html/game/';
        $html = file_get_contents($url);
        ob_start();
        echo $html;
        $this->createhtml($path); 
    }
    /**
        * 写入文件
        * @param $file 文件路径
        * @param $copyjs 是否复制js,跨站调用评论时,需要该js
        */
    private function createhtml($file, $copyjs = '') {
            $data = ob_get_contents();
            ob_clean();
            $dir = dirname($file);
            if(!is_dir($dir)) {
                    mkdir($dir, 0777,1);
            }
            if ($copyjs && !file_exists($dir.'/js.html')) {
                    @copy(PC_PATH.'modules/content/templates/js.html', $dir.'/js.html');
            }
            $strlen = file_put_contents($file, $data);
            @chmod($file,0777);
            if(!is_writable($file)) {
                    $file = str_replace(PHPCMS_PATH,'',$file);
                    showmessage(L('file').':'.$file.'<br>'.L('not_writable'));
            }
            return $strlen;
    }
}
?>

 

posted @ 2014-09-29 17:26  笑笑别人  阅读(625)  评论(0编辑  收藏  举报