XML Sitemap & Google News feeds - Version 5.0.7

Version Description

Bugfix release.

=

Download this release

Release Info

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

Code changes from version 4.9.4 to 5.0.7

Files changed (107) hide show
  1. controllers/admin/main.php +527 -0
  2. controllers/admin/notices.php +58 -0
  3. controllers/admin/sitemap-news.php +212 -0
  4. controllers/admin/sitemap.php +224 -0
  5. controllers/global.php +238 -0
  6. controllers/main.php +178 -0
  7. controllers/public/shared.php +34 -0
  8. controllers/public/sitemap-news.php +9 -0
  9. controllers/public/sitemap.php +106 -0
  10. includes/class-xmlsitemapfeed-admin.php +0 -1127
  11. includes/class-xmlsitemapfeed.php +0 -1905
  12. includes/feed-sitemap-taxonomy.php +0 -43
  13. includes/feed-sitemap.php +0 -72
  14. includes/functions.php +0 -174
  15. languages/instructions.txt +0 -27
  16. languages/xml-sitemap-feed-es_ES.mo +0 -0
  17. languages/xml-sitemap-feed-es_ES.po +0 -528
  18. languages/xml-sitemap-feed-fr_FR.mo +0 -0
  19. languages/xml-sitemap-feed-fr_FR.po +0 -594
  20. languages/xml-sitemap-feed-ga_GA.mo +0 -0
  21. languages/xml-sitemap-feed-ga_GA.po +0 -77
  22. languages/xml-sitemap-feed-id_ID.mo +0 -0
  23. languages/xml-sitemap-feed-id_ID.po +0 -304
  24. languages/xml-sitemap-feed-it_IT.mo +0 -0
  25. languages/xml-sitemap-feed-it_IT.po +0 -539
  26. languages/xml-sitemap-feed-nl_NL.mo +0 -0
  27. languages/xml-sitemap-feed-nl_NL.po +0 -814
  28. languages/xml-sitemap-feed-sr_RS.mo +0 -0
  29. languages/xml-sitemap-feed-sr_RS.po +0 -264
  30. languages/xml-sitemap-feed-ua_UA.mo +0 -0
  31. languages/xml-sitemap-feed-ua_UA.po +0 -86
  32. languages/xml-sitemap-feed-xx_XX.po +0 -539
  33. languages/xml-sitemap-feed.pot +0 -544
  34. models/admin/main.php +157 -0
  35. models/admin/sitemap-news.php +34 -0
  36. models/admin/sitemap.php +104 -0
  37. models/class-xmlsitemapfeed.php +276 -0
  38. models/global.php +81 -0
  39. models/main.php +106 -0
  40. models/public/shared.php +123 -0
  41. models/public/sitemap-news.php +131 -0
  42. models/public/sitemap.php +648 -0
  43. readme.txt +83 -43
  44. uninstall.php +19 -13
  45. views/_generator.php +4 -0
  46. views/_usage.php +1 -0
  47. views/admin/field-news-categories.php +12 -0
  48. views/admin/field-news-image.php +10 -0
  49. views/admin/field-news-labels.php +6 -0
  50. views/admin/field-news-name.php +7 -0
  51. views/admin/field-news-post-type.php +23 -0
  52. views/admin/field-ping.php +16 -0
  53. views/admin/field-robots.php +7 -0
  54. views/admin/field-sitemap-custom.php +7 -0
  55. views/admin/field-sitemap-domains.php +7 -0
  56. views/admin/field-sitemap-post-type.php +78 -0
  57. views/admin/field-sitemap-taxonomies.php +20 -0
  58. views/admin/field-sitemap-taxonomy-settings.php +36 -0
  59. views/admin/field-sitemap-urls.php +7 -0
  60. views/admin/field-sitemaps.php +37 -0
  61. views/admin/help-tab-advanced.php +17 -0
  62. views/admin/help-tab-allowed-domains.php +4 -0
  63. views/admin/help-tab-news-categories.php +3 -0
  64. views/admin/help-tab-news-images.php +7 -0
  65. views/admin/help-tab-news-labels.php +8 -0
  66. views/admin/help-tab-news-name.php +4 -0
  67. views/admin/help-tab-news-sidebar.php +12 -0
  68. views/admin/help-tab-news.php +4 -0
  69. views/admin/help-tab-ping.php +10 -0
  70. views/admin/help-tab-post-types.php +15 -0
  71. views/admin/help-tab-robots.php +7 -0
  72. views/admin/help-tab-sidebar.php +9 -0
  73. views/admin/help-tab-sitemaps.php +3 -0
  74. views/admin/help-tab-support.php +18 -0
  75. views/admin/help-tab-taxonomies.php +10 -0
  76. views/admin/help-tab-tools.php +8 -0
  77. views/admin/meta-box-news.php +7 -0
  78. views/admin/meta-box.php +15 -0
  79. views/admin/notice-cleared.php +5 -0
  80. views/admin/notice-date-redirect.php +22 -0
  81. views/admin/notice-deleted.php +5 -0
  82. views/admin/notice-failed.php +8 -0
  83. views/admin/notice-nonce-error.php +5 -0
  84. views/admin/notice-none-found.php +5 -0
  85. views/admin/notice-not-allowed.php +5 -0
  86. views/admin/notice-static-files.php +27 -0
  87. views/admin/notice-wpseo-date-redirect.php +23 -0
  88. views/admin/notice-wpseo-sitemap.php +22 -0
  89. views/admin/notice.php +26 -0
  90. views/admin/page-sitemap-news.php +54 -0
  91. views/admin/page-sitemap.php +57 -0
  92. views/admin/sidebar-contribute.php +19 -0
  93. views/admin/sidebar-help.php +8 -0
  94. {includes → views}/feed-sitemap-custom.php +15 -21
  95. {includes → views}/feed-sitemap-home.php +8 -12
  96. {includes → views}/feed-sitemap-news.php +17 -90
  97. {includes → views}/feed-sitemap-post_type.php +17 -15
  98. views/feed-sitemap-taxonomy.php +36 -0
  99. views/feed-sitemap.php +76 -0
  100. {images → views/images}/sitemapxml.gif +0 -0
  101. views/robots.php +19 -0
  102. views/styles/admin.css +19 -0
  103. {includes/xsl → views/styles}/sitemap-index.xsl +0 -0
  104. {includes/xsl → views/styles}/sitemap-news.xsl +0 -6
  105. views/styles/sitemap-taxonomy.xsl +46 -0
  106. {includes/xsl → views/styles}/sitemap.xsl +0 -0
  107. xml-sitemap.php +30 -62
