@@ -14,18 +14,22 @@ public function action()
1414 ->where ('table.contents.type = ? ' , 'page ' )
1515 ->order ('table.contents.created ' , Typecho_Db::SORT_DESC ));
1616
17- $ articles = $ db ->fetchAll ($ db ->select ()->from ('table.contents ' )
17+ $ articleCount = $ db ->fetchObject ($ db ->select (array ( ' COUNT(table.contents.cid) ' => ' num ' ) )->from ('table.contents ' )
1818 ->where ('table.contents.status = ? ' , 'publish ' )
19- ->where ('table.contents.created < ? ' , $ options ->gmtTime )
20- ->where ('table.contents.type = ? ' , 'post ' )
21- ->order ('table.contents.created ' , Typecho_Db::SORT_DESC ));
19+ ->where ('table.contents.created < ? ' , $ options ->time )
20+ ->where ('table.contents.type = ? ' , 'post ' ))->num ;
21+
22+ Typecho_Widget::widget (
23+ 'Widget_Contents_Post_Recent@sitemapArticles ' ,
24+ 'pageSize= ' . max (1 , (int ) $ articleCount )
25+ )->to ($ articles );
2226
2327 Typecho_Widget::widget ('Widget_Metas_Category_List@cate ' )->to ($ cates );
24-
2528
2629 $ tags = $ db ->fetchAll ($ db ->select ()->from ('table.metas ' )
2730 ->where ('table.metas.type = ? ' , 'tag ' )
2831 ->order ('table.metas.mid ' , Typecho_Db::SORT_DESC ));
32+ $ minTagCount = max (1 , (int ) $ options ->plugin ('Sitemap ' )->minTagCount );
2933
3034 header ("Content-Type: application/xml " );
3135 echo "<?xml version= \"1.0 \" encoding= \"utf-8 \"?> \n" ;
@@ -49,26 +53,10 @@ public function action()
4953 echo "\t\t<priority>0.6</priority> \n" ;
5054 echo "\t</url> \n" ;
5155 }
52- foreach ($ articles AS $ article ) {
53- $ type = $ article ['type ' ];
54- $ article ['categories ' ] = $ db ->fetchAll ($ db ->select ()->from ('table.metas ' )
55- ->join ('table.relationships ' , 'table.relationships.mid = table.metas.mid ' )
56- ->where ('table.relationships.cid = ? ' , $ article ['cid ' ])
57- ->where ('table.metas.type = ? ' , 'category ' )
58- ->order ('table.metas.order ' , Typecho_Db::SORT_ASC ));
59- $ article ['category ' ] = urlencode (current (Typecho_Common::arrayFlatten ($ article ['categories ' ], 'slug ' )));
60- $ article ['slug ' ] = urlencode ($ article ['slug ' ]);
61- $ article ['date ' ] = new Typecho_Date ($ article ['created ' ]);
62- $ article ['year ' ] = $ article ['date ' ]->year ;
63- $ article ['month ' ] = $ article ['date ' ]->month ;
64- $ article ['day ' ] = $ article ['date ' ]->day ;
65- $ routeExists = (NULL != Typecho_Router::get ($ type ));
66- $ article ['pathinfo ' ] = $ routeExists ? Typecho_Router::url ($ type , $ article ) : '# ' ;
67- $ article ['permalink ' ] = Typecho_Common::url ($ article ['pathinfo ' ], $ options ->index );
68-
56+ while ($ articles ->next ()) {
6957 echo "\t<url> \n" ;
70- echo "\t\t<loc> " .$ article [ ' permalink ' ] ."</loc> \n" ;
71- echo "\t\t<lastmod> " .date ('Y-m-d ' ,$ article [ ' modified ' ] )."</lastmod> \n" ;
58+ echo "\t\t<loc> " .$ articles -> permalink ."</loc> \n" ;
59+ echo "\t\t<lastmod> " .date ('Y-m-d ' ,$ articles -> modified )."</lastmod> \n" ;
7260 echo "\t\t<changefreq>always</changefreq> \n" ;
7361 echo "\t\t<priority>0.8</priority> \n" ;
7462 echo "\t</url> \n" ;
@@ -91,22 +79,24 @@ public function action()
9179 }
9280 foreach ($ tags AS $ tag ) {
9381 $ type = $ tag ['type ' ];
94- $ art_rt = $ db ->fetchRow ($ db ->select ()->from ('table.contents ' )
82+ $ tagArticles = $ db ->fetchAll ($ db ->select (' table.contents.modified ' )->from ('table.contents ' )
9583 ->join ('table.relationships ' , 'table.contents.cid = table.relationships.cid ' )
9684 ->where ('table.contents.status = ? ' , 'publish ' )
85+ ->where ('table.contents.created < ? ' , $ options ->time )
86+ ->where ('table.contents.type = ? ' , 'post ' )
9787 ->where ('table.relationships.mid = ? ' , $ tag ['mid ' ])
98- ->order ('table.relationships.cid ' , Typecho_Db::SORT_DESC )
99- ->limit (1 ));
100- // 文章的标签跳过
101- if ( empty ( $ art_rt [ ' modified ' ])) continue ;
88+ ->order ('table.contents.modified ' , Typecho_Db::SORT_DESC )
89+ ->limit ($ minTagCount ));
90+ if ( count ( $ tagArticles ) < $ minTagCount ) continue ;
91+ $ latestTagArticle = current ( $ tagArticles ) ;
10292
10393 $ routeExists = (NULL != Typecho_Router::get ($ type ));
10494 $ tag ['pathinfo ' ] = $ routeExists ? Typecho_Router::url ($ type , $ tag ) : '# ' ;
10595 $ tag ['permalink ' ] = Typecho_Common::url ($ tag ['pathinfo ' ], $ options ->index );
10696
10797 echo "\t<url> \n" ;
10898 echo "\t\t<loc> " .$ tag ['permalink ' ]."</loc> \n" ;
109- echo "\t\t<lastmod> " .date ('Y-m-d ' ,$ art_rt ['modified ' ])."</lastmod> \n" ;
99+ echo "\t\t<lastmod> " .date ('Y-m-d ' ,$ latestTagArticle ['modified ' ])."</lastmod> \n" ;
110100 echo "\t\t<changefreq>daily</changefreq> \n" ;
111101 echo "\t\t<priority>0.5</priority> \n" ;
112102 echo "\t</url> \n" ;
0 commit comments