Skip to content

Commit 431d013

Browse files
committed
v.1.0.1 First public release
1 parent 6d5c776 commit 431d013

File tree

7 files changed

+1009
-1
lines changed

7 files changed

+1009
-1
lines changed

LICENSE.txt

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1-
# easy_xmlsitemap
1+
Easy XML sitemap
2+
===================================
3+
4+
Simple module for build a XML sitemap following to
5+
[Google's recommendations](https://support.google.com/webmasters/answer/2620865)
6+
for using "hreflang" attribute in sitemap of multilingual site.
7+
8+
Features
9+
--------
10+
Sitemap file will be accessible on URL *http(s)://your.domain/sitemap.xml*
11+
and automatically include URLs for:
12+
13+
- pages created by nodes
14+
- non-empty taxonomy terms pages
15+
- public available pages by "Views" module
16+
17+
If some node is set as site's front page, URL of this node will be
18+
automatically excluded from sitemap to avoid content duplication.
19+
20+
For URLs which you do not want include to sitemap, exclusions may be added.
21+
22+
Each time sitemap re-built, backup copy of previous file state is saved as
23+
public://easy_xmlsitemap/sitemap.xml.bak
24+
25+
Optional and less important URLs attributes "priority" and "lastmod"
26+
are omitted in this version.
27+
28+
Installation
29+
------------
30+
If you have file "sitemap.xml" in website root directory, please remove
31+
or rename this file before you start module installation.
32+
33+
Install this module using the official Backdrop CMS instructions at
34+
https://backdropcms.org/guide/modules
35+
36+
Configuration and usage
37+
-----------------------
38+
Administration page is available via *Administration > Configuration >
39+
Search and metadata > Easy XML Sitemap* (admin/config/search/easy_xmlsitemap)
40+
and may be useful for:
41+
42+
- build XML sitemap by using button "BUILD SITEMAP NOW" (before first time build
43+
you will get error 404 from "/sitemap.xml)
44+
- get information about last time sitemap build
45+
46+
under "SETTINGS" fieldset:
47+
- set (if you need) different default base URL used for sitemap links
48+
- select sitemap rebuild frequency: manually, daily (default) or any cron run
49+
- add exclusions for URLs you won't include in sitemap (see description on the form).
50+
51+
License
52+
-------
53+
54+
This project is GPL v2 software. See the LICENSE.txt file in this directory for
55+
complete text.
56+
57+
Current Maintainer
58+
------------------
59+
60+
Vladimir (https://github.com/findlabnet/)
61+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"_config_name": "easy_xmlsitemap.settings",
3+
"base_url": "",
4+
"sitemap_dir": "easy_xmlsitemap",
5+
"rebuild_frequency": "daily",
6+
"last_build_date": 0,
7+
"excluded_urls": ""
8+
}

easy_xmlsitemap.admin.inc

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* @file
4+
* Admin forms to manage module
5+
*
6+
*/
7+
8+
/**
9+
*
10+
* Settings form for module.
11+
*
12+
*/
13+
function easy_xmlsitemap_settings_form() {
14+
15+
$config = config('easy_xmlsitemap.settings');
16+
$last_build_date = $config->get('last_build_date');
17+
18+
$info = $last_build_date != 0
19+
? t('Sitemap file last build time: ') . format_date($last_build_date, 'short')
20+
: t('Sitemap file has not built yet.');
21+
22+
$form = array();
23+
24+
$form['build_info'] = array(
25+
'#type' => 'fieldset',
26+
'#title' => t('Sitemap build'),
27+
'#collapsible' => TRUE,
28+
'#collapsed' => FALSE,
29+
);
30+
31+
$form['build_info']['info'] = array(
32+
'#markup' => '<p>' . $info . '</p>',
33+
);
34+
$form['build_info']['actions'] = array('#type' => 'actions');
35+
$form['build_info']['actions']['build'] = array(
36+
'#type' => 'submit',
37+
'#value' => t('Build sitemap now'),
38+
);
39+
$form['build_info']['actions']['info'] = array(
40+
'#markup' => '<div class="description">' . t('This will rebuild XML sitemap.') . '</div>',
41+
);
42+
43+
$form['settings'] = array(
44+
'#type' => 'fieldset',
45+
'#title' => t('Settings'),
46+
'#collapsible' => TRUE,
47+
'#collapsed' => TRUE,
48+
);
49+
50+
$form['settings']['base_url'] = array(
51+
'#type' => 'textfield',
52+
'#title' => t('Default base URL'),
53+
'#default_value' => $config->get('base_url'),
54+
'#description' => t('Optional default base URL used for sitemaps and sitemap links, for example: http://example.com, can be left empty.'),
55+
);
56+
$form['settings']['rebuild_frequency'] = array(
57+
'#type' => 'select',
58+
'#title' => t('Sitemap rebuild frequency'),
59+
'#options' => array(
60+
'cron' => t('Any cron run'),
61+
'daily' => t('Once per day'),
62+
'manually' => t('Manually only'),
63+
),
64+
'#default_value' => $config->get('rebuild_frequency'),
65+
'#description' => t('Select time interval for sitemap rebuild.'),
66+
);
67+
$form['settings']['excluded_urls'] = array(
68+
'#type' => 'textarea',
69+
'#title' => t('Excluded URLs list (optional)'),
70+
'#default_value' => $config->get('excluded_urls'),
71+
'#description' => t('If some URLs should be excluded from sitemap, place these URLs here, one URL per line without domain, for example:')
72+
. '<br />403.html'
73+
. '<br />404.html'
74+
. '<br />node/123'
75+
. '<br />some-test-page.html'
76+
);
77+
78+
$form['settings']['actions'] = array('#type' => 'actions');
79+
$form['settings']['actions']['submit'] = array(
80+
'#type' => 'submit',
81+
'#value' => t('Save settings'),
82+
);
83+
84+
return $form;
85+
86+
}
87+
88+
/**
89+
* Submit actions for form
90+
*
91+
*/
92+
function easy_xmlsitemap_settings_form_submit($form, &$form_state) {
93+
94+
global $user;
95+
$config = config('easy_xmlsitemap.settings');
96+
97+
if ($form_state['clicked_button']['#id'] == 'edit-submit') {
98+
99+
$config->set('base_url', trim($form_state['values']['base_url']));
100+
$config->set('rebuild_frequency', $form_state['values']['rebuild_frequency']);
101+
$config->set('excluded_urls', trim($form_state['values']['excluded_urls']));
102+
103+
$config->save();
104+
watchdog('easy_xmlsitemap', t('Settings changed by @user.', array('@user' => $user->name)));
105+
backdrop_set_message(t('Configuration settings have been saved.'));
106+
}
107+
else {
108+
easy_xmlsitemap_build();
109+
}
110+
}
111+

easy_xmlsitemap.info

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name = Easy XML sitemap
2+
description = Provides sitemap file in XML format with multilingual attributes.
3+
package = SEO
4+
backdrop = 1.x
5+
type = module
6+
configure = admin/config/search/easy_xmlsitemap
7+
version = 1.0.1
8+

easy_xmlsitemap.install

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* @file
4+
* Easy XML Sitemap install
5+
*/
6+
7+
/**
8+
* Implements hook_requirements().
9+
*/
10+
function easy_xmlsitemap_requirements($phase) {
11+
// Ensure translations don't break during installation.
12+
$t = get_t();
13+
14+
$requirements = array();
15+
16+
if ($phase == 'install') {
17+
if (file_exists('./sitemap.xml')) {
18+
19+
$requirements['easy_xmlsitemap'] = array(
20+
'severity' => REQUIREMENT_ERROR,
21+
'description' => $t('The "Easy XML sitemap" module cannot display generated file "sitemap.xml",'
22+
. ' because file with this name already exists in website root directory.'
23+
. ' Please remove or rename an existing file, then try again.'),
24+
);
25+
}
26+
}
27+
28+
return $requirements;
29+
}

0 commit comments

Comments
 (0)