parent
392b685530
commit
f890f0c850
4 changed files with 218 additions and 0 deletions
@ -0,0 +1 @@ |
|||||||
|
google-site-verification: google9fe984dd345e8a6a.html |
@ -0,0 +1,64 @@ |
|||||||
|
<?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($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.8</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.5</priority>\n"; |
||||||
|
echo "\t</url>\n"; |
||||||
|
} |
||||||
|
echo "</urlset>"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,54 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* Sitemap for Typecho |
||||||
|
* |
||||||
|
* @package Sitemap |
||||||
|
* @author bayunjiang |
||||||
|
* @version 1.0.0 |
||||||
|
* @link https://www.bayun.org |
||||||
|
* |
||||||
|
*/ |
||||||
|
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){} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,99 @@ |
|||||||
|
<?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; |
||||||
|
} |
||||||
|
|
||||||
|
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="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"> |
||||||
|
<a href="https://www.eee.dog" target="_blank">呓喵酱</a> |
||||||
|
</div> |
||||||
|
</body> |
||||||
|
</html> |
||||||
|
</xsl:template> |
||||||
|
</xsl:stylesheet> |
Loading…
Reference in new issue