Skip to content

Commit d24b026

Browse files
committed
v.1.0.12
1 parent 76388a2 commit d24b026

File tree

6 files changed

+95
-12
lines changed

6 files changed

+95
-12
lines changed

README.md

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

4-
Provides XML sitemap conforming to [Google's recommendations](https://support.google.com/webmasters/answer/2620865)
5-
by using "hreflang" attribute in sitemap on multilingual site and [sitemaps.org protocol](http://www.sitemaps.org/protocol.html).
4+
Provides XML sitemap conforming to Google's recommendations and sitemaps.org protocol.
5+
[Google's recommendations](https://support.google.com/webmasters/answer/2620865)
6+
[sitemaps.org protocol](http://www.sitemaps.org/protocol.html)
7+
8+
New in version 1.0.12 - integration with "SEO Meta Tags" module - exclude from sitemap
9+
any page have "noindex" in meta-tag "robots".
610

711
Features
812
--------
@@ -52,6 +56,8 @@ Under "Advanced settings" fieldset:
5256
- select sitemap rebuild frequency: manually, daily (default) or any cron run;
5357
- add exclusions for URLs you won't include in sitemap;
5458
- add exclusions for content of languages you won't include in sitemap.
59+
Note: if you have module "SEO Meta Tags" installed, you can exclude from sitemap
60+
also all pages with "noindex" in meta-tag "robots".
5561

5662
License
5763
-------

config/easy_xmlsitemap.settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"rebuild_frequency": "daily",
66
"excluded_urls": "",
77
"excluded_langs": [],
8-
"force_https": 0
8+
"force_https": 0,
9+
"seo_meta_integration": 0
910
}

easy_xmlsitemap.admin.inc

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,37 @@ function easy_xmlsitemap_settings_form() {
7676
);
7777
$form['settings']['excluded_urls'] = array(
7878
'#type' => 'textarea',
79-
'#title' => t('Excluded URLs list (optional)'),
79+
'#title' => t('Excluded URLs list:'),
8080
'#default_value' => $config->get('excluded_urls'),
81-
'#description' => t('If some URLs should be excluded from sitemap, place these URLs here, one URL per line without domain, see an example below:')
81+
'#description' => t('If URL should be excluded from sitemap, place one URL per line without domain part, see an example below:')
8282
. '<br />403.html'
8383
. '<br />404.html'
8484
. '<br />node/123'
8585
. '<br />' . t('Multiple similar URLs can be selected by using asterisk wildcard (*), for example:')
8686
. '<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.')
87+
. '<br />' . t('so all URLs starting with post- (such as post-123 or post-about-cat.html) will be excluded from sitemap.'),
88+
'#prefix' => '<b>' . t('Exclusions:') . '</b>'
89+
8890
);
8991
if (count($site_langs) > 1) {
9092
$form['settings']['excluded_langs'] = array(
9193
'#type' => 'checkboxes',
92-
'#title' => t('Exclude from sitemap all pages for selected language (optional):'),
94+
'#title' => t('Exclude from sitemap all pages for selected language:'),
9395
'#options' => $site_langs,
9496
'#default_value' => $config->get('excluded_langs'),
95-
'#description' => t('In some cases you might want do not include to sitemap links to pages for specific language.'),
97+
'#description' => t('You might want do not include to sitemap links to pages for specific language.'),
9698
);
9799
}
100+
if (module_exists('seo_meta')) {
101+
$form['settings']['seo_meta_integration'] = array(
102+
'#type' => 'checkbox',
103+
'#title' => t('Exclude also pages with "noindex" value of meta tag "robots".'),
104+
'#default_value' => $config->get('seo_meta_integration'),
105+
'#description' => t('Your site have module "SEO Meta Tags" enabled, so "noindex" in "robots" can be used for excluding pages from sitemap.'),
106+
'#prefix' => '<b>' . t('"SEO Meta Tags" module integration:') . '</b>',
107+
);
108+
}
109+
98110
$form['settings']['submit'] = array(
99111
'#type' => 'submit',
100112
'#value' => t('Save settings'),
@@ -122,6 +134,9 @@ function easy_xmlsitemap_settings_form_submit($form, &$form_state) {
122134
if (isset($form_state['values']['excluded_langs'])) {
123135
$config->set('excluded_langs', $form_state['values']['excluded_langs']);
124136
}
137+
if (isset($form_state['values']['seo_meta_integration'])) {
138+
$config->set('seo_meta_integration', $form_state['values']['seo_meta_integration']);
139+
}
125140
$config->save();
126141
watchdog('easy_xmlsitemap', t('Settings changed by @user.', array('@user' => $user->name)));
127142
backdrop_set_message(t('Configuration settings have been saved.'));

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.11
7+
version = 1.0.12
88

easy_xmlsitemap.install

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,13 @@ function easy_xmlsitemap_update_1002() {
5252
$config = config('easy_xmlsitemap.settings');
5353
$config->set('force_https', 0);
5454
$config->save();
55+
}
56+
57+
/**
58+
* Add and initialize new variable
59+
*/
60+
function easy_xmlsitemap_update_1003() {
61+
$config = config('easy_xmlsitemap.settings');
62+
$config->set('seo_meta_integration', 0);
63+
$config->save();
5564
}

easy_xmlsitemap.module

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* @file main module file
44
*/
55

6+
// Define same content entry types as in module "SEO Meta Tags"
7+
define('SEO_META_TYPE_NODE', 2);
8+
define('SEO_META_TYPE_VIEW', 3);
9+
define('SEO_META_TYPE_TAXONOMY', 4);
10+
611
/**
712
* Implements hook_config_info().
813
*/
@@ -115,7 +120,7 @@ function easy_xmlsitemap_build() {
115120
$url = url('node/' . $node->nid, array('absolute' => FALSE, 'language' => (object) array('langcode' => $node->langcode)));
116121

117122
// skip excluded URLs
118-
if (easy_xmlsitemap_url_excluded($url)) {
123+
if (easy_xmlsitemap_seo_meta_check_robots(SEO_META_TYPE_NODE, $node->nid) || easy_xmlsitemap_url_excluded($url)) {
119124
continue;
120125
}
121126

@@ -176,6 +181,7 @@ function easy_xmlsitemap_url_excluded($url) {
176181
}
177182
}
178183
}
184+
179185
return $excluded;
180186
}
181187

@@ -306,7 +312,7 @@ function easy_xmlsitemap_build_taxonomy_items($base_url) {
306312
if (!empty($array_of_nodes)) {
307313
$url = url('taxonomy/term/' . $term->tid, array('absolute' => FALSE, 'language' => (object) array('langcode' => $langcode)));
308314
// skip excluded URLs
309-
if (easy_xmlsitemap_url_excluded($url)) {
315+
if (easy_xmlsitemap_seo_meta_check_robots(SEO_META_TYPE_TAXONOMY, $term->tid) || easy_xmlsitemap_url_excluded($url)) {
310316
continue;
311317
}
312318

@@ -346,7 +352,7 @@ function easy_xmlsitemap_build_views_items($base_url) {
346352
if (strpos($page_path, 'admin/') === FALSE) {
347353
$url = url('/' . $page_path, array('absolute' => FALSE, 'language' => (object) array('langcode' => $langcode)));
348354
// skip excluded URLs
349-
if (easy_xmlsitemap_url_excluded($url)) {
355+
if (easy_xmlsitemap_seo_meta_check_robots(SEO_META_TYPE_VIEW, str_replace('-', '_', $view_name)) || easy_xmlsitemap_url_excluded($url)) {
350356
continue;
351357
}
352358

@@ -472,3 +478,49 @@ function easy_xmlsitemap_cron() {
472478
easy_xmlsitemap_build();
473479
}
474480
}
481+
482+
/**
483+
* Check given page for meta-tag "robots"
484+
* @param string $ce_type
485+
* @param string $item_id
486+
* @return boolean TRUE if found value "noindex"
487+
*/
488+
489+
function easy_xmlsitemap_seo_meta_check_robots($ce_type, $item_id) {
490+
if (!module_exists('seo_meta')) {
491+
return FALSE;
492+
}
493+
else {
494+
$seo_meta_integration = config_get('easy_xmlsitemap.settings', 'seo_meta_integration');
495+
if ($seo_meta_integration == 1) {
496+
$found = FALSE;
497+
498+
if ($ce_type == SEO_META_TYPE_TAXONOMY) {
499+
$term = taxonomy_term_load($item_id);
500+
$ce_id = $term->name;
501+
}
502+
else {
503+
$ce_id = $item_id;
504+
}
505+
506+
$result = db_select('seo_meta', 'sm')
507+
->fields('sm', array(
508+
'meta_robots',
509+
)
510+
)
511+
->condition('ce_type', $ce_type, '=')
512+
->condition('ce_id', $ce_id, '=')
513+
->execute()
514+
->fetchAssoc();
515+
516+
if ($result) {
517+
$meta_robots = unserialize($result['meta_robots']);
518+
if ($meta_robots['NOINDEX'] !== 0) {
519+
$found = TRUE;
520+
}
521+
}
522+
523+
return $found;
524+
}
525+
}
526+
}

0 commit comments

Comments
 (0)