| Server IP : 156.238.232.47 / Your IP : 216.73.216.150 Web Server : nginx/1.25.3 System : Linux C202504152095410 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : www ( 1000) PHP Version : 8.3.25 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /www/data/wwwroot/2026_06_22_01/apps/home/controller/ |
Upload File : |
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年7月15日
* 生成sitemap文件
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\SitemapModel;
use core\basic\Url;
class SitemapController extends Controller
{
protected $model;
public function __construct()
{
$this->model = new SitemapModel();
}
public function index()
{
header("Content-type:text/xml;charset=utf-8");
$str = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
//$str .= '<urlset>' . "\n";
$str .= '<urlset xmlns= "http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" ;
$str .= $this->makeNode('', date('Y-m-d'), '1.00', 'always'); // 根目录
$sorts = $this->model->getSorts();
$Parser = new ParserController();
foreach ($sorts as $value) {
if ($value->outlink) {
continue;
} elseif ($value->type == 1) {
$link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
$str .= $this->makeNode($link, date('Y-m-d'), '0.80', 'daily');
} else {
$link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
$str .= $this->makeNode($link, date('Y-m-d'), '0.80', 'daily');
$contents = $this->model->getSortContent($value->scode);
foreach ($contents as $value2) {
if ($value2->outlink) { // 外链
continue;
} else {
$link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
}
$str .= $this->makeNode($link, date('Y-m-d', strtotime($value2->date)), '0.60', 'daily');
}
}
}
echo $str . "\n</urlset>";
}
// 生成结点信息
private function makeNode($link, $date, $priority = 0.60, $changefreq = 'always')
{
$node = '
<url>
<loc>' . get_http_url() . $link . '</loc>
<priority>' . $priority . '</priority>
<lastmod>' . $date . '</lastmod>
<changefreq>' . $changefreq . '</changefreq>
</url>';
return $node;
}
// 文本格式 重建静态缓存需要
public function linkTxt()
{
header("Content-type:text/plain;charset=utf-8");
$sorts = $this->model->getSorts();
$Parser = new ParserController();
$str = get_http_url() . "\r\n";
foreach ($sorts as $value) {
if ($value->outlink) {
continue;
} elseif ($value->type == 1) {
$link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
$str .= get_http_url() . $link . "\r\n";
} else {
$link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
$str .= get_http_url() . $link . "\r\n";
$contents = $this->model->getSortContent($value->scode);
foreach ($contents as $value2) {
if ($value2->outlink) { // 外链
continue;
} else {
$link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
}
$str .= get_http_url() . $link . "\r\n";
}
}
}
echo $str;
}
// 文本格式每日 重建静态缓存需要
public function linkTxtday()
{
header("Content-type:text/plain;charset=utf-8");
$sorts = $this->model->getSorts();
$Parser = new ParserController();
$str = get_http_url() . "\r\n";
foreach ($sorts as $value) {
if ($value->outlink) {
continue;
} elseif ($value->type == 1) {
$link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
$str .= get_http_url() . $link . "\r\n";
} else {
$link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
$str .= get_http_url() . $link . "\r\n";
$contents = $this->model->getSortContent($value->scode);
foreach ($contents as $value2) {
if ($value2->outlink) { // 外链
continue;
} else {
if(date('Y-m-d', strtotime($value2->date)) == date('Y-m-d', time())){
$link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
} else {
continue;
}
}
$str .= get_http_url() . $link . "\r\n";
}
}
}
echo $str;
}
}