Skip to content

Commit

Permalink
v.1.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
findlabnet committed Dec 3, 2021
1 parent c9a4a71 commit d0ce249
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 25 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ Features
--------
XML sitemap file is available at *http(s)://your.domain/sitemap.xml* and include URLs generated for:

- pages created by nodes;
- pages created from nodes;
- non-empty taxonomy terms pages;
- publicly available pages by "Views" module.
- public pages provided by "Views" module.

If some node is set as site's front page, direct URL to this node will be
automatically excluded from sitemap to avoid content duplication.

You may exclude from sitemap:

- specific URLs, for example 403/404 error pages;
- specific URLs, for example 403/404 error pages;
- content types that should not be directly accessible from its URL;
- all content which presented on any of available languages.

Each time sitemap re-built, backup copy of previous file state is saved as
Expand Down Expand Up @@ -55,9 +56,13 @@ Under "Advanced settings" fieldset:
- set (if you need) different default base URL used for sitemap links;
- select sitemap rebuild frequency: manually, daily (default) or any cron run;
- add exclusions for URLs you won't include in sitemap;
- add exclusions for content of languages you won't include in sitemap.
Note: if you have module "SEO Meta Tags" installed, you can exclude from sitemap
also all pages with "noindex" in meta-tag "robots".
- add exclusions for content types you won't include in sitemap;
- add exclusions for content of languages you won't include in sitemap.

Note: if you have "SEO Meta Tags" module installed, you can also exclude all pages
with "noindex" in the "robots" meta tag from the sitemap.

**Screenshots** are available at https://findlab.net/projects/easy-xmlsitemap

License
-------
Expand Down
1 change: 1 addition & 0 deletions config/easy_xmlsitemap.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"sitemap_dir": "easy_xmlsitemap",
"rebuild_frequency": "daily",
"excluded_urls": "",
"excluded_types": [],
"excluded_langs": [],
"force_https": 0,
"seo_meta_integration": 0
Expand Down
67 changes: 54 additions & 13 deletions easy_xmlsitemap.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
/**
* @file
* Admin forms to manage module
*
*/

