Skip to content

Commit c32668b

Browse files
committed
v.1.0.10
1 parent 07d535a commit c32668b

File tree

4 files changed

+48
-23
lines changed

4 files changed

+48
-23
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Easy XML sitemap
2-
===================================
2+
================
33

44
Provides XML sitemap conforming to [Google's recommendations](https://support.google.com/webmasters/answer/2620865)
5-
for using "hreflang" attribute in sitemap on multilingual site and [sitemaps.org protocol](http://www.sitemaps.org/protocol.html).
5+
by using "hreflang" attribute in sitemap on multilingual site and [sitemaps.org protocol](http://www.sitemaps.org/protocol.html).
66

77
Features
88
--------
@@ -23,7 +23,7 @@ You may exclude from sitemap:
2323
Each time sitemap re-built, backup copy of previous file state is saved as
2424
*public://easy_xmlsitemap/sitemap.xml.bak*
2525

26-
Less important and optional URLs attributes "priority" and "lastmod" are omitted in this version.
26+
Less important and optional URLs attributes "priority" and "lastmod" are omitted.
2727

2828
You can want add at end of your file robots.txt line:
2929

easy_xmlsitemap.admin.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function easy_xmlsitemap_settings_form() {
5454
'#type' => 'checkbox',
5555
'#title' => t('Force "https" protocol for URLs in sitemap.'),
5656
'#default_value' => $config->get('force_https'),
57-
'#description' => t('Can be used for generating links behind SSL-proxy like Cloudflare.'),
57+
'#description' => t('Can be used for sites behind SSL-proxy like Cloudflare.'),
5858
);
5959

6060
$form['settings']['base_url'] = array(
@@ -82,7 +82,9 @@ function easy_xmlsitemap_settings_form() {
8282
. '<br />403.html'
8383
. '<br />404.html'
8484
. '<br />node/123'
85-
. '<br />some-test-page.html'
85+
. '<br />' . t('Multiple similar URLs can be selected by using asterisk wildcard (*), for example:')
86+
. '<br /><em>post-*</em>,'
87+
. '<br />' . t('so all URLs starting with post- (such as post-123 or post-about-cat.html) will be excluded from sitemap.')
8688
);
8789
if (count($site_langs) > 1) {
8890
$form['settings']['excluded_langs'] = array(

easy_xmlsitemap.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package = SEO
44
backdrop = 1.x
55
type = module
66
configure = admin/config/metadata/easy_xmlsitemap
7-
version = 1.0.9
7+
version = 1.0.10
88

easy_xmlsitemap.module

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,41 @@ function easy_xmlsitemap_url_excluded($url) {
152152
$excluded_raw_urls = $config->get('excluded_urls');
153153
$excluded_urls = easy_xmlsitemap_textarea_to_array($excluded_raw_urls);
154154
$excluded = FALSE;
155+
$masked = array();
155156

156157
if (!empty($excluded_urls)) {
157-
if (in_array(substr($url, 1), $excluded_urls)) {
158-
$excluded = TRUE;
158+
// Check for url groups masked by *, then full url
159+
foreach ($excluded_urls as $excluded_url) {
160+
if (substr($excluded_url, -1) == '*') {
161+
$masked[] = substr($excluded_url, 0, -1);
162+
}
163+
}
164+
if (!empty($masked)) {
165+
foreach ($masked as $found) {
166+
$position = strpos($url, $found);
167+
if ($position !== FALSE) {
168+
$excluded = TRUE;
169+
}
170+
else {
171+
$excluded = easy_xml_found($url, $excluded_urls);
172+
}
173+
}
174+
}
175+
else {
176+
$excluded = easy_xml_found($url, $excluded_urls);
159177
}
160178
}
161179
return $excluded;
162180
}
181+
/**
182+
* Found in array
183+
* @param string $url
184+
* @param array $excluded_urls
185+
* @return boolean
186+
*/
187+
function easy_xml_found($url, $excluded_urls) {
188+
return in_array(substr($url, 1), $excluded_urls);
189+
}
163190

164191
/**
165192
* Return node nid if this node set as front page
@@ -177,7 +204,7 @@ function easy_xmlsitemap_get_frontpage_nid() {
177204
}
178205

179206
/**
180-
* Find ans print front page(s) URL
207+
* Find and print front page(s) URL
181208
* @param string $base_url
182209
* @return string
183210
*/
@@ -364,6 +391,7 @@ function easy_xmlsitemap_file_save($content) {
364391
rename($file_path, $file_path . '.bak');
365392
}
366393

394+
$content = $content . "\n" . '<!-- ' . format_date(time(), 'short') . ' -->';
367395
file_put_contents($file_path, $content);
368396

369397
$success = file_exists($file_path);
@@ -384,23 +412,18 @@ function easy_xmlsitemap_output() {
384412
$config = config('easy_xmlsitemap.settings');
385413
$file_dir = 'public://' . $config->get('sitemap_dir');
386414
$file_path = $file_dir . '/' . 'sitemap.xml';
387-
$last_build_date = state_get('easy_xmlsitemap_last_build_date', 0);
388415

389416
if (!file_exists($file_path) || !is_readable($file_path)) {
390-
return backdrop_not_found();
417+
backdrop_not_found();
418+
backdrop_exit();
419+
}
420+
else {
421+
$file = file_get_contents($file_path);
422+
backdrop_add_http_header('Content-type', 'text/xml; charset=utf-8');
423+
backdrop_add_http_header('X-Robots-Tag', 'noindex, follow');
424+
echo $file;
425+
exit();
391426
}
392-
393-
$file = file_get_contents($file_path);
394-
/** DEBUG
395-
$ua = getenv('HTTP_USER_AGENT');
396-
$ip = getenv('REMOTE_ADDR');
397-
watchdog('easy_xmlsitemap', 'Request for sitemap.xml by ' . $ua . ' from ' . $ip, NULL, WATCHDOG_INFO);
398-
*/
399-
backdrop_add_http_header('Content-type', 'text/xml; charset=utf-8');
400-
backdrop_add_http_header('X-Robots-Tag', 'noindex, follow');
401-
echo $file;
402-
echo "\n" . '<!-- ' . format_date($last_build_date, 'short') . ' -->';
403-
exit();
404427
}
405428

406429
/**

0 commit comments

Comments
 (0)