XML Sitemap & Google News feeds - Version 5.2

Version Description

Major DB query reduction and speed improvements. Bugfixes.

=

Download this release

Release Info

Developer deployer
Plugin Icon 128x128 XML Sitemap & Google News feeds
Version 5.2
Comparing to
See all releases

Code changes from version 5.1.2 to 5.2

Files changed (55) hide show
  1. README.md +6 -0
  2. {views → assets}/images/sitemapxml.gif +0 -0
  3. {views → assets}/styles/admin.css +0 -0
  4. assets/styles/sitemap-custom.xsl +43 -0
  5. {views → assets}/styles/sitemap-index.xsl +2 -3
  6. {views → assets}/styles/sitemap-news.xsl +3 -6
  7. {views → assets}/styles/sitemap-taxonomy.xsl +2 -3
  8. {views → assets}/styles/sitemap.xsl +3 -3
  9. controllers/{admin/notices.php → class.xmlsf-admin-notices.php} +2 -4
  10. controllers/{admin/sitemap-news.php → class.xmlsf-admin-sitemap-news.php} +30 -56
  11. controllers/{admin/sitemap.php → class.xmlsf-admin-sitemap.php} +77 -83
  12. controllers/{admin/main.php → class.xmlsf-admin.php} +53 -36
  13. controllers/class.xmlsf-sitemap-news.php +89 -0
  14. controllers/class.xmlsf-sitemap.php +414 -0
  15. controllers/{global.php → functions.php} +30 -15
  16. controllers/functions.shared.php +73 -0
  17. controllers/main.php +0 -50
  18. controllers/sitemap-news.php +0 -67
  19. controllers/sitemap.php +0 -241
  20. models/admin/sitemap.php +0 -104
  21. models/class-xmlsitemapfeed.php +22 -11
  22. models/{admin/sitemap-news.php → class.xmlsf-admin-sitemap-news-sanitize.php} +0 -0
  23. models/class.xmlsf-admin-sitemap-sanitize.php +148 -0
  24. models/{admin/main.php → functions.admin.php} +11 -0
  25. models/{global.php → functions.php} +1 -1
  26. models/functions.public-shared.php +68 -0
  27. models/{public/sitemap-news.php → functions.public-sitemap-news.php} +61 -13
  28. models/{public/sitemap.php → functions.public-sitemap.php} +264 -234
  29. models/{main.php → functions.shared.php} +25 -24
  30. models/{sitemap-news.php → functions.sitemap-news.php} +1 -1
  31. models/functions.sitemap.php +255 -0
  32. models/public/shared.php +0 -123
  33. models/sitemap.php +0 -68
  34. readme.txt +19 -9
  35. uninstall.php +23 -4
  36. controllers/upgrade.php → upgrade.php +7 -0
  37. views/_generator.php +1 -1
  38. views/_usage.php +1 -1
  39. views/admin/field-news-categories.php +8 -8
  40. views/admin/field-news-image.php +0 -10
  41. views/admin/field-sitemap-taxonomies.php +18 -14
  42. views/admin/field-sitemap-taxonomy-settings.php +32 -34
  43. views/admin/help-tab-news-images.php +0 -7
  44. views/admin/meta-box-news.php +1 -2
  45. views/admin/meta-box.php +13 -9
  46. views/admin/notice-static-files.php +1 -1
  47. views/admin/page-sitemap-news.php +3 -3
  48. views/admin/page-sitemap.php +8 -3
  49. views/feed-sitemap-custom.php +2 -1
  50. views/feed-sitemap-home.php +2 -1
  51. views/feed-sitemap-news.php +4 -38
  52. views/feed-sitemap-post_type.php +30 -29
  53. views/feed-sitemap-taxonomy.php +4 -3
  54. views/feed-sitemap.php +6 -5
  55. xml-sitemap.php +8 -4
