Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[发布] 全论坛生成静态html-首页、贴子列表、贴子内容(后台可控制)

[复制链接]
晶莹雪花 发表于 2006-6-16 20:06:17 | 显示全部楼层 |阅读模式
<?
程序信息:

/*
        [DISCUZ!] Discuz! threads html system
       
        Powered by mfboy(lzh-0808@163.com)
        -> Version: 1.1.0 L
        -> Copyright: For author
        -> Last Modified: 2006-06-16 by snow
        -> 此程序是在“魔焰男孩”的源程序的基础上修改而成,在此表示感谢
*/


写在前面:因为我的论坛服务器是破p3,win2003+IIS,如果开启rewrite,简直就跑不动了,没办法,所以只好想这个办法,呵呵


程序功能:
1、将DZ论坛首页、贴子列表、贴子内容生成html静态文件,降低服务器负担,提高访问速度和被搜索引擎收录的机会,但会占用部分空间(每贴大约在30-50K左右)
2、管理员可以在后台设置是否开启此功能,并且可以设置开启的范围(仅贴子内容、贴子列表和内容、全部页面)(后台 - 论坛功能 - 论坛生成静态html页面)
3、能够针对某一论坛分区设置是否开启此功能(后台 - 编辑论坛 - 编辑要开启或关闭此功能的论坛,找到“允许自动生成 html 页面”选项进行设置)
4、首页因为有某些隐藏论坛,所以不管后台开启与否,管理人员和特殊用户组浏览首页时,全部为动态页面(普通会员根据后台设置而定)
5、当有新短消息时,自动转到动态模式下
6、根据论坛风格自动生成不同的html文件,所以切换风格不存在问题(但切换风格时需要进入“动态模式”切换)
7、其它功能在使用中慢慢开发


演示论坛:http://bbs.snowcn.com

后台升级数据库

  1. INSERT INTO `cdb_settings` ( `variable` , `value` )
  2. VALUES (
  3. 'createhtml', '3'
  4. );

  5. ALTER TABLE cdb_forums ADD createhtml Tinyint(1) NOT NULL DEFAULT '1'
复制代码


默认的升级语句会自动打开全论坛的html生成功能,如果你想默认为关闭,请将上面语句中的'createhtml', '3' 改成 'createhtml', '0'来升级数据库


admin/forums.inc.php
查找:

  1. showsetting('forums_edit_jammer', 'jammernew', $forum['jammer'], 'radio');
复制代码

在下面添加上:

  1. showsetting('forums_edit_createhtml', 'createhtmlnew', $forum['createhtml'], 'radio');
复制代码


查找

  1. jammer='$jammernew',
复制代码

后面添加(注意前面有个空格)

  1. createhtml='$createhtmlnew',
复制代码


admin/setting.inc.php
查找

  1. 'rssttl', 'rewritestatus',
复制代码

替换为

  1. 'rssttl', 'rewritestatus', 'createhtml',
复制代码



查找

  1. $checkrewrite = array($settings['rewritestatus'] => 'checked');
复制代码

在下面一行添加

  1. $checkcreatehtml = array($settings['createhtml'] => 'checked');
复制代码


查找

  1. showsetting('settings_rewritestatus', '', '', '<input type="radio" name="settingsnew[rewritestatus]" value="0" '.$checkrewrite[0].'> '.$lang['none'].'<br><input type="radio" name="settingsnew[rewritestatus]" value="1" '.$checkrewrite[1].'> '.$lang['settings_rewritestatus_archiver'].'<br><input type="radio" name="settingsnew[rewritestatus]" value="2" '.$checkrewrite[2].'> '.$lang['settings_rewritestatus_pages'].'<br><input type="radio" name="settingsnew[rewritestatus]" value="3" '.$checkrewrite[3].'> '.$lang['settings_rewritestatus_both']);
复制代码

在下面一行添加

  1. showsetting('settings_createhtml', '', '', '<input type="radio" name="settingsnew[createhtml]" value="0" '.$checkcreatehtml[0].'> '.$lang['none'].'<br><input type="radio" name="settingsnew[createhtml]" value="1" '.$checkcreatehtml[1].'> '.$lang['settings_createhtml_viewthread'].'<br><input type="radio" name="settingsnew[createhtml]" value="2" '.$checkcreatehtml[2].'> '.$lang['settings_createhtml_forumdisplay'].'<br><input type="radio" name="settingsnew[createhtml]" value="3" '.$checkcreatehtml[3].'> '.$lang['settings_createhtml_all']);
