This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsitemap-core.php
2390 lines (1968 loc) · 65.7 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$
*/
//Enable for dev! Good code doesn't generate any notices...
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
/**
* Represents the status (successes and failures) of a ping process
* @author Arne Brachhold
* @package sitemap
* @since 3.0b5
*/
class GoogleSitemapGeneratorStatus {
/**
* @var float $_startTime The start time of the building process
*/
private $startTime = 0;
/**
* @var float $_endTime The end time of the building process
*/
private $endTime = 0;
/**
* @var array Holding an array with the results and information of the last ping
*/
private $pingResults = array();
/**
* @var bool If the status should be saved to the database automatically
*/
private $autoSave = true;
/**
* Constructs a new status ued for saving the ping results
*/
public function __construct($autoSave = true) {
$this->startTime = microtime(true);
$this->autoSave = $autoSave;
if($autoSave) {
$exists = get_option("sm_status");
if ($exists === false)
add_option("sm_status", "", null, "no");
$this->Save();
}
}
/**
* Saves the status back to the database
*/
public function Save() {
update_option("sm_status", $this);
}
/**
* Returns the last saved status object or null
*
* @return GoogleSitemapGeneratorStatus
*/
public static function Load() {
$status = @get_option("sm_status");
if(is_a($status, "GoogleSitemapGeneratorStatus")) {
return $status;
}
else return null;
}
/**
* Ends the ping process
*/
public function End() {
$this->endTime = microtime(true);
if($this->autoSave) $this->Save();
}
/**
* Returns the duration of the ping process
* @return int
*/
public function GetDuration() {
return round($this->endTime - $this->startTime, 2);
}
/**
* Returns the time when the pings were started
* @return int
*/
public function GetStartTime() {
return round($this->startTime, 2);
}
/**
* @param $service string The internal name of the ping service
* @param $url string The URL to ping
* @param $name string The display name of the service
* @return void
*/
public function StartPing($service, $url, $name = null) {
$this->pingResults[$service] = array(
'startTime' => microtime(true),
'endTime' => 0,
'success' => false,
'url' => $url,
'name' => $name ? $name : $service
);
if($this->autoSave) $this->Save();
}
/**
* @param $service string The internal name of the ping service
* @param $success boolean If the ping was successful
* @return void
*/
public function EndPing($service, $success) {
$this->pingResults[$service]['endTime'] = microtime(true);
$this->pingResults[$service]['success'] = $success;
if($this->autoSave) $this->Save();
}
/**
* Returns the duration of the last ping of a specific ping service
*
* @param $service string The internal name of the ping service
* @return float
*/
public function GetPingDuration($service) {
$res = $this->pingResults[$service];
return round($res['endTime'] - $res['startTime'], 2);
}
/**
* Returns the last result for a specific ping service
*
* @param $service string The internal name of the ping service
* @return array
*/
public function GetPingResult($service) {
return $this->pingResults[$service]['success'];
}
/**
* Returns the URL for a specific ping service
*
* @param $service string The internal name of the ping service
* @return array
*/
public function GetPingUrl($service) {
return $this->pingResults[$service]['url'];
}
/**
* Returns the name for a specific ping service
*
* @param $service string The internal name of the ping service
* @return array
*/
public function GetServiceName($service) {
return $this->pingResults[$service]['name'];
}
/**
* Returns if a service was used in the last ping
*
* @param $service string The internal name of the ping service
* @return bool
*/
public function UsedPingService($service) {
return array_key_exists($service, $this->pingResults);
}
/**
* Returns the services which were used in the last ping
*
* @return array
*/
public function GetUsedPingServices() {
return array_keys($this->pingResults);
}
}
/**
* 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
*/
public $_url;
/**
* @var float $_priority Sets the priority of this page
*/
public $_priority;
/**
* @var string $_changeFreq Sets the chanfe frequency of the page. I want Enums!
*/
public $_changeFreq;
/**
* @var int $_lastMod Sets the lastMod date as a UNIX timestamp.
*/
public $_lastMod;
/**
* @var int $_postID Sets the post ID in case this item is a WordPress post or page
*/
public $_postID;
/**
* Initialize a new page object
*
* @since 3.0
* @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
* @param int $postID The post ID of this page
* @return GoogleSitemapGeneratorPage
*
*/
public function __construct($url = "", $priority = 0.0, $changeFreq = "never", $lastMod = 0, $postID = 0) {
$this->SetUrl($url);
$this->SetProprity($priority);
$this->SetChangeFreq($changeFreq);
$this->SetLastMod($lastMod);
$this->SetPostID($postID);
}
/**
* Returns the URL of the page
*
* @return string The URL
*/
public function GetUrl() {
return $this->_url;
}
/**
* Sets the URL of the page
*
* @param string $url The new URL
*/
public function SetUrl($url) {
$this->_url = (string) $url;
}
/**
* Returns the priority of this page
*
* @return float the priority, from 0.0 to 1.0
*/
public function GetPriority() {
return $this->_priority;
}
/**
* Sets the priority of the page
*
* @param float $priority The new priority from 0.1 to 1.0
*/
public function SetProprity($priority) {
$this->_priority = floatval($priority);
}
/**
* Returns the change frequency of the page
*
* @return string The change frequncy like hourly, weekly, monthly etc.
*/
public function GetChangeFreq() {
return $this->_changeFreq;
}
/**
* Sets the change frequency of the page
*
* @param string $changeFreq The new change frequency
*/
public function SetChangeFreq($changeFreq) {
$this->_changeFreq = (string) $changeFreq;
}
/**
* Returns the last mod of the page
*
* @return int The lastmod value in seconds
*/
public function GetLastMod() {
return $this->_lastMod;
}
/**
* Sets the last mod of the page
*
* @param int $lastMod The lastmod of the page
*/
public function SetLastMod($lastMod) {
$this->_lastMod = intval($lastMod);
}
/**
* Returns the ID of the post
*
* @return int The post ID
*/
public function GetPostID() {
return $this->_postID;
}
/**
* Sets the ID of the post
*
* @param int $postID The new ID
*/
public function SetPostID($postID) {
$this->_postID = intval($postID);
}
public 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;
}
protected function EscapeXML($string) {
return str_replace(array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $string);
}
}
/**
* Represents an XML entry, like definitions
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorXmlEntry {
protected $_xml;
public function __construct($xml) {
$this->_xml = $xml;
}
public function Render() {
return $this->_xml;
}
}
/**
* Represents an comment
* @author Arne Brachhold
* @package sitemap
* @since 3.0
* @uses GoogleSitemapGeneratorXmlEntry
*/
class GoogleSitemapGeneratorDebugEntry extends GoogleSitemapGeneratorXmlEntry {
public function Render() {
return "<!-- " . $this->_xml . " -->\n";
}
}
/**
* Represents an item in the sitemap
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorSitemapEntry {
/**
* @var string $_url Sets the URL or the relative path to the blog dir of the page
*/
protected $_url;
/**
* @var int $_lastMod Sets the lastMod date as a UNIX timestamp.
*/
protected $_lastMod;
/**
* Returns the URL of the page
*
* @return string The URL
*/
public function GetUrl() {
return $this->_url;
}
/**
* Sets the URL of the page
*
* @param string $url The new URL
*/
public function SetUrl($url) {
$this->_url = (string) $url;
}
/**
* Returns the last mod of the page
*
* @return int The lastmod value in seconds
*/
public function GetLastMod() {
return $this->_lastMod;
}
/**
* Sets the last mod of the page
*
* @param int $lastMod The lastmod of the page
*/
public function SetLastMod($lastMod) {
$this->_lastMod = intval($lastMod);
}
public function __construct($url = "", $lastMod = 0) {
$this->SetUrl($url);
$this->SetLastMod($lastMod);
}
public function Render() {
if($this->_url == "/" || empty($this->_url)) return '';
$r = "";
$r .= "\t<sitemap>\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";
$r .= "\t</sitemap>\n";
return $r;
}
protected function EscapeXML($string) {
return str_replace(array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $string);
}
}
/**
* Interface for all priority providers
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
interface GoogleSitemapGeneratorPrioProviderBase {
/**
* 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
*/
function __construct($totalComments, $totalPosts);
/**
* Returns the (translated) name of this priority provider
*
* @since 3.0
* @return string The translated name
*/
static function GetName();
/**
* Returns the (translated) description of this priority provider
*
* @since 3.0
* @return string The translated description
*/
static function GetDescription();
/**
* 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
* @return int The calculated priority
*/
function GetPostPriority($postID, $commentCount);
}
/**
* Priority Provider which calculates the priority based on the number of comments
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorPrioByCountProvider implements GoogleSitemapGeneratorPrioProviderBase {
/**
* @var int $_totalComments The total number of comments of all posts
*/
protected $_totalComments = 0;
/**
* @var int $_totalComments The total number of posts
*/
protected $_totalPosts = 0;
/**
* 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
*/
public function __construct($totalComments, $totalPosts) {
$this->_totalComments = $totalComments;
$this->_totalPosts = $totalPosts;
}
/**
* Returns the (translated) name of this priority provider
*
* @since 3.0
* @return string The translated name
*/
public static function GetName() {
return __("Comment Count", 'sitemap');
}
/**
* Returns the (translated) description of this priority provider
*
* @since 3.0
* @return string The translated description
*/
public static function GetDescription() {
return __("Uses the number of comments of the post to calculate the priority", 'sitemap');
}
/**
* 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
* @return int The calculated priority
*/
public function GetPostPriority($postID, $commentCount) {
if($this->_totalComments > 0 && $commentCount > 0) {
return round(($commentCount * 100 / $this->_totalComments) / 100, 1);
} else {
return 0;
}
}
}
/**
* Priority Provider which calculates the priority based on the average number of comments
* @author Arne Brachhold
* @package sitemap
* @since 3.0
*/
class GoogleSitemapGeneratorPrioByAverageProvider implements GoogleSitemapGeneratorPrioProviderBase {
/**
* @var int $_totalComments The total number of comments of all posts
*/
protected $_totalComments = 0;
/**
* @var int $_totalComments The total number of posts
*/
protected $_totalPosts = 0;
/**
* @var int $_average The average number of comments per post
*/
protected $_average = 0.0;
/**
* Returns the (translated) name of this priority provider
*
* @since 3.0
* @return string The translated name
*/
public static function GetName() {
return __("Comment Average", 'sitemap');
}
/**
* Returns the (translated) description of this priority provider
*
* @since 3.0
* @return string The translated description
*/
public static 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
*/
public function __construct($totalComments, $totalPosts) {
$this->_totalComments = $totalComments;
$this->_totalPosts = $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
* @return int The calculated priority
*/
public function GetPostPriority($postID, $commentCount) {
//Do not divide by zero!
if($this->_average == 0) {
if($commentCount > 0) $priority = 1;
else $priority = 0;
} else {
$priority = $commentCount / $this->_average;
if($priority > 1) $priority = 1;
else if($priority < 0) $priority = 0;
}
return round($priority, 1);
}
}
/**
* Class to generate a sitemaps.org Sitemaps compliant sitemap of a WordPress blog.
*
* @package sitemap
* @author Arne Brachhold
* @since 3.0
*/
final class GoogleSitemapGenerator {
/**
* @var array The unserialized array with the stored options
*/
private $options = array();
/**
* @var array The saved additional pages
*/
private $pages = array();
/**
* @var array The values and names of the change frequencies
*/
private $freqNames = array();
/**
* @var array A list of class names which my be called for priority calculation
*/
private $prioProviders = array();
/**
* @var bool True if init complete (options loaded etc)
*/
private $isInitiated = false;
/**
* @var bool Defines if the sitemap building process is active at the moment
*/
private $isActive = false;
/**
* @var array Holds options like output format and compression for the current request
*/
private $buildOptions = array();
/**
* Holds the user interface object
*
* @since 3.1.1
* @var GoogleSitemapGeneratorUI
*/
private $ui = null;
/**
* Defines if the simulation mode is on. In this case, data is not echoed but saved instead.
* @var boolean
*/
private $simMode = false;
/**
* Holds the data if simulation mode is on
* @var array
*/
private $simData = array("sitemaps" => array(), "content" => array());
/**
* @var bool Defines if the options have been loaded
*/
private $optionsLoaded = false;
/**
* @var string[] The list of cached sitemap transients
*/
private $savedTransients = null;
/*************************************** CONSTRUCTION AND INITIALIZING ***************************************/
/**
* Initializes a new Google Sitemap Generator
*
* @since 4.0
*/
private function __construct() {
}
/**
* Returns the instance of the Sitemap Generator
*
* @since 3.0
* @return GoogleSitemapGenerator The instance or null if not available.
*/
public static function GetInstance() {
if(isset($GLOBALS["sm_instance"])) {
return $GLOBALS["sm_instance"];
} else return null;
}
/**
* Enables the Google Sitemap Generator and registers the WordPress hooks
*
* @since 3.0
*/
public static function Enable() {
if(!isset($GLOBALS["sm_instance"])) {
$GLOBALS["sm_instance"] = new GoogleSitemapGenerator();
}
}
/**
* Loads up the configuration and validates the prioity providers
*
* This method is only called if the sitemaps needs to be build or the admin page is displayed.
*
* @since 3.0
*/
public function Initate() {
if(!$this->isInitiated) {
load_plugin_textdomain('sitemap',false,dirname( plugin_basename( __FILE__ ) ) . '/lang');
$this->freqNames = array(
"always" => __("Always", "sitemap"),
"hourly" => __("Hourly", "sitemap"),
"daily" => __("Daily", "sitemap"),
"weekly" => __("Weekly", "sitemap"),
"monthly" => __("Monthly", "sitemap"),
"yearly" => __("Yearly", "sitemap"),
"never" => __("Never", "sitemap")
);
$this->LoadOptions();
$this->LoadPages();
//Register our own priority providers
add_filter("sm_add_prio_provider", array($this, 'AddDefaultPrioProviders'));
//Let other plugins register their providers
$r = apply_filters("sm_add_prio_provider", $this->prioProviders);
//Check if no plugin return null
if($r != null) $this->prioProviders = $r;
$this->ValidatePrioProviders();
$this->isInitiated = true;
}
}
/*************************************** VERSION AND LINK HELPERS ***************************************/
/**
* Returns the version of the generator
*
* @since 3.0
* @return int The version
*/
public static function GetVersion() {
return GoogleSitemapGeneratorLoader::GetVersion();
}
/**
* Returns the SVN version of the generator
*
* @since 4.0
* @return string The SVN version string
*/
public static function GetSvnVersion() {
return GoogleSitemapGeneratorLoader::GetSvnVersion();
}
/**
* Returns a link pointing to a specific page of the authors website
*
* @since 3.0
* @param $redir string The to link to
* @return string The full url
*/
public static function GetRedirectLink($redir) {
return trailingslashit("http://www.arnebrachhold.de/redir/" . $redir);
}
/**
* Returns a link pointing back to the plugin page in WordPress
*
* @since 3.0
* @return string The full url
*/
public static function GetBackLink() {
global $wp_version;
$url = admin_url("options-general.php?page=" . GoogleSitemapGeneratorLoader::GetBaseName());
return $url;
}
/**
* Converts a mysql datetime value into a unix timestamp
* @param $mysqlDateTime string The timestamp in the mysql datetime format
* @return int The time in seconds
*/
public static function GetTimestampFromMySql($mysqlDateTime) {
list($date, $hours) = explode(' ', $mysqlDateTime);
list($year, $month, $day) = explode('-', $date);
list($hour, $min, $sec) = explode(':', $hours);
return mktime(intval($hour), intval($min), intval($sec), intval($month), intval($day), intval($year));
}
/*************************************** SIMPLE GETTERS ***************************************/
/**
* Returns the names for the frequency values
* @return array
*/
public function GetFreqNames() {
return $this->freqNames;
}
/**
* Returns if the blog is running in multi site mode
* @since 4.0
* @return bool
*/
public function IsMultiSite() {
return (function_exists("is_multisite") && is_multisite());
}
/**
* Returns if the sitemap building process is currently active
*
* @since 3.0
* @return bool true if active
*/
public function IsActive() {
$inst = GoogleSitemapGenerator::GetInstance();
return ($inst != null && $inst->isActive);
}
/**
* Returns if the compressed sitemap was activated
*
* @since 3.0b8
* @return true if compressed
*/
public function IsGzipEnabled() {
return (function_exists("gzwrite") && $this->GetOption('b_autozip'));
}
/**
* Returns if the XML Dom and XSLT functions are enabled
*
* @since 4.0b1
* @return true if compressed
*/
public function IsXslEnabled() {
return (class_exists("DomDocument") && class_exists("XSLTProcessor"));
}
/**
* Returns if Nginx is used as the server software
* @since 4.0.3
*
* @return bool
*/
function IsNginx() {
if ( isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false ) {
return true;
}
return false;
}
/*************************************** TAXONOMIES AND CUSTOM POST TYPES ***************************************/
/**
* Returns if this version of WordPress supports the new taxonomy system
*
* @since 3.0b8
* @return true if supported
*/
public function IsTaxonomySupported() {
return (function_exists("get_taxonomy") && function_exists("get_terms") && function_exists("get_taxonomies"));
}
/**
* Returns the list of custom taxonomies. These are basically all taxonomies without categories and post tags
*
* @since 3.1.7
* @return array Array of names of user-defined taxonomies
*/
public function GetCustomTaxonomies() {
$taxonomies = get_taxonomies(array("public" => 1));
return array_diff($taxonomies, array("category", "post_tag", "nav_menu", "link_category", "post_format"));
}
/**
* Returns if this version of WordPress supports custom post types
*
* @since 3.2.5
* @return true if supported
*/
public function IsCustomPostTypesSupported() {
return (function_exists("get_post_types") && function_exists("register_post_type"));
}
/**
* Returns the list of custom post types. These are all custom post types except post, page and attachment
*
* @since 3.2.5
* @return array Array of custom post types as per get_post_types
*/
public function GetCustomPostTypes() {
$post_types = get_post_types(array("public" => 1));
$post_types = array_diff($post_types, array("post", "page", "attachment"));
return $post_types;
}
/**
* Returns the list of active post types, built-in and custom ones.
*
* @since 4.0b5
* @return array Array of custom post types as per get_post_types
*/
public function GetActivePostTypes() {
$cacheKey = __CLASS__ . "::GetActivePostTypes";
$activePostTypes = wp_cache_get($cacheKey,'sitemap');
if($activePostTypes === false) {
$allPostTypes = get_post_types();
$enabledPostTypes = $this->GetOption('in_customtypes');
if($this->GetOption("in_posts")) $enabledPostTypes[] = "post";
if($this->GetOption("in_pages")) $enabledPostTypes[] = "page";
$activePostTypes = array();