README.md ADDED
@@ -0,0 +1,6 @@
1
+ # XML Sitemap & Google News feeds
2
+
3
+ XML and Google News Sitemaps for WordPress to feed the hungry spiders. Multisite, WP Super Cache, Polylang and WPML compatible.
4
+
5
+ [https://wordpress.org/plugins/xml-sitemap-feed/](https://wordpress.org/plugins/xml-sitemap-feed/)
6
+
{views → assets}/images/sitemapxml.gif RENAMED
File without changes
{views → assets}/styles/admin.css RENAMED
File without changes
assets/styles/sitemap-custom.xsl ADDED
@@ -0,0 +1,43 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet version="2.0"
3
+ xmlns:html="http://www.w3.org/TR/REC-html40"
4
+ xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
6
+ <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
7
+ <xsl:template match="/">
8
+ <html xmlns="http://www.w3.org/1999/xhtml">
9
+ <head>
10
+ <title>XML Sitemap Feed</title>
11
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
12
+ <style type="text/css">body{font-family:"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif;font-size:13px}#header,#footer{padding:2px;margin:10px;font-size:8pt;color:gray}a{color:black}td{font-size:11px}th{text-align:left;padding-right:30px;font-size:11px}tr.high{background-color:whitesmoke}#footer img{vertical-align:middle}</style>
13
+ </head>
14
+ <body>
15
+ <h1>XML Sitemap Feed</h1>
16
+ <div id="header">
17
+ <p>This is an XML Sitemap to aid search engines like <a href="https://www.google.com">Google</a>, <a href="https://www.bing.com/">Bing</a>, <a href="https://www.yahoo.com">Yahoo!</a> and <a href="https://www.ask.com">Ask</a> indexing your site better. Read more about XML sitemaps on <a href="https://www.sitemaps.org/">Sitemaps.org</a>.</p>
18
+ </div>
19
+ <div id="content">
20
+ <table cellpadding="5">
21
+ <tr class="high">
22
+ <th>#</th>
23
+ <th>URL</th>
24
+ <th>Priority</th>
25
+ </tr>
26
+ <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
27
+ <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
28
+ <xsl:for-each select="sitemap:urlset/sitemap:url">
29
+ <tr><xsl:if test="position() mod 2 != 1"><xsl:attribute name="class">high</xsl:attribute></xsl:if>
30
+ <td><xsl:value-of select="position()"/></td>
31
+ <td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable><a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a></td>
32
+ <td><xsl:value-of select="concat(sitemap:priority*100,'%')"/></td>
33
+ </tr>
34
+ </xsl:for-each>
35
+ </table>
36
+ </div>
37
+ <div id="footer">
38
+ <p><img src="data:image/gif;base64,R0lGODlhUAAPAJEAAGZmZv////9mAImOeSwAAAAAUAAPAAACoISPqcvtD0+YtNqLs968myCE4kiW5jkGw8q27gvDwYfWdq3G+i7T9w/M8Ya7GQAUoiSTEyYSKYA2nSKhdXUdCIlaXzRVDVdB0+dS2lJZ1bkt0Sgti6NysvM5jbq2ai2WywJHYrZUaEhIWJXm99foNiRI9XUoV4g4GJjJyEgBGAkEivIIyPUZeppCqorlheo6ulr00UFba3uLEaG7y9urUAAAOw%3D%3D" alt="XML Sitemap" title="XML Sitemap" /> generated by <a href="https://status301.net/wordpress-plugins/xml-sitemap-feed/">XML Sitemap &amp; Google News</a> for <a href="https://wordpress.org/">WordPress</a>.</p>
39
+ </div>
40
+ </body>
41
+ </html>
42
+ </xsl:template>
43
+ </xsl:stylesheet>
{views → assets}/styles/sitemap-index.xsl RENAMED
@@ -2,7 +2,6 @@
2
<xsl:stylesheet version="2.0"
3
xmlns:html="http://www.w3.org/TR/REC-html40"
4
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
- sitemap:news="http://www.google.com/schemas/sitemap-news/0.9"
6
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
8
<xsl:template match="/">
@@ -23,7 +22,7 @@
23
<tr class="high">
24
<th>#</th>
25
<th>XML Sitemap</th>
26
- <th>Last Changed</th>
27
</tr>
28
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
29
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
@@ -33,7 +32,7 @@
33
<td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable>
34
<a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a>
35
</td>
36
- <td><xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/></td>
37
</tr>
38
</xsl:for-each>
39
</table>
2
<xsl:stylesheet version="2.0"
3
xmlns:html="http://www.w3.org/TR/REC-html40"
4
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
6
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
7
<xsl:template match="/">
22
<tr class="high">
23
<th>#</th>
24
<th>XML Sitemap</th>
25
+ <th>Last Modified</th>
26
</tr>
27
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
28
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
32
<td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable>
33
<a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a>
34
</td>
35
+ <td><xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,8)))"/> (<xsl:value-of select="substring(sitemap:lastmod,20,6)"/>)</td>
36
</tr>
37
</xsl:for-each>
38
</table>
{views → assets}/styles/sitemap-news.xsl RENAMED
@@ -2,8 +2,7 @@
2
<xsl:stylesheet version="2.0"
3
xmlns:html="http://www.w3.org/TR/REC-html40"
4
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
- xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
6
- xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
7
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
8
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
9
<xsl:template match="/">
@@ -26,10 +25,9 @@
26
<th>#</th>
27
<th>Title</th>
28
<th>Language</th>
29
- <th>Image(s)</th>
30
<th>Keyword(s)</th>
31
<th>Stock(s)</th>
32
- <th>Publication Date (GMT)</th>
33
</tr>
34
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
35
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
@@ -40,10 +38,9 @@
40
<a href="{$itemURL}"><xsl:value-of select="news:news/news:title"/></a>
41
</td>
42
<td><xsl:value-of select="news:news/news:publication/news:language"/></td>
43
- <td><xsl:value-of select="count(image:image)"/></td>
44
<td><xsl:value-of select="news:news/news:keywords"/></td>
45
<td><xsl:value-of select="news:news/news:stock_tickers"/></td>
46
- <td><xsl:value-of select="concat(substring(news:news/news:publication_date,0,11),concat(' ', substring(news:news/news:publication_date,12,8)))"/></td>
47
</tr>
48
</xsl:for-each>
49
</table>
2
<xsl:stylesheet version="2.0"
3
xmlns:html="http://www.w3.org/TR/REC-html40"
4
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
+ xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
6
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
8
<xsl:template match="/">
25
<th>#</th>
26
<th>Title</th>
27
<th>Language</th>
28
<th>Keyword(s)</th>
29
<th>Stock(s)</th>
30
+ <th>Publication Date</th>
31
</tr>
32
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
33
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
38
<a href="{$itemURL}"><xsl:value-of select="news:news/news:title"/></a>
39
</td>
40
<td><xsl:value-of select="news:news/news:publication/news:language"/></td>
41
<td><xsl:value-of select="news:news/news:keywords"/></td>
42
<td><xsl:value-of select="news:news/news:stock_tickers"/></td>
43
+ <td><xsl:value-of select="concat(substring(news:news/news:publication_date,0,11),concat(' ', substring(news:news/news:publication_date,12,8)))"/> (<xsl:value-of select="substring(news:news/news:publication_date,20,6)"/>)</td>
44
</tr>
45
</xsl:for-each>
46
</table>
{views → assets}/styles/sitemap-taxonomy.xsl RENAMED
@@ -2,7 +2,6 @@
2
<xsl:stylesheet version="2.0"
3
xmlns:html="http://www.w3.org/TR/REC-html40"
4
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
- xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
6
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
8
<xsl:template match="/">
@@ -23,7 +22,7 @@
23
<th>#</th>
24
<th>URL</th>
25
<th>Priority</th>
26
- <th>Last Changed</th>
27
</tr>
28
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
29
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
@@ -32,7 +31,7 @@
32
<td><xsl:value-of select="position()"/></td>
33
<td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable><a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a></td>
34
<td><xsl:value-of select="concat(sitemap:priority*100,'%')"/></td>
35
- <td><xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/></td>
36
</tr>
37
</xsl:for-each>
38
</table>
2
<xsl:stylesheet version="2.0"
3
xmlns:html="http://www.w3.org/TR/REC-html40"
4
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
6
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
7
<xsl:template match="/">
22
<th>#</th>
23
<th>URL</th>
24
<th>Priority</th>
25
+ <th>Last Modified</th>
26
</tr>
27
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
28
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
31
<td><xsl:value-of select="position()"/></td>
32
<td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable><a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a></td>
33
<td><xsl:value-of select="concat(sitemap:priority*100,'%')"/></td>
34
+ <td><xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,8)))"/> (<xsl:value-of select="substring(sitemap:lastmod,20,6)"/>)</td>
35
</tr>
36
</xsl:for-each>
37
</table>
{views → assets}/styles/sitemap.xsl RENAMED
@@ -2,7 +2,7 @@
2
<xsl:stylesheet version="2.0"
3
xmlns:html="http://www.w3.org/TR/REC-html40"
4
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
- xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
6
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
8
<xsl:template match="/">
@@ -24,7 +24,7 @@
24
<th>URL</th>
25
<th># Images</th>
26
<th>Priority</th>
27
- <th>Last Changed</th>
28
</tr>
29
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
30
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
@@ -34,7 +34,7 @@
34
<td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable><a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a></td>
35
<td><xsl:value-of select="count(image:image)"/></td>
36
<td><xsl:value-of select="concat(sitemap:priority*100,'%')"/></td>
37
- <td><xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/></td>
38
</tr>
39
</xsl:for-each>
40
</table>
2
<xsl:stylesheet version="2.0"
3
xmlns:html="http://www.w3.org/TR/REC-html40"
4
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
5
+ xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
6
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
8
<xsl:template match="/">
24
<th>URL</th>
25
<th># Images</th>
26
<th>Priority</th>
27
+ <th>Last Modified</th>
28
</tr>
29
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
30
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
34
<td><xsl:variable name="itemURL"><xsl:value-of select="sitemap:loc"/></xsl:variable><a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a></td>
35
<td><xsl:value-of select="count(image:image)"/></td>
36
<td><xsl:value-of select="concat(sitemap:priority*100,'%')"/></td>
37
+ <td><xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,8)))"/> (<xsl:value-of select="substring(sitemap:lastmod,20,6)"/>)</td>
38
</tr>
39
</xsl:for-each>
40
</table>
controllers/{admin/notices.php → class.xmlsf-admin-notices.php} RENAMED
@@ -4,16 +4,14 @@
4
* Dismissable or interactive admin notices
5
*/
6
7
- class XMLSF_Admin_Notices extends XMLSF_Admin_Controller
8
{
9
function __construct() {}
10
11
public static function notice_static_files()
12
{
13
$number = count( parent::$static_files );
14
- if ( 0 == $number ) return;
15
-
16
- $static_files = parent::$static_files;
17
18
include XMLSF_DIR . '/views/admin/notice-static-files.php';
19
}
4
* Dismissable or interactive admin notices
5
*/
6
7
+ class XMLSF_Admin_Notices extends XMLSF_Admin
8
{
9
function __construct() {}
10
11
public static function notice_static_files()
12
{
13
$number = count( parent::$static_files );
14
+ if ( ! $number ) return;
15
16
include XMLSF_DIR . '/views/admin/notice-static-files.php';
17
}
controllers/{admin/sitemap-news.php → class.xmlsf-admin-sitemap-news.php} RENAMED
@@ -1,6 +1,6 @@
1
<?php
2
3
- class XMLSF_Admin_Sitemap_News extends XMLSF_Admin_Controller
4
{
5
/**
6
* Holds the values to be used in the fields callbacks
@@ -33,40 +33,35 @@ class XMLSF_Admin_Sitemap_News extends XMLSF_Admin_Controller
33
34
public function tools_actions()
35
{
36
- if ( ! isset( $_POST['xmlsf-ping-sitemap-news'] ) )
37
return;
38
39
- if ( isset( $_POST['_xmlsf_help_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_help_nonce'], XMLSF_BASENAME.'-help' ) ) {
40
41
- $sitemaps = get_option( 'xmlsf_sitemaps' );
42
- $result = xmlsf_ping( 'google', $sitemaps['sitemap-news'], 5 * MINUTE_IN_SECONDS );
43
44
- switch( $result ) {
45
- case 200:
46
- $msg = sprintf( /* Translators: Search engine / Service name */ __( 'Pinged %s with success.', 'xml-sitemap-feed' ), __( 'Google News', 'xml-sitemap-feed' ) );
47
- $type = 'updated';
48
- break;
49
50
- case 999:
51
- $msg = sprintf( /* Translators: Search engine / Service name, interval number */ __( 'Ping %s skipped: Sitemap already sent within the last %d minutes.', 'xml-sitemap-feed' ), __( 'Google News', 'xml-sitemap-feed' ), 5 );
52
- $type = 'notice-warning';
53
- break;
54
55
- case '':
56
- $msg = sprintf( translate('Oops: %s'), translate('Something went wrong.') );
57
- $type = 'error';
58
- break;
59
-
60
- default:
61
- $msg = sprintf( /* Translators: Search engine / Service name, response code number */ __( 'Ping %s failed with response code: %d', 'xml-sitemap-feed' ), __( 'Google News', 'xml-sitemap-feed' ), $result );
62
- $type = 'error';
63
- }
64
65
- add_settings_error( 'ping_sitemap', 'ping_sitemap', $msg, $type );
66
67
- } else {
68
- add_settings_error( 'ping_sitemap', 'ping_sitemap', translate('Security check failed.') );
69
- }
70
}
71
72
/**
@@ -107,17 +102,18 @@ class XMLSF_Admin_Sitemap_News extends XMLSF_Admin_Controller
107
/* When the post is saved, save our meta data */
108
public function save_metadata( $post_id )
109
{
110
- if ( !isset($post_id) )
111
- $post_id = (int)$_REQUEST['post_ID'];
112
-
113
- if ( !current_user_can( 'edit_post', $post_id ) || !isset($_POST['_xmlsf_news_nonce']) || !wp_verify_nonce($_POST['_xmlsf_news_nonce'], XMLSF_BASENAME) )
114
- return;
115
116
// _xmlsf_news_exclude
117
if ( empty($_POST['xmlsf_news_exclude']) )
118
- delete_post_meta($post_id, '_xmlsf_news_exclude');
119
else
120
- update_post_meta($post_id, '_xmlsf_news_exclude', $_POST['xmlsf_news_exclude']);
121
}
122
123
/**
@@ -195,9 +191,6 @@ class XMLSF_Admin_Sitemap_News extends XMLSF_Admin_Controller
195
}
196
}
197
198
- // Images
199
- add_settings_field( 'xmlsf_news_image', translate('Images'), array( $this,'image_field' ), 'xmlsf_news_general', 'news_sitemap_general_section' );
200
-
201
// Source labels - deprecated
202
add_settings_field( 'xmlsf_news_labels', __('Source labels', 'xml-sitemap-feed' ), array($this,'labels_field'), 'xmlsf_news_general', 'news_sitemap_general_section' );
203
}
@@ -251,17 +244,6 @@ class XMLSF_Admin_Sitemap_News extends XMLSF_Admin_Controller
251
'content' => $content
252
) );
253
254
- ob_start();
255
- include XMLSF_DIR . '/views/admin/help-tab-news-images.php';
256
- include XMLSF_DIR . '/views/admin/help-tab-support.php';
257
- $content = ob_get_clean();
258
-
259
- $screen->add_help_tab( array(
260
- 'id' => 'sitemap-news-images',
261
- 'title' => translate('Images'),
262
- 'content' => $content
263
- ) );
264
-
265
ob_start();
266
include XMLSF_DIR . '/views/admin/help-tab-news-keywords.php';
267
include XMLSF_DIR . '/views/admin/help-tab-support.php';
@@ -345,14 +327,6 @@ class XMLSF_Admin_Sitemap_News extends XMLSF_Admin_Controller
345
include XMLSF_DIR . '/views/admin/field-news-categories.php';
346
}
347
348
- public function image_field()
349
- {
350
- $image = !empty( $this->options['image'] ) ? $this->options['image'] : '';
351
-
352
- // The actual fields for data entry
353
- include XMLSF_DIR . '/views/admin/field-news-image.php';
354
- }
355
-
356
public function keywords_field()
357
{
358
// The actual fields for data entry
1
<?php
2
3
+ class XMLSF_Admin_Sitemap_News extends XMLSF_Admin
4
{
5
/**
6
* Holds the values to be used in the fields callbacks
33
34
public function tools_actions()
35
{
36
+ if ( ! isset( $_POST['xmlsf-ping-sitemap-news'] ) || ! xmlsf_verify_nonce('help') )
37
return;
38
39
+ $sitemaps = get_option( 'xmlsf_sitemaps' );
40
+ $result = xmlsf_ping( 'google', $sitemaps['sitemap-news'], 5 * MINUTE_IN_SECONDS );
41
42
+ switch( $result ) {
43
+ case 200:
44
+ $msg = sprintf( /* Translators: Search engine / Service name */ __( 'Pinged %s with success.', 'xml-sitemap-feed' ), __( 'Google News', 'xml-sitemap-feed' ) );
45
+ $type = 'updated';
46
+ break;
47
48
+ case 999:
49
+ $msg = sprintf( /* Translators: Search engine / Service name, interval number */ __( 'Ping %s skipped: Sitemap already sent within the last %d minutes.', 'xml-sitemap-feed' ), __( 'Google News', 'xml-sitemap-feed' ), 5 );
50
+ $type = 'notice-warning';
51
+ break;
52
53
+ case '':
54
+ $msg = sprintf( translate('Oops: %s'), translate('Something went wrong.') );
55
+ $type = 'error';
56
+ break;
57
58
+ default:
59
+ $msg = sprintf( /* Translators: Search engine / Service name, response code number */ __( 'Ping %s failed with response code: %d', 'xml-sitemap-feed' ), __( 'Google News', 'xml-sitemap-feed' ), $result );
60
+ $type = 'error';
61
+ }
62
63
+ add_settings_error( 'ping_sitemap', 'ping_sitemap', $msg, $type );
64
65
}
66
67
/**
102
/* When the post is saved, save our meta data */
103
public function save_metadata( $post_id )
104
{
105
+ if (
106
+ // verify nonce
107
+ ! isset($_POST['_xmlsf_news_nonce']) || ! wp_verify_nonce($_POST['_xmlsf_news_nonce'], XMLSF_BASENAME) ||
108
+ // user not allowed
109
+ ! current_user_can( 'edit_post', $post_id )
110
+ ) return;
111
112
// _xmlsf_news_exclude
113
if ( empty($_POST['xmlsf_news_exclude']) )
114
+ delete_post_meta( $post_id, '_xmlsf_news_exclude' );
115
else
116
+ update_post_meta( $post_id, '_xmlsf_news_exclude', '1' );
117
}
118
119
/**
191
}
192
}
193
194
// Source labels - deprecated
195
add_settings_field( 'xmlsf_news_labels', __('Source labels', 'xml-sitemap-feed' ), array($this,'labels_field'), 'xmlsf_news_general', 'news_sitemap_general_section' );
196
}
244
'content' => $content
245
) );
246
247
ob_start();
248
include XMLSF_DIR . '/views/admin/help-tab-news-keywords.php';
249
include XMLSF_DIR . '/views/admin/help-tab-support.php';
327
include XMLSF_DIR . '/views/admin/field-news-categories.php';
328
}
329
330
public function keywords_field()
331
{
332
// The actual fields for data entry
controllers/{admin/sitemap.php → class.xmlsf-admin-sitemap.php} RENAMED
@@ -1,22 +1,22 @@
1
<?php
2
3
- class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
4
{
5
- /**
6
- * Holds the values to be used in the fields callbacks
7
- */
8
- private $screen_id;
9
10
/**
11
- * Holds the public taxonomies array
12
- */
13
- private $public_taxonomies;
14
-
15
- /**
16
- * Start up
17
- */
18
- public function __construct()
19
- {
20
add_action( 'admin_menu', array( $this, 'add_settings_page' ) );
21
add_action( 'admin_init', array( $this, 'tools_actions' ) );
22
add_action( 'admin_init', array( $this, 'check_plugin_conflicts' ), 11 );
@@ -27,45 +27,40 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
27
28
public function tools_actions()
29
{
30
- if ( ! isset( $_POST['xmlsf-ping-sitemap'] ) )
31
return;
32
33
- if ( isset( $_POST['_xmlsf_help_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_help_nonce'], XMLSF_BASENAME.'-help' ) ) {
34
35
- $sitemaps = get_option( 'xmlsf_sitemaps' );
36
37
- foreach ( array('google','bing') as $se ) {
38
- $result = xmlsf_ping( $se, $sitemaps['sitemap'], HOUR_IN_SECONDS );
39
40
- $se_name = 'google' == $se ? __('Google','xml-sitemap-feed') : __('Bing & Yahoo','xml-sitemap-feed');
41
42
- switch( $result ) {
43
- case 200:
44
- $msg = sprintf( /* Translators: Search engine / Service name */ __( 'Pinged %s with success.', 'xml-sitemap-feed' ), $se_name );
45
- $type = 'updated';
46
- break;
47
48
- case 999:
49
- $msg = sprintf( /* Translators: Search engine / Service name, interval number */ __( 'Ping %s skipped: Sitemap already sent within the last %d minutes.', 'xml-sitemap-feed' ), $se_name, 60 );
50
- $type = 'notice-warning';
51
- break;
52
53
- case '':
54
- $msg = sprintf( translate('Oops: %s'), translate('Something went wrong.') );
55
- $type = 'error';
56
- break;
57
-
58
- default:
59
- $msg = sprintf( /* Translators: Search engine / Service name, response code number */ __( 'Ping %s failed with response code: %d', 'xml-sitemap-feed' ), $se_name, $result );
60
- $type = 'error';
61
- }
62
-
63
- add_settings_error( 'ping_sitemap', 'ping_sitemap', $msg, $type );
64
}
65
66
- } else {
67
- add_settings_error( 'ping_sitemap', 'ping_sitemap', translate('Security check failed.') );
68
}
69
}
70
71
/**
@@ -190,17 +185,18 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
190
/* When the post is saved, save our meta data */
191
public function save_metadata( $post_id )
192
{
193
- if ( !isset($post_id) )
194
- $post_id = (int)$_REQUEST['post_ID'];
195
-
196
- if ( !current_user_can( 'edit_post', $post_id ) || !isset($_POST['_xmlsf_nonce']) || !wp_verify_nonce($_POST['_xmlsf_nonce'], XMLSF_BASENAME) )
197
- return;
198
199
// _xmlsf_priority
200
if ( empty($_POST['xmlsf_priority']) )
201
delete_post_meta($post_id, '_xmlsf_priority');
202
else
203
- update_post_meta($post_id, '_xmlsf_priority', XMLSF_Admin_Sitemap_Sanitize::priority($_POST['xmlsf_priority']) );
204
205
// _xmlsf_exclude
206
if ( empty($_POST['xmlsf_exclude']) )
@@ -210,13 +206,11 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
210
}
211
212
/**
213
- * Gets public taxonomies
214
- */
215
- public function public_taxonomies()
216
{
217
if ( !isset( $this->public_taxonomies ) ) {
218
- require_once XMLSF_DIR . '/models/public/sitemap.php';
219
-
220
$this->public_taxonomies = xmlsf_public_taxonomies();
221
}
222
@@ -224,25 +218,25 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
224
}
225
226
/**
227
- * Add options page
228
- */
229
- public function add_settings_page()
230
{
231
- // This page will be under "Settings"
232
- $this->screen_id = add_options_page(
233
- __('XML Sitemap','xml-sitemap-feed'),
234
- __('XML Sitemap','xml-sitemap-feed'),
235
- 'manage_options',
236
- 'xmlsf',
237
- array( $this, 'settings_page' )
238
- );
239
- }
240
-
241
- /**
242
- * Options page callback
243
- */
244
- public function settings_page()
245
- {
246
// SECTIONS & SETTINGS
247
// post_types
248
add_settings_section( 'xml_sitemap_post_types_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_post_types' );
@@ -261,9 +255,9 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
261
// taxonomies
262
add_settings_section( 'xml_sitemap_taxonomies_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_taxonomies' );
263
add_settings_field( 'xmlsf_taxonomy_settings', translate('General'), array($this,'taxonomy_settings_field'), 'xmlsf_taxonomies', 'xml_sitemap_taxonomies_section' );
264
- $taxonomy_settings = get_option( 'xmlsf_taxonomy_settings' );
265
- if ( !empty( $taxonomy_settings['active'] ) && get_option( 'xmlsf_taxonomies' ) )
266
- add_settings_field( 'xmlsf_taxonomies', __('Include taxonomies','xml-sitemap-feed'), array($this,'taxonomies_field'), 'xmlsf_taxonomies', 'xml_sitemap_taxonomies_section' );
267
268
add_settings_section( 'xml_sitemap_advanced_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_advanced' );
269
// custom urls
@@ -277,13 +271,13 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
277
$url = trailingslashit(get_bloginfo('url')) . ( xmlsf()->plain_permalinks() || empty($sitemaps['sitemap']) ? '?feed=sitemap' : $sitemaps['sitemap'] );
278
279
include XMLSF_DIR . '/views/admin/page-sitemap.php';
280
- }
281
282
- /**
283
- * Register and add settings
284
- */
285
- public function register_settings()
286
- {
287
// Help tab
288
add_action( 'load-'.$this->screen_id, array($this,'help_tab') );
289
@@ -296,7 +290,7 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
296
register_setting( 'xmlsf_advanced', 'xmlsf_urls', array('XMLSF_Admin_Sitemap_Sanitize','custom_urls_settings') );
297
// custom sitemaps
298
register_setting( 'xmlsf_advanced', 'xmlsf_custom_sitemaps', array('XMLSF_Admin_Sitemap_Sanitize','custom_sitemaps_settings') );
299
- }
300
301
/**
302
* XML SITEMAP SECTION
@@ -369,7 +363,6 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
369
370
public function taxonomy_settings_field()
371
{
372
- $taxonomies = get_option( 'xmlsf_taxonomies' );
373
$taxonomy_settings = get_option( 'xmlsf_taxonomy_settings' );
374
375
// The actual fields for data entry
@@ -393,7 +386,8 @@ class XMLSF_Admin_Sitemap extends XMLSF_Admin_Controller
393
include XMLSF_DIR . '/views/admin/field-sitemap-custom.php';
394
}
395
396
- public function urls_settings_field() {
397
$urls = get_option( 'xmlsf_urls' );
398
$lines = array();
399
1
<?php
2
3
+ class XMLSF_Admin_Sitemap extends XMLSF_Admin
4
{
5
+ /**
6
+ * Holds the values to be used in the fields callbacks
7
+ */
8
+ private $screen_id;
9
10
/**
11
+ * Holds the public taxonomies array
12
+ */
13
+ private $public_taxonomies;
14
+
15
+ /**
16
+ * Start up
17
+ */
18
+ public function __construct()
19
+ {
20
add_action( 'admin_menu', array( $this, 'add_settings_page' ) );
21
add_action( 'admin_init', array( $this, 'tools_actions' ) );
22
add_action( 'admin_init', array( $this, 'check_plugin_conflicts' ), 11 );
27
28
public function tools_actions()
29
{
30
+ if ( ! isset( $_POST['xmlsf-ping-sitemap'] ) || ! xmlsf_verify_nonce('help') )
31
return;
32
33
+ $sitemaps = get_option( 'xmlsf_sitemaps' );
34
35
+ foreach ( array('google','bing') as $se ) {
36
+ $result = xmlsf_ping( $se, $sitemaps['sitemap'], HOUR_IN_SECONDS );
37
38
+ $se_name = 'google' == $se ? __('Google','xml-sitemap-feed') : __('Bing & Yahoo','xml-sitemap-feed');
39
40
+ switch( $result ) {
41
+ case 200:
42
+ $msg = sprintf( /* Translators: Search engine / Service name */ __( 'Pinged %s with success.', 'xml-sitemap-feed' ), $se_name );
43
+ $type = 'updated';
44
+ break;
45
46
+ case 999:
47
+ $msg = sprintf( /* Translators: Search engine / Service name, interval number */ __( 'Ping %s skipped: Sitemap already sent within the last %d minutes.', 'xml-sitemap-feed' ), $se_name, 60 );
48
+ $type = 'notice-warning';
49
+ break;
50
51
+ case '':
52
+ $msg = sprintf( translate('Oops: %s'), translate('Something went wrong.') );
53
+ $type = 'error';
54
+ break;
55
56
+ default:
57
+ $msg = sprintf( /* Translators: Search engine / Service name, response code number */ __( 'Ping %s failed with response code: %d', 'xml-sitemap-feed' ), $se_name, $result );
58
+ $type = 'error';
59
}
60
61
+ add_settings_error( 'ping_sitemap', 'ping_sitemap', $msg, $type );
62
}
63
+
64
}
65
66
/**
185
/* When the post is saved, save our meta data */
186
public function save_metadata( $post_id )
187
{
188
+ if (
189
+ // verify nonce
190
+ ! isset($_POST['_xmlsf_nonce']) || ! wp_verify_nonce($_POST['_xmlsf_nonce'], XMLSF_BASENAME) ||
191
+ // user not allowed
192
+ ! current_user_can( 'edit_post', $post_id )
193
+ ) return;
194
195
// _xmlsf_priority
196
if ( empty($_POST['xmlsf_priority']) )
197
delete_post_meta($post_id, '_xmlsf_priority');
198
else
199
+ update_post_meta($post_id, '_xmlsf_priority', xmlsf_sanitize_priority( $_POST['xmlsf_priority'] ) );
200
201
// _xmlsf_exclude
202
if ( empty($_POST['xmlsf_exclude']) )
206
}
207
208
/**
209
+ * Gets public taxonomies
210
+ */
211
+ public function public_taxonomies()
212
{
213
if ( !isset( $this->public_taxonomies ) ) {
214
$this->public_taxonomies = xmlsf_public_taxonomies();
215
}
216
218
}
219
220
/**
221
+ * Add options page
222
+ */
223
+ public function add_settings_page()
224
{
225
+ // This page will be under "Settings"
226
+ $this->screen_id = add_options_page(
227
+ __('XML Sitemap','xml-sitemap-feed'),
228
+ __('XML Sitemap','xml-sitemap-feed'),
229
+ 'manage_options',
230
+ 'xmlsf',
231
+ array( $this, 'settings_page' )
232
+ );
233
+ }
234
+
235
+ /**
236
+ * Options page callback
237
+ */
238
+ public function settings_page()
239
+ {
240
// SECTIONS & SETTINGS
241
// post_types
242
add_settings_section( 'xml_sitemap_post_types_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_post_types' );
255
// taxonomies
256
add_settings_section( 'xml_sitemap_taxonomies_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_taxonomies' );
257
add_settings_field( 'xmlsf_taxonomy_settings', translate('General'), array($this,'taxonomy_settings_field'), 'xmlsf_taxonomies', 'xml_sitemap_taxonomies_section' );
258
+ //$taxonomy_settings = get_option( 'xmlsf_taxonomy_settings' );
259
+ if ( apply_filters( 'xmlsf_taxonomies', ! empty( get_option( 'xmlsf_taxonomies' ) ) ) )
260
+ add_settings_field( 'xmlsf_taxonomies', __('Taxonomies','xml-sitemap-feed'), array($this,'taxonomies_field'), 'xmlsf_taxonomies', 'xml_sitemap_taxonomies_section' );
261
262
add_settings_section( 'xml_sitemap_advanced_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_advanced' );
263
// custom urls
271
$url = trailingslashit(get_bloginfo('url')) . ( xmlsf()->plain_permalinks() || empty($sitemaps['sitemap']) ? '?feed=sitemap' : $sitemaps['sitemap'] );
272
273
include XMLSF_DIR . '/views/admin/page-sitemap.php';
274
+ }
275
276
+ /**
277
+ * Register and add settings
278
+ */
279
+ public function register_settings()
280
+ {
281
// Help tab
282
add_action( 'load-'.$this->screen_id, array($this,'help_tab') );
283
290
register_setting( 'xmlsf_advanced', 'xmlsf_urls', array('XMLSF_Admin_Sitemap_Sanitize','custom_urls_settings') );
291
// custom sitemaps
292
register_setting( 'xmlsf_advanced', 'xmlsf_custom_sitemaps', array('XMLSF_Admin_Sitemap_Sanitize','custom_sitemaps_settings') );
293
+ }
294
295
/**
296
* XML SITEMAP SECTION
363
364
public function taxonomy_settings_field()
365
{
366
$taxonomy_settings = get_option( 'xmlsf_taxonomy_settings' );
367
368
// The actual fields for data entry
386
include XMLSF_DIR . '/views/admin/field-sitemap-custom.php';
387
}
388
389
+ public function urls_settings_field()
390
+ {
391
$urls = get_option( 'xmlsf_urls' );
392
$lines = array();
393
controllers/{admin/main.php → class.xmlsf-admin.php} RENAMED
@@ -3,8 +3,14 @@
3
* XMLSF Admin CLASS
4
* ------------------------------ */
5
6
- class XMLSF_Admin_Controller
7
{
8
/**
9
* Static files conflicting with this plugin
10
* @var array
@@ -19,24 +25,23 @@ class XMLSF_Admin_Controller
19
20
/**
21
* CONSTRUCTOR
22
- * Runs on init
23
*/
24
25
function __construct()
26
{
27
- require XMLSF_DIR . '/models/admin/main.php';
28
- require XMLSF_DIR . '/controllers/admin/notices.php';
29
30
$this->sitemaps = (array) get_option( 'xmlsf_sitemaps', array() );
31
32
if ( isset($this->sitemaps['sitemap']) ) {
33
- require XMLSF_DIR . '/models/admin/sitemap.php';
34
- require XMLSF_DIR . '/controllers/admin/sitemap.php';
35
}
36
37
if ( isset($this->sitemaps['sitemap-news']) ) {
38
- require XMLSF_DIR . '/models/admin/sitemap-news.php';
39
- require XMLSF_DIR . '/controllers/admin/sitemap-news.php';
40
}
41
42
// ACTION LINK
@@ -49,8 +54,7 @@ class XMLSF_Admin_Controller
49
50
// ACTIONS & CHECKS
51
add_action( 'admin_init', array( $this, 'tools_actions' ) );
52
- if ( ( !is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() )
53
- add_action( 'admin_init', array( $this, 'static_files' ) );
54
add_action( 'admin_init', array( $this, 'check_theme_conflicts' ) );
55
}
56
@@ -260,6 +264,8 @@ class XMLSF_Admin_Controller
260
*/
261
public function static_files()
262
{
263
if ( null === self::$static_files )
264
self::$static_files = get_transient( 'xmlsf_static_files' );
265
@@ -281,7 +287,7 @@ class XMLSF_Admin_Controller
281
}
282
283
foreach ( $check_for as $name => $pretty ) {
284
- if ( file_exists( $home_path . $pretty ) ) {
285
self::$static_files[$pretty] = $home_path . $pretty;
286
}
287
}
@@ -308,23 +314,19 @@ class XMLSF_Admin_Controller
308
public function tools_actions()
309
{
310
if ( isset( $_POST['xmlsf-clear-settings-submit'] ) && isset( $_POST['xmlsf-clear-settings'] ) ) {
311
- if ( isset( $_POST['_xmlsf_help_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_help_nonce'], XMLSF_BASENAME.'-help' ) ) {
312
$this->clear_settings( $_POST['xmlsf-clear-settings'] );
313
- } else {
314
- add_settings_error( 'clear_settings', 'clear_settings_failed', translate('Security check failed.') );
315
}
316
}
317
318
if ( isset( $_POST['xmlsf-delete-submit'] ) ) {
319
- if ( isset( $_POST['_xmlsf_notice_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_notice_nonce'], XMLSF_BASENAME.'-notice' ) ) {
320
$this->delete_static_files();
321
- } else {
322
- add_settings_error( 'delete_files', 'delete_files_failed', translate('Security check failed.') );
323
}
324
}
325
326
if ( isset( $_POST['xmlsf-check-conflicts'] ) ) {
327
- if ( isset( $_POST['_xmlsf_help_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_help_nonce'], XMLSF_BASENAME.'-help' ) ) {
328
// reset ignored warnings
329
delete_user_meta( get_current_user_id(), 'xmlsf_dismissed' );
330
self::$dismissed = array();
@@ -332,20 +334,43 @@ class XMLSF_Admin_Controller
332
$this->check_static_files();
333
if ( empty( self::$static_files ) )
334
add_settings_error( 'static_files_notice', 'static_files', __('No conflicting static files found.','xml-sitemap-feed'), 'notice-info');
335
- } else {
336
- add_settings_error( 'check_conflicts', 'check_conflicts_failed', translate('Security check failed.') );
337
}
338
}
339
340
if ( isset( $_POST['xmlsf-flush-rewrite-rules'] ) ) {
341
- if ( isset( $_POST['_xmlsf_help_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_help_nonce'], XMLSF_BASENAME.'-help' ) ) {
342
// flush rewrite rules
343
flush_rewrite_rules();
344
add_settings_error( 'flush_admin_notice', 'flush_admin_notice', __('WordPress rewrite rules have been flushed.','xml-sitemap-feed'), 'updated' );
345
- } else {
346
- add_settings_error( 'flush_rewrite_rules', 'flush_rewrite_rules_failed', translate('Security check failed.') );
347
}
348
}
349
}
350
351
public function notices_actions()
@@ -353,11 +378,9 @@ class XMLSF_Admin_Controller
353
self::$dismissed = (array) get_user_meta( get_current_user_id(), 'xmlsf_dismissed' );
354
355
if ( isset( $_POST['xmlsf-dismiss-submit'] ) && isset( $_POST['xmlsf-dismiss'] ) ) {
356
- if ( isset( $_POST['_xmlsf_notice_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_notice_nonce'], XMLSF_BASENAME.'-notice' ) ) {
357
add_user_meta( get_current_user_id(), 'xmlsf_dismissed', $_POST['xmlsf-dismiss'], false );
358
self::$dismissed[] = $_POST['xmlsf-dismiss'];
359
- } else {
360
- add_settings_error( 'dismiss_notice', 'dismiss_notice_failed', translate('Security check failed.') );
361
}
362
}
363
}
@@ -365,18 +388,12 @@ class XMLSF_Admin_Controller
365
public function transients_actions()
366
{
367
// CATCH TRANSIENT for flushing rewrite rules after the sitemaps setting has changed
368
- if ( delete_transient('xmlsf_flush_rewrite_rules') ) {
369
- flush_rewrite_rules();
370
- if ( defined('WP_DEBUG') && WP_DEBUG == true ) {
371
- error_log('Rewrite rules flushed by XML Sitemap Feeds.');
372
- }
373
- }
374
375
// CATCH TRANSIENT for static file check
376
- if ( delete_transient('xmlsf_check_static_files') ) {
377
- $this->check_static_files();
378
- }
379
}
380
}
381
382
- new XMLSF_Admin_Controller();
3
* XMLSF Admin CLASS
4
* ------------------------------ */
5
6
+ class XMLSF_Admin
7
{
8
+ /**
9
+ * Sitemaps settings
10
+ * @var array
11
+ */
12
+ private $sitemaps = array();
13
+
14
/**
15
* Static files conflicting with this plugin
16
* @var array
25
26
/**
27
* CONSTRUCTOR
28
*/
29
30
function __construct()
31
{
32
+ require XMLSF_DIR . '/models/functions.admin.php';
33
+ require XMLSF_DIR . '/controllers/class.xmlsf-admin-notices.php';
34
35
$this->sitemaps = (array) get_option( 'xmlsf_sitemaps', array() );
36
37
if ( isset($this->sitemaps['sitemap']) ) {
38
+ require XMLSF_DIR . '/models/class.xmlsf-admin-sitemap-sanitize.php';
39
+ require XMLSF_DIR . '/controllers/class.xmlsf-admin-sitemap.php';
40
}
41
42
if ( isset($this->sitemaps['sitemap-news']) ) {
43
+ require XMLSF_DIR . '/models/class.xmlsf-admin-sitemap-news-sanitize.php';
44
+ require XMLSF_DIR . '/controllers/class.xmlsf-admin-sitemap-news.php';
45
}
46
47
// ACTION LINK
54
55
// ACTIONS & CHECKS
56
add_action( 'admin_init', array( $this, 'tools_actions' ) );
57
+ add_action( 'admin_init', array( $this, 'static_files' ) );
58
add_action( 'admin_init', array( $this, 'check_theme_conflicts' ) );
59
}
60
264
*/
265
public function static_files()
266
{
267
+ if ( ( is_multisite() && ! is_super_admin() ) || ! current_user_can( 'manage_options' ) ) return;
268
+
269
if ( null === self::$static_files )
270
self::$static_files = get_transient( 'xmlsf_static_files' );
271
287
}
288
289
foreach ( $check_for as $name => $pretty ) {
290
+ if ( ! empty( $pretty ) && file_exists( $home_path . $pretty ) ) {
291
self::$static_files[$pretty] = $home_path . $pretty;
292
}
293
}
314
public function tools_actions()
315
{
316
if ( isset( $_POST['xmlsf-clear-settings-submit'] ) && isset( $_POST['xmlsf-clear-settings'] ) ) {
317
+ if ( xmlsf_verify_nonce('help') ) {
318
$this->clear_settings( $_POST['xmlsf-clear-settings'] );
319
}
320
}
321
322
if ( isset( $_POST['xmlsf-delete-submit'] ) ) {
323
+ if ( xmlsf_verify_nonce('help') ) {
324
$this->delete_static_files();
325
}
326
}
327
328
if ( isset( $_POST['xmlsf-check-conflicts'] ) ) {
329
+ if ( xmlsf_verify_nonce('help') ) {
330
// reset ignored warnings
331
delete_user_meta( get_current_user_id(), 'xmlsf_dismissed' );
332
self::$dismissed = array();
334
$this->check_static_files();
335
if ( empty( self::$static_files ) )
336
add_settings_error( 'static_files_notice', 'static_files', __('No conflicting static files found.','xml-sitemap-feed'), 'notice-info');
337
}
338
}
339
340
if ( isset( $_POST['xmlsf-flush-rewrite-rules'] ) ) {
341
+ if ( xmlsf_verify_nonce('help') ) {
342
// flush rewrite rules
343
flush_rewrite_rules();
344
add_settings_error( 'flush_admin_notice', 'flush_admin_notice', __('WordPress rewrite rules have been flushed.','xml-sitemap-feed'), 'updated' );
345
}
346
}
347
+
348
+ if ( isset( $_POST['xmlsf-clear-term-meta'] ) ) {
349
+ if ( xmlsf_verify_nonce('help') ) {
350
+ // remove metadata
351
+ global $wpdb;
352
+ // terms meta
353
+ $wpdb->delete( $wpdb->prefix.'termmeta', array( 'meta_key' => 'term_modified' ) );
354
+ add_settings_error( 'clear_meta_notice', 'clear_meta_notice', __('Sitemap term meta cache has been cleared.','xml-sitemap-feed'), 'updated' );
355
+ }
356
+ }
357
+
358
+ if ( isset( $_POST['xmlsf-clear-post-meta'] ) ) {
359
+ if ( xmlsf_verify_nonce('help') ) {
360
+ // remove metadata
361
+ global $wpdb;
362
+ // images meta
363
+ $wpdb->delete( $wpdb->prefix.'postmeta', array( 'meta_key' => '_xmlsf_image_attached' ) );
364
+ $wpdb->delete( $wpdb->prefix.'postmeta', array( 'meta_key' => '_xmlsf_image_featured' ) );
365
+ update_option( 'xmlsf_images_meta_primed', array() );
366
+ // comments meta
367
+ $wpdb->delete( $wpdb->prefix.'postmeta', array( 'meta_key' => '_xmlsf_comment_date' ) );
368
+ update_option( 'xmlsf_comments_meta_primed', array() );
369
+
370
+ add_settings_error( 'clear_meta_notice', 'clear_meta_notice', __('Sitemap post meta caches have been cleared.','xml-sitemap-feed'), 'updated' );
371
+ }
372
+ }
373
+
374
}
375
376
public function notices_actions()
378
self::$dismissed = (array) get_user_meta( get_current_user_id(), 'xmlsf_dismissed' );
379
380
if ( isset( $_POST['xmlsf-dismiss-submit'] ) && isset( $_POST['xmlsf-dismiss'] ) ) {
381
+ if ( xmlsf_verify_nonce('notice') ) {
382
add_user_meta( get_current_user_id(), 'xmlsf_dismissed', $_POST['xmlsf-dismiss'], false );
383
self::$dismissed[] = $_POST['xmlsf-dismiss'];
384
}
385
}
386
}
388
public function transients_actions()
389
{
390
// CATCH TRANSIENT for flushing rewrite rules after the sitemaps setting has changed
391
+ delete_transient('xmlsf_flush_rewrite_rules') && flush_rewrite_rules();
392
393
// CATCH TRANSIENT for static file check
394
+ delete_transient('xmlsf_check_static_files') && $this->check_static_files();
395
}
396
+
397
}
398
399
+ new XMLSF_Admin();
controllers/class.xmlsf-sitemap-news.php ADDED
@@ -0,0 +1,89 @@
1
+ <?php
2
+ /* ------------------------------
3
+ * XMLSF Controller CLASS
4
+ * ------------------------------ */
5
+
6
+ class XMLSF_Sitemap_News
7
+ {
8
+ /**
9
+ * Sitemap index name
10
+ * @var string
11
+ */
12
+ private $sitemap = 'sitemap-news.xml';
13
+
14
+ /**
15
+ * Post types included in sitemap index
16
+ * @var array
17
+ */
18
+ private $post_types;
19
+
20
+ /**
21
+ * CONSTRUCTOR
22
+ * Runs on init
23
+ */
24
+
25
+ function __construct( $sitemap )
26
+ {
27
+ $this->sitemap = $sitemap;
28
+
29
+ // PINGING
30
+ add_action( 'transition_post_status', array( $this, 'do_ping' ), 10, 3 );
31
+
32
+ // FEED TEMPLATES
33
+ add_action( 'do_feed_sitemap-news', 'xmlsf_news_load_template', 10, 1 );
34
+ }
35
+
36
+ /**
37
+ * Do pings, hooked to transition post status
38
+ *
39
+ * @param $new_status
40
+ * @param $old_status
41
+ * @param $post
42
+ */
43
+ public function do_ping( $new_status, $old_status, $post )
44
+ {
45
+ // bail out when already published or not publishing
46
+ if ( $old_status == 'publish' || $new_status != 'publish' ) return;
47
+
48
+ // bail out when REST API call without new post data, see Gutenberg issue https://github.com/WordPress/gutenberg/issues/15094
49
+ // NO ! Don't bail out now because there will be no other chance as long as bug is not fixed...
50
+ // ... we'll have to make do without $_POST data so potentially incorrect get_post_meta() information.
51
+ //if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) return;
52
+
53
+ // bail out when Google ping not checked
54
+ if ( ! in_array( 'google', (array) get_option( 'xmlsf_ping' ) ) ) return;
55
+
56
+ // we're saving from post edit screen
57
+ if ( ! empty( $_POST ) && 'editpost' == $_POST['action'] ) {
58
+ // bail out when exclude field is checked
59
+ if ( ! empty( $_POST['_xmlsf_news_exclude'] ) ) return;
60
+ } else {
61
+ // fall back on exclude meta data from DB whic may be outdated (see bug)
62
+ if ( ! empty( get_post_meta( $post->ID, '_xmlsf_news_exclude' ) ) ) return;
63
+ }
64
+
65
+ $news_tags = (array) get_option('xmlsf_news_tags');
66
+
67
+ error_log('6');
68
+ // is this an active post type?
69
+ if ( empty( $news_tags['post_type'] ) || ! in_array( $post->post_type, (array) $news_tags['post_type'] ) ) return;
70
+
71
+ error_log('7');
72
+ // are categories limited and is not in correct category?
73
+ if ( ! empty( $news_tags['categories'] ) ) {
74
+ $cats = wp_get_post_categories( $post->ID, array( 'fields' => 'ids' ) );
75
+ if ( empty( array_intersect( (array) $cats, (array) $news_tags['categories'] ) ) ) return;
76
+ }
77
+
78
+ // PING
79
+ xmlsf_ping( 'google', $this->sitemap, 5 * MINUTE_IN_SECONDS );
80
+ }
81
+
82
+ }
83
+
84
+ /**
85
+ * set up the news sitemap template
86
+ */
87
+ function xmlsf_news_load_template() {
88
+ load_template( XMLSF_DIR . '/views/feed-sitemap-news.php' );
89
+ }
controllers/class.xmlsf-sitemap.php ADDED
@@ -0,0 +1,414 @@
1
+ <?php
2
+
3
+ /* ------------------------------
4
+ * XMLSF Controller CLASS
5
+ * ------------------------------ */
6
+
7
+ class XMLSF_Sitemap
8
+ {
9
+ /**
10
+ * Sitemap index name
11
+ * @var string
12
+ */
13
+ private $sitemap = 'sitemap.xml';
14
+
15
+ /**
16
+ * Post types included in sitemap index
17
+ * @var array
18
+ */
19
+ private $post_types = array();
20
+
21
+ /**
22
+ * CONSTRUCTOR
23
+ * Runs on init
24
+ */
25
+
26
+ function __construct( $sitemap )
27
+ {
28
+ $this->sitemap = $sitemap;
29
+
30
+ // Cache clearance
31
+ add_action( 'clean_post_cache', array($this,'clean_post_cache'), 99, 2 );
32
+
33
+ // Update term meta lastmod date
34
+ add_action( 'transition_post_status', array($this,'update_term_modified_meta'), 10, 3 );
35
+
36
+ // Update images post meta
37
+ add_action( 'transition_post_status', array($this,'update_post_images_meta'), 10, 3 );
38
+
39
+ // Update last comment date post meta
40
+ add_action( 'transition_comment_status', array($this,'update_post_comment_meta'), 10, 3 );
41
+ add_action( 'comment_post', array($this,'update_post_comment_meta_cp'), 10, 3 ); // when comment is not held for moderation
42
+
43
+ // PINGING
44
+ add_action( 'transition_post_status', array($this,'do_pings'), 10, 3 );
45
+
46
+ // FEED TEMPLATES
47
+ add_action( 'do_feed_sitemap', 'xmlsf_load_template_index', 10, 1 );
48
+ add_action( 'do_feed_sitemap_index', 'xmlsf_load_template_index', 10, 1 );
49
+ add_action( 'do_feed_sitemap-home', 'xmlsf_load_template_home', 10, 1 );
50
+ add_action( 'do_feed_sitemap-custom', 'xmlsf_load_template_custom', 10, 1 );
51
+
52
+ $this->post_types = (array) get_option( 'xmlsf_post_types', array() );
53
+
54
+ if ( is_array($this->post_types) ) {
55
+ foreach ( $this->post_types as $post_type => $settings ) {
56
+ if ( !empty($settings['active']) )
57
+ // FEED TEMPLATES
58
+ add_action( 'do_feed_sitemap-posttype-'.$post_type, 'xmlsf_load_template', 10, 1 );
59
+ }
60
+ }
61
+
62
+ foreach ( xmlsf_get_taxonomies() as $name ) {
63
+ add_action( 'do_feed_sitemap-taxonomy-'.$name, 'xmlsf_load_template_taxonomy', 10, 1 );
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Do pings, hooked to transition post status
69
+ *
70
+ * @param $new_status
71
+ * @param $old_status
72
+ * @param $post
73
+ */
74
+ public function do_pings( $new_status, $old_status, $post )
75
+ {
76
+ // bail out when already published or not publishing
77
+ if ( $old_status == 'publish' || $new_status != 'publish' ) return;
78
+
79
+ // bail out when REST API call without new post data, see Gutenberg issue https://github.com/WordPress/gutenberg/issues/15094
80
+ // NO ! Don't bail out now because there will be no other chance as long as bug is not fixed...
81
+ // ... we'll have to make do without $_POST data so potentially incorrect get_post_meta() information.
82
+ //if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) return;
83
+
84
+ // bail out when inactive post type
85
+ if ( ! array_key_exists( $post->post_type, (array) $this->post_types ) ) return;
86
+
87
+ // we're saving from post edit screen (f.e. 'inline-save' would be from quick edit)
88
+ if ( ! empty( $_POST ) && 'editpost' == $_POST['action'] ) {
89
+ // bail out when exclude field is checked
90
+ if ( ! empty( $_POST['_xmlsf_exclude'] ) ) return;
91
+ } else {
92
+ // fall back on exclude meta data from DB whic may be outdated (see bug)
93
+ if ( ! empty( get_post_meta( $post->ID, '_xmlsf_exclude' ) ) ) return;
94
+ }
95
+
96
+ $ping = (array) get_option( 'xmlsf_ping', array() );
97
+ // PING !
98
+ foreach ( $ping as $se ) {
99
+ xmlsf_ping( $se, $this->sitemap, HOUR_IN_SECONDS );
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Cache delete on clean_post_cache
105
+ *
106
+ * @param $post_ID
107
+ * @param $post
108
+ */
109
+ public function clean_post_cache( $post_ID, $post )
110
+ {
111
+ // are we moving the post in or out of published status?
112
+ wp_cache_delete( 'xmlsf_get_archives', 'general' );
113
+
114
+ // TODO get year / month here to delete specific keys too !!!!
115
+ $m = mysql2date( 'Ym', $post->post_date, false );
116
+ $y = substr( $m, 0, 4 );
117
+
118
+ // clear possible last post modified cache keys
119
+ wp_cache_delete( 'lastpostmodified:gmt', 'timeinfo' ); // should be handled by WP core?
120
+ wp_cache_delete( 'lastpostmodified'.$y.':gmt', 'timeinfo' );
121
+ wp_cache_delete( 'lastpostmodified'.$m.':gmt', 'timeinfo' );
122
+ wp_cache_delete( 'lastpostmodified'.$y.':gmt:'.$post->post_type, 'timeinfo' );
123
+ wp_cache_delete( 'lastpostmodified'.$m.':gmt:'.$post->post_type, 'timeinfo' );
124
+
125
+ // clear possible last post date cache keys
126
+ wp_cache_delete( 'lastpostdate:gmt', 'timeinfo' );
127
+ wp_cache_delete( 'lastpostdate:gmt:'.$post->post_type, 'timeinfo' );
128
+
129
+ // clear possible fist post date cache keys
130
+ wp_cache_delete( 'firstpostdate:gmt', 'timeinfo' );
131
+ wp_cache_delete( 'firstpostdate:gmt:'.$post->post_type, 'timeinfo' );
132
+ }
133
+
134
+ /**
135
+ * Update term modified meta, hooked to transition post status
136
+ *
137
+ * @param $new_status
138
+ * @param $old_status
139
+ * @param $post
140
+ */
141
+ public function update_term_modified_meta( $new_status, $old_status, $post )
142
+ {
143
+ // bail when...
144
+ if (
145
+ // no status transition or not moving in or out of 'publish' status
146
+ $old_status == $new_status || ( 'publish' != $new_status && 'publish' != $old_status ) ||
147
+ // inactive post type
148
+ ! array_key_exists($post->post_type, $this->post_types) || empty( $this->post_types[$post->post_type]['active'] )
149
+ ) return;
150
+
151
+ $taxonomy_settings = get_option( 'xmlsf_taxonomy_settings' );
152
+
153
+ // bail if no taxonomies activated
154
+ if ( ! is_array($taxonomy_settings) || empty( $taxonomy_settings['active'] ) )
155
+ return;
156
+
157
+ $taxonomies = get_option( 'xmlsf_taxonomies' );
158
+ if ( empty( $taxonomies ) )
159
+ $taxonomies = xmlsf_public_taxonomies();
160
+
161
+ $term_ids = array();
162
+ foreach ( (array) $taxonomies as $slug => $name ) {
163
+ $terms = wp_get_post_terms( $post->ID, $slug, array( 'fields' => 'ids' ));
164
+ if ( !is_wp_error($terms) ) {
165
+ $term_ids = array_merge( $term_ids, $terms );
166
+ }
167
+ }
168
+
169
+ $time = date('Y-m-d H:i:s');
170
+
171
+ foreach( $term_ids as $id ) {
172
+ update_term_meta( $id, 'term_modified', $time );
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Update post images meta, hooked to transition post status
178
+ *
179
+ * @since 5.2
180
+ *
181
+ * @param $new_status
182
+ * @param $old_status
183
+ * @param $post
184
+ */
185
+ public function update_post_images_meta( $new_status, $old_status, $post )
186
+ {
187
+ // bail when...
188
+ if (
189
+ // not publishing or updating
190
+ $new_status != 'publish' ||
191
+ // inactive post type
192
+ ! array_key_exists($post->post_type, $this->post_types) || empty( $this->post_types[$post->post_type]['active'] ) ||
193
+ // no image tags active
194
+ empty( $this->post_types[$post->post_type]['tags']['image'] )
195
+ ) return;
196
+
197
+ $which = $this->post_types[$post->post_type]['tags']['image'];
198
+
199
+ // delete old image meta data
200
+ delete_post_meta( $post->ID, '_xmlsf_image_'.$which );
201
+
202
+ $this->_add_images_meta( $post, $which );
203
+
204
+ }
205
+
206
+ /**
207
+ * Update post comment meta, hooked to transition comment status
208
+ *
209
+ * @since 5.2
210
+ *
211
+ * @param string $new_status
212
+ * @param string $old_status
213
+ * @param object $comment
214
+ */
215
+ public function update_post_comment_meta( $new_status, $old_status, $comment )
216
+ {
217
+ // bail when not publishing or unpublishing
218
+ if ( $old_status == $new_status || ( $new_status != 'approved' && $old_status != 'approved' ) ) return;
219
+
220
+ $post_type = get_post_type( $comment->comment_post_ID );
221
+
222
+ // bail when...
223
+ if ( ! array_key_exists($post_type, $this->post_types) // inactive post type
224
+ || empty( $this->post_types[$post_type]['update_lastmod_on_comments'] ) // comments date irrelevant
225
+ ) return;
226
+
227
+ // update comment meta data
228
+ update_post_meta( $comment->comment_post_ID, '_xmlsf_comment_date', $comment->comment_date );
229
+ }
230
+
231
+ /**
232
+ * Update post comment meta, hooked to transition comment status
233
+ *
234
+ * @since 5.2
235
+ *
236
+ * @param int $comment_ID
237
+ * @param int $comment_approved
238
+ * @param array $commentdata
239
+ */
240
+ public function update_post_comment_meta_cp( $comment_ID, $comment_approved, $commentdata )
241
+ {
242
+ // bail when not published
243
+ if ( $comment_approved !== 1 ) return;
244
+
245
+ $post_type = get_post_type( $commentdata['comment_post_ID'] );
246
+
247
+ // bail when...
248
+ if ( ! array_key_exists($post_type, $this->post_types) // inactive post type
249
+ || empty( $this->post_types[$post_type]['update_lastmod_on_comments'] ) // comments date irrelevant
250
+ ) return;
251
+
252
+ // update comment meta data
253
+ update_post_meta( $commentdata['comment_post_ID'], '_xmlsf_comment_date', $commentdata['comment_date'] );
254
+ }
255
+
256
+ /**
257
+ * Prefetch all queried posts image and comment meta data
258
+ *
259
+ * @since 5.2
260
+ * @uses global $wp_query
261
+ */
262
+ public function prefetch_posts_meta()
263
+ {
264
+ if ( ! is_sitemap() ) return;
265
+
266
+ global $wp_query;
267
+
268
+ $post_type = $wp_query->get( 'post_type' );
269
+
270
+ if ( ! isset($this->post_types[$post_type]) ) return;
271
+
272
+ $y = $wp_query->get( 'year' );
273
+ $m = $wp_query->get( 'm' );
274
+ if ( empty($m) ) $m = 'all';
275
+
276
+ // if image tag active then prefetch images
277
+ if (
278
+ isset($this->post_types[$post_type]['tags']) &&
279
+ is_array( $this->post_types[$post_type]['tags'] ) &&
280
+ !empty( $this->post_types[$post_type]['tags']['image'] )
281
+ ) {
282
+ $primed = (array) get_option( 'xmlsf_images_meta_primed', array() );
283
+
284
+ if (
285
+ ! isset( $primed[$post_type] ) ||
286
+ ! is_array( $primed[$post_type] ) ||
287
+ (
288
+ ! in_array( $m, $primed[$post_type] ) &&
289
+ ! in_array( $y, $primed[$post_type] ) &&
290
+ ! in_array( 'all', $primed[$post_type] )
291
+ )
292
+ ) {
293
+ // prime images meta data
294
+ foreach ( $wp_query->posts as $post ) {
295
+ $this->_add_images_meta( $post, $this->post_types[$post_type]['tags']['image'] );
296
+ }
297
+
298
+ // add query to primed array
299
+ $primed[$post_type][] = $m;
300
+
301
+ // update
302
+ update_option( 'xmlsf_images_meta_primed', $primed );
303
+ }
304
+ }
305
+
306
+ // if update_lastmod_on_comments active then prefetch comments
307
+ if ( !empty($this->post_types[$post_type]['update_lastmod_on_comments']) ) {
308
+ $primed = (array) get_option( 'xmlsf_comments_meta_primed', array() );
309
+
310
+ if (
311
+ ! isset( $primed[$post_type] ) ||
312
+ ! is_array( $primed[$post_type] ) ||
313
+ (
314
+ ! in_array( $m, $primed[$post_type] ) &&
315
+ ! in_array( $y, $primed[$post_type] ) &&
316
+ ! in_array( 'all', $primed[$post_type] )
317
+ )
318
+ ) {
319
+ // prime comment meta data
320
+ foreach ( $wp_query->posts as $post ) {
321
+ $this->_add_comment_meta( $post );
322
+ }
323
+
324
+ // add query to primed array
325
+ $primed[$post_type][] = $m;
326
+
327
+ // update
328
+ update_option( 'xmlsf_comments_meta_primed', $primed );
329
+ }
330
+ }
331
+
332
+ }
333
+
334
+ /**
335
+ * Set posts images meta data
336
+ *
337
+ * @since 5.2
338
+ * @param array $post Post object
339
+ * @param string $which
340
+ */
341
+ private function _add_images_meta( $post, $which )
342
+ {
343
+ if ( ! is_object($post) || ! isset( $post->ID ) ) return;
344
+
345
+ $stored = (array) get_post_meta( $post->ID, '_xmlsf_image_'.$which );
346
+
347
+ // populate images and add as meta data
348
+ foreach ( xmlsf_images_data( $post, $which ) as $data ) {
349
+ if ( ! in_array( $data, $stored ) )
350
+ add_post_meta( $post->ID, '_xmlsf_image_'.$which, $data );
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Set post comment meta data
356
+ *
357
+ * @since 5.2
358
+ * @param array $post Post object
359
+ */
360
+ private function _add_comment_meta( $post )
361
+ {
362
+ if ( ! is_object( $post ) || ! isset( $post->ID ) ) return;
363
+
364
+ // get latest post comment
365
+ $comments = get_comments( array(
366
+ 'status' => 'approve',
367
+ 'number' => 1,
368
+ 'post_id' => $post->ID,
369
+ ) );
370
+
371
+ if ( isset( $comments[0]->comment_date ) )
372
+ update_post_meta( $post->ID, '_xmlsf_comment_date', $comments[0]->comment_date );
373
+ }
374
+
375
+ }
376
+
377
+ /**
378
+ * FEED TEMPLATES
379
+ */
380
+
381
+ /**
382
+ * Set up the sitemap index template
383
+ */
384
+ function xmlsf_load_template_index() {
385
+ load_template( XMLSF_DIR . '/views/feed-sitemap.php' );
386
+ }
387
+
388
+ /**
389
+ * set up the sitemap home page(s) template
390
+ */
391
+ function xmlsf_load_template_home() {
392
+ load_template( XMLSF_DIR . '/views/feed-sitemap-home.php' );
393
+ }
394
+
395
+ /**
396
+ * set up the post types sitemap template
397
+ */
398
+ function xmlsf_load_template() {
399
+ load_template( XMLSF_DIR . '/views/feed-sitemap-post_type.php' );
400
+ }
401
+
402
+ /**
403
+ * set up the taxonomy sitemap template
404
+ */
405
+ function xmlsf_load_template_taxonomy() {
406
+ load_template( XMLSF_DIR . '/views/feed-sitemap-taxonomy.php' );
407
+ }
408
+
409
+ /**
410
+ * set up the custom sitemap template
411
+ */
412
+ function xmlsf_load_template_custom() {
413
+ load_template( XMLSF_DIR . '/views/feed-sitemap-custom.php' );
414
+ }
controllers/{global.php → functions.php} RENAMED
@@ -9,19 +9,15 @@ function xmlsf_init() {
9
// Upgrade/install, maybe...
10
$db_version = get_option( 'xmlsf_version', 0 );
11
if ( ! version_compare( XMLSF_VERSION, $db_version, '=' ) ) {
12
- require XMLSF_DIR . '/controllers/upgrade.php';
13
new XMLSitemapFeed_Upgrade( $db_version );
14
}
15
16
- if ( is_admin() ) {
17
- require XMLSF_DIR . '/controllers/admin/main.php';
18
- }
19
-
20
$sitemaps = get_option( 'xmlsf_sitemaps' );
21
// include sitemaps if any enabled
22
if ( $sitemaps ) {
23
// main model functions
24
- require XMLSF_DIR . '/models/main.php';
25
26
// force remove url trailing slash
27
add_filter( 'user_trailingslashit', 'xmlsf_untrailingslash' );
@@ -33,25 +29,33 @@ function xmlsf_init() {
33
add_filter( 'rt_nginx_helper_purge_urls', 'xmlsf_nginx_helper_purge_urls', 10, 2 );
34
35
// main controller functions
36
- require XMLSF_DIR . '/controllers/main.php';
37
38
// include and instantiate class
39
xmlsf();
40
41
if ( ! empty( $sitemaps['sitemap-news'] ) ) {
42
- require XMLSF_DIR . '/models/sitemap-news.php';
43
add_filter( 'xmlsf_news_post_types', 'xmlsf_news_filter_post_types' );
44
45
- require XMLSF_DIR . '/controllers/sitemap-news.php';
46
- new XMLSF_Sitemap_News_Controller( $sitemaps['sitemap-news'] );
47
- }
48
49
if ( ! empty( $sitemaps['sitemap'] ) ) {
50
- require XMLSF_DIR . '/models/sitemap.php';
51
add_filter( 'xmlsf_post_types', 'xmlsf_filter_post_types' );
52
53
- require XMLSF_DIR . '/controllers/sitemap.php';
54
- new XMLSF_Sitemap_Controller( $sitemaps['sitemap'] );
55
}
56
57
// common sitemap element filters
@@ -86,7 +90,18 @@ function xmlsf_activate() {
86
function xmlsf_deactivate() {
87
delete_transient( 'xmlsf_flush_rewrite_rules' );
88
delete_transient( 'xmlsf_check_static_files' );
89
// remove filter and flush rules
90
- remove_filter( 'rewrite_rules_array', 'xmlsf_rewrite_rules', 1, 1 );
91
flush_rewrite_rules();
92
}
9
// Upgrade/install, maybe...
10
$db_version = get_option( 'xmlsf_version', 0 );
11
if ( ! version_compare( XMLSF_VERSION, $db_version, '=' ) ) {
12
+ require_once XMLSF_DIR . '/upgrade.php';
13
new XMLSitemapFeed_Upgrade( $db_version );
14
}
15
16
$sitemaps = get_option( 'xmlsf_sitemaps' );
17
// include sitemaps if any enabled
18
if ( $sitemaps ) {
19
// main model functions
20
+ require XMLSF_DIR . '/models/functions.shared.php';
21
22
// force remove url trailing slash
23
add_filter( 'user_trailingslashit', 'xmlsf_untrailingslash' );
29
add_filter( 'rt_nginx_helper_purge_urls', 'xmlsf_nginx_helper_purge_urls', 10, 2 );
30
31
// main controller functions
32
+ require XMLSF_DIR . '/controllers/functions.shared.php';
33
+
34
+ add_action( 'xmlsf_ping', 'xmlsf_debug_ping', 9, 4 );
35
36
// include and instantiate class
37
xmlsf();
38
39
if ( ! empty( $sitemaps['sitemap-news'] ) ) {
40
+ require XMLSF_DIR . '/models/functions.sitemap-news.php';
41
add_filter( 'xmlsf_news_post_types', 'xmlsf_news_filter_post_types' );
42
43
+ require XMLSF_DIR . '/controllers/class.xmlsf-sitemap-news.php';
44
+ new XMLSF_Sitemap_News( $sitemaps['sitemap-news'] );
45
+
46
+ // add feed type, news can now be accessed via /feed/sitemap-news too
47
+ add_feed( 'sitemap-news', 'xmlsf_news_load_template' );
48
+ }
49
50
if ( ! empty( $sitemaps['sitemap'] ) ) {
51
+ require XMLSF_DIR . '/models/functions.sitemap.php';
52
add_filter( 'xmlsf_post_types', 'xmlsf_filter_post_types' );
53
54
+ xmlsf_sitemap( $sitemaps['sitemap'] );
55
+
56
+ // add feed type, index can now be accessed via /feed/sitemap too
57
+ add_feed( 'sitemap', 'xmlsf_load_template_index' );
58
+ //add_filter( 'feed_content_type', 'xmlsf_content_type', 10, 2 );
59
}
60
61
// common sitemap element filters
90
function xmlsf_deactivate() {
91
delete_transient( 'xmlsf_flush_rewrite_rules' );
92
delete_transient( 'xmlsf_check_static_files' );
93
+
94
+ // remove metadata
95
+ global $wpdb;
96
+ // posts meta
97
+ $wpdb->delete( $wpdb->prefix.'postmeta', array( 'meta_key' => '_xmlsf_image_attached' ) );
98
+ $wpdb->delete( $wpdb->prefix.'postmeta', array( 'meta_key' => '_xmlsf_image_featured' ) );
99
+ $wpdb->delete( $wpdb->prefix.'postmeta', array( 'meta_key' => '_xmlsf_comment_date' ) );
100
+ // terms meta
101
+ $wpdb->delete( $wpdb->prefix.'termmeta', array( 'meta_key' => 'term_modified' ) );
102
+
103
// remove filter and flush rules
104
+ remove_filter( 'rewrite_rules_array', 'xmlsf_rewrite_rules', 99 );
105
+ // how to unset add_feed() ?
106
flush_rewrite_rules();
107
}
controllers/functions.shared.php ADDED
@@ -0,0 +1,73 @@
1
+ <?php
2
+
3
+ /**
4
+ * WPML: switch language
5
+ * @see https://wpml.org/wpml-hook/wpml_post_language_details/
6
+ */
7
+ function xmlsf_wpml_language_switcher() {
8
+ global $sitepress, $post;
9
+ if ( isset( $sitepress ) ) {
10
+ $post_language = apply_filters( 'wpml_post_language_details', NULL, $post->ID );
11
+ $sitepress->switch_lang( $post_language['language_code'] );
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Generator info
17
+ */
18
+ function xmlsf_generator() {
19
+ $date = date( 'c' );
20
+
21
+ require XMLSF_DIR . '/views/_generator.php';
22
+ }
23
+
24
+ /**
25
+ * Usage info for debugging
26
+ */
27
+ function xmlsf_usage() {
28
+ if ( defined('WP_DEBUG') && WP_DEBUG == true ) {
29
+ $num = get_num_queries();
30
+ $mem = function_exists('memory_get_peak_usage') ? round( memory_get_peak_usage()/1024/1024, 2 ) . 'M' : false;
31
+ $limit = ini_get('memory_limit');
32
+
33
+ require XMLSF_DIR . '/views/_usage.php';
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Try to turn on ob_gzhandler output compression
39
+ */
40
+ function xmlsf_output_compression() {
41
+ // try to enable zlib.output_compression or fall back to output buffering with ob_gzhandler
42
+ if ( false !== ini_set( 'zlib.output_compression', 'On' ) )
43
+ // if zlib.output_compression turned on, then make sure to remove wp_ob_end_flush_all
44
+ remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 );
45
+ else {
46
+ ob_get_length()
47
+ || in_array('ob_gzhandler', ob_list_handlers())
48
+ || ob_start('ob_gzhandler');
49
+ }
50
+
51
+ if ( defined('WP_DEBUG') && WP_DEBUG == true ) {
52
+ // zlib
53
+ $zlib = ini_get( 'zlib.output_compression' ) ? 'ENABLED' : 'DISABLED';
54
+ error_log('Zlib output compression '.$zlib);
55
+
56
+ // ob_gzhandler
57
+ $gz = in_array('ob_gzhandler', ob_list_handlers()) ? 'ENABLED' : 'DISABLED';
58
+ error_log('GZhandler output buffer compression '.$gz);
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Error messages for ping
64
+ */
65
+ function xmlsf_debug_ping( $se, $sitemap, $ping_url, $response_code ) {
66
+ if ( defined('WP_DEBUG') && WP_DEBUG == true ) {
67
+ if ( $response_code == 999 ) {
68
+ error_log( 'Ping '. $se .' skipped.' );
69
+ } else {
70
+ error_log( 'Pinged '. $ping_url .' with response code: ' . $response_code );
71
+ }
72
+ }
73
+ }
controllers/main.php DELETED
@@ -1,50 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * WPML: switch language
5
- * @see https://wpml.org/wpml-hook/wpml_post_language_details/
6
- */
7
- function xmlsf_wpml_language_switcher() {
8
- global $sitepress, $post;
9
- if ( isset( $sitepress ) ) {
10
- $post_language = apply_filters( 'wpml_post_language_details', NULL, $post->ID );
11
- $sitepress->switch_lang( $post_language['language_code'] );
12
- }
13
- }
14
-
15
- /**
16
- * Generator info
17
- */
18
- function xmlsf_generator() {
19
- $date = date('Y-m-d\TH:i:s+00:00');
20
-
21
- require XMLSF_DIR . '/views/_generator.php';
22
- }
23
-
24
- /**
25
- * Usage info for debugging
26
- */
27
- function xmlsf_usage() {
28
- if ( defined('WP_DEBUG') && WP_DEBUG == true ) {
29
- $num = get_num_queries();
30
- $mem = function_exists('memory_get_peak_usage') ? round(memory_get_peak_usage()/1024/1024,2) : 0;
31
-
32
- require XMLSF_DIR . '/views/_usage.php';
33
- }
34
- }
35
-
36
- /**
37
- * Try to turn on ob_gzhandler output compression
38
- */
39
- function xmlsf_ob_gzhandler() {
40
- in_array('ob_gzhandler', ob_list_handlers())
41
- || ob_get_contents()
42
- || ini_get("zlib.output_compression")
43
- || ( isset($_SERVER['HTTP_X_VARNISH']) && is_numeric($_SERVER['HTTP_X_VARNISH']) )
44
- || ob_start("ob_gzhandler");
45
-
46
- if ( defined('WP_DEBUG') && WP_DEBUG == true ) {
47
- $status = in_array('ob_gzhandler', ob_list_handlers()) ? 'ENABLED' : 'DISABLED';
48
- error_log('GZhandler output buffer compression '.$status);
49
- }
50
- }
controllers/sitemap-news.php DELETED
@@ -1,67 +0,0 @@
1
- <?php
2
- /* ------------------------------
3
- * XMLSF Controller CLASS
4
- * ------------------------------ */
5
-
6
- class XMLSF_Sitemap_News_Controller
7
- {
8
- /**
9
- * Sitemap index name
10
- * @var string
11
- */
12
- private $sitemap = 'sitemap-news.xml';
13
-
14
- /**
15
- * Post types included in sitemap index
16
- * @var array
17
- */
18
- private $post_types;
19
-
20
- /**
21
- * CONSTRUCTOR
22
- * Runs on init
23
- */
24
-
25
- function __construct( $sitemap )
26
- {
27
- $this->sitemap = $sitemap;
28
-
29
- // PINGING
30
- add_action( 'transition_post_status', array($this,'do_pings'), 10, 3 );
31
-
32
- // FEED TEMPLATES
33
- add_action('do_feed_sitemap-news', 'xmlsf_news_load_template', 10, 1);
34
- }
35
-
36
- /**
37
- * Do pings, hooked to transition post status
38
- *
39
- * @param $new_status
40
- * @param $old_status
41
- * @param $post
42
- */
43
- public function do_pings( $new_status, $old_status, $post ) {
44
- // are we publishing?
45
- if ( $old_status == 'publish' || $new_status != 'publish' )
46
- return;
47
-
48
- $ping = (array) get_option( 'xmlsf_ping', array() );
49
-
50
- if ( in_array( 'google', $ping ) ) {
51
- // check if we've got a post type that is included in our news sitemap
52
- // TODO also check category if needed
53
- $news_tags = get_option('xmlsf_news_tags');
54
- if ( ! empty( $news_tags['post_type'] ) && in_array( $post->post_type, (array) $news_tags['post_type'] ) ) {
55
- xmlsf_ping( 'google', $this->sitemap, 5 * MINUTE_IN_SECONDS );
56
- }
57
- }
58
- }
59
-
60
- }
61
-
62
- /**
63
- * set up the news sitemap template
64
- */
65
- function xmlsf_news_load_template() {
66
- load_template( XMLSF_DIR . '/views/feed-sitemap-news.php' );
67
- }
controllers/sitemap.php DELETED
@@ -1,241 +0,0 @@
1
- <?php
2
-
3
- /* ------------------------------
4
- * XMLSF Controller CLASS
5
- * ------------------------------ */
6
-
7
- class XMLSF_Sitemap_Controller
8
- {
9
- /**
10
- * Sitemap index name
11
- * @var string
12
- */
13
- private $sitemap = 'sitemap.xml';
14
-
15
- /**
16
- * Post types included in sitemap index
17
- * @var array
18
- */
19
- private $post_types;
20
-
21
- /**
22
- * CONSTRUCTOR
23
- * Runs on init
24
- */
25
-
26
- function __construct( $sitemap )
27
- {
28
- $this->sitemap = $sitemap;
29
-
30
- // Cache clearance
31
- add_action( 'clean_post_cache', array($this,'clean_post_cache'), 99, 2 );
32
-
33
- // Update term meta lastmod date
34
- add_action( 'transition_post_status', array($this,'update_term_modified_meta'), 10, 3 );
35
-
36
- // PINGING
37
- add_action( 'transition_post_status', array($this,'do_pings'), 10, 3 );
38
-
39
- // FEED TEMPLATES
40
- add_action( 'do_feed_sitemap', 'xmlsf_load_template_index', 10, 1 );
41
- add_action( 'do_feed_sitemap_index', 'xmlsf_load_template_index', 10, 1 );
42
- add_action( 'do_feed_sitemap-home', 'xmlsf_load_template_home', 10, 1 );
43
- add_action( 'do_feed_sitemap-custom', 'xmlsf_load_template_custom', 10, 1 );
44
-
45
- $this->post_types = get_option( 'xmlsf_post_types' );
46
-
47
- if ( is_array($this->post_types) ) {
48
- foreach ( $this->post_types as $post_type => $settings ) {
49
- if ( !empty($settings['active']) )
50
- add_action( 'do_feed_sitemap-posttype-'.$post_type, 'xmlsf_load_template', 10, 1 );
51
- }
52
- }
53
-
54
- foreach ( xmlsf_get_taxonomies() as $name ) {
55
- add_action( 'do_feed_sitemap-taxonomy-'.$name, 'xmlsf_load_template_taxonomy', 10, 1 );
56
- }
57
- }
58
-
59
- /**
60
- * Do pings, hooked to transition post status
61
- *
62
- * @param $new_status
63
- * @param $old_status
64
- * @param $post
65
- */
66
- public function do_pings( $new_status, $old_status, $post ) {
67
- // are we publishing?
68
- if ( $old_status == 'publish' || $new_status != 'publish' )
69
- return;
70
-
71
- $ping = get_option( 'xmlsf_ping' );
72
-
73
- if ( empty( $ping ) )
74
- return;
75
-
76
- // check if we've got a post type that is included in our sitemap
77
- $post_types = get_option( 'xmlsf_post_types' );
78
- if ( array_key_exists( $post->post_type, (array) $this->post_types ) ) {
79
-
80
- foreach ( $ping as $se ) {
81
- xmlsf_ping( $se, $this->sitemap, HOUR_IN_SECONDS );
82
- }
83
- }
84
- }
85
-
86
- /**
87
- * Cache delete on clean_post_cache
88
- *
89
- * @param $post_ID
90
- * @param $post
91
- */
92
- public function clean_post_cache( $post_ID, $post ) {
93
- // are we moving the post in or out of published status?
94
- wp_cache_delete( 'xmlsf_get_archives', 'general' );
95
-
96
- // TODO get year / month here to delete specific keys too !!!!
97
- $m = mysql2date( 'Ym', $post->post_date_gmt, false );
98
- $y = substr( $m, 0, 4 );
99
-
100
- // clear possible last post modified cache keys
101
- wp_cache_delete( 'lastpostmodified:gmt', 'timeinfo' ); // should be handled by WP core?
102
- wp_cache_delete( 'lastpostmodified'.$y.':gmt', 'timeinfo' );
103
- wp_cache_delete( 'lastpostmodified'.$m.':gmt', 'timeinfo' );
104
- wp_cache_delete( 'lastpostmodified'.$y.':gmt:'.$post->post_type, 'timeinfo' );
105
- wp_cache_delete( 'lastpostmodified'.$m.':gmt:'.$post->post_type, 'timeinfo' );
106
-
107
- // clear possible last post date cache keys
108
- wp_cache_delete( 'lastpostdate:gmt', 'timeinfo' );
109
- wp_cache_delete( 'lastpostdate:gmt:'.$post->post_type, 'timeinfo' );
110
-
111
- // clear possible fist post date cache keys
112
- wp_cache_delete( 'firstpostdate:gmt', 'timeinfo' );
113
- wp_cache_delete( 'firstpostdate:gmt:'.$post->post_type, 'timeinfo' );
114
- }
115
-
116
- /**
117
- * Update term modified meta, hooked to transition post status
118
- *
119
- * @param $new_status
120
- * @param $old_status
121
- * @param $post
122
- */
123
- public function update_term_modified_meta( $new_status, $old_status, $post ) {
124
-
125
- // bail out on inactive post types
126
- if ( ! array_key_exists($post->post_type, $this->post_types) || empty( $this->post_types[$post->post_type]['active'] ) )
127
- return;
128
-
129
- // bail out when not publishing or unpublishing or editing a live post
130
- // note: prepend " $old_status == $new_status || " to exclude live editong too
131
- if ( $new_status != 'publish' && $old_status != 'publish' )
132
- return;
133
-
134
- $taxonomy_settings = get_option( 'xmlsf_taxonomy_settings' );
135
-
136
- // bail if no taxonomies activated
137
- if ( ! is_array($taxonomy_settings) || empty( $taxonomy_settings['active'] ) )
138
- return;
139
-
140
- require_once XMLSF_DIR . '/models/public/sitemap.php';
141
-
142
- $taxonomies = get_option( 'xmlsf_taxonomies' );
143
- if ( empty( $taxonomies ) )
144
- $taxonomies = xmlsf_public_taxonomies();
145
-
146
- $term_ids = array();
147
- foreach ( (array) $taxonomies as $tax_name ) {
148
- $terms = wp_get_post_terms( $post->ID, $tax_name, array( 'fields' => 'ids' ));
149
- if ( !is_wp_error($terms) ) {
150
- $term_ids = array_merge( $term_ids, $terms );
151
- }
152
- }
153
-
154
- $time = date('Y-m-d H:i:s');
155
-
156
- foreach( $term_ids as $id ) {
157
- update_term_meta( $id, 'term_modified_gmt', $time );
158
- }
159
- }
160
-
161
- }
162
-
163
- /**
164
- * FEED TEMPLATES
165
- */
166
-
167
- /**
168
- * Set up the sitemap index template
169
- */
170
- function xmlsf_load_template_index() {
171
- load_template( XMLSF_DIR . '/views/feed-sitemap.php' );
172
- }
173
-
174
- /**
175
- * set up the sitemap home page(s) template
176
- */
177
- function xmlsf_load_template_home() {
178
- load_template( XMLSF_DIR . '/views/feed-sitemap-home.php' );
179
- }
180
-
181
- /**
182
- * set up the post types sitemap template
183
- */
184
- function xmlsf_load_template() {
185
- load_template( XMLSF_DIR . '/views/feed-sitemap-post_type.php' );
186
- }
187
-
188
- /**
189
- * set up the taxonomy sitemap template
190
- */
191
- function xmlsf_load_template_taxonomy() {
192
- load_template( XMLSF_DIR . '/views/feed-sitemap-taxonomy.php' );
193
- }
194
-
195
- /**
196
- * set up the custom sitemap template
197
- */
198
- function xmlsf_load_template_custom() {
199
- load_template( XMLSF_DIR . '/views/feed-sitemap-custom.php' );
200
- }
201
-
202
- /* -------------------------------------
203
- * MISSING WORDPRESS FUNCTIONS
204
- * ------------------------------------- */
205
-
206
- /**
207
- * Retrieve the date that the first post/page was published.
208
- * Variation of function get_lastpostdate, uses _get_post_time
209
- *
210
- * The server timezone is the default and is the difference between GMT and
211
- * server time. The 'blog' value is the date when the last post was posted. The
212
- * 'gmt' is when the last post was posted in GMT formatted date.
213
- *
214
- * @uses apply_filters() Calls 'get_firstpostdate' filter
215
- * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
216
- * @param string $post_type Post type to check.
217
- * @return string The date of the last post.
218
- */
219
- if( !function_exists('get_firstpostdate') ) {
220
- function get_firstpostdate($timezone = 'server', $post_type = 'any') {
221
- return apply_filters( 'get_firstpostdate', _get_post_time( $timezone, 'date', $post_type, 'first' ), $timezone );
222
- }
223
- }
224
-
225
- /**
226
- * Retrieve last post/page modified date depending on timezone.
227
- * Variation of function get_lastpostmodified, uses _get_post_time
228
- *
229
- * The server timezone is the default and is the difference between GMT and
230
- * server time. The 'blog' value is the date when the last post was posted. The
231
- * 'gmt' is when the last post was posted in GMT formatted date.
232
- *
233
- * @uses apply_filters() Calls 'get_lastmodified' filter
234
- * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
235
- * @return string The date of the oldest modified post.
236
- */
237
- if( !function_exists('get_lastmodified') ) {
238
- function get_lastmodified( $timezone = 'server', $post_type = 'any', $m = '' ) {
239
- return apply_filters( 'get_lastmodified', _get_post_time( $timezone, 'modified', $post_type, 'last', $m ), $timezone );
240
- }
241
- }
models/admin/sitemap.php DELETED
@@ -1,104 +0,0 @@
1
- <?php
2
-
3
- class XMLSF_Admin_Sitemap_Sanitize
4
- {
5
- public static function taxonomies( $new )
6
- {
7
- return $new;
8
- }
9
-
10
- public static function taxonomy_settings( $new )
11
- {
12
- $sanitized = array();
13
-
14
- $sanitized['active'] = !empty($new['active']) ? '1' : '';
15
- $sanitized['priority'] = isset($new['priority']) ? self::priority($new['priority'],'0.1','0.9') : '0.3';
16
- $sanitized['dynamic_priority'] = !empty($new['dynamic_priority']) ? '1' : '';
17
- $sanitized['term_limit'] = isset($new['term_limit']) ? intval($new['term_limit']) : 5000;
18
- if ( $sanitized['term_limit'] < 1 || $sanitized['term_limit'] > 50000 ) $sanitized['term_limit'] = 50000;
19
-
20
- return $sanitized;
21
- }
22
-
23
- public static function post_types_settings( $new = array() )
24
- {
25
- $sanitized = is_array($new) ? $new : array();
26
-
27
- foreach ($sanitized as $post_type => $settings) {
28
- $sanitized[$post_type]['priority'] = isset($settings['priority']) ? self::priority($settings['priority'],'0.1','0.9') : '0.5';
29
- }
30
-
31
- return $sanitized;
32
- }
33
-
34
- public static function priority( $priority, $min = 0, $max = 1 )
35
- {
36
- // make sure we have the proper locale setting for calculations
37
- setlocale( LC_NUMERIC, 'C' );
38
-
39
- $priority = floatval(str_replace(',','.',$priority));
40
-
41
- if ( $priority <= (float) $min ) {
42
- return number_format( $min, 1 );
43
- } elseif ( $priority >= (float) $max ) {
44
- return number_format( $max, 1 );
45
- } else {
46
- return number_format( $priority, 1 );
47
- }
48
- }
49
-
50
- public static function custom_sitemaps_settings( $new )
51
- {
52
- // clean up input
53
- if ( is_array( $new ) ) {
54
- $new = array_filter($new);
55
- $new = reset($new);
56
- }
57
-
58
- if ( empty($new) )
59
- return '';
60
-
61
- // build sanitized output
62
- $input = explode( PHP_EOL, sanitize_textarea_field($new) );
63
- $sanitized = array();
64
- foreach ( $input as $line ) {
65
- $line = filter_var( esc_url( trim( $line ) ), FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED );
66
- if ( ! empty( $line ) )
67
- $sanitized[] = $line;
68
- }
69
-
70
- return !empty($sanitized) ? $sanitized : '';
71
- }
72
-
73
- public static function custom_urls_settings( $new )
74
- {
75
- // clean up input
76
- if ( is_array( $new ) ) {
77
- $new = array_filter($new);
78
- $new = reset($new);
79
- }
80
-
81
- if ( empty($new) )
82
- return '';
83
-
84
- $input = explode( PHP_EOL, sanitize_textarea_field( $new ) );
85
-
86
- // build sanitized output
87
- $sanitized = array();
88
- foreach ( $input as $line ) {
89
- if ( empty( $line ) )
90
- continue;
91
-
92
- $arr = explode( " ", trim( $line ) );
93
-
94
- $url = filter_var( esc_url( trim( $arr[0] ) ), FILTER_VALIDATE_URL );
95
-
96
- if ( !empty( $url ) ) {
97
- $priority = isset( $arr[1] ) ? self::priority($arr[1]) : '0.5';
98
- $sanitized[] = array( $url, $priority );
99
- }
100
- }
101
-
102
- return !empty($sanitized) ? $sanitized : '';
103
- }
104
- }
models/class-xmlsitemapfeed.php CHANGED
@@ -9,14 +9,13 @@ class XMLSitemapFeed {
9
private $defaults = array();
10
11
/**
12
- * Defaults
13
* @var array
14
*/
15
public $default_news_tags = array(
16
'name' => '',
17
'post_type' => array('post'),
18
- 'categories' => '',
19
- 'image' => 'featured'
20
);
21
22
/**
@@ -100,6 +99,13 @@ class XMLSitemapFeed {
100
*/
101