From 12a18f414b579ac6914449b90bc3a9809ab7ffd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E6=81=92?= <2323333339@qq.com> Date: Fri, 19 Feb 2021 15:30:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core.php | 6 ++++++ core/function.php | 2 +- functions.php | 3 ++- library/sitemap.php | 52 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 library/sitemap.php diff --git a/core/core.php b/core/core.php index de07f2a..9a14a27 100644 --- a/core/core.php +++ b/core/core.php @@ -71,6 +71,12 @@ function themeInit($self) break; }; } + + /* 增加自定义sitemap功能 */ + if ($self->request->getRequestUri() == "/sitemap.xml" || $self->request->getRequestUri() == "/index.php/sitemap.xml") { + $self->setThemeFile("library/sitemap.php"); + $self->response->setStatus(200); + } } /* 增加自定义字段 */ diff --git a/core/function.php b/core/function.php index 1c4b85f..5177067 100644 --- a/core/function.php +++ b/core/function.php @@ -3,7 +3,7 @@ /* 获取主题当前版本号 */ function _getVersion() { - return "5.1.9"; + return "5.2.0"; }; /* 判断是否是手机 */ diff --git a/functions.php b/functions.php index d20bbf7..2ae7669 100644 --- a/functions.php +++ b/functions.php @@ -195,7 +195,8 @@ function themeConfig($form) $JFooter_Right = new Typecho_Widget_Helper_Form_Element_Textarea( 'JFooter_Right', NULL, - 'RSS', + 'RSS + MAP', '自定义底部栏右侧内容(非必填)', '介绍:用于修改全站底部右侧内容
例如:<a href="/">首页</a> <a href="/">关于</a>' diff --git a/library/sitemap.php b/library/sitemap.php new file mode 100644 index 0000000..f810ffe --- /dev/null +++ b/library/sitemap.php @@ -0,0 +1,52 @@ +fetchAll($db->select()->from('table.contents') + ->where('table.contents.status = ?', 'publish') + ->where('table.contents.created < ?', $options->gmtTime) + ->where('table.contents.type = ?', 'page') + ->order('table.contents.created', Typecho_Db::SORT_DESC)); +$articles = $db->fetchAll($db->select()->from('table.contents') + ->where('table.contents.status = ?', 'publish') + ->where('table.contents.created < ?', $options->gmtTime) + ->where('table.contents.type = ?', 'post') + ->order('table.contents.created', Typecho_Db::SORT_DESC)); +header("Content-Type: application/xml"); +echo "\n"; +echo "\n"; +foreach ($pages as $page) { + $type = $page['type']; + $routeExists = (NULL != Typecho_Router::get($type)); + $page['pathinfo'] = $routeExists ? Typecho_Router::url($type, $page) : '#'; + $page['permalink'] = Typecho_Common::url($page['pathinfo'], $options->index); + echo "\t\n"; + echo "\t\t" . $page['permalink'] . "\n"; + echo "\t\t" . date('Y-m-d\TH:i:s\Z', $page['modified']) . "\n"; + echo "\t\talways\n"; + echo "\t\t0.8\n"; + echo "\t\n"; +} +foreach ($articles as $article) { + $type = $article['type']; + $article['categories'] = $db->fetchAll($db->select()->from('table.metas') + ->join('table.relationships', 'table.relationships.mid = table.metas.mid') + ->where('table.relationships.cid = ?', $article['cid']) + ->where('table.metas.type = ?', 'category') + ->order('table.metas.order', Typecho_Db::SORT_ASC)); + $article['category'] = urlencode(current(Typecho_Common::arrayFlatten($article['categories'], 'slug'))); + $article['slug'] = urlencode($article['slug']); + $article['date'] = new Typecho_Date($article['created']); + $article['year'] = $article['date']->year; + $article['month'] = $article['date']->month; + $article['day'] = $article['date']->day; + $routeExists = (NULL != Typecho_Router::get($type)); + $article['pathinfo'] = $routeExists ? Typecho_Router::url($type, $article) : '#'; + $article['permalink'] = Typecho_Common::url($article['pathinfo'], $options->index); + echo "\t\n"; + echo "\t\t" . $article['permalink'] . "\n"; + echo "\t\t" . date('Y-m-d\TH:i:s\Z', $article['modified']) . "\n"; + echo "\t\talways\n"; + echo "\t\t0.5\n"; + echo "\t\n"; +} +echo "";