Version Description
- massive priority calculation improvement
Download this release
Release Info
Developer | RavanH |
Plugin | XML Sitemap & Google News feeds |
Version | 3.6 |
Comparing to | |
See all releases |
Code changes from version 3.5 to 3.6
- feed-sitemap.php +107 -0
- readme.txt +14 -7
- sitemap.xml.php +0 -83
- xml-sitemap.php +113 -28
feed-sitemap.php
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* ---------------------------
|
3 |
+
XML Sitemap Feed Template
|
4 |
+
--------------------------- */
|
5 |
+
|
6 |
+
// presets
|
7 |
+
$frontpage_priority = 1.0;
|
8 |
+
$min_priority = 0.1;
|
9 |
+
$max_priority = 0.9;
|
10 |
+
$maxURLS = 9999; // 10,000 (including 1 for front page) of maximum 50,000 URLs allowed in a sitemap.xml
|
11 |
+
// should be more than enough for any blog...
|
12 |
+
$comment_weight = 0.1;
|
13 |
+
$age_weight = 0.1;
|
14 |
+
$level_weight = 0.1;
|
15 |
+
|
16 |
+
// site variables
|
17 |
+
$post_count = wp_count_posts('post');
|
18 |
+
$page_count = wp_count_posts('page');
|
19 |
+
$totalcommentcount = wp_count_comments();
|
20 |
+
$lastpostmodified = get_lastpostmodified('GMT');
|
21 |
+
$firstpostmodified = get_firstpostmodified('GMT'); // function defined in xml-sitemap.php !
|
22 |
+
$average_commentcount = $totalcommentcount/($post_count->publish + $page_count->publish);
|
23 |
+
|
24 |
+
// calculated presets
|
25 |
+
if ($totalcommentcount->approved > 0)
|
26 |
+
$comment_weight = ($max_priority - $min_priority) / $totalcommentcount->approved;
|
27 |
+
|
28 |
+
if ($post_count->publish > $page_count->publish) { // site emphasis on posts
|
29 |
+
$post_priority = 0.7;
|
30 |
+
$page_priority = 0.4;
|
31 |
+
} else { // site emphasis on pages
|
32 |
+
$post_priority = 0.4;
|
33 |
+
$page_priority = 0.7;
|
34 |
+
}
|
35 |
+
|
36 |
+
if ( $lastpostmodified > $firstpostmodified )
|
37 |
+
$age_weight = ($max_priority - $min_priority) / ($lastpostmodified - $firstpostmodified);
|
38 |
+
|
39 |
+
// reset the query
|
40 |
+
global $post;
|
41 |
+
query_posts( array(
|
42 |
+
'posts_per_page' => $maxURLS,
|
43 |
+
'post_type' => 'any',
|
44 |
+
'post_status' => 'publish',
|
45 |
+
'caller_get_posts' => '1'
|
46 |
+
)
|
47 |
+
);
|
48 |
+
|
49 |
+
// start the xml output
|
50 |
+
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
51 |
+
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?>
|
52 |
+
<?xml-stylesheet type="text/xsl" href="'.get_option('home').'/'.str_replace(ABSPATH,"", XMLSF_PLUGIN_DIR).'/sitemap.xsl.php?v='.XMLSF_VERSION.'"?>
|
53 |
+
<!-- generated-on="'.date('Y-m-d\TH:i:s+00:00').'" -->
|
54 |
+
<!-- generator="XML Sitemap Feed plugin for WordPress" -->
|
55 |
+
<!-- generator-url="http://4visions.nl/en/index.php?section=57" -->
|
56 |
+
<!-- generator-version="'.XMLSF_VERSION.'" -->
|
57 |
+
'; ?>
|
58 |
+
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
59 |
+
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
|
60 |
+
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
61 |
+
<url>
|
62 |
+
<loc><?php bloginfo_rss('url') ?>/</loc>
|
63 |
+
<lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', $lastpostmodified, false); ?></lastmod>
|
64 |
+
<changefreq>daily</changefreq>
|
65 |
+
<priority>1.0</priority>
|
66 |
+
</url>
|
67 |
+
<?php
|
68 |
+
// and loop away!
|
69 |
+
while ( have_posts() ) : the_post();
|
70 |
+
|
71 |
+
if($post->post_type == "page") {
|
72 |
+
if ($post->ID == get_option('page_on_front')) // check if we are not doing the front page twice
|
73 |
+
continue;
|
74 |
+
|
75 |
+
if (!is_array($post->ancestors)) { // $post->ancestors seems always empty. something to do with http://core.trac.wordpress.org/ticket/10381 ??
|
76 |
+
$page_obj = $post;
|
77 |
+
$ancestors = array();
|
78 |
+
while($page_obj->post_parent!=0) {
|
79 |
+
$page_obj = get_page($page_obj->post_parent);
|
80 |
+
$ancestors[] = $page_obj->ID;
|
81 |
+
}
|
82 |
+
} else {
|
83 |
+
$ancestors = $post->ancestors;
|
84 |
+
}
|
85 |
+
$offset = (($post->comment_count - $average_commentcount) * $comment_weight) - (count($ancestors) * $level_weight);
|
86 |
+
$priority = $page_priority + round($offset,1);
|
87 |
+
} else {
|
88 |
+
$offset = (($post->comment_count - $average_commentcount) * $comment_weight) - (($lastpostmodified - $post->post_modified_gmt) * $age_weight);
|
89 |
+
$priority = $post_priority + round($offset,1);
|
90 |
+
}
|
91 |
+
$priority = ($priority > $max_priority) ? $max_priority : $priority;
|
92 |
+
$priority = ($priority < $min_priority) ? $min_priority : $priority;
|
93 |
+
?>
|
94 |
+
<url>
|
95 |
+
<loc><?php the_permalink_rss() ?></loc>
|
96 |
+
<lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', $post->post_modified_gmt, false) ?></lastmod>
|
97 |
+
<?php if($post->comment_count > ($totalcommentcount->approved / 2)) { ?>
|
98 |
+
<changefreq>daily</changefreq>
|
99 |
+
<?php } else if($post->comment_count > 0 ) { ?>
|
100 |
+
<changefreq>weekly</changefreq>
|
101 |
+
<?php } else { ?>
|
102 |
+
<changefreq>monthly</changefreq>
|
103 |
+
<?php } ?>
|
104 |
+
<priority><?php echo $priority ?></priority>
|
105 |
+
</url>
|
106 |
+
<?php endwhile; ?>
|
107 |
+
</urlset>
|
readme.txt
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
=== XML Sitemap Feed ===
|
2 |
Contributors: RavanH
|
3 |
-
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap&item_number=
|
4 |
Tags: sitemap, xml sitemap, google, yahoo, bing, feed, wpmu
|
5 |
Requires at least: 2.6
|
6 |
Tested up to: 3.0
|
7 |
-
Stable tag: 3.
|
8 |
|
9 |
Creates a feed that complies with the XML Sitemap protocol ready for indexing by Google, Yahoo, Bing, Ask and others.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
-
This plugin dynamically creates an XML feed that complies with the XML Sitemap protocol. There are no options to be set and the feed becomes instantly available after activation on yourblogurl.tld/sitemap.xml (or yourblogurl.tld/index.php?sitemap
|
14 |
|
15 |
An entry `Sitemap: http://yourblogurl.tld/sitemap.xml` is added to the (by WordPress dynamically created) robots.txt on yourblogurl.tld/robots.txt to tell search engines where to find your XML Sitemap. If you do not use fancy URL's in WordPress, have WP installed in a subdirectory or if you use WP for pages only and do not have any posts, WordPress does not generate a robots.txt output. You will have to create your own robots.txt file and upload it to your site root. See FAQ's.
|
16 |
|
@@ -67,7 +67,11 @@ Installed in /mu-plugins/ alongside [WordPress MU Sitewide Tags Pages](http://wo
|
|
67 |
|
68 |
= How are the values for priority and changefreq calculated? =
|
69 |
|
70 |
-
The front page has a fixed priority of 100% (1.0), pages
|
|
|
|
|
|
|
|
|
71 |
|
72 |
Dynamic pages like category pages, tag pages and archive pages are not listed in the XML Sitemap.
|
73 |
|
@@ -126,9 +130,9 @@ If you already have a robots.txt file with a line like that, you might want to r
|
|
126 |
|
127 |
No. While I would advise you to use any one of the nicer Permalink structures, you might not be able to (or don't want to) do that. If so, you can still use this plugin:
|
128 |
|
129 |
-
Check to see if the URL yourblogurl.tld/index.php?
|
130 |
`
|
131 |
-
Sitemap: http://yourblogurl.tld/index.php?sitemap
|
132 |
|
133 |
User-agent: *
|
134 |
Allow: /
|
@@ -137,7 +141,7 @@ You can also choose to notify major search engines of your new XML sitemap manua
|
|
137 |
|
138 |
= Can I change the sitemap name/URL? =
|
139 |
|
140 |
-
No. If you have fancy URL's turned ON in WordPress (Permalinks), the sitemap url that you manually submit to Google (if you are impatient) should be `yourblogurl.tld/sitemap.xml` but if you have the Default option set the feed is only available via `yourblogurl.tld/?sitemap
|
141 |
|
142 |
= Where can I customize the xml output? =
|
143 |
|
@@ -173,6 +177,9 @@ Yes.
|
|
173 |
|
174 |
== Changelog ==
|
175 |
|
|
|
|
|
|
|
176 |
= 3.5 =
|
177 |
* complete rewrite of plugin internals
|
178 |
* speed improvements
|
1 |
=== XML Sitemap Feed ===
|
2 |
Contributors: RavanH
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap&item_number=3%2e0&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8
|
4 |
Tags: sitemap, xml sitemap, google, yahoo, bing, feed, wpmu
|
5 |
Requires at least: 2.6
|
6 |
Tested up to: 3.0
|
7 |
+
Stable tag: 3.6
|
8 |
|
9 |
Creates a feed that complies with the XML Sitemap protocol ready for indexing by Google, Yahoo, Bing, Ask and others.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
+
This plugin dynamically creates an XML feed that complies with the XML Sitemap protocol. There are no options to be set and the feed becomes instantly available after activation on yourblogurl.tld/sitemap.xml (or yourblogurl.tld/index.php?feed=sitemap if you do not use a fancy permalink structure) ready for indexing by search engines like Google, Yahoo, MSN, Ask.com and others.
|
14 |
|
15 |
An entry `Sitemap: http://yourblogurl.tld/sitemap.xml` is added to the (by WordPress dynamically created) robots.txt on yourblogurl.tld/robots.txt to tell search engines where to find your XML Sitemap. If you do not use fancy URL's in WordPress, have WP installed in a subdirectory or if you use WP for pages only and do not have any posts, WordPress does not generate a robots.txt output. You will have to create your own robots.txt file and upload it to your site root. See FAQ's.
|
16 |
|
67 |
|
68 |
= How are the values for priority and changefreq calculated? =
|
69 |
|
70 |
+
The front page has a fixed priority of 100% (1.0). When your site has more posts that pages (you must be using WordPress for a blog), pages have a default priority of 40% (0.4) and posts have a default priority of 70% (0.7). If your site has more pages than posts (you must be using WordPress as CMS), pages have a default priority of 70% (0.7) and posts have a default priority of 40% (0.4).
|
71 |
+
|
72 |
+
Page priotity can vary between 10% (0.1) and 90% (0.9) depending on the page level (decreasing 10% for each sub-level) and relative number of comments. Post priority can vary between 10% (0.1) and 90% (0.9) depending on relative number of comments and relative post age.
|
73 |
+
|
74 |
+
The cangefreq of the frontpage is fixed to daily and calculated for pages and post to either monthly, weekly or daily depending on comments.
|
75 |
|
76 |
Dynamic pages like category pages, tag pages and archive pages are not listed in the XML Sitemap.
|
77 |
|
130 |
|
131 |
No. While I would advise you to use any one of the nicer Permalink structures, you might not be able to (or don't want to) do that. If so, you can still use this plugin:
|
132 |
|
133 |
+
Check to see if the URL yourblogurl.tld/index.php?feed=sitemap does produce a feed. Now manually upload your own robots.txt file to your website root containing:
|
134 |
`
|
135 |
+
Sitemap: http://yourblogurl.tld/index.php?feed=sitemap
|
136 |
|
137 |
User-agent: *
|
138 |
Allow: /
|
141 |
|
142 |
= Can I change the sitemap name/URL? =
|
143 |
|
144 |
+
No. If you have fancy URL's turned ON in WordPress (Permalinks), the sitemap url that you manually submit to Google (if you are impatient) should be `yourblogurl.tld/sitemap.xml` or `yourblogurl.tld/feed/sitemap/` but if you have the Permalinks' Default option set the feed is only available via `yourblogurl.tld/?feed=sitemap`.
|
145 |
|
146 |
= Where can I customize the xml output? =
|
147 |
|
177 |
|
178 |
== Changelog ==
|
179 |
|
180 |
+
= 3.6 =
|
181 |
+
* massive priority calculation improvement
|
182 |
+
|
183 |
= 3.5 =
|
184 |
* complete rewrite of plugin internals
|
185 |
* speed improvements
|
sitemap.xml.php
DELETED
@@ -1,83 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/* ---------------------------
|
3 |
-
XML Sitemap Feed Template
|
4 |
-
--------------------------- */
|
5 |
-
|
6 |
-
// priority presets
|
7 |
-
$frontpage_priority = 1.0;
|
8 |
-
$post_priority = 0.7;
|
9 |
-
$minpost_priority = 0.1;
|
10 |
-
$maxpost_priority = 0.9;
|
11 |
-
$page_priority = 0.4;
|
12 |
-
|
13 |
-
$lastpostmodified = get_lastpostmodified('GMT');
|
14 |
-
$totalcommentcount = get_comment_count();
|
15 |
-
|
16 |
-
global $post;
|
17 |
-
query_posts( array(
|
18 |
-
'posts_per_page' => '-1',
|
19 |
-
'post_type' => 'any',
|
20 |
-
'post_status' => 'publish',
|
21 |
-
'caller_get_posts' => '1'
|
22 |
-
)
|
23 |
-
);
|
24 |
-
|
25 |
-
// start the xml output
|
26 |
-
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
27 |
-
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?>
|
28 |
-
<?xml-stylesheet type="text/xsl" href="'.get_option('home').'/'.str_replace(ABSPATH,"", XMLSF_PLUGIN_DIR).'/sitemap.xsl.php?v='.XMLSF_VERSION.'"?>
|
29 |
-
<!-- generated-on="'.date('Y-m-d\TH:i:s+00:00').'" -->
|
30 |
-
<!-- generator="XML Sitemap Feed plugin for WordPress" -->
|
31 |
-
<!-- generator-url="http://4visions.nl/en/index.php?section=57" -->
|
32 |
-
<!-- generator-version="'.XMLSF_VERSION.'" -->
|
33 |
-
'; ?>
|
34 |
-
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
35 |
-
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
|
36 |
-
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
37 |
-
<url>
|
38 |
-
<loc><?php bloginfo_rss('url') ?>/</loc>
|
39 |
-
<lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', $lastpostmodified, false); ?></lastmod>
|
40 |
-
<changefreq>daily</changefreq>
|
41 |
-
<priority>1.0</priority>
|
42 |
-
</url>
|
43 |
-
<?php
|
44 |
-
// first check if there is a static page set as frontpage and exclude it to avoid double url
|
45 |
-
//$has_page_as_front = $wpdb->get_results("SELECT option_value FROM $wpdb->options WHERE option_name = 'show_on_front'");
|
46 |
-
//if ($has_page_as_front[0]->option_value == "page") {
|
47 |
-
// $frontpage = $wpdb->get_results("SELECT option_value FROM $wpdb->options WHERE option_name = 'page_on_front'");
|
48 |
-
// $frontpage_id = $frontpage[0]->option_value;
|
49 |
-
//} else {
|
50 |
-
// $frontpage_id = -1;
|
51 |
-
//}
|
52 |
-
|
53 |
-
// and loop away!
|
54 |
-
while ( have_posts() ) : the_post();
|
55 |
-
|
56 |
-
//setup_postdata($post);
|
57 |
-
$post_modified_time = get_post_modified_time('Y-m-d H:i:s', true);
|
58 |
-
$post_comment_count = get_comment_count($post->ID);
|
59 |
-
$priority_down = (($lastpostmodified - $post_modified_time) > 0) ? ($lastpostmodified - $post_modified_time)/10 : 0;
|
60 |
-
$priority_up = ($post_comment_count['approved'] > 0) ? ($post_comment_count['approved']/$totalcommentcount['approved'])*10 : 0;
|
61 |
-
$priority = $post_priority - $priority_down + $priority_up;
|
62 |
-
$priority = ($priority > $maxpost_priority) ? $maxpost_priority : $priority;
|
63 |
-
$priority = ($priority < $minpost_priority) ? $minpost_priority : $priority;
|
64 |
-
?>
|
65 |
-
<url>
|
66 |
-
<loc><?php the_permalink_rss() ?></loc>
|
67 |
-
<lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', $post_modified_time, false) ?></lastmod>
|
68 |
-
<?php if($post->post_type == "page") { ?>
|
69 |
-
<changefreq>monthly</changefreq>
|
70 |
-
<priority><?php echo $page_priority ?></priority>
|
71 |
-
<?php } else {
|
72 |
-
if($post_comment_count['approved'] > 10) { ?>
|
73 |
-
<changefreq>daily</changefreq>
|
74 |
-
<?php } else if($post_comment_count['approved'] > 0) { ?>
|
75 |
-
<changefreq>weekly</changefreq>
|
76 |
-
<?php } else { ?>
|
77 |
-
<changefreq>monthly</changefreq>
|
78 |
-
<?php } ?>
|
79 |
-
<priority><?php echo $priority ?></priority>
|
80 |
-
<?php } ?>
|
81 |
-
</url>
|
82 |
-
<?php endwhile; ?>
|
83 |
-
</urlset>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xml-sitemap.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: XML Sitemap Feed
|
4 |
Plugin URI: http://4visions.nl/portfolio/wordpress-plugins/xml-sitemap-feed/
|
5 |
Description: Creates a feed that complies with the XML Sitemap protocol ready for indexing by Google, Yahoo, Bing, Ask and others.
|
6 |
-
Version: 3.
|
7 |
Author: RavanH
|
8 |
Author URI: http://4visions.nl/
|
9 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=2%2e6%2e2%2e9&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8
|
@@ -37,7 +37,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravan
|
|
37 |
-------------------- */
|
38 |
|
39 |
// set version
|
40 |
-
define('XMLSF_VERSION','3.
|
41 |
|
42 |
// dir
|
43 |
$xmlsf_dir = dirname(__FILE__);
|
@@ -55,30 +55,28 @@ define('XMLSF_PLUGIN_URL', WP_PLUGIN_URL.'/'.basename($xmlsf_dir));
|
|
55 |
FUNCTIONS
|
56 |
-------------------- */
|
57 |
|
58 |
-
//
|
59 |
-
//
|
60 |
-
function
|
61 |
-
|
62 |
-
return $vars;
|
63 |
}
|
64 |
|
65 |
// TEMPLATES //
|
66 |
-
// set the XML
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
exit;
|
72 |
-
}
|
73 |
}
|
74 |
|
75 |
// REWRITES //
|
76 |
// add the rewrite rules
|
77 |
-
function xml_sitemap_rewrite($
|
78 |
-
$
|
79 |
-
'sitemap\.xml$' =>
|
80 |
-
|
81 |
-
|
|
|
82 |
}
|
83 |
// recreate rewrite rules
|
84 |
function xml_sitemap_flush_rewrite_rules() {
|
@@ -89,7 +87,7 @@ function xml_sitemap_flush_rewrite_rules() {
|
|
89 |
// ROBOTSTXT //
|
90 |
// add sitemap location in robots.txt generated by WP
|
91 |
function xml_sitemap_robots() {
|
92 |
-
|
93 |
}
|
94 |
|
95 |
// DE/ACTIVATION
|
@@ -98,12 +96,102 @@ function xml_sitemap_activate() {
|
|
98 |
xml_sitemap_flush_rewrite_rules();
|
99 |
}
|
100 |
function xml_sitemap_deactivate() {
|
101 |
-
remove_filter('query_vars', 'xml_sitemap_vars');
|
102 |
-
remove_filter('
|
103 |
delete_option('xml-sitemap-feed-version');
|
104 |
xml_sitemap_flush_rewrite_rules();
|
105 |
}
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
/* --------------------
|
108 |
HOOKS
|
109 |
-------------------- */
|
@@ -121,14 +209,11 @@ if ( $wpdb->blogid && function_exists('get_site_option') && get_site_option('tag
|
|
121 |
// of links outside the blogs own domain...
|
122 |
return;
|
123 |
} else {
|
124 |
-
//
|
125 |
-
|
126 |
-
|
127 |
-
// TEMPLATES
|
128 |
-
add_action('template_redirect', 'xml_sitemap_redirect');
|
129 |
|
130 |
// REWRITES
|
131 |
-
add_filter('
|
132 |
|
133 |
// ROBOTSTXT
|
134 |
add_action('do_robotstxt', 'xml_sitemap_robots');
|
3 |
Plugin Name: XML Sitemap Feed
|
4 |
Plugin URI: http://4visions.nl/portfolio/wordpress-plugins/xml-sitemap-feed/
|
5 |
Description: Creates a feed that complies with the XML Sitemap protocol ready for indexing by Google, Yahoo, Bing, Ask and others.
|
6 |
+
Version: 3.6
|
7 |
Author: RavanH
|
8 |
Author URI: http://4visions.nl/
|
9 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=2%2e6%2e2%2e9&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8
|
37 |
-------------------- */
|
38 |
|
39 |
// set version
|
40 |
+
define('XMLSF_VERSION','3.6');
|
41 |
|
42 |
// dir
|
43 |
$xmlsf_dir = dirname(__FILE__);
|
55 |
FUNCTIONS
|
56 |
-------------------- */
|
57 |
|
58 |
+
// FEEDS //
|
59 |
+
// set the XML feed up
|
60 |
+
function xml_sitemap_add_feed() {
|
61 |
+
add_feed('sitemap','do_feed_sitemap');
|
|
|
62 |
}
|
63 |
|
64 |
// TEMPLATES //
|
65 |
+
// set the XML feed template up
|
66 |
+
if ( !function_exists(do_feed_sitemap) ) {
|
67 |
+
function do_feed_sitemap() {
|
68 |
+
load_template( XMLSF_PLUGIN_DIR . '/feed-sitemap.php' );
|
69 |
+
}
|
|
|
|
|
70 |
}
|
71 |
|
72 |
// REWRITES //
|
73 |
// add the rewrite rules
|
74 |
+
function xml_sitemap_rewrite($wp_rewrite) {
|
75 |
+
$feed_rules = array(
|
76 |
+
'sitemap\.xml$' => $wp_rewrite->index . '?feed=sitemap',
|
77 |
+
'feed/sitemap$' => $wp_rewrite->index . '?feed=sitemap'
|
78 |
+
);
|
79 |
+
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
|
80 |
}
|
81 |
// recreate rewrite rules
|
82 |
function xml_sitemap_flush_rewrite_rules() {
|
87 |
// ROBOTSTXT //
|
88 |
// add sitemap location in robots.txt generated by WP
|
89 |
function xml_sitemap_robots() {
|
90 |
+
echo "\nSitemap: ".get_feed_link('sitemap')."\n\n";
|
91 |
}
|
92 |
|
93 |
// DE/ACTIVATION
|
96 |
xml_sitemap_flush_rewrite_rules();
|
97 |
}
|
98 |
function xml_sitemap_deactivate() {
|
99 |
+
//remove_filter('query_vars', 'xml_sitemap_vars');
|
100 |
+
remove_filter('generate_rewrite_rules', 'xml_sitemap_rewrite');
|
101 |
delete_option('xml-sitemap-feed-version');
|
102 |
xml_sitemap_flush_rewrite_rules();
|
103 |
}
|
104 |
|
105 |
+
// MISSING WORDPRESS FUNCTIONS
|
106 |
+
/**
|
107 |
+
* Retrieve first post modified date depending on timezone.
|
108 |
+
*
|
109 |
+
* The server timezone is the default and is the difference between GMT and
|
110 |
+
* server time. The 'blog' value is the date when the last post was posted. The
|
111 |
+
* 'gmt' is when the last post was posted in GMT formatted date.
|
112 |
+
*
|
113 |
+
* Reverse of get_lastpostmodified defined in wp-includes/post.php since WP 1.2.0
|
114 |
+
*
|
115 |
+
* @uses $wpdb
|
116 |
+
* @uses apply_filters() Calls 'get_firstpostmodified' filter
|
117 |
+
*
|
118 |
+
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
|
119 |
+
* @return string The date of the oldest modified post.
|
120 |
+
*/
|
121 |
+
if( !function_exists(get_firstpostmodified) ) {
|
122 |
+
function get_firstpostmodified($timezone = 'server') {
|
123 |
+
global $wpdb;
|
124 |
+
|
125 |
+
$add_seconds_server = date('Z');
|
126 |
+
$timezone = strtolower( $timezone );
|
127 |
+
|
128 |
+
$firstpostmodified = wp_cache_get( "firstpostmodified:$timezone", 'timeinfo' );
|
129 |
+
if ( $firstpostmodified )
|
130 |
+
return apply_filters( 'get_firstpostmodified', $firstpostmodified, $timezone );
|
131 |
+
|
132 |
+
switch ( strtolower($timezone) ) {
|
133 |
+
case 'gmt':
|
134 |
+
$firstpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt ASC LIMIT 1");
|
135 |
+
break;
|
136 |
+
case 'blog':
|
137 |
+
$firstpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt ASC LIMIT 1");
|
138 |
+
break;
|
139 |
+
case 'server':
|
140 |
+
$firstpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt ASC LIMIT 1");
|
141 |
+
break;
|
142 |
+
}
|
143 |
+
|
144 |
+
$firstpostdate = get_firstpostdate($timezone);
|
145 |
+
if ( $firstpostdate > $firstpostmodified )
|
146 |
+
$firstpostmodified = $firstpostdate;
|
147 |
+
|
148 |
+
if ( $firstpostmodified )
|
149 |
+
wp_cache_set( "firstpostmodified:$timezone", $firstpostmodified, 'timeinfo' );
|
150 |
+
|
151 |
+
return apply_filters( 'get_firstpostmodified', $firstpostmodified, $timezone );
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Retrieve the date that the first post was published.
|
157 |
+
*
|
158 |
+
* The server timezone is the default and is the difference between GMT and
|
159 |
+
* server time. The 'blog' value is the date when the last post was posted. The
|
160 |
+
* 'gmt' is when the last post was posted in GMT formatted date.
|
161 |
+
*
|
162 |
+
* Reverse of get_lastpostmodified defined in wp-includes/post.php since 0.71
|
163 |
+
*
|
164 |
+
* @uses $wpdb
|
165 |
+
* @uses $cache_firstpostdate
|
166 |
+
* @uses $blog_id
|
167 |
+
* @uses apply_filters() Calls 'get_firstpostdate' filter
|
168 |
+
*
|
169 |
+
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
|
170 |
+
* @return string The date of the last post.
|
171 |
+
*/
|
172 |
+
if( !function_exists(get_firstpostdate) ) {
|
173 |
+
function get_firstpostdate($timezone = 'server') {
|
174 |
+
global $cache_firstpostdate, $wpdb, $blog_id;
|
175 |
+
$add_seconds_server = date('Z');
|
176 |
+
if ( !isset($cache_firstpostdate[$blog_id][$timezone]) ) {
|
177 |
+
switch(strtolower($timezone)) {
|
178 |
+
case 'gmt':
|
179 |
+
$firstpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt ASC LIMIT 1");
|
180 |
+
break;
|
181 |
+
case 'blog':
|
182 |
+
$firstpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt ASC LIMIT 1");
|
183 |
+
break;
|
184 |
+
case 'server':
|
185 |
+
$firstpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt ASC LIMIT 1");
|
186 |
+
break;
|
187 |
+
}
|
188 |
+
$cache_firstpostdate[$blog_id][$timezone] = $firstpostdate;
|
189 |
+
} else {
|
190 |
+
$firstpostdate = $cache_firstpostdate[$blog_id][$timezone];
|
191 |
+
}
|
192 |
+
return apply_filters( 'get_firstpostdate', $firstpostdate, $timezone );
|
193 |
+
}
|
194 |
+
}
|
195 |
/* --------------------
|
196 |
HOOKS
|
197 |
-------------------- */
|
209 |
// of links outside the blogs own domain...
|
210 |
return;
|
211 |
} else {
|
212 |
+
// FEEDS
|
213 |
+
add_action('init', 'xml_sitemap_add_feed');
|
|
|
|
|
|
|
214 |
|
215 |
// REWRITES
|
216 |
+
add_filter('generate_rewrite_rules', 'xml_sitemap_rewrite');
|
217 |
|
218 |
// ROBOTSTXT
|
219 |
add_action('do_robotstxt', 'xml_sitemap_robots');
|