diff --git a/core/core.php b/core/core.php index a100512..3e407b8 100644 --- a/core/core.php +++ b/core/core.php @@ -70,10 +70,12 @@ function themeInit($self) }; } - /* 增加自定义sitemap功能 */ - if ($self->request->getRequestUri() == "/sitemap.xml" || $self->request->getRequestUri() == "/index.php/sitemap.xml") { - $self->setThemeFile("library/sitemap.php"); - $self->response->setStatus(200); + /* 增加自定义SiteMap功能 */ + if (Helper::options()->JSiteMap && Helper::options()->JSiteMap !== 'off') { + 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 e106bf5..78cd678 100644 --- a/core/function.php +++ b/core/function.php @@ -3,7 +3,7 @@ /* 获取主题当前版本号 */ function _getVersion() { - return "5.5.9"; + return "5.6.0"; }; /* 判断是否是手机 */ diff --git a/functions.php b/functions.php index bb11b42..8976c16 100644 --- a/functions.php +++ b/functions.php @@ -851,6 +851,34 @@ function themeConfig($form) $JPasteUpload->setAttribute('class', 'joe_content joe_other'); $form->addInput($JPasteUpload->multiMode()); + $JSiteMap = new Typecho_Widget_Helper_Form_Element_Select( + 'JSiteMap', + array( + 'off' => '关闭(默认)', + '100' => '显示最新 100 条链接', + '200' => '显示最新 200 条链接', + '300' => '显示最新 300 条链接', + '400' => '显示最新 400 条链接', + '500' => '显示最新 500 条链接', + '600' => '显示最新 600 条链接', + '700' => '显示最新 700 条链接', + '800' => '显示最新 800 条链接', + '900' => '显示最新 900 条链接', + '1000' => '显示最新 1000 条链接', + ), + 'off', + '是否开启主题自带SiteMap功能', + '介绍:开启后博客将享有SiteMap功能
+ 其他:链接为博客最新实时链接
+ 好处:无需手动生成,无需频繁提交,提交一次即可
+ 开启后SiteMap访问地址:
+ http(s)://域名/sitemap.xml (开启了伪静态)
+ http(s)://域名/index.php/sitemap.xml (未开启伪静态) + ' + ); + $JSiteMap->setAttribute('class', 'joe_content joe_other'); + $form->addInput($JSiteMap->multiMode()); + $JBaiduToken = new Typecho_Widget_Helper_Form_Element_Text( 'JBaiduToken', NULL, diff --git a/library/sitemap.php b/library/sitemap.php index f810ffe..3e20d74 100644 --- a/library/sitemap.php +++ b/library/sitemap.php @@ -1,16 +1,24 @@ 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)); +$limit = Helper::options()->JSiteMap; +$pages = $db->fetchAll( + $db->select()->from('table.contents') + ->where('table.contents.status = ?', 'publish') + ->where('table.contents.created < ?', $options->gmtTime) + ->where('table.contents.type = ?', 'page') + ->limit($limit) + ->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') + ->limit($limit) + ->order('table.contents.created', Typecho_Db::SORT_DESC) +); header("Content-Type: application/xml"); echo "\n"; echo "\n"; @@ -22,7 +30,7 @@ foreach ($pages as $page) { 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\tmonthly\n"; echo "\t\t0.8\n"; echo "\t\n"; } @@ -45,7 +53,7 @@ foreach ($articles as $article) { 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\tmonthly\n"; echo "\t\t0.5\n"; echo "\t\n"; }