欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用PHP实现的生成静态HTML速度快类库

程序员文章站 2022-04-08 23:49:45
复制代码 代码如下:
复制代码 代码如下:

<?php 
/////////////////////////////////////////////////////////////////////////////// 
// 
// 张树林 - 慧佳工作室 
// 
// module name:     woods-bhtml.php 
// abstract:        生成静态html处理程序尾底 
// version:         2.0 
// date                                1006-11-25 
// author:          woods·zhang 
// website:         http://www.hoojar.com/ 
// email:           hoojar@53.com 
// msn:             hoojar@hotmail.com 
// copyright 1001-1006, hoojar studio all rights reserved 
// 
// 版权 1001-1006,慧佳工作室所有版权保护 

//the software for free software, allowing use, copy, 
//modify and distribute the software and files. any 
//use of this software must place a copy of all the 
//above copyright notice. by the software huijia studio 
//maintenance, if you have any queries please contact us. 
//thank you. 
// 
//此软件为*软件,允许使用、拷贝、修改、分发本软件及其文档。 
//任何使用此软件的地方都得出现以上版权通告所有副本。此软件由 
//慧佳工作室维护,如果您有什么疑问请与我们联系。谢谢使用。 
// 
/////////////////////////////////////////////////////////////////////////////// 
//此文件只能加载在程序的最尾 
/*________________生成html文件______________________beign________________________________*/ 
if ($make_html) 

        $buffer = ob_get_flush(); 
        if ($go_html)//是否直接转到html文件显示还是php读得内容输出(0:php读内容输出1:直接转) 
        { 
                /*__________处理因生成了html文件而产生的种径问题____________________begin_______________*/ 
                $search = array( 
                        "/(src=|action=|href=|ajaxread\()\"/ie", 
                        "/\.\.\./e", 
                        "/\.\/\./e", 
                        "/\.\.\/http:\/\//ies", 
                        "/\.\.\/#/", 
                        "/\'\.\'/e", 
                        "/\.\.\/javascript:/ies"); 

                $replace = array( 
                        "'\\1\"../'", 
                        "'..'", 
                        "'.'", 
                        "'http://'", 
                        "#", 
                        "'\'..\''", 
                        "'javascript:'"); 
                $buffer = preg_replace($search, $replace, $buffer); 
                /*__________处理因生成了html文件而产生的种径问题____________________end_______________*/ 
        } 

        $fp = fopen(html_file, "w"); 
        if ($fp) 
        { 
                fwrite($fp, $buffer); 
                fclose($fp); 
        } 

/*________________生成html文件______________________beign________________________________*/ 
?> 

<?php 
/////////////////////////////////////////////////////////////////////////////// 
// 
// 张树林 - 慧佳工作室 
// 
// module name:     woods-thtml.php 
// abstract:        生成静态html处理程序头 
// version:         2.0 
// date                                1006-11-25 
// author:          woods·zhang 
// website:         http://www.hoojar.com/ 
// email:           hoojar@53.com 
// msn:             hoojar@hotmail.com 
// copyright 1001-1006, hoojar studio all rights reserved 
// 
// 版权 1001-1006,慧佳工作室所有版权保护 

//the software for free software, allowing use, copy, 
//modify and distribute the software and files. any 
//use of this software must place a copy of all the 
//above copyright notice. by the software huijia studio 
//maintenance, if you have any queries please contact us. 
//thank you. 
// 
//此软件为*软件,允许使用、拷贝、修改、分发本软件及其文档。 
//任何使用此软件的地方都得出现以上版权通告所有副本。此软件由 
//慧佳工作室维护,如果您有什么疑问请与我们联系。谢谢使用。 
// 
/////////////////////////////////////////////////////////////////////////////// 
//此文件只能加载在程序的开头 
ob_start(); 
/*___________判断是否已生成了html文件,若生成了则跳转到html页面___________begin__________*/ 
$qstring = isset($_server["query_string"]) ? $_server["query_string"] : ""; 
if ($qstring)//程序加了get请求的处理 

        $qstring = str_replace("=", "", $qstring); 
        define("html_file", "./h/{$efilename}-{$qstring}.html"); 

else 

        define("html_file", "./h/{$efilename}.html"); 

if (file_exists(html_file)) 

        $lcft = filemtime(html_file);//last create file time 
        if (($lcft + 3600) > time())//判断上次生成html文件是否以过去1时间,若没有才直接输出文件内容 
        { 
                if ($show_html)//是否以html静态页面展示(0不以html展显1以html展显) 
                { 
                        if ($go_html)//是否直接转到html文件显示还是php读得内容输出(0:php读内容输出1:直接转) 
                        { 
                                header("location: " . html_file);//直接转 
                        } 
                        else 
                        { 
                                echo(file_get_contents(html_file));//读出展显 
                        } 
                        exit(0); 
                } 
        } 

/*___________判断是否已生成了html文件,若生成了则跳转到html页面___________end__________*/ 
?> 

<?php 
/////////////////////////////////////////////////////////////////////////////// 
// 
// 张树林 - 慧佳工作室 
// 
// module name:     index.php 
// abstract:        首页信息 
// version:         1.0 
// date                                2006-11-7 
// author:          woods·zhang 
// website:         http://www.hoojar.com/ 
// cemail:           hoojar@163.com 
// msn:             hoojar@hotmail.com 
// copyright 2001-2006, hoojar studio all rights reserved 
// 
// 版权 2001-2006,慧佳工作室所有版权保护 

//the software for free software, allowing use, copy, 
//modify and distribute the software and files. any 
//use of this software must place a copy of all the 
//above copyright notice. by the software huijia studio 
//maintenance, if you have any queries please contact us. 
//thank you. 
// 
//此软件为*软件,允许使用、拷贝、修改、分发本软件及其文档。 
//任何使用此软件的地方都得出现以上版权通告所有副本。此软件由 
//慧佳工作室维护,如果您有什么疑问请与我们联系。谢谢使用。 
// 
/////////////////////////////////////////////////////////////////////////////// 
require("woods-thtml.php");//生成html处理头 
//if (count($_get) < 1 && count($_post) < 1){require("woods-thtml.php");}//生成html处理头 

require("{$exec_file}");//注册语言定义文件 
foreach ($lang as $key => $value) 

        $atpl[strtoupper($key) ."_lang"] = $value; 

/*____________________________________列表常识向上走的项__________________end_____________________*/ 
include("woods-templates.php"); 
$tpl = new woodstpl("./templates/"); 
$tpl->require_tpl("header.html"); 
$tpl->set_file(); 
$tpl->block("ebcorp", $scorp); 
$tpl->block("news", $news); 

$tpl->block("product", $product); 
$tpl->block("ebpname_msg", $spname); 

$tpl->block("lore", $lore); 
$tpl->require_tpl("footer.html"); 
$tpl->parse($atpl, true); 
$tpl = null; 
/*________________模板操作_________________________end___________________________________*/ 
require("woods-bhtml.php");//生成html处理尾 
?>