Google XML Sitemaps - Version 3.1.1

Version Description

Download this release

Release Info

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

Code changes from version 3.1.0.1 to 3.1.1

Files changed (5) hide show
  1. documentation.txt +5 -0
  2. readme.txt +1 -1
  3. sitemap-core.php +321 -260
  4. sitemap-ui.php +753 -710
  5. sitemap.php +42 -22
documentation.txt CHANGED
@@ -180,6 +180,11 @@
180
2008-05-27 3.1.0.1 Extracted UI JS to external file
181
Enabled the option to include following pages of multi-page posts
182
Script tries to raise memory and time limit if active
183
184
185
180
2008-05-27 3.1.0.1 Extracted UI JS to external file
181
Enabled the option to include following pages of multi-page posts
182
Script tries to raise memory and time limit if active
183
+ 2008-12-21 3.1.1 Fixed redirect issue if wp-admin is rewritten via mod_rewrite, thanks to macjoost
184
+ Fixed wrong path to assets, thanks PozHonks
185
+ Fixed wrong plugin URL if wp-content was renamed / redirected, thanks to wnorris
186
+ Updated WP User Interface for 2.7
187
+ Various other small things
188
189
190
readme.txt CHANGED
@@ -11,7 +11,7 @@ This plugin will create a Google sitemaps compliant XML-Sitemap of your WordPres
11
12
This plugin will create a Google sitemaps compliant XML-Sitemap of your WordPress blog. It supports all of the WordPress generated pages as well as custom ones. Everytime you edit or create a post, your sitemap is updated and all major search engines that support the sitemap protocol, like ASK.com, Google, MSN Search and YAHOO, are notified about the update.
13
14
- Plugin related Links:
15
16
* <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/" title="Google XML Sitemaps Plugin for WordPress">Plugin Homepage</a>
17
* <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/changelog/" title="Changelog of the Google XML Sitemaps Plugin for WordPress">Changelog</a>
11
12
This plugin will create a Google sitemaps compliant XML-Sitemap of your WordPress blog. It supports all of the WordPress generated pages as well as custom ones. Everytime you edit or create a post, your sitemap is updated and all major search engines that support the sitemap protocol, like ASK.com, Google, MSN Search and YAHOO, are notified about the update.
13
14
+ Related Links:
15
16
* <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/" title="Google XML Sitemaps Plugin for WordPress">Plugin Homepage</a>
17
* <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/changelog/" title="Changelog of the Google XML Sitemaps Plugin for WordPress">Changelog</a>
sitemap-core.php CHANGED
@@ -1,7 +1,7 @@
1
- <?php
2
/*
3
4
- $Id: sitemap-core.php 48034 2008-05-27 14:36:18Z arnee $
5
6
*/
7
@@ -9,7 +9,6 @@
9
//error_reporting(E_ALL);
10
//ini_set("display_errors",1);
11
12
-
13
#region PHP5 compat functions
14
if (!function_exists('file_get_contents')) {
15
/**
@@ -41,7 +40,7 @@ if (!function_exists('file_get_contents')) {
41
42
fclose($fh);
43
return $data;
44
- }
45
}
46
47
@@ -151,13 +150,13 @@ class GoogleSitemapGeneratorStatus {
151
}
152
153
function Save() {
154
- update_option("sm_status",$this);
155
}
156
157
function Load() {
158
$status = @get_option("sm_status");
159
if(is_a($status,"GoogleSitemapGeneratorStatus")) return $status;
160
- else return null;
161
}
162
163
/**
@@ -182,7 +181,7 @@ class GoogleSitemapGeneratorStatus {
182
* @var int $_memoryUsage The amount of memory used in bytes
183
* @access private
184
*/
185
- var $_memoryUsage = 0;
186
187
/**
188
* @var int $_lastPost The number of posts processed. This value is updated every 50 posts.
@@ -211,11 +210,11 @@ class GoogleSitemapGeneratorStatus {
211
$this->_memoryUsage = memory_get_peak_usage(true);
212
} else if(function_exists("memory_get_usage")) {
213
$this->_memoryUsage = memory_get_usage(true);
214
- }
215
}
216
217
function GetMemoryUsage() {
218
- return round($this->_memoryUsage / 1024 / 1024,2);
219
}
220
221
function SaveStep($postCount) {
@@ -223,23 +222,23 @@ class GoogleSitemapGeneratorStatus {
223
$this->_lastPost = $postCount;
224
$this->_lastTime = $this->GetMicrotimeFloat();
225
226
- $this->Save();
227
}
228
229
function GetTime() {
230
- return round($this->_endTime - $this->_startTime,2);
231
}
232
233
function GetStartTime() {
234
- return round($this->_startTime, 2);
235
}
236
237
function GetLastTime() {
238
- return round($this->_lastTime - $this->_startTime,2);
239
}
240
241
function GetLastPost() {
242
- return $this->_lastPost;
243
}
244
245
var $_usedXml = false;
@@ -252,11 +251,11 @@ class GoogleSitemapGeneratorStatus {
252
$this->_xmlPath = $path;
253
$this->_xmlUrl = $url;
254
255
- $this->Save();
256
}
257
258
function EndXml($success) {
259
- $this->_xmlSuccess = $success;
260
261
$this->Save();
262
}
@@ -270,7 +269,7 @@ class GoogleSitemapGeneratorStatus {
270
function StartZip($path,$url) {
271
$this->_usedZip = true;
272
$this->_zipPath = $path;
273
- $this->_zipUrl = $url;
274
275
$this->Save();
276
}
@@ -278,7 +277,7 @@ class GoogleSitemapGeneratorStatus {
278
function EndZip($success) {
279
$this->_zipSuccess = $success;
280
281
- $this->Save();
282
}
283
284
var $_usedGoogle = false;
@@ -290,20 +289,20 @@ class GoogleSitemapGeneratorStatus {
290
function StartGooglePing($url) {
291
$this->_googleUrl = true;
292
$this->_usedGoogle = true;
293
- $this->_googleStartTime = $this->GetMicrotimeFloat();
294
295
$this->Save();
296
}
297
298
function EndGooglePing($success) {
299
$this->_googleEndTime = $this->GetMicrotimeFloat();
300
- $this->_gooogleSuccess = $success;
301
302
- $this->Save();
303
}
304
305
function GetGoogleTime() {
306
- return round($this->_googleEndTime - $this->_googleStartTime,2);
307
}
308
309
var $_usedYahoo = false;
@@ -317,18 +316,18 @@ class GoogleSitemapGeneratorStatus {
317
$this->_usedYahoo = true;
318
$this->_yahooStartTime = $this->GetMicrotimeFloat();
319
320
- $this->Save();
321
}
322
323
function EndYahooPing($success) {
324
$this->_yahooEndTime = $this->GetMicrotimeFloat();
325
- $this->_yahooSuccess = $success;
326
327
- $this->Save();
328
}
329
330
function GetYahooTime() {
331
- return round($this->_yahooEndTime - $this->_yahooStartTime,2);
332
}
333
334
var $_usedAsk = false;
@@ -342,18 +341,18 @@ class GoogleSitemapGeneratorStatus {
342
$this->_askUrl = $url;
343
$this->_askStartTime = $this->GetMicrotimeFloat();
344
345
- $this->Save();
346
}
347
348
function EndAskPing($success) {
349
$this->_askEndTime = $this->GetMicrotimeFloat();
350
- $this->_askSuccess = $success;
351
352
- $this->Save();
353
}
354
355
function GetAskTime() {
356
- return round($this->_askEndTime - $this->_askStartTime,2);
357
}
358
359
var $_usedMsn = false;
@@ -367,18 +366,18 @@ class GoogleSitemapGeneratorStatus {
367
$this->_msnUrl = $url;
368
$this->_msnStartTime = $this->GetMicrotimeFloat();
369
370
- $this->Save();
371
}
372
373
function EndMsnPing($success) {
374
$this->_msnEndTime = $this->GetMicrotimeFloat();
375
- $this->_msnSuccess = $success;
376
377
- $this->Save();
378
}
379
380
function GetMsnTime() {
381
- return round($this->_msnEndTime - $this->_msnStartTime,2);
382
}
383
384
function GetMicrotimeFloat() {
@@ -414,14 +413,14 @@ class GoogleSitemapGeneratorPage {
414
var $_changeFreq;
415
416
/**
417
- * @var int $_lastMod Sets the lastMod date as a UNIX timestamp.
418
* @access private
419
*/
420
- var $_lastMod;
421
422
/**
423
* Initialize a new page object
424
- *
425
* @since 3.0
426
* @access public
427
* @author Arne Brachhold
@@ -444,7 +443,7 @@ class GoogleSitemapGeneratorPage {
444
* @return string The URL
445
*/
446
function GetUrl() {
447
- return $this->_url;
448
}
449
450
/**
@@ -453,7 +452,7 @@ class GoogleSitemapGeneratorPage {
453
* @param string $url The new URL
454
*/
455
function SetUrl($url) {
456
- $this->_url=(string) $url;
457
}
458
459
/**
@@ -462,7 +461,7 @@ class GoogleSitemapGeneratorPage {
462
* @return float the priority, from 0.0 to 1.0
463
*/
464
function GetPriority() {
465
- return $this->_priority;
466
}
467
468
/**
@@ -471,7 +470,7 @@ class GoogleSitemapGeneratorPage {
471
* @param float $priority The new priority from 0.1 to 1.0
472
*/
473
function SetProprity($priority) {
474
- $this->_priority=floatval($priority);
475
}
476
477
/**
@@ -480,7 +479,7 @@ class GoogleSitemapGeneratorPage {
480
* @return string The change frequncy like hourly, weekly, monthly etc.
481
*/
482
function GetChangeFreq() {
483
- return $this->_changeFreq;
484
}
485
486
/**
@@ -489,7 +488,7 @@ class GoogleSitemapGeneratorPage {
489
* @param string $changeFreq The new change frequency
490
*/
491
function SetChangeFreq($changeFreq) {
492
- $this->_changeFreq=(string) $changeFreq;
493
}
494
495
/**
@@ -498,7 +497,7 @@ class GoogleSitemapGeneratorPage {
498
* @return int The lastmod value in seconds
499
*/
500
function GetLastMod() {
501
- return $this->_lastMod;
502
}
503
504
/**
@@ -508,7 +507,7 @@ class GoogleSitemapGeneratorPage {
508
*/
509
function SetLastMod($lastMod) {
510
$this->_lastMod=intval($lastMod);
511
- }
512
513
function Render() {
514
@@ -518,15 +517,15 @@ class GoogleSitemapGeneratorPage {
518
$r.= "\t<url>\n";
519
$r.= "\t\t<loc>" . $this->EscapeXML($this->_url) . "</loc>\n";
520
if($this->_lastMod>0) $r.= "\t\t<lastmod>" . date('Y-m-d\TH:i:s+00:00',$this->_lastMod) . "</lastmod>\n";
521
- if(!empty($this->_changeFreq)) $r.= "\t\t<changefreq>" . $this->_changeFreq . "</changefreq>\n";
522
if($this->_priority!==false && $this->_priority!=="") $r.= "\t\t<priority>" . number_format($this->_priority,1) . "</priority>\n";
523
- $r.= "\t</url>\n";
524
return $r;
525
- }
526
527
function EscapeXML($string) {
528
return str_replace ( array ( '&', '"', "'", '<', '>'), array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;'), $string);
529
- }
530
}
531
532
class GoogleSitemapGeneratorXmlEntry {
@@ -534,19 +533,19 @@ class GoogleSitemapGeneratorXmlEntry {
534
var $_xml;
535
536
function GoogleSitemapGeneratorXmlEntry($xml) {
537
- $this->_xml = $xml;
538
}
539
540
function Render() {
541
- return $this->_xml;
542
- }
543
}
544
545
class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry {
546
547
function Render() {
548
- return "<!-- " . $this->_xml . " -->";
549
- }
550
}
551
552
/**
@@ -554,7 +553,7 @@ class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry {
554
* @author Arne Brachhold
555
* @package sitemap
556
* @since 3.0
557
- */
558
class GoogleSitemapGeneratorPrioProviderBase {
559
560
/**
@@ -590,14 +589,14 @@ class GoogleSitemapGeneratorPrioProviderBase {
590
* @return string The translated description
591
*/
592
function GetDescription() {
593
- return "";
594
}
595
596
/**
597
* Initializes a new priority provider
598
*
599
* @param $totalComments int The total number of comments of all posts
600
- * @param $totalPosts int The total number of posts
601
* @since 3.0
602
* @access public
603
* @author Arne Brachhold
@@ -606,7 +605,7 @@ class GoogleSitemapGeneratorPrioProviderBase {
606
$this->_totalComments=$totalComments;
607
$this->_totalPosts=$totalPosts;
608
609
- }
610
611
/**
612
* Returns the priority for a specified post
@@ -620,7 +619,7 @@ class GoogleSitemapGeneratorPrioProviderBase {
620
*/
621
function GetPostPriority($postID,$commentCount) {
622
return 0;
623
- }
624
}
625
626
/**
@@ -628,7 +627,7 @@ class GoogleSitemapGeneratorPrioProviderBase {
628
* @author Arne Brachhold
629
* @package sitemap
630
* @since 3.0
631
- */
632
class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPrioProviderBase {
633
634
/**
@@ -652,20 +651,20 @@ class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPr
652
* @return string The translated description
653
*/
654
function GetDescription() {
655
- return __("Uses the number of comments of the post to calculate the priority",'sitemap');
656
}
657
658
/**
659
* Initializes a new priority provider which calculates the post priority based on the number of comments
660
*
661
* @param $totalComments int The total number of comments of all posts
662
- * @param $totalPosts int The total number of posts
663
* @since 3.0
664
* @access public
665
* @author Arne Brachhold
666
*/
667
function GoogleSitemapGeneratorPrioByCountProvider($totalComments,$totalPosts) {
668
- parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
669
}
670
671
/**
@@ -681,12 +680,12 @@ class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPr
681
function GetPostPriority($postID,$commentCount) {
682
$prio=0;
683
if($this->_totalComments>0 && $commentCount>0) {
684
- $prio = round(($commentCount*100/$this->_totalComments)/100,1);
685
} else {
686
- $prio = 0;
687
}
688
return $prio;
689
- }
690
}
691
692
/**
@@ -694,7 +693,7 @@ class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPr
694
* @author Arne Brachhold
695
* @package sitemap
696
* @since 3.0
697
- */
698
class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGeneratorPrioProviderBase {
699
700
/**
@@ -724,14 +723,14 @@ class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGenerator
724
* @return string The translated description
725
*/
726
function GetDescription() {
727
- return __("Uses the average comment count to calculate the priority",'sitemap');
728
}
729
730
/**
731
* Initializes a new priority provider which calculates the post priority based on the average number of comments
732
*
733
* @param $totalComments int The total number of comments of all posts
734
- * @param $totalPosts int The total number of posts
735
* @since 3.0
736
* @access public
737
* @author Arne Brachhold
@@ -758,24 +757,24 @@ class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGenerator
758
$prio = 0;
759
//Do not divide by zero!
760
if($this->_average==0) {
761
- if($commentCount>0) $prio = 1;
762
else $prio = 0;
763
} else {
764
- $prio = $commentCount/$this->_average;
765
if($prio>1) $prio = 1;
766
else if($prio<0) $prio = 0;
767
}
768
769
return round($prio,1);
770
}
771
- }
772
773
/**
774
* Priority Provider which calculates the priority based on the popularity by the PopularityContest Plugin
775
* @author Arne Brachhold
776
* @package sitemap
777
* @since 3.0
778
- */
779
class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitemapGeneratorPrioProviderBase {
780
781
/**
@@ -787,7 +786,7 @@ class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitema
787
* @return string The translated name
788
*/
789
function GetName() {
790
- return __("Popularity Contest",'sitemap');
791
}
792
793
/**
@@ -806,7 +805,7 @@ class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitema
806
* Initializes a new priority provider which calculates the post priority based on the popularity by the PopularityContest Plugin
807
*
808
* @param $totalComments int The total number of comments of all posts
809
- * @param $totalPosts int The total number of posts
810
* @since 3.0
811
* @access public
812
* @author Arne Brachhold
@@ -844,27 +843,27 @@ class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitema
844
preg_match("/([0-9]{1,3})\%/si",$popresult,$matches);
845
if(!empty($matches) && is_array($matches) && count($matches)==2) {
846
//Divide it so 100% = 1, 10% = 0.1
847
- $res=round(intval($matches[1])/100,1);
848
}
849
}
850
}
851
}
852
return $res;
853
- }
854
}
855
856
/**
857
* Class to generate a sitemaps.org Sitemaps compliant sitemap of a WordPress blog.
858
- *
859
* @package sitemap
860
* @author Arne Brachhold
861
* @since 3.0
862
*/
863
- class GoogleSitemapGenerator {
864
/**
865
* @var Version of the generator in SVN
866
*/
867
- var $_svnVersion = '$Id: sitemap-core.php 48034 2008-05-27 14:36:18Z arnee #x27;;
868
869
/**
870
* @var array The unserialized array with the stored options
@@ -893,37 +892,37 @@ class GoogleSitemapGenerator {
893
894
/**
895
* @var string Holds the last error if one occurs when writing the files
896
- */
897
var $_lastError=null;
898
899
/**
900
* @var int The last handled post ID
901
- */
902
var $_lastPostID = 0;
903
904
/**
905
* @var bool Defines if the sitemap building process is active at the moment
906
- */
907
var $_isActive = false;
908
909
/**
910
* @var bool Defines if the sitemap building process has been scheduled via Wp cron
911
- */
912
var $_isScheduled = false;
913
914
/**
915
* @var object The file handle which is used to write the sitemap file
916
- */
917
var $_fileHandle = null;
918
919
/**
920
* @var object The file handle which is used to write the zipped sitemap file
921
- */
922
var $_fileZipHandle = null;
923
924
/**
925
* Returns the path to the blog directory
926
- *
927
* @since 3.0
928
* @access private
929
* @author Arne Brachhold
@@ -934,7 +933,7 @@ class GoogleSitemapGenerator {
934
$res="";
935
//Check if we are in the admin area -> get_home_path() is avaiable
936
if(function_exists("get_home_path")) {
937
- $res = get_home_path();
938
} else {
939
//get_home_path() is not available, but we can't include the admin
940
//libraries because many plugins check for the "check_admin_referer"
@@ -975,11 +974,14 @@ class GoogleSitemapGenerator {
975
* @return string The URL to the plugin directory
976
*/
977
function GetPluginUrl() {
978
$path = dirname(__FILE__);
979
$path = str_replace("\\","/",$path);
980
$path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));
981
return $path;
982
- }
983
984
/**
985
* Returns the URL to default XSLT style if it exists
@@ -991,33 +993,33 @@ class GoogleSitemapGenerator {
991
function GetDefaultStyle() {
992
$p = $this->GetPluginPath();
993
if(file_exists($p . "sitemap.xsl")) {
994
- return $this->GetPluginUrl() . 'sitemap.xsl';
995
}
996
return '';
997
}
998
999
/**
1000
* Returns the path to the robots.txt file in the blog root
1001
- *
1002
* @since 3.0b8
1003
* @access private
1004
* @author Arne Brachhold
1005
* @return The full path to the robots.txt file
1006
*/
1007
function GetRobotsFilePath() {
1008
- return trailingslashit($this->GetHomePath()) . 'robots.txt';
1009
}
1010
1011
/**
1012
* Returns the URL to the robots.txt file in the blog root
1013
- *
1014
* @since 3.0b8
1015
* @access private
1016
* @author Arne Brachhold
1017
* @return The full URL to the robots.txt file
1018
*/
1019
function GetRobotsFileUrl() {
1020
- return trailingslashit(get_bloginfo('siteurl')) . 'robots.txt';
1021
}
1022
1023
/**
@@ -1051,6 +1053,7 @@ class GoogleSitemapGenerator {
1051
$this->_options["sm_b_style"] = $this->GetDefaultStyle(); //Include a stylesheet in the XML
1052
$this->_options["sm_b_robots"] = false; //Modify or create robots.txt file in blog root which contains the sitemap location
1053
$this->_options["sm_b_exclude"] = array(); //List of post / page IDs to exclude
1054
$this->_options["sm_b_location_mode"]="auto"; //Mode of location, auto or manual
1055
$this->_options["sm_b_filename_manual"]=""; //Manuel filename
1056
$this->_options["sm_b_fileurl_manual"]=""; //Manuel fileurl
@@ -1078,9 +1081,9 @@ class GoogleSitemapGenerator {
1078
$this->_options["sm_pr_posts_min"]=0.2; //Minimum Priority of posts, even if autocalc is enabled
1079
$this->_options["sm_pr_pages"]=0.6; //Priority of static pages
1080
$this->_options["sm_pr_cats"]=0.3; //Priority of categories
1081
- $this->_options["sm_pr_arch"]=0.3; //Priority of archives
1082
$this->_options["sm_pr_auth"]=0.3; //Priority of author pages
1083
- $this->_options["sm_pr_tags"]=0.3; //Priority of tags
1084
1085
$this->_options["sm_i_donated"]=false; //Did you donate? Thank you! :)
1086
$this->_options["sm_i_hide_donated"]=false; //And hide the thank you..
@@ -1105,7 +1108,7 @@ class GoogleSitemapGenerator {
1105
$storedoptions=get_option("sm_options");
1106
if($storedoptions && is_array($storedoptions)) {
1107
foreach($storedoptions AS $k=>$v) {
1108
- $this->_options[$k]=$v;
1109
}
1110
} else update_option("sm_options",$this->_options); //First time use, store default values
1111
}
@@ -1176,7 +1179,7 @@ class GoogleSitemapGenerator {
1176
1177
$parents=$this->GetParentClasses($className);
1178
1179
- return in_array($parentName,$parents);
1180
}
1181
1182
/**
@@ -1222,7 +1225,7 @@ class GoogleSitemapGenerator {
1222
$r = apply_filters("sm_add_prio_provider",$this->_prioProviders);
1223
1224
//Check if no plugin return null
1225
- if($r != null) $this->_prioProviders = $r;
1226
1227
$this->ValidatePrioProviders();
1228
@@ -1235,7 +1238,7 @@ class GoogleSitemapGenerator {
1235
*
1236
* @since 3.0
1237
* @access public
1238
- * @return GoogleSitemapGenerator The instance or null if not available.
1239
* @author Arne Brachhold
1240
*/
1241
function &GetInstance() {
@@ -1259,7 +1262,7 @@ class GoogleSitemapGenerator {
1259
1260
/**
1261
* Returns if the compressed sitemap was activated
1262
- *
1263
* @since 3.0b8
1264
* @access private
1265
* @author Arne Brachhold
@@ -1271,7 +1274,7 @@ class GoogleSitemapGenerator {
1271
1272
/**
1273
* Returns if this version of WordPress supports the new taxonomy system
1274
- *
1275
* @since 3.0b8
1276
* @access private
1277
* @author Arne Brachhold
@@ -1289,7 +1292,7 @@ class GoogleSitemapGenerator {
1289
* @author Arne Brachhold
1290
*/
1291
function Enable() {
1292
- if(!isset($GLOBALS["sm_instance"])) {
1293
$GLOBALS["sm_instance"]=new GoogleSitemapGenerator();
1294
}
1295
}
@@ -1306,7 +1309,6 @@ class GoogleSitemapGenerator {
1306
$this->Initate();
1307
//Build one time per post and if not importing.
1308
if($this->GetOption("b_auto_enabled")===true && $this->_lastPostID != $postID && (!defined('WP_IMPORTING') || WP_IMPORTING != true)) {
1309
- $this->_lastPostID = $postID;
1310
1311
//Build the sitemap directly or schedule it with WP cron
1312
if($this->GetOption("b_auto_delay")==true) {
@@ -1314,12 +1316,16 @@ class GoogleSitemapGenerator {
1314
//Schedule in 15 seconds, this should be enough to catch all changes.
1315
//Clear all other existing hooks, so the sitemap is only built once.
1316
wp_clear_scheduled_hook('sm_build_cron');
1317
- wp_schedule_single_event(time()+15,'sm_build_cron');
1318
$this->_isScheduled = true;
1319
}
1320
} else {
1321
- $this->BuildSitemap();
1322
}
1323
}
1324
}
1325
@@ -1334,10 +1340,10 @@ class GoogleSitemapGenerator {
1334
if(!empty($_GET["sm_command"]) && !empty($_GET["sm_key"])) {
1335
$this->Initate();
1336
if($this->GetOption("b_manual_enabled")===true && $_GET["sm_command"]=="build" && $_GET["sm_key"]==$this->GetOption("b_manual_key")) {
1337
- $this->BuildSitemap();
1338
echo "DONE";
1339
exit;
1340
- }
1341
}
1342
}
1343
@@ -1362,7 +1368,7 @@ class GoogleSitemapGenerator {
1362
1363
if(!$this->GetOption("b_prio_provider")) {
1364
if(!in_array($this->GetOption("b_prio_provider"),$this->_prioProviders,true)) {
1365
- $this->SetOption("b_prio_provider","");
1366
}
1367
}
1368
}
@@ -1378,9 +1384,9 @@ class GoogleSitemapGenerator {
1378
array_push($providers,"GoogleSitemapGeneratorPrioByCountProvider");
1379
array_push($providers,"GoogleSitemapGeneratorPrioByAverageProvider");
1380
if(class_exists("ak_popularity_contest")) {
1381
- array_push($providers,"GoogleSitemapGeneratorPrioByPopularityContestProvider");
1382
}
1383
- return $providers;
1384
}
1385
1386
/**
@@ -1408,7 +1414,7 @@ class GoogleSitemapGenerator {
1408
$this->_pages=$storedpages;
1409
} else {
1410
$this->_pages=array();
1411
- }
1412
1413
if($needsUpdate) $this->SavePages();
1414
}
@@ -1462,7 +1468,7 @@ class GoogleSitemapGenerator {
1462
* @return The URL to the gzipped Sitemap file
1463
*/
1464
function GetZipUrl($forceAuto=false) {
1465
- return $this->GetXmlUrl($forceAuto) . ".gz";
1466
}
1467
1468
/**
@@ -1474,9 +1480,9 @@ class GoogleSitemapGenerator {
1474
* @param bool $forceAuto Force the return value to the autodetected value.
1475
* @return The file system path;
1476
*/
1477
- function GetXmlPath($forceAuto=false) {
1478
if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") {
1479
- return $this->GetOption("b_filename_manual");
1480
} else {
1481
return $this->GetHomePath() . $this->GetOption("b_filename");
1482
}
@@ -1492,7 +1498,7 @@ class GoogleSitemapGenerator {
1492
* @return The file system path;
1493
*/
1494
function GetZipPath($forceAuto=false) {
1495
- return $this->GetXmlPath($forceAuto) . ".gz";
1496
}
1497
1498
/**
@@ -1521,7 +1527,7 @@ class GoogleSitemapGenerator {
1521
function GetOption($key) {
1522
if(strpos($key,"sm_")!==0) $key="sm_" . $key;
1523
if(array_key_exists($key,$this->_options)) {
1524
- return $this->_options[$key];
1525
} else return null;
1526
}
1527
@@ -1537,7 +1543,7 @@ class GoogleSitemapGenerator {
1537
function SetOption($key,$value) {
1538
if(strstr($key,"sm_")!==0) $key="sm_" . $key;
1539
1540
- $this->_options[$key]=$value;
1541
}
1542
1543
/**
@@ -1551,8 +1557,8 @@ class GoogleSitemapGenerator {
1551
function SaveOptions() {
1552
$oldvalue = get_option("sm_options");
1553
if($oldvalue == $this->_options) {
1554
- return true;
1555
- } else return update_option("sm_options",$this->_options);
1556
}
1557
1558
/**
@@ -1573,26 +1579,26 @@ class GoogleSitemapGenerator {
1573
if($commentRes) {
1574
foreach($commentRes as $comment) {
1575
$comments[$comment->post_id]=$comment->comment_count;
1576
- }
1577
}
1578
return $comments;
1579
}
1580
1581
/**
1582
* Calculates the full number of comments from an sm_getComments() generated array
1583
- *
1584
* @since 3.0
1585
* @access private
1586
- * @author Arne Brachhold
1587
* @param $comments array The Array with posts and c0mment count
1588
* @see sm_getComments
1589
* @return The full number of comments
1590
- */
1591
function GetCommentCount($comments) {
1592
$commentCount=0;
1593
foreach($comments AS $k=>$v) {
1594
- $commentCount+=$v;
1595
- }
1596
return $commentCount;
1597
}
1598
@@ -1601,7 +1607,7 @@ class GoogleSitemapGenerator {
1601
*
1602
* @since 3.0
1603
* @access public
1604
- * @author Arne Brachhold
1605
* @param $loc string The location (url) of the page
1606
* @param $lastMod int The last Modification time as a UNIX timestamp
1607
* @param $changeFreq string The change frequenty of the page, Valid values are "always", "hourly", "daily", "weekly", "monthly", "yearly" and "never".
@@ -1617,7 +1623,7 @@ class GoogleSitemapGenerator {
1617
1618
/**
1619
* Adds an element to the sitemap
1620
- *
1621
* @since 3.0
1622
* @access private
1623
* @author Arne Brachhold
@@ -1639,13 +1645,13 @@ class GoogleSitemapGenerator {
1639
1640
/**
1641
* Checks if a file is writable and tries to make it if not.
1642
- *
1643
* @since 3.05b
1644
* @access private
1645
* @author VJTD3 <http://www.VJTD3.com>
1646
* @return bool true if writable
1647
*/
1648
- function IsFileWritable($filename) {
1649
//can we write?
1650
if(!is_writable($filename)) {
1651
//no we can't.
@@ -1658,7 +1664,7 @@ class GoogleSitemapGenerator {
1658
//darn couldn't fix up parrent directory this hosting is foobar.
1659
//Lets error because of the permissions problems.
1660
return false;
1661
- }
1662
}
1663
}
1664
}
@@ -1668,7 +1674,7 @@ class GoogleSitemapGenerator {
1668
1669
/**
1670
* Creates or opens the robots.txt in blog root and inserts the sitemap location
1671
- *
1672
* @since 3.0b8
1673
* @access private
1674
* @author Arne Brachhold
@@ -1684,7 +1690,7 @@ class GoogleSitemapGenerator {
1684
1685
$smUrl = $this->GetXmlUrl();
1686
if($this->IsGzipEnabled()) {
1687
- $smUrl = $this->GetZipUrl();
1688
}
1689
1690
$new = "Sitemap: " . $smUrl;
@@ -1693,28 +1699,28 @@ class GoogleSitemapGenerator {
1693
if($this->IsFileWritable($file)) return insert_with_markers($file,$marker,array($new));
1694
else return false;
1695
}
1696
- return true;
1697
}
1698
1699
/**
1700
* Builds the sitemap and writes it into a xml file.
1701
- *
1702
* @since 3.0
1703
* @access public
1704
* @author Arne Brachhold <himself [at] arnebrachhold [dot] de>
1705
* @return array An array with messages such as failed writes etc.
1706
*/
1707
function BuildSitemap() {
1708
- global $wpdb, $posts, $wp_version;
1709
$this->Initate();
1710
1711
if($this->GetOption("b_memory")!='') {
1712
- @ini_set("memory_limit",$this->GetOption("b_memory"));
1713
}
1714
1715
if($this->GetOption("sm_b_time")!=-1) {
1716
- @set_time_limit($this->GetOption("sm_b_time"));
1717
- }
1718
1719
//This object saves the status information of the script directly to the database
1720
$status = new GoogleSitemapGeneratorStatus();
@@ -1750,20 +1756,20 @@ class GoogleSitemapGenerator {
1750
$this->_fileZipHandle = gzopen($fileName,"w1");
1751
if(!$this->_fileZipHandle) $status->EndZip(false,"Not openable");
1752
1753
- } else $status->EndZip(false,"not writable");
1754
- }
1755
1756
if(!$this->_fileHandle && !$this->_fileZipHandle) {
1757
$status->End();
1758
return;
1759
- }
1760
1761
1762
//Content of the XML file
1763
$this->AddElement(new GoogleSitemapGeneratorXmlEntry('<?xml version="1.0" encoding="UTF-8"' . '?' . '>'));
1764
1765
if($this->GetOption("b_style")!='') {
1766
- $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<' . '?xml-stylesheet type="text/xsl" href="' . $this->GetOption("b_style") . '"?' . '>'));
1767
}
1768
1769
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("generator=\"wordpress/" . get_bloginfo('version') . "\""));
@@ -1777,7 +1783,7 @@ class GoogleSitemapGenerator {
1777
$commentCount=(count($comments)>0?$this->GetCommentCount($comments):0);
1778
1779
if($debug && $this->GetOption("b_prio_provider")!="") {
1780
- $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Total comment count: " . $commentCount));
1781
}
1782
1783
//Go XML!
@@ -1798,21 +1804,41 @@ class GoogleSitemapGenerator {
1798
//Pre 2.1 compatibility. 2.1 introduced 'future' as post_status so we don't need to check post_date
1799
$wpCompat = (floatval($wp_version) < 2.1);
1800
1801
$postPageStmt = '';
1802
1803
$inSubPages = ($this->GetOption('sm_in_posts_sub')===true);
1804
1805
if($inSubPages && $this->GetOption('in_posts')===true) {
1806
$pageDivider='<!--nextpage-->';
1807
- $postPageStmt = ", (character_length(`post_content`) - character_length(REPLACE(`post_content`, '$pageDivider', ''))) / " . strlen($pageDivider) . " as postPages";
1808
}
1809
1810
- $sql="SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` $postPageStmt FROM `" . $wpdb->posts . "` WHERE ";
1811
1812
$where = '(';
1813
1814
if($this->GetOption('in_posts')) {
1815
- //WP < 2.1: posts are post_status = publish
1816
//WP >= 2.1: post_type must be 'post', no date check required because future posts are post_status='future'
1817
if($wpCompat) $where.="(post_status = 'publish' AND post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "')";
1818
else $where.=" (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) ";
@@ -1820,23 +1846,22 @@ class GoogleSitemapGenerator {
1820
1821
if($this->GetOption('in_pages')) {
1822
if($this->GetOption('in_posts')) {
1823
- $where.=" OR ";
1824
}
1825
if($wpCompat) {
1826
//WP < 2.1: posts have post_status = published, pages have post_status = static
1827
$where.=" post_status='static' ";
1828
} else {
1829
- //WP >= 2.1: posts have post_type = 'post' and pages have post_type = 'page'. Both must be published.
1830
$where.=" (post_status = 'publish' AND post_type = 'page') ";
1831
}
1832
}
1833
1834
$where.=") ";
1835
1836
- $excludes = $this->GetOption('b_exclude');
1837
1838
if(is_array($excludes) && count($excludes)>0) {
1839
- $where.=" AND ID NOT IN ('" . implode("','",$excludes) . "')";
1840
}
1841
1842
$where.=" AND post_password='' ORDER BY post_modified DESC";
@@ -1844,8 +1869,8 @@ class GoogleSitemapGenerator {
1844
$sql .= $where;
1845
1846
if($this->GetOption("sm_b_max_posts")>0) {
1847
- $sql.=" LIMIT 0," . $this->GetOption("sm_b_max_posts");
1848
- }
1849
1850
$postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` WHERE ". $where,0,0));
1851
@@ -1853,10 +1878,10 @@ class GoogleSitemapGenerator {
1853
//Safe Mode for other plugins which use mysql_query() without a connection handler and will destroy our resultset :(
1854
$con = $postRes = null;
1855
if($this->GetOption("b_safemode")===true) {
1856
- $postRes = mysql_query($sql,$wpdb->dbh);
1857
if(!$postRes) {
1858
trigger_error("MySQL query failed: " . mysql_error(),E_USER_NOTICE); //E_NOTE will be displayed on our debug mode
1859
- return;
1860
}
1861
} else {
1862
$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD,true);
@@ -1872,7 +1897,7 @@ class GoogleSitemapGenerator {
1872
1873
if(!$postRes) {
1874
trigger_error("MySQL unbuffered query failed: " . mysql_error(),E_USER_NOTICE);
1875
- return;
1876
}
1877
}
1878
@@ -1888,7 +1913,7 @@ class GoogleSitemapGenerator {
1888
1889
//$posts is used by Alex King's Popularity Contest plugin
1890
//if($posts == null || !is_array($posts)) {
1891
- // $posts = &$postRes;
1892
//}
1893
1894
$z = 1;
@@ -1904,7 +1929,6 @@ class GoogleSitemapGenerator {
1904
1905
$minPrio=$this->GetOption('pr_posts_min');
1906
1907
- $useQTransLate = false; //function_exists('qtrans_convertURL'); Not ready yet
1908
1909
//Cycle through all posts and add them
1910
while($post = mysql_fetch_object($postRes)) {
@@ -1920,7 +1944,7 @@ class GoogleSitemapGenerator {
1920
if($wpCompat) {
1921
$isPage = ($post->post_status == 'static');
1922
} else {
1923
- $isPage = ($post->post_type == 'page');
1924
}
1925
1926
//Set the current working post
@@ -1945,7 +1969,7 @@ class GoogleSitemapGenerator {
1945
$prio = $prioProvider->GetPostPriority($post->ID,$cmtcnt);
1946
1947
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry('Debug: Priority report of postID ' . $post->ID . ': Comments: ' . $cmtcnt . ' of ' . $commentCount . ' = ' . $prio . ' points'));
1948
- }
1949
1950
if(!$isPage && $minPrio>0 && $prio<$minPrio) {
1951
$prio = $minPrio;
@@ -1961,30 +1985,29 @@ class GoogleSitemapGenerator {
1961
$subPage = $permalink . '&amp;page=' . $p;
1962
} else {
1963
$subPage = trailingslashit($permalink) . user_trailingslashit($p, 'single_paged');
1964
- }
1965
1966
$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);
1967
}
1968
}
1969
1970
-
1971
- // Multilingual Support with qTranslate, thanks to Qian Qin
1972
- if($useQTransLate) {
1973
- global $q_config;
1974
- foreach($q_config['enabled_languages'] as $language) {
1975
- if($language != $q_config['default_language']) {
1976
- $this->AddUrl(qtrans_convertURL($permalink,$language),$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);
1977
- }
1978
- }
1979
- }
1980
}
1981
1982
- //Update the status every 100 posts and at the end.
1983
- //If the script breaks because of memory or time limit,
1984
//we have a "last reponded" value which can be compared to the server settings
1985
if($zz==100 || $z == $postCount) {
1986
$status->SaveStep($z);
1987
- $zz=0;
1988
} else $zz++;
1989
1990
$z++;
@@ -1992,7 +2015,7 @@ class GoogleSitemapGenerator {
1992
//Clean cache because it's incomplete
1993
if(version_compare($wp_version,"2.5",">=")) {
1994
//WP 2.5 makes a mysql query for every clean_post_cache to clear the child cache
1995
- //so I've vopied the function here until a patch arrives...
1996
wp_cache_delete($post->ID, 'posts');
1997
wp_cache_delete($post->ID, 'post_meta');
1998
clean_object_term_cache($post->ID, 'post');
@@ -2015,10 +2038,10 @@ class GoogleSitemapGenerator {
2015
if(!$this->IsTaxonomySupported()) {
2016
2017
$catsRes=$wpdb->get_results("
2018
- SELECT
2019
- c.cat_ID AS ID,
2020
- MAX(p.post_modified_gmt) AS last_mod
2021
- FROM
2022
`" . $wpdb->categories . "` c,
2023
`" . $wpdb->post2cat . "` pc,
2024
`" . $wpdb->posts . "` p
@@ -2029,24 +2052,24 @@ class GoogleSitemapGenerator {
2029
AND p.post_type='post'
2030
GROUP
2031
BY c.cat_id
2032
- ");
2033
if($catsRes) {
2034
foreach($catsRes as $cat) {
2035
if($cat && $cat->ID && $cat->ID>0) {
2036
- if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Cat-ID:" . $cat->ID));
2037
$this->AddUrl(get_category_link($cat->ID),$this->GetTimestampFromMySql($cat->last_mod),$this->GetOption("cf_cats"),$this->GetOption("pr_cats"));
2038
}
2039
- }
2040
}
2041
} else {
2042
$cats = get_terms("category",array("hide_empty"=>true,"hierarchical"=>false));
2043
if($cats && is_array($cats) && count($cats)>0) {
2044
foreach($cats AS $cat) {
2045
- $this->AddUrl(get_category_link($cat->term_id),0,$this->GetOption("cf_cats"),$this->GetOption("pr_cats"));
2046
- }
2047
- }
2048
}
2049
- if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Cats"));
2050
}
2051
2052
//Add the archives
@@ -2056,22 +2079,22 @@ class GoogleSitemapGenerator {
2056
2057
//WP2.1 introduced post_status='future', for earlier WP versions we need to check the post_date_gmt
2058
$arcresults = $wpdb->get_results("
2059
- SELECT DISTINCT
2060
- YEAR(post_date_gmt) AS `year`,
2061
- MONTH(post_date_gmt) AS `month`,
2062
- MAX(post_date_gmt) as last_mod,
2063
- count(ID) as posts
2064
- FROM
2065
- $wpdb->posts
2066
- WHERE
2067
- post_date < '$now'
2068
- AND post_status = 'publish'
2069
AND post_type = 'post'
2070
" . (floatval($wp_version) < 2.1?"AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . "
2071
- GROUP BY
2072
- YEAR(post_date_gmt),
2073
- MONTH(post_date_gmt)
2074
- ORDER BY
2075
post_date_gmt DESC");
2076
if ($arcresults) {
2077
foreach ($arcresults as $arcresult) {
@@ -2081,15 +2104,15 @@ class GoogleSitemapGenerator {
2081
2082
//Archive is the current one
2083
if($arcresult->month==date("n") && $arcresult->year==date("Y")) {
2084
- $changeFreq=$this->GetOption("cf_arch_curr");
2085
} else { // Archive is older
2086
- $changeFreq=$this->GetOption("cf_arch_old");
2087
}
2088
2089
- $this->AddUrl($url,$this->GetTimestampFromMySql($arcresult->last_mod),$changeFreq,$this->GetOption("pr_arch"));
2090
}
2091
}
2092
- if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Archive"));
2093
}
2094
2095
//Add the author pages
@@ -2098,50 +2121,50 @@ class GoogleSitemapGenerator {
2098
2099
$linkFunc = null;
2100
2101
- //get_author_link is deprecated in WP 2.1, try to use get_author_posts_url first.
2102
if(function_exists('get_author_posts_url')) {
2103
- $linkFunc = 'get_author_posts_url';
2104
} else if(function_exists('get_author_link')) {
2105
- $linkFunc = 'get_author_link';
2106
- }
2107
2108
//Who knows what happens in later WP versions, so check again if it worked
2109
if($linkFunc !== null) {
2110
//Unfortunately there is no API function to get all authors, so we have to do it the dirty way...
2111
//We retrieve only users with published and not password protected posts (and not pages)
2112
//WP2.1 introduced post_status='future', for earlier WP versions we need to check the post_date_gmt
2113
- $sql = "SELECT DISTINCT
2114
- {$wpdb->users}.ID,
2115
- {$wpdb->users}.user_nicename,
2116
- MAX({$wpdb->posts}.post_modified_gmt) AS last_post
2117
- FROM
2118
- {$wpdb->users},
2119
- {$wpdb->posts}
2120
- WHERE
2121
- {$wpdb->posts}.post_author = {$wpdb->users}.ID
2122
AND {$wpdb->posts}.post_status = 'publish'
2123
- AND {$wpdb->posts}.post_type = 'post'
2124
- AND {$wpdb->posts}.post_password = ''
2125
" . (floatval($wp_version) < 2.1?"AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . "
2126
- GROUP BY
2127
- {$wpdb->users}.ID,
2128
{$wpdb->users}.user_nicename";
2129
2130
$authors = $wpdb->get_results($sql);
2131
2132
if($authors && is_array($authors)) {
2133
foreach($authors as $author) {
2134
- if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Author-ID:" . $author->ID));
2135
$url = ($linkFunc=='get_author_posts_url'?get_author_posts_url($author->ID,$author->user_nicename):get_author_link(false,$author->ID,$author->user_nicename));
2136
$this->AddUrl($url,$this->GetTimestampFromMySql($author->last_post),$this->GetOption("cf_auth"),$this->GetOption("pr_auth"));
2137
}
2138
}
2139
} else {
2140
//Too bad, no author pages for you :(
2141
- if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: No valid author link function found"));
2142
}
2143
2144
- if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Author pages"));
2145
}
2146
2147
//Add tag pages
@@ -2150,10 +2173,10 @@ class GoogleSitemapGenerator {
2150
$tags = get_terms("post_tag",array("hide_empty"=>true,"hierarchical"=>false));
2151
if($tags && is_array($tags) && count($tags)>0) {
2152
foreach($tags AS $tag) {
2153
- $this->AddUrl(get_tag_link($tag->term_id),0,$this->GetOption("cf_tags"),$this->GetOption("pr_tags"));
2154
- }
2155
- }
2156
- if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Tags"));
2157
}
2158
2159
//Add the custom pages
@@ -2162,7 +2185,7 @@ class GoogleSitemapGenerator {
2162
//#type $page GoogleSitemapGeneratorPage
2163
foreach($this->_pages AS $page) {
2164
$this->AddUrl($page->GetUrl(),$page->getLastMod(),$page->getChangeFreq(),$page->getPriority());
2165
- }
2166
}
2167
2168
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Custom Pages"));
@@ -2205,7 +2228,7 @@ class GoogleSitemapGenerator {
2205
} else {
2206
$status->EndGooglePing(true);
2207
}
2208
- }
2209
2210
//Ping Ask.com
2211
if($this->GetOption("b_pingask") && !empty($pingUrl)) {
@@ -2230,8 +2253,8 @@ class GoogleSitemapGenerator {
2230
$status->EndYahooPing(false,$this->_lastError);
2231
} else {
2232
$status->EndYahooPing(true);
2233
- }
2234
- }
2235
2236
//Ping MSN
2237
if($this->GetOption("b_pingmsn") && !empty($pingUrl)) {
@@ -2239,17 +2262,17 @@ class GoogleSitemapGenerator {
2239
$status->StartMsnPing($sPingUrl);
2240
$pingres=$this->RemoteOpen($sPingUrl);
2241
2242
- if($pingres==NULL || $pingres===false || strpos($pingres,"Thanks for submitting your sitemap")===false) {
2243
$status->EndMsnPing(false,$this->_lastError);
2244
} else {
2245
$status->EndMsnPing(true);
2246
}
2247
}
2248
2249
- $status->End();
2250
2251
2252
- $this->_isActive = false;
2253
2254
//done...
2255
return $status;
@@ -2262,13 +2285,13 @@ class GoogleSitemapGenerator {
2262
require_once( ABSPATH . 'wp-includes/class-snoopy.php');
2263
2264
$s = new Snoopy();
2265
- $s->fetch($url);
2266
2267
if($s->status == 200) {
2268
- $res = $s->results;
2269
}
2270
} else {
2271
- $res = wp_remote_fopen($url);
2272
}
2273
return $res;
2274
}
@@ -2281,22 +2304,22 @@ class GoogleSitemapGenerator {
2281
* @author Arne Brachhold
2282
*/
2283
function TrackError($log_level, $log_text, $error_file, $error_line) {
2284
- $this->_lastError = $log_text;
2285
}
2286
2287
/**
2288
* Echos option fields for an select field containing the valid change frequencies
2289
- *
2290
* @since 3.0
2291
* @access private
2292
* @author Arne Brachhold
2293
* @param $currentVal The value which should be selected
2294
- * @return all valid change frequencies as html option fields
2295
*/
2296
function HtmlGetFreqNames($currentVal) {
2297
2298
foreach($this->_freqNames AS $k=>$v) {
2299
- echo "<option value=\"$k\" " . $this->HtmlGetSelected($k,$currentVal) .">" . $v . "</option>";
2300
}
2301
}
2302
@@ -2307,15 +2330,15 @@ class GoogleSitemapGenerator {
2307
* @access private
2308
* @author Arne Brachhold
2309
* @param $currentVal string The value which should be selected
2310
- * @return 0.0 - 1.0 as html option fields
2311
*/
2312
function HtmlGetPriorityValues($currentVal) {
2313
$currentVal=(float) $currentVal;
2314
for($i=0.0; $i<=1.0; $i+=0.1) {
2315
echo "<option value=\"$i\" " . $this->HtmlGetSelected("$i","$currentVal") .">";
2316
_e(strval($i));
2317
- echo "</option>";
2318
- }
2319
}
2320
2321
/**
@@ -2330,7 +2353,7 @@ class GoogleSitemapGenerator {
2330
*/
2331
function HtmlGetChecked($val,$equals) {
2332
if($val==$equals) return $this->HtmlGetAttribute("checked");
2333
- else return "";
2334
}
2335
2336
/**
@@ -2345,7 +2368,7 @@ class GoogleSitemapGenerator {
2345
*/
2346
function HtmlGetSelected($val,$equals) {
2347
if($val==$equals) return $this->HtmlGetAttribute("selected");
2348
- else return "";
2349
}
2350
2351
/**
@@ -2360,7 +2383,7 @@ class GoogleSitemapGenerator {
2360
*/
2361
function HtmlGetAttribute($attr,$value=NULL) {
2362
if($value==NULL) $value=$attr;
2363
- return " " . $attr . "=\"" . $value . "\" ";
2364
}
2365
2366
/**
@@ -2404,8 +2427,8 @@ class GoogleSitemapGenerator {
2404
2405
//Add it to the array
2406
array_push($pages,$p);
2407
- }
2408
- }
2409
return $pages;
2410
}
2411
@@ -2430,20 +2453,58 @@ class GoogleSitemapGenerator {
2430
if(isset($_GET['page']) && !empty($_GET['page'])) {
2431
$page = preg_replace('[^a-zA-Z0-9\.\_\-]','',$_GET['page']);
2432
}
2433
- return $_SERVER['PHP_SELF'] . "?page=" . $page;
2434
}
2435
2436
function HtmlShowOptionsPage() {
2437
- if(!class_exists("GoogleSitemapGeneratorUI")) {
2438
-
2439
- $path = trailingslashit(dirname(__FILE__));
2440
2441
- if(!file_exists( $path . 'sitemap-ui.php')) return false;
2442
- require_once($path. 'sitemap-ui.php');
2443
- }
2444
2445
- $ui = new GoogleSitemapGeneratorUI($this);
2446
- $ui->HtmlShowOptionsPage();
2447
- return true;
2448
}
2449
}
1
+ <?php
2
/*
3
4
+ $Id: sitemap-core.php 81061 2008-12-19 03:19:01Z arnee $
5
6
*/
7
9
//error_reporting(E_ALL);
10
//ini_set("display_errors",1);
11
12
#region PHP5 compat functions
13
if (!function_exists('file_get_contents')) {
14
/**
40
41
fclose($fh);
42
return $data;
43
+ }
44
}
45
46
150
}
151
152
function Save() {
153
+ update_option("sm_status",$this);
154
}
155
156
function Load() {
157
$status = @get_option("sm_status");
158
if(is_a($status,"GoogleSitemapGeneratorStatus")) return $status;
159
+ else return null;
160
}
161
162
/**
181
* @var int $_memoryUsage The amount of memory used in bytes
182
* @access private
183
*/
184
+ var $_memoryUsage = 0;
185
186
/**
187
* @var int $_lastPost The number of posts processed. This value is updated every 50 posts.
210
$this->_memoryUsage = memory_get_peak_usage(true);
211
} else if(function_exists("memory_get_usage")) {
212
$this->_memoryUsage = memory_get_usage(true);
213
+ }
214
}
215
216
function GetMemoryUsage() {
217
+ return round($this->_memoryUsage / 1024 / 1024,2);
218
}
219
220
function SaveStep($postCount) {
222
$this->_lastPost = $postCount;
223
$this->_lastTime = $this->GetMicrotimeFloat();
224
225
+ $this->Save();
226
}
227
228
function GetTime() {
229
+ return round($this->_endTime - $this->_startTime,2);
230
}
231
232
function GetStartTime() {
233
+ return round($this->_startTime, 2);
234
}
235
236
function GetLastTime() {
237
+ return round($this->_lastTime - $this->_startTime,2);
238
}
239
240
function GetLastPost() {
241
+ return $this->_lastPost;
242
}
243
244
var $_usedXml = false;
251
$this->_xmlPath = $path;
252
$this->_xmlUrl = $url;
253
254
+ $this->Save();
255
}
256
257
function EndXml($success) {
258
+ $this->_xmlSuccess = $success;
259
260
$this->Save();
261
}
269
function StartZip($path,$url) {
270
$this->_usedZip = true;
271
$this->_zipPath = $path;
272
+ $this->_zipUrl = $url;
273
274
$this->Save();
275
}
277
function EndZip($success) {
278
$this->_zipSuccess = $success;
279
280
+ $this->Save();
281
}
282
283
var $_usedGoogle = false;
289
function StartGooglePing($url) {
290
$this->_googleUrl = true;
291
$this->_usedGoogle = true;
292
+ $this->_googleStartTime = $this->GetMicrotimeFloat();
293
294
$this->Save();
295
}
296
297
function EndGooglePing($success) {
298
$this->_googleEndTime = $this->GetMicrotimeFloat();
299
+ $this->_gooogleSuccess = $success;
300
301
+ $this->Save();
302
}
303
304
function GetGoogleTime() {
305
+ return round($this->_googleEndTime - $this->_googleStartTime,2);
306
}
307
308
var $_usedYahoo = false;
316
$this->_usedYahoo = true;
317
$this->_yahooStartTime = $this->GetMicrotimeFloat();
318
319
+ $this->Save();
320
}
321
322
function EndYahooPing($success) {
323
$this->_yahooEndTime = $this->GetMicrotimeFloat();
324
+ $this->_yahooSuccess = $success;
325
326
+ $this->Save();
327
}
328
329
function GetYahooTime() {
330
+ return round($this->_yahooEndTime - $this->_yahooStartTime,2);
331
}
332
333
var $_usedAsk = false;
341
$this->_askUrl = $url;
342
$this->_askStartTime = $this->GetMicrotimeFloat();
343
344
+ $this->Save();
345
}
346
347
function EndAskPing($success) {
348
$this->_askEndTime = $this->GetMicrotimeFloat();
349
+ $this->_askSuccess = $success;
350
351
+ $this->Save();
352
}
353
354
function GetAskTime() {
355
+ return round($this->_askEndTime - $this->_askStartTime,2);
356
}
357
358
var $_usedMsn = false;
366
$this->_msnUrl = $url;
367
$this->_msnStartTime = $this->GetMicrotimeFloat();
368
369
+ $this->Save();
370
}
371
372
function EndMsnPing($success) {
373
$this->_msnEndTime = $this->GetMicrotimeFloat();
374
+ $this->_msnSuccess = $success;
375
376
+ $this->Save();
377
}
378
379
function GetMsnTime() {
380
+ return round($this->_msnEndTime - $this->_msnStartTime,2);
381
}
382
383
function GetMicrotimeFloat() {
413
var $_changeFreq;
414
415
/**
416
+ * @var int $_lastMod Sets the lastMod date as a UNIX timestamp.
417
* @access private
418
*/
419
+ var $_lastMod;
420
421
/**
422
* Initialize a new page object
423
+ *
424
* @since 3.0
425
* @access public
426
* @author Arne Brachhold
443
* @return string The URL
444
*/
445
function GetUrl() {
446
+ return $this->_url;
447
}
448
449
/**
452
* @param string $url The new URL
453
*/
454
function SetUrl($url) {
455
+ $this->_url=(string) $url;
456
}
457
458
/**
461
* @return float the priority, from 0.0 to 1.0
462
*/
463
function GetPriority() {
464
+ return $this->_priority;
465
}
466
467
/**
470
* @param float $priority The new priority from 0.1 to 1.0
471
*/
472
function SetProprity($priority) {
473
+ $this->_priority=floatval($priority);
474
}
475
476
/**
479
* @return string The change frequncy like hourly, weekly, monthly etc.
480
*/
481
function GetChangeFreq() {
482
+ return $this->_changeFreq;
483
}
484
485
/**
488
* @param string $changeFreq The new change frequency
489
*/
490
function SetChangeFreq($changeFreq) {
491
+ $this->_changeFreq=(string) $changeFreq;
492
}
493
494
/**
497
* @return int The lastmod value in seconds
498
*/
499
function GetLastMod() {
500
+ return $this->_lastMod;
501
}
502
503
/**
507
*/
508
function SetLastMod($lastMod) {
509
$this->_lastMod=intval($lastMod);
510
+ }
511
512
function Render() {
513
517
$r.= "\t<url>\n";
518
$r.= "\t\t<loc>" . $this->EscapeXML($this->_url) . "</loc>\n";
519
if($this->_lastMod>0) $r.= "\t\t<lastmod>" . date('Y-m-d\TH:i:s+00:00',$this->_lastMod) . "</lastmod>\n";
520
+ if(!empty($this->_changeFreq)) $r.= "\t\t<changefreq>" . $this->_changeFreq . "</changefreq>\n";
521
if($this->_priority!==false && $this->_priority!=="") $r.= "\t\t<priority>" . number_format($this->_priority,1) . "</priority>\n";
522
+ $r.= "\t</url>\n";
523
return $r;
524
+ }
525
526
function EscapeXML($string) {
527
return str_replace ( array ( '&', '"', "'", '<', '>'), array ( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;'), $string);
528
+ }
529
}
530
531
class GoogleSitemapGeneratorXmlEntry {
533
var $_xml;
534
535
function GoogleSitemapGeneratorXmlEntry($xml) {
536
+ $this->_xml = $xml;
537
}
538
539
function Render() {
540
+ return $this->_xml;
541
+ }
542
}
543
544
class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry {
545
546
function Render() {
547
+ return "<!-- " . $this->_xml . " -->";
548
+ }
549
}
550
551
/**
553
* @author Arne Brachhold
554
* @package sitemap
555
* @since 3.0
556
+ */
557
class GoogleSitemapGeneratorPrioProviderBase {
558
559
/**
589
* @return string The translated description
590
*/
591
function GetDescription() {
592
+ return "";
593
}
594
595
/**
596
* Initializes a new priority provider
597
*
598
* @param $totalComments int The total number of comments of all posts
599
+ * @param $totalPosts int The total number of posts
600
* @since 3.0
601
* @access public
602
* @author Arne Brachhold
605
$this->_totalComments=$totalComments;
606
$this->_totalPosts=$totalPosts;
607
608
+ }
609
610
/**
611
* Returns the priority for a specified post
619
*/
620
function GetPostPriority($postID,$commentCount) {
621
return 0;
622
+ }
623
}
624
625
/**
627
* @author Arne Brachhold
628
* @package sitemap
629
* @since 3.0
630
+ */
631
class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPrioProviderBase {
632
633
/**
651
* @return string The translated description
652
*/
653
function GetDescription() {
654
+ return __("Uses the number of comments of the post to calculate the priority",'sitemap');
655
}
656
657
/**
658
* Initializes a new priority provider which calculates the post priority based on the number of comments
659
*
660
* @param $totalComments int The total number of comments of all posts
661
+ * @param $totalPosts int The total number of posts
662
* @since 3.0
663
* @access public
664
* @author Arne Brachhold
665
*/
666
function GoogleSitemapGeneratorPrioByCountProvider($totalComments,$totalPosts) {
667
+ parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
668
}
669
670
/**
680
function GetPostPriority($postID,$commentCount) {
681
$prio=0;
682
if($this->_totalComments>0 && $commentCount>0) {
683
+ $prio = round(($commentCount*100/$this->_totalComments)/100,1);
684
} else {
685
+ $prio = 0;
686
}
687
return $prio;
688
+ }
689
}
690
691
/**
693
* @author Arne Brachhold
694
* @package sitemap
695
* @since 3.0
696
+ */
697
class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGeneratorPrioProviderBase {
698
699
/**
723
* @return string The translated description
724
*/
725
function GetDescription() {
726
+ return __("Uses the average comment count to calculate the priority",'sitemap');
727
}
728
729
/**
730
* Initializes a new priority provider which calculates the post priority based on the average number of comments
731
*
732
* @param $totalComments int The total number of comments of all posts
733
+ * @param $totalPosts int The total number of posts
734
* @since 3.0
735
* @access public
736
* @author Arne Brachhold
757
$prio = 0;
758
//Do not divide by zero!
759
if($this->_average==0) {
760
+ if($commentCount>0) $prio = 1;
761
else $prio = 0;
762
} else {
763
+ $prio = $commentCount/$this->_average;
764
if($prio>1) $prio = 1;
765
else if($prio<0) $prio = 0;
766
}
767
768
return round($prio,1);
769
}
770
+ }
771
772
/**
773
* Priority Provider which calculates the priority based on the popularity by the PopularityContest Plugin
774
* @author Arne Brachhold
775
* @package sitemap
776
* @since 3.0
777
+ */
778
class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitemapGeneratorPrioProviderBase {
779
780
/**
786
* @return string The translated name
787
*/
788
function GetName() {
789
+ return __("Popularity Contest",'sitemap');
790
}
791
792
/**
805
* Initializes a new priority provider which calculates the post priority based on the popularity by the PopularityContest Plugin
806
*
807
* @param $totalComments int The total number of comments of all posts
808
+ * @param $totalPosts int The total number of posts
809
* @since 3.0
810
* @access public
811
* @author Arne Brachhold
843
preg_match("/([0-9]{1,3})\%/si",$popresult,$matches);
844
if(!empty($matches) && is_array($matches) && count($matches)==2) {
845
//Divide it so 100% = 1, 10% = 0.1
846
+ $res=round(intval($matches[1])/100,1);
847
}
848
}
849
}
850
}
851
return $res;
852
+ }
853
}
854
855
/**
856
* Class to generate a sitemaps.org Sitemaps compliant sitemap of a WordPress blog.
857
+ *
858
* @package sitemap
859
* @author Arne Brachhold
860
* @since 3.0
861
*/
862
+ class GoogleSitemapGenerator {
863
/**
864
* @var Version of the generator in SVN
865
*/
866
+ var $_svnVersion = '$Id: sitemap-core.php 81061 2008-12-19 03:19:01Z arnee #x27;;
867
868
/**
869
* @var array The unserialized array with the stored options
892
893
/**
894
* @var string Holds the last error if one occurs when writing the files
895
+ */
896
var $_lastError=null;
897
898
/**
899
* @var int The last handled post ID
900
+ */
901
var $_lastPostID = 0;
902
903
/**
904
* @var bool Defines if the sitemap building process is active at the moment
905
+ */
906
var $_isActive = false;
907
908
/**
909
* @var bool Defines if the sitemap building process has been scheduled via Wp cron
910
+ */
911
var $_isScheduled = false;
912
913
/**
914
* @var object The file handle which is used to write the sitemap file
915
+ */
916
var $_fileHandle = null;
917
918
/**
919
* @var object The file handle which is used to write the zipped sitemap file
920
+ */
921
var $_fileZipHandle = null;
922
923
/**
924
* Returns the path to the blog directory
925
+ *
926
* @since 3.0
927
* @access private
928
* @author Arne Brachhold
933
$res="";
934
//Check if we are in the admin area -> get_home_path() is avaiable
935
if(function_exists("get_home_path")) {
936
+ $res = get_home_path();
937
} else {
938
//get_home_path() is not available, but we can't include the admin
939
//libraries because many plugins check for the "check_admin_referer"
974
* @return string The URL to the plugin directory
975
*/
976
function GetPluginUrl() {
977
+
978
+ if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__))));
979
+
980
$path = dirname(__FILE__);
981
$path = str_replace("\\","/",$path);
982
$path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));
983
return $path;
984
+ }
985
986
/**
987
* Returns the URL to default XSLT style if it exists
993
function GetDefaultStyle() {
994
$p = $this->GetPluginPath();
995
if(file_exists($p . "sitemap.xsl")) {
996
+ return $this->GetPluginUrl() . 'sitemap.xsl';
997
}
998
return '';
999
}
1000
1001
/**
1002
* Returns the path to the robots.txt file in the blog root
1003
+ *
1004
* @since 3.0b8
1005
* @access private
1006
* @author Arne Brachhold
1007
* @return The full path to the robots.txt file
1008
*/
1009
function GetRobotsFilePath() {
1010
+ return trailingslashit($this->GetHomePath()) . 'robots.txt';
1011
}
1012
1013
/**
1014
* Returns the URL to the robots.txt file in the blog root
1015
+ *
1016
* @since 3.0b8
1017
* @access private
1018
* @author Arne Brachhold
1019
* @return The full URL to the robots.txt file
1020
*/
1021
function GetRobotsFileUrl() {
1022
+ return trailingslashit(get_bloginfo('siteurl')) . 'robots.txt';
1023
}
1024
1025
/**
1053
$this->_options["sm_b_style"] = $this->GetDefaultStyle(); //Include a stylesheet in the XML
1054
$this->_options["sm_b_robots"] = false; //Modify or create robots.txt file in blog root which contains the sitemap location
1055
$this->_options["sm_b_exclude"] = array(); //List of post / page IDs to exclude
1056
+ $this->_options["sm_b_exclude_cats"] = array(); //List of post / page IDs to exclude
1057
$this->_options["sm_b_location_mode"]="auto"; //Mode of location, auto or manual
1058
$this->_options["sm_b_filename_manual"]=""; //Manuel filename
1059
$this->_options["sm_b_fileurl_manual"]=""; //Manuel fileurl
1081
$this->_options["sm_pr_posts_min"]=0.2; //Minimum Priority of posts, even if autocalc is enabled
1082
$this->_options["sm_pr_pages"]=0.6; //Priority of static pages
1083
$this->_options["sm_pr_cats"]=0.3; //Priority of categories
1084
+ $this->_options["sm_pr_arch"]=0.3; //Priority of archives
1085
$this->_options["sm_pr_auth"]=0.3; //Priority of author pages
1086
+ $this->_options["sm_pr_tags"]=0.3; //Priority of tags
1087
1088
$this->_options["sm_i_donated"]=false; //Did you donate? Thank you! :)
1089
$this->_options["sm_i_hide_donated"]=false; //And hide the thank you..
1108
$storedoptions=get_option("sm_options");
1109
if($storedoptions && is_array($storedoptions)) {
1110
foreach($storedoptions AS $k=>$v) {
1111
+ $this->_options[$k]=$v;
1112
}
1113
} else update_option("sm_options",$this->_options); //First time use, store default values
1114
}
1179
1180
$parents=$this->GetParentClasses($className);
1181
1182
+ return in_array($parentName,$parents);
1183
}
1184
1185
/**
1225
$r = apply_filters("sm_add_prio_provider",$this->_prioProviders);
1226
1227
//Check if no plugin return null
1228
+ if($r != null) $this->_prioProviders = $r;
1229
1230
$this->ValidatePrioProviders();
1231
1238
*
1239
* @since 3.0
1240
* @access public
1241
+ * @return GoogleSitemapGenerator The instance or null if not available.
1242
* @author Arne Brachhold
1243
*/
1244
function &GetInstance() {
1262
1263
/**
1264
* Returns if the compressed sitemap was activated
1265
+ *
1266
* @since 3.0b8
1267
* @access private
1268
* @author Arne Brachhold
1274
1275
/**
1276
* Returns if this version of WordPress supports the new taxonomy system
1277
+ *
1278
* @since 3.0b8
1279
* @access private
1280
* @author Arne Brachhold
1292
* @author Arne Brachhold
1293
*/
1294
function Enable() {
1295
+ if(!isset($GLOBALS["sm_instance"])) {
1296
$GLOBALS["sm_instance"]=new GoogleSitemapGenerator();
1297
}
1298
}
1309
$this->Initate();
1310
//Build one time per post and if not importing.
1311
if($this->GetOption("b_auto_enabled")===true && $this->_lastPostID != $postID && (!defined('WP_IMPORTING') || WP_IMPORTING != true)) {
1312
1313
//Build the sitemap directly or schedule it with WP cron
1314
if($this->GetOption("b_auto_delay")==true) {
1316
//Schedule in 15 seconds, this should be enough to catch all changes.
1317
//Clear all other existing hooks, so the sitemap is only built once.
1318
wp_clear_scheduled_hook('sm_build_cron');
1319
+ wp_schedule_single_event(time()+15,'sm_build_cron');
1320
$this->_isScheduled = true;
1321
}
1322
} else {
1323
+ //Build sitemap only once and never in bulk mode
1324
+ if(!$this->_lastPostID && (!isset($_GET["delete"]) || count((array) $_GET['delete'])<=0)) {
1325
+ $this->BuildSitemap();
1326
+ }
1327
}
1328
+ $this->_lastPostID = $postID;
1329
}
1330
}
1331
1340
if(!empty($_GET["sm_command"]) && !empty($_GET["sm_key"])) {
1341
$this->Initate();
1342
if($this->GetOption("b_manual_enabled")===true && $_GET["sm_command"]=="build" && $_GET["sm_key"]==$this->GetOption("b_manual_key")) {
1343
+ $this->BuildSitemap();
1344
echo "DONE";
1345
exit;
1346
+ }
1347
}
1348
}
1349
1368
1369
if(!$this->GetOption("b_prio_provider")) {
1370
if(!in_array($this->GetOption("b_prio_provider"),$this->_prioProviders,true)) {
1371
+ $this->SetOption("b_prio_provider","");
1372
}
1373
}
1374
}
1384
array_push($providers,"GoogleSitemapGeneratorPrioByCountProvider");
1385
array_push($providers,"GoogleSitemapGeneratorPrioByAverageProvider");
1386
if(class_exists("ak_popularity_contest")) {
1387
+ array_push($providers,"GoogleSitemapGeneratorPrioByPopularityContestProvider");
1388
}
1389
+ return $providers;
1390
}
1391
1392
/**
1414
$this->_pages=$storedpages;
1415
} else {
1416
$this->_pages=array();
1417
+ }
1418
1419
if($needsUpdate) $this->SavePages();
1420
}
1468
* @return The URL to the gzipped Sitemap file
1469
*/
1470
function GetZipUrl($forceAuto=false) {
1471
+ return $this->GetXmlUrl($forceAuto) . ".gz";
1472
}
1473
1474
/**
1480
* @param bool $forceAuto Force the return value to the autodetected value.
1481
* @return The file system path;
1482
*/
1483
+ function GetXmlPath($forceAuto=false) {
1484
if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") {
1485
+ return $this->GetOption("b_filename_manual");
1486
} else {
1487
return $this->GetHomePath() . $this->GetOption("b_filename");
1488
}
1498
* @return The file system path;
1499
*/
1500
function GetZipPath($forceAuto=false) {
1501
+ return $this->GetXmlPath($forceAuto) . ".gz";
1502
}
1503
1504
/**
1527
function GetOption($key) {
1528
if(strpos($key,"sm_")!==0) $key="sm_" . $key;
1529
if(array_key_exists($key,$this->_options)) {
1530
+ return $this->_options[$key];
1531
} else return null;
1532
}
1533
1543
function SetOption($key,$value) {
1544
if(strstr($key,"sm_")!==0) $key="sm_" . $key;
1545
1546
+ $this->_options[$key]=$value;
1547
}
1548
1549
/**
1557
function SaveOptions() {
1558
$oldvalue = get_option("sm_options");
1559
if($oldvalue == $this->_options) {
1560
+ return true;
1561
+ } else return update_option("sm_options",$this->_options);
1562
}
1563
1564
/**
1579
if($commentRes) {
1580
foreach($commentRes as $comment) {
1581
$comments[$comment->post_id]=$comment->comment_count;
1582
+ }
1583
}
1584
return $comments;
1585
}
1586
1587
/**
1588
* Calculates the full number of comments from an sm_getComments() generated array
1589
+ *
1590
* @since 3.0
1591
* @access private
1592
+ * @author Arne Brachhold
1593
* @param $comments array The Array with posts and c0mment count
1594
* @see sm_getComments
1595
* @return The full number of comments
1596
+ */
1597
function GetCommentCount($comments) {
1598
$commentCount=0;
1599
foreach($comments AS $k=>$v) {
1600
+ $commentCount+=$v;
1601
+ }
1602
return $commentCount;
1603
}
1604
1607
*
1608
* @since 3.0
1609
* @access public
1610
+ * @author Arne Brachhold
1611
* @param $loc string The location (url) of the page
1612
* @param $lastMod int The last Modification time as a UNIX timestamp
1613
* @param $changeFreq string The change frequenty of the page, Valid values are "always", "hourly", "daily", "weekly", "monthly", "yearly" and "never".
1623
1624
/**
1625
* Adds an element to the sitemap
1626
+ *
1627
* @since 3.0
1628
* @access private
1629
* @author Arne Brachhold
1645
1646
/**
1647
* Checks if a file is writable and tries to make it if not.
1648
+ *
1649
* @since 3.05b
1650
* @access private
1651
* @author VJTD3 <http://www.VJTD3.com>
1652
* @return bool true if writable
1653
*/
1654
+ function IsFileWritable($filename) {
1655
//can we write?
1656
if(!is_writable($filename)) {
1657
//no we can't.
1664
//darn couldn't fix up parrent directory this hosting is foobar.
1665
//Lets error because of the permissions problems.
1666
return false;
1667
+ }
1668
}
1669
}
1670
}
1674
1675
/**
1676
* Creates or opens the robots.txt in blog root and inserts the sitemap location
1677
+ *
1678
* @since 3.0b8
1679
* @access private
1680
* @author Arne Brachhold
1690
1691
$smUrl = $this->GetXmlUrl();
1692
if($this->IsGzipEnabled()) {
1693
+ $smUrl = $this->GetZipUrl();
1694
}
1695
1696
$new = "Sitemap: " . $smUrl;
1699
if($this->IsFileWritable($file)) return insert_with_markers($file,$marker,array($new));
1700
else return false;
1701
}
1702
+ return true;
1703
}
1704
1705
/**
1706
* Builds the sitemap and writes it into a xml file.
1707
+ *
1708
* @since 3.0
1709
* @access public
1710
* @author Arne Brachhold <himself [at] arnebrachhold [dot] de>
1711
* @return array An array with messages such as failed writes etc.
1712
*/
1713
function BuildSitemap() {
1714
+ global $wpdb, $posts, $wp_version;
1715
$this->Initate();
1716
1717
if($this->GetOption("b_memory")!='') {
1718
+ @ini_set("memory_limit",$this->GetOption("b_memory"));
1719
}
1720
1721
if($this->GetOption("sm_b_time")!=-1) {
1722
+ @set_time_limit($this->GetOption("sm_b_time"));
1723
+ }
1724
1725
//This object saves the status information of the script directly to the database
1726
$status = new GoogleSitemapGeneratorStatus();
1756
$this->_fileZipHandle = gzopen($fileName,"w1");
1757
if(!$this->_fileZipHandle) $status->EndZip(false,"Not openable");
1758
1759
+ } else $status->EndZip(false,"not writable");
1760
+ }
1761
1762
if(!$this->_fileHandle && !$this->_fileZipHandle) {
1763
$status->End();
1764
return;
1765
+ }
1766
1767
1768
//Content of the XML file
1769
$this->AddElement(new GoogleSitemapGeneratorXmlEntry('<?xml version="1.0" encoding="UTF-8"' . '?' . '>'));
1770
1771
if($this->GetOption("b_style")!='') {
1772
+ $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<' . '?xml-stylesheet type="text/xsl" href="' . $this->GetOption("b_style") . '"?' . '>'));
1773
}
1774
1775
$this->AddElement(new GoogleSitemapGeneratorDebugEntry("generator=\"wordpress/" . get_bloginfo('version') . "\""));
1783
$commentCount=(count($comments)>0?$this->GetCommentCount($comments):0);
1784
1785
if($debug && $this->GetOption("b_prio_provider")!="") {
1786
+ $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Total comment count: " . $commentCount));
1787
}
1788
1789
//Go XML!
1804
//Pre 2.1 compatibility. 2.1 introduced 'future' as post_status so we don't need to check post_date
1805
$wpCompat = (floatval($wp_version) < 2.1);
1806
1807
+ $excludes = $this->GetOption('b_exclude'); //Excluded posts
1808
+
1809
+ $exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats
1810
+
1811
+ if($exclCats && count($exclCats)>0 && $this->IsTaxonomySupported()) {
1812
+
1813
+ $exPosts = get_objects_in_term($exclCats,"category"); // Get all posts in excl. cats
1814
+
1815
+ if(is_array($exPosts) && count($exPosts) > 0) { //Merge it with the list of user excluded posts
1816
+ $excludes = array_merge($excludes, $exPosts);
1817
+ }
1818
+ }
1819
+
1820
+ $useQTransLate = false; //function_exists('qtrans_convertURL') && function_exists('qtrans_getEnabledLanguages'); Not ready yet
1821
+
1822
+ $contentStmt = '';
1823
+ if($useQTransLate) {
1824
+ $contentStmt.=', post_content ';
1825
+ }
1826
+
1827
$postPageStmt = '';
1828
1829
$inSubPages = ($this->GetOption('sm_in_posts_sub')===true);
1830
1831
if($inSubPages && $this->GetOption('in_posts')===true) {
1832
$pageDivider='<!--nextpage-->';
1833
+ $postPageStmt = ", (character_length(`post_content`) - character_length(REPLACE(`post_content`, '$pageDivider', ''))) / " . strlen($pageDivider) . " as postPages";
1834
}
1835
1836
+ $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 ";
1837
1838
$where = '(';
1839
1840
if($this->GetOption('in_posts')) {
1841
+ //WP < 2.1: posts are post_status = publish
1842
//WP >= 2.1: post_type must be 'post', no date check required because future posts are post_status='future'
1843
if($wpCompat) $where.="(post_status = 'publish' AND post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "')";
1844
else $where.=" (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) ";
1846
1847
if($this->GetOption('in_pages')) {
1848
if($this->GetOption('in_posts')) {
1849
+ $where.=" OR ";
1850
}
1851
if($wpCompat) {
1852
//WP < 2.1: posts have post_status = published, pages have post_status = static
1853
$where.=" post_status='static' ";
1854
} else {
1855
+ //WP >= 2.1: posts have post_type = 'post' and pages have post_type = 'page'. Both must be published.
1856
$where.=" (post_status = 'publish' AND post_type = 'page') ";
1857
}
1858
}
1859
1860
$where.=") ";
1861
1862
1863
if(is_array($excludes) && count($excludes)>0) {
1864
+ $where.=" AND ID NOT IN ('" . implode("','",$excludes) . "')";
1865
}
1866
1867
$where.=" AND post_password='' ORDER BY post_modified DESC";
1869
$sql .= $where;
1870
1871
if($this->GetOption("sm_b_max_posts")>0) {
1872
+ $sql.=" LIMIT 0," . $this->GetOption("sm_b_max_posts");
1873
+ }
1874
1875
$postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` WHERE ". $where,0,0));
1876
1878
//Safe Mode for other plugins which use mysql_query() without a connection handler and will destroy our resultset :(
1879
$con = $postRes = null;
1880
if($this->GetOption("b_safemode")===true) {
1881
+ $postRes = mysql_query($sql,$wpdb->dbh);
1882
if(!$postRes) {
1883
trigger_error("MySQL query failed: " . mysql_error(),E_USER_NOTICE); //E_NOTE will be displayed on our debug mode
1884
+ return;
1885
}
1886
} else {
1887
$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD,true);
1897
1898
if(!$postRes) {
1899
trigger_error("MySQL unbuffered query failed: " . mysql_error(),E_USER_NOTICE);
1900
+ return;
1901
}
1902
}
1903
1913
1914
//$posts is used by Alex King's Popularity Contest plugin
1915
//if($posts == null || !is_array($posts)) {
1916
+ // $posts = &$postRes;
1917
//}
1918
1919
$z = 1;
1929
1930
$minPrio=$this->GetOption('pr_posts_min');
1931
1932
1933
//Cycle through all posts and add them
1934
while($post = mysql_fetch_object($postRes)) {
1944
if($wpCompat) {
1945
$isPage = ($post->post_status == 'static');
1946
} else {
1947
+ $isPage = ($post->post_type == 'page');
1948
}
1949
1950
//Set the current working post
1969
$prio = $prioProvider->GetPostPriority($post->ID,$cmtcnt);
1970
1971
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry('Debug: Priority report of postID ' . $post->ID . ': Comments: ' . $cmtcnt . ' of ' . $commentCount . ' = ' . $prio . ' points'));
1972
+ }
1973
1974
if(!$isPage && $minPrio>0 && $prio<$minPrio) {
1975
$prio = $minPrio;
1985
$subPage = $permalink . '&amp;page=' . $p;
1986
} else {
1987
$subPage = trailingslashit($permalink) . user_trailingslashit($p, 'single_paged');
1988
+ }
1989
1990
$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);
1991
}
1992
}
1993
1994
+ // Multilingual Support with qTranslate, thanks to Qian Qin
1995
+ if($useQTransLate) {
1996
+ global $q_config;
1997
+ foreach(qtrans_getEnabledLanguages($post->post_content) as $language) {
1998
+ if($language!=$q_config['default_language']) {
1999
+ $this->AddUrl(qtrans_convertURL($permalink,$language),$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);
2000
+ }
2001
+ }
2002
+ }
2003
}
2004
2005
+ //Update the status every 100 posts and at the end.
2006
+ //If the script breaks because of memory or time limit,
2007
//we have a "last reponded" value which can be compared to the server settings
2008
if($zz==100 || $z == $postCount) {
2009
$status->SaveStep($z);
2010
+ $zz=0;
2011
} else $zz++;
2012
2013
$z++;
2015
//Clean cache because it's incomplete
2016
if(version_compare($wp_version,"2.5",">=")) {
2017
//WP 2.5 makes a mysql query for every clean_post_cache to clear the child cache
2018
+ //so I've vopied the function here until a patch arrives...
2019
wp_cache_delete($post->ID, 'posts');
2020
wp_cache_delete($post->ID, 'post_meta');
2021
clean_object_term_cache($post->ID, 'post');
2038
if(!$this->IsTaxonomySupported()) {
2039
2040
$catsRes=$wpdb->get_results("
2041
+ SELECT
2042
+ c.cat_ID AS ID,
2043
+ MAX(p.post_modified_gmt) AS last_mod
2044
+ FROM
2045
`" . $wpdb->categories . "` c,
2046
`" . $wpdb->post2cat . "` pc,
2047
`" . $wpdb->posts . "` p
2052
AND p.post_type='post'
2053
GROUP
2054
BY c.cat_id
2055
+ ");
2056
if($catsRes) {
2057
foreach($catsRes as $cat) {
2058
if($cat && $cat->ID && $cat->ID>0) {
2059
+ if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Cat-ID:" . $cat->ID));
2060
$this->AddUrl(get_category_link($cat->ID),$this->GetTimestampFromMySql($cat->last_mod),$this->GetOption("cf_cats"),$this->GetOption("pr_cats"));
2061
}
2062
+ }
2063
}
2064
} else {
2065
$cats = get_terms("category",array("hide_empty"=>true,"hierarchical"=>false));
2066
if($cats && is_array($cats) && count($cats)>0) {
2067
foreach($cats AS $cat) {
2068
+ $this->AddUrl(get_category_link($cat->term_id),0,$this->GetOption("cf_cats"),$this->GetOption("pr_cats"));
2069
+ }
2070
+ }
2071
}
2072
+ if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Cats"));
2073
}
2074
2075
//Add the archives
2079
2080
//WP2.1 introduced post_status='future', for earlier WP versions we need to check the post_date_gmt
2081
$arcresults = $wpdb->get_results("
2082
+ SELECT DISTINCT
2083
+ YEAR(post_date_gmt) AS `year`,
2084
+ MONTH(post_date_gmt) AS `month`,
2085
+ MAX(post_date_gmt) as last_mod,
2086
+ count(ID) as posts
2087
+ FROM
2088
+ $wpdb->posts
2089
+ WHERE
2090
+ post_date < '$now'
2091
+ AND post_status = 'publish'
2092
AND post_type = 'post'
2093
" . (floatval($wp_version) < 2.1?"AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . "
2094
+ GROUP BY
2095
+ YEAR(post_date_gmt),
2096
+ MONTH(post_date_gmt)
2097
+ ORDER BY
2098
post_date_gmt DESC");
2099
if ($arcresults) {
2100
foreach ($arcresults as $arcresult) {
2104
2105
//Archive is the current one
2106
if($arcresult->month==date("n") && $arcresult->year==date("Y")) {
2107
+ $changeFreq=$this->GetOption("cf_arch_curr");
2108
} else { // Archive is older
2109
+ $changeFreq=$this->GetOption("cf_arch_old");
2110
}
2111
2112
+ $this->AddUrl($url,$this->GetTimestampFromMySql($arcresult->last_mod),$changeFreq,$this->GetOption("pr_arch"));
2113
}
2114
}
2115
+ if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Archive"));
2116
}
2117
2118
//Add the author pages
2121
2122
$linkFunc = null;
2123
2124
+ //get_author_link is deprecated in WP 2.1, try to use get_author_posts_url first.
2125
if(function_exists('get_author_posts_url')) {
2126
+ $linkFunc = 'get_author_posts_url';
2127
} else if(function_exists('get_author_link')) {
2128
+ $linkFunc = 'get_author_link';
2129
+ }
2130
2131
//Who knows what happens in later WP versions, so check again if it worked
2132
if($linkFunc !== null) {
2133
//Unfortunately there is no API function to get all authors, so we have to do it the dirty way...
2134
//We retrieve only users with published and not password protected posts (and not pages)
2135
//WP2.1 introduced post_status='future', for earlier WP versions we need to check the post_date_gmt
2136
+ $sql = "SELECT DISTINCT
2137
+ {$wpdb->users}.ID,
2138
+ {$wpdb->users}.user_nicename,
2139
+ MAX({$wpdb->posts}.post_modified_gmt) AS last_post
2140
+ FROM
2141
+ {$wpdb->users},
2142
+ {$wpdb->posts}
2143
+ WHERE
2144
+ {$wpdb->posts}.post_author = {$wpdb->users}.ID
2145
AND {$wpdb->posts}.post_status = 'publish'
2146
+ AND {$wpdb->posts}.post_type = 'post'
2147
+ AND {$wpdb->posts}.post_password = ''
2148
" . (floatval($wp_version) < 2.1?"AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . "
2149
+ GROUP BY
2150
+ {$wpdb->users}.ID,
2151
{$wpdb->users}.user_nicename";
2152
2153
$authors = $wpdb->get_results($sql);
2154
2155
if($authors && is_array($authors)) {
2156
foreach($authors as $author) {
2157
+ if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Author-ID:" . $author->ID));
2158
$url = ($linkFunc=='get_author_posts_url'?get_author_posts_url($author->ID,$author->user_nicename):get_author_link(false,$author->ID,$author->user_nicename));
2159
$this->AddUrl($url,$this->GetTimestampFromMySql($author->last_post),$this->GetOption("cf_auth"),$this->GetOption("pr_auth"));
2160
}
2161
}
2162
} else {
2163
//Too bad, no author pages for you :(
2164
+ if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: No valid author link function found"));
2165
}
2166
2167
+ if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Author pages"));
2168
}
2169
2170
//Add tag pages
2173
$tags = get_terms("post_tag",array("hide_empty"=>true,"hierarchical"=>false));
2174
if($tags && is_array($tags) && count($tags)>0) {
2175
foreach($tags AS $tag) {
2176
+ $this->AddUrl(get_tag_link($tag->term_id),0,$this->GetOption("cf_tags"),$this->GetOption("pr_tags"));
2177
+ }
2178
+ }
2179
+ if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Tags"));
2180
}
2181
2182
//Add the custom pages
2185
//#type $page GoogleSitemapGeneratorPage
2186
foreach($this->_pages AS $page) {
2187
$this->AddUrl($page->GetUrl(),$page->getLastMod(),$page->getChangeFreq(),$page->getPriority());
2188
+ }
2189
}
2190
2191
if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Custom Pages"));
2228
} else {
2229
$status->EndGooglePing(true);
2230
}
2231
+ }
2232
2233
//Ping Ask.com
2234
if($this->GetOption("b_pingask") && !empty($pingUrl)) {
2253
$status->EndYahooPing(false,$this->_lastError);
2254
} else {
2255
$status->EndYahooPing(true);
2256
+ }
2257
+ }
2258
2259
//Ping MSN
2260
if($this->GetOption("b_pingmsn") && !empty($pingUrl)) {
2262
$status->StartMsnPing($sPingUrl);
2263
$pingres=$this->RemoteOpen($sPingUrl);
2264
2265
+ if($pingres==NULL || $pingres===false || strpos($pingres,"Thanks for submitting your sitemap")===false) {
2266
$status->EndMsnPing(false,$this->_lastError);
2267
} else {
2268
$status->EndMsnPing(true);
2269
}
2270
}
2271
2272
+ $status->End();
2273
2274
2275
+ $this->_isActive = false;
2276
2277
//done...
2278
return $status;
2285
require_once( ABSPATH . 'wp-includes/class-snoopy.php');
2286
2287
$s = new Snoopy();
2288
+ $s->fetch($url);
2289
2290
if($s->status == 200) {
2291
+ $res = $s->results;
2292
}
2293
} else {
2294
+ $res = wp_remote_fopen($url);
2295
}
2296
return $res;
2297
}
2304
* @author Arne Brachhold
2305
*/
2306
function TrackError($log_level, $log_text, $error_file, $error_line) {
2307
+ $this->_lastError = $log_text;
2308
}
2309
2310
/**
2311
* Echos option fields for an select field containing the valid change frequencies
2312
+ *
2313
* @since 3.0
2314
* @access private
2315
* @author Arne Brachhold
2316
* @param $currentVal The value which should be selected
2317
+ * @return all valid change frequencies as html option fields
2318
*/
2319
function HtmlGetFreqNames($currentVal) {
2320
2321
foreach($this->_freqNames AS $k=>$v) {
2322
+ echo "<option value=\"$k\" " . $this->HtmlGetSelected($k,$currentVal) .">" . $v . "</option>";
2323
}
2324
}
2325
2330
* @access private
2331
* @author Arne Brachhold
2332
* @param $currentVal string The value which should be selected
2333
+ * @return 0.0 - 1.0 as html option fields
2334
*/
2335
function HtmlGetPriorityValues($currentVal) {
2336
$currentVal=(float) $currentVal;
2337
for($i=0.0; $i<=1.0; $i+=0.1) {
2338
echo "<option value=\"$i\" " . $this->HtmlGetSelected("$i","$currentVal") .">";
2339
_e(strval($i));
2340
+ echo "</option>";
2341
+ }
2342
}
2343
2344
/**
2353
*/
2354
function HtmlGetChecked($val,$equals) {
2355
if($val==$equals) return $this->HtmlGetAttribute("checked");
2356
+ else return "";
2357
}
2358
2359
/**
2368
*/
2369
function HtmlGetSelected($val,$equals) {
2370
if($val==$equals) return $this->HtmlGetAttribute("selected");
2371
+ else return "";
2372
}
2373
2374
/**
2383
*/
2384
function HtmlGetAttribute($attr,$value=NULL) {
2385
if($value==NULL) $value=$attr;
2386
+ return " " . $attr . "=\"" . $value . "\" ";
2387
}
2388
2389
/**
2427
2428
//Add it to the array
2429
array_push($pages,$p);
2430
+ }
2431
+ }
2432
return $pages;
2433
}
2434
2453
if(isset($_GET['page']) && !empty($_GET['page'])) {
2454
$page = preg_replace('[^a-zA-Z0-9\.\_\-]','',$_GET['page']);
2455
}
2456
+
2457
+ if(function_exists("admin_url")) return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
2458
+ else return $_SERVER['PHP_SELF'] . "?page=" . $page;
2459
+ }
2460
+
2461
+ function HtmlRegScripts() {
2462
+ $ui = $this->GetUI();
2463
+ if($ui) {
2464
+ $ui->HtmlRegScripts();
2465
+ return true;
2466
+ }
2467
}
2468
2469
function HtmlShowOptionsPage() {
2470
+
2471
+ $ui = $this->GetUI();
2472
+ if($ui) {
2473
+ $ui->HtmlShowOptionsPage();
2474
+ return true;
2475
+ }
2476
+
2477
+ return false;
2478
+ }
2479
+
2480
+ var $_ui = null;
2481
+
2482
+ function GetUI() {
2483
+
2484
+ global $wp_version;
2485
+
2486
+ if($this->_ui === null) {
2487
2488
+ $className='GoogleSitemapGeneratorUI';
2489
+ $fileName='sitemap-ui.php';
2490
2491
+ if(!class_exists($className)) {
2492
+
2493
+ $path = trailingslashit(dirname(__FILE__));
2494
+
2495
+ if(!file_exists( $path . $fileName)) return false;
2496
+ require_once($path. $fileName);
2497
+ }
2498
+
2499
+ $this->_ui = new $className($this);
2500
+
2501
+ }
2502
+
2503
+ return $this->_ui;
2504
+ }
2505
+
2506
+ function HtmlShowHelp() {
2507
+
2508
+
2509
}
2510
}
sitemap-ui.php CHANGED
@@ -1,16 +1,63 @@
1
<?php
2
/*
3
4
- $Id: sitemap-ui.php 48028 2008-05-27 14:29:50Z arnee $
5
6
*/
7
8
class GoogleSitemapGeneratorUI {
9
10
var $sg = null;
11
12
function GoogleSitemapGeneratorUI($sitemapBuilder) {
13
- $this->sg = $sitemapBuilder;
14
}
15
16
/**
@@ -29,19 +76,19 @@ class GoogleSitemapGeneratorUI {
29
30
if(isset($_GET['sm_hidedonate'])) {
31
$this->sg->SetOption('i_hide_donated',true);
32
- $this->sg->SaveOptions();
33
}
34
if(isset($_GET['sm_donated'])) {
35
$this->sg->SetOption('i_donated',true);
36
- $this->sg->SaveOptions();
37
}
38
if(isset($_GET['sm_hide_note'])) {
39
$this->sg->SetOption('i_hide_note',true);
40
- $this->sg->SaveOptions();
41
}
42
if(isset($_GET['sm_hidedonors'])) {
43
$this->sg->SetOption('i_hide_donors',true);
44
- $this->sg->SaveOptions();
45
}
46
47
if(isset($_GET['sm_donated']) || ($this->sg->GetOption('i_donated')===true && $this->sg->GetOption('i_hide_donated')!==true)) {
@@ -49,15 +96,15 @@ class GoogleSitemapGeneratorUI {
49
<div class="updated">
50
<strong><p><?php _e('Thank you very much for your donation. You help me to continue support and development of this plugin and other free software!','sitemap'); ?> <a href="<?php echo $this->sg->GetBackLink() . "&amp;sm_hidedonate=true"; ?>"><small style="font-weight:normal;"><?php _e('Hide this notice', 'sitemap'); ?></small></a></p></strong>
51
</div>
52
- <?php
53
} else if($this->sg->GetOption('i_donated') !== true && $this->sg->GetOption('i_install_date')>0 && $this->sg->GetOption('i_hide_note')!==true && time() > ($this->sg->GetOption('i_install_date') + (60*60*24*30))) {
54
?>
55
<div class="updated">
56
<strong><p><?php echo str_replace("%s",$this->sg->GetRedirectLink("sitemap-donate-note"),__('Thanks for using this plugin! You\'ve installed this plugin over a month ago. If it works and your are satisfied with the results, isn\'t it worth at least one dollar? <a href="%s">Donations</a> help me to continue support and development of this <i>free</i> software! <a href="%s">Sure, no problem!</a>','sitemap')); ?> <a href="<?php echo $this->sg->GetBackLink() . "&amp;sm_hide_note=true"; ?>" style="float:right; display:block; border:none;"><small style="font-weight:normal; "><?php _e('No thanks, please don\'t bug me anymore!', 'sitemap'); ?></small></a></p></strong>
57
<div style="clear:right;"></div>
58
</div>
59
- <?php
60
- }
61
62
if(function_exists("wp_next_scheduled")) {
63
$next = wp_next_scheduled('sm_build_cron');
@@ -66,14 +113,14 @@ class GoogleSitemapGeneratorUI {
66
if($diff <= 0) {
67
$diffMsg = __('Your sitemap is being refreshed at the moment. Depending on your blog size this might take some time!','sitemap');
68
} else {
69
- $diffMsg = str_replace("%s",$diff,__('Your sitemap will be refreshed in %s seconds. Depending on your blog size this might take some time!','sitemap'));
70
}
71
?>
72
<div class="updated">
73
<strong><p><?php echo $diffMsg ?></p></strong>
74
<div style="clear:right;"></div>
75
</div>
76
- <?php
77
}
78
}
79
@@ -83,7 +130,7 @@ class GoogleSitemapGeneratorUI {
83
84
//Check again, just for the case that something went wrong before
85
if(!current_user_can("administrator")) {
86
- echo '<p>Please log in as admin</p>';
87
return;
88
}
89
@@ -118,7 +165,7 @@ class GoogleSitemapGeneratorUI {
118
echo "<pre>";
119
print_r($this->sg->_options);
120
echo "</pre>";
121
- echo '<h3>Errors, Warnings, Notices</h3>';
122
echo '<div>';
123
$status = $this->sg->BuildSitemap();
124
echo '</div>';
@@ -130,12 +177,12 @@ class GoogleSitemapGeneratorUI {
130
131
$total = 0;
132
foreach($GLOBALS['wpdb']->queries as $q) {
133
- $total+=$q[1];
134
}
135
echo '<h4>Total Query Time</h4>';
136
echo '<pre>' . count($GLOBALS['wpdb']->queries) . ' queries in ' . round($total,2) . ' seconds.</pre>';
137
} else {
138
- echo '<p>Please edit wp-db.inc.php in wp-includes and set SAVEQUERIES to true if you want to see the queries.</p>';
139
}
140
echo "<h3>Build Process Results</h3>";
141
echo "<pre>";
@@ -156,7 +203,7 @@ class GoogleSitemapGeneratorUI {
156
echo '<noscript><a href="' . $this->sg->GetBackLink() . '">Click here to continue</a></noscript>';
157
exit;
158
}
159
- } else if (!empty($_POST['sm_update'])) { //Pressed Button: Update Config
160
check_admin_referer('sitemap');
161
foreach($this->sg->_options as $k=>$v) {
162
//Check vor values and convert them into their types, based on the category they are in
@@ -167,6 +214,7 @@ class GoogleSitemapGeneratorUI {
167
if($k=="sm_b_filename_manual" && strpos($_POST[$k],"\\")!==false){
168
$_POST[$k]=stripslashes($_POST[$k]);
169
}
170
$this->sg->_options[$k]=(string) $_POST[$k];
171
} else if($k=="sm_b_location_mode") {
172
$tmp=(string) $_POST[$k];
@@ -182,22 +230,34 @@ class GoogleSitemapGeneratorUI {
182
$IDss = array();
183
$IDs = explode(",",$_POST[$k]);
184
for($x = 0; $x<count($IDs); $x++) {
185
- $ID = intval(trim($IDs[$x]));
186
if($ID>0) $IDss[] = $ID;
187
}
188
$this->sg->_options[$k] = $IDss;
189
} else {
190
- $this->sg->_options[$k]=(bool) $_POST[$k];
191
}
192
//Options of the category "Includes" are boolean
193
} else if(substr($k,0,6)=="sm_in_") {
194
- $this->sg->_options[$k]=(bool) $_POST[$k];
195
//Options of the category "Change frequencies" are string
196
} else if(substr($k,0,6)=="sm_cf_") {
197
- $this->sg->_options[$k]=(string) $_POST[$k];
198
//Options of the category "Priorities" are float
199
} else if(substr($k,0,6)=="sm_pr_") {
200
- $this->sg->_options[$k]=(float) $_POST[$k];
201
}
202
}
203
@@ -212,10 +272,10 @@ class GoogleSitemapGeneratorUI {
212
213
if($this->sg->GetOption('sm_b_robots')===true) {
214
if($this->sg->WriteRobotsFile()) {
215
- $message.=str_replace("%s",$this->sg->GetRobotsFileUrl(),__("<a href=\"%s\">Robots.txt</a> file saved",'sitemap')) . "<br />";
216
} else {
217
- $message.=__("Error while saving Robots.txt file",'sitemap') . "<br />";
218
- }
219
}
220
221
} else if(!empty($_POST["sm_reset_config"])) { //Pressed Button: Reset Config
@@ -259,7 +319,7 @@ class GoogleSitemapGeneratorUI {
259
display:block;
260
padding-left:25px;
261
background-repeat:no-repeat;
262
- background-position:5px 50%;
263
text-decoration:none;
264
border:none;
265
}
@@ -269,97 +329,106 @@ class GoogleSitemapGeneratorUI {
269
}
270
271
a.sm_donatePayPal {
272
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-paypal.gif);
273
}
274
275
a.sm_donateAmazon {
276
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-amazon.gif);
277
}
278
279
a.sm_pluginHome {
280
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-arne.gif);
281
}
282
283
a.sm_pluginList {
284
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-email.gif);
285
}
286
287
a.sm_pluginSupport {
288
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-wordpress.gif);
289
}
290
291
a.sm_pluginBugs {
292
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-trac.gif);
293
}
294
295
a.sm_resGoogle {
296
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-google.gif);
297
}
298
299
a.sm_resYahoo {
300
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-yahoo.gif);
301
}
302
303
a.sm_resLive {
304
- background-image:url(<?php echo $this->sg->GetPluginUrl(); ?>/img/icon-live.gif);
305
}
306
307
div.sm-update-nag p {
308
margin:5px;
309
- }
310
311
</style>
312
313
<?php
314
- if(version_compare($wp_version,"2.5",">=")) {
315
- ?>
316
<style type="text/css">
317
- div#moremeta {
318
- float:right;
319
- width:200px;
320
- margin-left:10px;
321
- }
322
- div#advancedstuff {
323
- width:770px;
324
- }
325
- div#poststuff {
326
- margin-top:10px;
327
- }
328
- fieldset.dbx-box {
329
- margin-bottom:5px;
330
- }
331
-
332
- div.sm-update-nag {
333
- margin-top:10px!important;
334
- }
335
-
336
- </style>
337
- <!--[if lt IE 7]>
338
- <style type="text/css">
339
- div#advancedstuff {
340
- width:735px;
341
- }
342
- </style>
343
- <![endif]-->
344
-
345
- <?php
346
- } else { ?>
347
- <style type="text/css">
348
- div.updated-message {
349
- margin-left:0; margin-right:0;
350
- }
351
</style>
352
- <?php }
353
?>
354
355
-
356
-
357
-
358
-
359
<div class="wrap" id="sm_div">
360
<form method="post" action="<?php echo $this->sg->GetBackLink() ?>">
361
<h2><?php _e('XML Sitemap Generator for WordPress', 'sitemap'); echo " " . $this->sg->GetVersion() ?> </h2>
362
- <?php
363
if(function_exists("wp_update_plugins") && (!defined('SM_NO_UPDATE') || SM_NO_UPDATE == false)) {
364
wp_update_plugins();
365
@@ -378,7 +447,7 @@ class GoogleSitemapGeneratorUI {
378
printf( __('There is a new version of %1$s available. <a href="%2$s">Download version %3$s here</a> or <a href="%4$s">upgrade automatically</a>.','default'), $plugin_data['Name'], $r->url, $r->new_version, wp_nonce_url("update.php?action=upgrade-plugin&amp;plugin=$file", 'upgrade-plugin_' . $file) );
379
380
?></div><?php
381
- }
382
}
383
?>
384
@@ -428,662 +497,630 @@ class GoogleSitemapGeneratorUI {
428
</script>
429
<?php endif; ?>
430
431
<div id="poststuff">
432
<div id="moremeta">
433
<div id="grabit" class="dbx-group">
434
- <fieldset id="sm_pnres" class="dbx-box">
435
- <h3 class="dbx-handle"><?php _e('About this Plugin:','sitemap'); ?></h3>
436
- <div class="dbx-content">
437
- <a class="sm_button sm_pluginHome" href="<?php echo $this->sg->GetRedirectLink('sitemap-home'); ?>"><?php _e('Plugin Homepage','sitemap'); ?></a>
438
- <a class="sm_button sm_pluginHome" href="<?php echo $this->sg->GetRedirectLink('sitemap-feedback'); ?>"><?php _e('Suggest a Feature','sitemap'); ?></a>
439
- <a class="sm_button sm_pluginList" href="<?php echo $this->sg->GetRedirectLink('sitemap-list'); ?>"><?php _e('Notify List','sitemap'); ?></a>
440
- <a class="sm_button sm_pluginSupport" href="<?php echo $this->sg->GetRedirectLink('sitemap-support'); ?>"><?php _e('Support Forum','sitemap'); ?></a>
441
- <a class="sm_button sm_pluginBugs" href="<?php echo $this->sg->GetRedirectLink('sitemap-bugs'); ?>"><?php _e('Report a Bug','sitemap'); ?></a>
442
-
443
- <a class="sm_button sm_donatePayPal" href="<?php echo $this->sg->GetRedirectLink('sitemap-paypal'); ?>"><?php _e('Donate with PayPal','sitemap'); ?></a>
444
- <a class="sm_button sm_donateAmazon" href="<?php echo $this->sg->GetRedirectLink('sitemap-amazon'); ?>"><?php _e('My Amazon Wish List','sitemap'); ?></a>
445
- <?php if(__('translator_name','sitemap')!='translator_name') {?><a class="sm_button sm_pluginSupport" href="<?php _e('translator_url','sitemap'); ?>"><?php _e('translator_name','sitemap'); ?></a><?php } ?>
446
- </div>
447
- </fieldset>
448
- <fieldset id="sm_smres" class="dbx-box">
449
- <h3 class="dbx-handle"><?php _e('Sitemap Resources:','sitemap'); ?></h3>
450
- <div class="dbx-content">
451
- <a class="sm_button sm_resGoogle" href="<?php echo $this->sg->GetRedirectLink('sitemap-gwt'); ?>"><?php _e('Webmaster Tools','sitemap'); ?></a>
452
- <a class="sm_button sm_resGoogle" href="<?php echo $this->sg->GetRedirectLink('sitemap-gwb'); ?>"><?php _e('Webmaster Blog','sitemap'); ?></a>
453
-
454
- <a class="sm_button sm_resYahoo" href="<?php echo $this->sg->GetRedirectLink('sitemap-yse'); ?>"><?php _e('Site Explorer','sitemap'); ?></a>
455
- <a class="sm_button sm_resYahoo" href="<?php echo $this->sg->GetRedirectLink('sitemap-ywb'); ?>"><?php _e('Search Blog','sitemap'); ?></a>
456
-
457
- <a class="sm_button sm_resLive" href="<?php echo $this->sg->GetRedirectLink('sitemap-lwt'); ?>"><?php _e('Webmaster Tools','sitemap'); ?></a>
458
- <a class="sm_button sm_resLive" href="<?php echo $this->sg->GetRedirectLink('sitemap-lswcb'); ?>"><?php _e('Webmaster Center Blog','sitemap'); ?></a>
459
- <br />