复制代码




templates\default\admincp.lang.php
查找

  1. 'forums_edit_anonymous'
复制代码

上面添加

  1.         'forums_edit_createhtml' => '允许自动生成 html 页面:',
  2.         'forums_edit_createhtml_comment' => '选择“是”将会自动生成本版帖子的 html 页面,增加对搜索引擎的友好度,减轻服务器的负担',
复制代码


查找

  1. 'settings_bdaystatus' => '生日显示与邮件祝福:',
复制代码

上面添加

  1.         'settings_createhtml' => '论坛生成静态html页面功能',
  2.         'settings_createhtml_viewthread' => '贴子内容生成静态html文件',
  3.         'settings_createhtml_forumdisplay' => '贴子内容及主题列表生成静态html',
  4.         'settings_createhtml_all' => '首页、主题列表、贴子内容全部生成静态html',
  5.         'settings_createhtml_comment' => '本功能会明显降低服务器负担,提高论坛的访问速度和被搜索引擎收录的机会,但会占较多的服务器空间,平均每个文件占用30-50K左右,对于贴子量很大的论坛,请慎用,设置完,请到编辑论坛 - 编辑要开启或关闭此功能的论坛,找到“允许自动生成 html 页面”选项进行设置',
复制代码




index.php
查找

  1. $discuz_action = 1;
复制代码

在下面添加

  1. //生成静态html文件 by snow 2006-06-16
  2. $htmlfile = "./htmdata/index_{$styleid}.htm";
  3. $phpview = $_GET['view'] ? 1 : 0;
  4. if(!$newpm && !$adminid && file_exists($htmlfile) && !$phpview) {
  5.         exit(header('location: ' . $htmlfile));
  6. } else {
  7.         ob_start();
  8. }
  9. //生成静态html文件 by snow 2006-06-16
复制代码


查找

  1. include template('index');
复制代码

替换为

  1. //生成静态html文件 by snow 2006-06-16
  2. if($discuz_uid && !$adminid && $createhtml == 3 && !$newpm && !$phpview){
  3.         include DISCUZ_ROOT.'./include/htmdata.func.php';
  4.         check_html('index');
  5.         include template('index_html');
  6.         $html = ob_get_contents();
  7.     ob_end_clean();       
  8.         createhtml(url_tags($html), $thread['fid'], $tid, $page, $styleid);
  9.         header('location: ' . $htmlfile);
  10. }else{
  11.                 include template('index');
  12. }
  13. //生成静态html文件 by snow 2006-06-16
复制代码




forumdisplay.php
查找

  1. $discuz_action = 2;
复制代码

在下面添加

  1. //生成静态html文件 by snow 2006-06-16
  2. @$page = isset($page) ? $page : 1;
  3. $htmlfile = "./htmdata/{$fid}/{$fid}_{$page}_{$styleid}.htm";
  4. $phpview = $_GET['view'] ? 1 : 0;
  5. if(file_exists($htmlfile) && !$newpm && !$phpview) {
  6.         exit(header('location: ' . $htmlfile));
  7. } else {
  8.         ob_start();
  9. }
  10. //生成静态html文件 by snow 2006-06-16
复制代码


查找

  1. include template('forumdisplay');
复制代码

替换为

  1. //生成静态html文件 by snow 2006-06-16
  2. if($discuz_uid && $createhtml >= 2 && $forum['createhtml'] && !$newpm && !$phpview){
  3.         include DISCUZ_ROOT.'./include/htmdata.func.php';
  4.         check_html('forumdisplay');
  5.         include template('forumdisplay_html');
  6.         $html = ob_get_contents();
  7.     ob_end_clean();       
  8.         createhtml(url_tags($html), $thread['fid'], $tid, $page, $styleid);
  9.         header('location: ' . $htmlfile);
  10. }else{
  11.                 include template('forumdisplay');
  12. }
  13. //生成静态html文件 by snow 2006-06-16
复制代码




viewthread.php
查找

  1. $thread['subjectenc'] = rawurlencode($thread['subject']);
复制代码

在下面添加

  1. //生成静态html文件 by snow 2006-06-16
  2. @$page = isset($page) ? $page : 1;
  3. $htmlfile = "./htmdata/{$thread['fid']}/{$tid}/{$tid}_{$page}_{$styleid}.htm";
  4. $phpview = $_GET['view'] ? 1 : 0;
  5. if(file_exists($htmlfile) && !$newpm && !$phpview) {
  6.         exit(header('location: ' . $htmlfile));
  7. } else {
  8.         ob_start();
  9. }
  10. //生成静态html文件 by snow 2006-06-16
