search
HomeCMS TutorialEmpire CMSClassic Empire CMS generates sitemap for code sharing

Classic Empire CMS generates sitemap for code sharing

Because I was not satisfied with the sitemap plug-in of Empire CMS, I wrote a sitemap generation tool myself, put the homepage link, column page link and content page link in the sitemap, and then generated XML file and submit it to Baidu Webmaster Tools. The code in this article needs to be generated vividly. I wrote a scheduled task using cron in Linux and generated it once a day at a fixed time. Let’s do this for now~

The code is as follows:

<?php
/*引用文件*/
require(&#39;e/class/connect.php&#39;);
require(&#39;e/class/db_sql.php&#39;);
require(&#39;e/data/dbcache/class.php&#39;);</p> <p>/*建立数据库链接 与 实例化类*/
$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[&#39;operation&#39;];
$current_url = explode(&#39;/&#39;,$_SERVER[&#39;PHP_SELF&#39;]);
$current_script_name = end($current_url); </p> <p>if($operation && $operation == "makexml")
{
$xml = generate_sitemp_xml();
$result = save_xml(&#39;sitemap.xml&#39;,$xml);
if($result)
{
echo &#39;生成成功,<a href="sitemap.xml">点此查看</a>&#39;;
}
else
{
echo &#39;生成失败,<a href="&#39;.$current_script_name.&#39;">在来一次</a>!&#39;;
}
}
else
{
echo &#39;欢迎使用微笑的鱼Sitemap生成工具,请<a href="&#39;.$current_script_name.&#39;?operation=makexml">点此生成</a>!&#39;;
}</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数据
function generate_sitemp_xml()
{
global $dbtbpre,$empire;

$xml = &#39;&#39;;
$xml .= &#39;<?xml version="1.0" encoding="utf-8"?>&#39; .PHP_EOL;
$xml .= &#39;<urlset>&#39; .PHP_EOL;
$xml .= generate_home_xml();//首页
$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 .= &#39; <url>&#39; .PHP_EOL;
$xml .= &#39; <loc>&#39;.$titleurl.&#39;</loc>&#39; .PHP_EOL;
$xml .= &#39; <lastmod>&#39;.strftime(&#39;%Y-%m-%d&#39;,$r[&#39;newstime&#39;]).&#39;</lastmod>&#39; .PHP_EOL;
$xml .= &#39; <changefreq>daily</changefreq>&#39; .PHP_EOL;
$xml .= &#39; <priority>0.8</priority>&#39; .PHP_EOL;
$xml .= &#39; </url>&#39; .PHP_EOL;

}
$xml .= &#39;</urlset>&#39; .PHP_EOL;

return $xml;
}
//生成栏目链接XML数据
function generate_class_xml()
{
global $dbtbpre,$empire,$class_r;
$xml = &#39;&#39;;

$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=&#39;$r[classid]&#39; ORDER BY newstime DESC LIMIT 1");
$class_url=sys_ReturnBqClassname($r, 9);

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

}

return $xml;
}
//生成栏目链接XML数据
function generate_home_xml()
{
$xml = &#39;&#39;;
$xml .= &#39; <url>&#39; .PHP_EOL;
$xml .= &#39; <loc>https://www.jb51.net</loc>&#39; .PHP_EOL;
$xml .= &#39; <lastmod>&#39;.strftime(&#39;%Y-%m-%d&#39;,time()).&#39;</lastmod>&#39; .PHP_EOL;
$xml .= &#39; <changefreq>daily</changefreq>&#39; .PHP_EOL;
$xml .= &#39; <priority>0.8</priority>&#39; .PHP_EOL;
$xml .= &#39; </url>&#39; .PHP_EOL;

return $xml;</p> <p>}</p> <p>/*关闭数据库连接 与 释放类*/
db_close();
$empire=null;
?

Recommended to study "Empirecms Tutorial"

The above is the detailed content of Classic Empire CMS generates sitemap for code sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:www.word666.com. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment