-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml-sitemaps.php
111 lines (83 loc) · 3.6 KB
/
xml-sitemaps.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
<?php
// hook into Better Wordpress Google XML Sitemaps plugin for Multi-Site http://wordpress.org/plugins/bwp-google-xml-sitemaps/
//add_action('bwp_gxs_modules_built', array('dsSearchAgent_XmlSitemaps', 'BwpGoogleXmlSitemapModule'));
add_filter('bwp_gxs_external_pages', array('dsSearchAgent_XmlSitemaps', 'BwpGoogleXmlSitemap'));
// or hook into Google XML Sitemaps Generator plugin http://wordpress.org/extend/plugins/google-sitemap-generator/
add_action('sm_buildmap', array('dsSearchAgent_XmlSitemaps', 'GoogleXmlSitemap'));
class dsSearchAgent_XmlSitemaps {
static function GetSitemapOptions() {
$options = get_option(DSIDXPRESS_OPTION_NAME);
$urlBase = get_home_url();
if (substr($urlBase, strlen($urlBase), 1) != "/") $urlBase .= "/";
$urlBase .= dsSearchAgent_Rewrite::GetUrlSlug();
$sitemapUrls = array();
$idxPages = get_pages(array('post_type' => 'ds-idx-listings-page', 'post_status'=>'publish'));
foreach ($idxPages as $page) {
$sitemapUrls[] = array('location' => get_permalink($page->ID), 'frequency' => 'daily', 'priority' => 0.5);
}
if (isset($options["SitemapLocations"]) && is_array($options["SitemapLocations"])) {
$location_index = 0;
usort($options["SitemapLocations"], array("dsSearchAgent_XmlSitemaps", "CompareListObjects"));
foreach ($options["SitemapLocations"] as $key => $value) {
$area = $value["value"];
$type = $value["type"];
if (preg_match('/^[\w\d\s\-_]+$/', $area)) {
$location_sanitized = urlencode(strtolower(str_replace(array("-", " "), array("_", "-"), $value["value"])));
$url = $urlBase . $value["type"] .'/'. $location_sanitized . '/';
} else if ($type == "city") {
$url = $urlBase . "?idx-q-Cities=" . urlencode($area);
} else if ($type == "community") {
$url = $urlBase . "?idx-q-Communities=" . urlencode($area);
} else if ($type == "tract") {
$url = $urlBase . "?idx-q-TractIdentifiers=" . urlencode($area);
}
// zips will always match the regex
$sitemapUrls[] = array('location' => $url, 'frequency' => $options['SitemapFrequency'], 'priority' => floatval($value["priority"]));
}
}
/**
* Modify what URLs are displayed in the sitemap
* @param array $sitemapUrls Array of sitemap URLs to be displayed.
*/
$sitemapUrls = apply_filters( 'dsidxpress_xmlsitemaps_urls', $sitemapUrls );
return empty($sitemapUrls)?false:$sitemapUrls;
}
static function GoogleXmlSitemap() {
if (class_exists('GoogleSitemapGenerator') || class_exists('GoogleSitemapGeneratorStandardBuilder')) {
$generatorObject = &GoogleSitemapGenerator::GetInstance();
$options = self::GetSitemapOptions();
if ($generatorObject != null && is_array($options)) {
foreach ($options as $optionArr) {
$generatorObject->AddUrl($optionArr['location'], time(), $optionArr['frequency'], $optionArr['priority']);
}
}
}
}
static function BwpGoogleXmlSitemap() {
if (class_exists('BWP_GXS_MODULE_PAGE_EXTERNAL')) {
$options = self::GetSitemapOptions();
if (is_array($options)) {
for ($i=0; $i<count($options); $i++) {
$options[$i]['lastmod'] = 'now';
}
return $options;
}
}
}
/*
static function BwpGoogleXmlSitemapModule() {
global $bwp_gxs;
$bwp_gxs->add_module('page', 'idxpress');
}
*/
static function CompareListObjects($a, $b)
{
$al = strtolower($a["value"]);
$bl = strtolower($b["value"]);
if ($al == $bl) {
return 0;
}
return ($al > $bl) ? +1 : -1;
}
}
?>