controllers/admin/main.php ADDED
@@ -0,0 +1,527 @@
1
+ <?php
2
+ /* ------------------------------
3
+ * XMLSF Admin CLASS
4
+ * ------------------------------ */
5
+
6
+ class XMLSF_Admin_Controller
7
+ {
8
+ /**
9
+ * Static files conflicting with this plugin
10
+ * @var array
11
+ */
12
+ public static $static_files = null;
13
+
14
+ /**
15
+ * CONSTRUCTOR
16
+ * Runs on init
17
+ */
18
+
19
+ function __construct()
20
+ {
21
+ require XMLSF_DIR . '/models/admin/main.php';
22
+ require XMLSF_DIR . '/controllers/admin/notices.php';
23
+
24
+ $sitemaps = (array) get_option( 'xmlsf_sitemaps' );
25
+
26
+ if ( isset($sitemaps['sitemap']) ) {
27
+ require XMLSF_DIR . '/models/admin/sitemap.php';
28
+ require XMLSF_DIR . '/controllers/admin/sitemap.php';
29
+ }
30
+
31
+ if ( isset($sitemaps['sitemap-news']) ) {
32
+ require XMLSF_DIR . '/models/admin/sitemap-news.php';
33
+ require XMLSF_DIR . '/controllers/admin/sitemap-news.php';
34
+ }
35
+
36
+ // NGINX HELPER PURGE URLS
37
+ add_filter( 'rt_nginx_helper_purge_urls', 'xmlsf_nginx_helper_purge_urls', 10, 2 );
38
+
39
+ // ACTION LINK
40
+ add_filter( 'plugin_action_links_' . XMLSF_BASENAME, 'xmlsf_add_action_link' );
41
+
42
+ add_action( 'admin_init', array( $this, 'notices_actions' ) );
43
+ add_action( 'admin_init', array( $this, 'transients_actions' ) );
44
+ add_action( 'admin_init', array( $this, 'tools_actions' ) );
45
+ add_action( 'admin_init', array( $this, 'register_settings' ) );
46
+ add_action( 'admin_init', array( $this, 'register_meta_boxes' ) );
47
+ if ( ( !is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() )
48
+ add_action( 'admin_init', array( $this, 'static_files' ) );
49
+ add_action( 'admin_init', array( $this, 'verify_wpseo_settings' ) );
50
+ }
51
+
52
+ /**
53
+ * SETTINGS
54
+ */
55
+
56
+ /**
57
+ * Register settings and add settings fields
58
+ */
59
+
60
+ public function register_settings()
61
+ {
62
+ $sitemaps = (array) get_option( 'xmlsf_sitemaps' );
63
+
64
+ // sitemaps
65
+ register_setting( 'reading', 'xmlsf_sitemaps', array('XMLSF_Admin_Sanitize','sitemaps_settings') );
66
+ add_settings_field( 'xmlsf_sitemaps', __('Enable XML sitemaps','xml-sitemap-feed'), array($this,'sitemaps_settings_field'), 'reading' );
67
+
68
+ // custom domains, only when any sitemap is active
69
+ if ( isset($sitemaps['sitemap']) || isset($sitemaps['sitemap-news']) ) {
70
+ register_setting( 'reading', 'xmlsf_domains', array('XMLSF_Admin_Sanitize','domains_settings') );
71
+ add_settings_field( 'xmlsf_domains', __('Allowed domains','xml-sitemap-feed'), array($this,'domains_settings_field'), 'reading' );
72
+ }
73
+
74
+ // help tab
75
+ add_action( 'load-options-reading.php', array($this,'xml_sitemaps_help') );
76
+
77
+ // robots rules, only when permalinks are set
78
+ $rules = get_option( 'rewrite_rules' );
79
+ if( ! xmlsf()->plain_permalinks() && isset( $rules['robots\.txt#x27;] ) ) {
80
+ register_setting( 'reading', 'xmlsf_robots', array('XMLSF_Admin_Sanitize','robots_settings') );
81
+ add_settings_field( 'xmlsf_robots', __('Additional robots.txt rules','xml-sitemap-feed'), array($this,'robots_settings_field'), 'reading' );
82
+ }
83
+
84
+ // ping, only when any sitemap is active
85
+ if ( isset($sitemaps['sitemap']) || isset($sitemaps['sitemap-news']) ) {
86
+ register_setting( 'writing', 'xmlsf_ping', array('XMLSF_Admin_Sanitize','ping_settings') );
87
+ add_settings_field( 'xmlsf_ping', __('Ping Services','xml-sitemap-feed'), array($this,'ping_settings_field'), 'writing' );
88
+ add_action( 'load-options-writing.php', array($this,'ping_settings_help') );
89
+ }
90
+ }
91
+
92
+ /* SITEMAPS */
93
+
94
+ public function xml_sitemaps_help()
95
+ {
96
+ ob_start();
97
+ include XMLSF_DIR . '/views/admin/help-tab-sitemaps.php';
98
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
99
+ $content = ob_get_clean();
100
+
101
+ get_current_screen()->add_help_tab( array(
102
+ 'id' => 'sitemap-settings',
103
+ 'title' => __( 'Enable XML sitemaps', 'xml-sitemap-feed' ),
104
+ 'content' => $content,
105
+ 'priority' => 11
106
+ ) );
107
+
108
+ ob_start();
109
+ include XMLSF_DIR . '/views/admin/help-tab-allowed-domains.php';
110
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
111
+ $content = ob_get_clean();
112
+
113
+ get_current_screen()->add_help_tab( array(
114
+ 'id' => 'allowed-domains',
115
+ 'title' =>__( 'Allowed domains', 'xml-sitemap-feed' ),
116
+ 'content' => $content,
117
+ 'priority' => 11
118
+ ) );
119
+
120
+ ob_start();
121
+ include XMLSF_DIR . '/views/admin/help-tab-robots.php';
122
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
123
+ $content = ob_get_clean();
124
+
125
+ get_current_screen()->add_help_tab( array(
126
+ 'id' => 'robots',
127
+ 'title' => __( 'Additional robots.txt rules', 'xml-sitemap-feed' ),
128
+ 'content' => $content,
129
+ 'priority' => 11
130
+ ) );
131
+ }
132
+
133
+ /**
134
+ * Sitemap settings fields
135
+ */
136
+
137
+ public function sitemaps_settings_field()
138
+ {
139
+ if ( 1 == get_option('blog_public') ) :
140
+
141
+ $options = (array) get_option( 'xmlsf_sitemaps' );
142
+
143
+ // The actual fields for data entry
144
+ include XMLSF_DIR . '/views/admin/field-sitemaps.php';
145
+
146
+ else :
147
+
148
+ _e( 'XML Sitemaps are not available because of your site&#8217;s visibility settings (above).', 'xml-sitemap-feed' );
149
+
150
+ endif;
151
+ }
152
+
153
+ /**
154
+ * Domain settings field
155
+ */
156
+
157
+ public function domains_settings_field()
158
+ {
159
+ $domains = get_option('xmlsf_domains');
160
+ if ( !is_array($domains) ) $domains = array();
161
+
162
+ // The actual fields for data entry
163
+ include XMLSF_DIR . '/views/admin/field-sitemap-domains.php';
164
+ }
165
+
166
+ /* ROBOTS */
167
+
168
+ public function robots_settings_field()
169
+ {
170
+ // The actual fields for data entry
171
+ include XMLSF_DIR . '/views/admin/field-robots.php';
172
+ }
173
+
174
+ /* PING SETTINGS */
175
+
176
+ public function ping_settings_help()
177
+ {
178
+ ob_start();
179
+ include XMLSF_DIR . '/views/admin/help-tab-ping.php';
180
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
181
+ $content = ob_get_clean();
182
+
183
+ get_current_screen()->add_help_tab( array(
184
+ 'id' => 'ping-services',
185
+ 'title' => __( 'Ping Services', 'xml-sitemap-feed' ),
186
+ 'content' => $content,
187
+ 'priority' => 11
188
+ ) );
189
+ }
190
+
191
+ public function ping_settings_field()
192
+ {
193
+ $options = get_option( 'xmlsf_ping' );
194
+
195
+ // The actual fields for data entry
196
+ include XMLSF_DIR . '/views/admin/field-ping.php';
197
+ }
198
+
199
+ /**
200
+ * META BOXES
201
+ */
202
+
203
+ /**
204
+ * Register settings and add settings fields
205
+ */
206
+
207
+ public function register_meta_boxes()
208
+ {
209
+ $sitemaps = (array) get_option( 'xmlsf_sitemaps' );
210
+
211
+ if ( isset($sitemaps['sitemap-news']) ) {
212
+ // post meta box
213
+ add_action( 'add_meta_boxes', array($this,'add_meta_box_news') );
214
+ }
215
+
216
+ if ( isset($sitemaps['sitemap']) ) {
217
+ // post meta box
218
+ add_action( 'add_meta_boxes', array($this,'add_meta_box') );
219
+ }
220
+
221
+ if ( isset($sitemaps['sitemap']) || isset($sitemaps['sitemap-news']) ) {
222
+ // save post meta box settings
223
+ add_action( 'save_post', array($this,'save_metadata') );
224
+ }
225
+ }
226
+
227
+ /* Adds a XML Sitemap box to the side column */
228
+ public function add_meta_box ()
229
+ {
230
+ $post_types = get_option( 'xmlsf_post_types' );
231
+ if ( !is_array( $post_types ) ) return;
232
+
233
+ foreach ( $post_types as $post_type => $settings ) {
234
+ // Only include metaboxes on post types that are included
235
+ if ( isset( $settings["active"] ) )
236
+ add_meta_box(
237
+ 'xmlsf_section',
238
+ __( 'XML Sitemap', 'xml-sitemap-feed' ),
239
+ array( $this, 'meta_box' ),
240
+ $post_type,
241
+ 'side',
242
+ 'low'
243
+ );
244
+ }
245
+ }
246
+
247
+ public function meta_box( $post )
248
+ {
249
+ // Use nonce for verification
250
+ wp_nonce_field( XMLSF_BASENAME, '_xmlsf_nonce' );
251
+
252
+ // Use get_post_meta to retrieve an existing value from the database and use the value for the form
253
+ $exclude = get_post_meta( $post->ID, '_xmlsf_exclude', true );
254
+ $priority = get_post_meta( $post->ID, '_xmlsf_priority', true );
255
+ $disabled = false;
256
+
257
+ // disable options and (visibly) set excluded to true for private posts
258
+ if ( 'private' == $post->post_status ) {
259
+ $disabled = true;
260
+ $exclude = true;
261
+ }
262
+
263
+ // disable options and (visibly) set priority to 1 for front page
264
+ if ( $post->ID == get_option('page_on_front') ) {
265
+ $disabled = true;
266
+ $exclude = false;
267
+ $priority = '1'; // force priority to 1 for front page
268
+ }
269
+
270
+ $description = sprintf(
271
+ __('Leave empty for automatic Priority as configured on %1$s > %2$s.','xml-sitemap-feed'),
272
+ translate('Settings'),
273
+ '<a href="' . admin_url('options-general.php') . '?page=xmlsf">' . __('XML Sitemap','xml-sitemap-feed') . '</a>'
274
+ );
275
+
276
+ // The actual fields for data entry
277
+ include XMLSF_DIR . '/views/admin/meta-box.php';
278
+ }
279
+
280
+ /* Adds a News Sitemap box to the side column */
281
+ public function add_meta_box_news ()
282
+ {
283
+ $news_tags = get_option('xmlsf_news_tags');
284
+ $news_post_types = !empty($news_tags['post_type']) && is_array($news_tags['post_type']) ? $news_tags['post_type'] : array('post');
285
+
286
+ foreach ( $news_post_types as $post_type ) {
287
+ // Only include metabox on post types that are included
288
+ add_meta_box(
289
+ 'xmlsf_news_section',
290
+ __( 'Google News', 'xml-sitemap-feed' ),
291
+ array($this,'meta_box_news'),
292
+ $post_type,
293
+ 'side'
294
+ );
295
+ }
296
+ }
297
+
298
+ public function meta_box_news( $post )
299
+ {
300
+ // Use nonce for verification
301
+ wp_nonce_field( XMLSF_BASENAME, '_xmlsf_nonce' );
302
+
303
+ // Use get_post_meta to retrieve an existing value from the database and use the value for the form
304
+ $exclude = 'private' == $post->post_status || get_post_meta( $post->ID, '_xmlsf_news_exclude', true );
305
+ $disabled = 'private' == $post->post_status;
306
+
307
+ // The actual fields for data entry
308
+ include XMLSF_DIR . '/views/admin/meta-box-news.php';
309
+ }
310
+
311
+ /* When the post is saved, save our meta data */
312
+ public function save_metadata( $post_id )
313
+ {
314
+ if ( !isset($post_id) )
315
+ $post_id = (int)$_REQUEST['post_ID'];
316
+
317
+ if ( !current_user_can( 'edit_post', $post_id ) || !isset($_POST['_xmlsf_nonce']) || !wp_verify_nonce($_POST['_xmlsf_nonce'], XMLSF_BASENAME) )
318
+ return;
319
+
320
+ // _xmlsf_priority
321
+ if ( empty($_POST['xmlsf_priority']) && '0' !== $_POST['xmlsf_priority'] ) {
322
+ delete_post_meta($post_id, '_xmlsf_priority');
323
+ } else {
324
+ update_post_meta($post_id, '_xmlsf_priority', XMLSF_Admin_Sitemap_Sanitize::priority($_POST['xmlsf_priority']) );
325
+ }
326
+
327
+ // _xmlsf_exclude
328
+ if ( isset($_POST['xmlsf_exclude']) && $_POST['xmlsf_exclude'] != '' ) {
329
+ update_post_meta($post_id, '_xmlsf_exclude', $_POST['xmlsf_exclude']);
330
+ } else {
331
+ delete_post_meta($post_id, '_xmlsf_exclude');
332
+ }
333
+
334
+ // _xmlsf_news_exclude
335
+ if ( isset($_POST['xmlsf_news_exclude']) && $_POST['xmlsf_news_exclude'] != '' ) {
336
+ update_post_meta($post_id, '_xmlsf_news_exclude', $_POST['xmlsf_news_exclude']);
337
+ } else {
338
+ delete_post_meta($post_id, '_xmlsf_news_exclude');
339
+ }
340
+ }
341
+
342
+ /**
343
+ * Clear settings
344
+ */
345
+ public function clear_settings()
346
+ {
347
+ if ( !isset( $_POST['_xmlsf_help_nonce'] ) || !wp_verify_nonce( $_POST['_xmlsf_help_nonce'], XMLSF_BASENAME.'-help' ) ) {
348
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','notice_nonce_fail') );
349
+ return;
350
+ }
351
+
352
+ $defaults = xmlsf()->defaults();
353
+ unset($defaults['sitemaps']);
354
+
355
+ foreach ( $defaults as $option => $settings ) {
356
+ update_option( 'xmlsf_' . $option, $settings );
357
+ }
358
+
359
+ delete_option( 'xmlsf_static_files' );
360
+ delete_option( 'xmlsf_pong' );
361
+
362
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','notice_clear_settings') );
363
+ }
364
+
365
+ /**
366
+ * Delete static sitemap files
367
+ */
368
+
369
+ public function delete_static_files()
370
+ {
371
+ if ( !isset( $_POST['_xmlsf_notice_nonce'] ) || !wp_verify_nonce( $_POST['_xmlsf_notice_nonce'], XMLSF_BASENAME.'-notice' ) ) {
372
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','notice_nonce_fail') );
373
+ return;
374
+ }
375
+
376
+ if ( empty($_POST['xmlsf-delete']) ) {
377
+ return;
378
+ }
379
+
380
+ $allowed_files = array('sitemap.xml','sitemap-news.xml','robots.txt');
381
+
382
+ $this->static_files();
383
+
384
+ $i = '1';
385
+ foreach ( $_POST['xmlsf-delete'] as $name ) {
386
+ if ( !in_array($name,$allowed_files) ) {
387
+ unset(self::$static_files[$name]);
388
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','static_files_not_allowed'), $i );
389
+ continue;
390
+ }
391
+ if ( !isset(self::$static_files[$name]) ) {
392
+ // do nothing and be quiet about it...
393
+ continue;
394
+ }
395
+ if ( unlink(self::$static_files[$name]) ) {
396
+ unset(self::$static_files[$name]);
397
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','static_files_deleted'), $i );
398
+ } else {
399
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','static_files_failed'), $i );
400
+ }
401
+ $i ++;
402
+ }
403
+
404
+ $this->check_static_files();
405
+ }
406
+
407
+ /**
408
+ * Check for conflicting WPSEO settings
409
+ */
410
+ public function verify_wpseo_settings()
411
+ {
412
+ // WP SEO Plugin conflict notice
413
+ if ( is_plugin_active('wordpress-seo/wp-seo.php') ) {
414
+ // check date archive redirection
415
+ $wpseo_titles = get_option( 'wpseo_titles' );
416
+ if ( !empty( $wpseo_titles['disable-date'] ) ) {
417
+ // check is Split by option is set anywhere
418
+ foreach ( (array) get_option( 'xmlsf_post_types' ) as $type => $settings ) {
419
+ if ( is_array( $settings ) && !empty( $settings['archive'] ) ) {
420
+ add_action( 'admin_notices', array( 'XMLSF_Admin_Notices', 'notice_wpseo_date_redirect' ) );
421
+ break;
422
+ }
423
+ }
424
+ }
425
+ // check wpseo sitemap option
426
+ $wpseo = get_option( 'wpseo' );
427
+ $sitemaps = get_option( 'xmlsf_sitemaps' );
428
+ if ( !empty( $wpseo['enable_xml_sitemap'] ) && !empty( $sitemaps['sitemap'] ) ) {
429
+ add_action( 'admin_notices', array( 'XMLSF_Admin_Notices', 'notice_wpseo_sitemap' ) );
430
+ }
431
+ }
432
+ }
433
+
434
+ /**
435
+ * Check for static sitemap files
436
+ */
437
+ public function static_files()
438
+ {
439
+ if ( null === self::$static_files )
440
+ self::$static_files = get_option( 'xmlsf_static_files', array() );
441
+
442
+ if ( !empty(self::$static_files) )
443
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','notice_static_files') );
444
+ }
445
+
446
+ /**
447
+ * Check for static sitemap files
448
+ */
449
+ public function check_static_files()
450
+ {
451
+ $home_path = trailingslashit( get_home_path() );
452
+ $sitemaps = get_option( 'xmlsf_sitemaps' );
453
+ self::$static_files = array();
454
+ $check_for = is_array($sitemaps) ? $sitemaps : array();
455
+ if ( get_option('xmlsf_robots') ) {
456
+ $check_for['robots'] = 'robots.txt';
457
+ }
458
+
459
+ foreach ( $check_for as $name => $pretty ) {
460
+ if ( file_exists( $home_path . $pretty ) ) {
461
+ self::$static_files[$pretty] = $home_path . $pretty;
462
+ }
463
+ }
464
+
465
+ if ( !empty( self::$static_files ) ) {
466
+ update_option( 'xmlsf_static_files', self::$static_files, false );
467
+ } else {
468
+ delete_option( 'xmlsf_static_files' );
469
+ }
470
+ }
471
+
472
+ public function tools_actions()
473
+ {
474
+ if ( isset( $_POST['xmlsf-clear-settings'] ) ) {
475
+ $this->clear_settings();
476
+ }
477
+
478
+ if ( isset( $_POST['xmlsf-delete-submit'] ) ) {
479
+ $this->delete_static_files();
480
+ }
481
+
482
+ if ( isset( $_POST['xmlsf-check-conflicts'] ) ) {
483
+ if ( isset( $_POST['_xmlsf_help_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_help_nonce'], XMLSF_BASENAME.'-help' ) ) {
484
+ // reset ignored warnings
485
+ delete_user_meta( get_current_user_id(), 'xmlsf_dismissed' );
486
+
487
+ $this->check_static_files();
488
+ if ( empty( self::$static_files ) )
489
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','static_files_none_found') );
490
+
491
+ $this->verify_wpseo_settings();
492
+
493
+ } else {
494
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','notice_nonce_fail') );
495
+ }
496
+ }
497
+ }
498
+
499
+ public function notices_actions()
500
+ {
501
+ if ( isset( $_POST['xmlsf-dismiss'] ) ) {
502
+ if ( isset( $_POST['_xmlsf_notice_nonce'] ) && wp_verify_nonce( $_POST['_xmlsf_notice_nonce'], XMLSF_BASENAME.'-notice' ) ) {
503
+ add_user_meta( get_current_user_id(), 'xmlsf_dismissed', $_POST['xmlsf-dismiss'], false );
504
+ } else {
505
+ add_action( 'admin_notices', array('XMLSF_Admin_Notices','notice_nonce_fail') );
506
+ }
507
+ }
508
+ }
509
+
510
+ public function transients_actions()
511
+ {
512
+ // CATCH TRANSIENT for flushing rewrite rules after the sitemaps setting has changed
513
+ if ( delete_transient('xmlsf_flush_rewrite_rules') ) {
514
+ flush_rewrite_rules();
515
+ if ( defined('WP_DEBUG') && WP_DEBUG == true ) {
516
+ error_log('Rewrite rules flushed by XML Sitemap Feeds.');
517
+ }
518
+ }
519
+
520
+ // CATCH TRANSIENT for static file check
521
+ if ( delete_transient('xmlsf_check_static_files') ) {
522
+ $this->check_static_files();
523
+ }
524
+ }
525
+ }
526
+
527
+ new XMLSF_Admin_Controller();
controllers/admin/notices.php ADDED
@@ -0,0 +1,58 @@
1
+ <?php
2
+
3
+ class XMLSF_Admin_Notices extends XMLSF_Admin_Controller
4
+ {
5
+ function __construct() {}
6
+
7
+ public static function notice_clear_settings()
8
+ {
9
+ include XMLSF_DIR . '/views/admin/notice-cleared.php';
10
+ }
11
+
12
+ public static function static_files_deleted()
13
+ {
14
+ include XMLSF_DIR . '/views/admin/notice-deleted.php';
15
+ }
16
+
17
+ public static function static_files_not_allowed()
18
+ {
19
+ include XMLSF_DIR . '/views/admin/notice-not-allowed.php';
20
+ }
21
+
22
+ public static function static_files_none_found()
23
+ {
24
+ include XMLSF_DIR . '/views/admin/notice-none-found.php';
25
+ }
26
+
27
+ public static function static_files_failed()
28
+ {
29
+ include XMLSF_DIR . '/views/admin/notice-failed.php';
30
+ }
31
+
32
+ public static function notice_nonce_fail()
33
+ {
34
+ include XMLSF_DIR . '/views/admin/notice-nonce-error.php';
35
+ }
36
+
37
+ public static function notice_static_files()
38
+ {
39
+ if ( !in_array( 'static_files', get_user_meta( get_current_user_id(), 'xmlsf_dismissed' ) ) ) {
40
+ if ( $number = count(parent::$static_files) )
41
+ include XMLSF_DIR . '/views/admin/notice-static-files.php';
42
+ }
43
+ }
44
+
45
+ public static function notice_wpseo_date_redirect()
46
+ {
47
+ if ( !in_array( 'date_redirect', get_user_meta( get_current_user_id(), 'xmlsf_dismissed' ) ) ) {
48
+ include XMLSF_DIR . '/views/admin/notice-wpseo-date-redirect.php';
49
+ }
50
+ }
51
+
52
+ public static function notice_wpseo_sitemap()
53
+ {
54
+ if ( !in_array( 'wpseo_sitemap', get_user_meta( get_current_user_id(), 'xmlsf_dismissed' ) ) ) {
55
+ include XMLSF_DIR . '/views/admin/notice-wpseo-sitemap.php';
56
+ }
57
+ }
58
+ }
controllers/admin/sitemap-news.php ADDED
@@ -0,0 +1,212 @@
1
+ <?php
2
+
3
+ class XMLSF_Admin_Sitemap_News
4
+ {
5
+ /**
6
+ * Holds the values to be used in the fields callbacks
7
+ */
8
+ private $screen_id;
9
+
10
+ /**
11
+ * Holds the values to be used in the fields callbacks
12
+ */
13
+ private $options;
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, 'register_settings' ) );
22
+ }
23
+
24
+ /**
25
+ * Add options page
26
+ */
27
+ public function add_settings_page()
28
+ {
29
+ // This page will be under "Settings"
30
+ $this->screen_id = add_options_page(
31
+ __('Google News Sitemap','xml-sitemap-feed'),
32
+ __('Google News','xml-sitemap-feed'),
33
+ 'manage_options',
34
+ 'xmlsf-news',
35
+ array( $this, 'settings_page' )
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Options page callback
41
+ */
42
+ public function settings_page()
43
+ {
44
+ $this->options = get_option( 'xmlsf_news_tags', array() );
45
+
46
+ // SECTION
47
+ add_settings_section( 'news_sitemap_section', /* '<a name="xmlnf"></a>'.__('Google News Sitemap','xml-sitemap-feed') */ '', '', 'xmlsf-news' );
48
+
49
+ // SETTINGS
50
+ add_settings_field( 'xmlsf_news_name', '<label for="xmlsf_news_name">'.__('Publication name','xml-sitemap-feed').'</label>', array($this,'name_field'), 'xmlsf-news', 'news_sitemap_section' );
51
+ add_settings_field( 'xmlsf_news_post_type', __('Post type','xml-sitemap-feed'), array($this,'post_type_field'), 'xmlsf-news', 'news_sitemap_section' );
52
+
53
+ global $wp_taxonomies;
54
+ $news_post_type = isset( $this->options['post_type'] ) && !empty( $this->options['post_type'] ) ? (array) $this->options['post_type'] : array('post');
55
+ $post_types = ( isset( $wp_taxonomies['category'] ) ) ? $wp_taxonomies['category']->object_type : array();
56
+
57
+ foreach ( $news_post_type as $post_type ) {
58
+ if ( in_array( $post_type, $post_types ) ) {
59
+ add_settings_field( 'xmlsf_news_categories', translate('Categories'), array($this,'categories_field'), 'xmlsf-news', 'news_sitemap_section' );
60
+ break;
61
+ }
62
+ }
63
+
64
+ add_settings_field( 'xmlsf_news_image', translate('Images'), array( $this,'image_field' ), 'xmlsf-news', 'news_sitemap_section' );
65
+ add_settings_field( 'xmlsf_news_labels', __('Source labels', 'xml-sitemap-feed' ), array($this,'labels_field'), 'xmlsf-news', 'news_sitemap_section' );
66
+
67
+ $options = (array) get_option( 'xmlsf_sitemaps' );
68
+ $url = trailingslashit(get_bloginfo('url')) . ( xmlsf()->plain_permalinks() ? '?feed=sitemap-news' : $options['sitemap-news'] );
69
+
70
+ include XMLSF_DIR . '/views/admin/page-sitemap-news.php';
71
+ }
72
+
73
+ /**
74
+ * Register and add settings
75
+ */
76
+ public function register_settings()
77
+ {
78
+ // Help tab
79
+ add_action( 'load-'.$this->screen_id, array($this,'help_tab') );
80
+
81
+ register_setting( 'xmlsf-news', 'xmlsf_news_tags', array('XMLSF_Admin_Sitemap_News_Sanitize','news_tags_settings') );
82
+ }
83
+
84
+ /**
85
+ * GOOGLE NEWS SITEMAP SECTION
86
+ */
87
+
88
+ public function help_tab() {
89
+ $screen = get_current_screen();
90
+
91
+ ob_start();
92
+ include XMLSF_DIR . '/views/admin/help-tab-news.php';
93
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
94
+ $content = ob_get_clean();
95
+
96
+ $screen->add_help_tab( array(
97
+ 'id' => 'sitemap-news-settings',
98
+ 'title' => __( 'Google News Sitemap', 'xml-sitemap-feed' ),
99
+ 'content' => $content
100
+ ) );
101
+
102
+ ob_start();
103
+ include XMLSF_DIR . '/views/admin/help-tab-news-name.php';
104
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
105
+ $content = ob_get_clean();
106
+
107
+ $screen->add_help_tab( array(
108
+ 'id' => 'sitemap-news-name',
109
+ 'title' => __( 'Publication name', 'xml-sitemap-feed' ),
110
+ 'content' => $content
111
+ ) );
112
+
113
+ ob_start();
114
+ include XMLSF_DIR . '/views/admin/help-tab-news-images.php';
115
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
116
+ $content = ob_get_clean();
117
+
118
+ $screen->add_help_tab( array(
119
+ 'id' => 'sitemap-news-images',
120
+ 'title' => translate('Images'),
121
+ 'content' => $content
122
+ ) );
123
+
124
+ ob_start();
125
+ include XMLSF_DIR . '/views/admin/help-tab-news-categories.php';
126
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
127
+ $content = ob_get_clean();
128
+
129
+ $screen->add_help_tab( array(
130
+ 'id' => 'sitemap-news-categories',
131
+ 'title' => translate('Categories'),
132
+ 'content' => $content
133
+ ) );
134
+
135
+ ob_start();
136
+ include XMLSF_DIR . '/views/admin/help-tab-news-labels.php';
137
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
138
+ $content = ob_get_clean();
139
+
140
+ $screen->add_help_tab( array(
141
+ 'id' => 'sitemap-news-labels',
142
+ 'title' => __( 'Source labels', 'xml-sitemap-feed' ),
143
+ 'content' => $content
144
+ ) );
145
+
146
+ ob_start();
147
+ include XMLSF_DIR . '/views/admin/help-tab-news-sidebar.php';
148
+ $content = ob_get_clean();
149
+
150
+ $screen->set_help_sidebar( $content );
151
+ }
152
+
153
+ public function name_field()
154
+ {
155
+ $name = !empty($this->options['name']) ? $this->options['name'] : '';
156
+
157
+ // The actual fields for data entry
158
+ include XMLSF_DIR . '/views/admin/field-news-name.php';
159
+ }
160
+
161
+ public function post_type_field()
162
+ {
163
+ global $wp_taxonomies;
164
+ $post_types = apply_filters( 'xmlsf_news_post_types', get_post_types( array( 'public' => true ) /*,'objects'*/) );
165
+
166
+ if ( is_array($post_types) && !empty($post_types) ) :
167
+
168
+ $news_post_type = isset($this->options['post_type']) && !empty( $this->options['post_type'] ) ? (array) $this->options['post_type'] : array('post');
169
+
170
+ $type = ( 1 == count( $news_post_type ) ) ? 'radio' : 'checkbox';
171
+
172
+ $allowed = ( !empty( $this->options['categories'] ) && isset( $wp_taxonomies['category'] ) ) ? $wp_taxonomies['category']->object_type : $post_types;
173
+
174
+ $do_warning = !empty( $this->options['categories'] ) && count($post_types) > 1 ? true : false;
175
+
176
+ // The actual fields for data entry
177
+ include XMLSF_DIR . '/views/admin/field-news-post-type.php';
178
+
179
+ else :
180
+
181
+ echo '<p class="description warning">'.__('There appear to be no post types available.','xml-sitemap-feed').'</p>';
182
+
183
+ endif;
184
+ }
185
+
186
+ public function categories_field()
187
+ {
188
+ $selected_categories = isset( $this->options['categories'] ) && is_array( $this->options['categories'] ) ? $this->options['categories'] : array();
189
+
190
+ $cat_list = str_replace('name="post_category[]"','name="'.'xmlsf_news_tags[categories][]"', wp_terms_checklist( null, array( 'taxonomy' => 'category', 'selected_cats' => $selected_categories, 'echo' => false ) ) );
191
+
192
+ // The actual fields for data entry
193
+ include XMLSF_DIR . '/views/admin/field-news-categories.php';
194
+ }
195
+
196
+ public function image_field() {
197
+ $options = get_option( 'xmlsf_news_tags' );
198
+
199
+ $image = !empty( $options['image'] ) ? $options['image'] : '';
200
+
201
+ // The actual fields for data entry
202
+ include XMLSF_DIR . '/views/admin/field-news-image.php';
203
+ }
204
+
205
+ public function labels_field() {
206
+ // The actual fields for data entry
207
+ include XMLSF_DIR . '/views/admin/field-news-labels.php';
208
+ }
209
+
210
+ }
211
+
212
+ new XMLSF_Admin_Sitemap_News();
controllers/admin/sitemap.php ADDED
@@ -0,0 +1,224 @@
1
+ <?php
2
+
3
+ class XMLSF_Admin_Sitemap
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, 'register_settings' ) );
22
+ }
23
+
24
+ /**
25
+ * Gets public taxonomies
26
+ */
27
+ public function public_taxonomies()
28
+ {
29
+ if ( !isset( $this->public_taxonomies ) ) {
30
+ include XMLSF_DIR . '/models/public/sitemap.php';
31
+ $this->public_taxonomies = xmlsf_public_taxonomies();
32
+ }
33
+
34
+ return $this->public_taxonomies;
35
+ }
36
+
37
+ /**
38
+ * Add options page
39
+ */
40
+ public function add_settings_page()
41
+ {
42
+ // This page will be under "Settings"
43
+ $this->screen_id = add_options_page(
44
+ __('XML Sitemap','xml-sitemap-feed'),
45
+ __('XML Sitemap','xml-sitemap-feed'),
46
+ 'manage_options',
47
+ 'xmlsf',
48
+ array( $this, 'settings_page' )
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Options page callback
54
+ */
55
+ public function settings_page()
56
+ {
57
+ // SECTIONS & SETTINGS
58
+ // post_types
59
+ add_settings_section( 'xml_sitemap_post_types_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_post_types' );
60
+ $post_types = apply_filters( 'xmlsf_post_types', get_post_types( array( 'public' => true ) /*,'objects'*/) );
61
+
62
+ if ( is_array($post_types) && !empty($post_types) ) :
63
+ foreach ( $post_types as $post_type ) {
64
+ $obj = get_post_type_object( $post_type );
65
+ if ( !is_object( $obj ) )
66
+ continue;
67
+ add_settings_field( 'xmlsf_post_type_'.$obj->name, $obj->label, array($this,'post_types_settings_field'), 'xmlsf_post_types', 'xml_sitemap_post_types_section', $post_type );
68
+ // Note: (ab)using section name parameter to pass post type name
69
+ }
70
+ endif;
71
+
72
+ // taxonomies
73
+ add_settings_section( 'xml_sitemap_taxonomies_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_taxonomies' );
74
+ add_settings_field( 'xmlsf_taxonomy_settings', translate('General'), array($this,'taxonomy_settings_field'), 'xmlsf_taxonomies', 'xml_sitemap_taxonomies_section' );
75
+ $taxonomy_settings = get_option( 'xmlsf_taxonomy_settings' );
76
+ if ( !empty( $taxonomy_settings['active'] ) && get_option( 'xmlsf_taxonomies' ) )
77
+ add_settings_field( 'xmlsf_taxonomies', __('Include taxonomies','xml-sitemap-feed'), array($this,'taxonomies_field'), 'xmlsf_taxonomies', 'xml_sitemap_taxonomies_section' );
78
+
79
+ add_settings_section( 'xml_sitemap_advanced_section', /*'<a name="xmlsf"></a>'.__('XML Sitemap','xml-sitemap-feed')*/ '', '', 'xmlsf_advanced' );
80
+ // custom urls
81
+ add_settings_field( 'xmlsf_urls', __('External web pages','xml-sitemap-feed'), array($this,'urls_settings_field'), 'xmlsf_advanced', 'xml_sitemap_advanced_section' );
82
+ // custom sitemaps
83
+ add_settings_field( 'xmlsf_custom_sitemaps', __('External XML Sitemaps','xml-sitemap-feed'), array($this,'custom_sitemaps_settings_field'), 'xmlsf_advanced', 'xml_sitemap_advanced_section' );
84
+
85
+ $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'post_types';
86
+
87
+ $options = (array) get_option( 'xmlsf_sitemaps' );
88
+ $url = trailingslashit(get_bloginfo('url')) . ( xmlsf()->plain_permalinks() ? '?feed=sitemap' : $options['sitemap'] );
89
+
90
+ include XMLSF_DIR . '/views/admin/page-sitemap.php';
91
+ }
92
+
93
+ /**
94
+ * Register and add settings
95
+ */
96
+ public function register_settings()
97
+ {
98
+ // Help tab
99
+ add_action( 'load-'.$this->screen_id, array($this,'help_tab') );
100
+
101
+ // post_types
102
+ register_setting( 'xmlsf_post_types', 'xmlsf_post_types', array('XMLSF_Admin_Sitemap_Sanitize','post_types_settings') );
103
+ // taxonomies
104
+ register_setting( 'xmlsf_taxonomies', 'xmlsf_taxonomy_settings', array('XMLSF_Admin_Sitemap_Sanitize','taxonomy_settings') );
105
+ register_setting( 'xmlsf_taxonomies', 'xmlsf_taxonomies', array('XMLSF_Admin_Sitemap_Sanitize','taxonomies') );
106
+ // custom urls
107
+ register_setting( 'xmlsf_advanced', 'xmlsf_urls', array('XMLSF_Admin_Sitemap_Sanitize','custom_urls_settings') );
108
+ // custom sitemaps
109
+ register_setting( 'xmlsf_advanced', 'xmlsf_custom_sitemaps', array('XMLSF_Admin_Sitemap_Sanitize','custom_sitemaps_settings') );
110
+ }
111
+
112
+ /**
113
+ * XML SITEMAP SECTION
114
+ */
115
+
116
+ public function help_tab()
117
+ {
118
+ $screen = get_current_screen();
119
+
120
+ ob_start();
121
+ include XMLSF_DIR . '/views/admin/help-tab-sitemaps.php';
122
+ include XMLSF_DIR . '/views/admin/help-tab-support.php';
123
+ $content = ob_get_clean();
124
+
125
+ $screen->add_help_tab( array(
126
+ 'id' => 'sitemap-settings',
127
+ 'title' => __( 'XML Sitemap', 'xml-sitemap-feed' ),
128
+ 'content' => $content
129
+ ) );
130
+
131
+ ob_start();
132
+ include XMLSF_DIR . '/views/admin/help-tab-post-types.php';
133
+ $content = ob_get_clean();
134
+
135
+ $screen->add_help_tab( array(
136
+ 'id' => 'sitemap-settings-post-types',
137
+ 'title' => __( 'Post types', 'xml-sitemap-feed' ),
138
+ 'content' => $content
139
+ ) );
140
+
141
+ ob_start();
142
+ include XMLSF_DIR . '/views/admin/help-tab-taxonomies.php';
143
+ $content = ob_get_clean();
144
+
145
+ $screen->add_help_tab( array(
146
+ 'id' => 'sitemap-settings-taxonomies',
147
+ 'title' => __( 'Taxonomies', 'xml-sitemap-feed' ),
148
+ 'content' => $content,
149
+ ) );
150
+
151
+ ob_start();
152
+ include XMLSF_DIR . '/views/admin/help-tab-advanced.php';
153
+ $content = ob_get_clean();
154
+
155
+ $screen->add_help_tab( array(
156
+ 'id' => 'sitemap-settings-advanced',
157
+ 'title' => translate( 'Advanced' ),
158
+ 'content' => $content
159
+ ) );
160
+
161
+ ob_start();
162
+ include XMLSF_DIR . '/views/admin/help-tab-sidebar.php';
163
+ $content = ob_get_clean();
164
+
165
+ $screen->set_help_sidebar( $content );
166
+ }
167
+
168
+ public function post_types_settings_field( $post_type )
169
+ {
170
+ // post type slug passed as section name
171
+ $obj = get_post_type_object( $post_type );
172
+
173
+ $count = wp_count_posts( $obj->name );
174
+
175
+ $options = get_option('xmlsf_post_types');
176
+
177
+ // The actual fields for data entry
178
+ include XMLSF_DIR . '/views/admin/field-sitemap-post-type.php';
179
+ }
180
+
181
+ public function taxonomy_settings_field()
182
+ {
183
+ $taxonomies = get_option( 'xmlsf_taxonomies' );
184
+ $taxonomy_settings = get_option( 'xmlsf_taxonomy_settings' );
185
+
186
+ // The actual fields for data entry
187
+ include XMLSF_DIR . '/views/admin/field-sitemap-taxonomy-settings.php';
188
+ }
189
+
190
+ public function taxonomies_field()
191
+ {
192
+ $taxonomies = get_option( 'xmlsf_taxonomies' );
193
+
194
+ // The actual fields for data entry
195
+ include XMLSF_DIR . '/views/admin/field-sitemap-taxonomies.php';
196
+ }
197
+
198
+ public function custom_sitemaps_settings_field()
199
+ {
200
+ $custom_sitemaps = get_option( 'xmlsf_custom_sitemaps' );
201
+ $lines = is_array($custom_sitemaps) ? implode( PHP_EOL, $custom_sitemaps ) : $custom_sitemaps;
202
+
203
+ // The actual fields for data entry
204
+ include XMLSF_DIR . '/views/admin/field-sitemap-custom.php';
205
+ }
206
+
207
+ public function urls_settings_field() {
208
+ $urls = get_option('xmlsf_urls');
209
+ $lines = array();
210
+
211
+ if( is_array($urls) && !empty($urls) ) {
212
+ foreach( $urls as $arr ) {
213
+ if( is_array($arr) )
214
+ $lines[] = implode( " ", $arr );
215
+ }
216
+ }
217
+
218
+ // The actual fields for data entry
219
+ include XMLSF_DIR . '/views/admin/field-sitemap-urls.php';
220
+ }
221
+
222
+ }
223
+
224
+ new XMLSF_Admin_Sitemap();
controllers/global.php ADDED
@@ -0,0 +1,238 @@
1
+ <?php
2
+
3
+ /* --------------------------
4
+ * INITIALIZE
5
+ * -------------------------- */
6
+
7
+ function xmlsf_init() {
8
+
9
+ xmlsf_maybe_upgrade();
10
+
11
+ if ( is_admin() ) {
12
+ require XMLSF_DIR . '/controllers/admin/main.php';
13
+ }
14
+
15
+ // include sitemaps if any enabled
16
+ if ( get_option( 'xmlsf_sitemaps' ) ) {
17
+
18
+ // include main controller functions
19
+ require XMLSF_DIR . '/controllers/main.php';
20
+
21
+ add_action( 'clean_post_cache', 'xmlsf_clean_post_cache', 99, 2 );
22
+
23
+ // PINGING
24
+ add_action( 'transition_post_status', 'xmlsf_do_pings', 10, 3 );
25
+
26
+ // Update term meta lastmod date
27
+ add_action( 'transition_post_status', 'update_term_modified_meta', 10, 3 );
28
+
29
+ // add rewrite rules
30
+ xmlsf_rewrite_rules();
31
+
32
+ // include main model functions
33
+ require XMLSF_DIR . '/models/main.php';
34
+
35
+ // MAIN REQUEST filter
36
+ add_filter( 'request', 'xmlsf_filter_request', 1 );
37
+
38
+ // force remove url trailing slash
39
+ add_filter( 'user_trailingslashit', 'xmlsf_untrailingslash' );
40
+
41
+ // common sitemap element filters
42
+ add_filter( 'the_title_xmlsitemap', 'strip_tags' );
43
+ add_filter( 'the_title_xmlsitemap', 'ent2ncr', 8 );
44
+ add_filter( 'the_title_xmlsitemap', 'esc_html' );
45
+
46
+ add_filter( 'xmlsf_news_post_types', 'xmlsf_news_filter_post_types' );
47
+ add_filter( 'xmlsf_post_types', 'xmlsf_filter_post_types' );
48
+
49
+ // include and instantiate class
50
+ xmlsf();
51
+ }
52
+
53
+ // add robots.txt filter
54
+ add_filter( 'robots_txt', 'xmlsf_robots_txt', 9 );
55
+ }
56
+
57
+ /**
58
+ * Upgrade/install, maybe...
59
+ *
60
+ * @since 5.0
61
+ * @return void
62
+ */
63
+ function xmlsf_maybe_upgrade() {
64
+ $db_version = get_option( 'xmlsf_version', 0 );
65
+
66
+ if ( version_compare( XMLSF_VERSION, $db_version, '=' ) ) {
67
+ return;
68
+ }
69
+
70
+ // don't flush rules from init as Polylang chokes on that
71
+ // just remove the db option and let WP regenerate them when ready...
72
+ delete_option( 'rewrite_rules' );
73
+ // ... but make sure rules are regenerated when admin is visited.
74
+ set_transient( 'xmlsf_flush_rewrite_rules', '' );
75
+ // static files checking
76
+ set_transient( 'xmlsf_check_static_files', '' );
77
+
78
+ // upgrade or install
79
+ if ( $db_version ) :
80
+
81
+ if ( version_compare( '4.4', $db_version, '>' ) ) {
82
+ // remove robots.txt rules blocking stylesheets
83
+ if ( $robot_rules = get_option( 'xmlsf_robots' ) ) {
84
+ $robot_rules = str_replace( array('Disallow: */wp-content/','Allow: */wp-content/uploads/'), '', $robot_rules );
85
+ delete_option( 'xmlsf_robots' );
86
+ add_option( 'xmlsf_robots', $robot_rules, null, false );
87
+ }
88
+
89
+ // make sure custom sitemaps is an array
90
+ $urls = get_option('xmlsf_custom_sitemaps');
91
+ if ( !is_array($urls) ) {
92
+ $urls = explode( PHP_EOL, $urls );
93
+ update_option('xmlsf_custom_sitemaps',$urls);
94
+ }
95
+
96
+ // register location taxonomies then delete all terms
97
+ register_taxonomy( 'gn-location-3', null );
98
+ $terms = get_terms( 'gn-location-3', array('hide_empty' => false) );
99
+ foreach ( $terms as $term ) {
100
+ wp_delete_term( $term->term_id, 'gn-location-3' );
101
+ }
102
+
103
+ register_taxonomy( 'gn-location-2', null );
104
+ $terms = get_terms( 'gn-location-2',array( 'hide_empty' => false ) );
105
+ foreach ( $terms as $term ) {
106
+ wp_delete_term( $term->term_id, 'gn-location-2' );
107
+ }
108
+
109
+ register_taxonomy( 'gn-location-1', null );
110
+ $terms = get_terms( 'gn-location-1',array( 'hide_empty' => false ) );
111
+ foreach ( $terms as $term ) {
112
+ wp_delete_term( $term->term_id, 'gn-location-1' );
113
+ }
114
+ }
115
+
116
+ if ( version_compare( '5.0.1', $db_version, '>' ) ) {
117
+ // delete all taxonomy terms
118
+ register_taxonomy( 'gn-genre', null );
119
+
120
+ $terms = get_terms( 'gn-genre', array( 'hide_empty' => false ) );
121
+
122
+ if ( is_array( $terms ) )
123
+ foreach ( $terms as $term )
124
+ wp_delete_term( $term->term_id, 'gn-genre' );
125
+
126
+ // new taxonomy settings
127
+ $taxonomies = get_option( 'xmlsf_taxonomies' );
128
+ if ( empty($taxonomies) ) {
129
+ $active = '';
130
+ } else {
131
+ $available = 0;
132
+ $checked = count($taxonomies);
133
+ foreach ( (array) get_option( 'xmlsf_post_types' ) as $post_type => $settings ) {
134
+ if ( empty($settings['active']) ) continue;
135
+ $taxonomies = get_object_taxonomies( $post_type, 'objects' );
136
+ // check each tax public flag and term count and append name to array
137
+ foreach ( $taxonomies as $taxonomy ) {
138
+ if ( !empty( $taxonomy->public ) && !in_array( $taxonomy->name, xmlsf()->disabled_taxonomies() ) )
139
+ $available++;
140
+ }
141
+ }
142
+ if ( $checked == $available )
143
+ update_option( 'xmlsf_taxonomies', '' );
144
+ $active = '1';
145
+ }
146
+ $taxonomy_settings = array(
147
+ 'active' => $active,
148
+ 'priority' => '0.3',
149
+ 'dynamic_priority' => '1',
150
+ 'term_limit' => '5000'
151
+ );
152
+ add_option( 'xmlsf_taxonomy_settings', $taxonomy_settings );
153
+
154
+ // update ping option
155
+ $ping = get_option( 'xmlsf_ping' );
156
+ $new = array( 'google', 'bing' );
157
+ if ( is_array($ping) ) {
158
+ foreach ( $ping as $key => $value ) {
159
+ if ( is_array($value) && empty( $value['active'] ) && isset( $new[$key] ) ) {
160
+ unset( $new[$key] );
161
+ }
162
+ }
163
+ }
164
+ update_option( 'xmlsf_ping', $new, false );
165
+
166
+ // make sure no pong option remains
167
+ delete_option( 'xmlsf_pong');
168
+
169
+ // update or create robots option
170
+ $robots = get_option( 'xmlsf_robots', '' );
171
+ delete_option( 'xmlsf_robots');
172
+ add_option( 'xmlsf_robots', $robots, null, false );
173
+ }
174
+
175
+ if ( version_compare( '5.0.2', $db_version, '>' ) ) {
176
+ $defaults = xmlsf()->defaults();
177
+
178
+ foreach ( $defaults as $option => $default ) {
179
+ if ( get_option( 'xmlsf_'.$option ) ) continue;
180
+ if ( in_array( $option, array('ping','robots') ) )
181
+ add_option( 'xmlsf_'.$option, $default, null, false );
182
+ else
183
+ add_option( 'xmlsf_'.$option, $default );
184
+ }
185
+
186
+ delete_option( 'xmlsf_version' );
187
+ }
188
+
189
+ if ( defined('WP_DEBUG') && WP_DEBUG ) {
190
+ error_log('XML Sitemap Feeds upgraded from '.$db_version.' to '.XMLSF_VERSION);
191
+ };
192
+
193
+ else :
194
+
195
+ $defaults = xmlsf()->defaults();
196
+
197
+ foreach ( $defaults as $option => $default ) {
198
+ delete_option( 'xmlsf_'.$option );
199
+ if ( in_array( $option, array('ping','robots') ) )
200
+ add_option( 'xmlsf_'.$option, $default, null, false );
201
+ else
202
+ add_option( 'xmlsf_'.$option, $default );
203
+ }
204
+
205
+ if ( defined('WP_DEBUG') && WP_DEBUG ) {
206
+ error_log('XML Sitemap Feeds version '.XMLSF_VERSION.' installed.');
207
+ };
208
+
209
+ endif;
210
+
211
+ update_option( 'xmlsf_version', XMLSF_VERSION );
212
+ }
213
+
214
+ /**
215
+ * Plugin activation
216
+ *
217
+ * @since 5.0
218
+ * @return void
219
+ */
220
+
221
+ function xmlsf_activate() {
222
+ delete_option( 'rewrite_rules' );
223
+ set_transient( 'xmlsf_flush_rewrite_rules', '' );
224
+ set_transient( 'xmlsf_check_static_files', '' );
225
+ }
226
+
227
+ /**
228
+ * Plugin de-activation
229
+ *
230
+ * @since 5.0
231
+ * @return void
232
+ */
233
+
234
+ function xmlsf_deactivate() {
235
+ delete_transient( 'xmlsf_flush_rewrite_rules' );
236
+ delete_transient( 'xmlsf_check_static_files' );
237
+ flush_rewrite_rules();
238
+ }
controllers/main.php ADDED
@@ -0,0 +1,178 @@
1
+ <?php
2
+
3
+ /**
4
+ * Add sitemap rewrite rules
5
+ *
6
+ * @uses object $wp_rewrite
7
+ *
8
+ * @return void
9
+ */
10
+ function xmlsf_rewrite_rules() {
11
+ global $wp_rewrite;
12
+
13
+ $sitemaps = get_option( 'xmlsf_sitemaps' );
14
+
15
+ if ( isset($sitemaps['sitemap']) ) {
16
+ /* One rule to ring them all */
17
+ add_rewrite_rule('sitemap([a-z0-9_-]+)?\.([0-9]+)?\.?xml#x27;, $wp_rewrite->index . '?feed=sitemap$matches[1]&m=$matches[2]', 'top');
18
+ }
19
+
20
+ if( isset($sitemaps['sitemap-news']) ) {
21
+ add_rewrite_rule('sitemap-news\.xml#x27;, $wp_rewrite->index . '?feed=sitemap-news', 'top');
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Cache delete on clean_post_cache
27
+ *
28
+ * @param $post_ID
29
+ * @param $post
30
+ */
31
+ function xmlsf_clean_post_cache( $post_ID, $post ) {
32
+ // are we moving the post in or out of published status?
33
+ wp_cache_delete('xmlsf_get_archives', 'general');
34
+
35
+ // TODO get year / month here to delete specific keys too !!!!
36
+ $m = mysql2date('Ym',$post->post_date_gmt, false);
37
+ $y = substr($m, 0, 4);
38
+
39
+ // clear possible last post modified cache keys
40
+ wp_cache_delete( 'lastpostmodified:gmt', 'timeinfo' ); // should be handled by WP core?
41
+ wp_cache_delete( 'lastpostmodified'.$y.':gmt', 'timeinfo' );
42
+ wp_cache_delete( 'lastpostmodified'.$m.':gmt', 'timeinfo' );
43
+ wp_cache_delete( 'lastpostmodified'.$y.':gmt:'.$post->post_type, 'timeinfo' );
44
+ wp_cache_delete( 'lastpostmodified'.$m.':gmt:'.$post->post_type, 'timeinfo' );
45
+
46
+ // clear possible last post date cache keys
47
+ wp_cache_delete( 'lastpostdate:gmt', 'timeinfo' );
48
+ wp_cache_delete( 'lastpostdate:gmt:'.$post->post_type, 'timeinfo' );
49
+
50
+ // clear possible fist post date cache keys
51
+ wp_cache_delete( 'firstpostdate:gmt', 'timeinfo' );
52
+ wp_cache_delete( 'firstpostdate:gmt:'.$post->post_type, 'timeinfo' );
53
+ }
54
+
55
+ /**
56
+ * Do pings, hooked to transition post status
57
+ *
58
+ * @param $new_status
59
+ * @param $old_status
60
+ * @param $post
61
+ */
62
+ function xmlsf_do_pings( $new_status, $old_status, $post ) {
63
+ // are we publishing?
64
+ if ( $old_status == 'publish' || $new_status != 'publish' )
65
+ return;
66
+
67
+ $sitemaps = get_option( 'xmlsf_sitemaps' );
68
+ $ping = get_option( 'xmlsf_ping' );
69
+
70
+ if ( !is_array($sitemaps) || empty($sitemaps) || !is_array($ping) || empty($ping) )
71
+ return;
72
+
73
+ if ( isset( $sitemaps['sitemap-news'] ) ) {
74
+
75
+ // check if we've got a post type that is included in our news sitemap
76
+ $news_tags = get_option('xmlsf_news_tags');
77
+ if ( !empty($news_tags['post_type']) && is_array($news_tags['post_type']) && in_array($post->post_type,$news_tags['post_type']) ) {
78
+
79
+ // Google ?
80
+ if ( in_array( 'google', $ping ) ) {
81
+ // check if we did not ping already within the last hour
82
+ if ( false === get_transient('xmlsf_ping_google_sitemap_news') ) {
83
+ // Ping !
84
+ $uri = add_query_arg( 'sitemap', urlencode( trailingslashit( get_bloginfo( 'url' ) ) . $sitemaps['sitemap-news'] ), 'https://www.google.com/ping' );
85
+ $response = wp_remote_request( $uri );
86
+ $code = wp_remote_retrieve_response_code( $response );
87
+ if ( 200 === $code ) {
88
+ set_transient( 'xmlsf_ping_google_sitemap_news', $sitemaps['sitemap-news'], 5 * MINUTE_IN_SECONDS );
89
+ } elseif ( defined('WP_DEBUG') && WP_DEBUG == true ) {
90
+ error_log( 'Ping to '. $uri .' failed with response code: ' . $code );
91
+ }
92
+ } elseif ( defined('WP_DEBUG') && WP_DEBUG == true ) {
93
+ error_log( 'Ping skipped: previous News Sitemap was sent to Google less than ' . 5 * MINUTE_IN_SECONDS . ' seconds ago.' );
94
+ }
95
+ }
96
+
97
+ // Bing ?
98
+ // nope...
99
+ }
100
+ }
101
+
102
+ if ( isset( $sitemaps['sitemap'] ) ) {
103
+
104
+ // check if we've got a post type that is included in our sitemap
105
+ $post_types = get_option( 'xmlsf_post_types' );
106
+ if ( is_array( $post_types ) && array_key_exists( $post->post_type, $post_types ) ) {
107
+
108
+ // Google ?
109
+ if ( in_array( 'google', $ping ) ) {
110
+ // check if we did not ping already within the last hour
111
+ if ( false === get_transient('xmlsf_ping_google_sitemap') ) {
112
+ // Ping !
113
+ $uri = add_query_arg( 'sitemap', urlencode( trailingslashit( get_bloginfo( 'url' ) ) . $sitemaps['sitemap'] ), 'https://www.google.com/ping' );
114
+ $response = wp_remote_request( $uri );
115
+ $code = wp_remote_retrieve_response_code( $response );
116
+ if ( 200 === $code ) {
117
+ set_transient( 'xmlsf_ping_google_sitemap', $sitemaps['sitemap'], HOUR_IN_SECONDS );
118
+ } elseif ( defined('WP_DEBUG') && WP_DEBUG == true ) {
119
+ error_log( 'Ping to '. $uri .' failed with response code: ' . $code );
120
+ }
121
+ } elseif ( defined('WP_DEBUG') && WP_DEBUG == true ) {
122
+ error_log( 'Ping skipped: previous XML Sitemap was sent to Google less than ' . HOUR_IN_SECONDS . ' seconds ago.' );
123
+ }
124
+ }
125
+
126
+ // Bing ?
127
+ if ( in_array( 'bing', $ping ) ) {
128
+ // check if we did not ping already within the last hour
129
+ if ( false === get_transient('xmlsf_ping_bing_sitemap') ) {
130
+ // Ping !
131
+ $uri = add_query_arg( 'sitemap', urlencode( trailingslashit( get_bloginfo( 'url' ) ) . $sitemaps['sitemap'] ), 'https://www.bing.com/ping' );
132
+ $response = wp_remote_request( $uri );
133
+ $code = wp_remote_retrieve_response_code( $response );
134
+ if ( 200 === $code ) {
135
+ set_transient( 'xmlsf_ping_bing_sitemap', $sitemaps['sitemap'], HOUR_IN_SECONDS );
136
+ } elseif ( defined('WP_DEBUG') && WP_DEBUG == true ) {
137
+ error_log( 'Ping to '. $uri .' failed with response code: ' . $code );
138
+ }
139
+ } elseif ( defined('WP_DEBUG') && WP_DEBUG == true ) {
140
+ error_log( 'Ping skipped: previous XML Sitemap was sent to Bing less than ' . HOUR_IN_SECONDS . ' seconds ago.' );
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Update term modified meta, hooked to transition post status
149
+ *
150
+ * @param $new_status
151
+ * @param $old_status
152
+ * @param $post
153
+ */
154
+ function update_term_modified_meta( $new_status, $old_status, $post ) {
155
+
156
+ $taxonomies = get_option( 'xmlsf_taxonomies' );
157
+
158
+ if ( empty( $taxonomies ) )
159
+ return;
160
+
161
+ // are we not publishing or unpublishing?
162
+ if ( $old_status == $new_status || $old_status != 'publish' && $new_status != 'publish' )
163
+ return;
164
+
165
+ $term_ids = array();
166
+ foreach ( $taxonomies as $tax_name ) {
167
+ $terms = wp_get_post_terms( $post->ID, $tax_name, array( 'fields' => 'ids' ));
168
+ if ( !is_wp_error($terms) ) {
169
+ $term_ids = array_merge( $term_ids, $terms );
170
+ }
171
+ }
172
+
173
+ $time = date('Y-m-d H:i:s');
174
+
175
+ foreach( $term_ids as $id ) {
176
+ update_term_meta( $id, 'term_modified_gmt', $time );
177
+ }
178
+ }
controllers/public/shared.php ADDED
@@ -0,0 +1,34 @@
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
+ }
controllers/public/sitemap-news.php ADDED
@@ -0,0 +1,9 @@
1
+ <?php
2
+ /**
3
+ * set up the news sitemap template
4
+ */
5
+ function xmlsf_load_template_news() {
6
+ load_template( XMLSF_DIR . '/views/feed-sitemap-news.php' );
7
+ }
8
+
9
+ add_action('do_feed_sitemap-news', 'xmlsf_load_template_news', 10, 1);
controllers/public/sitemap.php ADDED
@@ -0,0 +1,106 @@
1
+ <?php
2
+ /**
3
+ * FEED TEMPLATES
4
+ */
5
+
6
+ /**
7
+ * Set up the sitemap index template
8
+ */
9
+ function xmlsf_load_template_index() {
10
+ load_template( XMLSF_DIR . '/views/feed-sitemap.php' );
11
+ }
12
+
13
+ /**
14
+ * set up the sitemap home page(s) template
15
+ */
16
+ function xmlsf_load_template_home() {
17
+ load_template( XMLSF_DIR . '/views/feed-sitemap-home.php' );
18
+ }
19
+
20
+ /**
21
+ * set up the post types sitemap template
22
+ */
23
+ function xmlsf_load_template() {
24
+ load_template( XMLSF_DIR . '/views/feed-sitemap-post_type.php' );
25
+ }
26
+
27
+ /**
28
+ * set up the taxonomy sitemap template
29
+ */
30
+ function xmlsf_load_template_taxonomy() {
31
+ load_template( XMLSF_DIR . '/views/feed-sitemap-taxonomy.php' );
32
+ }
33
+
34
+ /**
35
+ * set up the custom sitemap template
36
+ */
37
+ function xmlsf_load_template_custom() {
38
+ load_template( XMLSF_DIR . '/views/feed-sitemap-custom.php' );
39
+ }
40
+
41
+ /**
42
+ * Do feed templates
43
+ */
44
+ function xmlsf_feed_templates() {
45
+ $sitemaps = get_option( 'xmlsf_sitemaps' );
46
+
47
+ if ( is_array($sitemaps) && isset($sitemaps['sitemap'])) {
48
+ // setup feed templates
49
+ add_action( 'do_feed_sitemap', 'xmlsf_load_template_index', 10, 1 );
50
+ add_action( 'do_feed_sitemap_index', 'xmlsf_load_template_index', 10, 1 );
51
+ add_action( 'do_feed_sitemap-home', 'xmlsf_load_template_home', 10, 1 );
52
+ add_action( 'do_feed_sitemap-custom', 'xmlsf_load_template_custom', 10, 1 );
53
+
54
+ $post_types = get_option('xmlsf_post_types');
55
+ if ( is_array($post_types) ) {
56
+ foreach ( $post_types as $post_type => $settings ) {
57
+ if ( !empty($settings['active']) )
58
+ add_action( 'do_feed_sitemap-posttype-'.$post_type, 'xmlsf_load_template', 10, 1 );
59
+ }
60
+ }
61
+ foreach ( xmlsf_get_taxonomies() as $name ) {
62
+ add_action( 'do_feed_sitemap-taxonomy-'.$name, 'xmlsf_load_template_taxonomy', 10, 1 );
63
+ }
64
+ }
65
+ }
66
+
67
+ /* -------------------------------------
68
+ * MISSING WORDPRESS FUNCTIONS
69
+ * ------------------------------------- */
70
+
71
+ /**
72
+ * Retrieve the date that the first post/page was published.
73
+ * Variation of function get_lastpostdate, uses _get_post_time
74
+ *
75
+ * The server timezone is the default and is the difference between GMT and
76
+ * server time. The 'blog' value is the date when the last post was posted. The
77
+ * 'gmt' is when the last post was posted in GMT formatted date.
78
+ *
79
+ * @uses apply_filters() Calls 'get_firstpostdate' filter
80
+ * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
81
+ * @param string $post_type Post type to check.
82
+ * @return string The date of the last post.
83
+ */
84
+ if( !function_exists('get_firstpostdate') ) {
85
+ function get_firstpostdate($timezone = 'server', $post_type = 'any') {
86
+ return apply_filters( 'get_firstpostdate', _get_post_time( $timezone, 'date', $post_type, 'first' ), $timezone );
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Retrieve last post/page modified date depending on timezone.
92
+ * Variation of function get_lastpostmodified, uses _get_post_time
93
+ *
94
+ * The server timezone is the default and is the difference between GMT and
95
+ * server time. The 'blog' value is the date when the last post was posted. The
96
+ * 'gmt' is when the last post was posted in GMT formatted date.
97
+ *
98
+ * @uses apply_filters() Calls 'get_lastmodified' filter
99
+ * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
100
+ * @return string The date of the oldest modified post.
101
+ */
102
+ if( !function_exists('get_lastmodified') ) {
103
+ function get_lastmodified( $timezone = 'server', $post_type = 'any', $m = '' ) {
104
+ return apply_filters( 'get_lastmodified', _get_post_time( $timezone, 'modified', $post_type, 'last', $m ), $timezone );
105
+ }
106
+ }
includes/class-xmlsitemapfeed-admin.php DELETED
@@ -1,1127 +0,0 @@
1
- <?php
2
- /* ------------------------------
3
- * XMLSF Admin CLASS
4
- * ------------------------------ */
5
-
6
- class XMLSitemapFeed_Admin extends XMLSitemapFeed {
7
-
8
- /**
9
- * SETTINGS
10
- */
11
-
12
- // TODO refer to support forum + invite plugin rating !
13
-
14
- /**
15
- * Sitemaps
16
- * settings field
17
- */
18
- public function sitemaps_settings_field() {
19
- $options = parent::get_sitemaps();
20
- $disabled = ('1' == get_option('blog_public')) ? false : true;
21
-
22
- echo '<fieldset id="xmlsf_sitemaps"><legend class="screen-reader-text">'.__('XML Sitemaps','xml-sitemap-feed').'</legend>
23
- <label><input type="checkbox" name="'.$this->prefix.'sitemaps[sitemap]" id="xmlsf_sitemaps_index" value="'.htmlspecialchars(XMLSF_NAME).'" '.checked(isset($options['sitemap']), true, false).' '.disabled($disabled, true, false).' /> '.__('XML Sitemap Index','xml-sitemap-feed').'</label>';//xmlsf
24
- if (isset($options['sitemap']))
25
- echo '<span class="description"> &nbsp;&ndash;&nbsp; <a href="#xmlsf" id="xmlsf_link">'.translate('Settings').'</a> &nbsp;&ndash;&nbsp; <a href="'.trailingslashit(get_bloginfo('url')). ( ('' == get_option('permalink_structure')) ? '?feed=sitemap' : $options['sitemap'] ) .'" target="_blank">'.translate('View').'</a></span>';
26
-
27
- echo '<br>
28
- <label><input type="checkbox" name="'.$this->prefix.'sitemaps[sitemap-news]" id="xmlsf_sitemaps_news" value="'.htmlspecialchars(XMLSF_NEWS_NAME).'" '.checked(isset($options['sitemap-news']), true, false).' '.disabled($disabled, true, false).' /> '.__('Google News Sitemap','xml-sitemap-feed').'</label>';
29
- if (isset($options['sitemap-news']))
30
- echo '<span class="description"> &nbsp;&ndash;&nbsp; <a href="#xmlnf" id="xmlnf_link">'.translate('Settings').'</a> &nbsp;&ndash;&nbsp; <a href="'.trailingslashit(get_bloginfo('url')). ( ('' == get_option('permalink_structure')) ? '?feed=sitemap-news' : $options['sitemap-news'] ) .'" target="_blank">'.translate('View').'</a></span>';
31
-
32
- echo '
33
- </fieldset>';
34
- echo '
35
- <script type="text/javascript">
36
- jQuery( document ).ready( function() {
37
- jQuery( "input[name=\'blog_public\']" ).on( \'change\', function() {
38
- jQuery("#xmlsf_sitemaps input").each(function() {
39
- var $this = jQuery(this);
40
- $this.attr("disabled") ? $this.removeAttr("disabled") : $this.attr("disabled", "disabled");
41
- });
42
- jQuery("#xmlsf_ping input").each(function() {
43
- var $this = jQuery(this);
44
- $this.attr("disabled") ? $this.removeAttr("disabled") : $this.attr("disabled", "disabled");
45
- });
46
- });
47
- jQuery( "#xmlsf_link" ).click( function(event) {
48
- event.preventDefault();
49
- jQuery("html, body").animate({
50
- scrollTop: jQuery("a[name=\'xmlsf\']").offset().top - 30
51
- }, 1000);
52
- });
53
- jQuery( "#xmlnf_link" ).click( function(event) {
54
- event.preventDefault();
55
- jQuery("html, body").animate({
56
- scrollTop: jQuery("a[name=\'xmlnf\']").offset().top - 30
57
- }, 1000);
58
- });
59
- });
60
- </script>';
61
- }
62
-
63
- /* PINGS */
64
-
65
- public function ping_settings_field() {
66
- $options = parent::get_ping();
67
- $defaults = parent::defaults('ping');
68
- $update_services = get_option('ping_sites');
69
-
70
- $names = array(
71
- 'google' => array (
72
- 'name' => __('Google','xml-sitemap-feed'),
73
- ),
74
- 'bing' => array (
75
- 'name' => __('Bing & Yahoo','xml-sitemap-feed'),
76
- ),
77
- 'yandex' => array (
78
- 'name' => __('Yandex','xml-sitemap-feed'),
79
- ),
80
- 'baidu' => array (
81
- 'name' => __('Baidu','xml-sitemap-feed'),
82
- ),
83
- 'others' => array (
84
- 'name' => __('Ping-O-Matic','xml-sitemap-feed'),
85
- )
86
- );
87
- foreach ( $names as $key => $values ) {
88
- if (array_key_exists($key,$defaults) && is_array($values))
89
- $defaults[$key] += $values;
90
- }
91
-
92
- echo '
93
- <fieldset id="xmlsf_ping"><legend class="screen-reader-text">'.translate('Update Services').'</legend>
94
- ';
95
-
96
- foreach ( $defaults as $key => $values ) {
97
- if ( isset($values['type']) && $values['type'] == 'RPC' ) {
98
- $active = ( strpos($update_services,untrailingslashit($values['uri'])) === false ) ? false : true;
99
- } else {
100
- $active = !empty($options[$key]['active']) ? true : false;
101
- }
102
- echo '
103
- <label><input type="checkbox" name="'.$this->prefix.'ping['.
104
- $key.'][active]" id="xmlsf_ping_'.
105
- $key.'" value="1"'.
106
- checked( $active, true, false).' /> ';
107
- echo isset($names[$key]) && !empty($names[$key]['name']) ? $names[$key]['name'] : $key ;
108
- echo '</label>';
109
-
110
- echo '
111
- <input type="hidden" name="'.$this->prefix.'ping['.
112
- $key.'][uri]" value="'.
113
- $values['uri'].'" />';
114
- echo '
115
- <input type="hidden" name="'.$this->prefix.'ping['.
116
- $key.'][type]" value="'.
117
- $values['type'].'" />';
118
- if (isset($values['news']))
119
- echo '
120
- <input type="hidden" name="'.$this->prefix.'ping['.
121
- $key.'][news]" value="'.
122
- $values['news'].'" />';
123
-
124
- echo ' <span class="description">';
125
- if (!empty($options[$key]['pong'])) {
126
- if ( $tzstring = get_option('timezone_string') ) {
127
- // use same timezoneformat as translatable examples in options-general.php
128
- $timezone_format = translate_with_gettext_context('Y-m-d G:i:s', 'timezone date format');
129
- date_default_timezone_set($tzstring);
130
- } else {
131
- $timezone_format = 'Y-m-d G:i:s T';
132
- }
133
-
134
- foreach ((array)$options[$key]['pong'] as $pretty => $time) {
135
- echo '
136
- <input type="hidden" name="'.$this->prefix.'ping['.
137
- $key.'][pong]['.$pretty.']" value="'.
138
- $time.'" />';
139
- if ( !empty($time) )
140
- echo sprintf(__('Successfully sent %1$s on %2$s.','xml-sitemap-feed'),$pretty, date($timezone_format,$time)).' ';
141
- }
142
- date_default_timezone_set('UTC');
143
- }
144
- echo '</span><br>';
145
- }
146
-
147
- echo '
148
- </fieldset>';
149
- }
150
-
151
- public function sanitize_ping_settings($new) {
152
- $defaults = parent::defaults('ping');
153
- $old = parent::get_option('ping');
154
- $sanitized = array();
155
- $update_services = get_option('ping_sites');
156
- $update_services_new = $update_services;
157
-
158
- foreach ($defaults as $key => $values) {
159
- if(!isset($new[$key]))
160
- continue;
161
-
162
- if ( isset($values['type']) && $values['type']=='RPC' && isset($values['uri']) ) {
163
- // did we toggle the option?
164
- $changed = true;
165
- if ( isset($old[$key]) ) {
166
- $old_active = isset($old[$key]['active']) ? $old[$key]['active'] : '';
167
- $new_active = isset($new[$key]['active']) ? $new[$key]['active'] : '';
168
- if ( $old_active == $new_active )
169
- $changed = false;
170
- }
171
-
172
- if ( $changed ) {
173
- // then change the ping_sites list according to option
174
- if ( !empty($new[$key]['active']) && strpos($update_services,untrailingslashit($values['uri'])) === false )
175
- $update_services_new .= "\n" . $values['uri'];
176
- elseif ( empty($new[$key]['active']) && strpos($update_services,untrailingslashit($values['uri'])) !== false )
177
- $update_services_new = str_replace(array(trailingslashit($values['uri']),untrailingslashit($values['uri'])),'',$update_services_new);
178
- } else {
179
- // or change the option according to ping_sites
180
- if ( strpos($update_services,untrailingslashit($values['uri'])) !== false )
181
- $new[$key]['active'] = '1';
182
- else
183
- unset($new[$key]['active']);
184
- }
185
- }
186
- if ( is_array($new[$key]) ) {
187
- $sanitized += array( $key => $new[$key] );
188
- }
189
- }
190
-
191
- if($update_services_new != $update_services)
192
- update_option('ping_sites',$update_services_new);
193
-
194
- return $sanitized;
195
- }
196
-
197
- /* ROBOTS */
198
-
199
- public function robots_settings_field() {
200
- echo '
201
- <fieldset><legend class="screen-reader-text">'.__('Additional robots.txt rules','xml-sitemap-feed').'</legend>
202
- <label>'.sprintf(__('Rules that will be appended to the %s generated by WordPress:','xml-sitemap-feed'),'<a href="'.trailingslashit(get_bloginfo('url')).'robots.txt" target="_blank">robots.txt</a>').'<br><textarea name="'.$this->prefix.'robots" id="xmlsf_robots" class="large-text" cols="50" rows="6" />'.esc_attr( parent::get_robots() ).'</textarea></label>
203
- <p class="description">'.__('These rules will not have effect when you are using a static robots.txt file.','xml-sitemap-feed').'<br><span style="color: red" class="warning">'.__('Only add rules here when you know what you are doing, otherwise you might break search engine access to your site.','xml-sitemap-feed').'</span></p>
204
- </fieldset>';
205
- }
206
-
207
- public function reset_settings_field() {
208
- echo '
209
- <fieldset><legend class="screen-reader-text">'.__('Reset XML sitemaps','xml-sitemap-feed').'</legend>
210
- <label><input type="checkbox" name="'.$this->prefix.'sitemaps[reset]" value="1" onchange="if(this.checked){if(!confirm(\''.
211
- __('Selecting this will clear all XML Sitemap & Google News Sitemap settings after Save Changes. Are you sure?','xml-sitemap-feed').'\')){this.checked=false}}" /> '.
212
- __('Clear all XML Sitemap & Google News Sitemap settings.','xml-sitemap-feed').'</label>
213
- </fieldset>';
214
- echo '
215
- <p class="description">'.__('Check this option and Save Changes to start fresh with the default settings.','xml-sitemap-feed').'</p>';
216
- }
217
-
218
- /**
219
- * XML SITEMAP SECTION
220
- */
221
-
222
- public function xml_sitemap_settings() {
223
- echo '<p><a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feeds&item_number='.XMLSF_VERSION.'&no_shipping=0&tax=0&charset=UTF%2d8" title="'.
224
- sprintf(__('Donate to keep the free %s plugin development & support going!','xml-sitemap-feed'),__('XML Sitemap & Google News Feeds','xml-sitemap-feed')).'"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" style="border:none;float:right;margin:4px 0 0 10px" alt="'.
225
- sprintf(__('Donate to keep the free %s plugin development & support going!','xml-sitemap-feed'),__('XML Sitemap & Google News Feeds','xml-sitemap-feed')).'" width="92" height="26" /></a>'.
226
- sprintf(__('These settings control the XML Sitemaps generated by the %s plugin.','xml-sitemap-feed'),__('XML Sitemap & Google News Feeds','xml-sitemap-feed')).' '.
227
- sprintf(__('For ping options, go to %s.','xml-sitemap-feed'),'<a href="options-writing.php">'.translate('Writing Settings').'</a>').'</p>';
228
- }
229
-
230
- public function post_types_settings_field() {
231
- $options = parent::get_post_types();
232
- $defaults = parent::defaults('post_types');
233
- $do_note = false;
234
-
235
- $post_types = get_post_types(array('public'=>true),'objects');
236
- if ( !is_array($post_types) || is_wp_error($post_types) )
237
- return;
238
-
239
- echo '<fieldset id="xmlsf_post_types"><legend class="screen-reader-text">'.__('XML Sitemaps for post types','xml-sitemap-feed').'</legend>
240
- ';
241
- foreach ( $post_types as $post_type ) {
242
- // skip unallowed post types
243
- if (in_array($post_type->name,parent::disabled_post_types()))
244
- continue;
245
-
246
- $count = wp_count_posts( $post_type->name );
247
-
248
- echo '
249
- <input type="hidden" name="'.$this->prefix.'post_types['.
250
- $post_type->name.'][name]" value="'.
251
- $post_type->name.'" />';
252
-
253
- echo '
254
- <label><input type="checkbox" name="'.$this->prefix.'post_types['.
255
- $post_type->name.'][active]" id="xmlsf_post_types_'.
256
- $post_type->name.'" value="1" '.
257
- checked( !empty($options[$post_type->name]["active"]), true, false).' /> '.
258
- $post_type->label.'</label> ('.
259
- $count->publish.')';
260
-
261
- if (!empty($options[$post_type->name]['active'])) {
262
-
263
- echo ' &nbsp;&ndash;&nbsp; <span class="description"><a id="xmlsf_post_types_'.$post_type->name.'_link" href="#xmlsf_post_types_'.$post_type->name.'_settings">'.translate('Settings').'</a></span><br>
264
- <script type="text/javascript">
265
- jQuery( document ).ready( function() {
266
- jQuery("#xmlsf_post_types_'.$post_type->name.'_settings").hide();
267
- jQuery("#xmlsf_post_types_'.$post_type->name.'_link").click( function(event) {
268
- event.preventDefault();
269
- jQuery("#xmlsf_post_types_'.$post_type->name.'_settings").toggle("slow");
270
- });
271
- });
272
- </script>
273
- <ul style="margin-left:18px" id="xmlsf_post_types_'.$post_type->name.'_settings">';
274
-
275
-
276
- if ( isset($defaults[$post_type->name]['archive']) ) {
277
- $archives = array (
278
- 'yearly' => __('Year','xml-sitemap-feed'),
279
- 'monthly' => __('Month','xml-sitemap-feed')
280
- );
281
- $archive = !empty($options[$post_type->name]['archive']) ? $options[$post_type->name]['archive'] : $defaults[$post_type->name]['archive'];
282
- echo '
283
- <li><label>'.__('Split by','xml-sitemap-feed').' <select name="'.$this->prefix.'post_types['.
284
- $post_type->name.'][archive]" id="xmlsf_post_types_'.
285
- $post_type->name.'_archive">
286
- <option value="">'.translate('None').'</option>';
287
- foreach ($archives as $value => $translation)
288
- echo '
289
- <option value="'.$value.'" '.
290
- selected( $archive == $value, true, false).
291
- '>'.$translation.'</option>';
292
- echo '</select>
293
- </label> <span class="description"> '.__('Split by year if you experience errors or slow sitemaps. In very rare cases, split by month is needed.','xml-sitemap-feed').'</span></li>';
294
- }
295
-
296
- $priority_val = !empty($options[$post_type->name]['priority']) ? $options[$post_type->name]['priority'] : $defaults[$post_type->name]['priority'];
297
- echo '
298
- <li><label>'.__('Priority','xml-sitemap-feed').' <input type="number" step="0.1" min="0.1" max="0.9" name="'.$this->prefix.'post_types['.
299
- $post_type->name.'][priority]" id="xmlsf_post_types_'.
300
- $post_type->name.'_priority" value="'.$priority_val.'" class="small-text"></label> <span class="description">'.__('Priority can be overridden on individual posts.','xml-sitemap-feed').' *</span></li>';
301
-
302
- echo '
303
- <li><label><input type="checkbox" name="'.$this->prefix.'post_types['.
304
- $post_type->name.'][dynamic_priority]" value="1" '.
305
- checked( !empty($options[$post_type->name]['dynamic_priority']), true, false).' /> '.__('Automatic Priority calculation.','xml-sitemap-feed').'</label> <span class="description">'.__('Adjusts the Priority based on factors like age, comments, sticky post or blog page. Individual posts with fixed Priority will always keep that value.','xml-sitemap-feed').'</span></li>';
306
-
307
- echo '
308
- <li><label><input type="checkbox" name="'.$this->prefix.'post_types['.
309
- $post_type->name.'][update_lastmod_on_comments]" value="1" '.
310
- checked( !empty($options[$post_type->name]["update_lastmod_on_comments"]), true, false).' /> '.__('Update Lastmod on comments.','xml-sitemap-feed').'</label> <span class="description">'.__('Set this if discussion on your site warrants reindexation upon each new comment.','xml-sitemap-feed').'</li>';
311
-
312
- $image = isset($options[$post_type->name]['tags']['image']) ? $options[$post_type->name]['tags']['image'] : $defaults[$post_type->name]['tags']['image'];
313
- $context = ( $post_type->name === 'page' ) ? 'page' : 'post';
314
- echo '
315
- <li><label>'.__('Add image tags for','xml-sitemap-feed').' <select name="'.$this->prefix.'post_types['.
316
- $post_type->name.'][tags][image]">
317
- <option value="">'.translate('None').'</option>
318
- <option value="featured" '.
319
- selected( $image == "featured", true, false).
320
- '>'.translate_with_gettext_context('Featured Image',$context).'</option>
321
- <option value="attached" '.
322
- selected( $image == "attached", true, false).
323
- '>'.__('Attached images','xml-sitemap-feed').'</option>
324
- </select></label></li>
325
-
326
- </ul>';
327
- } else {
328
- echo '<br>';
329
- }
330
- }
331
-
332
- echo '
333
- <p class="description">* '.__('Priority settings do not affect ranking in search results in any way. They are only meant to suggest search engines which URLs to index first. Once a URL has been indexed, its Priority becomes meaningless until its Lastmod is updated.','xml-sitemap-feed').' <a href="#xmlsf_post_types_note_1_more" id="xmlsf_post_types_note_1_link">'.translate('Read more...').'</a>
334
- <span id="xmlsf_post_types_note_1_more">'.__('Maximum Priority (1.0) is reserved for the front page, individual posts and, when allowed, posts with high comment count.','xml-sitemap-feed').' '.__('Priority values are taken as relative values. Setting all to the same (high) value is pointless.','xml-sitemap-feed').'</span></p>
335
- <script type="text/javascript">
336
- jQuery( document ).ready( function() {
337
- jQuery("#xmlsf_post_types_note_1_more").hide();
338
- jQuery("#xmlsf_post_types_note_1_link").click( function(event) {
339
- event.preventDefault();
340
- jQuery("#xmlsf_post_types_note_1_link").hide();
341
- jQuery("#xmlsf_post_types_note_1_more").show("slow");
342
- });
343
- });
344
- </script>';
345
- echo '
346
- </fieldset>';
347
- }
348
-
349
- public function taxonomies_settings_field() {
350
- $options = parent::get_taxonomies();
351
- $active = parent::get_option('post_types');
352
- $output = '';
353
-
354
- foreach ( get_taxonomies(array('public'=>true),'objects') as $taxonomy ) {
355
- // skip unallowed post types
356
- if (in_array($taxonomy->name,parent::disabled_taxonomies()))
357
- continue;
358
-
359
- $skip = true;
360
- foreach ( $taxonomy->object_type as $post_type)
361
- if (!empty($active[$post_type]['active']) && $active[$post_type]['active'] == '1')
362
- $skip = false;
363
- if ($skip) continue; // skip if none of the associated post types are active
364
-
365
- $count = wp_count_terms( $taxonomy->name );
366
- $output .= '
367
- <label><input type="checkbox" name="'.$this->prefix.'taxonomies['.
368
- $taxonomy->name.']" id="xmlsf_taxonomies_'.
369
- $taxonomy->name.'" value="'.
370
- $taxonomy->name.'"'.
371
- checked(in_array($taxonomy->name,$options), true, false).' /> '.
372
- $taxonomy->label.'</label> ('.
373
- $count.') ';
374
-
375
- // if ( in_array($taxonomy->name,$options) && empty($taxonomy->show_tagcloud) )
376
- // echo '<span class="description error" style="color: red">'.__('This taxonomy type might not be suitable for public use. Please check the urls in the taxonomy sitemap.','xml-sitemap-feed').'</span>';
377
-
378
- $output .= '
379
- <br>';
380
- }
381
-
382
- if ($output) {
383
- echo '
384
- <fieldset id="xmlsf_taxonomies"><legend class="screen-reader-text">'.__('XML Sitemaps for taxonomies','xml-sitemap-feed').'</legend>
385
- ';
386
-
387
- echo $output;
388
-
389
- echo '
390
- <p class="description">'.__('It is generally not recommended to include taxonomy pages, unless their content brings added value.','xml-sitemap-feed').' <a href="#xmlsf_taxonomies_note_1_more" id="xmlsf_taxonomies_note_1_link">'.translate('Read more...').'</a>
391
- <span id="xmlsf_taxonomies_note_1_more">'.__('For example, when you use category descriptions with information that is not present elsewhere on your site or if taxonomy pages list posts with an excerpt that is different from, but complementary to the post content. In these cases you might consider including certain taxonomies. Otherwise, if you fear <a href="http://moz.com/learn/seo/duplicate-content">negative affects of duplicate content</a> or PageRank spread, you might even consider disallowing indexation of taxonomies.','xml-sitemap-feed').' '.
392
- sprintf(__('You can do this by adding specific robots.txt rules in the %s field above.','xml-sitemap-feed'),'<strong>'.__('Additional robots.txt rules','xml-sitemap-feed').'</strong>');
393
- echo '</span></p>
394
- <script type="text/javascript">
395
- jQuery( document ).ready( function() {
396
- jQuery("#xmlsf_taxonomies_note_1_more").hide();
397
- jQuery("#xmlsf_taxonomies_note_1_link").click( function(event) {
398
- event.preventDefault();
399
- jQuery("#xmlsf_taxonomies_note_1_link").hide();
400
- jQuery("#xmlsf_taxonomies_note_1_more").show("slow");
401
- });
402
- });
403
- </script>
404
- </fieldset>';
405
- } else {
406
- echo '
407
-<