/**
*
* Settings form for module.
*
*/
function easy_xmlsitemap_settings_form() {
$config = config('easy_xmlsitemap.settings');
$config = config('easy_xmlsitemap.settings');
$last_build_date = state_get('easy_xmlsitemap_last_build_date', 0);

$info = $last_build_date != 0
? t('Sitemap last build time: ') . format_date($last_build_date, 'short')
: t('Sitemap has not built yet.');

$site_langs = language_list(TRUE, TRUE);

$site_langs = language_list(TRUE, TRUE);
$node_types = node_type_get_types();
$excluded_types = array();

foreach ($node_types as $key => $value) {
$excluded_types[$key] = $value->name;
}

$form = array();

$form['build_info'] = array(
Expand All @@ -32,13 +35,15 @@ function easy_xmlsitemap_settings_form() {
$form['build_info']['info'] = array(
'#markup' => '<p>' . $info . '</p>',
);

$form['build_info']['build'] = array(
'#type' => 'submit',
'#value' => t('Build sitemap now'),
'#attributes' => array(
'class' => array('button-primary'),
),
);

$form['build_info']['actions']['info'] = array(
'#markup' => '<div class="description">' . t('This will rebuild sitemap immediately.') . '</div>',
);
Expand All @@ -63,6 +68,7 @@ function easy_xmlsitemap_settings_form() {
'#default_value' => $config->get('base_url'),
'#description' => t('Optional replacement for base URL, should be used instead of actual domain for sitemap links, for example: http://example.com. In most cases can be left empty.'),
);

$form['settings']['rebuild_frequency'] = array(
'#type' => 'select',
'#title' => t('Sitemap rebuild frequency'),
Expand All @@ -74,9 +80,23 @@ function easy_xmlsitemap_settings_form() {
'#default_value' => $config->get('rebuild_frequency'),
'#description' => t('Select time interval for sitemap rebuild.'),
);
$form['settings']['excluded_urls'] = array(

$form['settings']['exclusions'] = array(
'#markup' => '<b>' . t('Sitemap exclusions can be configured below.') . '</b>',
);

$form['settings']['set_exclusions'] = array(
'#type' => 'vertical_tabs',
);

$form['settings']['urls'] = array(
'#type' => 'fieldset',
'#title' => t('Excluded URLs'),
'#group' => 'set_exclusions',
);

$form['settings']['urls']['excluded_urls'] = array(
'#type' => 'textarea',
'#title' => t('Excluded URLs list:'),
'#default_value' => $config->get('excluded_urls'),
'#description' => t('If URL should be excluded from sitemap, place one URL per line without domain part, see an example below:')
. '<br />403.html'
Expand All @@ -85,25 +105,43 @@ function easy_xmlsitemap_settings_form() {
. '<br />' . t('Multiple similar URLs can be selected by using asterisk wildcard (*), for example:')
. '<br /><em>post-*</em>,'
. '<br />' . t('so all URLs starting with post- (such as post-123 or post-about-cat.html) will be excluded from sitemap.'),
'#prefix' => '<b>' . t('Exclusions:') . '</b>'

);

$form['settings']['types'] = array(
'#type' => 'fieldset',
'#title' => t('Excluded content types'),
'#group' => 'set_exclusions',
);

$form['settings']['types']['excluded_types'] = array(
'#type' => 'checkboxes',
'#options' => $excluded_types,
'#default_value' => $config->get('excluded_types'),
'#description' => t('Select what content types do not include to sitemap.'),
);

if (count($site_langs) > 1) {
$form['settings']['excluded_langs'] = array(
$form['settings']['langs'] = array(
'#type' => 'fieldset',
'#title' => t('Excluded content languages'),
'#group' => 'set_exclusions',
);

$form['settings']['langs']['excluded_langs'] = array(
'#type' => 'checkboxes',
'#title' => t('Exclude from sitemap all pages for selected language:'),
'#options' => $site_langs,
'#default_value' => $config->get('excluded_langs'),
'#description' => t('You might want do not include to sitemap links to pages for specific language.'),
);
}

if (module_exists('seo_meta')) {
$form['settings']['seo_meta_integration'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude also pages with "noindex" value of meta tag "robots".'),
'#default_value' => $config->get('seo_meta_integration'),
'#description' => t('Your site have module "SEO Meta Tags" enabled, so "noindex" in "robots" can be used for excluding pages from sitemap.'),
'#prefix' => '<b>' . t('"SEO Meta Tags" module integration:') . '</b>',
'#prefix' => t('"SEO Meta Tags" module integration:'),
);
}

Expand Down Expand Up @@ -131,6 +169,9 @@ function easy_xmlsitemap_settings_form_submit($form, &$form_state) {
$config->set('base_url', trim($form_state['values']['base_url']));
$config->set('rebuild_frequency', $form_state['values']['rebuild_frequency']);
$config->set('excluded_urls', trim($form_state['values']['excluded_urls']));
if (isset($form_state['values']['excluded_types'])) {
$config->set('excluded_types', $form_state['values']['excluded_types']);
}
if (isset($form_state['values']['excluded_langs'])) {
$config->set('excluded_langs', $form_state['values']['excluded_langs']);
}
Expand Down
2 changes: 1 addition & 1 deletion easy_xmlsitemap.info
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package = SEO
backdrop = 1.x
type = module
configure = admin/config/metadata/easy_xmlsitemap
version = 1.0.13
version = 1.0.14

11 changes: 10 additions & 1 deletion easy_xmlsitemap.install
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ function easy_xmlsitemap_update_1003() {
$config = config('easy_xmlsitemap.settings');
$config->set('seo_meta_integration', 0);
$config->save();
}
}

/**
* Add and initialize new variable
*/
function easy_xmlsitemap_update_1004() {
$config = config('easy_xmlsitemap.settings');
$config->set('excluded_types', []);
$config->save();
}
16 changes: 12 additions & 4 deletions easy_xmlsitemap.module
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,25 @@ function easy_xmlsitemap_build_front_url($base_url) {
* @return string
*/
function easy_xmlsitemap_build_node_items($base_url) {
$config = config('easy_xmlsitemap.settings');
$default_langcode = config_get('system.core', 'language_default');
$site_langs = easy_xmlsitemap_language_list();
$urls_block = array();
$output = '';
$site_langs = easy_xmlsitemap_language_list();
$urls_block = array();
$output = '';
$excluded_types = $config->get('excluded_types');
$types = array_values($excluded_types);

foreach (array_keys($types, 0, true) as $key) {
unset($types[$key]);
}

$frontpage_nid = easy_xmlsitemap_get_frontpage_nid();

$result = db_select('node', 'n')
->addTag('node_access')
->fields('n')
->condition('status', 0, '>')
->condition('n.type', $types, 'NOT IN')
->condition('n.status', 0, '>')
->execute()
->fetchAll();

Expand Down

0 comments on commit d0ce249

Please sign in to comment.