很简单的修改了 原phpcms自带的 生成xml的程序文件 ,

原来的生成程序文件是 /phpcms/modules/admin/googlesitemap.php

修改这个文件放到根目录下命名为sitemap.php,代码如下:

if(PHP_SAPI != 'cli')

{

header('location: sitemap.xml');

exit;

}

define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);

include PHPCMS_PATH.'phpcms/base.php';

pc_base::load_sys_class('form', '', 0);

class gbsitemap {

function __construct() {

$this->header = "\n\t";

$this->charset = "UTF-8";

$this->footer = "\t\n";

$this->baidunews_footer = "";

$this->items = array();

$this->baidunew_items = array();

//生成栏目级别选项

$this->siteid = 1;

$this->categorys = getcache('category_content_'.$this->siteid,'commons');

}

function add_item2($new_item) {

$this->items[] = $new_item;

}

function build( $file_name = null ) {

$map = $this->header . "\n";

foreach ($this->items AS $item){

$map .= "\t\t\n\t\t\t$item[loc]\n";

$map .= "\t\t\t$item[lastmod]\n";

$map .= "\t\t\t$item[changefreq]\n";

$map .= "\t\t\t$item[priority]\n";

$map .= "\t\t\n\n";

}

$map .= $this->footer . "\n";

if (!is_null($file_name)){

return file_put_contents($file_name, $map);

} else {

return $map;

}

}

function google_sitemap_item($loc, $lastmod = '', $changefreq = '', $priority = '') {

$data = array();

$data['loc'] = $loc;

$data['lastmod'] = $lastmod;

$data['changefreq'] = $changefreq;

$data['priority'] = $priority;

return $data;

}

/**

*

* 百度新闻数组 组成

* @param $title

* @param $link

* @param $description

* @param $text

* @param $image

* @param $keywords

* @param $category

* @param $author

* @param $source

* @param $pubDate

*/

function baidunews_item($title, $link = '', $description = '',$text = '',$image = '', $keywords = '',$category = '',$author = '',$source='',$pubDate='') {

$data = array();

$data['title'] = $title;

$data['link'] = $link;

$data['description'] = $description;

$data['text'] = $text;

$data['image'] = $image;

$data['keywords'] = $keywords;

$data['category'] = $category;

$data['author'] = $author;

$data['source'] = $source;

$data['pubDate'] = $pubDate;

return $data;

}

function add_baidunews_item($new_item){

$this->baidunew_items[] = $new_item;

}

function baidunews_build( $file_name = null ,$this_domain,$email,$time) {

//百度头部

$this->baidunews = '';

$this->baidunews = "<?xml version=\"1.0\" encoding=\"".CHARSET."\" ?>\n";

$this->baidunews .= "\n";

$this->baidunews .= "".$this_domain."\n";

$this->baidunews .= "".$email."\n";

$this->baidunews .= "".$time."\n";

foreach ($this->baidunew_items AS $item){

$this->baidunews .= "\n";

$this->baidunews .= "

".$item['title']."\n";

$this->baidunews .= "".$item['link']."\n";

$this->baidunews .= "".$item['description'] ."\n";

$this->baidunews .= "".$item['text']."\n";

$this->baidunews .= "".$item['image']."\n";

$this->baidunews .= "".$item['keywords']."\n";

$this->baidunews .= "".$item['category']."\n";

$this->baidunews .= "".$item['author']."\n";

$this->baidunews .= "".$item['source']."\n";

$this->baidunews .= "".$item['pubDate']."\n";

$this->baidunews .= "\n";

}

$this->baidunews .= $this->baidunews_footer . "\n";

if (!is_null($file_name)){

return file_put_contents($file_name, $this->baidunews);

} else {

return $this->baidunews;

}

}

/**

*

* Enter 生成google sitemap, 百度新闻协议

*/

function set ($request) {

$hits_db = pc_base::load_model('hits_model');

$dosubmit = isset($request['dosubmit']) ? $request['dosubmit'] : $_GET['dosubmit'];

//读站点缓存

$siteid = $this->siteid;

$sitecache = getcache('sitelist','commons');

//根据当前站点,取得文件存放路径

$systemconfig = pc_base::load_config('system');

$html_root = substr($systemconfig['html_root'], 1);

//判断当前站点目录,是PHPCMS则把文件写到根目录下, 不是则写到分站目录下.(分站目录用由静态文件路经html_root和分站目录dirname组成)

if($siteid==1){

$dir = PHPCMS_PATH;

}else {

$dir = PHPCMS_PATH.$html_root.DIRECTORY_SEPARATOR.$sitecache[$siteid]['dirname'].DIRECTORY_SEPARATOR;

}

//模型缓存

$modelcache = getcache('model','commons');

//获取当前站点域名,下面生成URL时会用到.

$this_domain = substr($sitecache[$siteid]['domain'], 0,strlen($sitecache[$siteid]['domain'])-1);

//生成百度新闻

if($request['mark']) {

$baidunum = $request['baidunum'] ? intval($request['baidunum']) : 20;

if($request['catids']=="")showmessage(L('choose_category'), HTTP_REFERER);

$catids = $request['catids'];

$catid_cache = $this->categorys;//栏目缓存

$this->content_db = pc_base::load_model('content_model');

foreach ($catids as $catid) {

$modelid = $catid_cache[$catid]['modelid'];//根据栏目ID查出modelid 进而确定表名,并结合栏目ID:catid 检索出对应栏目下的新闻条数

$this->content_db->set_model($modelid);

$result = $this->content_db->select(array('catid'=>$catid,'status'=>99), '*', $limit = "0,$baidunum", 'id desc');

//重设表前缀,for循环时用来查,文章正文

$this->content_db->table_name = $this->content_db->table_name.'_data';

foreach ($result as $arr){

//把每一条数据都装入数组中

extract($arr);

if(!preg_match('/^(http|https):\/\//', $url)){

$url = $this_domain.$url;

}

if($thumb != ""){

if(!preg_match('/^(http|https):\/\//', $thumb)){

$thumb = $this_domain.$thumb;

}

}

//取当前新闻模型 附属表 取 新闻正文

$url = htmlspecialchars($url);

$description = htmlspecialchars(strip_tags($description));

//根据本条ID,从对应tablename_data取出正文内容

$content_arr = $this->content_db->get_one(array('id'=>$id),'content');

$content = htmlspecialchars(strip_tags($content_arr['content']));

//组合数据

$smi = $this->baidunews_item($title,$url,$description,$content,$thumb, $keywords,$category,$author,$source,date('Y-m-d', $inputtime));//推荐文件

$this->add_baidunews_item($smi);

}

}

$baidunews_file = $dir.'baidunews.xml';

@mkdir($dir,0777,true);

$this->baidunews_build($baidunews_file,$this_domain,$request['email'],$request['time']);

}

//生成网站地图

$content_priority = $request['content_priority'];

$content_changefreq = $request['content_changefreq'];

$num = $request['num'] ? intval($request['num']) : 100;

$today = date('Y-m-d');

$domain = $this_domain;

//生成地图头部 -第一条

$smi = $this->google_sitemap_item($domain, $today, 'daily', '1.0');

$this->add_item2($smi);

$this->content_db = pc_base::load_model('content_model');

//只提取该站点的模型.再循环取数据,生成站点地图.

$modelcache = getcache('model','commons');

$new_model = array();

foreach ($modelcache as $modelid => $mod){

if($mod['siteid']==$siteid){

$new_model[$modelid]['modelid'] = $modelid;

$new_model[$modelid]['name'] = $mod['name'];

}

}

foreach($new_model as $modelid=>$m) {//每个模块取出num条数据

$this->content_db->set_model($modelid);// 或者 $this->conetnt_db->set_model($modelid);

$result = $this->content_db->select(array('status'=>99), '*', $limit = "0,$num", $order = 'inputtime desc');

foreach ($result as $arr){

if(substr($arr['url'],0,1)=='/'){

$url = htmlspecialchars(strip_tags($domain.$arr['url']));

}else {

$url = htmlspecialchars(strip_tags($arr['url']));

}

$hit_r = $hits_db->get_one(array('hitsid'=>'c-'.$modelid.'-'.$arr['id']));

if($hit_r['views']>1000) $content_priority = 0.9;

$smi = $this->google_sitemap_item($url, $today, $content_changefreq, $content_priority);//推荐文件

$this->add_item2($smi);

}

}

$sm_file = $dir.'sitemaps.xml';

if($this->build($sm_file)){

showmessage(L('create_success'), HTTP_REFERER);

}

}

}

