部分论坛可能设定了域名 ,生成的页面地址不合适 ,可以设定网址
- <?php
- /***
- * Discuz! X Baidu BBS Sitemap Generator
- *
- * @category Include/Cron
- * @package Discuz! X
- * @copyright Copyright (c) 2008-2011 HiceonStudio
- * @version $Id: cron_baiduspider.php 20111 2011-11-31 02:05:09 $
- * @contact 解海 : QQ:50083000 | MSN:xiehai@hiceon.com $
- */
- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- /***
- * This cron module will be generated in line with standard format of Baidu Forum Open Protocol.
- * Protocal URL : http://www.baidu.com/search/pageop.htm
- * Format is as follows:
- *
- * <?xml version="1.0" encoding="GB2312"?>
- * <document xmlns:bbs="http://www.baidu.com/search/bbs_sitemap.xsd">
- * <webSite>ForumURL(bbs.domain.com)</webSite>
- * <webMaster>webmaster@domain.com</webMaster>
- * <updatePeri>12(in hours)</updatePeri>
- * <updatetime>2011-11-11 19:00:00</updatetime>
- * <version>Discuz! X2</version>
- * <item>
- * <link>http://bbs.domain.com/thread-100-1-1.html</link>
- * <title>Thread subject</title>
- * <pubDate>2011-11-11 16:00:00</pubDate>
- * <bbs:lastDate>2011-11-11 16:00:00</bbs:lastDate>
- * <bbs:reply>Reply number</bbs:reply>
- * <bbs:hit>Hit number</bbs:hit>
- * <bbs:mainLen>The length of the main post:In bytes</bbs:mainLen>
- * <bbs:boardid>Belongs to the name of the forum</bbs:boardid>
- * <bbs:pick>1(is digest or not,value can be 0 or 1)</bbs:pick>
- * </item>
- * <item>
- * ... ...
- * </item>
- * </document>
- */
- $file = 'sitemap_baidu.xml';
- $updateperi = 12;
- $version = 'DISCUZ!X2';
- $outputnum = '1000';
- /***********************************************************************************************
- * Controllers
- **********************************************************************************************/
- //Reset rewrite rules
- function Ctl_isrewrite($rewrite,$row,$param = ''){
- global $_G,$discuz;
- $rewriterule = $_G['setting']['rewriterule'];
- $status = $_G['setting']['rewritestatus'];
- if(in_array($rewrite,$status)){
- $mod=$rewriterule[$rewrite];
- $mod=preg_replace("/{page}/","1",$mod);
- $mod=preg_replace("/{prevpage}/","1",$mod);
- $mod=str_replace("{fid}","".$param."",$mod);
- $mod=str_replace("{tid}","".$row."",$mod);
- }
- elseif($rewrite =="forum_viewthread"){$mod="forum.php?mod=viewthread&tid=".$row."";}
- return $mod;
- }
- //Positioning forum application domain
- function Ctl_domain(){
- global $_G,$discuz;
- $appdomain = $_G['setting']['domain']['app'];
- if (!empty($appdomain['forum']) && empty($appdomain['default'])) {
- $domain = 'http://'.$appdomain['forum'].'/';
- }elseif(empty($appdomain['forum']) && !empty($appdomain['default'])){
- $domain = 'http://'.$appdomain['default'].'/';
- }else{
- $domain = 'http://bbs.0933.me/';
- }
- return $domain;
- }
- // Get unencrypted forum
- function Ctl_unencrypted(){
- $u = array();
- $query = DBfactory('forum');
- while ($v = DB::fetch($query)) {
- $u[$v['fid']] = $v['fid'];
- }
- return $u;
- }
- /***********************************************************************************************
- * Models
- **********************************************************************************************/
- function DBfactory($mod,$param = ''){
- switch ($mod) {
- case 'forum':
- return DB::query("SELECT a.fid FROM ".DB::table("forum_forum")." AS a , ".DB::table("forum_forumfield")." AS b WHERE a.fid = b.fid AND a.`status` = 1 AND b.viewperm = '' AND a.fup <> 0 ORDER BY displayorder");
- break;
- case 'forum_name':
- return DB::result_first("SELECT name FROM ".DB::table("forum_forum")." WHERE fid=".$param."");
- break;
- case 'thread':
- return DB::query("SELECT tid,fid,subject,dateline,lastpost,views,replies,digest FROM ".DB::table('forum_thread')." WHERE readperm = 0 ORDER BY lastpost DESC LIMIT ".$param);
- break;
- case 'thread_message':
- return DB::result_first("SELECT message FROM ".DB::table('forum_post')." WHERE tid=".$param." AND first=1");
- break;
- }
- }
- /***********************************************************************************************
- * Class
- **********************************************************************************************/
- class baiduspider
- {
- var $xml;
- var $file;
- var $size;
- var $updateperi;
- var $version;
- function baiduspider($file,$updateperi,$version)
- {
- $this->file=$file;
- $this->size=1024*10240;
- $this->updateperi=$updateperi;
- $this->version=$version;
- }
-
- function additem($link,$title,$pubdate,$lastdate,$reply,$hit,$mainlen,$boardid,$pick){
- $str="<item><link>".str_replace('&','&',$link)."</link><title>".trim($title)."</title><pubDate>".date('Y-m-d H:i:s',$pubdate)."</pubDate><bbs:lastDate>".date('Y-m-d H:i:s',$lastdate)."</bbs:lastDate><bbs:reply>".$reply."</bbs:reply><bbs:hit>".$hit."</bbs:hit><bbs:mainLen>".$mainlen."</bbs:mainLen><bbs:boardid>".$boardid."</bbs:boardid><bbs:pick>".$pick."</bbs:pick></item>";
- $this->xml.=$str;
- }
- function write(){
- global $_G;
- @file_put_contents($this->file,'<?xml version="1.0" encoding="GB2312"?><document xmlns:bbs="'.(!empty($_G['setting']['domain']['app']['forum'">http://www.baidu.com/search/bbs_sitemap.xsd"><webSite>'.(!empty($_G['setting']['domain']['app']['forum']) ? $_G['setting']['domain']['app']['forum'] : $_G['setting']['domain']['app']['default']).'</webSite><webMaster>'.$_G['setting']['adminemail'].'</webMaster><updatePeri>'.$this->updateperi.'</updatePeri><updatetime>'.date("Y-m-d H:i:s").'</updatetime><version>'.$this->version.'</version>'.$this->xml.'</document>');
- }
- }
- /***********************************************************************************************
- * Run and output
- **********************************************************************************************/
- $spider[]=new baiduspider($file,$updateperi,$version);
- $query = DBfactory('thread',$outputnum);
- while ($row = DB::fetch($query)) {
- if (in_array($row['fid'],Ctl_unencrypted())) {
- $row['url']=Ctl_isrewrite("forum_viewthread",$row['tid'],empty($_G['setting']['forumkeys'][$row['fid']]) ? $row['fid'] : $_G['setting']['forumkeys'][$row['fid']]);
- foreach($spider as $key=>$item){
- $spider[$key]->additem(Ctl_domain().$row['url'],str_replace(array('&', '"', '<', '>',"'"), array('&', '"', '<', '>' ,'''), $row['subject']),$row['dateline'],$row['lastpost'],$row['replies'],$row['views'],strlen(DBfactory('thread_message',$row['tid'])),DBfactory('forum_name',$row['fid']),$row['digest']);
- }
- }
- }
- foreach($spider as $item){
- $item->write();
- }
- ?>
复制代码
$domain = 'http://bbs.0933.me/'; 将这个中的网址改成你自己想要的
将代码保存成php文件 ,放在 /source/include/cron/ ,然后在工具添加计划任务就可以的
别人的作品,我重新发布一下* Discuz! X Baidu BBS Sitemap Generator
*
* @category Include/Cron
* @package Discuz! X
* @copyright Copyright (c) 2008-2011 HiceonStudio
* @version $Id: cron_baiduspider.php 20111 2011-11-31 02:05:09 $
* @contact 解海 : QQ:50083000 | MSN:xiehai@hiceon.com $
|