forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
383 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
class Sitemap_Action extends Typecho_Widget implements Widget_Interface_Do | ||
{ | ||
public function action() | ||
{ | ||
$db = Typecho_Db::get(); | ||
$options = Typecho_Widget::widget('Widget_Options'); | ||
|
||
$pages = $db->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)); | ||
|
||
$cates = $db->fetchAll($db->select()->from('table.metas') | ||
->where('table.metas.type = ?', 'category') | ||
->order('table.metas.order', Typecho_Db::SORT_DESC)); | ||
|
||
$tags = $db->fetchAll($db->select()->from('table.metas') | ||
->where('table.metas.type = ?', 'tag') | ||
->order('table.metas.mid', Typecho_Db::SORT_DESC)); | ||
|
||
header("Content-Type: application/xml"); | ||
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; | ||
echo "<?xml-stylesheet type='text/xsl' href='" . $options->pluginUrl . "/Sitemap/sitemap.xsl'?>\n"; | ||
echo "<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\nxsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"\nxmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"; | ||
echo "\t<url>\n"; | ||
echo "\t\t<loc>".$options->siteUrl."</loc>\n"; | ||
echo "\t\t<changefreq>daily</changefreq>\n"; | ||
echo "\t\t<priority>1.0</priority>\n"; | ||
echo "\t</url>\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<url>\n"; | ||
echo "\t\t<loc>".$page['permalink']."</loc>\n"; | ||
echo "\t\t<lastmod>".date('Y-m-d',$page['modified'])."</lastmod>\n"; | ||
echo "\t\t<changefreq>always</changefreq>\n"; | ||
echo "\t\t<priority>0.6</priority>\n"; | ||
echo "\t</url>\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<url>\n"; | ||
echo "\t\t<loc>".$article['permalink']."</loc>\n"; | ||
echo "\t\t<lastmod>".date('Y-m-d',$article['modified'])."</lastmod>\n"; | ||
echo "\t\t<changefreq>always</changefreq>\n"; | ||
echo "\t\t<priority>0.8</priority>\n"; | ||
echo "\t</url>\n"; | ||
} | ||
foreach($cates AS $cate) { | ||
$type = $cate['type']; | ||
$art_rs = $db->fetchRow($db->select()->from('table.contents') | ||
->join('table.relationships', 'table.contents.cid = table.relationships.cid') | ||
->where('table.contents.status = ?', 'publish') | ||
->where('table.relationships.mid = ?', $cate['mid']) | ||
->order('table.relationships.cid', Typecho_Db::SORT_DESC) | ||
->limit(1)); | ||
$routeExists = (NULL != Typecho_Router::get($type)); | ||
$cate['pathinfo'] = $routeExists ? Typecho_Router::url($type, $cate) : '#'; | ||
$cate['permalink'] = Typecho_Common::url($cate['pathinfo'], $options->index); | ||
|
||
echo "\t<url>\n"; | ||
echo "\t\t<loc>".$cate['permalink']."</loc>\n"; | ||
echo "\t\t<lastmod>".date('Y-m-d',$art_rs['modified'])."</lastmod>\n"; | ||
echo "\t\t<changefreq>daily</changefreq>\n"; | ||
echo "\t\t<priority>0.5</priority>\n"; | ||
echo "\t</url>\n"; | ||
} | ||
foreach($tags AS $tag) { | ||
$type = $tag['type']; | ||
$art_rt = $db->fetchRow($db->select()->from('table.contents') | ||
->join('table.relationships', 'table.contents.cid = table.relationships.cid') | ||
->where('table.contents.status = ?', 'publish') | ||
->where('table.relationships.mid = ?', $tag['mid']) | ||
->order('table.relationships.cid', Typecho_Db::SORT_DESC) | ||
->limit(1)); | ||
$routeExists = (NULL != Typecho_Router::get($type)); | ||
$tag['pathinfo'] = $routeExists ? Typecho_Router::url($type, $tag) : '#'; | ||
$tag['permalink'] = Typecho_Common::url($tag['pathinfo'], $options->index); | ||
|
||
echo "\t<url>\n"; | ||
echo "\t\t<loc>".$tag['permalink']."</loc>\n"; | ||
echo "\t\t<lastmod>".date('Y-m-d',$art_rt['modified'])."</lastmod>\n"; | ||
echo "\t\t<changefreq>daily</changefreq>\n"; | ||
echo "\t\t<priority>0.5</priority>\n"; | ||
echo "\t</url>\n"; | ||
} | ||
echo "</urlset>"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Google Sitemap 生成器 【<a href="https://github.com/typecho-fans/plugins" target="_blank">TF</a>社区维护版】 | ||
* | ||
* @package Sitemap | ||
* @author 迷你日志,八云酱,Hanny | ||
* @version 1.0.4 | ||
* @dependence 9.9.2-* | ||
* @link https://github.com/typecho-fans/plugins/blob/master/Sitemap | ||
* | ||
* version 1.0.4 at 2020-07-02 by Typecho Fans (合并多人修改) | ||
* 页面改xml后缀,加入美化样式,简化时间戳 by Suming/八云酱 | ||
* 调整优先级比例,增加分类页面及首页链接 by 迷你日志/羽中 | ||
* | ||
* version 1.0.3 at 2017-03-28 by 禾令奇 | ||
* 修改增加标签链接,修改页面权重分级 | ||
* | ||
* 历史版本 | ||
* version 1.0.1 at 2010-01-02 | ||
* 修改自定义静态链接时错误的Bug | ||
* | ||
* version 1.0.0 at 2010-01-02 | ||
* Sitemap for Google | ||
* 生成文章和页面的Sitemap | ||
* | ||
*/ | ||
class Sitemap_Plugin implements Typecho_Plugin_Interface | ||
{ | ||
/** | ||
* 激活插件方法,如果激活失败,直接抛出异常 | ||
* | ||
* @access public | ||
* @return void | ||
* @throws Typecho_Plugin_Exception | ||
*/ | ||
public static function activate() | ||
{ | ||
Helper::addRoute('sitemap', '/sitemap.xml', 'Sitemap_Action', 'action'); | ||
} | ||
|
||
/** | ||
* 禁用插件方法,如果禁用失败,直接抛出异常 | ||
* | ||
* @static | ||
* @access public | ||
* @return void | ||
* @throws Typecho_Plugin_Exception | ||
*/ | ||
public static function deactivate() | ||
{ | ||
Helper::removeRoute('sitemap'); | ||
} | ||
|
||
/** | ||
* 获取插件配置面板 | ||
* | ||
* @access public | ||
* @param Typecho_Widget_Helper_Form $form 配置面板 | ||
* @return void | ||
*/ | ||
public static function config(Typecho_Widget_Helper_Form $form){} | ||
|
||
/** | ||
* 个人用户的配置面板 | ||
* | ||
* @access public | ||
* @param Typecho_Widget_Helper_Form $form | ||
* @return void | ||
*/ | ||
public static function personalConfig(Typecho_Widget_Helper_Form $form){} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<a href="https://typecho-fans.github.io"> | ||
<img src="https://typecho-fans.github.io/text-logo.svg" alt="TF Logo" title="Typecho Fans开源作品社区" align="right" height="100" /> | ||
</a> | ||
|
||
Sitemap v1.0.4 - 社区维护版 | ||
====================== | ||
<h4 align="center">—— 动态生成符合搜索引擎收录标准的Xml格式站点地图插件,支持输出分类/标签页地址。</h4> | ||
|
||
<p align="center"> | ||
<a href="#使用说明">使用说明</a> • | ||
<a href="#版本历史">版本历史</a> • | ||
<a href="#贡献作者">贡献作者</a> • | ||
<a href="#附注链接">附注/链接</a> • | ||
<a href="#授权协议">授权协议</a> | ||
</p> | ||
|
||
--- | ||
|
||
## 使用说明 | ||
|
||
<table> | ||
<tr> | ||
<td> | ||
|
||
###### Sitemap 可方便站长通知搜索引擎网站上有哪些可供抓取的网页。最简单通行的就是Google制定的XML格式标准,其中可列出网址及其元数据(上次更新时间、更改频率和优先级权重等),便于搜索引擎更高效智能地抓取网站内容。 | ||
|
||
**使用方法**: | ||
##### 1. 下载本插件,放在 `usr/plugins/` 目录中,确保文件夹名为 Sitemap; | ||
##### 2. 激活插件; | ||
##### 3. 访问http://[example].com/sitemap.xml即可看到页面效果。 | ||
|
||
</td> | ||
</tr> | ||
</table> | ||
|
||
## 版本历史 | ||
|
||
* v1.0.4 (20-7-02 [@jzwalk](https://github.com/jzwalk)) | ||
* 增加首页地址输出,合并4个衍生版改动: | ||
* 含魔改版Sitemap功能支持分类/标签地址输出([@kavico](https://minirizhi.com)); | ||
* 对调页面文章优先级使Google正常收录([@raymond9zhou](https://github.com/raymond9zhou)); | ||
* 简化样式说明,优化时间戳仅保留日期([@bayunjiang](https://github.com/bayunjiang)); | ||
* 页面路径带xml文件后缀,套用xsl美化样式([@Suming](https://inwao.com))。 | ||
* v1.0.3 (17-03-28 [@Vicshs](https://github.com/Vicshs)) | ||
* 增加标签页地址遍历; | ||
* 提升页面地址优先级。 | ||
* v1.0.2 ([@Vicshs](https://github.com/Vicshs)) | ||
* (不详) | ||
* v1.0.1 (10-01-02 [@Hanny](http://www.imhan.com)) | ||
* 修改自定义静态链接时错误的Bug。 | ||
* v1.0.0 (10-01-02 [@Hanny](http://www.imhan.com)) | ||
* 实现生成含文章页面地址的Google标准sitemap页面。 | ||
|
||
## 贡献作者 | ||
|
||
[](https://github.com/jzwalk) | [](https://minirizhi.com) | [](https://github.com/raymond9zhou) | [](https://github.com/bayunjiang) | [](https://inwao.com) | [](http://www.imhan.com) | ||
:---:|:---:|:---:|:---:|:---:|:---: | ||
[jzwalk](https://github.com/jzwalk) (2020) | [kavico](https://minirizhi.com) (2020) | [raymond9zhou](https://github.com/raymond9zhou) (2019) | [bayunjiang](https://github.com/bayunjiang) (2017) | [Suming](https://inwao.com) (2016) | [Hanny](http://www.imhan.com) (2010) | ||
|
||
*为避免作者栏显示过长,插件信息仅选取登记3个署名,如有异议可协商修改。 | ||
|
||
## 附注/链接 | ||
|
||
本社区维护版已包含以下各版本功能并做优化调整: | ||
|
||
* [合并版(kavico)](http://forum.typecho.org/viewtopic.php?f=6&t=12315&p=45414) - 含输出分类功能。 | ||
* [微调版(raymond9zhou)](https://github.com/raymond9zhou/typecho-auto-sitemap-plugin) - 调整优先级。 | ||
* [增强版(Vicshs)](https://github.com/Vicshs/Sitemap) - 输出tag,提升优先级。 | ||
* [简化版(bayunjiang)](https://github.com/bayunjiang/typecho-sitemap) - 简化样式及时间戳。 | ||
* [美化版(Suming)](https://inwao.com/Sitemap.html) - 改xml后缀,套用样式。 | ||
* [原版](http://www.imhan.com/typecho) - 实现基本功能。 | ||
|
||
欢迎社区成员继续贡献代码参与更新。 | ||
|
||
## 授权协议 | ||
|
||
TF目录下的社区维护版作品如果没有明确声明,默认采用与Typecho相同的[GPLv2](https://github.com/typecho/typecho/blob/master/LICENSE.txt)开源协议。(要求提及出处,保持开源并注明修改。) | ||
|
||
> Sitemap原作未附协议声明,原作者保留所有权利。 © [Hanny](http://www.imhan.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="2.0" | ||
xmlns:html="http://www.w3.org/TR/REC-html40" | ||
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> | ||
<xsl:template match="/"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title>XML Sitemap</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<style type="text/css"> | ||
body { | ||
font-family:"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana; | ||
font-size:13px; | ||
} | ||
|
||
#intro { | ||
background-color:#CFEBF7; | ||
border:1px #2580B2 solid; | ||
padding:5px 13px 5px 13px; | ||
margin:10px; | ||
} | ||
|
||
#intro p { | ||
line-height: 16.8667px; | ||
} | ||
|
||
table { | ||
width: 100%; | ||
} | ||
|
||
td { | ||
font-size:11px; | ||
} | ||
|
||
th { | ||
text-align:left; | ||
padding-right:30px; | ||
font-size:11px; | ||
} | ||
|
||
tr.even { | ||
background-color:whitesmoke; | ||
} | ||
|
||
#footer { | ||
padding:2px; | ||
margin:10px; | ||
font-size:8pt; | ||
color:gray; | ||
} | ||
|
||
#footer a { | ||
color:gray; | ||
} | ||
|
||
a { | ||
color:black; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>XML Sitemap</h1> | ||
<div id="intro"> | ||
<p> | ||
This is a XML Sitemap which is supposed to be processed by search engines like <a href="http://www.baidu.com">Baidu</a>, <a href="http://www.google.com">Google</a>, <a href="http://www.so.com">360</a>, <a href="http://www.bing.com">Bing</a> and <a href="http://www.sogou.com">Sogou</a>.<br /> | ||
You can find more information about XML sitemaps on <a href="http://sitemaps.org">sitemaps.org</a> and Google's <a href="http://code.google.com/sm_thirdparty.html">list of sitemap programs</a>. | ||
</p> | ||
</div> | ||
<div id="content"> | ||
<table cellpadding="5"> | ||
<tr style="border-bottom:1px black solid;"> | ||
<th>URL</th> | ||
<th>Priority</th> | ||
<th>Change Frequency</th> | ||
<th>LastChange</th> | ||
</tr> | ||
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/> | ||
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> | ||
<xsl:for-each select="sitemap:urlset/sitemap:url"> | ||
<tr> | ||
<xsl:if test="position() mod 2 != 0"> | ||
<xsl:attribute name="class">ood</xsl:attribute> | ||
</xsl:if> | ||
<xsl:if test="position() mod 2 != 1"> | ||
<xsl:attribute name="class">even</xsl:attribute> | ||
</xsl:if> | ||
<td> | ||
<xsl:variable name="itemURL"> | ||
<xsl:value-of select="sitemap:loc"/> | ||
</xsl:variable> | ||
<a href="{$itemURL}"> | ||
<xsl:value-of select="sitemap:loc"/> | ||
</a> | ||
</td> | ||
<td> | ||
<xsl:value-of select="concat(sitemap:priority*100,'%')"/> | ||
</td> | ||
<td> | ||
<xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat($lower, $upper),concat($upper, $lower)),substring(sitemap:changefreq, 2))"/> | ||
</td> | ||
<td> | ||
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/> | ||
</td> | ||
</tr> | ||
</xsl:for-each> | ||
</table> | ||
</div> | ||
<div id="footer"> | ||
This XSLT template is released under GPL. | ||
</div> | ||
</body> | ||
</html> | ||
</xsl:template> | ||
</xsl:stylesheet> |
Binary file not shown.