欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

帝國(guó)CMS生成sitemap實(shí)現(xiàn)代碼分享

  發(fā)布時(shí)間:2014-08-17 09:59:51   作者:佚名   我要評(píng)論
這篇文章主要介紹了帝國(guó)CMS生成sitemap實(shí)現(xiàn)代碼分享,可以生成含有首頁(yè)鏈接、欄目頁(yè)鏈接和內(nèi)容頁(yè)鏈接的sitemap文件,需要的朋友可以參考下

因?yàn)閷?duì)帝國(guó)CMS的sitemap插件不太滿意,所以自己寫了個(gè)sitemap生成工具,在sitemap中放了首頁(yè)鏈接、欄目頁(yè)鏈接和內(nèi)容頁(yè)鏈接,然后生成XML文件并且提交到百度站長(zhǎng)工具,本文中的代碼是需要生動(dòng)生成的,我自己是在Linux中用cron寫的定時(shí)任務(wù),每天固定時(shí)間生成一次,先這樣吧~

復(fù)制代碼
代碼如下:

<?php
/*引用文件*/
require('e/class/connect.php');
require('e/class/db_sql.php');
require('e/data/dbcache/class.php');</p> <p>/*建立數(shù)據(jù)庫(kù)鏈接 與 實(shí)例化類*/
$link = db_connect();
$empire=new mysqlquery(); </p> <p>//header("Content-type:application/xml");
header("Content-type: text/html; charset=utf-8");</p> <p>$operation = $_GET['operation'];
$current_url = explode('/',$_SERVER['PHP_SELF']);
$current_script_name = end($current_url); </p> <p>if($operation && $operation == "makexml")
{
$xml = generate_sitemp_xml();
$result = save_xml('sitemap.xml',$xml);
if($result)
{
echo '生成成功,<a href="sitemap.xml">點(diǎn)此查看</a>';
}
else
{
echo '生成失敗,<a href="'.$current_script_name.'">在來一次</a>!';
}
}
else
{
echo '歡迎使用微笑的魚Sitemap生成工具,請(qǐng)<a href="'.$current_script_name.'?operation=makexml">點(diǎn)此生成</a>!';
}</p> <p></p> <p>
//保存到文件
function save_xml($filename, $text) {
if (!$filename || !$text)
return false;

@chmod($filename,0777);
if ($fp = fopen($filename, "w")) {
if (@fwrite($fp, $text)) {
fclose($fp);
return true;
} else {
fclose($fp);
return false;
}
}
return false;
}
//生成Sitemap XML數(shù)據(jù)
function generate_sitemp_xml()
{
global $dbtbpre,$empire;

$xml = '';
$xml .= '<?xml version="1.0" encoding="utf-8"?>' .PHP_EOL;
$xml .= '<urlset>' .PHP_EOL;
$xml .= generate_home_xml();//首頁(yè)
$xml .= generate_class_xml();//欄目

$query="select * from {$dbtbpre}ecms_news order by id desc limit 100";
$sql=$empire->query($query);
while($r=$empire->fetch($sql))
{
$titleurl=sys_ReturnBqTitleLink($r);

$xml .= ' <url>' .PHP_EOL;
$xml .= ' <loc>'.$titleurl.'</loc>' .PHP_EOL;
$xml .= ' <lastmod>'.strftime('%Y-%m-%d',$r['newstime']).'</lastmod>' .PHP_EOL;
$xml .= ' <changefreq>daily</changefreq>' .PHP_EOL;
$xml .= ' <priority>0.8</priority>' .PHP_EOL;
$xml .= ' </url>' .PHP_EOL;

}
$xml .= '</urlset>' .PHP_EOL;

return $xml;
}
//生成欄目鏈接XML數(shù)據(jù)
function generate_class_xml()
{
global $dbtbpre,$empire,$class_r;
$xml = '';

$sql=$empire->query("SELECT * FROM {$dbtbpre}enewsclass WHERE islast=1");
while($r=$empire->fetch($sql))
{
$infor=$empire->fetch1("SELECT newstime FROM {$dbtbpre}ecms_".$class_r[$r[classid]][tbname]." WHERE classid='$r[classid]' ORDER BY newstime DESC LIMIT 1");
$class_url=sys_ReturnBqClassname($r, 9);

$xml .= ' <url>' .PHP_EOL;
$xml .= ' <loc>'.$class_url.'</loc>' .PHP_EOL;
$xml .= ' <lastmod>'.strftime('%Y-%m-%d',time()).'</lastmod>' .PHP_EOL;
$xml .= ' <changefreq>daily</changefreq>' .PHP_EOL;
$xml .= ' <priority>0.8</priority>' .PHP_EOL;
$xml .= ' </url>' .PHP_EOL;

}

return $xml;
}
//生成欄目鏈接XML數(shù)據(jù)
function generate_home_xml()
{
$xml = '';
$xml .= ' <url>' .PHP_EOL;
$xml .= ' <loc>http://www.dbjr.com.cn</loc>' .PHP_EOL;
$xml .= ' <lastmod>'.strftime('%Y-%m-%d',time()).'</lastmod>' .PHP_EOL;
$xml .= ' <changefreq>daily</changefreq>' .PHP_EOL;
$xml .= ' <priority>0.8</priority>' .PHP_EOL;
$xml .= ' </url>' .PHP_EOL;

return $xml;</p> <p>}</p> <p>/*關(guān)閉數(shù)據(jù)庫(kù)連接 與 釋放類*/
db_close();
$empire=null;
?>

文章來源:微笑的魚

相關(guān)文章

最新評(píng)論