-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsitemap-core.php
2598 lines (2189 loc) · 79.3 KB
/
sitemap-core.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
$Id: sitemap-core.php 440117 2011-09-19 13:24:49Z arnee $
*/
//Enable for dev! Good code doesn't generate any notices...
//error_reporting(E_ALL);
//ini_set("display_errors",1);
/**
* Represents the status (success and failures) of a building process
* @author Arne Brachhold
* @package sitemap
* @since 3.0b5
*/
class GoogleSitemapGeneratorStatus {
function GoogleSitemapGeneratorStatus() {
$this->_startTime = $this->GetMicrotimeFloat();
$exists = get_option("sm_status");
if($exists === false) add_option("sm_status","",null,"no");
$this->Save();
}
function Save() {
update_option("sm_status",$this);
}
/**
* Returns the last saved status object or null
*
* @return GoogleSitemapGeneratorStatus
*/
function &Load() {
$status = @get_option("sm_status");
if(is_a($status,"GoogleSitemapGeneratorStatus")) return $status;
else return null;
}
/**
* @var float $_startTime The start time of the building process
* @access private
*/
var $_startTime = 0;
/**
* @var float $_endTime The end time of the building process
* @access private
*/
var $_endTime = 0;
/**
* @var bool $$_hasChanged Indicates if the sitemap content has changed
* @access private
*/
var $_hasChanged = true;
/**
* @var int $_memoryUsage The amount of memory used in bytes
* @access private
*/
var $_memoryUsage = 0;
/**
* @var int $_lastPost The number of posts processed. This value is updated every 50 posts.
* @access private
*/
var $_lastPost = 0;
/**
* @var int $_lastTime The time when the last step-update occured. This value is updated every 50 posts.
* @access private
*/
var $_lastTime = 0;
function End($hasChanged = true) {
$this->_endTime = $this->GetMicrotimeFloat();
$this->SetMemoryUsage();
$this->_hasChanged = $hasChanged;
$this->Save();
}
function SetMemoryUsage() {
if(function_exists("memory_get_peak_usage")) {
$this->_memoryUsage = memory_get_peak_usage(true);
} else if(function_exists("memory_get_usage")) {
$this->_memoryUsage = memory_get_usage(true);
}
}
function GetMemoryUsage() {
return round($this->_memoryUsage / 1024 / 1024,2);
}
function SaveStep($postCount) {
$this->SetMemoryUsage();
$this->_lastPost = $postCount;
$this->_lastTime = $this->GetMicrotimeFloat();
$this->Save();
}
function GetTime() {
return round($this->_endTime - $this->_startTime,2);
}
function GetStartTime() {
return round($this->_startTime, 2);
}
function GetLastTime() {
return round($this->_lastTime - $this->_startTime,2);
}
function GetLastPost() {
return $this->_lastPost;
}
var $_usedXml = false;
var $_xmlSuccess = false;
var $_xmlPath = '';
var $_xmlUrl = '';
function StartXml($path,$url) {
$this->_usedXml = true;
$this->_xmlPath = $path;
$this->_xmlUrl = $url;
$this->Save();
}
function EndXml($success) {
$this->_xmlSuccess = $success;
$this->Save();
}
var $_usedZip = false;
var $_zipSuccess = false;
var $_zipPath = '';
var $_zipUrl = '';
function StartZip($path,$url) {
$this->_usedZip = true;
$this->_zipPath = $path;
$this->_zipUrl = $url;
$this->Save();
}
function EndZip($success) {
$this->_zipSuccess = $success;
$this->Save();
}
var $_usedGoogle = false;
var $_googleUrl = '';
var $_gooogleSuccess = false;
var $_googleStartTime = 0;
var $_googleEndTime = 0;
function StartGooglePing($url) {
$this->_googleUrl = $url;
$this->_usedGoogle = true;
$this->_googleStartTime = $this->GetMicrotimeFloat();
$this->Save();
}
function EndGooglePing($success) {
$this->_googleEndTime = $this->GetMicrotimeFloat();
$this->_gooogleSuccess = $success;
$this->Save();
}
function GetGoogleTime() {
return round($this->_googleEndTime - $this->_googleStartTime,2);
}
var $_usedAsk = false;
var $_askUrl = '';
var $_askSuccess = false;
var $_askStartTime = 0;
var $_askEndTime = 0;
function StartAskPing($url) {
$this->_usedAsk = true;
$this->_askUrl = $url;
$this->_askStartTime = $this->GetMicrotimeFloat();
$this->Save();
}
function EndAskPing($success) {
$this->_askEndTime = $this->GetMicrotimeFloat();
$this->_askSuccess = $success;
$this->Save();
}
function GetAskTime() {
return round($this->_askEndTime - $this->_askStartTime,2);
}
var $_usedMsn = false;
var $_msnUrl = '';
var $_msnSuccess = false;
var $_msnStartTime = 0;
var $_msnEndTime = 0;
function StartMsnPing($url) {
$this->_usedMsn = true;
$this->_msnUrl = $url;
$this->_msnStartTime = $this->GetMicrotimeFloat();
$this->Save();
}
function EndMsnPing($success) {
$this->_msnEndTime = $this->GetMicrotimeFloat();
$this->_msnSuccess = $success;
$this->Save();
}
function GetMsnTime() {
return round($this->_msnEndTime - $this->_msnStartTime,2);
}
function GetMicrotimeFloat() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
}
/**
* Represents an item in the page list
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorPage {
/**
* @var string $_url Sets the URL or the relative path to the blog dir of the page
* @access private
*/
var $_url;
/**
* @var float $_priority Sets the priority of this page
* @access private
*/
var $_priority;
/**
* @var string $_changeFreq Sets the chanfe frequency of the page. I want Enums!
* @access private
*/
var $_changeFreq;
/**
* @var int $_lastMod Sets the lastMod date as a UNIX timestamp.
* @access private
*/
var $_lastMod;
/**
* Initialize a new page object
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @param bool $enabled Should this page be included in thesitemap
* @param string $url The URL or path of the file
* @param float $priority The Priority of the page 0.0 to 1.0
* @param string $changeFreq The change frequency like daily, hourly, weekly
* @param int $lastMod The last mod date as a unix timestamp
*/
function GoogleSitemapGeneratorPage($url="",$priority=0.0,$changeFreq="never",$lastMod=0) {
$this->SetUrl($url);
$this->SetProprity($priority);
$this->SetChangeFreq($changeFreq);
$this->SetLastMod($lastMod);
}
/**
* Returns the URL of the page
*
* @return string The URL
*/
function GetUrl() {
return $this->_url;
}
/**
* Sets the URL of the page
*
* @param string $url The new URL
*/
function SetUrl($url) {
$this->_url=(string) $url;
}
/**
* Returns the priority of this page
*
* @return float the priority, from 0.0 to 1.0
*/
function GetPriority() {
return $this->_priority;
}
/**
* Sets the priority of the page
*
* @param float $priority The new priority from 0.1 to 1.0
*/
function SetProprity($priority) {
$this->_priority=floatval($priority);
}
/**
* Returns the change frequency of the page
*
* @return string The change frequncy like hourly, weekly, monthly etc.
*/
function GetChangeFreq() {
return $this->_changeFreq;
}
/**
* Sets the change frequency of the page
*
* @param string $changeFreq The new change frequency
*/
function SetChangeFreq($changeFreq) {
$this->_changeFreq=(string) $changeFreq;
}
/**
* Returns the last mod of the page
*
* @return int The lastmod value in seconds
*/
function GetLastMod() {
return $this->_lastMod;
}
/**
* Sets the last mod of the page
*
* @param int $lastMod The lastmod of the page
*/
function SetLastMod($lastMod) {
$this->_lastMod=intval($lastMod);
}
function Render() {
if($this->_url == "/" || empty($this->_url)) return '';
$r="";
$r.= "\t<url>\n";
$r.= "\t\t<loc>" . $this->EscapeXML($this->_url) . "</loc>\n";
if($this->_lastMod>0) $r.= "\t\t<lastmod>" . date('Y-m-d\TH:i:s+00:00',$this->_lastMod) . "</lastmod>\n";
if(!empty($this->_changeFreq)) $r.= "\t\t<changefreq>" . $this->_changeFreq . "</changefreq>\n";
if($this->_priority!==false && $this->_priority!=="") $r.= "\t\t<priority>" . number_format($this->_priority,1) . "</priority>\n";
$r.= "\t</url>\n";
return $r;
}
function EscapeXML($string) {
return str_replace ( array ( '&', '"', "'", '<', '>'), array ( '&' , '"', ''' , '<' , '>'), $string);
}
}
class GoogleSitemapGeneratorXmlEntry {
var $_xml;
function GoogleSitemapGeneratorXmlEntry($xml) {
$this->_xml = $xml;
}
function Render() {
return $this->_xml;
}
}
class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry {
function Render() {
return "<!-- " . $this->_xml . " -->\n";
}
}
/**
* Base class for all priority providers
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorPrioProviderBase {
/**
* @var int $_totalComments The total number of comments of all posts
* @access protected
*/
var $_totalComments=0;
/**
* @var int $_totalComments The total number of posts
* @access protected
*/
var $_totalPosts=0;
/**
* Returns the (translated) name of this priority provider
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return string The translated name
*/
function GetName() {
return "";
}
/**
* Returns the (translated) description of this priority provider
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return string The translated description
*/
function GetDescription() {
return "";
}
/**
* Initializes a new priority provider
*
* @param $totalComments int The total number of comments of all posts
* @param $totalPosts int The total number of posts
* @since 3.0
* @access public
* @author Arne Brachhold
*/
function GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts) {
$this->_totalComments=$totalComments;
$this->_totalPosts=$totalPosts;
}
/**
* Returns the priority for a specified post
*
* @param $postID int The ID of the post
* @param $commentCount int The number of comments for this post
* @since 3.0
* @access public
* @author Arne Brachhold
* @return int The calculated priority
*/
function GetPostPriority($postID,$commentCount) {
return 0;
}
}
/**
* Priority Provider which calculates the priority based on the number of comments
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorPrioByCountProvider extends GoogleSitemapGeneratorPrioProviderBase {
/**
* Returns the (translated) name of this priority provider
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return string The translated name
*/
function GetName() {
return __("Comment Count",'sitemap');
}
/**
* Returns the (translated) description of this priority provider
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return string The translated description
*/
function GetDescription() {
return __("Uses the number of comments of the post to calculate the priority",'sitemap');
}
/**
* Initializes a new priority provider which calculates the post priority based on the number of comments
*
* @param $totalComments int The total number of comments of all posts
* @param $totalPosts int The total number of posts
* @since 3.0
* @access public
* @author Arne Brachhold
*/
function GoogleSitemapGeneratorPrioByCountProvider($totalComments,$totalPosts) {
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
}
/**
* Returns the priority for a specified post
*
* @param $postID int The ID of the post
* @param $commentCount int The number of comments for this post
* @since 3.0
* @access public
* @author Arne Brachhold
* @return int The calculated priority
*/
function GetPostPriority($postID,$commentCount) {
$prio=0;
if($this->_totalComments>0 && $commentCount>0) {
$prio = round(($commentCount*100/$this->_totalComments)/100,1);
} else {
$prio = 0;
}
return $prio;
}
}
/**
* Priority Provider which calculates the priority based on the average number of comments
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorPrioByAverageProvider extends GoogleSitemapGeneratorPrioProviderBase {
/**
* @var int $_average The average number of comments per post
* @access protected
*/
var $_average=0.0;
/**
* Returns the (translated) name of this priority provider
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return string The translated name
*/
function GetName() {
return __("Comment Average",'sitemap');
}
/**
* Returns the (translated) description of this priority provider
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return string The translated description
*/
function GetDescription() {
return __("Uses the average comment count to calculate the priority",'sitemap');
}
/**
* Initializes a new priority provider which calculates the post priority based on the average number of comments
*
* @param $totalComments int The total number of comments of all posts
* @param $totalPosts int The total number of posts
* @since 3.0
* @access public
* @author Arne Brachhold
*/
function GoogleSitemapGeneratorPrioByAverageProvider($totalComments,$totalPosts) {
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
if($this->_totalComments>0 && $this->_totalPosts>0) {
$this->_average= (double) $this->_totalComments / $this->_totalPosts;
}
}
/**
* Returns the priority for a specified post
*
* @param $postID int The ID of the post
* @param $commentCount int The number of comments for this post
* @since 3.0
* @access public
* @author Arne Brachhold
* @return int The calculated priority
*/
function GetPostPriority($postID,$commentCount) {
$prio = 0;
//Do not divide by zero!
if($this->_average==0) {
if($commentCount>0) $prio = 1;
else $prio = 0;
} else {
$prio = $commentCount/$this->_average;
if($prio>1) $prio = 1;
else if($prio<0) $prio = 0;
}
return round($prio,1);
}
}
/**
* Priority Provider which calculates the priority based on the popularity by the PopularityContest Plugin
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorPrioByPopularityContestProvider extends GoogleSitemapGeneratorPrioProviderBase {
/**
* Returns the (translated) name of this priority provider
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return string The translated name
*/
function GetName() {
return __("Popularity Contest",'sitemap');
}
/**
* Returns the (translated) description of this priority provider
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return string The translated description
*/
function GetDescription() {
return str_replace("%4","index.php?page=popularity-contest.php",str_replace("%3","options-general.php?page=popularity-contest.php",str_replace("%2","http://www.alexking.org/",str_replace("%1","http://www.alexking.org/index.php?content=software/wordpress/content.php",__("Uses the activated <a href=\"%1\">Popularity Contest Plugin</a> from <a href=\"%2\">Alex King</a>. See <a href=\"%3\">Settings</a> and <a href=\"%4\">Most Popular Posts</a>",'sitemap')))));
}
/**
* Initializes a new priority provider which calculates the post priority based on the popularity by the PopularityContest Plugin
*
* @param $totalComments int The total number of comments of all posts
* @param $totalPosts int The total number of posts
* @since 3.0
* @access public
* @author Arne Brachhold
*/
function GoogleSitemapGeneratorPrioByPopularityContestProvider($totalComments,$totalPosts) {
parent::GoogleSitemapGeneratorPrioProviderBase($totalComments,$totalPosts);
}
/**
* Returns the priority for a specified post
*
* @param $postID int The ID of the post
* @param $commentCount int The number of comments for this post
* @since 3.0
* @access public
* @author Arne Brachhold
* @return int The calculated priority
*/
function GetPostPriority($postID,$commentCount) {
//$akpc is the global instance of the Popularity Contest Plugin
global $akpc,$posts;
$res=0;
//Better check if its there
if(!empty($akpc) && is_object($akpc)) {
//Is the method we rely on available?
if(method_exists($akpc,"get_post_rank")) {
if(!is_array($posts) || !$posts) $posts = array();
if(!isset($posts[$postID])) $posts[$postID] = get_post($postID);
//popresult comes as a percent value
$popresult=$akpc->get_post_rank($postID);
if(!empty($popresult) && strpos($popresult,"%")!==false) {
//We need to parse it to get the priority as an int (percent)
$matches=null;
preg_match("/([0-9]{1,3})\%/si",$popresult,$matches);
if(!empty($matches) && is_array($matches) && count($matches)==2) {
//Divide it so 100% = 1, 10% = 0.1
$res=round(intval($matches[1])/100,1);
}
}
}
}
return $res;
}
}
/**
* Class to generate a sitemaps.org Sitemaps compliant sitemap of a WordPress blog.
*
* @package sitemap
* @author Arne Brachhold
* @since 3.0
*/
class GoogleSitemapGenerator {
/**
* @var Version of the generator in SVN
*/
var $_svnVersion = '$Id: sitemap-core.php 440117 2011-09-19 13:24:49Z arnee $';
/**
* @var array The unserialized array with the stored options
*/
var $_options = array();
/**
* @var array The saved additional pages
*/
var $_pages = array();
/**
* @var array The values and names of the change frequencies
*/
var $_freqNames = array();
/**
* @var array A list of class names which my be called for priority calculation
*/
var $_prioProviders = array();
/**
* @var bool True if init complete (options loaded etc)
*/
var $_initiated = false;
/**
* @var string Holds the last error if one occurs when writing the files
*/
var $_lastError=null;
/**
* @var int The last handled post ID
*/
var $_lastPostID = 0;
/**
* @var bool Defines if the sitemap building process is active at the moment
*/
var $_isActive = false;
/**
* @var bool Defines if the sitemap building process has been scheduled via Wp cron
*/
var $_isScheduled = false;
/**
* @var object The file handle which is used to write the sitemap file
*/
var $_fileHandle = null;
/**
* @var object The file handle which is used to write the zipped sitemap file
*/
var $_fileZipHandle = null;
/**
* Holds the user interface object
*
* @since 3.1.1
* @var GoogleSitemapGeneratorUI
*/
var $_ui = null;
/**
* Returns the path to the blog directory
*
* @since 3.0
* @access private
* @author Arne Brachhold
* @return string The full path to the blog directory
*/
function GetHomePath() {
$res="";
//Check if we are in the admin area -> get_home_path() is avaiable
if(function_exists("get_home_path")) {
$res = get_home_path();
} else {
//get_home_path() is not available, but we can't include the admin
//libraries because many plugins check for the "check_admin_referer"
//function to detect if you are on an admin page. So we have to copy
//the get_home_path function in our own...
$home = get_option( 'home' );
if ( $home != '' && $home != get_option( 'url' ) ) {
$home_path = parse_url( $home );
$home_path = $home_path['path'];
$root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
$home_path = trailingslashit( $root.$home_path );
} else {
$home_path = ABSPATH;
}
$res = $home_path;
}
return $res;
}
/**
* Returns the path to the directory where the plugin file is located
* @since 3.0b5
* @access private
* @author Arne Brachhold
* @return string The path to the plugin directory
*/
function GetPluginPath() {
$path = dirname(__FILE__);
return trailingslashit(str_replace("\\","/",$path));
}
/**
* Returns the URL to the directory where the plugin file is located
* @since 3.0b5
* @access private
* @author Arne Brachhold
* @return string The URL to the plugin directory
*/
function GetPluginUrl() {
//Try to use WP API if possible, introduced in WP 2.6
if (function_exists('plugins_url')) return trailingslashit(plugins_url(basename(dirname(__FILE__))));
//Try to find manually... can't work if wp-content was renamed or is redirected
$path = dirname(__FILE__);
$path = str_replace("\\","/",$path);
$path = trailingslashit(get_bloginfo('wpurl')) . trailingslashit(substr($path,strpos($path,"wp-content/")));
return $path;
}
/**
* Returns the URL to default XSLT style if it exists
* @since 3.0b5
* @access private
* @author Arne Brachhold
* @return string The URL to the default stylesheet, empty string if not available.
*/
function GetDefaultStyle() {
$p = $this->GetPluginPath();
if(file_exists($p . "sitemap.xsl")) {
$url = $this->GetPluginUrl();
//If called over the admin area using HTTPS, the stylesheet would also be https url, even if the blog frontend is not.
if(substr(get_bloginfo('url'),0,5) !="https" && substr($url,0,5)=="https") $url="http" . substr($url,5);
return $url . 'sitemap.xsl';
}
return '';
}
/**
* Sets up the default configuration
*
* @since 3.0
* @access private
* @author Arne Brachhold
*/
function InitOptions() {
$this->_options=array();
$this->_options["sm_b_prio_provider"]="GoogleSitemapGeneratorPrioByCountProvider"; //Provider for automatic priority calculation
$this->_options["sm_b_filename"]="sitemap.xml"; //Name of the Sitemap file
$this->_options["sm_b_debug"]=true; //Write debug messages in the xml file
$this->_options["sm_b_xml"]=true; //Create a .xml file
$this->_options["sm_b_gzip"]=true; //Create a gzipped .xml file(.gz) file
$this->_options["sm_b_ping"]=true; //Auto ping Google
$this->_options["sm_b_pingask"]=true; //Auto ping Ask.com
$this->_options["sm_b_pingmsn"]=true; //Auto ping MSN
$this->_options["sm_b_manual_enabled"]=false; //Allow manual creation of the sitemap via GET request
$this->_options["sm_b_auto_enabled"]=true; //Rebuild sitemap when content is changed
$this->_options["sm_b_auto_delay"]=true; //Use WP Cron to execute the building process in the background
$this->_options["sm_b_manual_key"]=md5(microtime());//The secret key to build the sitemap via GET request
$this->_options["sm_b_memory"] = ''; //Set Memory Limit (e.g. 16M)
$this->_options["sm_b_time"] = -1; //Set time limit in seconds, 0 for unlimited, -1 for disabled
$this->_options["sm_b_max_posts"] = -1; //Maximum number of posts, <= 0 for all
$this->_options["sm_b_safemode"] = false; //Enable MySQL Safe Mode (doesn't use unbuffered results)
$this->_options["sm_b_style_default"] = true; //Use default style
$this->_options["sm_b_style"] = ''; //Include a stylesheet in the XML
$this->_options["sm_b_robots"] = true; //Add sitemap location to WordPress' virtual robots.txt file
$this->_options["sm_b_exclude"] = array(); //List of post / page IDs to exclude
$this->_options["sm_b_exclude_cats"] = array(); //List of post / page IDs to exclude
$this->_options["sm_b_location_mode"]="auto"; //Mode of location, auto or manual
$this->_options["sm_b_filename_manual"]=""; //Manuel filename
$this->_options["sm_b_fileurl_manual"]=""; //Manuel fileurl
$this->_options["sm_in_home"]=true; //Include homepage
$this->_options["sm_in_posts"]=true; //Include posts
$this->_options["sm_in_posts_sub"]=false; //Include post pages (<!--nextpage--> tag)
$this->_options["sm_in_pages"]=true; //Include static pages
$this->_options["sm_in_cats"]=false; //Include categories
$this->_options["sm_in_arch"]=false; //Include archives
$this->_options["sm_in_auth"]=false; //Include author pages
$this->_options["sm_in_tags"]=false; //Include tag pages
$this->_options["sm_in_tax"]=array(); //Include additional taxonomies
$this->_options["sm_in_customtypes"]=array(); //Include custom post types
$this->_options["sm_in_lastmod"]=true; //Include the last modification date
$this->_options["sm_cf_home"]="daily"; //Change frequency of the homepage
$this->_options["sm_cf_posts"]="monthly"; //Change frequency of posts
$this->_options["sm_cf_pages"]="weekly"; //Change frequency of static pages
$this->_options["sm_cf_cats"]="weekly"; //Change frequency of categories
$this->_options["sm_cf_auth"]="weekly"; //Change frequency of author pages
$this->_options["sm_cf_arch_curr"]="daily"; //Change frequency of the current archive (this month)
$this->_options["sm_cf_arch_old"]="yearly"; //Change frequency of older archives
$this->_options["sm_cf_tags"]="weekly"; //Change frequency of tags
$this->_options["sm_pr_home"]=1.0; //Priority of the homepage
$this->_options["sm_pr_posts"]=0.6; //Priority of posts (if auto prio is disabled)
$this->_options["sm_pr_posts_min"]=0.2; //Minimum Priority of posts, even if autocalc is enabled
$this->_options["sm_pr_pages"]=0.6; //Priority of static pages
$this->_options["sm_pr_cats"]=0.3; //Priority of categories
$this->_options["sm_pr_arch"]=0.3; //Priority of archives
$this->_options["sm_pr_auth"]=0.3; //Priority of author pages
$this->_options["sm_pr_tags"]=0.3; //Priority of tags
$this->_options["sm_i_donated"]=false; //Did you donate? Thank you! :)
$this->_options["sm_i_hide_donated"]=false; //And hide the thank you..
$this->_options["sm_i_install_date"]=time(); //The installation date
$this->_options["sm_i_hide_note"]=false; //Hide the note which appears after 30 days
$this->_options["sm_i_hide_works"]=false; //Hide the "works?" message which appears after 15 days
$this->_options["sm_i_hide_donors"]=false; //Hide the list of donations
}
/**
* Loads the configuration from the database
*
* @since 3.0
* @access private
* @author Arne Brachhold
*/
function LoadOptions() {
$this->InitOptions();
//First init default values, then overwrite it with stored values so we can add default
//values with an update which get stored by the next edit.
$storedoptions=get_option("sm_options");
if($storedoptions && is_array($storedoptions)) {
foreach($storedoptions AS $k=>$v) {
$this->_options[$k]=$v;
}
} else update_option("sm_options",$this->_options); //First time use, store default values
}
/**
* Initializes a new Google Sitemap Generator
*
* @since 3.0
* @access private
* @author Arne Brachhold
*/
function GoogleSitemapGenerator() {
}
/**
* Returns the version of the generator
*
* @since 3.0
* @access public
* @author Arne Brachhold
* @return int The version
*/
function GetVersion() {
return GoogleSitemapGeneratorLoader::GetVersion();
}
/**
* Returns all parent classes of a class
*
* @param $className string The name of the class
*
* @since 3.0
* @access private
* @author Arne Brachhold
* @return array An array which contains the names of the parent classes