mirror of
https://github.com/typecho/plugins.git
synced 2025-04-22 14:09:50 +08:00
Merge bb9d1a30e2
into 975251b0f8
This commit is contained in:
commit
ba4b2771c3
66
Sitemap/Action.php
Normal file
66
Sitemap/Action.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?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));
|
||||
|
||||
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\">";
|
||||
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\TH:i:s\Z',$article['modified'])."</lastmod>\n";
|
||||
echo "\t\t<changefreq>always</changefreq>\n";
|
||||
echo "\t\t<priority>0.8</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\TH:i:s\Z',$page['modified'])."</lastmod>\n";
|
||||
echo "\t\t<changefreq>always</changefreq>\n";
|
||||
echo "\t\t<priority>0.6</priority>\n";
|
||||
echo "\t</url>\n";
|
||||
}
|
||||
|
||||
echo "</urlset>";
|
||||
}
|
||||
}
|
55
Sitemap/Plugin.php
Normal file
55
Sitemap/Plugin.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Sitemap 自动生成器<Br />由<a href="https://tyblog.com.cn" title="Ty">Ty</a>开发
|
||||
*
|
||||
* @package XML Sitemap
|
||||
* @author Ty
|
||||
* @version 0.0.1
|
||||
* @link https://tyblog.com.cn
|
||||
*/
|
||||
class Sitemap_Plugin implements Typecho_Plugin_Interface
|
||||
{
|
||||
/**
|
||||
* 激活插件方法,如果激活失败,直接抛出异常
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function activate()
|
||||
{
|
||||
Helper::addRoute('sitemap', '/sitemap-maker.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){}
|
||||
|
||||
}
|
35
Sitemap/README.md
Normal file
35
Sitemap/README.md
Normal file
@ -0,0 +1,35 @@
|
||||
## 系统要求
|
||||
- [CentOS7.0][1]及以后版本(其他Linux系统未验证可用性)
|
||||
- [宝塔面板][2]
|
||||
- [PHP7.4][3]及以后版本(PHP8.0未验证可用性)
|
||||
- Typecho1.1及以后版本
|
||||
## 插件必要设置
|
||||
1.打开宝塔面板,点击‘网站’,点击对应网站的‘设置’
|
||||
|
||||
2.点击‘伪静态’,左上角选择‘typecho’,点击‘保存’
|
||||
|
||||
![伪静态配置][5]
|
||||
|
||||
3.进入typecho后台,点击‘设置->永久链接’
|
||||
|
||||
4.启用‘地址重写功能’
|
||||
## 插件安装
|
||||
1.在GitHub[下载][6]插件
|
||||
|
||||
2.将‘sitemap’目录上传到网站服务器‘/usr/plugins’目录下
|
||||
|
||||
3.进入Typecho后台启用插件
|
||||
## 插件使用
|
||||
**访问http(s)://你的域名/sitemap-maker.xml即可生成XML sitemap**
|
||||
> Demo:[https://tyblog.com.cn/sitemap-maker.xml][7]
|
||||
## 支持
|
||||
在[GitHub][8]提issue
|
||||
|
||||
|
||||
[1]: https://www.centos.org
|
||||
[2]: https://bt.cn
|
||||
[3]: https://www.php.net
|
||||
[5]: http://image-cdn-tyblog.test.upcdn.net/sitemap-plugin/1.png
|
||||
[6]: https://github.com/ty-yqs/Typecho-Sitemap-Plugin
|
||||
[7]: https://tyblog.com.cn/sitemap-maker.xml
|
||||
[8]: https://github.com/ty-yqs/Typecho-Sitemap-Plugin/issues/new
|
112
Sitemap/sitemap.xsl
Normal file
112
Sitemap/sitemap.xsl
Normal file
@ -0,0 +1,112 @@
|
||||
<?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 XML sitemap plugin was made by <a href="https://tyblog.com.cn">Ty</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>
|
||||
</body>
|
||||
</html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
Loading…
Reference in New Issue
Block a user