Google XML Sitemaps - Version 3.2.9

Version Description

Download this release

Release Info

Developer arnee
Plugin Icon 128x128 Google XML Sitemaps
Version 3.2.9
Comparing to
See all releases

Code changes from version 3.2.8 to 3.2.9

Files changed (5) hide show
  1. documentation.txt +44 -43
  2. readme.txt +2 -6
  3. sitemap-core.php +398 -381
  4. sitemap-ui.php +159 -152
  5. sitemap.php +46 -46
documentation.txt CHANGED
@@ -1,27 +1,27 @@
1
 Google XML Sitemaps Generator for WordPress
2
==============================================================================
3
-
4
This generator will create a sitemaps.org compliant sitemap of your WordPress blog.
5
Currently homepage, posts, static pages, categories, archives and author pages are supported.
6
-
7
The priority of a post depends on its comments. You can choose the way the priority
8
is calculated in the options screen.
9
-
10
Feel free to visit my website under www.arnebrachhold.de or contact me at
11
himself [at] arnebrachhold [dot] de
12
-
13
- Have fun!
14
Arne
15
-
16
Installation:
17
==============================================================================
18
1. Upload the full directory into your wp-content/plugins directory
19
- 2. Make your blog directory writeable OR create two files called sitemap.xml
20
and sitemap.xml.gz and make them writeable via CHMOD In most cases, your blog directory is already writeable.
21
2. Activate it in the Plugin options
22
3. Edit or publish a post or click on Rebuild Sitemap on the Sitemap Administration Interface
23
-
24
-
25
Additional contributors:
26
==============================================================================
27
Inspiration Michael Nguyen http://www.socialpatterns.com/
@@ -33,16 +33,16 @@
33
Simpl.Chinese File june6 http://www.june6.cn/
34
Swedish Lang. File Tobias Bergius http://tobiasbergius.se/
35
Czech Lang. File Peter Kahoun http://kahi.cz
36
- Finnish Lang. File Olli Jarva http://kuvat.blog.olli.jarva.fi/
37
Belorussian Lang. File Marcis Gasuns
38
Bulgarian Lang. File Alexander Dichev http://dichev.com
39
-
40
- Thanks to all contributors and bug reporters! There were much more people involved
41
in testing this plugin and reporting bugs, either by email or in the WordPress forums.
42
-
43
Unfortunately I can't maintain a whole list here, but thanks again to everybody not listed here!
44
-
45
-
46
Release History:
47
==============================================================================
48
2005-06-05 1.0 First release
@@ -57,7 +57,7 @@
57
Fixed bug which ignored different post/page priorities
58
Should support now different wordpress/admin directories
59
2005-06-07 2.11 Fixed bug with hardcoded table table names instead of the $wpd vars
60
- 2005-06-07 2.12 Changed SQL Statement of the categories to get it work on MySQL 3
61
2005-06-08 2.2 Added language file support:
62
- Japanese Language Files and code modifications by hiromasa (http://hiromasa.zone.ne.jp/)
63
- German Language File by Arne Brachhold (http://www.arnebrachhold.de)
@@ -212,7 +212,7 @@
212
2009-11-13 3.1.9 Fixed MySQL Error if author pages were included
213
2009-11-23 3.2 Added function to show the actual results of a ping instead of only linking to the url
214
Added new hook (sm_rebuild) for third party plugins to start building the sitemap
215
- Fixed bug which showed the wrong URL for the latest Google ping result
216
Added some missing phpdoc documentation
217
Removed hardcoded php name for sitemap file for admin urls
218
Uses KSES for showing ping test results
@@ -240,12 +240,13 @@
240
2012-08-08 3.2.8 Fixed wrong custom taxonomy URLs, thanks to ramon fincken of the wordpress.org forum!
241
Removed ASK ping since they shut down their service.
242
Exclude post_format taxonomy from custom taxonomy list
243
244
Maybe Todo:
245
==============================================================================
246
- Your wishes :)
247
-
248
-
249
License:
250
==============================================================================
251
Copyright 2005 - 2012 ARNE BRACHHOLD (email : himself - arnebrachhold - de)
@@ -254,7 +255,7 @@
254
it under the terms of the GNU General Public License as published by
255
the Free Software Foundation; either version 2 of the License, or
256
(at your option) any later version.
257
-
258
This program is distributed in the hope that it will be useful,
259
but WITHOUT ANY WARRANTY; without even the implied warranty of
260
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -263,33 +264,33 @@
263
You should have received a copy of the GNU General Public License
264
along with this program; if not, write to the Free Software
265
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
266
-
267
-
268
Developer Documentation
269
==============================================================================
270
-
271
Adding other pages to the sitemap via other plugins
272
-
273
This plugin uses the action system of WordPress to allow other plugins
274
to add urls to the sitemap. Simply add your function with add_action to
275
the list and the plugin will execute yours every time the sitemap is build.
276
- Use the static method "GetInstance" to get the generator and AddUrl method
277
to add your content.
278
-
279
Sample:
280
-
281
function your_pages() {
282
$generatorObject = &GoogleSitemapGenerator::GetInstance(); //Please note the "&" sign for PHP4!
283
if($generatorObject!=null) $generatorObject->AddUrl("http://blog.uri/tags/hello/",time(),"daily",0.5);
284
}
285
add_action("sm_buildmap","your_pages");
286
-
287
Parameters:
288
- The URL to the page
289
- The last modified data, as a UNIX timestamp (optional)
290
- The Change Frequency (daily, hourly, weekly and so on) (optional)
291
- The priority 0.0 to 1.0 (optional)
292
-
293
294
Rebuilding the sitemap on request
295
@@ -298,38 +299,38 @@
298
All other methods, like calling the Build method directly are highly unrecommended and might
299
not work anymore with the next version of the plugin. Using this hook, the sitemap plugin will
300
take care of everything like loading the required classes and so on.
301
-
302
Sample:
303
-
304
do_action("sm_rebuild");
305
-
306
The sitemap might not be rebuild immediately, since newer versions use a background WP-Cron
307
job by default to prevent that the user has to wait and avoid multiple rebuilds within a very short time.
308
In case the sitemap plugin is not installed, nothing will happen and no errors will be thrown.
309
-
310
===============================================
311
-
312
Adding additional PriorityProviders
313
-
314
This plugin uses several classes to calculate the post priority.
315
You can register your own provider and choose it at the options screen.
316
-
317
Your class has to extend the GoogleSitemapGeneratorPrioProviderBase class
318
which has a default constructor and a method called GetPostPriority
319
which you can override.
320
-
321
Look at the GoogleSitemapGeneratorPrioByPopularityContestProvider class
322
for an example.
323
-
324
To register your provider to the sitemap generator, use the following filter:
325
-
326
add_filter("sm_add_prio_provider","AddMyProvider");
327
-
328
Your function could look like this:
329
-
330
function AddMyProvider($providers) {
331
array_push($providers,"MyProviderClass");
332
return $providers;
333
}
334
-
335
- Note that you have to return the modified list!
1
 Google XML Sitemaps Generator for WordPress
2
==============================================================================
3
+
4
This generator will create a sitemaps.org compliant sitemap of your WordPress blog.
5
Currently homepage, posts, static pages, categories, archives and author pages are supported.
6
+
7
The priority of a post depends on its comments. You can choose the way the priority
8
is calculated in the options screen.
9
+
10
Feel free to visit my website under www.arnebrachhold.de or contact me at
11
himself [at] arnebrachhold [dot] de
12
+
13
+ Have fun!
14
Arne
15
+
16
Installation:
17
==============================================================================
18
1. Upload the full directory into your wp-content/plugins directory
19
+ 2. Make your blog directory writeable OR create two files called sitemap.xml
20
and sitemap.xml.gz and make them writeable via CHMOD In most cases, your blog directory is already writeable.
21
2. Activate it in the Plugin options
22
3. Edit or publish a post or click on Rebuild Sitemap on the Sitemap Administration Interface
23
+
24
+
25
Additional contributors:
26
==============================================================================
27
Inspiration Michael Nguyen http://www.socialpatterns.com/
33
Simpl.Chinese File june6 http://www.june6.cn/
34
Swedish Lang. File Tobias Bergius http://tobiasbergius.se/
35
Czech Lang. File Peter Kahoun http://kahi.cz
36
+ Finnish Lang. File Olli Jarva http://kuvat.blog.olli.jarva.fi/
37
Belorussian Lang. File Marcis Gasuns
38
Bulgarian Lang. File Alexander Dichev http://dichev.com
39
+
40
+ Thanks to all contributors and bug reporters! There were much more people involved
41
in testing this plugin and reporting bugs, either by email or in the WordPress forums.
42
+
43
Unfortunately I can't maintain a whole list here, but thanks again to everybody not listed here!
44
+
45
+
46
Release History:
47
==============================================================================
48
2005-06-05 1.0 First release
57
Fixed bug which ignored different post/page priorities
58
Should support now different wordpress/admin directories
59
2005-06-07 2.11 Fixed bug with hardcoded table table names instead of the $wpd vars
60
+ 2005-06-07 2.12 Changed SQL Statement of the categories to get it work on MySQL 3
61
2005-06-08 2.2 Added language file support:
62
- Japanese Language Files and code modifications by hiromasa (http://hiromasa.zone.ne.jp/)
63
- German Language File by Arne Brachhold (http://www.arnebrachhold.de)
212
2009-11-13 3.1.9 Fixed MySQL Error if author pages were included
213
2009-11-23 3.2 Added function to show the actual results of a ping instead of only linking to the url
214
Added new hook (sm_rebuild) for third party plugins to start building the sitemap
215
+ Fixed bug which showed the wrong URL for the latest Google ping result
216
Added some missing phpdoc documentation
217
Removed hardcoded php name for sitemap file for admin urls
218
Uses KSES for showing ping test results
240
2012-08-08 3.2.8 Fixed wrong custom taxonomy URLs, thanks to ramon fincken of the wordpress.org forum!
241
Removed ASK ping since they shut down their service.
242
Exclude post_format taxonomy from custom taxonomy list
243
+ 2013-01-11 3.2.9 Fixed security issue with change frequencies and filename of sitemap file. Exploit was only possible for admin accounts.
244
245
Maybe Todo:
246
==============================================================================
247
- Your wishes :)
248
+
249
+
250
License:
251
==============================================================================
252
Copyright 2005 - 2012 ARNE BRACHHOLD (email : himself - arnebrachhold - de)
255
it under the terms of the GNU General Public License as published by
256
the Free Software Foundation; either version 2 of the License, or
257
(at your option) any later version.
258
+
259
This program is distributed in the hope that it will be useful,
260
but WITHOUT ANY WARRANTY; without even the implied warranty of
261
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
264
You should have received a copy of the GNU General Public License
265
along with this program; if not, write to the Free Software
266
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
267
+
268
+
269
Developer Documentation
270
==============================================================================
271
+
272
Adding other pages to the sitemap via other plugins
273
+
274
This plugin uses the action system of WordPress to allow other plugins
275
to add urls to the sitemap. Simply add your function with add_action to
276
the list and the plugin will execute yours every time the sitemap is build.
277
+ Use the static method "GetInstance" to get the generator and AddUrl method
278
to add your content.
279
+
280
Sample:
281
+
282
function your_pages() {
283
$generatorObject = &GoogleSitemapGenerator::GetInstance(); //Please note the "&" sign for PHP4!
284
if($generatorObject!=null) $generatorObject->AddUrl("http://blog.uri/tags/hello/",time(),"daily",0.5);
285
}
286
add_action("sm_buildmap","your_pages");
287
+
288
Parameters:
289
- The URL to the page
290
- The last modified data, as a UNIX timestamp (optional)
291
- The Change Frequency (daily, hourly, weekly and so on) (optional)
292
- The priority 0.0 to 1.0 (optional)
293
+
294
295
Rebuilding the sitemap on request
296
299
All other methods, like calling the Build method directly are highly unrecommended and might
300
not work anymore with the next version of the plugin. Using this hook, the sitemap plugin will
301
take care of everything like loading the required classes and so on.
302
+
303
Sample:
304
+
305
do_action("sm_rebuild");
306
+
307
The sitemap might not be rebuild immediately, since newer versions use a background WP-Cron
308
job by default to prevent that the user has to wait and avoid multiple rebuilds within a very short time.
309
In case the sitemap plugin is not installed, nothing will happen and no errors will be thrown.
310
+
311
===============================================
312
+
313
Adding additional PriorityProviders
314
+
315
This plugin uses several classes to calculate the post priority.
316
You can register your own provider and choose it at the options screen.
317
+
318
Your class has to extend the GoogleSitemapGeneratorPrioProviderBase class
319
which has a default constructor and a method called GetPostPriority
320
which you can override.
321
+
322
Look at the GoogleSitemapGeneratorPrioByPopularityContestProvider class
323
for an example.
324
+
325
To register your provider to the sitemap generator, use the following filter:
326
+
327
add_filter("sm_add_prio_provider","AddMyProvider");
328
+
329
Your function could look like this:
330
+
331
function AddMyProvider($providers) {
332
array_push($providers,"MyProviderClass");
333
return $providers;
334
}
335
+
336
+ Note that you have to return the modified list!
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: arnee
3
Donate link: http://www.arnebrachhold.de/redir/sitemap-paypal
4
Tags: seo, google, sitemaps, google sitemaps, yahoo, msn, ask, live, xml sitemap, xml
5
Requires at least: 2.1
6
- Tested up to: 3.5
7
- Stable tag: 3.2.7
8
9
This plugin will generate a special XML sitemap which will help search engines to better index your blog.
10
@@ -12,10 +12,6 @@ This plugin will generate a special XML sitemap which will help search engines t
12
13
This plugin will generate a special XML sitemap which will help search engines like Google, Bing, Yahoo and Ask.com to better index your blog. With such a sitemap, it's much easier for the crawlers to see the complete structure of your site and retrieve it more efficiently. The plugin supports all kinds of WordPress generated pages as well as custom URLs. Additionally it notifies all major search engines every time you create a post about the new content.
14
15
-
16
- > #### Try out the brand new Beta version!
17
- > Download the new beta version and try the new features like dynamic sitemap generation, full support for network activation, reduced memory usage and much more! <a href="http://www.arnebrachhold.de/redir/sitemap-dl-beta/">Download the beta version here!</a>
18
-
19
Related Links:
20
21
* <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/" title="Google XML Sitemaps Plugin for WordPress">Plugin Homepage</a>
3
Donate link: http://www.arnebrachhold.de/redir/sitemap-paypal
4
Tags: seo, google, sitemaps, google sitemaps, yahoo, msn, ask, live, xml sitemap, xml
5
Requires at least: 2.1
6
+ Tested up to: 3.6
7
+ Stable tag: 3.2.9
8
9
This plugin will generate a special XML sitemap which will help search engines to better index your blog.
10
12
13
This plugin will generate a special XML sitemap which will help search engines like Google, Bing, Yahoo and Ask.com to better index your blog. With such a sitemap, it's much easier for the crawlers to see the complete structure of your site and retrieve it more efficiently. The plugin supports all kinds of WordPress generated pages as well as custom URLs. Additionally it notifies all major search engines every time you create a post about the new content.
14
15
Related Links:
16
17
* <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/" title="Google XML Sitemaps Plugin for WordPress">Plugin Homepage</a>
sitemap-core.php CHANGED
@@ -1,7 +1,7 @@
1
<?php
2
/*
3
-
4
- $Id: sitemap-core.php 583237 2012-08-08 21:06:12Z arnee $
5
6
*/
7
@@ -19,21 +19,21 @@ class GoogleSitemapGeneratorStatus {
19
20
function GoogleSitemapGeneratorStatus() {
21
$this->_startTime = $this->GetMicrotimeFloat();
22
-
23
$exists = get_option("sm_status");
24
-
25
if($exists === false) add_option("sm_status","",null,"no");
26
-
27
$this->Save();
28
}
29
-
30
function Save() {
31
update_option("sm_status",$this);
32
}
33
-
34
/**
35
* Returns the last saved status object or null
36
- *
37
* @return GoogleSitemapGeneratorStatus
38
*/
39
function &Load() {
@@ -41,53 +41,53 @@ class GoogleSitemapGeneratorStatus {
41
if(is_a($status,"GoogleSitemapGeneratorStatus")) return $status;
42
else return null;
43
}
44
-
45
/**
46
* @var float $_startTime The start time of the building process
47
* @access private
48
*/
49
var $_startTime = 0;
50
-
51
/**
52
* @var float $_endTime The end time of the building process
53
* @access private
54
*/
55
var $_endTime = 0;
56
-
57
/**
58
* @var bool $_hasChanged Indicates if the sitemap content has changed
59
* @access private
60
*/
61
var $_hasChanged = true;
62
-
63
/**
64
* @var int $_memoryUsage The amount of memory used in bytes
65
* @access private
66
*/
67
var $_memoryUsage = 0;
68
-
69
/**
70
* @var int $_lastPost The number of posts processed. This value is updated every 50 posts.
71
* @access private
72
*/
73
var $_lastPost = 0;
74
-
75
/**
76
* @var int $_lastTime The time when the last step-update occured. This value is updated every 50 posts.
77
* @access private
78
*/
79
var $_lastTime = 0;
80
-
81
function End($hasChanged = true) {
82
$this->_endTime = $this->GetMicrotimeFloat();
83
-
84
$this->SetMemoryUsage();
85
-
86
$this->_hasChanged = $hasChanged;
87
-
88
$this->Save();
89
}
90
-
91
function SetMemoryUsage() {
92
if(function_exists("memory_get_peak_usage")) {
93
$this->_memoryUsage = memory_get_peak_usage(true);
@@ -95,130 +95,130 @@ class GoogleSitemapGeneratorStatus {
95
$this->_memoryUsage = memory_get_usage(true);
96
}
97
}
98
-
99
function GetMemoryUsage() {
100
return round($this->_memoryUsage / 1024 / 1024,2);
101
}
102
-
103
function SaveStep($postCount) {
104
$this->SetMemoryUsage();
105
$this->_lastPost = $postCount;
106
$this->_lastTime = $this->GetMicrotimeFloat();
107
-
108
$this->Save();
109
}
110
-
111
function GetTime() {
112
return round($this->_endTime - $this->_startTime,2);
113
}
114
-
115
function GetStartTime() {
116
return round($this->_startTime, 2);
117
}
118
-
119
function GetLastTime() {
120
return round($this->_lastTime - $this->_startTime,2);
121
}
122
-
123
function GetLastPost() {
124
return $this->_lastPost;
125
}
126
-
127
var $_usedXml = false;
128
var $_xmlSuccess = false;
129
var $_xmlPath = '';
130
var $_xmlUrl = '';
131
-
132
function StartXml($path,$url) {
133
$this->_usedXml = true;
134
$this->_xmlPath = $path;
135
$this->_xmlUrl = $url;
136
-
137
$this->Save();
138
}
139
-
140
function EndXml($success) {
141
$this->_xmlSuccess = $success;
142
-
143
$this->Save();
144
}
145
-
146
-
147
var $_usedZip = false;
148
var $_zipSuccess = false;
149
var $_zipPath = '';
150
var $_zipUrl = '';
151
-
152
function StartZip($path,$url) {
153
$this->_usedZip = true;
154
$this->_zipPath = $path;
155
$this->_zipUrl = $url;
156
-
157
$this->Save();
158
}
159
-
160
function EndZip($success) {
161
$this->_zipSuccess = $success;
162
-
163
$this->Save();
164
}
165
-
166
var $_usedGoogle = false;
167
var $_googleUrl = '';
168
var $_gooogleSuccess = false;
169
var $_googleStartTime = 0;
170
var $_googleEndTime = 0;
171
-
172
function StartGooglePing($url) {
173
$this->_googleUrl = $url;
174
$this->_usedGoogle = true;
175
$this->_googleStartTime = $this->GetMicrotimeFloat();
176
-
177
$this->Save();
178
}
179
-
180
function EndGooglePing($success) {
181
$this->_googleEndTime = $this->GetMicrotimeFloat();
182
$this->_gooogleSuccess = $success;
183
-
184
$this->Save();
185
}
186
-
187
function GetGoogleTime() {
188
return round($this->_googleEndTime - $this->_googleStartTime,2);
189
}
190
-
191
var $_usedMsn = false;
192
var $_msnUrl = '';
193
var $_msnSuccess = false;
194
var $_msnStartTime = 0;
195
var $_msnEndTime = 0;
196
-
197
function StartMsnPing($url) {
198
$this->_usedMsn = true;
199
$this->_msnUrl = $url;
200
$this->_msnStartTime = $this->GetMicrotimeFloat();
201
-
202
$this->Save();
203
}
204
-
205
function EndMsnPing($success) {
206
$this->_msnEndTime = $this->GetMicrotimeFloat();
207
$this->_msnSuccess = $success;
208
-
209
$this->Save();
210
}
211
-
212
function GetMsnTime() {
213
return round($this->_msnEndTime - $this->_msnStartTime,2);
214
}
215
-
216
function GetMicrotimeFloat() {
217
list($usec, $sec) = explode(" ", microtime());
218
return ((float)$usec + (float)$sec);
219
}
220
}
221
-
222
/**
223
* Represents an item in the page list
224
* @author Arne Brachhold
@@ -226,31 +226,31 @@ class GoogleSitemapGeneratorStatus {
226
* @since 3.0
227
*/
228
class GoogleSitemapGeneratorPage {
229
-
230
/**
231
* @var string $_url Sets the URL or the relative path to the blog dir of the page
232
* @access private
233
*/
234
var $_url;
235
-
236
/**
237
* @var float $_priority Sets the priority of this page
238
* @access private
239
*/
240
var $_priority;
241
-
242
/**
243
* @var string $_changeFreq Sets the chanfe frequency of the page. I want Enums!
244
* @access private
245
*/
246
var $_changeFreq;
247
-
248
/**
249
* @var int $_lastMod Sets the lastMod date as a UNIX timestamp.
250
* @access private
251
*/
252
var $_lastMod;
253
-
254
/**
255
* Initialize a new page object
256
*
@@ -269,7 +269,7 @@ class GoogleSitemapGeneratorPage {
269
$this->SetChangeFreq($changeFreq);
270
$this->SetLastMod($lastMod);
271
}
272
-
273
/**
274
* Returns the URL of the page
275
*
@@ -278,7 +278,7 @@ class GoogleSitemapGeneratorPage {
278
function GetUrl() {
279
return $this->_url;
280
}
281
-
282
/**
283
* Sets the URL of the page
284
*
@@ -287,7 +287,7 @@ class GoogleSitemapGeneratorPage {
287
function SetUrl($url) {
288
$this->_url=(string) $url;
289
}
290
-
291
/**
292
* Returns the priority of this page
293
*
@@ -296,7 +296,7 @@ class GoogleSitemapGeneratorPage {
296
function GetPriority() {
297
return $this->_priority;
298
}
299
-
300
/**
301
* Sets the priority of the page
302
*
@@ -305,7 +305,7 @@ class GoogleSitemapGeneratorPage {
305
function SetProprity($priority) {
306
$this->_priority=floatval($priority);
307
}
308
-
309
/**
310
* Returns the change frequency of the page
311
*
@@ -314,7 +314,7 @@ class GoogleSitemapGeneratorPage {
314
function GetChangeFreq() {
315
return $this->_changeFreq;
316
}
317
-
318
/**
319
* Sets the change frequency of the page
320
*
@@ -323,7 +323,7 @@ class GoogleSitemapGeneratorPage {
323
function SetChangeFreq($changeFreq) {
324
$this->_changeFreq=(string) $changeFreq;
325
}
326
-
327
/**
328
* Returns the last mod of the page
329
*
@@ -332,7 +332,7 @@ class GoogleSitemapGeneratorPage {
332
function GetLastMod() {
333
return $this->_lastMod;
334
}
335
-
336
/**
337
* Sets the last mod of the page
338
*
@@ -341,41 +341,41 @@ class GoogleSitemapGeneratorPage {
341
function SetLastMod($lastMod) {
342
$this->_lastMod=intval($lastMod);
343
}
344
-
345
function Render() {
346
-
347
if($this->_url == "/" || empty($this->_url)) return '';
348
-
349
$r="";
350
$r.= "\t<url>\n";
351
$r.= "\t\t<loc>" . $this->EscapeXML($this->_url) . "</loc>\n";
352
if($this->_lastMod>0) $r.= "\t\t<lastmod>" . date('Y-m-d\TH:i:s+00:00',$this->_lastMod) . "</lastmod>\n";
353
- if(!empty($this->_changeFreq)) $r.= "\t\t<changefreq>" . $this->_changeFreq . "</changefreq>\n";
354
if($this->_priority!==false && $this->_priority!=="") $r.= "\t\t<priority>" . number_format($this->_priority,1) . "</priority>\n";
355
$r.= "\t</url>\n";
356
return $r;
357
}
358
-
359
function EscapeXML($string) {
360
return str_replace ( array ( '&', '"', "'", '<', '>'), array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;'), $string);
361
}
362
}
363
364
class GoogleSitemapGeneratorXmlEntry {
365
-
366
var $_xml;
367
-
368
function GoogleSitemapGeneratorXmlEntry($xml) {
369
$this->_xml = $xml;
370
}
371
-
372
function Render() {
373
return $this->_xml;
374
}
375
}
376
377
class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry {
378
-
379
function Render() {
380
return "<!-- " . $this->_xml . " -->\n";
381
}
@@ -388,19 +388,19 @@ class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry {
388
* @since 3.0
389
*/
390
class GoogleSitemapGeneratorPrioProviderBase {
391
-
392
/**
393
* @var int $_totalComments The total number of comments of all posts
394
* @access protected
395
*/
396
var $_totalComments=0;
397
-
398
/**
399
* @var int $_totalComments The total number of posts
400
* @access protected
401
*/
402
var $_totalPosts=0;
403
-
404
/**
405
* Returns the (translated) name of this priority provider
406
*
@@ -412,7 +412,7 @@ class GoogleSitemapGeneratorPrioProviderBase {
412
function GetName() {
413
return "";
414
}
415
-
416
/**
417
* Returns the (translated) description of this priority provider
418
*
@@ -424,7 +424,7 @@ class GoogleSitemapGeneratorPrioProviderBase {
424
function GetDescription() {
425
return "";
426
}
427
-
428
/**
429
* Initializes a new priority provider
430
*
@@ -437,9 +437,9 @@ class GoogleSitemapGeneratorPrioProviderBase {
437
function GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts) {
438
$this->_totalComments=$totalComments;
439
$this->_totalPosts=$totalPosts;
440
-
441
}
442
-
443
/**
444
* Returns the priority for a specified post
445
*
@@ -462,7 +462,7 @@ class GoogleSitemapGeneratorPrioProviderBase {
462
* @since 3.0
463
*/
464
class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPrioProviderBase {
465
-
466
/**
467
* Returns the (translated) name of this priority provider
468
*
@@ -474,7 +474,7 @@ class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPr
474
function GetName() {
475
return __("Comment Count",'sitemap');
476
}
477
-
478
/**
479
* Returns the (translated) description of this priority provider
480
*
@@ -486,7 +486,7 @@ class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPr
486
function GetDescription() {
487
return __("Uses the number of comments of the post to calculate the priority",'sitemap');
488
}
489
-
490
/**
491
* Initializes a new priority provider which calculates the post priority based on the number of comments
492
*
@@ -499,7 +499,7 @@ class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPr
499
function GoogleSitemapGeneratorPrioByCountProvider($totalComments,$totalPosts) {
500
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
501
}
502
-
503
/**
504
* Returns the priority for a specified post
505
*
@@ -528,13 +528,13 @@ class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPr
528
* @since 3.0
529
*/
530
class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGeneratorPrioProviderBase {
531
-
532
/**
533
* @var int $_average The average number of comments per post
534
* @access protected
535
*/
536
var $_average=0.0;
537
-
538
/**
539
* Returns the (translated) name of this priority provider
540
*
@@ -546,7 +546,7 @@ class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGenerator
546
function GetName() {
547
return __("Comment Average",'sitemap');
548
}
549
-
550
/**
551
* Returns the (translated) description of this priority provider
552
*
@@ -558,7 +558,7 @@ class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGenerator
558
function GetDescription() {
559
return __("Uses the average comment count to calculate the priority",'sitemap');
560
}
561
-
562
/**
563
* Initializes a new priority provider which calculates the post priority based on the average number of comments
564
*
@@ -570,12 +570,12 @@ class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGenerator
570
*/
571
function GoogleSitemapGeneratorPrioByAverageProvider($totalComments,$totalPosts) {
572
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
573
-
574
if($this->_totalComments>0 && $this->_totalPosts>0) {
575
$this->_average= (double) $this->_totalComments / $this->_totalPosts;
576
}
577
}
578
-
579
/**
580
* Returns the priority for a specified post
581
*
@@ -597,7 +597,7 @@ class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGenerator
597
if($prio>1) $prio = 1;
598
else if($prio<0) $prio = 0;
599
}
600
-
601
return round($prio,1);
602
}
603
}
@@ -609,7 +609,7 @@ class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGenerator
609
* @since 3.0
610
*/
611
class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitemapGeneratorPrioProviderBase {
612
-
613
/**
614
* Returns the (translated) name of this priority provider
615
*
@@ -621,7 +621,7 @@ class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitema
621
function GetName() {
622
return __("Popularity Contest",'sitemap');
623
}
624
-
625
/**
626
* Returns the (translated) description of this priority provider
627
*
@@ -633,7 +633,7 @@ class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitema
633
function GetDescription() {
634
return str_replace("%4","index.php?page=popularity-contest.php",str_replace("%3","options-general.php?page=popularity-contest.php",str_replace("%2","http://www.alexking.org/",str_replace("%1","http://www.alexking.org/index.php?content=software/wordpress/content.php",__("Uses the activated <a href=\"%1\">Popularity Contest Plugin</a> from <a href=\"%2\">Alex King</a>. See <a href=\"%3\">Settings</a> and <a href=\"%4\">Most Popular Posts</a>",'sitemap')))));
635
}
636
-
637
/**
638
* Initializes a new priority provider which calculates the post priority based on the popularity by the PopularityContest Plugin
639
*
@@ -646,7 +646,7 @@ class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitema
646
function GoogleSitemapGeneratorPrioByPopularityContestProvider($totalComments,$totalPosts) {
647
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
648
}
649
-
650
/**
651
* Returns the priority for a specified post
652
*
@@ -660,7 +660,7 @@ class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitema
660
function GetPostPriority($postID,$commentCount) {
661
//$akpc is the global instance of the Popularity Contest Plugin
662
global $akpc,$posts;
663
-
664
$res=0;
665
//Better check if its there
666
if(!empty($akpc) && is_object($akpc)) {
@@ -696,13 +696,13 @@ class GoogleSitemapGenerator {
696
/**
697
* @var Version of the generator in SVN
698
*/
699
- var $_svnVersion = '$Id: sitemap-core.php 583237 2012-08-08 21:06:12Z arnee #x27;;
700
-
701
/**
702
* @var array The unserialized array with the stored options
703
*/
704
var $_options = array();
705
-
706
/**
707
* @var array The saved additional pages
708
*/
@@ -712,32 +712,32 @@ class GoogleSitemapGenerator {
712
* @var array The values and names of the change frequencies
713
*/
714
var $_freqNames = array();
715
-
716
/**
717
* @var array A list of class names which my be called for priority calculation
718
*/
719
var $_prioProviders = array();
720
-
721
/**
722
* @var bool True if init complete (options loaded etc)
723
*/
724
var $_initiated = false;
725
-
726
/**
727
* @var string Holds the last error if one occurs when writing the files
728
*/
729
var $_lastError=null;
730
-
731
/**
732
* @var int The last handled post ID
733
*/
734
var $_lastPostID = 0;
735
-
736
/**
737
* @var bool Defines if the sitemap building process is active at the moment
738
*/
739
var $_isActive = false;
740
-
741
/**
742
* @var bool Defines if the sitemap building process has been scheduled via Wp cron
743
*/
@@ -747,20 +747,20 @@ class GoogleSitemapGenerator {
747
* @var object The file handle which is used to write the sitemap file
748
*/
749
var $_fileHandle = null;
750
-
751
/**
752
* @var object The file handle which is used to write the zipped sitemap file
753
*/
754
var $_fileZipHandle = null;
755
-
756
/**
757
* Holds the user interface object
758
- *
759
* @since 3.1.1
760
* @var GoogleSitemapGeneratorUI
761
*/
762
var $_ui = null;
763
-
764
/**
765
* Returns the path to the blog directory
766
*
@@ -770,7 +770,7 @@ class GoogleSitemapGenerator {
770
* @return string The full path to the blog directory
771
*/
772
function GetHomePath() {
773
-
774
$res="";
775
//Check if we are in the admin area -> get_home_path() is avaiable
776
if(function_exists("get_home_path")) {
@@ -794,7 +794,7 @@ class GoogleSitemapGenerator {
794
}
795
return $res;
796
}
797
-
798
/**
799
* Returns the path to the directory where the plugin file is located
800
* @since 3.0b5
@@ -806,7 +806,7 @@ class GoogleSitemapGenerator {
806
$path = dirname(__FILE__);
807
return trailingslashit(str_replace("\\","/",$path));
808
}
809
-
810
/**
811
* Returns the URL to the directory where the plugin file is located
812
* @since 3.0b5
@@ -815,17 +815,17 @@ class GoogleSitemapGenerator {
815
* @return string The URL to the plugin directory
816
*/
817
function GetPluginUrl() {
818
-
819
//Try to use WP API if possible, introduced in WP 2.6
820
if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__))));
821
-
822
//Try to find manually... can't work if wp-content was renamed or is redirected
823
$path = dirname(__FILE__);
824
$path = str_replace("\\","/",$path);
825
$path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));
826
return $path;
827
}
828
-
829
/**
830
* Returns the URL to default XSLT style if it exists
831
* @since 3.0b5
@@ -843,7 +843,7 @@ class GoogleSitemapGenerator {
843
}
844
return '';
845
}
846
-
847
/**
848
* Sets up the default configuration
849
*
@@ -852,7 +852,7 @@ class GoogleSitemapGenerator {
852
* @author Arne Brachhold
853
*/
854
function InitOptions() {
855
-
856
$this->_options=array();
857
$this->_options["sm_b_prio_provider"]="GoogleSitemapGeneratorPrioByCountProvider"; //Provider for automatic priority calculation
858
$this->_options["sm_b_filename"]="sitemap.xml"; //Name of the Sitemap file
@@ -907,7 +907,7 @@ class GoogleSitemapGenerator {
907
$this->_options["sm_pr_arch"]=0.3; //Priority of archives
908
$this->_options["sm_pr_auth"]=0.3; //Priority of author pages
909
$this->_options["sm_pr_tags"]=0.3; //Priority of tags
910
-
911
$this->_options["sm_i_donated"]=false; //Did you donate? Thank you! :)
912
$this->_options["sm_i_hide_donated"]=false; //And hide the thank you..
913
$this->_options["sm_i_install_date"]=time(); //The installation date
@@ -915,7 +915,7 @@ class GoogleSitemapGenerator {
915
$this->_options["sm_i_hide_works"]=false; //Hide the "works?" message which appears after 15 days
916
$this->_options["sm_i_hide_donors"]=false; //Hide the list of donations
917
}
918
-
919
/**
920
* Loads the configuration from the database
921
*
@@ -924,9 +924,9 @@ class GoogleSitemapGenerator {
924
* @author Arne Brachhold
925
*/
926
function LoadOptions() {
927
-
928
$this->InitOptions();
929
-
930
//First init default values, then overwrite it with stored values so we can add default
931
//values with an update which get stored by the next edit.
932
$storedoptions=get_option("sm_options");
@@ -936,7 +936,7 @@ class GoogleSitemapGenerator {
936
}
937
} else update_option("sm_options",$this->_options); //First time use, store default values
938
}
939
-
940
/**
941
* Initializes a new Google Sitemap Generator
942
*
@@ -947,10 +947,10 @@ class GoogleSitemapGenerator {
947
function GoogleSitemapGenerator() {
948
949
950
-
951
-
952
}
953
-
954
/**
955
* Returns the version of the generator
956
*
@@ -962,7 +962,7 @@ class GoogleSitemapGenerator {
962
function GetVersion() {
963
return GoogleSitemapGeneratorLoader::GetVersion();
964
}
965
-
966
/**
967
* Returns all parent classes of a class
968
*
@@ -982,7 +982,7 @@ class GoogleSitemapGenerator {
982
}
983
return $parents;
984
}
985
-
986
/**
987
* Returns if a class is a subclass of another class
988
*
@@ -995,17 +995,17 @@ class GoogleSitemapGenerator {
995
* @return bool true if the given class is a subclass of the other one
996
*/
997
function IsSubclassOf($className, $parentName) {
998
-
999
$className = strtolower($className);
1000
$parentName = strtolower($parentName);
1001
-
1002
if(empty($className) || empty($parentName) || !class_exists($className) || !class_exists($parentName)) return false;
1003
-
1004
$parents=$this->GetParentClasses($className);
1005
-
1006
return in_array($parentName,$parents);
1007
}
1008
-
1009
/**
1010
* Loads up the configuration and validates the prioity providers
1011
*
@@ -1017,7 +1017,7 @@ class GoogleSitemapGenerator {
1017
*/
1018
function Initate() {
1019
if(!$this->_initiated) {
1020
-
1021
//Loading language file...
1022
//load_plugin_textdomain('sitemap');
1023
//Hmm, doesn't work if the plugin file has its own directory.
@@ -1027,7 +1027,7 @@ class GoogleSitemapGenerator {
1027
$moFile = dirname(__FILE__) . "/lang/sitemap-" . $currentLocale . ".mo";
1028
if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('sitemap', $moFile);
1029
}
1030
-
1031
$this->_freqNames = array(
1032
"always"=>__("Always","sitemap"),
1033
"hourly"=>__("Hourly","sitemap"),
@@ -1037,26 +1037,26 @@ class GoogleSitemapGenerator {
1037
"yearly"=>__("Yearly","sitemap"),
1038
"never"=>__("Never","sitemap")
1039
);
1040
-
1041
-
1042
$this->LoadOptions();
1043
$this->LoadPages();
1044
-
1045
//Register our own priority providers
1046
add_filter("sm_add_prio_provider",array(&$this, 'AddDefaultPrioProviders'));
1047
-
1048
//Let other plugins register their providers
1049
$r = apply_filters("sm_add_prio_provider",$this->_prioProviders);
1050
-
1051
//Check if no plugin return null
1052
if($r != null) $this->_prioProviders = $r;
1053
-
1054
$this->ValidatePrioProviders();
1055
-
1056
$this->_initiated = true;
1057
}
1058
}
1059
-
1060
/**
1061
* Returns the instance of the Sitemap Generator
1062
*
@@ -1070,7 +1070,7 @@ class GoogleSitemapGenerator {
1070
return $GLOBALS["sm_instance"];
1071
} else return null;
1072
}
1073
-
1074
/**
1075
* Returns if the sitemap building process is currently active
1076
*
@@ -1083,7 +1083,7 @@ class GoogleSitemapGenerator {
1083
$inst = &GoogleSitemapGenerator::GetInstance();
1084
return ($inst != null && $inst->_isActive);
1085
}
1086
-
1087
/**
1088
* Returns if the compressed sitemap was activated
1089
*
@@ -1119,10 +1119,10 @@ class GoogleSitemapGenerator {
1119
function IsCustomPostTypesSupported() {
1120
return (function_exists("get_post_types") && function_exists("register_post_type"));
1121
}
1122
-
1123
/**
1124
* Returns the list of custom taxonies. These are basically all taxonomies without categories and post tags
1125
- *
1126
* @since 3.1.7
1127
* @return array Array of names of user-defined taxonomies
1128
*/
@@ -1133,7 +1133,7 @@ class GoogleSitemapGenerator {
1133
1134
/**
1135
* Returns the list of custom post types. These are all custome post types except post, page and attachment
1136
- *
1137
* @since 3.2.5
1138
* @author Lee Willis
1139
* @return array Array of custom post types as per get_post_types
@@ -1144,7 +1144,7 @@ class GoogleSitemapGenerator {
1144
$post_types = array_diff($post_types,array("post","page","attachment"));
1145
return $post_types;
1146
}
1147
-
1148
/**
1149
* Enables the Google Sitemap Generator and registers the WordPress hooks
1150
*
@@ -1157,7 +1157,7 @@ class GoogleSitemapGenerator {
1157
$GLOBALS["sm_instance"]=new GoogleSitemapGenerator();
1158
}
1159
}
1160
-
1161
/**
1162
* Checks if sitemap building after content changed is enabled and rebuild the sitemap
1163
*
@@ -1172,7 +1172,7 @@ class GoogleSitemapGenerator {
1172
$this->Initate();
1173
//Build one time per post and if not importing.
1174
if((($this->GetOption("b_auto_enabled")===true && $this->_lastPostID != $postID) || $external) && (!defined('WP_IMPORTING') || WP_IMPORTING != true)) {
1175
-
1176
//Build the sitemap directly or schedule it with WP cron
1177
if($this->GetOption("b_auto_delay")==true && floatval($wp_version) >= 2.1) {
1178
if(!$this->_isScheduled) {
@@ -1191,17 +1191,17 @@ class GoogleSitemapGenerator {
1191
$this->_lastPostID = $postID;
1192
}
1193
}
1194
-
1195
/**
1196
* Builds the sitemap by external request, for example other plugins.
1197
- *
1198
* @since 3.1.9
1199
* @return null
1200
*/
1201
function BuildNowRequest() {
1202
- $this->CheckForAutoBuild(null, true);
1203
}
1204
-
1205
/**
1206
* Checks if the rebuild request was send and starts to rebuilt the sitemap
1207
*
@@ -1229,7 +1229,7 @@ class GoogleSitemapGenerator {
1229
*/
1230
function ValidatePrioProviders() {
1231
$validProviders=array();
1232
-
1233
for($i=0; $i<count($this->_prioProviders); $i++) {
1234
if(class_exists($this->_prioProviders[$i])) {
1235
if($this->IsSubclassOf($this->_prioProviders[$i],"GoogleSitemapGeneratorPrioProviderBase")) {
@@ -1238,7 +1238,7 @@ class GoogleSitemapGenerator {
1238
}
1239
}
1240
$this->_prioProviders=$validProviders;
1241
-
1242
if(!$this->GetOption("b_prio_provider")) {
1243
if(!in_array($this->GetOption("b_prio_provider"),$this->_prioProviders,true)) {
1244
$this->SetOption("b_prio_provider","");
@@ -1261,7 +1261,7 @@ class GoogleSitemapGenerator {
1261
}
1262
return $providers;
1263
}
1264
-
1265
/**
1266
* Loads the stored pages from the database
1267
*
@@ -1271,27 +1271,27 @@ class GoogleSitemapGenerator {
1271
*/
1272
function LoadPages() {
1273
global $wpdb;
1274
-
1275
$needsUpdate=false;
1276
-
1277
$pagesString=$wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'sm_cpages'");
1278
-
1279
//Class sm_page was renamed with 3.0 -> rename it in serialized value for compatibility
1280
if(!empty($pagesString) && strpos($pagesString,"sm_page")!==false) {
1281
$pagesString = str_replace("O:7:\"sm_page\"","O:26:\"GoogleSitemapGeneratorPage\"",$pagesString);
1282
$needsUpdate=true;
1283
}
1284
-
1285
if(!empty($pagesString)) {
1286
$storedpages=unserialize($pagesString);
1287
$this->_pages=$storedpages;
1288
} else {
1289
$this->_pages=array();
1290
}
1291
-
1292
if($needsUpdate) $this->SavePages();
1293
}
1294
-
1295
/**
1296
* Saved the additional pages back to the database
1297
*
@@ -1311,8 +1311,8 @@ class GoogleSitemapGenerator {
1311
return true;
1312
}
1313
}
1314
-
1315
-
1316
/**
1317
* Returns the URL for the sitemap file
1318
*
@@ -1323,12 +1323,20 @@ class GoogleSitemapGenerator {
1323
* @return The URL to the Sitemap file
1324
*/
1325
function GetXmlUrl($forceAuto=false) {
1326
-
1327
if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") {
1328
- return $this->GetOption("b_fileurl_manual");
1329
} else {
1330
- return trailingslashit(get_bloginfo('url')). $this->GetOption("b_filename");
1331
}
1332
}
1333
1334
/**
@@ -1343,7 +1351,7 @@ class GoogleSitemapGenerator {
1343
function GetZipUrl($forceAuto=false) {
1344
return $this->GetXmlUrl($forceAuto) . ".gz";
1345
}
1346
-
1347
/**
1348
* Returns the file system path to the sitemap file
1349
*
@@ -1354,13 +1362,22 @@ class GoogleSitemapGenerator {
1354
* @return The file system path;
1355
*/
1356
function GetXmlPath($forceAuto=false) {
1357
if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") {
1358
- return $this->GetOption("b_filename_manual");
1359
} else {
1360
- return $this->GetHomePath() . $this->GetOption("b_filename");
1361
}
1362
}
1363
-
1364
/**
1365
* Returns the file system path to the gzipped sitemap file
1366
*
@@ -1373,7 +1390,7 @@ class GoogleSitemapGenerator {
1373
function GetZipPath($forceAuto=false) {
1374
return $this->GetXmlPath($forceAuto) . ".gz";
1375
}
1376
-
1377
/**
1378
* Returns the option value for the given key
1379
*
@@ -1389,7 +1406,7 @@ class GoogleSitemapGenerator {
1389
return $this->_options[$key];
1390
} else return null;
1391
}
1392
-
1393
/**
1394
* Sets an option to a new value
1395
*
@@ -1401,10 +1418,10 @@ class GoogleSitemapGenerator {
1401
*/
1402
function SetOption($key,$value) {
1403
if(strstr($key,"sm_")!==0) $key="sm_" . $key;
1404
-
1405
$this->_options[$key]=$value;
1406
}
1407
-
1408
/**
1409
* Saves the options back to the database
1410
*
@@ -1419,7 +1436,7 @@ class GoogleSitemapGenerator {
1419
return true;
1420
} else return update_option("sm_options",$this->_options);
1421
}
1422
-
1423
/**
1424
* Retrieves the number of comments of a post in a asso. array
1425
* The key is the postID, the value the number of comments
@@ -1442,7 +1459,7 @@ class GoogleSitemapGenerator {
1442
}
1443
return $comments;
1444
}
1445
-
1446
/**
1447
* Calculates the full number of comments from an sm_getComments() generated array
1448
*
@@ -1460,7 +1477,7 @@ class GoogleSitemapGenerator {
1460
}
1461
return $commentCount;
1462
}
1463
-
1464
/**
1465
* Adds a url to the sitemap. You can use this method or call AddElement directly.
1466
*
@@ -1478,10 +1495,10 @@ class GoogleSitemapGenerator {
1478
//Strip out the last modification time if activated
1479
if($this->GetOption('in_lastmod')===false) $lastMod = 0;
1480
$page = new GoogleSitemapGeneratorPage($loc, $priority, $changeFreq, $lastMod);
1481
-
1482
$this->AddElement($page);
1483
}
1484
-
1485
/**
1486
* Adds an element to the sitemap
1487
*
@@ -1492,18 +1509,18 @@ class GoogleSitemapGenerator {
1492
*/
1493
function AddElement(&$page) {
1494
if(empty($page)) return;
1495
-
1496
$s = $page->Render();
1497
-
1498
if($this->_fileZipHandle && $this->IsGzipEnabled()) {
1499
gzwrite($this->_fileZipHandle,$s);
1500
}
1501
-
1502
if($this->_fileHandle && $this->GetOption("b_xml")) {
1503
fwrite($this->_fileHandle,$s);
1504
}
1505
}
1506
-
1507
/**
1508
* Checks if a file is writable and tries to make it if not.
1509
*
@@ -1532,11 +1549,11 @@ class GoogleSitemapGenerator {
1532
//we can write, return 1/true/happy dance.
1533
return true;
1534
}
1535
-
1536
/**
1537
* Adds the sitemap to the virtual robots.txt file
1538
* This function is executed by WordPress with the do_robots hook
1539
- *
1540
* @since 3.1.2
1541
*/
1542
function DoRobots() {
@@ -1547,14 +1564,14 @@ class GoogleSitemapGenerator {
1547
if($this->IsGzipEnabled()) {
1548
$smUrl = $this->GetZipUrl();
1549
}
1550
-
1551
echo "\nSitemap: " . $smUrl . "\n";
1552
}
1553
}
1554
-
1555
/**
1556
* Builds the sitemap and writes it into a xml file.
1557
- *
1558
* ATTENTION PLUGIN DEVELOPERS! DONT CALL THIS METHOD DIRECTLY!
1559
* The method is probably not available, since it is only loaded when needed.
1560
* Use do_action("sm_rebuild"); if you want to rebuild the sitemap.
@@ -1568,87 +1585,87 @@ class GoogleSitemapGenerator {
1568
function BuildSitemap() {
1569
global $wpdb, $posts, $wp_version;
1570
$this->Initate();
1571
-
1572
if($this->GetOption("b_memory")!='') {
1573
@ini_set("memory_limit",$this->GetOption("b_memory"));
1574
}
1575
-
1576
if($this->GetOption("b_time")!=-1) {
1577
@set_time_limit($this->GetOption("b_time"));
1578
}
1579
-
1580
//This object saves the status information of the script directly to the database
1581
$status = new GoogleSitemapGeneratorStatus();
1582
-
1583
//Other plugins can detect if the building process is active
1584
$this->_isActive = true;
1585
-
1586
//$this->AddElement(new GoogleSitemapGeneratorXmlEntry());
1587
-
1588
//Debug mode?
1589
$debug=$this->GetOption("b_debug");
1590
-
1591
if($this->GetOption("b_xml")) {
1592
$fileName = $this->GetXmlPath();
1593
$status->StartXml($this->GetXmlPath(),$this->GetXmlUrl());
1594
-
1595
if($this->IsFileWritable($fileName)) {
1596
-
1597
$this->_fileHandle = fopen($fileName,"w");
1598
if(!$this->_fileHandle) $status->EndXml(false,"Not openable");
1599
-
1600
} else $status->EndXml(false,"not writable");
1601
}
1602
-
1603
//Write gzipped sitemap file
1604
if($this->IsGzipEnabled()) {
1605
$fileName = $this->GetZipPath();
1606
$status->StartZip($this->GetZipPath(),$this->GetZipUrl());
1607
-
1608
if($this->IsFileWritable($fileName)) {
1609
-
1610
$this->_fileZipHandle = gzopen($fileName,"w1");
1611
if(!$this->_fileZipHandle) $status->EndZip(false,"Not openable");
1612
-
1613
} else $status->EndZip(false,"not writable");
1614
}
1615
-
1616
if(!$this->_fileHandle && !$this->_fileZipHandle) {
1617
$status->End();
1618
return;
1619
}
1620
-
1621
-
1622
//Content of the XML file
1623
$this->AddElement(new GoogleSitemapGeneratorXmlEntry('<?xml version="1.0" encoding="UTF-8"' . '?' . '>'));
1624
-
1625
$styleSheet = ($this->GetDefaultStyle() && $this->GetOption('b_style_default')===true?$this->GetDefaultStyle():$this->GetOption('b_style'));
1626
-
1627
if(!empty($styleSheet)) {
1628
$this->AddElement(new GoogleSitemapGeneratorXmlEntry('<' . '?xml-stylesheet type="text/xsl" href="' . $styleSheet . '"?' . '>'));
1629
}
1630
-
1631
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("generator=\"wordpress/" . get_bloginfo('version') . "\""));
1632
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("sitemap-generator-url=\"http://www.arnebrachhold.de\" sitemap-generator-version=\"" . $this->GetVersion() . "\""));
1633
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("generated-on=\"" . date(get_option("date_format") . " " . get_option("time_format")) . "\""));
1634
-
1635
//All comments as an asso. Array (postID=>commentCount)
1636
$comments=($this->GetOption("b_prio_provider")!=""?$this->GetComments():array());
1637
-
1638
//Full number of comments
1639
$commentCount=(count($comments)>0?$this->GetCommentCount($comments):0);
1640
-
1641
if($debug && $this->GetOption("b_prio_provider")!="") {
1642
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Total comment count: " . $commentCount));
1643
}
1644
-
1645
//Go XML!
1646
$this->AddElement(new GoogleSitemapGeneratorXmlEntry('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'));
1647
-
1648
$home = get_bloginfo('url');
1649
-
1650
$homePid = 0;
1651
-
1652
//Add the home page (WITH a slash!)
1653
if($this->GetOption("in_home")) {
1654
if('page' == get_option('show_on_front') && get_option('page_on_front')) {
@@ -1662,58 +1679,58 @@ class GoogleSitemapGenerator {
1662
$this->AddUrl(trailingslashit($home),$this->GetTimestampFromMySql(get_lastpostmodified('GMT')),$this->GetOption("cf_home"),$this->GetOption("pr_home"));
1663
}
1664
}
1665
-
1666
//Add the posts
1667
if($this->GetOption("in_posts") || $this->GetOption("in_pages")) {
1668
-
1669
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Postings"));
1670
-
1671
//Pre 2.1 compatibility. 2.1 introduced 'future' as post_status so we don't need to check post_date
1672
$wpCompat = (floatval($wp_version) < 2.1);
1673
-
1674
$useQTransLate = false; //function_exists('qtrans_convertURL') && function_exists('qtrans_getEnabledLanguages'); Not really working yet
1675
-
1676
$excludes = $this->GetOption('b_exclude'); //Excluded posts and pages (user enetered ID)
1677
-
1678
$exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats
1679
-
1680
if($exclCats && count($exclCats)>0 && $this->IsTaxonomySupported()) {
1681
-
1682
$excludedCatPosts = get_objects_in_term($exclCats,"category"); // Get all posts in excl. cats. Unforttunately this also gives us pages, revisions and so on...
1683
-
1684
//Remove the pages, revisions etc from the exclude by category list, because they are always in the uncategorized one.
1685
if(count($excludedCatPosts)>0) {
1686
$exclPages = $wpdb->get_col("SELECT ID FROM `" . $wpdb->posts . "` WHERE post_type!='post' AND ID IN ('" . implode("','",$excludedCatPosts) . "')");
1687
-
1688
$exclPages = array_map('intval', $exclPages);
1689
-
1690
//Remove the pages from the exlusion list before
1691
if(count($exclPages)>0) $excludedCatPosts = array_diff($excludedCatPosts, $exclPages);
1692
-
1693
//Merge the category exclusion list with the users one
1694
if(count($excludedCatPosts)>0) $excludes = array_merge($excludes, $excludedCatPosts);
1695
}
1696
}
1697
-
1698
-
1699
$contentStmt = '';
1700
if($useQTransLate) {
1701
$contentStmt.=', post_content ';
1702
}
1703
-
1704
$postPageStmt = '';
1705
-
1706
$inSubPages = ($this->GetOption('in_posts_sub')===true);
1707
-
1708
if($inSubPages && $this->GetOption('in_posts')===true) {
1709
$pageDivider='<!--nextpage-->';
1710
$postPageStmt = ", (character_length(`post_content`) - character_length(REPLACE(`post_content`, '$pageDivider', ''))) / " . strlen($pageDivider) . " as postPages";
1711
}
1712
-
1713
$sql="SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` $postPageStmt $contentStmt FROM `" . $wpdb->posts . "` WHERE ";
1714
-
1715
$where = '(';
1716
-
1717
if($this->GetOption('in_posts')) {
1718
//WP < 2.1: posts are post_status = publish
1719
//WP >= 2.1: post_type must be 'post', no date check required because future posts are post_status='future'
@@ -1728,7 +1745,7 @@ class GoogleSitemapGenerator {
1728
$where.=" (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) ";
1729
}
1730
}
1731
-
1732
if($this->GetOption('in_pages')) {
1733
if($this->GetOption('in_posts')) {
1734
$where.=" OR ";
@@ -1741,33 +1758,33 @@ class GoogleSitemapGenerator {
1741
$where.=" (post_status = 'publish' AND post_type = 'page') ";
1742
}
1743
}
1744
-
1745
$where.=") ";
1746
-
1747
-
1748
if(is_array($excludes) && count($excludes)>0) {
1749
$where.=" AND ID NOT IN ('" . implode("','",$excludes) . "')";
1750
}
1751
-
1752
$where.=" AND post_password='' ORDER BY post_modified DESC";
1753
-
1754
$sql .= $where;
1755
-
1756
if($this->GetOption("b_max_posts")>0) {
1757
$sql.=" LIMIT 0," . $this->GetOption("b_max_posts");
1758
}
1759
1760
$postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` WHERE ". $where,0,0));
1761
-
1762
//Create a new connection because we are using mysql_unbuffered_query and don't want to disturb the WP connection
1763
//Safe Mode for other plugins which use mysql_query() without a connection handler and will destroy our resultset :(
1764
$con = $postRes = null;
1765
-
1766
//In 2.2, a bug which prevented additional DB connections was fixed
1767
if(floatval($wp_version) < 2.2) {
1768
$this->SetOption("b_safemode",true);
1769
}
1770
-
1771
if($this->GetOption("b_safemode")===true) {
1772
$postRes = mysql_query($sql,$wpdb->dbh);
1773
if(!$postRes) {
@@ -1785,66 +1802,66 @@ class GoogleSitemapGenerator {
1785
return;
1786
}
1787
$postRes = mysql_unbuffered_query($sql,$con);
1788
-
1789
if(!$postRes) {
1790
trigger_error("MySQL unbuffered query failed: " . mysql_error(),E_USER_NOTICE);
1791
return;
1792
}
1793
}
1794
-
1795
if($postRes) {
1796
-
1797
//#type $prioProvider GoogleSitemapGeneratorPrioProviderBase
1798
$prioProvider=NULL;
1799
-
1800
if($this->GetOption("b_prio_provider") != '') {
1801
$providerClass=$this->GetOption('b_prio_provider');
1802
$prioProvider = new $providerClass($commentCount,$postCount);
1803
}
1804
-
1805
//$posts is used by Alex King's Popularity Contest plugin
1806
//if($posts == null || !is_array($posts)) {
1807
// $posts = &$postRes;
1808
//}
1809
-
1810
$z = 1;
1811
$zz = 1;
1812
-
1813
//Default priorities
1814
$default_prio_posts = $this->GetOption('pr_posts');
1815
$default_prio_pages = $this->GetOption('pr_pages');
1816
-
1817
//Change frequencies
1818
$cf_pages = $this->GetOption('cf_pages');
1819
$cf_posts = $this->GetOption('cf_posts');
1820
-
1821
$minPrio=$this->GetOption('pr_posts_min');
1822
-
1823
-
1824
//Cycle through all posts and add them
1825
while($post = mysql_fetch_object($postRes)) {
1826
-
1827
//Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later.
1828
$cache = array(&$post);
1829
update_post_cache($cache);
1830
-
1831
//Set the current working post for other plugins which depend on "the loop"
1832
$GLOBALS['post'] = &$post;
1833
-
1834
$permalink = get_permalink($post->ID);
1835
if($permalink != $home && $post->ID != $homePid) {
1836
-
1837
$isPage = false;
1838
if($wpCompat) {
1839
$isPage = ($post->post_status == 'static');
1840
} else {
1841
$isPage = ($post->post_type == 'page');
1842
}
1843
-
1844
-
1845
//Default Priority if auto calc is disabled
1846
$prio = 0;
1847
-
1848
if($isPage) {
1849
//Priority for static pages
1850
$prio = $default_prio_pages;
@@ -1852,7 +1869,7 @@ class GoogleSitemapGenerator {
1852
//Priority for normal posts
1853
$prio = $default_prio_posts;
1854
}
1855
-
1856
//If priority calc. is enabled, calculate (but only for posts, not pages)!
1857
if($prioProvider !== null && !$isPage) {
1858
@@ -1862,14 +1879,14 @@ class GoogleSitemapGenerator {
1862
1863
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry('Debug: Priority report of postID ' . $post->ID . ': Comments: ' . $cmtcnt . ' of ' . $commentCount . ' = ' . $prio . ' points'));
1864
}
1865
-
1866
if(!$isPage && $minPrio>0 && $prio<$minPrio) {
1867
$prio = $minPrio;
1868
}
1869
-
1870
//Add it
1871
$this->AddUrl($permalink,$this->GetTimestampFromMySql(($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt)),($isPage?$cf_pages:$cf_posts),$prio);
1872
-
1873
if($inSubPages) {
1874
$subPage = '';
1875
for($p = 1; $p <= $post->postPages; $p++) {
@@ -1882,7 +1899,7 @@ class GoogleSitemapGenerator {
1882
$this->AddUrl($subPage,$this->GetTimestampFromMySql(($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt)),($isPage?$cf_pages:$cf_posts),$prio);
1883
}
1884
}
1885
-
1886
// Multilingual Support with qTranslate, thanks to Qian Qin
1887
if($useQTransLate) {
1888
global $q_config;
@@ -1893,7 +1910,7 @@ class GoogleSitemapGenerator {
1893
}
1894
}
1895
}
1896
-
1897
//Update the status every 100 posts and at the end.
1898
//If the script breaks because of memory or time limit,
1899
//we have a "last reponded" value which can be compared to the server settings
@@ -1901,9 +1918,9 @@ class GoogleSitemapGenerator {
1901
$status->SaveStep($z);
1902
$zz=0;
1903
} else $zz++;
1904
-
1905
$z++;
1906
-
1907
//Clean cache because it's incomplete
1908
if(version_compare($wp_version,"2.5",">=")) {
1909
//WP 2.5 makes a mysql query for every clean_post_cache to clear the child cache
@@ -1917,21 +1934,21 @@ class GoogleSitemapGenerator {
1917
}
1918
unset($postRes);
1919
unset($prioProvider);
1920
-
1921
if($this->GetOption("b_safemode")!==true && $con) mysql_close($con);
1922
}
1923
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Postings"));
1924
}
1925
-
1926
//Add the cats
1927
if($this->GetOption("in_cats")) {
1928
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Cats"));
1929
-
1930
$exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats
1931
if($exclCats == null) $exclCats=array();
1932
-
1933
if(!$this->IsTaxonomySupported()) {
1934
-
1935
$catsRes=$wpdb->get_results("
1936
SELECT
1937
c.cat_ID AS ID,
@@ -1966,7 +1983,7 @@ class GoogleSitemapGenerator {
1966
}
1967
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Cats"));
1968
}
1969
-
1970
//Add the archives
1971
if($this->GetOption("in_arch")) {
1972
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Archive"));
@@ -1993,36 +2010,36 @@ class GoogleSitemapGenerator {
1993
post_date_gmt DESC");
1994
if ($arcresults) {
1995
foreach ($arcresults as $arcresult) {
1996
-
1997
$url = get_month_link($arcresult->year, $arcresult->month);
1998
$changeFreq="";
1999
-
2000
//Archive is the current one
2001
if($arcresult->month==date("n") && $arcresult->year==date("Y")) {
2002
$changeFreq=$this->GetOption("cf_arch_curr");
2003
} else { // Archive is older
2004
$changeFreq=$this->GetOption("cf_arch_old");
2005
}
2006
-
2007
$this->AddUrl($url,$this->GetTimestampFromMySql($arcresult->last_mod),$changeFreq,$this->GetOption("pr_arch"));
2008
}
2009
}
2010
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Archive"));
2011
}
2012
-
2013
//Add the author pages
2014
if($this->GetOption("in_auth")) {
2015
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Author pages"));
2016
-
2017
$linkFunc = null;
2018
-
2019
//get_author_link is deprecated in WP 2.1, try to use get_author_posts_url first.
2020
if(function_exists('get_author_posts_url')) {
2021
$linkFunc = 'get_author_posts_url';
2022
} else if(function_exists('get_author_link')) {
2023
$linkFunc = 'get_author_link';
2024
}
2025
-
2026
//Who knows what happens in later WP versions, so check again if it worked
2027
if($linkFunc !== null) {
2028
//Unfortunately there is no API function to get all authors, so we have to do it the dirty way...
@@ -2044,9 +2061,9 @@ class GoogleSitemapGenerator {
2044
GROUP BY
2045
u.ID,
2046
u.user_nicename";
2047
-
2048
$authors = $wpdb->get_results($sql);
2049
-
2050
if($authors && is_array($authors)) {
2051
foreach($authors as $author) {
2052
if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Author-ID:" . $author->ID));
@@ -2058,10 +2075,10 @@ class GoogleSitemapGenerator {
2058
//Too bad, no author pages for you :(
2059
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: No valid author link function found"));
2060
}
2061
-
2062
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Author pages"));
2063
}
2064
-
2065
//Add tag pages
2066
if($this->GetOption("in_tags") && $this->IsTaxonomySupported()) {
2067
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Tags"));
@@ -2073,21 +2090,21 @@ class GoogleSitemapGenerator {
2073
}
2074
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Tags"));
2075
}
2076
-
2077
//Add custom taxonomy pages
2078
if($this->GetOption("in_tax") && $this->IsTaxonomySupported()) {
2079
-
2080
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start custom taxonomies"));
2081
-
2082
$enabledTaxonomies = $this->GetOption("in_tax");
2083
-
2084
$taxList = array();
2085
-
2086
foreach ($enabledTaxonomies as $taxName) {
2087
$taxonomy = get_taxonomy($taxName);
2088
if($taxonomy) $taxList[] = $wpdb->escape($taxonomy->name);
2089
}
2090
-
2091
if(count($taxList)>0) {
2092
//We're selecting all term information (t.*) plus some additional fields
2093
//like the last mod date and the taxonomy name, so WP doesnt need to make
@@ -2115,9 +2132,9 @@ class GoogleSitemapGenerator {
2115
AND tt.taxonomy IN ('" . implode("','",$taxList) . "')
2116
GROUP BY
2117
t.term_id";
2118
-
2119
$termInfo = $wpdb->get_results($sql);
2120
-
2121
foreach($termInfo AS $term) {
2122
$this->AddUrl(get_term_link($term->slug,$term->_taxonomy),$term->_mod_date ,$this->GetOption("cf_tags"),$this->GetOption("pr_tags"));
2123
}
@@ -2125,7 +2142,7 @@ class GoogleSitemapGenerator {
2125
2126
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End custom taxonomies"));
2127
}
2128
-
2129
//Add the custom pages
2130
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Custom Pages"));
2131
if($this->_pages && is_array($this->_pages) && count($this->_pages)>0) {
@@ -2134,20 +2151,20 @@ class GoogleSitemapGenerator {
2134
$this->AddUrl($page->GetUrl(),$page->getLastMod(),$page->getChangeFreq(),$page->getPriority());
2135
}
2136
}
2137
-
2138
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Custom Pages"));
2139
-
2140
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start additional URLs"));
2141
-
2142
do_action('sm_buildmap');
2143
-
2144
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End additional URLs"));
2145
-
2146
$this->AddElement(new GoogleSitemapGeneratorXmlEntry("</urlset>"));
2147
-
2148
2149
$pingUrl='';
2150
-
2151
if($this->GetOption("b_xml")) {
2152
if($this->_fileHandle && fclose($this->_fileHandle)) {
2153
$this->_fileHandle = null;
@@ -2155,7 +2172,7 @@ class GoogleSitemapGenerator {
2155
$pingUrl=$this->GetXmlUrl();
2156
} else $status->EndXml(false,"Could not close the sitemap file.");
2157
}
2158
-
2159
if($this->IsGzipEnabled()) {
2160
if($this->_fileZipHandle && fclose($this->_fileZipHandle)) {
2161
$this->_fileZipHandle = null;
@@ -2163,13 +2180,13 @@ class GoogleSitemapGenerator {
2163
$pingUrl=$this->GetZipUrl();
2164
} else $status->EndZip(false,"Could not close the zipped sitemap file");
2165
}
2166
-
2167
//Ping Google
2168
if($this->GetOption("b_ping") && !empty($pingUrl)) {
2169
$sPingUrl="http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($pingUrl);
2170
$status->StartGooglePing($sPingUrl);
2171
$pingres=$this->RemoteOpen($sPingUrl);
2172
-
2173
if($pingres==NULL || $pingres===false) {
2174
$status->EndGooglePing(false,$this->_lastError);
2175
trigger_error("Failed to ping Google: " . htmlspecialchars(strip_tags($pingres)),E_USER_NOTICE);
@@ -2177,8 +2194,8 @@ class GoogleSitemapGenerator {
2177
$status->EndGooglePing(true);
2178
}
2179
}
2180
-
2181
-
2182
//Ping Bing
2183
if($this->GetOption("b_pingmsn") && !empty($pingUrl)) {
2184
$sPingUrl="http://www.bing.com/webmaster/ping.aspx?siteMap=" . urlencode($pingUrl);
@@ -2192,36 +2209,36 @@ class GoogleSitemapGenerator {
2192
$status->EndMsnPing(true);
2193
}
2194
}
2195
-
2196
$status->End();
2197
-
2198
-
2199
$this->_isActive = false;
2200
-
2201
//done...
2202
return $status;
2203
}
2204
-
2205
/**
2206
* Tries to ping a specific service showing as much as debug output as possible
2207
* @since 3.1.9
2208
* @return null
2209
*/
2210
function ShowPingResult() {
2211
-
2212
check_admin_referer('sitemap');
2213
-
2214
if(!current_user_can("administrator")) {
2215
echo '<p>Please log in as admin</p>';
2216
return;
2217
}
2218
-
2219
$service = !empty($_GET["sm_ping_service"])?$_GET["sm_ping_service"]:null;
2220
-
2221
$status = &GoogleSitemapGeneratorStatus::Load();
2222
-
2223
if(!$status) die("No build status yet. Build the sitemap first.");
2224
-
2225
$url = null;
2226
2227
switch($service) {
@@ -2230,35 +2247,35 @@ class GoogleSitemapGenerator {
2230
break;
2231
case "msn":
2232
$url = $status->_msnUrl;
2233
- break;
2234
}
2235
-
2236
if(empty($url)) die("Invalid ping url");
2237
-
2238
echo '<html><head><title>Ping Test</title>';
2239
if(function_exists('wp_admin_css')) wp_admin_css('css/global',true);
2240
echo '</head><body><h1>Ping Test</h1>';
2241
-
2242
echo '<p>Trying to ping: <a href="' . $url . '">' . $url . '</a>. The sections below should give you an idea whats going on.</p>';
2243
-
2244
//Try to get as much as debug / error output as possible
2245
$errLevel = error_reporting(E_ALL);
2246
$errDisplay = ini_set("display_errors",1);
2247
if(!defined('WP_DEBUG')) define('WP_DEBUG',true);
2248
-
2249
echo '<h2>Errors, Warnings, Notices:</h2>';
2250
-
2251
if(WP_DEBUG == false) echo "<i>WP_DEBUG was set to false somewhere before. You might not see all debug information until you remove this declaration!</i><br />";
2252
if(ini_get("display_errors")!=1) echo "<i>Your display_errors setting currently prevents the plugin from showing errors here. Please check your webserver logfile instead.</i><br />";
2253
-
2254
$res = $this->RemoteOpen($url);
2255
-
2256
echo '<h2>Result (text only):</h2>';
2257
2258
echo wp_kses($res,array('a' => array('href' => array()),'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array()));
2259
-
2260
echo '<h2>Result (HTML):</h2>';
2261
-
2262
echo htmlspecialchars($res);
2263
2264
//Revert back old values
@@ -2267,7 +2284,7 @@ class GoogleSitemapGenerator {
2267
echo '</body></html>';
2268
exit;
2269
}
2270
-
2271
/**
2272
* Opens a remote file using the WordPress API or Snoopy
2273
* @since 3.0
@@ -2279,56 +2296,56 @@ class GoogleSitemapGenerator {
2279
*/
2280
function RemoteOpen($url,$method = 'get', $postData = null, $timeout = 10) {
2281
global $wp_version;
2282
-
2283
//Before WP 2.7, wp_remote_fopen was quite crappy so Snoopy was favoured.
2284
if(floatval($wp_version) < 2.7) {
2285
if(!file_exists(ABSPATH . 'wp-includes/class-snoopy.php')) {
2286
trigger_error('Snoopy Web Request failed: Snoopy not found.',E_USER_NOTICE);
2287
return false; //Hoah?
2288
}
2289
-
2290
require_once( ABSPATH . 'wp-includes/class-snoopy.php');
2291
-
2292
$s = new Snoopy();
2293
-
2294
$s->read_timeout = $timeout;
2295
-
2296
if($method == 'get') {
2297
$s->fetch($url);
2298
} else {
2299
$s->submit($url,$postData);
2300
}
2301
-
2302
if($s->status != "200") {
2303
trigger_error('Snoopy Web Request failed: Status: ' . $s->status . "; Content: " . htmlspecialchars($s->results),E_USER_NOTICE);
2304
}
2305
-
2306
return $s->results;
2307
-
2308
} else {
2309
-
2310
$options = array();
2311
$options['timeout'] = $timeout;
2312
-
2313
if($method == 'get') {
2314
$response = wp_remote_get( $url, $options );
2315
} else {
2316
$response = wp_remote_post($url, array_merge($options,array('body'=>$postData)));
2317
}
2318
-
2319
if ( is_wp_error( $response ) ) {
2320
$errs = $response->get_error_messages();
2321
$errs = htmlspecialchars(implode('; ', $errs));
2322
trigger_error('WP HTTP API Web Request failed: ' . $errs,E_USER_NOTICE);
2323
return false;
2324
}
2325
-
2326
return $response['body'];
2327
}
2328
-
2329
return false;
2330
}
2331
-
2332
/**
2333
* Echos option fields for an select field containing the valid change frequencies
2334
*
@@ -2339,12 +2356,12 @@ class GoogleSitemapGenerator {
2339
* @return all valid change frequencies as html option fields
2340
*/
2341
function HtmlGetFreqNames($currentVal) {
2342
-
2343
foreach($this->_freqNames AS $k=>$v) {
2344
echo "<option value=\"$k\" " . $this->HtmlGetSelected($k,$currentVal) .">" . $v . "</option>";
2345
}
2346
}
2347
-
2348
/**
2349
* Echos option fields for an select field containing the valid priorities (0- 1.0)
2350
*
@@ -2365,7 +2382,7 @@ class GoogleSitemapGenerator {
2365
echo "</option>";
2366
}
2367
}
2368
-
2369
/**
2370
* Returns the checked attribute if the given values match
2371
*
@@ -2380,7 +2397,7 @@ class GoogleSitemapGenerator {
2380
if($val==$equals) return $this->HtmlGetAttribute("checked");
2381
else return "";
2382
}
2383
-
2384
/**
2385
* Returns the selected attribute if the given values match
2386
*
@@ -2395,7 +2412,7 @@ class GoogleSitemapGenerator {
2395
if($val==$equals) return $this->HtmlGetAttribute("selected");
2396
else return "";
2397
}
2398
-
2399
/**
2400
* Returns an formatted attribute. If the value is NULL, the name will be used.
2401
*
@@ -2410,7 +2427,7 @@ class GoogleSitemapGenerator {
2410
if($value==NULL) $value=$attr;
2411
return " " . $attr . "=\"" . $value . "\" ";
2412
}
2413
-
2414
/**
2415
* Returns an array with GoogleSitemapGeneratorPage objects which is generated from POST values
2416
*
@@ -2423,13 +2440,13 @@ class GoogleSitemapGenerator {
2423
function HtmlApplyPages() {
2424
// Array with all page URLs
2425
$pages_ur=(!isset($_POST["sm_pages_ur"]) || !is_array($_POST["sm_pages_ur"])?array():$_POST["sm_pages_ur"]);
2426
-
2427
//Array with all priorities
2428
$pages_pr=(!isset($_POST["sm_pages_pr"]) || !is_array($_POST["sm_pages_pr"])?array():$_POST["sm_pages_pr"]);
2429
-
2430
//Array with all change frequencies
2431
$pages_cf=(!isset($_POST["sm_pages_cf"]) || !is_array($_POST["sm_pages_cf"])?array():$_POST["sm_pages_cf"]);
2432
-
2433
//Array with all lastmods
2434
$pages_lm=(!isset($_POST["sm_pages_lm"]) || !is_array($_POST["sm_pages_lm"])?array():$_POST["sm_pages_lm"]);
2435
@@ -2455,10 +2472,10 @@ class GoogleSitemapGenerator {
2455
2456
return $pages;
2457
}
2458
-
2459
/**
2460
* Converts a mysql datetime value into a unix timestamp
2461
- *
2462
* @param The value in the mysql datetime format
2463
* @return int The time in seconds
2464
*/
@@ -2468,10 +2485,10 @@ class GoogleSitemapGenerator {
2468
list($hour,$min,$sec) = explode(':',$hours);
2469
return mktime(intval($hour), intval($min), intval($sec), intval($month), intval($day), intval($year));
2470
}
2471
-
2472
/**
2473
* Returns a link pointing to a spcific page of the authors website
2474
- *
2475
* @since 3.0
2476
* @param The page to link to
2477
* @return string The full url
@@ -2479,10 +2496,10 @@ class GoogleSitemapGenerator {
2479
function GetRedirectLink($redir) {
2480
return trailingslashit("http://www.arnebrachhold.de/redir/" . $redir);
2481
}
2482
-
2483
/**
2484
* Returns a link pointing back to the plugin page in WordPress
2485
- *
2486
* @since 3.0
2487
* @return string The full url
2488
*/
@@ -2492,34 +2509,34 @@ class GoogleSitemapGenerator {
2492
//admin_url was added in WP 2.6.0
2493
if(function_exists("admin_url")) $url = admin_url("options-general.php?page=" . GoogleSitemapGeneratorLoader::GetBaseName());
2494
else $url = $_SERVER['PHP_SELF'] . "?page=" . GoogleSitemapGeneratorLoader::GetBaseName();
2495
-
2496
//Some browser cache the page... great! So lets add some no caching params depending on the WP and plugin version
2497
$url.='&sm_wpv=' . $wp_version . '&sm_pv=' . GoogleSitemapGeneratorLoader::GetVersion();
2498
-
2499
return $url;
2500
}
2501
-
2502
/**
2503
* Shows the option page of the plugin. Before 3.1.1, this function was basically the UI, afterwards the UI was outsourced to another class
2504
- *
2505
* @see GoogleSitemapGeneratorUI
2506
* @since 3.0
2507
* @return bool
2508
*/
2509
function HtmlShowOptionsPage() {
2510
-
2511
$ui = $this->GetUI();
2512
if($ui) {
2513
$ui->HtmlShowOptionsPage();
2514
return true;
2515
}
2516
-
2517
return false;
2518
}
2519
-
2520
/**
2521
* Includes the user interface class and intializes it
2522
- *
2523
* @since 3.1.1
2524
* @see GoogleSitemapGeneratorUI
2525
* @return GoogleSitemapGeneratorUI
@@ -2527,29 +2544,29 @@ class GoogleSitemapGenerator {
2527
function GetUI() {
2528
2529
global $wp_version;
2530
-
2531
if($this->_ui === null) {
2532
-
2533
$className='GoogleSitemapGeneratorUI';
2534
$fileName='sitemap-ui.php';
2535
2536
if(!class_exists($className)) {
2537
-
2538
$path = trailingslashit(dirname(__FILE__));
2539
-
2540
if(!file_exists( $path . $fileName)) return false;
2541
require_once($path. $fileName);
2542
}
2543
-
2544
$this->_ui = new $className($this);
2545
-
2546
}
2547
-
2548
return $this->_ui;
2549
}
2550
-
2551
function HtmlShowHelp() {
2552
-
2553
-
2554
}
2555
}
1
<?php
2
/*
3
+
4
+ $Id: sitemap-core.php 651444 2013-01-11 19:54:39Z arnee $
5
6
*/
7
19
20
function GoogleSitemapGeneratorStatus() {
21
$this->_startTime = $this->GetMicrotimeFloat();
22
+
23
$exists = get_option("sm_status");
24
+
25
if($exists === false) add_option("sm_status","",null,"no");
26
+
27
$this->Save();
28
}
29
+
30
function Save() {
31
update_option("sm_status",$this);
32
}
33
+
34
/**
35
* Returns the last saved status object or null
36
+ *
37
* @return GoogleSitemapGeneratorStatus
38
*/
39
function &Load() {
41
if(is_a($status,"GoogleSitemapGeneratorStatus")) return $status;
42
else return null;
43
}
44
+
45
/**
46
* @var float $_startTime The start time of the building process
47
* @access private
48
*/
49
var $_startTime = 0;
50
+
51
/**
52
* @var float $_endTime The end time of the building process
53
* @access private
54
*/
55
var $_endTime = 0;
56
+
57
/**
58
* @var bool $_hasChanged Indicates if the sitemap content has changed
59
* @access private
60
*/
61
var $_hasChanged = true;
62
+
63
/**
64
* @var int $_memoryUsage The amount of memory used in bytes
65
* @access private
66
*/
67
var $_memoryUsage = 0;
68
+
69
/**
70
* @var int $_lastPost The number of posts processed. This value is updated every 50 posts.
71
* @access private
72
*/
73
var $_lastPost = 0;
74
+
75
/**
76
* @var int $_lastTime The time when the last step-update occured. This value is updated every 50 posts.
77
* @access private
78
*/
79
var $_lastTime = 0;
80
+
81
function End($hasChanged = true) {
82
$this->_endTime = $this->GetMicrotimeFloat();
83
+
84
$this->SetMemoryUsage();
85
+
86
$this->_hasChanged = $hasChanged;
87
+
88
$this->Save();
89
}
90
+
91
function SetMemoryUsage() {
92
if(function_exists("memory_get_peak_usage")) {
93
$this->_memoryUsage = memory_get_peak_usage(true);
95
$this->_memoryUsage = memory_get_usage(true);
96
}
97
}
98
+
99
function GetMemoryUsage() {
100
return round($this->_memoryUsage / 1024 / 1024,2);
101
}
102
+
103
function SaveStep($postCount) {
104
$this->SetMemoryUsage();
105
$this->_lastPost = $postCount;
106
$this->_lastTime = $this->GetMicrotimeFloat();
107
+
108
$this->Save();
109
}
110
+
111
function GetTime() {
112
return round($this->_endTime - $this->_startTime,2);
113
}
114
+
115
function GetStartTime() {
116
return round($this->_startTime, 2);
117
}
118
+
119
function GetLastTime() {
120
return round($this->_lastTime - $this->_startTime,2);
121
}
122
+
123
function GetLastPost() {
124
return $this->_lastPost;
125
}
126
+
127
var $_usedXml = false;
128
var $_xmlSuccess = false;
129
var $_xmlPath = '';
130
var $_xmlUrl = '';
131
+
132
function StartXml($path,$url) {
133
$this->_usedXml = true;
134
$this->_xmlPath = $path;
135
$this->_xmlUrl = $url;
136
+
137
$this->Save();
138
}
139
+
140
function EndXml($success) {
141
$this->_xmlSuccess = $success;
142
+
143
$this->Save();
144
}
145
+
146
+
147
var $_usedZip = false;
148
var $_zipSuccess = false;
149
var $_zipPath = '';
150
var $_zipUrl = '';
151
+
152
function StartZip($path,$url) {
153
$this->_usedZip = true;
154
$this->_zipPath = $path;
155
$this->_zipUrl = $url;
156
+
157
$this->Save();
158
}
159
+
160
function EndZip($success) {
161
$this->_zipSuccess = $success;
162
+
163
$this->Save();
164
}
165
+
166
var $_usedGoogle = false;
167
var $_googleUrl = '';
168
var $_gooogleSuccess = false;
169
var $_googleStartTime = 0;
170
var $_googleEndTime = 0;
171
+
172
function StartGooglePing($url) {
173
$this->_googleUrl = $url;
174
$this->_usedGoogle = true;
175
$this->_googleStartTime = $this->GetMicrotimeFloat();
176
+
177
$this->Save();
178
}
179
+
180
function EndGooglePing($success) {
181
$this->_googleEndTime = $this->GetMicrotimeFloat();
182
$this->_gooogleSuccess = $success;
183
+
184
$this->Save();
185
}
186
+
187
function GetGoogleTime() {
188
return round($this->_googleEndTime - $this->_googleStartTime,2);
189
}
190
+
191
var $_usedMsn = false;
192
var $_msnUrl = '';
193
var $_msnSuccess = false;
194
var $_msnStartTime = 0;
195
var $_msnEndTime = 0;
196
+
197
function StartMsnPing($url) {
198
$this->_usedMsn = true;
199
$this->_msnUrl = $url;
200
$this->_msnStartTime = $this->GetMicrotimeFloat();
201
+
202
$this->Save();
203
}
204
+
205
function EndMsnPing($success) {
206
$this->_msnEndTime = $this->GetMicrotimeFloat();
207
$this->_msnSuccess = $success;
208
+
209
$this->Save();
210
}
211
+
212
function GetMsnTime() {
213
return round($this->_msnEndTime - $this->_msnStartTime,2);
214
}
215
+
216
function GetMicrotimeFloat() {
217
list($usec, $sec) = explode(" ", microtime());
218
return ((float)$usec + (float)$sec);
219
}
220
}
221
+
222
/**
223
* Represents an item in the page list
224
* @author Arne Brachhold
226
* @since 3.0
227
*/
228
class GoogleSitemapGeneratorPage {
229
+
230
/**
231
* @var string $_url Sets the URL or the relative path to the blog dir of the page
232
* @access private
233
*/
234
var $_url;
235
+
236
/**
237
* @var float $_priority Sets the priority of this page
238
* @access private
239
*/
240
var $_priority;
241
+
242
/**
243
* @var string $_changeFreq Sets the chanfe frequency of the page. I want Enums!
244
* @access private
245
*/
246
var $_changeFreq;
247
+
248
/**
249
* @var int $_lastMod Sets the lastMod date as a UNIX timestamp.
250
* @access private
251
*/
252
var $_lastMod;
253
+
254
/**
255
* Initialize a new page object
256
*
269
$this->SetChangeFreq($changeFreq);
270
$this->SetLastMod($lastMod);
271
}
272
+
273
/**
274
* Returns the URL of the page
275
*
278
function GetUrl() {
279
return $this->_url;
280
}
281
+
282
/**
283
* Sets the URL of the page
284
*
287
function SetUrl($url) {
288
$this->_url=(string) $url;
289
}
290
+
291
/**
292
* Returns the priority of this page
293
*
296
function GetPriority() {
297
return $this->_priority;
298
}
299
+
300
/**
301
* Sets the priority of the page
302
*
305
function SetProprity($priority) {
306
$this->_priority=floatval($priority);
307
}
308
+
309
/**
310
* Returns the change frequency of the page
311
*
314
function GetChangeFreq() {
315
return $this->_changeFreq;
316
}
317
+
318
/**
319
* Sets the change frequency of the page
320
*
323
function SetChangeFreq($changeFreq) {
324
$this->_changeFreq=(string) $changeFreq;
325
}
326
+
327
/**
328
* Returns the last mod of the page
329
*
332
function GetLastMod() {
333
return $this->_lastMod;
334
}
335
+
336
/**
337
* Sets the last mod of the page
338
*
341
function SetLastMod($lastMod) {
342
$this->_lastMod=intval($lastMod);
343
}
344
+
345
function Render() {
346
+
347
if($this->_url == "/" || empty($this->_url)) return '';
348
+
349
$r="";
350
$r.= "\t<url>\n";
351
$r.= "\t\t<loc>" . $this->EscapeXML($this->_url) . "</loc>\n";
352
if($this->_lastMod>0) $r.= "\t\t<lastmod>" . date('Y-m-d\TH:i:s+00:00',$this->_lastMod) . "</lastmod>\n";
353
+ if(!empty($this->_changeFreq)) $r.= "\t\t<changefreq>" . $this->EscapeXML($this->_changeFreq) . "</changefreq>\n";
354
if($this->_priority!==false && $this->_priority!=="") $r.= "\t\t<priority>" . number_format($this->_priority,1) . "</priority>\n";
355
$r.= "\t</url>\n";
356
return $r;
357
}
358
+
359
function EscapeXML($string) {
360
return str_replace ( array ( '&', '"', "'", '<', '>'), array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;'), $string);
361
}
362
}
363
364
class GoogleSitemapGeneratorXmlEntry {
365
+
366
var $_xml;
367
+
368
function GoogleSitemapGeneratorXmlEntry($xml) {
369
$this->_xml = $xml;
370
}
371
+
372
function Render() {
373
return $this->_xml;
374
}
375
}
376
377
class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry {
378
+
379
function Render() {
380
return "<!-- " . $this->_xml . " -->\n";
381
}
388
* @since 3.0
389
*/
390
class GoogleSitemapGeneratorPrioProviderBase {
391
+
392
/**
393
* @var int $_totalComments The total number of comments of all posts
394
* @access protected
395
*/
396
var $_totalComments=0;
397
+
398
/**
399
* @var int $_totalComments The total number of posts
400
* @access protected
401
*/
402
var $_totalPosts=0;
403
+
404
/**
405
* Returns the (translated) name of this priority provider
406
*
412
function GetName() {
413
return "";
414
}
415
+
416
/**
417
* Returns the (translated) description of this priority provider
418
*
424
function GetDescription() {
425
return "";
426
}
427
+
428
/**
429
* Initializes a new priority provider
430
*
437
function GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts) {
438
$this->_totalComments=$totalComments;
439
$this->_totalPosts=$totalPosts;
440
+
441
}
442
+
443
/**
444
* Returns the priority for a specified post
445
*
462
* @since 3.0
463
*/
464
class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPrioProviderBase {
465
+
466
/**
467
* Returns the (translated) name of this priority provider
468
*
474
function GetName() {
475
return __("Comment Count",'sitemap');
476
}
477
+
478
/**
479
* Returns the (translated) description of this priority provider
480
*
486
function GetDescription() {
487
return __("Uses the number of comments of the post to calculate the priority",'sitemap');
488
}
489
+
490
/**
491
* Initializes a new priority provider which calculates the post priority based on the number of comments
492
*
499
function GoogleSitemapGeneratorPrioByCountProvider($totalComments,$totalPosts) {
500
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
501
}
502
+
503
/**
504
* Returns the priority for a specified post
505
*
528
* @since 3.0
529
*/
530
class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGeneratorPrioProviderBase {
531
+
532
/**
533
* @var int $_average The average number of comments per post
534
* @access protected
535
*/
536
var $_average=0.0;
537
+
538
/**
539
* Returns the (translated) name of this priority provider
540
*
546
function GetName() {
547
return __("Comment Average",'sitemap');
548
}
549
+
550
/**
551
* Returns the (translated) description of this priority provider
552
*
558
function GetDescription() {
559
return __("Uses the average comment count to calculate the priority",'sitemap');
560
}
561
+
562
/**
563
* Initializes a new priority provider which calculates the post priority based on the average number of comments
564
*
570
*/
571
function GoogleSitemapGeneratorPrioByAverageProvider($totalComments,$totalPosts) {
572
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
573
+
574
if($this->_totalComments>0 && $this->_totalPosts>0) {
575
$this->_average= (double) $this->_totalComments / $this->_totalPosts;
576
}
577
}
578
+
579
/**
580
* Returns the priority for a specified post
581
*
597
if($prio>1) $prio = 1;
598
else if($prio<0) $prio = 0;
599
}
600
+
601
return round($prio,1);
602
}
603
}
609
* @since 3.0
610
*/
611
class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitemapGeneratorPrioProviderBase {
612
+
613
/**
614
* Returns the (translated) name of this priority provider
615
*
621
function GetName() {
622
return __("Popularity Contest",'sitemap');
623
}
624
+
625
/**
626
* Returns the (translated) description of this priority provider
627
*
633
function GetDescription() {
634
return str_replace("%4","index.php?page=popularity-contest.php",str_replace("%3","options-general.php?page=popularity-contest.php",str_replace("%2","http://www.alexking.org/",str_replace("%1","http://www.alexking.org/index.php?content=software/wordpress/content.php",__("Uses the activated <a href=\"%1\">Popularity Contest Plugin</a> from <a href=\"%2\">Alex King</a>. See <a href=\"%3\">Settings</a> and <a href=\"%4\">Most Popular Posts</a>",'sitemap')))));
635
}
636
+
637
/**
638
* Initializes a new priority provider which calculates the post priority based on the popularity by the PopularityContest Plugin
639
*
646
function GoogleSitemapGeneratorPrioByPopularityContestProvider($totalComments,$totalPosts) {
647
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
648
}
649
+
650
/**
651
* Returns the priority for a specified post
652
*
660
function GetPostPriority($postID,$commentCount) {
661
//$akpc is the global instance of the Popularity Contest Plugin
662
global $akpc,$posts;
663
+
664
$res=0;
665
//Better check if its there
666
if(!empty($akpc) && is_object($akpc)) {
696
/**
697
* @var Version of the generator in SVN
698
*/
699
+ var $_svnVersion = '$Id: sitemap-core.php 651444 2013-01-11 19:54:39Z arnee #x27;;
700
+
701
/**
702
* @var array The unserialized array with the stored options
703
*/
704
var $_options = array();
705
+
706
/**
707
* @var array The saved additional pages
708
*/
712
* @var array The values and names of the change frequencies
713
*/
714
var $_freqNames = array();
715
+
716
/**
717
* @var array A list of class names which my be called for priority calculation
718
*/
719
var $_prioProviders = array();
720
+
721
/**
722
* @var bool True if init complete (options loaded etc)
723
*/
724
var $_initiated = false;
725
+
726
/**
727
* @var string Holds the last error if one occurs when writing the files
728
*/
729
var $_lastError=null;
730
+
731
/**
732
* @var int The last handled post ID
733
*/
734
var $_lastPostID = 0;
735
+
736
/**
737
* @var bool Defines if the sitemap building process is active at the moment
738
*/
739
var $_isActive = false;
740
+
741
/**
742
* @var bool Defines if the sitemap building process has been scheduled via Wp cron
743
*/
747
* @var object The file handle which is used to write the sitemap file
748
*/
749
var $_fileHandle = null;
750
+
751
/**
752
* @var object The file handle which is used to write the zipped sitemap file
753
*/
754
var $_fileZipHandle = null;
755
+
756
/**
757
* Holds the user interface object
758
+ *
759
* @since 3.1.1
760
* @var GoogleSitemapGeneratorUI
761
*/
762
var $_ui = null;
763
+
764
/**
765
* Returns the path to the blog directory
766
*
770
* @return string The full path to the blog directory
771
*/
772
function GetHomePath() {
773
+
774
$res="";
775
//Check if we are in the admin area -> get_home_path() is avaiable
776
if(function_exists("get_home_path")) {
794
}
795
return $res;
796
}
797
+
798
/**
799
* Returns the path to the directory where the plugin file is located
800
* @since 3.0b5
806
$path = dirname(__FILE__);
807
return trailingslashit(str_replace("\\","/",$path));
808
}
809
+
810
/**
811
* Returns the URL to the directory where the plugin file is located
812
* @since 3.0b5
815
* @return string The URL to the plugin directory
816
*/
817
function GetPluginUrl() {
818
+
819
//Try to use WP API if possible, introduced in WP 2.6
820
if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__))));
821
+
822
//Try to find manually... can't work if wp-content was renamed or is redirected
823
$path = dirname(__FILE__);
824
$path = str_replace("\\","/",$path);
825
$path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));
826
return $path;
827
}
828
+
829
/**
830
* Returns the URL to default XSLT style if it exists
831
* @since 3.0b5
843
}
844
return '';
845
}
846
+
847
/**
848
* Sets up the default configuration
849
*
852
* @author Arne Brachhold
853
*/
854
function InitOptions() {
855
+
856
$this->_options=array();
857
$this->_options["sm_b_prio_provider"]="GoogleSitemapGeneratorPrioByCountProvider"; //Provider for automatic priority calculation
858
$this->_options["sm_b_filename"]="sitemap.xml"; //Name of the Sitemap file
907
$this->_options["sm_pr_arch"]=0.3; //Priority of archives
908
$this->_options["sm_pr_auth"]=0.3; //Priority of author pages
909
$this->_options["sm_pr_tags"]=0.3; //Priority of tags
910
+
911
$this->_options["sm_i_donated"]=false; //Did you donate? Thank you! :)
912
$this->_options["sm_i_hide_donated"]=false; //And hide the thank you..
913
$this->_options["sm_i_install_date"]=time(); //The installation date
915
$this->_options["sm_i_hide_works"]=false; //Hide the "works?" message which appears after 15 days
916
$this->_options["sm_i_hide_donors"]=false; //Hide the list of donations
917
}
918
+
919
/**
920
* Loads the configuration from the database
921
*
924
* @author Arne Brachhold
925
*/
926
function LoadOptions() {
927
+
928
$this->InitOptions();
929
+
930
//First init default values, then overwrite it with stored values so we can add default
931
//values with an update which get stored by the next edit.
932
$storedoptions=get_option("sm_options");
936
}
937
} else update_option("sm_options",$this->_options); //First time use, store default values
938
}
939
+
940
/**
941
* Initializes a new Google Sitemap Generator
942
*
947
function GoogleSitemapGenerator() {
948
949
950
+
951
+
952
}
953
+
954
/**
955
* Returns the version of the generator
956
*
962
function GetVersion() {
963
return GoogleSitemapGeneratorLoader::GetVersion();
964
}
965
+
966
/**
967
* Returns all parent classes of a class
968
*
982
}
983
return $parents;
984
}
985
+
986
/**
987
* Returns if a class is a subclass of another class
988
*
995
* @return bool true if the given class is a subclass of the other one
996
*/
997
function IsSubclassOf($className, $parentName) {
998
+
999
$className = strtolower($className);
1000
$parentName = strtolower($parentName);
1001
+
1002
if(empty($className) || empty($parentName) || !class_exists($className) || !class_exists($parentName)) return false;
1003
+
1004
$parents=$this->GetParentClasses($className);
1005
+
1006
return in_array($parentName,$parents);
1007
}
1008
+
1009
/**
1010
* Loads up the configuration and validates the prioity providers
1011
*
1017
*/
1018
function Initate() {
1019
if(!$this->_initiated) {
1020
+
1021
//Loading language file...
1022
//load_plugin_textdomain('sitemap');
1023
//Hmm, doesn't work if the plugin file has its own directory.
1027
$moFile = dirname(__FILE__) . "/lang/sitemap-" . $currentLocale . ".mo";
1028
if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('sitemap', $moFile);
1029
}
1030
+
1031
$this->_freqNames = array(
1032
"always"=>__("Always","sitemap"),
1033
"hourly"=>__("Hourly","sitemap"),
1037
"yearly"=>__("Yearly","sitemap"),
1038
"never"=>__("Never","sitemap")
1039
);
1040
+
1041
+
1042
$this->LoadOptions();
1043
$this->LoadPages();
1044
+
1045
//Register our own priority providers
1046
add_filter("sm_add_prio_provider",array(&$this, 'AddDefaultPrioProviders'));
1047
+
1048
//Let other plugins register their providers
1049
$r = apply_filters("sm_add_prio_provider",$this->_prioProviders);
1050
+
1051
//Check if no plugin return null
1052
if($r != null) $this->_prioProviders = $r;
1053
+
1054
$this->ValidatePrioProviders();
1055
+
1056
$this->_initiated = true;
1057
}
1058
}
1059
+
1060
/**
1061
* Returns the instance of the Sitemap Generator
1062
*
1070
return $GLOBALS["sm_instance"];
1071
} else return null;
1072
}
1073
+
1074
/**
1075
* Returns if the sitemap building process is currently active
1076
*
1083
$inst = &GoogleSitemapGenerator::GetInstance();
1084
return ($inst != null && $inst->_isActive);
1085
}
1086
+
1087
/**
1088
* Returns if the compressed sitemap was activated
1089
*
1119
function IsCustomPostTypesSupported() {
1120
return (function_exists("get_post_types") && function_exists("register_post_type"));
1121
}
1122
+
1123
/**
1124
* Returns the list of custom taxonies. These are basically all taxonomies without categories and post tags
1125
+ *
1126
* @since 3.1.7
1127
* @return array Array of names of user-defined taxonomies
1128
*/
1133
1134
/**
1135
* Returns the list of custom post types. These are all custome post types except post, page and attachment
1136
+ *
1137
* @since 3.2.5
1138
* @author Lee Willis
1139
* @return array Array of custom post types as per get_post_types
1144
$post_types = array_diff($post_types,array("post","page","attachment"));
1145
return $post_types;
1146
}
1147
+
1148
/**
1149
* Enables the Google Sitemap Generator and registers the WordPress hooks
1150
*
1157
$GLOBALS["sm_instance"]=new GoogleSitemapGenerator();
1158
}
1159
}
1160
+
1161
/**
1162
* Checks if sitemap building after content changed is enabled and rebuild the sitemap
1163
*
1172
$this->Initate();
1173
//Build one time per post and if not importing.
1174
if((($this->GetOption("b_auto_enabled")===true && $this->_lastPostID != $postID) || $external) && (!defined('WP_IMPORTING') || WP_IMPORTING != true)) {
1175
+
1176
//Build the sitemap directly or schedule it with WP cron
1177
if($this->GetOption("b_auto_delay")==true && floatval($wp_version) >= 2.1) {
1178
if(!$this->_isScheduled) {
1191
$this->_lastPostID = $postID;
1192
}
1193
}
1194
+
1195
/**
1196
* Builds the sitemap by external request, for example other plugins.
1197
+ *
1198
* @since 3.1.9
1199
* @return null
1200
*/
1201
function BuildNowRequest() {
1202
+ $this->CheckForAutoBuild(null, true);
1203
}
1204
+
1205
/**
1206
* Checks if the rebuild request was send and starts to rebuilt the sitemap
1207
*
1229
*/
1230
function ValidatePrioProviders() {
1231
$validProviders=array();
1232
+
1233
for($i=0; $i<count($this->_prioProviders); $i++) {
1234
if(class_exists($this->_prioProviders[$i])) {
1235
if($this->IsSubclassOf($this->_prioProviders[$i],"GoogleSitemapGeneratorPrioProviderBase")) {
1238
}
1239
}
1240
$this->_prioProviders=$validProviders;
1241
+
1242
if(!$this->GetOption("b_prio_provider")) {
1243
if(!in_array($this->GetOption("b_prio_provider"),$this->_prioProviders,true)) {
1244
$this->SetOption("b_prio_provider","");
1261
}
1262
return $providers;
1263
}
1264
+
1265
/**
1266
* Loads the stored pages from the database
1267
*
1271
*/
1272
function LoadPages() {
1273
global $wpdb;
1274
+
1275
$needsUpdate=false;
1276
+
1277
$pagesString=$wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'sm_cpages'");
1278
+
1279
//Class sm_page was renamed with 3.0 -> rename it in serialized value for compatibility
1280
if(!empty($pagesString) && strpos($pagesString,"sm_page")!==false) {
1281
$pagesString = str_replace("O:7:\"sm_page\"","O:26:\"GoogleSitemapGeneratorPage\"",$pagesString);
1282
$needsUpdate=true;
1283
}
1284
+
1285
if(!empty($pagesString)) {
1286
$storedpages=unserialize($pagesString);
1287
$this->_pages=$storedpages;
1288
} else {
1289
$this->_pages=array();
1290
}
1291
+
1292
if($needsUpdate) $this->SavePages();
1293
}
1294
+
1295
/**
1296
* Saved the additional pages back to the database
1297
*
1311
return true;
1312
}
1313
}
1314
+
1315
+
1316
/**
1317
* Returns the URL for the sitemap file
1318
*
1323
* @return The URL to the Sitemap file
1324
*/
1325
function GetXmlUrl($forceAuto=false) {
1326
+
1327
+ $name ="";
1328
+
1329
if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") {
1330
+ $name = $this->GetOption("b_fileurl_manual");
1331
} else {
1332
+ $name = trailingslashit(get_bloginfo('url')). $this->GetOption("b_filename");
1333
+ }
1334
+
1335
+ if(substr($name,-4)!=".xml") {
1336
+ $name.=".xml";
1337
}
1338
+
1339
+ return $name;
1340
}
1341
1342
/**
1351
function GetZipUrl($forceAuto=false) {
1352
return $this->GetXmlUrl($forceAuto) . ".gz";
1353
}
1354
+
1355
/**
1356
* Returns the file system path to the sitemap file
1357
*
1362
* @return The file system path;
1363
*/
1364
function GetXmlPath($forceAuto=false) {
1365
+
1366
+ $name ="";
1367
+
1368
if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") {
1369
+ $name = $this->GetOption("b_filename_manual");
1370
} else {
1371
+ $name = $this->GetHomePath() . $this->GetOption("b_filename");
1372
+ }
1373
+
1374
+ if(substr($name,-4)!=".xml") {
1375
+ $name.=".xml";
1376
}
1377
+
1378
+ return $name;
1379
}
1380
+
1381
/**
1382
* Returns the file system path to the gzipped sitemap file
1383
*
1390
function GetZipPath($forceAuto=false) {
1391
return $this->GetXmlPath($forceAuto) . ".gz";
1392
}
1393
+
1394
/**
1395
* Returns the option value for the given key
1396
*
1406
return $this->_options[$key];
1407
} else return null;
1408
}
1409
+
1410
/**
1411
* Sets an option to a new value
1412
*
1418
*/
1419
function SetOption($key,$value) {
1420
if(strstr($key,"sm_")!==0) $key="sm_" . $key;
1421
+
1422
$this->_options[$key]=$value;
1423
}
1424
+
1425
/**
1426
* Saves the options back to the database
1427
*
1436
return true;
1437
} else return update_option("sm_options",$this->_options);
1438
}
1439
+
1440
/**
1441
* Retrieves the number of comments of a post in a asso. array
1442
* The key is the postID, the value the number of comments
1459
}
1460
return $comments;
1461
}
1462
+
1463
/**
1464
* Calculates the full number of comments from an sm_getComments() generated array
1465
*
1477