//这个地方自己设定,catids是个数组,

$request = array(

'tabletype'=>'phpcmstables',

'content_priority'=>'0.7',

'content_changefreq'=>'weekly',//daily,monthly……

'num'=>'20',

'mark'=>'1',

'catids'=>range(6,17),

'time'=>'40',

'email'=>'phpcms@phpcms.cn',

'baidunum'=>'20',

);

//当然你可以通过外部传递参数,修改$request的值

$maps = new gbsitemap();

$maps->set($request);

?>

shell中

crontab -e

*/5 * * * *

cms php xml,phpcms 定时生成 sitemap 包括 百度 xml文件相关推荐

  1. java sitemap.xml站点地图创建 sitemap提交百度提示xml格式错误 sitemapgen4j使用 java百度链接主动(实时)推送

    一.前言 前几个月用jeesite4开发了个网站,上线运行了几个月,因为自己搞过SEO,所有,想把站点提交到百度收录,遇到了一些很尴尬的事,就是百度链接提交通过sitemap提交,一直提示XML格式错 ...

  2. html全自动生成安卓版,科讯cms内容页全自动定时生成HTML文件的设计

    HTML静态网站能尽可能的减轻服务器的负载,加快网站访问速度,提高网页的收录量和引擎关键字排名,但对于内容多的网站,大批量生成HTML时会导致服务器在生成时无法访问,而在添加时生成的内容页却因为后续内 ...

  3. Java生成sitemap网站地图

    访问我的博客 sitemap 是什么?对应没有接触过网站 SEO 的同学可能不知道,这里引用一下百度站长的一段解释. Sitemap(即站点地图)就是您网站上各网页的列表.创建并提交Sitemap有助 ...

  4. 帝国cmssitemap.php,帝国CMS如何自动生成sitemap.xml网站地图

    帝国CMS如何自动生成sitemap.xml网站地图? 步骤:登录网站的后台http://你的域名/e/admin/  进入后台栏目 =>增加自定义页面 =>选择直接页面,页面名称为:网站 ...

  5. php生成sitemap.xml地图文件

    文章目录 前言 什么是Sitemap? sitemap文件遵循指南 xml格式详解 实战代码 sitemap组件代码 调用sitemap组件 仓库地址 实战截图 相关问题 Sitemap提交后,多久能 ...

  6. vue项目SEO优化以及生成sitemap.xml

    众所周知vue项目本质是单页面项目,对SEO优化十分不好,找起资料来更是麻烦.闲话不多说,分享一下我对自己项目进行的SEO方案及生成sitemap.xml. 需要的库 npm install site ...

  7. 帝国cms自动生成sitemap地图

    帝国cms自动生成sitemap地图的方法, 新建自定义页面,复制以下代码,注意把www.tyyjyzs.com改成自己的网址,提交生成,刷新所以自定义页面即可 <?='<?xml ver ...

  8. SEO优化之根据网址自动生成sitemap.xml文件

    背景: 公司要做一个电商的网站,而该项目是由J2EE架构完成,项目经理说要让Java代码自助每天生成电子商务网站的Sitemap文件,然后开始上网各种查资料!!!然而,终于碰上了本人有生以来第一个在网 ...

  9. .net core将URL请求格式化为XML或JSON(网站动态生成sitemap.xml)

    .net core将URL请求格式化为XML或JSON(网站动态生成sitemap.xml) 首先设置 Startup.cs 文件 配置 ConfigureServices services.AddM ...