复制代码


查找

  1. include template('viewthread');
复制代码

替换为

  1. //生成静态html文件 by snow 2006-06-16
  2. if($discuz_uid && $createhtml >= 1 && $forum['createhtml'] && !$newpm && !$phpview){
  3.         include DISCUZ_ROOT.'./include/htmdata.func.php';
  4.         check_html('viewthread');
  5.         include template('viewthread_html');
  6.         $html = ob_get_contents();
  7.     ob_end_clean();       
  8.         createhtml(url_tags($html), $thread['fid'], $tid, $page, $styleid);
  9.         header('location: ' . $htmlfile);
  10. }else{
  11.                 include template('viewthread');
  12. }
  13. //生成静态html文件 by snow 2006-06-16
复制代码



include/global.func.php
查找

  1. && $GLOBALS['formhash'] == formhash()
复制代码

删除


post.php
查找

  1. if($action == 'newthread') {
复制代码

上面添加

  1. //生成静态html文件 by snow 2006-06-16
  2. include('./include/htmdata.func.php');
  3. delthread($forum['fid'], $tid);
  4. delthread_dir($forum['fid']);
  5. //生成静态html文件 by snow 2006-06-16
复制代码



topicadmin.php
查找

  1. $moderatetids .= ','.$thread['tid'];
复制代码

在下面添加

  1.         //生成静态html文件 by snow 2006-06-16
  2.                         $tid = $thread['tid'];
  3.                         if(is_dir("htmdata/{$fid}/{$tid}")) {
  4.                                 $root = dir("htmdata/{$fid}/{$tid}");
  5.                                 while($filename = $root->read()) {
  6.                                         if($filename != 'index.htm') {
  7.                                                 @unlink("htmdata/{$fid}/{$tid}/{$filename}");
  8.                                                 @rmdir("htmdata/{$fid}/{$tid}");
  9.                                         }
  10.                                 }
  11.                                 $root->close();
  12.                         }
  13.         //生成静态html文件 by snow 2006-06-16
复制代码




forumdisplay.php,
查找(共2处):


  1. f.threads,
复制代码

在后面(不是下面)添加上(注意前面有一个空格):

  1. f.createhtml,
复制代码


下载附件,按照目录结构上传,然后到论坛后台中进行相应设置,更新缓存,完成


更新记录:
2006-06-17 14:26更新附件,解决部分表格代背景空白的问题(主要针对DZ的默认风格),存在此问题的朋友,请下载附件解压后重新覆盖一下其中的两个文件,并删除论坛风格目录下的所有以 _html.htm结尾的文件


[ 本帖最后由 晶莹雪花 于 2006-6-17 14:49 编辑 ]
 楼主| 晶莹雪花 发表于 2006-6-16 20:07:28 | 显示全部楼层
请安装成功的朋友留个名,谢谢

[ 本帖最后由 晶莹雪花 于 2006-6-17 11:15 编辑 ]
回复

使用道具 举报

摄部落 发表于 2006-6-16 20:07:48 | 显示全部楼层
论坛自带的有,何必去修改,到时候出错误怎么办
回复

使用道具 举报

 楼主| 晶莹雪花 发表于 2006-6-16 20:07:52 | 显示全部楼层
占22222
回复

使用道具 举报

TaRot! 发表于 2006-6-16 20:10:00 | 显示全部楼层
就算占我硬盘,我也愿意选择生成,而不选择伪静态。
回复

使用道具 举报

81jun 发表于 2006-6-16 20:15:10 | 显示全部楼层
站个位子!
回复

使用道具 举报

haohao036 发表于 2006-6-16 20:17:27 | 显示全部楼层
只能支持。不装了。。
回复

使用道具 举报

81jun 发表于 2006-6-16 20:18:09 | 显示全部楼层
装了看看!不错!
回复

使用道具 举报

离恨天 发表于 2006-6-16 20:18:11 | 显示全部楼层
收藏了,支持了,有时间了,再装了。
回复

使用道具 举报

fishleong 发表于 2006-6-16 20:21:30 | 显示全部楼层
强 支持!!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-9-22 15:33 , Processed in 0.127746 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表