最新文章

  1. Python标准模块—Regular Expressions
  2. 李开复谏言学生转学Android软件开发
  3. gc 吞吐量和停顿时间_GC对吞吐量和延迟的影响
  4. 微信公众号开发之获取用户信息
  5. 都说互联网寒冬,有人却获一线大厂六枚Offer,他是怎么做到的?
  6. 【图像分割】基于matlab GUI多种阈值图像分割(带面板)【含Matlab源码 733期】
  7. 摩西十诫 摩西简介 世界宗教图谱
  8. 如何在软件UI设计中运用格式塔心理学5项法则?
  9. 分布式图数据库-JanusGraph简介
  10. 【MLPs+ESN】利用多层感知机MLPs对经典ESN(回声状态网络)的输出权值计算进行优化的MATLAB仿真
  11. 全球2%高智商天才必测脑力题!却只有1%的人,能在5分钟内全部做对!
  12. 大内高手—常见内存错误
  13. 增资扩股和股权转让有什么区别?
  14. 屈原与司马迁的对话--理想主义与辩证法
  15. java中的notify和notifyAll有什么区别?
  16. 配置全面升级!骨传导耳机机皇——南卡Runner Pro 4新发布!
  17. 详说TCP/IP协议
  18. i春秋新春战疫公益赛复现
  19. 真正解决TextView行间距、字间距的问题
  20. 常用电平标准——LVTTL、LVCMOS、LVDS

热门文章

  1. 解决GitHub下载速度太慢的问题
  2. Guitar Pro教程之不认识的符号讲解
  3. Mol Plant | 中科院昆植所吴建强团队解析列当科寄生植物的基因组演化历史
  4. b站 前端构架_技术干货:哔哩哔哩(B站)功能框架图 ——以B站为例分析面对秋招必须要掌握的前后端...
  5. 电脑相关:【二】电脑开机了但是一直黑屏 电脑开机后黑屏无桌面的解决方法
  6. Go语言中的goroutine
  7. 2016湖南湘潭邀请赛 - 2019牛客国庆集训派对day6
  8. Orcal listener.ora配置文件
  9. 大数据时代的“小数据 系列3 --Shapiro-Wilk检验
  10. 轩辕实验室丨欧盟EVITA项目预研 第一章(一)