security update for uuid xmlsitemap file_field_path

This commit is contained in:
2018-10-13 16:01:24 +02:00
parent f7ae17e6c4
commit a163542966
109 changed files with 5458 additions and 1952 deletions

View File

@@ -1,40 +1,53 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Installing
* Requirements
* Installation
* Configuration
* Uninstalling
* Frequently Asked Questions (FAQ)
* Known Issues
* More Information
* How Can You Contribute?
* Maintainers
INTRODUCTION
------------
Current Maintainer: Dave Reid <http://drupal.org/user/53892>
Co-maintainer: Kiam <http://drupal.org/user/55077>
Co-maintainer: Earnie <http://drupal.org/user/86710>
Co-maintainer: Darren Oh <http://drupal.org/user/30772>
Original Author: Matthew Loar <http://drupal.org/user/24879>
XML Sitemap automatically creates a sitemap that conforms to the sitemaps.org
specification. This helps search engines keep their search results up to date.
INSTALLING
----------
REQUIREMENTS
------------
See http://drupal.org/getting-started/install-contrib for instructions on
how to install or update Drupal modules.
No special requirements
INSTALLATION
------------
Install as you would normally install a contributed Drupal module. See:
https://drupal.org/documentation/install/modules-themes/modules-7 for further
information.
Once XML Sitemap is installed and enabled, you can adjust the settings for your
site's sitemap at admin/config/search/xmlsitemap. Your can view your site's
sitemap at http://yoursite.com/sitemap.xml.
It is highly recommended that you have clean URLs enabled for this module.
It is highly recommended that you have clean URLs enabled for this project.
CONFIGURATION
-------------
* Configure your XML sitemap in:
Configuration » Search and metadata »XML sitemap
- Check your XML site
- Click in Update for update the XML values.
UNINSTALLING
@@ -43,7 +56,7 @@ UNINSTALLING
Because Drupal does not uninstall modules in reverse order of their
dependencies, if you want to uninstall all the XML sitemap modules, be sure to
disable and uninstall all the sub-modules before the base XML sitemap module.
To help fix this bug in Drupal core, visit http://drupal.org/node/151452.
To help fix this bug in Drupal core, visit https://www.drupal.org/node/151452.
FREQUENTLY ASKED QUESTIONS (FAQ)
@@ -55,17 +68,17 @@ FREQUENTLY ASKED QUESTIONS (FAQ)
KNOWN ISSUES
------------
- See http://drupal.org/node/482550 for a list of the current known issues.
- See https://www.drupal.org/node/482550 for a list of the current known issues.
MORE INFORMATION
----------------
- To issue any bug reports, feature or support requests, see the module issue
queue at http://drupal.org/project/issues/xmlsitemap.
queue at https://www.drupal.org/project/issues/xmlsitemap.
- For additional documentation, see the online module handbook at
http://drupal.org/handbook/modules/xmlsitemap.
https://www.drupal.org/handbook/modules/xmlsitemap.
- You can view the sitemap.org specification at http://sitemaps.org.
@@ -74,7 +87,7 @@ HOW CAN YOU CONTRIBUTE?
-----------------------
- Report any bugs, feature requests, etc. in the issue tracker.
http://drupal.org/project/issues/xmlsitemap
https://www.drupal.org/project/issues/xmlsitemap
- Help translate this module.
http://localize.drupal.org/translate/projects/xmlsitemap
@@ -84,3 +97,15 @@ HOW CAN YOU CONTRIBUTE?
- Help keep development active by dontating to the developer.
http://davereid.chipin.com/
MAINTAINERS
-----------
Current maintainers:
* Current Maintainer: Dave Reid <https://www.drupal.org/user/53892>
* Co-maintainer: Renato Gonçalves RenatoG <https://www.drupal.org/user/3326031>
* Co-maintainer: Kiam <https://www.drupal.org/user/55077>
* Co-maintainer: Earnie <https://www.drupal.org/user/86710>
* Co-maintainer: Darren Oh <https://www.drupal.org/user/30772>
* Original Author: Matthew Loar <https://www.drupal.org/user/24879>

View File

@@ -35,8 +35,6 @@ function xmlsitemap_sitemap_list_form() {
$form['operations']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
//'#validate' => array('xmlsitemap_sitemap_list_form_validate'),
//'#submit' => array('xmlsitemap_sitemap_list_form_submit'),
);
$contexts = xmlsitemap_get_context_info();
@@ -48,7 +46,11 @@ function xmlsitemap_sitemap_list_form() {
$header['context_' . $context_key] = $context_info['label'];
}
}
$header['updated'] = array('data' => t('Last updated'), 'field' => 'updated', 'sort' => 'asc');
$header['updated'] = array(
'data' => t('Last updated'),
'field' => 'updated',
'sort' => 'asc',
);
$header['links'] = array('data' => t('Links'), 'field' => 'links');
$header['chunks'] = array('data' => t('Pages'), 'field' => 'chunks');
$header['operations'] = array('data' => t('Operations'));
@@ -82,8 +84,7 @@ function xmlsitemap_sitemap_list_form() {
$options[$smid]['chunks'] = $sitemap->updated ? $sitemap->chunks : '-';
// @todo Highlight sitemaps that need updating.
//$options[$smid]['#attributes']['class'][] = 'warning';
// $options[$smid]['#attributes']['class'][] = 'warning';
$operations = array();
$operations['edit'] = xmlsitemap_get_operation_link('admin/config/search/xmlsitemap/edit/' . $smid, array('title' => t('Edit'), 'modal' => TRUE));
$operations['delete'] = xmlsitemap_get_operation_link('admin/config/search/xmlsitemap/delete/' . $smid, array('title' => t('Delete'), 'modal' => TRUE));
@@ -151,12 +152,18 @@ function xmlsitemap_sitemap_list_form_submit($form, &$form_state) {
call_user_func_array($function, $args);
$count = count($form_state['values']['sitemaps']);
//watchdog('xmlsitemap', '@action @count XML sitemaps.', array('@action' => $operation['action past'], '@count' => $count));
drupal_set_message(format_plural(count($sitemaps), '@action @count XML sitemap.', '@action @count XML sitemaps.', array('@action' => $operation['action past'], '@count' => $count)));
//$form_state['redirect'] = 'admin/config/search/xmlsitemap';
drupal_set_message(
format_plural(
count($sitemaps), '@action @count XML sitemap.', '@action @count XML sitemaps.',
array('@action' => $operation['action past'], '@count' => $count)
)
);
}
}
/**
* Edit Form.
*/
function xmlsitemap_sitemap_edit_form(array $form, array &$form_state, stdClass $sitemap = NULL) {
_xmlsitemap_set_breadcrumb();
@@ -196,6 +203,9 @@ function xmlsitemap_sitemap_edit_form(array $form, array &$form_state, stdClass
return $form;
}
/**
* Edit Form Pre Render.
*/
function xmlsitemap_sitemap_edit_form_pre_render($form) {
$visible_children = element_get_visible_children($form['context']);
if (empty($visible_children)) {
@@ -207,6 +217,9 @@ function xmlsitemap_sitemap_edit_form_pre_render($form) {
return $form;
}
/**
* Edit form validate.
*/
function xmlsitemap_sitemap_edit_form_validate($form, &$form_state) {
// If there are no context options, the $form_state['values']['context']
// disappears.
@@ -217,6 +230,9 @@ function xmlsitemap_sitemap_edit_form_validate($form, &$form_state) {
}
}
/**
* Edit Form Submit.
*/
function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) {
form_state_values_clean($form_state);
$sitemap = (object) $form_state['values'];
@@ -225,6 +241,9 @@ function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/search/xmlsitemap';
}
/**
* Delete form.
*/
function xmlsitemap_sitemap_delete_form(array $form, array &$form_state, stdClass $sitemap) {
_xmlsitemap_set_breadcrumb();
@@ -248,6 +267,9 @@ function xmlsitemap_sitemap_delete_form(array $form, array &$form_state, stdClas
);
}
/**
* Delete form submit.
*/
function xmlsitemap_sitemap_delete_form_submit($form, $form_state) {
xmlsitemap_sitemap_delete($form_state['values']['smid']);
drupal_set_message(t('The sitemap has been deleted.'));
@@ -261,10 +283,22 @@ function xmlsitemap_sitemap_delete_form_submit($form, $form_state) {
* @see xmlsitemap_settings_form_validate()
*/
function xmlsitemap_settings_form($form, &$form_state) {
global $base_url;
$form['xmlsitemap_minimum_lifetime'] = array(
'#type' => 'select',
'#title' => t('Minimum sitemap lifetime'),
'#options' => array(0 => t('No minimum')) + drupal_map_assoc(array(300, 900, 1800, 3600, 10800, 21600, 43200, 86400, 172800, 259200, 604800), 'format_interval'),
'#options' => array(0 => t('No minimum')) + drupal_map_assoc(array(300,
900,
1800,
3600,
10800,
21600,
43200,
86400,
172800,
259200,
604800,
), 'format_interval'),
'#description' => t('The minimum amount of time that will elapse before the sitemaps are regenerated. The sitemaps will also only be regenerated on cron if any links have been added, updated, or deleted.') . '<br />' . t('Recommended value: %value.', array('%value' => t('1 day'))),
'#default_value' => variable_get('xmlsitemap_minimum_lifetime', 0),
);
@@ -288,16 +322,19 @@ function xmlsitemap_settings_form($form, &$form_state) {
'#collapsed' => !variable_get('xmlsitemap_developer_mode', 0),
'#weight' => 10,
);
//$form['advanced']['xmlsitemap_gz'] = array(
// '#type' => 'checkbox',
// '#title' => t('Generate additional compressed sitemaps using gzip.'),
// '#default_value' => xmlsitemap_var('gz'),
// '#disabled' => !function_exists('gzencode'),
//);
$form['advanced']['xmlsitemap_chunk_size'] = array(
'#type' => 'select',
'#title' => t('Number of links in each sitemap page'),
'#options' => array('auto' => t('Automatic (recommended)')) + drupal_map_assoc(array(100, 500, 1000, 2500, 5000, 10000, 25000, XMLSITEMAP_MAX_SITEMAP_LINKS)),
'#options' => array('auto' => t('Automatic (recommended)')) + drupal_map_assoc(array(
100,
500,
1000,
2500,
5000,
10000,
25000,
XMLSITEMAP_MAX_SITEMAP_LINKS,
)),
'#default_value' => xmlsitemap_var('chunk_size'),
// @todo This description is not clear.
'#description' => t('If there are problems with rebuilding the sitemap, you may want to manually set this value. If you have more than @max links, an index with multiple sitemap pages will be generated. There is a maximum of @max sitemap pages.', array('@max' => XMLSITEMAP_MAX_SITEMAP_LINKS)),
@@ -305,7 +342,18 @@ function xmlsitemap_settings_form($form, &$form_state) {
$form['advanced']['xmlsitemap_batch_limit'] = array(
'#type' => 'select',
'#title' => t('Maximum number of sitemap links to process at once'),
'#options' => drupal_map_assoc(array(5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000)),
'#options' => drupal_map_assoc(array(
5,
10,
25,
50,
100,
250,
500,
1000,
2500,
5000,
)),
'#default_value' => xmlsitemap_var('batch_limit'),
'#description' => t('If you have problems running cron or rebuilding the sitemap, you may want to lower this value.'),
);
@@ -325,7 +373,7 @@ function xmlsitemap_settings_form($form, &$form_state) {
$form['advanced']['xmlsitemap_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Default base URL'),
'#default_value' => variable_get('xmlsitemap_base_url', $GLOBALS['base_url']),
'#default_value' => variable_get('xmlsitemap_base_url', $base_url),
'#size' => 30,
'#description' => t('This is the default base URL used for sitemaps and sitemap links.'),
'#required' => TRUE,
@@ -362,7 +410,11 @@ function xmlsitemap_settings_form($form, &$form_state) {
'changefreq' => t('Change frequency: @changfreq', array('@changfreq' => '<changefreq>')),
'priority' => t('Priority: @priority', array('@priority' => '<priority>')),
),
'#default_value' => drupal_map_assoc(variable_get('xmlsitemap_output_elements', array('lastmod', 'changefreq', 'priority'))),
'#default_value' => drupal_map_assoc(variable_get('xmlsitemap_output_elements', array(
'lastmod',
'changefreq',
'priority',
))),
);
$form['xmlsitemap_settings'] = array(
@@ -425,7 +477,7 @@ function xmlsitemap_settings_form_validate($form, &$form_state) {
}
/**
* Submit handler;
* Submit handler;.
*
* @see xmlsitemap_settings_form()
*/
@@ -570,17 +622,6 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info)
*/
function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $entity, $bundle) {
$entity_info = xmlsitemap_get_link_info($entity);
//if (!isset($bundle) && isset($entity_info['bundle keys']['bundle'])) {
// $bundle_key = $entity_info['bundle keys']['bundle'];
// if (isset($form[$bundle_key]['#value'])) {
// $bundle = $form[$bundle_key]['#value'];
// }
// elseif (isset($form[$bundle_key]['#default_value'])) {
// $bundle = $form[$bundle_key]['#default_value'];
// }
//}
$bundle_info = xmlsitemap_link_bundle_load($entity, $bundle);
$form['xmlsitemap'] = array(
@@ -641,6 +682,9 @@ function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $
}
}
/**
* Link bundle settings form.
*/
function xmlsitemap_link_bundle_settings_form(array $form, array &$form_state, array $bundle) {
if (empty($form_state['ajax']) && $admin_path = xmlsitemap_get_bundle_path($bundle['entity'], $bundle['bundle'])) {
// If this is a non-ajax form, redirect to the bundle administration page.
@@ -649,7 +693,7 @@ function xmlsitemap_link_bundle_settings_form(array $form, array &$form_state, a
drupal_goto($admin_path, array('query' => $destination));
}
else {
drupal_set_title( t('@bundle XML sitemap settings', array('@bundle' => $bundle['info']['label'])));
drupal_set_title(t('@bundle XML sitemap settings', array('@bundle' => $bundle['info']['label'])));
}
$form = array();
@@ -707,7 +751,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
'#title' => t('XML sitemap'),
'#collapsible' => TRUE,
'#collapsed' => !$link['status_override'] && !$link['priority_override'],
'#access' => user_access('administer xmlsitemap') || xmlsitemap_link_bundle_access($bundle_info),
'#access' => user_access('administer xmlsitemap') || user_access('use xmlsitemap') || xmlsitemap_link_bundle_access($bundle_info),
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(
@@ -725,7 +769,12 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
$form['xmlsitemap']['description'] = array(
'#prefix' => '<div class="description">',
'#suffix' => '</div>',
'#markup' => t('The default XML sitemap settings for this @bundle can be changed <a href="@link-type">here</a>.', array('@bundle' => drupal_strtolower($info['bundle label']), '@link-type' => url($path, array('query' => drupal_get_destination())))),
'#markup' => t('The default XML sitemap settings for this @bundle can be changed <a href="@link-type">here</a>.', array(
'@bundle' => drupal_strtolower($info['bundle label']),
'@link-type' => url($path, array(
'query' => drupal_get_destination(),
)),
)),
);
}
@@ -756,7 +805,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
'#value' => $link['status_override'],
);
// Priority field
// Priority field.
$form['xmlsitemap']['priority'] = array(
'#type' => 'select',
'#title' => t('Priority'),
@@ -784,21 +833,6 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
'#type' => 'value',
'#value' => $link['priority_override'],
);
// Other persistent fields.
//$form['xmlsitemap']['lastmod'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['lastmod'],
//);
//$form['xmlsitemap']['changefreq'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['changefreq'],
//);
//$form['xmlsitemap']['changecount'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['changecount'],
//);
// Add the submit handler to adjust the default values if selected.
$form += array('#submit' => array());
if (!in_array('xmlsitemap_process_form_link_options', $form['#submit'])) {
@@ -809,11 +843,12 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
/**
* Get a list of priority options.
*
* @param $default
* @param string $default
* Include a 'default' option.
* @param $guides
* @param string $guides
* Add helpful indicators for the highest, middle and lowest values.
* @return
*
* @return array
* An array of options.
*/
function xmlsitemap_get_priority_options($default = NULL, $guides = TRUE) {
@@ -852,9 +887,10 @@ function xmlsitemap_get_priority_options($default = NULL, $guides = TRUE) {
/**
* Get a list of priority options.
*
* @param $default
* @param string $default
* Include a 'default' option.
* @return
*
* @return array
* An array of options.
*
* @see _xmlsitemap_translation_strings()

View File

@@ -24,9 +24,9 @@ function hook_xmlsitemap_link_info() {
'label' => 'My module',
'base table' => 'mymodule',
'entity keys' => array(
// Primary ID key on {base table}
// Primary ID key on {base table}.
'id' => 'myid',
// Subtype key on {base table}
// Subtype key on {base table}.
'bundle' => 'mysubtype',
),
'path callback' => 'mymodule_path',
@@ -52,11 +52,29 @@ function hook_xmlsitemap_link_info() {
'rebuild callback' => '',
// Callback function called from the XML sitemap settings page.
'settings callback' => '',
)
),
),
);
}
/**
* Act on a sitemap link being inserted or updated.
*
* This hook is currently invoked from xmlsitemap_node_node_update() before
* the node sitemap link is saved to the database with revoked access until
* the node permissions are checked in the cron.
*
* @param array $link
* An array with the data of the sitemap link.
* @param array $context
* An optional context array containing data related to the link.
*/
function hook_xmlsitemap_link_presave_alter(array &$link, array $context) {
if ($link['type'] == 'mymodule') {
$link['priority'] += 0.5;
}
}
/**
* Alter the data of a sitemap link before the link is saved.
*
@@ -74,7 +92,7 @@ function hook_xmlsitemap_link_alter(array &$link, array $context) {
/**
* Inform modules that an XML sitemap link has been created.
*
* @param $link
* @param array $link
* Associative array defining an XML sitemap link as passed into
* xmlsitemap_link_save().
* @param array $context
@@ -95,7 +113,7 @@ function hook_xmlsitemap_link_insert(array $link, array $context) {
/**
* Inform modules that an XML sitemap link has been updated.
*
* @param $link
* @param array $link
* Associative array defining an XML sitemap link as passed into
* xmlsitemap_link_save().
* @param array $context
@@ -127,6 +145,12 @@ function hook_xmlsitemap_rebuild_clear(array $types, $save_custom) {
->execute();
}
/**
* Respond to XML sitemap regeneration.
*/
function hook_xmlsitemap_regenerate_finished() {
}
/**
* Index links for the XML sitemaps.
*/
@@ -136,7 +160,7 @@ function hook_xmlsitemap_index_links($limit) {
/**
* Provide information about contexts available to XML sitemap.
*
* @see hook_xmlsitemap_context_info_alter().
* @see hook_xmlsitemap_context_info_alter()
*/
function hook_xmlsitemap_context_info() {
$info['vocabulary'] = array(
@@ -150,7 +174,7 @@ function hook_xmlsitemap_context_info() {
/**
* Alter XML sitemap context info.
*
* @see hook_xmlsitemap_context_info().
* @see hook_xmlsitemap_context_info()
*/
function hook_xmlsitemap_context_info_alter(&$info) {
$info['vocabulary']['label'] = t('Site vocabularies');
@@ -230,7 +254,11 @@ function hook_xmlsitemap_element_alter(array &$element, array $link, $sitemap) {
* Alter the attributes used for the root element of the XML sitemap.
*
* For example add an xmlns:video attribute:
* <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
*
* @code
* <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
* xmlns:video="https://www.google.com/schemas/sitemap-video/1.1">
* @endcode
*
* @param array $attributes
* An associative array of attributes to use in the root element of an XML
@@ -238,14 +266,14 @@ function hook_xmlsitemap_element_alter(array &$element, array $link, $sitemap) {
* @param object $sitemap
* The sitemap that is currently being generated.
*/
function hook_xmlsitemap_root_attributes_alter(&$attributes, $sitemap) {
$attributes['xmlns:video'] = 'http://www.google.com/schemas/sitemap-video/1.1';
function hook_xmlsitemap_root_attributes_alter(array &$attributes, $sitemap) {
$attributes['xmlns:video'] = 'https://www.google.com/schemas/sitemap-video/1.1';
}
/**
* Alter the query selecting data from {xmlsitemap} during sitemap generation.
*
* @param $query
* @param QueryAlterableInterface $query
* A Query object describing the composite parts of a SQL query.
*
* @see hook_query_TAG_alter()
@@ -277,11 +305,13 @@ function hook_xmlsitemap_sitemap_operations() {
* This hook is invoked from xmlsitemap_sitemap_delete_multiple() after the XML
* sitemap has been removed from the table in the database.
*
* @param $sitemap
* @param object $sitemap
* The XML sitemap object that was deleted.
*/
function hook_xmlsitemap_sitemap_delete(stdClass $sitemap) {
db_query("DELETE FROM {mytable} WHERE smid = '%s'", $sitemap->smid);
db_delete('mytable')
->condition('smid', $sitemap->smid, '=')
->execute();
}
/**

View File

@@ -7,10 +7,16 @@
* @ingroup xmlsitemap
*/
/**
* The default batch limit.
*/
define('XMLSITEMAP_BATCH_LIMIT', 100);
/**
* Implements hook_drush_command().
*/
function xmlsitemap_drush_command() {
$items['xmlsitemap-regenerate'] = array(
'description' => 'Regenerate the XML sitemap files.',
'callback' => 'drush_xmlsitemap_regenerate',
@@ -29,7 +35,7 @@ function xmlsitemap_drush_command() {
'callback' => 'drush_xmlsitemap_index',
'drupal dependencies' => array('xmlsitemap'),
'options' => array(
'limit' => 'The limit of links of each type to process. Default value: ' . variable_get('xmlsitemap_batch_limit', 100),
'limit' => 'The limit of links of each type to process. Default value: ' . variable_get('xmlsitemap_batch_limit', XMLSITEMAP_BATCH_LIMIT),
),
);
$items['xmlsitemap-queue-rebuild'] = array(
@@ -93,7 +99,7 @@ function drush_xmlsitemap_rebuild() {
* Process un-indexed XML sitemap links.
*/
function drush_xmlsitemap_index() {
$limit = (int) drush_get_option('limit', variable_get('xmlsitemap_batch_limit', 100));
$limit = (int) drush_get_option('limit', variable_get('xmlsitemap_batch_limit', XMLSITEMAP_BATCH_LIMIT));
$count_before = db_query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField();
module_invoke_all('xmlsitemap_index_links', $limit);
@@ -129,7 +135,7 @@ function drush_xmlsitemap_queue_rebuild() {
$link_count = 0;
$chunk_count = 0;
$chunk_size = (int) drush_get_option('limit', variable_get('xmlsitemap_batch_limit', 100));
$chunk_size = (int) drush_get_option('limit', variable_get('xmlsitemap_batch_limit', XMLSITEMAP_BATCH_LIMIT));
// @todo Figure out how to re-use this code with xmlsitemap_rebuild_batch_fetch()
foreach ($types as $type) {
@@ -162,7 +168,11 @@ function drush_xmlsitemap_queue_rebuild() {
}
if ($link_count) {
drush_log(dt('Queued @link_count links for rebuild processing in the xmlsitemap_link_process (in @chunk_count chunks of up to @chunk_size links each).', array('@link_count' => $link_count, '@chunk_count' => $chunk_count, '@chunk_size' => $chunk_size)), 'success');
drush_log(dt('Queued @link_count links for rebuild processing in the xmlsitemap_link_process (in @chunk_count chunks of up to @chunk_size links each).', array(
'@link_count' => $link_count,
'@chunk_count' => $chunk_count,
'@chunk_size' => $chunk_size,
)), 'success');
}
else {
drush_log(dt('No links to queue for rebuild processing.'), 'ok');

View File

@@ -14,9 +14,9 @@
* at once so that only one database query is executed instead of several or
* possibly thousands during sitemap generation.
*
* @param $path
* @param string $path
* An internal Drupal path.
* @param $language
* @param string $language
* A language code to use when looking up the paths.
*/
function xmlsitemap_get_path_alias($path, $language) {
@@ -70,13 +70,16 @@ function _xmlsitemap_regenerate_before() {
if (variable_get('xmlsitemap_developer_mode', 0)) {
watchdog('xmlsitemap', 'Starting XML sitemap generation. Memory usage: @memory-peak.', array(
'@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
),
'@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
),
WATCHDOG_DEBUG
);
}
}
/**
* Get Memory Usage.
*/
function _xmlsitemap_get_memory_usage($start = FALSE) {
static $memory_start;
$current = memory_get_peak_usage(TRUE);
@@ -113,7 +116,7 @@ function _xmlsitemap_get_optimal_memory_limit() {
/**
* Calculate the optimal memory level for sitemap generation.
*
* @param $new_limit
* @param string $new_limit
* An optional PHP memory limit in bytes. If not provided, the value of
* _xmlsitemap_get_optimal_memory_limit() will be used.
*/
@@ -132,9 +135,9 @@ function _xmlsitemap_set_memory_limit($new_limit = NULL) {
/**
* Generate one page (chunk) of the sitemap.
*
* @param $sitemap
* @param object $sitemap
* An unserialized data array for an XML sitemap.
* @param $page
* @param string $page
* An integer of the specific page of the sitemap to generate.
*/
function xmlsitemap_generate_page(stdClass $sitemap, $page) {
@@ -147,20 +150,27 @@ function xmlsitemap_generate_page(stdClass $sitemap, $page) {
catch (Exception $e) {
watchdog_exception('xmlsitemap', $e);
throw $e;
return FALSE;
}
return $writer->getSitemapElementCount();
}
/**
* Generate chunk.
*/
function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer, $chunk) {
$output_elements = drupal_map_assoc(variable_get('xmlsitemap_output_elements', array('lastmod', 'changefreq', 'priority')));
global $base_url;
$output_elements = drupal_map_assoc(variable_get('xmlsitemap_output_elements', array(
'lastmod',
'changefreq',
'priority',
)));
$lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);
$url_options = $sitemap->uri['options'];
$url_options += array(
'absolute' => TRUE,
'base_url' => variable_get('xmlsitemap_base_url', $GLOBALS['base_url']),
'base_url' => variable_get('xmlsitemap_base_url', $base_url),
'language' => language_default(),
'alias' => variable_get('xmlsitemap_prefetch_aliases', TRUE),
);
@@ -169,7 +179,19 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
$link_count = 0;
$query = db_select('xmlsitemap', 'x');
$query->fields('x', array('id', 'type', 'subtype', 'loc', 'lastmod', 'changefreq', 'changecount', 'priority', 'language', 'access', 'status'));
$query->fields('x', array(
'id',
'type',
'subtype',
'loc',
'lastmod',
'changefreq',
'changecount',
'priority',
'language',
'access',
'status',
));
$query->condition('x.access', 1);
$query->condition('x.status', 1);
$query->orderBy('x.language', 'DESC');
@@ -184,6 +206,9 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
while ($link = $links->fetchAssoc()) {
$link['language'] = $link['language'] != LANGUAGE_NONE ? xmlsitemap_language_load($link['language']) : $url_options['language'];
$parsed_url = drupal_parse_url($link['loc']);
// Remove query or fragment.
$link['loc'] = $parsed_url['path'];
if ($url_options['alias']) {
$link['loc'] = xmlsitemap_get_path_alias($link['loc'], $link['language']->language);
}
@@ -191,6 +216,8 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
'language' => $link['language'],
'xmlsitemap_link' => $link,
'xmlsitemap_sitemap' => $sitemap,
'query' => $parsed_url['query'],
'fragment' => $parsed_url['fragment'],
);
// @todo Add a separate hook_xmlsitemap_link_url_alter() here?
$link_url = url($link['loc'], $link_options + $url_options);
@@ -241,7 +268,7 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
/**
* Generate the index sitemap.
*
* @param $sitemap
* @param object $sitemap
* An unserialized data array for an XML sitemap.
*/
function xmlsitemap_generate_index(stdClass $sitemap) {
@@ -254,18 +281,17 @@ function xmlsitemap_generate_index(stdClass $sitemap) {
catch (Exception $e) {
watchdog_exception('xmlsitemap', $e);
throw $e;
return FALSE;
}
return $writer->getSitemapElementCount();
}
// BATCH OPERATIONS ------------------------------------------------------------
/**
* BATCH OPERATIONS -----------------------------------------------------------.
*
* Batch information callback for regenerating the sitemap files.
*
* @param $smids
* @param array $smids
* An optional array of XML sitemap IDs. If not provided, it will load all
* existing XML sitemaps.
*/
@@ -273,11 +299,8 @@ function xmlsitemap_regenerate_batch(array $smids = array()) {
if (empty($smids)) {
$smids = db_query("SELECT smid FROM {xmlsitemap_sitemap}")->fetchCol();
}
//$t = get_t();
$batch = array(
'operations' => array(),
//'error_message' => $t('An error has occurred.'),
'finished' => 'xmlsitemap_regenerate_batch_finished',
'title' => t('Regenerating Sitemap'),
'file' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.generate.inc',
@@ -361,7 +384,7 @@ function xmlsitemap_regenerate_batch_generate_index($smid, array &$context) {
function xmlsitemap_regenerate_batch_finished($success, $results, $operations, $elapsed) {
if ($success && !variable_get('xmlsitemap_regenerate_needed', FALSE)) {
variable_set('xmlsitemap_generated_last', REQUEST_TIME);
//drupal_set_message(t('The sitemaps were regenerated.'));
// drupal_set_message(t('The sitemaps were regenerated.'));
// Show a watchdog message that the sitemap was regenerated.
watchdog('xmlsitemap',
'Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.',
@@ -371,6 +394,7 @@ function xmlsitemap_regenerate_batch_finished($success, $results, $operations, $
),
WATCHDOG_NOTICE
);
module_invoke_all('xmlsitemap_regenerate_finished');
}
else {
drupal_set_message(t('The sitemaps were not successfully regenerated.'), 'error');
@@ -392,7 +416,9 @@ function xmlsitemap_rebuild_batch(array $entities, $save_custom = FALSE) {
$batch['operations'][] = array('xmlsitemap_batch_variable_set', array(array('xmlsitemap_rebuild_needed' => TRUE)));
// Purge any links first.
$batch['operations'][] = array('xmlsitemap_rebuild_batch_clear', array($entities, (bool) $save_custom));
$batch['operations'][] = array('xmlsitemap_rebuild_batch_clear',
array($entities, (bool) $save_custom),
);
// Fetch all the sitemap links and save them to the {xmlsitemap} table.
foreach ($entities as $entity) {
@@ -467,8 +493,7 @@ function xmlsitemap_rebuild_batch_fetch($entity, &$context) {
// PostgreSQL cannot have the ORDERED BY in the count query.
$query->entityOrderBy('entity_id');
$limit = 20; //variable_get('xmlsitemap_batch_limit', 100)
$limit = 20;
$query->range(0, $limit);
$result = $query->execute();
@@ -477,7 +502,12 @@ function xmlsitemap_rebuild_batch_fetch($entity, &$context) {
$info['xmlsitemap']['process callback']($ids);
$context['sandbox']['last_id'] = end($ids);
$context['sandbox']['progress'] += count($ids);
$context['message'] = t('Now processing %entity @last_id (@progress of @count).', array('%entity' => $entity, '@last_id' => $context['sandbox']['last_id'], '@progress' => $context['sandbox']['progress'], '@count' => $context['sandbox']['max']));
$context['message'] = t('Now processing %entity @last_id (@progress of @count).', array(
'%entity' => $entity,
'@last_id' => $context['sandbox']['last_id'],
'@progress' => $context['sandbox']['progress'],
'@count' => $context['sandbox']['max'],
));
if ($context['sandbox']['progress'] >= $context['sandbox']['max']) {
$context['finished'] = 1;
@@ -499,6 +529,9 @@ function xmlsitemap_rebuild_batch_finished($success, $results, $operations, $ela
}
}
/**
* Get Rebuildable link types.
*/
function xmlsitemap_get_rebuildable_link_types() {
$rebuild_types = array();
$entities = xmlsitemap_get_link_info();

View File

@@ -19,21 +19,24 @@ function _xmlsitemap_get_blurb($check_version = TRUE) {
$blurb = FALSE;
if (!$check_version || (($version = _xmlsitemap_get_version()) && preg_match('/dev|unstable|alpha|beta|HEAD/i', $version))) {
$sponsors = array(
l('Symantec', 'http://www.symantec.com/'),
l('WebWise Solutions', 'http://www.webwiseone.com/'),
l('Volacci', 'http://www.volacci.com/'),
l('lanetro', 'http://www.lanetro.com/'),
l('Coupons Dealuxe', 'http://couponsdealuxe.com/'),
l(t('Symantec'), 'http://www.symantec.com/'),
l(t('WebWise Solutions'), 'http://www.webwiseone.com/'),
l(t('Volacci'), 'http://www.volacci.com/'),
l(t('lanetro'), 'http://www.lanetro.com/'),
l(t('Coupons Dealuxe'), 'http://couponsdealuxe.com/'),
);
// Don't extract the following string for translation.
$blurb = '<div class="description"><p>Thank you for helping test the XML sitemap module rewrite. Please consider helping offset developer free time by <a href="http://davereid.chipin.com/">donating</a> or if your company is interested in sponsoring the rewrite or a specific feature, please <a href="http://davereid.net/contact">contact the developer</a>. Thank you to the following current sponsors: ' . implode(', ', $sponsors) . ', and all the individuals that have donated. This message will not be seen in the stable versions.</p></div>';
//http://drupalmodules.com/module/xml-sitemap
// http://drupalmodules.com/module/xml-sitemap
}
}
return $blurb;
}
/**
* Get version.
*/
function _xmlsitemap_get_version() {
static $version;
if (!isset($version)) {

View File

@@ -2,21 +2,14 @@ name = XML sitemap
description = Creates an XML sitemap conforming to the <a href="http://sitemaps.org/">sitemaps.org protocol</a>.
package = XML sitemap
core = 7.x
files[] = xmlsitemap.module
files[] = xmlsitemap.inc
files[] = xmlsitemap.admin.inc
files[] = xmlsitemap.drush.inc
files[] = xmlsitemap.generate.inc
files[] = xmlsitemap.xmlsitemap.inc
files[] = xmlsitemap.pages.inc
files[] = xmlsitemap.install
files[] = xmlsitemap.test
recommends[] = robotstxt
configure = admin/config/search/xmlsitemap
test_dependencies[] = robotstxt:robotstxt
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -25,7 +25,7 @@ function xmlsitemap_requirements($phase) {
'value' => $t('Disabled'),
'severity' => REQUIREMENT_ERROR,
'description' => $t("The XML sitemap module requires you to enable the PHP extensions in the following list (see the <a href=\"@xmlsitemap_requirements\">module's system requirements page</a> for more information):", array(
'@xmlsitemap_requirements' => 'http://drupal.org/documentation/modules/xmlsitemap/requirements',
'@xmlsitemap_requirements' => 'https://www.drupal.org/documentation/modules/xmlsitemap/requirements',
)) . theme('item_list', array('items' => $missing_extensions)),
);
}
@@ -50,7 +50,7 @@ function xmlsitemap_requirements($phase) {
if (!xmlsitemap_check_directory()) {
$requirements['xmlsitemap_directory']['value'] = $t('Not found or not writable');
$requirements['xmlsitemap_directory']['severity'] = REQUIREMENT_ERROR;
$requirements['xmlsitemap_directory']['description'] = $t('The directory %directory was not found or is not writable by the server. See <a href="@docpage">@docpage</a> for more information.', array('%directory' => xmlsitemap_get_directory(), '@docpage' => 'http://drupal.org/node/34025'));
$requirements['xmlsitemap_directory']['description'] = $t('The directory %directory was not found or is not writable by the server. See <a href="@docpage">@docpage</a> for more information.', array('%directory' => xmlsitemap_get_directory(), '@docpage' => 'https://www.drupal.org/node/244924'));
}
else {
$directories = xmlsitemap_check_all_directories();
@@ -62,7 +62,11 @@ function xmlsitemap_requirements($phase) {
if (!empty($directories)) {
$requirements['xmlsitemap_directory']['value'] = $t('Not found or not writable');
$requirements['xmlsitemap_directory']['severity'] = REQUIREMENT_ERROR;
$requirements['xmlsitemap_directory']['description'] = $t('The following directories were not found or are not writable by the server. See <a href="@docpage">@docpage</a> for more information. !directories', array('!directories' => theme('item_list', array('items' => array_keys($directories))), '@docpage' => 'http://drupal.org/node/34025'));
$requirements['xmlsitemap_directory']['description'] = $t('The following directories were not found or are not writable by the server. See <a href="@docpage">@docpage</a> for more information. !directories', array(
'!directories' => theme('item_list', array(
'items' => array_keys($directories),
)), '@docpage' => 'https://www.drupal.org/node/244924',
));
}
}
@@ -111,7 +115,10 @@ function xmlsitemap_requirements($phase) {
$generated_ago = REQUEST_TIME - $generated_last;
$requirements['xmlsitemap_generated'] = array(
'title' => $t('XML sitemap'),
'value' => $generated_last ? $t('Last attempted generation on !date (!interval ago).', array('!date' => format_date($generated_last, 'small'), '!interval' => format_interval($generated_ago))) : $t('Cached files have not been generated yet.'),
'value' => $generated_last ? $t('Last attempted generation on !date (!interval ago).', array(
'!date' => format_date($generated_last, 'small'),
'!interval' => format_interval($generated_ago),
)) : $t('Cached files have not been generated yet.'),
'severity' => REQUIREMENT_OK,
);
if (variable_get('xmlsitemap_rebuild_needed', FALSE) && _xmlsitemap_rebuild_form_access()) {
@@ -214,8 +221,8 @@ function xmlsitemap_schema() {
'type' => 'float',
'default' => NULL,
// @todo Convert this field to non-nullable.
//'default' => 0.5,
//'not null' => NULL,
// 'default' => 0.5,
// 'not null' => NULL,
),
'priority_override' => array(
'description' => 'A boolean that if TRUE means that the priority field has been overridden from its default value.',
@@ -286,13 +293,15 @@ function xmlsitemap_schema() {
'not null' => TRUE,
'default' => 0,
),
//'queued' => array(
// @codingStandardsIgnoreStart
// 'queued' => array(
// 'type' => 'int',
// 'unsigned' => TRUE,
// 'not null' => TRUE,
// 'default' => 0,
// 'description' => 'Time when this sitemap was queued for regeneration, 0 if not queued.',
//),
// ),.
// @codingStandardsIgnoreEnd
),
'primary key' => array('smid'),
);
@@ -463,6 +472,8 @@ function xmlsitemap_update_6202() {
}
/**
* Implements hook_update_N().
*
* Convert the xmlsitemap_max_filesize variable to a max_filesize column
* per-sitemap.
*/
@@ -539,6 +550,8 @@ function xmlsitemap_update_7201() {
}
/**
* Implements hook_update_N().
*
* Convert the xmlsitemap_max_filesize variable to a max_filesize column
* per-sitemap.
*/
@@ -554,6 +567,9 @@ function xmlsitemap_update_7203() {
_xmlsitemap_sitemap_rehash_all();
}
/**
* Rehash all.
*/
function _xmlsitemap_sitemap_rehash_all() {
// Reload the schema cache and reprocess all sitemap hashes into smids.
drupal_load('module', 'xmlsitemap');

View File

@@ -1,6 +1,7 @@
<?php
/**
* @file
* @defgroup xmlsitemap XML sitemap
*/
@@ -19,11 +20,16 @@ define('XMLSITEMAP_MAX_SITEMAP_LINKS', 50000);
*/
define('XMLSITEMAP_MAX_SITEMAP_FILESIZE', 10485760);
define('XMLSITEMAP_FREQUENCY_YEARLY', 31449600); // 60 * 60 * 24 * 7 * 52
define('XMLSITEMAP_FREQUENCY_MONTHLY', 2419200); // 60 * 60 * 24 * 7 * 4
define('XMLSITEMAP_FREQUENCY_WEEKLY', 604800); // 60 * 60 * 24 * 7
define('XMLSITEMAP_FREQUENCY_DAILY', 86400); // 60 * 60 * 24
define('XMLSITEMAP_FREQUENCY_HOURLY', 3600); // 60 * 60
// 60 * 60 * 24 * 7 * 52.
define('XMLSITEMAP_FREQUENCY_YEARLY', 31449600);
// 60 * 60 * 24 * 7 * 4.
define('XMLSITEMAP_FREQUENCY_MONTHLY', 2419200);
// 60 * 60 * 24 * 7.
define('XMLSITEMAP_FREQUENCY_WEEKLY', 604800);
// 60 * 60 * 24.
define('XMLSITEMAP_FREQUENCY_DAILY', 86400);
// 60 * 60.
define('XMLSITEMAP_FREQUENCY_HOURLY', 3600);
define('XMLSITEMAP_FREQUENCY_ALWAYS', 60);
/**
@@ -97,10 +103,13 @@ function xmlsitemap_help($path, $arg) {
case 'admin/config/search/xmlsitemap/edit/%':
case 'admin/config/search/xmlsitemap/delete/%':
return;
case 'admin/help#xmlsitemap':
break;
case 'admin/config/search/xmlsitemap':
break;
case 'admin/config/search/xmlsitemap/rebuild':
$output .= '<p>' . t("This action rebuilds your site's XML sitemap and regenerates the cached files, and may be a lengthy process. If you just installed XML sitemap, this can be helpful to import all your site's content into the sitemap. Otherwise, this should only be used in emergencies.") . '</p>';
}
@@ -122,7 +131,11 @@ function xmlsitemap_help($path, $arg) {
*/
function xmlsitemap_permission() {
$permissions['administer xmlsitemap'] = array(
'title' => t('Administer XML sitemap settings.'),
'title' => t('Administer XML sitemap settings'),
);
$permissions['use xmlsitemap'] = array(
'title' => t('Use XML sitemap'),
'description' => t('Users can change individually the default XML Sitemap settings.'),
);
return $permissions;
}
@@ -281,6 +294,7 @@ function xmlsitemap_robotstxt() {
* Internal default variables for xmlsitemap_var().
*/
function xmlsitemap_variables() {
global $base_url;
return array(
'xmlsitemap_rebuild_needed' => FALSE,
'xmlsitemap_regenerate_needed' => FALSE,
@@ -291,7 +305,7 @@ function xmlsitemap_variables() {
'xmlsitemap_chunk_size' => 'auto',
'xmlsitemap_batch_limit' => 100,
'xmlsitemap_path' => 'xmlsitemap',
'xmlsitemap_base_url' => $GLOBALS['base_url'],
'xmlsitemap_base_url' => $base_url,
'xmlsitemap_developer_mode' => 0,
'xmlsitemap_frontpage_priority' => 1.0,
'xmlsitemap_frontpage_changefreq' => XMLSITEMAP_FREQUENCY_DAILY,
@@ -338,13 +352,16 @@ function xmlsitemap_var($name, $default = NULL) {
/**
* Load an XML sitemap array from the database.
*
* @param $smid
* @param array $smid
* An XML sitemap ID.
*
* @return
* @return object
* The XML sitemap object.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_sitemap_load($smid) {
// @codingStandardsIgnoreEnd
$sitemap = xmlsitemap_sitemap_load_multiple(array($smid));
return $sitemap ? reset($sitemap) : FALSE;
}
@@ -352,15 +369,18 @@ function xmlsitemap_sitemap_load($smid) {
/**
* Load multiple XML sitemaps from the database.
*
* @param $smids
* @param array $smids
* An array of XML sitemap IDs, or FALSE to load all XML sitemaps.
* @param $conditions
* @param array $conditions
* An array of conditions in the form 'field' => $value.
*
* @return
* @return array
* An array of XML sitemap objects.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_sitemap_load_multiple($smids = array(), array $conditions = array()) {
// @codingStandardsIgnoreEnd
if ($smids !== FALSE) {
$conditions['smid'] = $smids;
}
@@ -383,7 +403,7 @@ function xmlsitemap_sitemap_load_multiple($smids = array(), array $conditions =
/**
* Load an XML sitemap array from the database based on its context.
*
* @param $context
* @param array $context
* An optional XML sitemap context array to use to find the correct XML
* sitemap. If not provided, the current site's context will be used.
*
@@ -401,7 +421,7 @@ function xmlsitemap_sitemap_load_by_context(array $context = NULL) {
/**
* Save changes to an XML sitemap or add a new XML sitemap.
*
* @param $sitemap
* @param object $sitemap
* The XML sitemap array to be saved. If $sitemap->smid is omitted, a new
* XML sitemap will be added.
*
@@ -450,25 +470,28 @@ function xmlsitemap_sitemap_save(stdClass $sitemap) {
/**
* Delete an XML sitemap.
*
* @param $smid
* @param array $smid
* An XML sitemap ID.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_sitemap_delete($smid) {
// @codingStandardsIgnoreEnd
xmlsitemap_sitemap_delete_multiple(array($smid));
}
/**
* Delete multiple XML sitemaps.
*
* @param $smids
* @param array $smids
* An array of XML sitemap IDs.
*/
function xmlsitemap_sitemap_delete_multiple(array $smids) {
if (!empty($smids)) {
$sitemaps = xmlsitemap_sitemap_load_multiple($smids);
db_delete('xmlsitemap_sitemap')
->condition('smid', $smids)
->execute();
->condition('smid', $smids)
->execute();
foreach ($sitemaps as $sitemap) {
xmlsitemap_clear_directory($sitemap, TRUE);
@@ -480,9 +503,9 @@ function xmlsitemap_sitemap_delete_multiple(array $smids) {
/**
* Return the expected file path for a specific sitemap chunk.
*
* @param $sitemap
* @param object $sitemap
* An XML sitemap array.
* @param $chunk
* @param string $chunk
* An optional specific chunk in the sitemap. Defaults to the index page.
*/
function xmlsitemap_sitemap_get_file(stdClass $sitemap, $chunk = 'index') {
@@ -492,7 +515,7 @@ function xmlsitemap_sitemap_get_file(stdClass $sitemap, $chunk = 'index') {
/**
* Find the maximum file size of all a sitemap's XML files.
*
* @param $sitemap
* @param object $sitemap
* The XML sitemap array.
*/
function xmlsitemap_sitemap_get_max_filesize(stdClass $sitemap) {
@@ -504,6 +527,9 @@ function xmlsitemap_sitemap_get_max_filesize(stdClass $sitemap) {
return $sitemap->max_filesize;
}
/**
* Get context.
*/
function xmlsitemap_sitemap_get_context_hash(array &$context) {
asort($context);
return drupal_hash_base64(serialize($context));
@@ -512,19 +538,21 @@ function xmlsitemap_sitemap_get_context_hash(array &$context) {
/**
* Returns the uri elements of an XML sitemap.
*
* @param $sitemap
* @param object $sitemap
* An unserialized data array for an XML sitemap.
* @return
*
* @return array
* An array containing the 'path' and 'options' keys used to build the uri of
* the XML sitemap, and matching the signature of url().
*/
function xmlsitemap_sitemap_uri(stdClass $sitemap) {
global $base_url;
$uri['path'] = 'sitemap.xml';
$uri['options'] = module_invoke_all('xmlsitemap_context_url_options', $sitemap->context);
drupal_alter('xmlsitemap_context_url_options', $uri['options'], $sitemap->context);
$uri['options'] += array(
'absolute' => TRUE,
'base_url' => variable_get('xmlsitemap_base_url', $GLOBALS['base_url']),
'base_url' => variable_get('xmlsitemap_base_url', $base_url),
);
return $uri;
}
@@ -532,11 +560,12 @@ function xmlsitemap_sitemap_uri(stdClass $sitemap) {
/**
* Load a specific sitemap link from the database.
*
* @param $entity_type
* @param string $entity_type
* A string with the entity type.
* @param $entity_id
* @param int $entity_id
* An integer with the entity ID.
* @return
*
* @return array
* A sitemap link (array) or FALSE if the conditions were not found.
*/
function xmlsitemap_link_load($entity_type, $entity_id) {
@@ -547,10 +576,11 @@ function xmlsitemap_link_load($entity_type, $entity_id) {
/**
* Load sitemap links from the database.
*
* @param $conditions
* @param array $conditions
* An array of conditions on the {xmlsitemap} table in the form
* 'field' => $value.
* @return
*
* @return array
* An array of sitemap link arrays.
*/
function xmlsitemap_link_load_multiple(array $conditions = array()) {
@@ -566,6 +596,26 @@ function xmlsitemap_link_load_multiple(array $conditions = array()) {
return $links;
}
/**
* Presave a sitemap link.
*
* @param array $link
* An array with a sitemap link.
* @param array $context
* An optional context array containing data related to the link.
*/
function xmlsitemap_link_presave(array $link, array $context = array()) {
// Force link access to 0 in presave so that the link is saved with revoked
// access until the node permissions are checked in the cron.
$link['access'] = 0;
// Allow other modules to alter the sitemap link presave.
drupal_alter('xmlsitemap_link_presave', $link, $context);
// Save or update a sitemap link which will be overwritten in Drupal cron job.
xmlsitemap_link_save($link, $context);
}
/**
* Saves or updates a sitemap link.
*
@@ -596,10 +646,16 @@ function xmlsitemap_link_save(array $link, array $context = array()) {
// Temporary validation checks.
// @todo Remove in final?
if ($link['priority'] < 0 || $link['priority'] > 1) {
trigger_error(t('Invalid sitemap link priority %priority.<br />@link', array('%priority' => $link['priority'], '@link' => var_export($link, TRUE))), E_USER_ERROR);
trigger_error(t('Invalid sitemap link priority %priority.<br />@link', array(
'%priority' => $link['priority'],
'@link' => var_export($link, TRUE),
)), E_USER_ERROR);
}
if ($link['changecount'] < 0) {
trigger_error(t('Negative changecount value. Please report this to <a href="@516928">@516928</a>.<br />@link', array('@516928' => 'http://drupal.org/node/516928', '@link' => var_export($link, TRUE))), E_USER_ERROR);
trigger_error(t('Negative changecount value. Please report this to <a href="@516928">@516928</a>.<br />@link', array(
'@516928' => 'https://www.drupal.org/node/516928',
'@link' => var_export($link, TRUE),
)), E_USER_ERROR);
$link['changecount'] = 0;
}
@@ -629,14 +685,18 @@ function xmlsitemap_link_save(array $link, array $context = array()) {
* If visible links are updated, this will automatically set the regenerate
* needed flag to TRUE.
*
* @param $updates
* @param array $updates
* An array of values to update fields to, keyed by field name.
* @param $conditions
* @param array $conditions
* An array of values to match keyed by field.
* @return
*
* @return int
* The number of links that were updated.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_link_update_multiple($updates = array(), $conditions = array(), $check_flag = TRUE) {
// @codingStandardsIgnoreEnd
// If we are going to modify a visible sitemap link, we will need to set
// the regenerate needed flag.
if ($check_flag && !variable_get('xmlsitemap_regenerate_needed', FALSE)) {
@@ -659,11 +719,12 @@ function xmlsitemap_link_update_multiple($updates = array(), $conditions = array
* If a visible sitemap link was deleted, this will automatically set the
* regenerate needed flag.
*
* @param $entity_type
* @param string $entity_type
* A string with the entity type.
* @param $entity_id
* @param int $entity_id
* An integer with the entity ID.
* @return
*
* @return int
* The number of links that were deleted.
*/
function xmlsitemap_link_delete($entity_type, $entity_id) {
@@ -677,17 +738,18 @@ function xmlsitemap_link_delete($entity_type, $entity_id) {
* If visible sitemap links were deleted, this will automatically set the
* regenerate needed flag.
*
* @param $conditions
* @param array $conditions
* An array of conditions on the {xmlsitemap} table in the form
* 'field' => $value.
* @return
*
* @return int
* The number of links that were deleted.
*/
function xmlsitemap_link_delete_multiple(array $conditions) {
// Because this function is called from sub-module uninstall hooks, we have
// to manually check if the table exists since it could have been removed
// in xmlsitemap_uninstall().
// @todo Remove this check when http://drupal.org/node/151452 is fixed.
// @todo Remove this check when https://www.drupal.org/node/151452 is fixed.
if (!db_table_exists('xmlsitemap')) {
return FALSE;
}
@@ -709,12 +771,13 @@ function xmlsitemap_link_delete_multiple(array $conditions) {
/**
* Check if there is a visible sitemap link given a certain set of conditions.
*
* @param $conditions
* @param array $conditions
* An array of values to match keyed by field.
* @param $flag
* @param string $flag
* An optional boolean that if TRUE, will set the regenerate needed flag if
* there is a match. Defaults to FALSE.
* @return
*
* @return bool
* TRUE if there is a visible link, or FALSE otherwise.
*/
function _xmlsitemap_check_changed_links(array $conditions = array(), array $updates = array(), $flag = FALSE) {
@@ -740,19 +803,23 @@ function _xmlsitemap_check_changed_links(array $conditions = array(), array $upd
/**
* Check if there is sitemap link is changed from the existing data.
*
* @param $link
* @param array $link
* An array of the sitemap link.
* @param $original_link
* @param array $original_link
* An optional array of the existing data. This should only contain the
* fields necessary for comparison. If not provided the existing data will be
* loaded from the database.
* @param $flag
* @param bool $flag
* An optional boolean that if TRUE, will set the regenerate needed flag if
* there is a match. Defaults to FALSE.
* @return
*
* @return bool
* TRUE if the link is changed, or FALSE otherwise.
*
* @codingStandardsIgnoreStart
*/
function _xmlsitemap_check_changed_link(array $link, $original_link = NULL, $flag = FALSE) {
// @codingStandardsIgnoreEnd
$changed = FALSE;
if ($original_link === NULL) {
@@ -772,7 +839,7 @@ function _xmlsitemap_check_changed_link(array $link, $original_link = NULL, $fla
$changed = TRUE;
}
elseif ($original_link['access'] && $original_link['status'] && array_diff_assoc($original_link, $link)) {
// Changing a visible link
// Changing a visible link.
$changed = TRUE;
}
}
@@ -787,7 +854,6 @@ function _xmlsitemap_check_changed_link(array $link, $original_link = NULL, $fla
/**
* @} End of "defgroup xmlsitemap_api"
*/
function xmlsitemap_get_directory(stdClass $sitemap = NULL) {
$directory = &drupal_static(__FUNCTION__);
@@ -815,6 +881,9 @@ function xmlsitemap_check_directory(stdClass $sitemap = NULL) {
return $result;
}
/**
* Check all directories.
*/
function xmlsitemap_check_all_directories() {
$directories = array();
@@ -837,6 +906,9 @@ function xmlsitemap_check_all_directories() {
return $directories;
}
/**
* Clear Directory.
*/
function xmlsitemap_clear_directory(stdClass $sitemap = NULL, $delete = FALSE) {
$directory = xmlsitemap_get_directory($sitemap);
return _xmlsitemap_delete_recursive($directory, $delete);
@@ -845,14 +917,14 @@ function xmlsitemap_clear_directory(stdClass $sitemap = NULL, $delete = FALSE) {
/**
* Move a directory to a new location.
*
* @param $old_dir
* @param string $old_dir
* A string specifying the filepath or URI of the original directory.
* @param $new_dir
* @param string $new_dir
* A string specifying the filepath or URI of the new directory.
* @param $replace
* @param string $replace
* Replace behavior when the destination file already exists.
*
* @return
* @return bool
* TRUE if the directory was moved successfully. FALSE otherwise.
*/
function xmlsitemap_directory_move($old_dir, $new_dir, $replace = FILE_EXISTS_REPLACE) {
@@ -882,9 +954,9 @@ function xmlsitemap_directory_move($old_dir, $new_dir, $replace = FILE_EXISTS_RE
*
* Note that this only deletes visible files with write permission.
*
* @param $path
* @param string $path
* A filepath relative to the Drupal root directory.
* @param $delete_root
* @param bool $delete_root
* A boolean if TRUE will delete the $path directory afterwards.
*/
function _xmlsitemap_delete_recursive($path, $delete_root = FALSE) {
@@ -908,10 +980,10 @@ function _xmlsitemap_delete_recursive($path, $delete_root = FALSE) {
/**
* Returns information about supported sitemap link types.
*
* @param $type
* @param string $type
* (optional) The link type to return information for. If omitted,
* information for all link types is returned.
* @param $reset
* @param bool $reset
* (optional) Boolean whether to reset the static cache and do nothing. Only
* used for tests.
*
@@ -943,7 +1015,7 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
foreach ($info['bundles'] as $bundle_key => $bundle) {
if (!isset($bundle['xmlsitemap'])) {
// Remove any un-supported entity bundles.
//unset($link_info[$key]['bundles'][$bundle_key]);
// unset($link_info[$key]['bundles'][$bundle_key]);.
}
}
}
@@ -979,19 +1051,25 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
return $link_info;
}
/**
* Enabled Bundles.
*/
function xmlsitemap_get_link_type_enabled_bundles($entity_type) {
$bundles = array();
$info = xmlsitemap_get_link_info($entity_type);
foreach ($info['bundles'] as $bundle => $bundle_info) {
$settings = xmlsitemap_link_bundle_load($entity_type, $bundle);
if (!empty($settings['status'])) {
//if (!empty($bundle_info['xmlsitemap']['status'])) {
// If (!empty($bundle_info['xmlsitemap']['status'])) {.
$bundles[] = $bundle;
}
}
return $bundles;
}
/**
* Indexed Status.
*/
function xmlsitemap_get_link_type_indexed_status($entity_type, $bundle = '') {
$info = xmlsitemap_get_link_info($entity_type);
@@ -1002,7 +1080,7 @@ function xmlsitemap_get_link_type_indexed_status($entity_type, $bundle = '') {
$total->entityCondition('entity_type', $entity_type);
$total->entityCondition('bundle', $bundle);
$total->entityCondition('entity_id', 0, '>');
//$total->addTag('xmlsitemap_link_bundle_access');
// $total->addTag('xmlsitemap_link_bundle_access');.
$total->addTag('xmlsitemap_link_indexed_status');
$total->addMetaData('entity', $entity_type);
$total->addMetaData('bundle', $bundle);
@@ -1016,7 +1094,7 @@ function xmlsitemap_get_link_type_indexed_status($entity_type, $bundle = '') {
/**
* Implements hook_entity_query_alter().
*
* @todo Remove when http://drupal.org/node/1054168 is fixed.
* @todo Remove when https://www.drupal.org/node/1054168 is fixed.
*/
function xmlsitemap_entity_query_alter($query) {
$conditions = &$query->entityConditions;
@@ -1027,22 +1105,38 @@ function xmlsitemap_entity_query_alter($query) {
}
}
/**
* Budle Settings.
*/
function xmlsitemap_link_bundle_settings_save($entity, $bundle, array $settings, $update_links = TRUE) {
if ($update_links) {
$old_settings = xmlsitemap_link_bundle_load($entity, $bundle);
if ($settings['status'] != $old_settings['status']) {
xmlsitemap_link_update_multiple(array('status' => $settings['status']), array('type' => $entity, 'subtype' => $bundle, 'status_override' => 0));
xmlsitemap_link_update_multiple(array('status' => $settings['status']), array(
'type' => $entity,
'subtype' => $bundle,
'status_override' => 0,
));
}
if ($settings['priority'] != $old_settings['priority']) {
xmlsitemap_link_update_multiple(array('priority' => $settings['priority']), array('type' => $entity, 'subtype' => $bundle, 'priority_override' => 0));
xmlsitemap_link_update_multiple(array(
'priority' => $settings['priority'],
), array(
'type' => $entity,
'subtype' => $bundle,
'priority_override' => 0,
));
}
}
variable_set("xmlsitemap_settings_{$entity}_{$bundle}", $settings);
cache_clear_all('xmlsitemap:link_info:', 'cache', TRUE);
//xmlsitemap_get_link_info(NULL, TRUE);
// xmlsitemap_get_link_info(NULL, TRUE);.
}
/**
* Bundle Rename.
*/
function xmlsitemap_link_bundle_rename($entity, $bundle_old, $bundle_new) {
if ($bundle_old != $bundle_new) {
$settings = xmlsitemap_link_bundle_load($entity, $bundle_old);
@@ -1070,6 +1164,9 @@ function xmlsitemap_link_type_rename($entity_old, $entity_new, $bundles = NULL)
xmlsitemap_get_link_info(NULL, TRUE);
}
/**
* Bundle Load.
*/
function xmlsitemap_link_bundle_load($entity, $bundle, $load_bundle_info = TRUE) {
$info = array(
'entity' => $entity,
@@ -1089,15 +1186,21 @@ function xmlsitemap_link_bundle_load($entity, $bundle, $load_bundle_info = TRUE)
return $info;
}
/**
* Bundle Delete.
*/
function xmlsitemap_link_bundle_delete($entity, $bundle, $delete_links = TRUE) {
variable_del("xmlsitemap_settings_{$entity}_{$bundle}");
if ($delete_links) {
xmlsitemap_link_delete_multiple(array('type' => $entity, 'subtype' => $bundle));
}
cache_clear_all('xmlsitemap:link_info:', 'cache', TRUE);
//xmlsitemap_get_link_info(NULL, TRUE);
// xmlsitemap_get_link_info(NULL, TRUE);.
}
/**
* Bundle Access.
*/
function xmlsitemap_link_bundle_access($entity, $bundle = NULL) {
if (is_array($entity) && !isset($bundle)) {
$bundle = $entity;
@@ -1122,6 +1225,9 @@ function xmlsitemap_link_bundle_access($entity, $bundle = NULL) {
return FALSE;
}
/**
* Get Bundle.
*/
function xmlsitemap_get_bundle_path($entity, $bundle) {
$info = xmlsitemap_get_link_info($entity);
@@ -1153,9 +1259,10 @@ function xmlsitemap_field_attach_delete_bundle($entity_type, $bundle, $instances
/**
* Determine the frequency of updates to a link.
*
* @param $interval
* @param string $interval
* An interval value in seconds.
* @return
*
* @return string
* A string representing the update frequency according to the sitemaps.org
* protocol.
*/
@@ -1203,9 +1310,10 @@ function xmlsitemap_get_link_count($reset = FALSE) {
* calculate the appropriate value. Use this function instead of @code
* xmlsitemap_var('chunk_size') @endcode when the actual value is needed.
*
* @param $reset
* @param bool $reset
* A boolean to reset the saved, static result. Defaults to FALSE.
* @return
*
* @return int
* An integer with the number of links in each sitemap page.
*/
function xmlsitemap_get_chunk_size($reset = FALSE) {
@@ -1213,7 +1321,8 @@ function xmlsitemap_get_chunk_size($reset = FALSE) {
if (!isset($size) || $reset) {
$size = xmlsitemap_var('chunk_size');
if ($size === 'auto') {
$count = max(xmlsitemap_get_link_count($reset), 1); // Prevent divide by zero.
// Prevent divide by zero.
$count = max(xmlsitemap_get_link_count($reset), 1);
$size = min(ceil($count / 10000) * 5000, XMLSITEMAP_MAX_SITEMAP_LINKS);
}
}
@@ -1223,10 +1332,13 @@ function xmlsitemap_get_chunk_size($reset = FALSE) {
/**
* Recalculate the changefreq of a sitemap link.
*
* @param $link
* @param array $link
* A sitemap link array.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_recalculate_changefreq(&$link) {
// @codingStandardsIgnoreEnd
$link['changefreq'] = round((($link['changefreq'] * $link['changecount']) + (REQUEST_TIME - $link['lastmod'])) / ($link['changecount'] + 1));
$link['changecount']++;
$link['lastmod'] = REQUEST_TIME;
@@ -1235,12 +1347,16 @@ function xmlsitemap_recalculate_changefreq(&$link) {
/**
* Calculates the average interval between UNIX timestamps.
*
* @param $timestamps
* @param array $timestamps
* An array of UNIX timestamp integers.
* @return
*
* @return int
* An integer of the average interval.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_calculate_changefreq($timestamps) {
// @codingStandardsIgnoreEnd
sort($timestamps);
$count = count($timestamps) - 1;
$diff = 0;
@@ -1275,7 +1391,7 @@ function xmlsitemap_form_submit_flag_regenerate($form, $form_state) {
/**
* Set the current user stored in $GLOBALS['user'].
*
* @todo Remove when http://drupal.org/node/287292 is fixed.
* @todo Remove when https://www.drupal.org/node/287292 is fixed.
*/
function xmlsitemap_switch_user($new_user = NULL) {
global $user;
@@ -1328,17 +1444,24 @@ function xmlsitemap_switch_user($new_user = NULL) {
/**
* Restore the user that was originally loaded.
*
* @return
* Current user.
* @codingStandardsIgnoreLine
* @return object.
* Current user.
*/
function xmlsitemap_restore_user() {
return xmlsitemap_switch_user();
}
/**
* Form Link.
*/
function xmlsitemap_process_form_link_options($form, &$form_state) {
$link = &$form_state['values']['xmlsitemap'];
$fields = array('status' => XMLSITEMAP_STATUS_DEFAULT, 'priority' => XMLSITEMAP_PRIORITY_DEFAULT);
if (empty($link)) {
return;
}
foreach ($fields as $field => $default) {
if ($link[$field] === 'default') {
$link[$field] = isset($link[$field . '_default']) ? $link[$field . '_default'] : $default;
@@ -1350,6 +1473,9 @@ function xmlsitemap_process_form_link_options($form, &$form_state) {
}
}
/**
* Link bundle settings form submit.
*/
function xmlsitemap_link_bundle_settings_form_submit($form, &$form_state) {
$entity = $form['xmlsitemap']['#entity'];
$bundle = $form['xmlsitemap']['#bundle'];
@@ -1376,11 +1502,13 @@ function xmlsitemap_link_bundle_settings_form_submit($form, &$form_state) {
// Unset the form values since we have already saved the bundle settings and
// we don't want these values to get saved as variables in-case this form
// also uses system_settings_form().
// Also uses system_settings_form().
unset($form_state['values']['xmlsitemap']);
}
/**
* Get Freq.
*
* @todo Document this function.
* @todo Make these translatable
*/
@@ -1398,11 +1526,12 @@ function xmlsitemap_get_changefreq_options() {
/**
* Load a language object by its language code.
*
* @todo Remove when http://drupal.org/node/660736 is fixed in Drupal core.
* @todo Remove when https://www.drupal.org/node/660736 is fixed in Drupal core.
*
* @param $language
* @param string $language
* A language code. If not provided the default language will be returned.
* @return
*
* @return object
* A language object.
*/
function xmlsitemap_language_load($language = LANGUAGE_NONE) {
@@ -1420,7 +1549,6 @@ function xmlsitemap_language_load($language = LANGUAGE_NONE) {
* @defgroup xmlsitemap_context_api XML sitemap API for sitemap contexts.
* @{
*/
function xmlsitemap_get_context_info($context = NULL, $reset = FALSE) {
global $language;
$info = &drupal_static(__FUNCTION__);
@@ -1462,6 +1590,9 @@ function xmlsitemap_get_current_context() {
return $context;
}
/**
* Context summary.
*/
function _xmlsitemap_sitemap_context_summary(stdClass $sitemap, $context_key, array $context_info) {
$context_value = isset($sitemap->context[$context_key]) ? $sitemap->context[$context_key] : NULL;
@@ -1505,7 +1636,7 @@ function xmlsitemap_run_unprogressive_batch() {
batch_set($batch);
// We need to manually set the progressive variable again.
// @todo Remove when http://drupal.org/node/638712 is fixed.
// @todo Remove when https://www.drupal.org/node/638712 is fixed.
$batch =& batch_get();
$batch['progressive'] = FALSE;
@@ -1519,7 +1650,7 @@ function xmlsitemap_run_unprogressive_batch() {
/**
* Workaround for missing breadcrumbs on callback and action paths.
*
* @todo Remove when http://drupal.org/node/576290 is fixed.
* @todo Remove when https://www.drupal.org/node/576290 is fixed.
*/
function _xmlsitemap_set_breadcrumb($path = 'admin/config/search/xmlsitemap') {
$breadcrumb = array();
@@ -1533,6 +1664,9 @@ function _xmlsitemap_set_breadcrumb($path = 'admin/config/search/xmlsitemap') {
drupal_set_breadcrumb($breadcrumb);
}
/**
* Get operation link.
*/
function xmlsitemap_get_operation_link($url, $options = array()) {
static $destination;

View File

@@ -74,14 +74,14 @@ function xmlsitemap_output_file($file, array $headers = array()) {
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;
if ($if_modified_since && $if_none_match && $if_none_match == $etag && $if_modified_since == $last_modified) {
header('HTTP/1.1 304 Not Modified');
// All 304 responses must send an etag if the 200 response for the same object contained an etag
// All 304 responses must send an etag if the 200 response for the same
// object contained an etag.
header('Etag: ' . $etag);
exit;
}
$headers += array(
'Content-type' => 'text/xml; charset=utf-8',
//'Content-length' => filesize($file),
'Last-modified' => $last_modified,
'Etag' => $etag,
'Expires' => gmdate(DATE_RFC1123, $mtime + variable_get('xmlsitemap_minimum_lifetime', 0)),
@@ -115,9 +115,11 @@ function xmlsitemap_file_transfer($uri, $headers) {
// Transfer file in 16 KB chunks to save memory usage.
if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) {
while (!feof($fd)) {
print fread($fd, 1024*16);
print fread($fd, 1024 * 16);
}
fclose($fd);
// Disable session manipulation if PHP transferred a file.
drupal_save_session(FALSE);
}
else {
drupal_not_found();
@@ -136,7 +138,7 @@ function xmlsitemap_output_xsl() {
// Make sure the strings in the XSL content are translated properly.
$replacements = array(
'Sitemap file' => t('Sitemap file'),
'Generated by the <a href="http://drupal.org/project/xmlsitemap">Drupal XML sitemap module</a>.' => t('Generated by the <a href="@link-xmlsitemap">Drupal XML sitemap module</a>.', array('@link-xmlsitemap' => 'http://drupal.org/project/xmlsitemap')),
'Generated by the <a href="https://www.drupal.org/project/xmlsitemap">Drupal XML sitemap</a>.' => t('Generated by the <a href="@link-xmlsitemap">Drupal XML sitemap</a>.', array('@link-xmlsitemap' => 'https://www.drupal.org/project/xmlsitemap')),
'Number of sitemaps in this index' => t('Number of sitemaps in this index'),
'Click on the table headers to change sorting.' => t('Click on the table headers to change sorting.'),
'Sitemap URL' => t('Sitemap URL'),

View File

@@ -2,7 +2,7 @@
/**
* @file
* Unit tests for the xmlsitemap module.
* Unit tests for the xmlsitemap.
*
* @ingroup xmlsitemap
*/
@@ -11,14 +11,30 @@
* Helper test class with some added functions for testing.
*/
class XMLSitemapTestHelper extends DrupalWebTestCase {
/**
* Admin User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $admin_user;
function setUp($modules = array()) {
/**
* SetUp.
*
* @codingStandardsIgnoreEnd
*/
public function setUp($modules = array()) {
array_unshift($modules, 'xmlsitemap');
parent::setUp($modules);
}
function tearDown() {
/**
* Tear Down.
*/
public function tearDown() {
// Capture any (remaining) watchdog errors.
$this->assertNoWatchdogErrors();
@@ -28,12 +44,13 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
/**
* Assert the page does not respond with the specified response code.
*
* @param $code
* @param string $code
* Response code. For example 200 is a successful page request. For a list
* of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
* @param $message
* @param string $message
* Message to display.
* @return
*
* @return string
* Assertion result.
*/
protected function assertNoResponse($code, $message = '') {
@@ -45,7 +62,7 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
/**
* Check the files directory is created (massive fails if not done).
*
* @todo This can be removed when http://drupal.org/node/654752 is fixed.
* @todo This can be removed when https://www.drupal.org/node/654752 is fixed.
*/
protected function checkFilesDirectory() {
if (!xmlsitemap_check_directory()) {
@@ -56,15 +73,16 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
/**
* Retrieves an XML sitemap.
*
* @param $context
* @param array $context
* An optional array of the XML sitemap's context.
* @param $options
* @param array $options
* Options to be forwarded to url(). These values will be merged with, but
* always override $sitemap->uri['options'].
* @param $headers
* @param array $headers
* An array containing additional HTTP request headers, each formatted as
* "name: value".
* @return
*
* @return string
* The retrieved HTML string, also available as $this->drupalGetContent()
*/
protected function drupalGetSitemap(array $context = array(), array $options = array(), array $headers = array()) {
@@ -85,6 +103,9 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
$this->assertTrue(variable_get('xmlsitemap_generated_last', 0) && !variable_get('xmlsitemap_regenerate_needed', FALSE), t('XML sitemaps regenerated and flag cleared.'));
}
/**
* Assert Sitemap Link.
*/
protected function assertSitemapLink($entity_type, $entity_id = NULL) {
if (is_array($entity_type)) {
$links = xmlsitemap_link_load_multiple($entity_type);
@@ -97,6 +118,9 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
return $link;
}
/**
* Assert No Sitemap Link.
*/
protected function assertNoSitemapLink($entity_type, $entity_id = NULL) {
if (is_array($entity_type)) {
$links = xmlsitemap_link_load_multiple($entity_type);
@@ -109,54 +133,94 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
return $link;
}
/**
* Assert Sitemap Link Visible.
*/
protected function assertSitemapLinkVisible($entity_type, $entity_id) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$this->assertTrue($link && $link['access'] && $link['status'], t('Sitemap link @type @id is visible.', array('@type' => $entity_type, '@id' => $entity_id)));
}
/**
* Assert Sitemap Link Not Visible.
*/
protected function assertSitemapLinkNotVisible($entity_type, $entity_id) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
$this->assertTrue($link && !($link['access'] && $link['status']), t('Sitemap link @type @id is not visible.', array('@type' => $entity_type, '@id' => $entity_id)));
$this->assertTrue($link && !($link['access'] && $link['status']), t('Sitemap link @type @id is not visible.', array(
'@type' => $entity_type,
'@id' => $entity_id,
)));
}
/**
* Assert Sitemap Link Values.
*/
protected function assertSitemapLinkValues($entity_type, $entity_id, array $conditions) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
if (!$link) {
return $this->fail(t('Could not load sitemap link for @type @id.', array('@type' => $entity_type, '@id' => $entity_id)));
return $this->fail(t('Could not load sitemap link for @type @id.', array(
'@type' => $entity_type,
'@id' => $entity_id,
)));
}
foreach ($conditions as $key => $value) {
if ($value === NULL || $link[$key] === NULL) {
// For nullable fields, always check for identical values (===).
$this->assertIdentical($link[$key], $value, t('Identical values for @type @id link field @key.', array('@type' => $entity_type, '@id' => $entity_id, '@key' => $key)));
$this->assertIdentical($link[$key], $value, t('Identical values for @type @id link field @key.', array(
'@type' => $entity_type,
'@id' => $entity_id,
'@key' => $key,
)));
}
else {
// Otherwise check simple equality (==).
$this->assertEqual($link[$key], $value, t('Equal values for @type @id link field @key.', array('@type' => $entity_type, '@id' => $entity_id, '@key' => $key)));
$this->assertEqual($link[$key], $value, t('Equal values for @type @id link field @key.', array(
'@type' => $entity_type,
'@id' => $entity_id,
'@key' => $key,
)));
}
}
}
/**
* Assert Not Sitemap Link Values.
*/
protected function assertNotSitemapLinkValues($entity_type, $entity_id, array $conditions) {
$link = xmlsitemap_link_load($entity_type, $entity_id);
if (!$link) {
return $this->fail(t('Could not load sitemap link for @type @id.', array('@type' => $entity_type, '@id' => $entity_id)));
return $this->fail(t('Could not load sitemap link for @type @id.', array(
'@type' => $entity_type,
'@id' => $entity_id,
)));
}
foreach ($conditions as $key => $value) {
if ($value === NULL || $link[$key] === NULL) {
// For nullable fields, always check for identical values (===).
$this->assertNotIdentical($link[$key], $value, t('Not identical values for @type @id link field @key.', array('@type' => $entity_type, '@id' => $entity_id, '@key' => $key)));
$this->assertNotIdentical($link[$key], $value, t('Not identical values for @type @id link field @key.', array(
'@type' => $entity_type,
'@id' => $entity_id,
'@key' => $key,
)));
}
else {
// Otherwise check simple equality (==).
$this->assertNotEqual($link[$key], $value, t('Not equal values for link @type @id field @key.', array('@type' => $entity_type, '@id' => $entity_id, '@key' => $key)));
$this->assertNotEqual($link[$key], $value, t('Not equal values for link @type @id field @key.', array(
'@type' => $entity_type,
'@id' => $entity_id,
'@key' => $key,
)));
}
}
}
/**
* Assert Raw Sitemap Links.
*/
protected function assertRawSitemapLinks() {
$links = func_get_args();
foreach ($links as $link) {
@@ -165,6 +229,9 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
}
}
/**
* Assert No Raw Sitemap Links.
*/
protected function assertNoRawSitemapLinks() {
$links = func_get_args();
foreach ($links as $link) {
@@ -173,6 +240,9 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
}
}
/**
* Add Sitemap Link.
*/
protected function addSitemapLink(array $link = array()) {
$last_id = &drupal_static(__FUNCTION__, 1);
@@ -191,6 +261,9 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
return $link;
}
/**
* Assert Flag.
*/
protected function assertFlag($variable, $assert_value = TRUE, $reset_if_true = TRUE) {
$value = xmlsitemap_var($variable);
@@ -201,7 +274,13 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
return $this->assertEqual($value, $assert_value, "xmlsitemap_$variable is " . ($assert_value ? 'TRUE' : 'FALSE'));
}
/**
* Assert XML Sitemap Problems.
*
* @codingStandardsIgnoreStart
*/
protected function assertXMLSitemapProblems($problem_text = FALSE) {
// @codingStandardsIgnoreEnd
$this->drupalGet('admin/config/search/xmlsitemap');
$this->assertText(t('One or more problems were detected with your XML sitemap configuration'));
if ($problem_text) {
@@ -209,7 +288,13 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
}
}
/**
* Assert No XML Sitemap Problems.
*
* @codingStandardsIgnoreStart
*/
protected function assertNoXMLSitemapProblems() {
// @codingStandardsIgnoreEnd
$this->drupalGet('admin/config/search/xmlsitemap');
$this->assertNoText(t('One or more problems were detected with your XML sitemap configuration'));
}
@@ -228,7 +313,14 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
}
$query = db_select('watchdog');
$query->fields('watchdog', array('wid', 'type', 'severity', 'message', 'variables', 'timestamp'));
$query->fields('watchdog', array(
'wid',
'type',
'severity',
'message',
'variables',
'timestamp',
));
foreach ($conditions as $field => $value) {
if ($field == 'variables' && !is_string($value)) {
$value = serialize($value);
@@ -245,10 +337,16 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
return $messages;
}
/**
* Assert Watchdog Message.
*/
protected function assertWatchdogMessage(array $conditions, $message = 'Watchdog message found.') {
$this->assertTrue($this->getWatchdogMessages($conditions), $message);
}
/**
* Assert No Watchdog Message.
*/
protected function assertNoWatchdogMessage(array $conditions, $message = 'Watchdog message not found.') {
$this->assertFalse($this->getWatchdogMessages($conditions), $message);
}
@@ -262,7 +360,13 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
foreach ($messages as $message) {
$message->text = $this->formatWatchdogMessage($message);
if (in_array($message->severity, array(WATCHDOG_EMERGENCY, WATCHDOG_ALERT, WATCHDOG_CRITICAL, WATCHDOG_ERROR, WATCHDOG_WARNING))) {
if (in_array($message->severity, array(
WATCHDOG_EMERGENCY,
WATCHDOG_ALERT,
WATCHDOG_CRITICAL,
WATCHDOG_ERROR,
WATCHDOG_WARNING,
))) {
$this->fail($message->text);
}
$verbose[] = $message->text;
@@ -280,9 +384,10 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
/**
* Format a watchdog message in a one-line summary.
*
* @param $message
* A watchdog messsage object.
* @return
* @param object $message
* A watchdog message object.
*
* @return string
* A string containing the watchdog message's timestamp, severity, type,
* and actual message.
*/
@@ -308,13 +413,14 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
* This is a copy of DrupalWebTestCase->verbose() but allows a customizable
* summary message rather than hard-coding 'Verbose message'.
*
* @param $verbose_message
* @param string $verbose_message
* The verbose message to be stored.
* @param $message
* @param string $message
* Message to display.
*
* @see simpletest_verbose()
*
* @todo Remove when http://drupal.org/node/800426 is fixed.
* @todo Remove when https://www.drupal.org/node/800426 is fixed.
*/
protected function verbose($verbose_message, $message = 'Verbose message') {
if ($id = simpletest_verbose($verbose_message)) {
@@ -322,9 +428,17 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
$this->error(l($message, $url, array('attributes' => array('target' => '_blank'))), 'User notice');
}
}
}
/**
* XML Sitemap UnitTest.
*/
class XMLSitemapUnitTest extends XMLSitemapTestHelper {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap unit tests',
@@ -333,7 +447,10 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
);
}
function testAssertFlag() {
/**
* Test Assert Flag.
*/
public function testAssertFlag() {
variable_set('xmlsitemap_rebuild_needed', TRUE);
$this->assertTrue(xmlsitemap_var('rebuild_needed'));
$this->assertTrue($this->assertFlag('rebuild_needed', TRUE, FALSE));
@@ -347,7 +464,7 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
/**
* Tests for xmlsitemap_get_changefreq().
*/
function testGetChangefreq() {
public function testGetChangefreq() {
// The test values.
$values = array(
0,
@@ -381,7 +498,7 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
/**
* Tests for xmlsitemap_get_chunk_count().
*/
function testGetChunkCount() {
public function testGetChunkCount() {
// Set a low chunk size for testing.
variable_set('xmlsitemap_chunk_size', 4);
@@ -407,24 +524,27 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
$this->assertEqual(xmlsitemap_get_link_count(), 0);
// Delete all links. The chunk count should be 1 not 0.
db_query("DELETE FROM {xmlsitemap}");
db_delete('xmlsitemap')->execute();
$this->assertEqual(db_query("SELECT COUNT(id) FROM {xmlsitemap}")->fetchField(), 0);
$this->assertEqual(xmlsitemap_get_chunk_count(TRUE), 1);
}
//function testGetChunkFile() {
//}
// @codingStandardsIgnoreStart
// Function testGetChunkFile() {
// }
//
//function testGetChunkSize() {
//}
// function testGetChunkSize() {
// }
//
//function testGetLinkCount() {
//}
// function testGetLinkCount() {
// }
// @codingStandardsIgnoreEnd
/**
* Tests for xmlsitemap_calculate_changereq().
*/
function testCalculateChangefreq() {
public function testCalculateChangefreq() {
// The test values.
$values = array(
array(),
@@ -439,16 +559,19 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
foreach ($values as $i => $value) {
$actual = xmlsitemap_calculate_changefreq($value);
$this->assertEqual($actual, $expected[$i]);
}
}
/**
* Test for xmlsitemap_recalculate_changefreq().
*/
function testRecalculateChangefreq() {
public function testRecalculateChangefreq() {
// The starting test value.
$value = array('lastmod' => REQUEST_TIME - 1000, 'changefreq' => 0, 'changecount' => 0);
$value = array(
'lastmod' => REQUEST_TIME - 1000,
'changefreq' => 0,
'changecount' => 0,
);
// Expected values.
$expecteds = array(
@@ -466,7 +589,7 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
/**
* Tests for xmlsitemap_switch_user and xmlsitemap_restore_user().
*/
function testSwitchUser() {
public function testSwitchUser() {
global $user;
$original_user = $user;
@@ -509,14 +632,21 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
$this->assertEqual($user->uid, 0);
}
//function testLoadLink() {
//}
// @codingStandardsIgnoreStart
// function testLoadLink() {
// }
// @codingStandardsIgnoreEnd
/**
* Tests for xmlsitemap_link_save().
*/
function testSaveLink() {
$link = array('type' => 'testing', 'id' => 1, 'loc' => 'testing', 'status' => 1);
public function testSaveLink() {
$link = array(
'type' => 'testing',
'id' => 1,
'loc' => 'testing',
'status' => 1,
);
xmlsitemap_link_save($link);
$this->assertFlag('regenerate_needed', TRUE);
@@ -564,7 +694,7 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
/**
* Tests for xmlsitemap_link_delete().
*/
function testLinkDelete() {
public function testLinkDelete() {
// Add our testing data.
$link1 = $this->addSitemapLink(array('loc' => 'testing1', 'status' => 0));
$link2 = $this->addSitemapLink(array('loc' => 'testing1', 'status' => 1));
@@ -589,55 +719,67 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
/**
* Tests for xmlsitemap_link_update_multiple().
*/
function testUpdateLinks() {
public function testUpdateLinks() {
// Add our testing data.
$links = array();
$links[1] = $this->addSitemapLink(array('subtype' => 'group1'));
$links[2] = $this->addSitemapLink(array('subtype' => 'group1'));
$links[3] = $this->addSitemapLink(array('subtype' => 'group2'));
variable_set('xmlsitemap_regenerate_needed', FALSE);
// id | type | subtype | language | access | status | priority
// Id | type | subtype | language | access | status | priority
// 1 | testing | group1 | '' | 1 | 1 | 0.5
// 2 | testing | group1 | '' | 1 | 1 | 0.5
// 3 | testing | group2 | '' | 1 | 1 | 0.5
$updated = xmlsitemap_link_update_multiple(array('status' => 0), array('type' => 'testing', 'subtype' => 'group1', 'status_override' => 0));
// 3 | testing | group2 | '' | 1 | 1 | 0.5.
$updated = xmlsitemap_link_update_multiple(array('status' => 0), array(
'type' => 'testing',
'subtype' => 'group1',
'status_override' => 0,
));
$this->assertEqual($updated, 2);
$this->assertFlag('regenerate_needed', TRUE);
// id | type | subtype | language | status | priority
// Id | type | subtype | language | status | priority
// 1 | testing | group1 | '' | 0 | 0.5
// 2 | testing | group1 | '' | 0 | 0.5
// 3 | testing | group2 | '' | 1 | 0.5
$updated = xmlsitemap_link_update_multiple(array('priority' => 0.0), array('type' => 'testing', 'subtype' => 'group1', 'priority_override' => 0));
// 3 | testing | group2 | '' | 1 | 0.5.
$updated = xmlsitemap_link_update_multiple(array('priority' => 0.0), array(
'type' => 'testing',
'subtype' => 'group1',
'priority_override' => 0,
));
$this->assertEqual($updated, 2);
$this->assertFlag('regenerate_needed', FALSE);
// id | type | subtype | language | status | priority
// Id | type | subtype | language | status | priority
// 1 | testing | group1 | '' | 0 | 0.0
// 2 | testing | group1 | '' | 0 | 0.0
// 3 | testing | group2 | '' | 1 | 0.5
$updated = xmlsitemap_link_update_multiple(array('subtype' => 'group2'), array('type' => 'testing', 'subtype' => 'group1'));
// 3 | testing | group2 | '' | 1 | 0.5.
$updated = xmlsitemap_link_update_multiple(array('subtype' => 'group2'), array(
'type' => 'testing',
'subtype' => 'group1',
));
$this->assertEqual($updated, 2);
$this->assertFlag('regenerate_needed', FALSE);
// id | type | subtype | language | status | priority
// Id | type | subtype | language | status | priority
// 1 | testing | group2 | '' | 0 | 0.0
// 2 | testing | group2 | '' | 0 | 0.0
// 3 | testing | group2 | '' | 1 | 0.5
$updated = xmlsitemap_link_update_multiple(array('status' => 1), array('type' => 'testing', 'subtype' => 'group2', 'status_override' => 0, 'status' => 0));
// 3 | testing | group2 | '' | 1 | 0.5.
$updated = xmlsitemap_link_update_multiple(array('status' => 1), array(
'type' => 'testing',
'subtype' => 'group2',
'status_override' => 0,
'status' => 0,
));
$this->assertEqual($updated, 2);
$this->assertFlag('regenerate_needed', TRUE);
// id | type | subtype | language | status | priority
// Id | type | subtype | language | status | priority
// 1 | testing | group2 | '' | 1 | 0.0
// 2 | testing | group2 | '' | 1 | 0.0
// 3 | testing | group2 | '' | 1 | 0.5
// 3 | testing | group2 | '' | 1 | 0.5.
}
/**
* Test that duplicate paths are skipped during generation.
*/
function testDuplicatePaths() {
public function testDuplicatePaths() {
$link1 = $this->addSitemapLink(array('loc' => 'duplicate'));
$link2 = $this->addSitemapLink(array('loc' => 'duplicate'));
$this->regenerateSitemap();
@@ -648,7 +790,7 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
/**
* Test that the sitemap will not be genereated before the lifetime expires.
*/
function testMinimumLifetime() {
public function testMinimumLifetime() {
variable_set('xmlsitemap_minimum_lifetime', 300);
$this->regenerateSitemap();
@@ -673,9 +815,17 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
$this->assertResponse(200);
$this->assertNoRaw('lifetime-test');
}
}
/**
* XML Sitemap Functional Test.
*/
class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap interface tests',
@@ -684,17 +834,24 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'path';
parent::setUp($modules);
$this->admin_user = $this->drupalCreateUser(array('access content', 'administer site configuration', 'administer xmlsitemap'));
$this->admin_user = $this->drupalCreateUser(array(
'access content',
'administer site configuration',
'administer xmlsitemap',
));
$this->drupalLogin($this->admin_user);
}
/**
* Test the sitemap file caching.
*/
function testSitemapCaching() {
public function testSitemapCaching() {
$this->regenerateSitemap();
$this->drupalGetSitemap();
$this->assertResponse(200);
@@ -709,8 +866,11 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
/**
* Test base URL functionality.
*
* @codingStandardsIgnoreStart
*/
function testBaseURL() {
public function testBaseURL() {
// @codingStandardsIgnoreEnd
$edit = array('xmlsitemap_base_url' => '');
$this->drupalPost('admin/config/search/xmlsitemap/settings', $edit, t('Save configuration'));
$this->assertText(t('Default base URL field is required.'));
@@ -733,20 +893,24 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
}
/**
* Test that configuration problems are reported properly in the status report.
* Test Status Report Function.
*
* Test that configuration problems are reported properly in the status
* report.
*/
function testStatusReport() {
public function testStatusReport() {
// Test the rebuild flag.
// @codingStandardsIgnoreStart
// @todo Re-enable these tests once we get a xmlsitemap_test.module.
//variable_set('xmlsitemap_generated_last', REQUEST_TIME);
//variable_set('xmlsitemap_rebuild_needed', TRUE);
//$this->assertXMLSitemapProblems(t('The XML sitemap data is out of sync and needs to be completely rebuilt.'));
//$this->clickLink(t('completely rebuilt'));
//$this->assertResponse(200);
//variable_set('xmlsitemap_rebuild_needed', FALSE);
//$this->assertNoXMLSitemapProblems();
// variable_set('xmlsitemap_generated_last', REQUEST_TIME);
// variable_set('xmlsitemap_rebuild_needed', TRUE);
// $this->assertXMLSitemapProblems(t('The XML sitemap data is out of sync and needs to be completely rebuilt.'));
// $this->clickLink(t('completely rebuilt'));
// $this->assertResponse(200);
// variable_set('xmlsitemap_rebuild_needed', FALSE);
// $this->assertNoXMLSitemapProblems();
// Test the regenerate flag (and cron hasn't run in a while).
// @codingStandardsIgnoreEnd
variable_set('xmlsitemap_regenerate_needed', TRUE);
variable_set('xmlsitemap_generated_last', REQUEST_TIME - variable_get('cron_threshold_warning', 172800) - 100);
$this->assertXMLSitemapProblems(t('The XML cached files are out of date and need to be regenerated. You can run cron manually to regenerate the sitemap files.'));
@@ -757,9 +921,17 @@ class XMLSitemapFunctionalTest extends XMLSitemapTestHelper {
// Test chunk count > 1000.
// Test directory not writable.
}
}
/**
* XML Sitemap Robots Txt Integration Test.
*/
class XMLSitemapRobotsTxtIntegrationTest extends XMLSitemapTestHelper {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap robots.txt',
@@ -769,15 +941,22 @@ class XMLSitemapRobotsTxtIntegrationTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'robotstxt';
parent::setUp($modules);
}
function testRobotsTxt() {
/**
* Test Robots Txt.
*/
public function testRobotsTxt() {
// Request the un-clean robots.txt path so this will work in case there is
// still the robots.txt file in the root directory.
$this->drupalGet('', array('query' => array('q' => 'robots.txt')));
$this->assertRaw('Sitemap: ' . url('sitemap.xml', array('absolute' => TRUE)));
}
}

View File

@@ -5,36 +5,69 @@
* XML sitemap integration functions for xmlsitemap.module.
*/
class XMLSitemapException extends Exception {}
/**
* Class for XML Sitemap Exception.
*/
class XMLSitemapException extends Exception {
class XMLSitemapGenerationException extends XMLSitemapException {}
}
/**
* Class for XML Sitemap Generation Exception.
*/
class XMLSitemapGenerationException extends XMLSitemapException {
}
/**
* Extended class for writing XML sitemap files.
*/
class XMLSitemapWriter extends XMLWriter {
protected $uri = NULL;
protected $sitemapElementCount = 0;
protected $linkCountFlush = 500;
protected $sitemap = NULL;
/**
* Sitemap Page.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $sitemap_page = NULL;
/**
* Root Element.
*
* @var string.
*
* @codingStandardsIgnoreEnd
*/
protected $rootElement = 'urlset';
/**
* Constructor.
*
* @param $sitemap
* @param array $sitemap
* The sitemap array.
* @param $page
* @param string $page
* The current page of the sitemap being generated.
*
* @codingStandardsIgnoreStart
*/
function __construct(stdClass $sitemap, $page) {
public function __construct(stdClass $sitemap, $page) {
// @codingStandardsIgnoreEnd
$this->sitemap = $sitemap;
$this->sitemap_page = $page;
$this->uri = xmlsitemap_sitemap_get_file($sitemap, $page);
$this->openUri($this->uri);
}
/**
* Open URI.
*/
public function openUri($uri) {
$return = parent::openUri($uri);
if (!$return) {
@@ -43,6 +76,9 @@ class XMLSitemapWriter extends XMLWriter {
return $return;
}
/**
* Start Document.
*/
public function startDocument($version = '1.0', $encoding = 'UTF-8', $standalone = NULL) {
$this->setIndent(FALSE);
$result = parent::startDocument($version, $encoding);
@@ -56,11 +92,15 @@ class XMLSitemapWriter extends XMLWriter {
return $result;
}
/**
* Get Sitemap URL.
*/
public function getSitemapUrl($path, array $options = array()) {
global $base_url;
$options += $this->sitemap->uri['options'];
$options += array(
'absolute' => TRUE,
'base_url' => variable_get('xmlsitemap_base_url', $GLOBALS['base_url']),
'base_url' => variable_get('xmlsitemap_base_url', $base_url),
'language' => language_default(),
'alias' => TRUE,
);
@@ -72,9 +112,12 @@ class XMLSitemapWriter extends XMLWriter {
/**
* Add the XML stylesheet to the XML page.
*
* @codingStandardsIgnoreStart
*/
public function writeXSL() {
$this->writePi('xml-stylesheet', 'type="text/xsl" href="' . $this->getSitemapUrl('sitemap.xsl', array('protocol_relative' => TRUE)) . '"');
// @codingStandardsIgnoreEnd
$this->writePi('xml-stylesheet', 'type="text/xsl" href="' . $this->getSitemapUrl('sitemap.xsl', array('absolute' => FALSE)) . '"');
$this->writeRaw(PHP_EOL);
}
@@ -93,10 +136,19 @@ class XMLSitemapWriter extends XMLWriter {
return $attributes;
}
/**
* Generate XML.
*
* @codingStandardsIgnoreStart
*/
public function generateXML() {
// @codingStandardsIgnoreEnd
return xmlsitemap_generate_chunk($this->sitemap, $this, $this->sitemap_page);
}
/**
* Start Element.
*/
public function startElement($name, $root = FALSE) {
parent::startElement($name);
@@ -111,9 +163,9 @@ class XMLSitemapWriter extends XMLWriter {
/**
* Write an full XML sitemap element tag.
*
* @param $name
* @param string $name
* The element name.
* @param $element
* @param array $element
* An array of the elements properties and values.
*/
public function writeSitemapElement($name, array &$element) {
@@ -152,14 +204,26 @@ class XMLSitemapWriter extends XMLWriter {
}
}
/**
* Get URI.
*
* @codingStandardsIgnoreStart
*/
public function getURI() {
// @codingStandardsIgnoreEnd
return $this->uri;
}
/**
* Get Count Sitemap Element.
*/
public function getSitemapElementCount() {
return $this->sitemapElementCount;
}
/**
* Document.
*/
public function endDocument() {
$return = parent::endDocument();
@@ -167,22 +231,34 @@ class XMLSitemapWriter extends XMLWriter {
throw new XMLSitemapGenerationException(t('Unknown error occurred while writing to file @file.', array('@file' => $this->uri)));
}
//if (xmlsitemap_var('gz')) {
// @code
// If (xmlsitemap_var('gz')) {
// $file_gz = $file . '.gz';
// file_put_contents($file_gz, gzencode(file_get_contents($file), 9));
//}
// }
// @endcode
return $return;
}
}
/**
* XML Sitemap Index Writer.
*/
class XMLSitemapIndexWriter extends XMLSitemapWriter {
protected $rootElement = 'sitemapindex';
function __construct(stdClass $sitemap, $page = 'index') {
/**
* Construct.
*/
public function __construct(stdClass $sitemap, $page = 'index') {
parent::__construct($sitemap, 'index');
}
/**
* Get Root Attributes.
*/
public function getRootAttributes() {
$attributes['xmlns'] = 'http://www.sitemaps.org/schemas/sitemap/0.9';
if (variable_get('xmlsitemap_developer_mode', 0)) {
@@ -195,7 +271,13 @@ class XMLSitemapIndexWriter extends XMLSitemapWriter {
return $attributes;
}
/**
* Generate XML.
*
* @codingStandardsIgnoreStart
*/
public function generateXML() {
// @codingStandardsIgnoreEnd
$lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);
for ($i = 1; $i <= $this->sitemap->chunks; $i++) {
@@ -207,6 +289,7 @@ class XMLSitemapIndexWriter extends XMLSitemapWriter {
$this->writeSitemapElement('sitemap', $element);
}
}
}
/**
@@ -285,7 +368,7 @@ function xmlsitemap_xmlsitemap_sitemap_operations() {
/**
* XML sitemap operation callback; regenerate sitemap files using the batch API.
*
* @param $smids
* @param array $smids
* An array of XML sitemap IDs.
*
* @see xmlsitemap_regenerate_batch()

View File

@@ -0,0 +1,76 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Recommended modules
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
The XML sitemap custom module, part of the XML sitemap
(https://www.drupal.org/project/xmlsitemap) package, adds user configurable
links to the sitemap. The XML sitemap module creates a sitemap that conforms to
the sitemaps.org specification. This helps search engines to more intelligently
crawl a website and keep their results up to date.
* For a full description of the module, visit
https://www.drupal.org/documentation/modules/xmlsitemap
* To submit bug reports and feature suggestions, or to track changes visit
https://www.drupal.org/project/issues/xmlsitemap
REQUIREMENTS
------------
This module requires the following module:
* XML sitemap - https://www.drupal.org/project/xmlsitemap
RECOMMENDED MODULES
-------------------
* Ctools - https://www.drupal.org/project/ctools
* RobotsTxt - https://www.drupal.org/project/robotstxt
* Site Verification - https://www.drupal.org/project/site_verify
* Browscap - https://www.drupal.org/project/browscap
* Vertical Tabs - https://www.drupal.org/project/vertical_tabs
INSTALLATION
------------
This is a submodule of the XML sitemap module. Install the XML sitemap module as
you would normally install a contributed Drupal module. Visit
https://www.drupal.org/node/895232 for further information.
CONFIGURATION
-------------
1. Install the XML sitemap module.
2. Enable the XML sitemap module.
3. To include custom links in the sitemap, enable the XML custom submodule.
4. Navigate to Administration > Configuration > Search > XML Sitemap.
5. Select on the Custom Links tab to add a custom link.
6. Enter the address and select Save.
7. Select on the XML sitemap vertical tab.
8. Select on the Rebuild Links tab in the upper right.
9. Select on "Rebuild sitemap" even if the message says that you do not need to.
10. Now you're taken back to the config page which shows you the link to your
XML sitemap which you can click and confirm that pages have been added.
MAINTAINERS
-----------
* Andrei Mateescu (amateescu) - https://www.drupal.org/u/amateescu
* Dave Reid - https://www.drupal.org/u/dave-reid
* Juampy NR (juampynr) - https://www.drupal.org/u/juampynr
* Tasya Rukmana (tadityar) - https://www.drupal.org/u/tadityar

View File

@@ -2,9 +2,12 @@
/**
* @file
* Administrative page callbacks for the xmlsitemap_custom module.
* Administrative page callbacks for the xmlsitemap_custom.
*/
/**
* List Links.
*/
function xmlsitemap_custom_list_links() {
$header = array(
'loc' => array('data' => t('Location'), 'field' => 'loc', 'sort' => 'asc'),
@@ -62,6 +65,9 @@ function xmlsitemap_custom_list_links() {
return $build;
}
/**
* Edit Link Form.
*/
function xmlsitemap_custom_edit_link_form($form, &$form_state, $link = array()) {
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
_xmlsitemap_set_breadcrumb('admin/config/search/xmlsitemap/custom');
@@ -116,7 +122,7 @@ function xmlsitemap_custom_edit_link_form($form, &$form_state, $link = array())
);
$form['actions'] = array(
'#type' => 'actions'
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
@@ -131,6 +137,9 @@ function xmlsitemap_custom_edit_link_form($form, &$form_state, $link = array())
return $form;
}
/**
* Edit Link Form Validate.
*/
function xmlsitemap_custom_edit_link_form_validate($form, &$form_state) {
$link = &$form_state['values'];
@@ -143,12 +152,16 @@ function xmlsitemap_custom_edit_link_form_validate($form, &$form_state) {
$menu_item = menu_get_item($link['loc']);
xmlsitemap_restore_user();
// Since the menu item access results are cached, manually check the current path.
// Since the menu item access results are cached, manually check the current
// path.
if ($menu_item && strpos($link['loc'], 'admin/config/search/xmlsitemap/custom') === 0 && !user_access('administer xmlsitemap', drupal_anonymous_user())) {
$menu_item['access'] = FALSE;
}
if (db_query_range("SELECT 1 FROM {xmlsitemap} WHERE type <> 'custom' AND loc = :loc AND status = 1 AND access = 1 AND language IN (:languages)", 0, 1, array(':loc' => $link['loc'], ':languages' => array(LANGUAGE_NONE, $link['language'])))->fetchField()) {
if (db_query_range("SELECT 1 FROM {xmlsitemap} WHERE type <> 'custom' AND loc = :loc AND status = 1 AND access = 1 AND language IN (:languages)", 0, 1, array(
':loc' => $link['loc'],
':languages' => array(LANGUAGE_NONE, $link['language']),
))->fetchField()) {
form_set_error('loc', t('There is already an existing link in the sitemap with the path %link.', array('%link' => $link['loc'])));
}
elseif (empty($menu_item['access']) && !is_readable('./' . $link['loc'])) {
@@ -158,6 +171,9 @@ function xmlsitemap_custom_edit_link_form_validate($form, &$form_state) {
}
}
/**
* Edit Link Form Submit.
*/
function xmlsitemap_custom_edit_link_form_submit($form, &$form_state) {
$link = $form_state['values'];
xmlsitemap_link_save($link);
@@ -165,8 +181,11 @@ function xmlsitemap_custom_edit_link_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/search/xmlsitemap/custom';
}
/**
* Delete Link Form.
*/
function xmlsitemap_custom_delete_link_form($form, &$form_state, array $link) {
// @todo Remove when http://drupal.org/node/576290 is fixed.
// @todo Remove when https://www.drupal.org/node/576290 is fixed.
_xmlsitemap_set_breadcrumb('admin/config/search/xmlsitemap/custom');
$form['#link'] = $link;
@@ -189,6 +208,9 @@ function xmlsitemap_custom_delete_link_form($form, &$form_state, array $link) {
);
}
/**
* Delete Link Form Submit.
*/
function xmlsitemap_custom_delete_link_form_submit($form, &$form_state) {
$link = $form_state['values']['link'];
xmlsitemap_link_delete('custom', $link['id']);

View File

@@ -3,15 +3,11 @@ description = Adds user configurable links to the sitemap.
package = XML sitemap
core = 7.x
dependencies[] = xmlsitemap
files[] = xmlsitemap_custom.module
files[] = xmlsitemap_custom.admin.inc
files[] = xmlsitemap_custom.install
files[] = xmlsitemap_custom.test
configure = admin/config/search/xmlsitemap/custom
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* Main file for XML sitemap Custom.
*/
/**
* Implements hook_menu().
*/
@@ -42,7 +47,7 @@ function xmlsitemap_custom_menu() {
/**
* Menu load callback; load a custom sitemap link from the {xmlsitemap} table.
*
* @param $id
* @param string $id
* The sitemap link ID of the custom link to load.
*
* @see xmlsitemap_link_load()

View File

@@ -2,10 +2,17 @@
/**
* @file
* Unit tests for the xmlsitemap_custom module.
* Unit tests for the xmlsitemap_custom.
*/
/**
* Class with Functional Test for XML Sitemap Custom.
*/
class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap custom interface tests',
@@ -14,7 +21,10 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_custom';
$modules[] = 'path';
parent::setUp($modules);
@@ -23,7 +33,10 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
$this->drupalLogin($this->admin_user);
}
function testCustomLinks() {
/**
* Test Custom Links.
*/
public function testCustomLinks() {
// Set a path alias for the node page.
$alias = array('source' => 'system/files', 'alias' => 'public-files');
path_save($alias);
@@ -57,7 +70,12 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
$links = xmlsitemap_link_load_multiple(array('type' => 'custom', 'loc' => 'system/files'));
$this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
$link = reset($links);
$this->assertSitemapLinkValues('custom', $link['id'], array('priority' => 0.5, 'changefreq' => 0, 'access' => 1, 'status' => 1));
$this->assertSitemapLinkValues('custom', $link['id'], array(
'priority' => 0.5,
'changefreq' => 0,
'access' => 1,
'status' => 1,
));
$this->clickLink('Edit');
$edit = array(
@@ -66,7 +84,12 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText('The custom link for system/files was saved');
$this->assertSitemapLinkValues('custom', $link['id'], array('priority' => 0.1, 'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS, 'access' => 1, 'status' => 1));
$this->assertSitemapLinkValues('custom', $link['id'], array(
'priority' => 0.1,
'changefreq' => XMLSITEMAP_FREQUENCY_ALWAYS,
'access' => 1,
'status' => 1,
));
$this->clickLink('Delete');
$this->drupalPost(NULL, array(), t('Delete'));
@@ -77,7 +100,7 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
/**
* Test adding files as custom links.
*/
function testCustomFileLinks() {
public function testCustomFileLinks() {
// Test an invalid file.
$edit['loc'] = $this->randomName();
$this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
@@ -85,11 +108,12 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
$this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
// Test an unaccessible file .
//$edit['loc'] = '.htaccess';
//$this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
//$this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
//$this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
// @codingStandardsIgnoreStart
// $edit['loc'] = '.htaccess';
// $this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
// $this->assertText(t('The custom link @link is either invalid or it cannot be accessed by anonymous users.', array('@link' => $edit['loc'])));
// $this->assertNoSitemapLink(array('type' => 'custom', 'loc' => $edit['loc']));
// @codingStandardsIgnoreEnd
// Test a valid file.
$edit['loc'] = 'misc/drupal.js';
$this->drupalPost('admin/config/search/xmlsitemap/custom/add', $edit, t('Save'));
@@ -104,4 +128,5 @@ class XMLSitemapCustomFunctionalTest extends XMLSitemapTestHelper {
$links = xmlsitemap_link_load_multiple(array('type' => 'custom', 'loc' => $edit['loc']));
$this->assertEqual(count($links), 1, t('Custom link saved in the database.'));
}
}

View File

@@ -0,0 +1,79 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Recommended modules
* Installation
* Configuration
* Troubleshooting
* Maintainers
INTRODUCTION
------------
The XML sitemap engines module, part of the XML sitemap
(https://www.drupal.org/project/xmlsitemap) package, uploads the sitemap to
search engines automatically. The XML sitemap module creates a sitemap that
conforms to the sitemaps.org specification. This helps search engines to more
intelligently crawl a website and keep their results up to date.
* For a full description of the module visit
https://www.drupal.org/documentation/modules/xmlsitemap
* To submit bug reports and feature suggestions, or to track changes visit
https://www.drupal.org/project/issues/xmlsitemap
REQUIREMENTS
------------
This module requires the following module:
* XML sitemap - https://www.drupal.org/project/xmlsitemap
RECOMMENDED MODULES
-------------------
* Ctools - https://www.drupal.org/project/ctools
* RobotsTxt - https://www.drupal.org/project/robotstxt
* Site Verification - https://www.drupal.org/project/site_verify
* Browscap - https://www.drupal.org/project/browscap
* Vertical Tabs - https://www.drupal.org/project/vertical_tabs
INSTALLATION
------------
This is a submodule of the XML sitemap module. Install the XML sitemap module
as you would normally install a contributed Drupal module. Visit
https://www.drupal.org/node/895232 for further information.
CONFIGURATION
-------------
1. Install the XML sitemap module.
2. Enable the XML sitemap module.
3. To upload sitemaps to the search engines and customize how often the sitemaps
should be uploaded, enable the XML sitemap engines module.
4. After building an XML sitemap, navigate to Administration > Configuration >
XML sitemap > Search Engines.
5. Choose which engines you wish to send the sitemap to by selecting the
appropriate checkboxes. Save configuration.
TROUBLESHOOTING
---------------
To verify the sitemaps ownership with search engines, be sure Cron is run
regularly.
MAINTAINERS
-----------
* Andrei Mateescu (amateescu) - https://www.drupal.org/u/amateescu
* Dave Reid - https://www.drupal.org/u/dave-reid
* Juampy NR (juampynr) - https://www.drupal.org/u/juampynr
* Tasya Rukmana (tadityar) - https://www.drupal.org/u/tadityar

View File

@@ -5,9 +5,25 @@
* Tests for the xmlsitemap_engines module.
*/
/**
* Functional Test.
*
* @codingStandardsIgnoreStart
*/
class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
/**
* Submit URL.
*
* @var string
*/
protected $submit_url;
/**
* Get Info.
*
* @codingStandardsIgnoreEnd
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap engines functional tests',
@@ -16,7 +32,10 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_engines';
$modules[] = 'xmlsitemap_engines_test';
parent::setUp($modules);
@@ -32,7 +51,10 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
}
function submitEngines() {
/**
* Submit Engines.
*/
public function submitEngines() {
variable_set('xmlsitemap_engines_submit_last', REQUEST_TIME - 10000);
variable_set('xmlsitemap_generated_last', REQUEST_TIME - 100);
variable_set('xmlsitemap_engines_minimum_lifetime', 0);
@@ -40,14 +62,23 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->assertTrue(variable_get('xmlsitemap_engines_submit_last', 0) > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines.');
}
function testPrepareURL() {
/**
* Test Prepare URL.
*
* @codingStandardsIgnoreStart
*/
public function testPrepareURL() {
// @codingStandardsIgnoreEnd
$sitemap = 'http://example.com/sitemap.xml';
$input = 'http://example.com/ping?sitemap=[sitemap]&foo=bar';
$output = 'http://example.com/ping?sitemap=http://example.com/sitemap.xml&foo=bar';
$this->assertEqual(xmlsitemap_engines_prepare_url($input, $sitemap), $output);
}
function testSubmitSitemaps() {
/**
* Test Submit Sitemaps.
*/
public function testSubmitSitemaps() {
$sitemaps = array();
$sitemap = new stdClass();
$sitemap->uri = array(
@@ -63,11 +94,26 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$sitemaps[] = $sitemap;
xmlsitemap_engines_submit_sitemaps($this->submit_url, $sitemaps);
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => 'http://example.com/sitemap.xml')));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => 'http://example.com/sitemap-2.xml')));
$this->assertWatchdogMessage(array(
'type' => 'xmlsitemap',
'message' => 'Recieved ping for @sitemap.',
'variables' => array(
'@sitemap' => 'http://example.com/sitemap.xml',
),
));
$this->assertWatchdogMessage(array(
'type' => 'xmlsitemap',
'message' => 'Recieved ping for @sitemap.',
'variables' => array(
'@sitemap' => 'http://example.com/sitemap-2.xml',
),
));
}
function testPing() {
/**
* Test Ping.
*/
public function testPing() {
$edit = array('xmlsitemap_engines_engines[simpletest]' => TRUE);
$this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
@@ -77,7 +123,13 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.'));
}
function testCustomURL() {
/**
* Test Custom URL.
*
* @codingStandardsIgnoreStart
*/
public function testCustomURL() {
// @codingStandardsIgnoreEnd
$edit = array('xmlsitemap_engines_custom_urls' => 'an-invalid-url');
$this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
$this->assertText('Invalid URL an-invalid-url.');
@@ -89,7 +141,14 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->assertText(t('The configuration options have been saved.'));
$this->submitEngines();
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.', 'variables' => array('%url' => $url, '@code' => '404')));
$this->assertWatchdogMessage(array(
'type' => 'xmlsitemap',
'message' => 'Submitted the sitemap to %url and received response @code.',
'variables' => array(
'%url' => $url,
'@code' => '404',
),
));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'No valid sitemap parameter provided.'));
$this->assertWatchdogMessage(array('type' => 'page not found', 'message' => 'ping'));
@@ -99,7 +158,23 @@ class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
$this->submitEngines();
$url = xmlsitemap_engines_prepare_url($this->submit_url, url('sitemap.xml', array('absolute' => TRUE)));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.', 'variables' => array('%url' => $url, '@code' => '200')));
$this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.', 'variables' => array('@sitemap' => url('sitemap.xml', array('absolute' => TRUE)))));
$this->assertWatchdogMessage(array(
'type' => 'xmlsitemap',
'message' => 'Submitted the sitemap to %url and received response @code.',
'variables' => array(
'%url' => $url,
'@code' => '200',
),
));
$this->assertWatchdogMessage(array(
'type' => 'xmlsitemap',
'message' => 'Recieved ping for @sitemap.',
'variables' => array(
'@sitemap' => url('sitemap.xml', array(
'absolute' => TRUE,
)),
),
));
}
}

View File

@@ -2,13 +2,10 @@ name = XML sitemap engines test
description = Support module for XML sitemap engines testing.
package = Testing
core = 7.x
files[] = xmlsitemap_engines_test.module
version = VERSION
hidden = TRUE
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -1,11 +1,17 @@
<?php
/**
* @file
* Unit tests for the XML sitemap engines project.
*/
/**
* Implements hook_menu().
*/
function xmlsitemap_engines_test_menu() {
$items['ping'] = array(
'page callback' => 'xmlsitemap_engines_test_pinged',
// @codingStandardsIgnoreLine
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
@@ -30,6 +36,9 @@ function xmlsitemap_engines_test_xmlsitemap_engine_info_alter(&$engines) {
$engines['simpletest']['url'] = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
}
/**
* Test pinged.
*/
function xmlsitemap_engines_test_pinged() {
if (empty($_GET['sitemap']) || !valid_url($_GET['sitemap'])) {
watchdog('xmlsitemap', 'No valid sitemap parameter provided.', array(), WATCHDOG_WARNING);

View File

@@ -26,7 +26,19 @@ function xmlsitemap_engines_settings_form() {
$form['xmlsitemap_engines_minimum_lifetime'] = array(
'#type' => 'select',
'#title' => t('Do not submit more often than every'),
'#options' => drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 604800 * 2, 604800 * 4), 'format_interval'),
'#options' => drupal_map_assoc(array(
3600,
10800,
21600,
32400,
43200,
86400,
172800,
259200,
604800,
604800 * 2,
604800 * 4,
), 'format_interval'),
'#default_value' => variable_get('xmlsitemap_engines_minimum_lifetime', 86400),
);
$form['xmlsitemap_engines_submit_updated'] = array(
@@ -37,7 +49,12 @@ function xmlsitemap_engines_settings_form() {
$form['xmlsitemap_engines_custom_urls'] = array(
'#type' => 'textarea',
'#title' => t('Custom submission URLs'),
'#description' => t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', array('%example-before' => 'http://example.com/ping?[sitemap]', '%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', url('sitemap.xml', array('absolute' => TRUE))))),
'#description' => t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', array(
'%example-before' => 'http://example.com/ping?[sitemap]',
'%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', url('sitemap.xml', array(
'absolute' => TRUE,
))),
)),
'#default_value' => variable_get('xmlsitemap_engines_custom_urls', ''),
'#rows' => 2,
'#wysiwyg' => FALSE,

View File

@@ -16,7 +16,7 @@
function hook_xmlsitemap_engine_info() {
$engines['example'] = array(
'name' => t('Example search engine'),
'url' => 'http://example.com/ping?sitemap=[sitemap]'
'url' => 'http://example.com/ping?sitemap=[sitemap]',
);
return $engines;
}

View File

@@ -3,16 +3,12 @@ description = Submit the sitemap to search engines.
package = XML sitemap
core = 7.x
dependencies[] = xmlsitemap
files[] = xmlsitemap_engines.module
files[] = xmlsitemap_engines.admin.inc
files[] = xmlsitemap_engines.install
files[] = tests/xmlsitemap_engines.test
recommends[] = site_verify
configure = admin/config/search/xmlsitemap/engines
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* Main file for XML sitemap engines.
*/
/**
* Implements hook_hook_info().
*/
@@ -21,7 +26,7 @@ function xmlsitemap_engines_help($path, $arg) {
switch ($path) {
case 'admin/config/search/xmlsitemap/engines':
if (!module_exists('site_verify')) {
$output .= '<p>' . t('In order to verify site ownership with the search engines listed below, it is highly recommended to download and install the <a href="@site-verify">Site verification module</a>.', array('@site-verify' => 'http://drupal.org/project/site_verify')) . '</p>';
$output .= '<p>' . t('In order to verify site ownership with the search engines listed below, it is highly recommended to download and install the <a href="@site-verify">Site verification module</a>.', array('@site-verify' => 'https://www.drupal.org/project/site_verify')) . '</p>';
}
break;
}
@@ -41,12 +46,13 @@ function xmlsitemap_engines_menu() {
'type' => MENU_LOCAL_TASK,
'file' => 'xmlsitemap_engines.admin.inc',
);
//$items['admin/config/search/xmlsitemap/engines/submit'] = array(
// 'page callback' => 'xmlsitemap_engines_submit',
// 'access callback' => 'xmlsitemap_engines_submit_access',
// 'type' => MENU_CALLBACK,
//);
// @code
// $items['admin/config/search/xmlsitemap/engines/submit'] = array(
// 'page callback' => 'xmlsitemap_engines_submit',
// 'access callback' => 'xmlsitemap_engines_submit_access',
// 'type' => MENU_CALLBACK,
// );
// @endcode
return $items;
}
@@ -59,6 +65,9 @@ function xmlsitemap_engines_cron() {
}
}
/**
* Check if can submit.
*/
function xmlsitemap_engines_can_submit() {
// Skip if the site is offline since search engines will not be able to
// access the site's content.
@@ -73,16 +82,21 @@ function xmlsitemap_engines_can_submit() {
return TRUE;
}
/**
* Submit access.
*/
function xmlsitemap_engines_submit_access() {
if (!xmlsitemap_engines_can_submit()) {
return FALSE;
}
// Allow manual submissions to run.
//if ($_GET['q'] == 'admin/config/search/xmlsitemap/engines/submit' && user_access('administer xmlsitemap')) {
// return TRUE;
//}
// @code
// @codingStandardsIgnoreLine
// if ($_GET['q'] == 'admin/config/search/xmlsitemap/engines/submit' && user_access('administer xmlsitemap')) {
// return TRUE;
// }
// @endcode
$submit_updated = variable_get('xmlsitemap_engines_submit_updated', TRUE);
$submitted_last = variable_get('xmlsitemap_engines_submit_last', 0);
$minimum_lifetime = variable_get('xmlsitemap_engines_minimum_lifetime', 86400);
@@ -103,7 +117,7 @@ function xmlsitemap_engines_submit_access() {
/**
* Submit the sitemaps to all the specified search engines.
*
* @param $smids
* @param array $smids
* An optional array of XML sitemap IDs. If not provided, it will load all
* existing XML sitemaps.
*/
@@ -134,9 +148,9 @@ function xmlsitemap_engines_submit_engines(array $smids = array()) {
/**
* Submit the sitemaps to a specific URL.
*
* @param $url
* @param string $url
* The URL for sitemap submission.
* @param $sitemaps
* @param array $sitemaps
* An array of URLs of the sitemaps to submit.
*/
function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) {
@@ -151,9 +165,10 @@ function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) {
/**
* Replace valid tokens in the URL with their appropriate values.
*
* @param $url
* @param string $url
* An un-tokenized URL.
* @return
*
* @return string
* A tokenized URL.
*/
function xmlsitemap_engines_prepare_url($url, $sitemap) {
@@ -163,12 +178,9 @@ function xmlsitemap_engines_prepare_url($url, $sitemap) {
/**
* Returns information about supported search engines.
*
* @param $engine
* @param string $engine
* (optional) The engine to return information for. If omitted, information
* for all engines is returned.
* @param $reset
* (optional) Boolean whether to reset the static cache and do nothing. Only
* used for tests.
*
* @see hook_xmlsitemap_engines_info()
* @see hook_xmlsitemap_engines_info_alter()
@@ -205,13 +217,13 @@ function xmlsitemap_engines_get_engine_info($engine = NULL) {
function xmlsitemap_engines_xmlsitemap_engine_info() {
$engines['google'] = array(
'name' => t('Google'),
'url' => 'http://www.google.com/webmasters/tools/ping?sitemap=[sitemap]',
'help url' => 'http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156184',
'url' => 'https://www.google.com/webmasters/tools/ping?sitemap=[sitemap]',
'help url' => 'https://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156184',
);
$engines['bing'] = array(
'name' => t('Bing'),
'url' => 'http://www.bing.com/webmaster/ping.aspx?siteMap=[sitemap]',
'help url' => 'http://www.bing.com/webmaster',
'url' => 'https://www.bing.com/webmaster/ping.aspx?siteMap=[sitemap]',
'help url' => 'https://www.bing.com/webmaster',
);
return $engines;
}

View File

@@ -4,12 +4,10 @@ package = XML sitemap
core = 7.x
dependencies[] = xmlsitemap
dependencies[] = i18n
files[] = xmlsitemap_i18n.module
files[] = xmlsitemap_i18n.test
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* Main file for XML sitemap i18n.
*/
/**
* Implements hook_xmlsitemap_context_info().
*/
@@ -88,14 +93,18 @@ function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface
// Current language and language neutral.
$query->condition('x.language', array($current, LANGUAGE_NONE));
break;
case 'mixed':
// Mixed current language (if available) or default language (if not) and language neutral.
// Mixed current language (if available) or default language (if not) and
// language neutral.
$query->condition('x.language', array($current, $default, LANGUAGE_NONE));
break;
case 'default':
// Only default language and language neutral.
$query->condition('x.language', array($default, LANGUAGE_NONE));
break;
case 'strict':
// Only current language (for nodes), simple for all other types.
$node_condition = db_and();
@@ -109,6 +118,7 @@ function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface
$condition->condition($normal_condition);
$query->condition($condition);
break;
case 'off':
// All content. No language conditions apply.
break;

View File

@@ -2,19 +2,29 @@
/**
* @file
* Unit tests for the xmlsitemap_i18n module.
* Unit tests for the xmlsitemap_i18n project.
*/
/**
* Common base test class for XML sitemap internationalization tests.
*/
class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
/**
* Admin User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $admin_user;
/**
* Set up an administrative user account and testing keys.
*
* @codingStandardsIgnoreEnd
*/
function setUp($modules = array()) {
public function setUp($modules = array()) {
// Call parent::setUp() allowing test cases to pass further modules.
$modules[] = 'locale';
$modules[] = 'translation';
@@ -29,7 +39,8 @@ class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
variable_set('language_negotiation', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
// Create the two different language-context sitemaps.
db_query("DELETE FROM {xmlsitemap_sitemap}");
db_delete('xmlsitemap_sitemap')->execute();
$sitemap = new stdClass();
$sitemap->context = array('language' => 'en');
xmlsitemap_sitemap_save($sitemap);
@@ -37,9 +48,17 @@ class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
$sitemap->context = array('language' => 'fr');
xmlsitemap_sitemap_save($sitemap);
}
}
/**
* I18n Test.
*/
class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap i18n tests',
@@ -49,7 +68,10 @@ class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
);
}
function testLanguageSelection() {
/**
* Language Selection.
*/
public function testLanguageSelection() {
// Create our three different language nodes.
$node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
$node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
@@ -104,9 +126,17 @@ class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
$this->assertRawSitemapLinks($node_fr, $link, $link_fr);
$this->assertNoRawSitemapLinks($node, $node_en, $link_en);
}
}
/**
* Node Test.
*/
class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap i18n node tests',
@@ -116,7 +146,10 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_node';
parent::setUp($modules);
@@ -125,7 +158,10 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
$this->drupalLogin($this->admin_user);
}
function testNodeLanguageData() {
/**
* Node Language Data.
*/
public function testNodeLanguageData() {
$node = $this->drupalCreateNode(array());
$this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'en'), t('Save'));
@@ -136,4 +172,5 @@ class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
$link = $this->assertSitemapLink('node', $node->nid);
$this->assertIdentical($link['language'], 'fr');
}
}

View File

@@ -0,0 +1,79 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Recommended modules
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
The XML sitemap menu module, part of the XML sitemap
(https://www.drupal.org/project/xmlsitemap) package, enables menu links to be on
the site map. The XML sitemap module creates a sitemap that conforms to the
sitemaps.org specification. This helps search engines to more intelligently
crawl a website and keep their results up to date.
* For a full description of the module visit
https://www.drupal.org/documentation/modules/xmlsitemap
* To submit bug reports and feature suggestions, or to track changes visit
https://www.drupal.org/project/issues/xmlsitemap
REQUIREMENTS
------------
This module requires the following module:
* XML sitemap - https://www.drupal.org/project/xmlsitemap
RECOMMENDED MODULES
-------------------
* Ctools - https://www.drupal.org/project/ctools
* RobotsTxt - https://www.drupal.org/project/robotstxt
* Site Verification - https://www.drupal.org/project/site_verify
* Browscap - https://www.drupal.org/project/browscap
* Vertical Tabs - https://www.drupal.org/project/vertical_tabs
INSTALLATION
------------
This is a submodule of the XML sitemap module. Install the XML sitemap module as
you would normally install a contributed Drupal module. Visit
https://www.drupal.org/node/895232 for further information.
CONFIGURATION
-------------
1. Install the XML sitemap module.
2. Enable the XML sitemap module.
3. To include menu items in the sitemap, enable the XML sitemap menu submodule.
4. Navigate to Administration > Configuration > Search > XML Sitemap.
5. Select the Settings tab and there will be a Menu link field set. Open.
6. Choose the menu link to be edited. There will now be a XML sitemap horizontal
tab. Under "Inclusion" change "Excluded" to become "Included". Select Save.
7. Once that is all complete, go to Configuration > Search and Metadata > XML
Sitemap.
8. Select the Rebuild Links tab in the upper right.
9. Select on "Rebuild sitemap" even if the message says that you do not need to.
10. Now you're taken back to the configuration page which shows you the link to
your XML sitemap which you can select and confirm that pages have been
added.
MAINTAINERS
-----------
* Andrei Mateescu (amateescu) - https://www.drupal.org/u/amateescu
* Dave Reid - https://www.drupal.org/u/dave-reid
* Juampy NR (juampynr) - https://www.drupal.org/u/juampynr
* Tasya Rukmana (tadityar) - https://www.drupal.org/u/tadityar

View File

@@ -4,13 +4,10 @@ package = XML sitemap
core = 7.x
dependencies[] = xmlsitemap
dependencies[] = menu
files[] = xmlsitemap_menu.module
files[] = xmlsitemap_menu.install
files[] = xmlsitemap_menu.test
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* Main file for XML sitemap menu.
*/
/**
* Implements hook_entity_info_alter().
*
@@ -54,6 +59,9 @@ function xmlsitemap_menu_entity_info_alter(&$info) {
'process callback' => 'xmlsitemap_menu_xmlsitemap_process_menu_links',
),
);
if (!isset($info['menu_link']['bundle label'])) {
$info['menu_link']['bundle label'] = t('Menu');
}
}
}
@@ -87,7 +95,7 @@ function xmlsitemap_menu_xmlsitemap_index_links($limit) {
/**
* Process menu sitemap links.
*
* @param $mlids
* @param array $mlids
* An array of menu link IDs.
*/
function xmlsitemap_menu_xmlsitemap_process_menu_links(array $mlids, array $xmlsitemap = array()) {
@@ -122,19 +130,23 @@ function xmlsitemap_menu_form_menu_edit_menu_alter(&$form, $form_state) {
xmlsitemap_add_link_bundle_settings($form, $form_state, 'menu_link', $menu);
}
//function xmlsitemap_menu_form_menu_overview_form_alter(&$form, $form_state) {
// $form['#submit'][] = 'xmlsitemap_menu_menu_overview_form_submit';
//}
//
//function xmlsitemap_menu_menu_overview_form_submit($form, $form_state) {
// $mlids = array();
// foreach (element_children($form) as $mlid) {
// if (isset($form[$mlid]['#item'])) {
// $mlids[] = $form[$mlid]['#item']['mlid'];
// }
// }
// xmlsitemap_menu_xmlsitemap_process_menu_links($mlids);
//}
/**
* Example functions.
*
* Function xmlsitemap_menu_form_menu_overview_form_alter(&$form, $form_state) {
* $form['#submit'][] = 'xmlsitemap_menu_menu_overview_form_submit';
* }
*
* Function xmlsitemap_menu_menu_overview_form_submit($form, $form_state) {
* $mlids = array();
* foreach (element_children($form) as $mlid) {
* if (isset($form[$mlid]['#item'])) {
* $mlids[] = $form[$mlid]['#item']['mlid'];
* }
* }
* xmlsitemap_menu_xmlsitemap_process_menu_links($mlids);
* }
*/
/**
* Implements hook_form_FORM_ID_alter().
@@ -202,8 +214,9 @@ function xmlsitemap_menu_menu_link_insert(array $link) {
* @see hook_menu_link_alter()
*/
function xmlsitemap_menu_menu_link_update(array $link) {
//$link += array('xmlsitemap' => array());
//xmlsitemap_menu_xmlsitemap_process_menu_links(array($link['mlid']), $link['xmlsitemap']);
// $link += array('xmlsitemap' => array());
// @codingStandardsIgnoreLine
// xmlsitemap_menu_xmlsitemap_process_menu_links(array($link['mlid']), $link['xmlsitemap']);.
}
/**
@@ -213,7 +226,7 @@ function xmlsitemap_menu_menu_link_update(array $link) {
* hook is not always called if the user does not edit the core menu item
* fields.
*
* @see http://drupal.org/node/1013856
* @see https://www.drupal.org/node/1013856
*/
function xmlsitemap_menu_menu_link_alter(array &$link) {
if (!empty($link['mlid'])) {
@@ -232,7 +245,7 @@ function xmlsitemap_menu_menu_link_delete(array $link) {
/**
* Create a sitemap link from a menu item.
*
* @param $menu_item
* @param array $menu_item
* A loaded menu item.
*/
function xmlsitemap_menu_create_link(array $menu_item) {
@@ -262,6 +275,19 @@ function xmlsitemap_menu_create_link(array $menu_item) {
$menu_item['xmlsitemap']['access'] = $menu_item['access'] && !$menu_item['external'] && !$menu_item['hidden'];
$menu_item['xmlsitemap']['language'] = isset($menu_item['options']['langcode']) ? $menu_item['options']['langcode'] : LANGUAGE_NONE;
// Exclude menu items created for nodes that are added by xmlsitemap_node.
if ($menu_item['xmlsitemap']['access'] && $menu_item['router_path'] == 'node/%' && module_exists('xmlsitemap_node')) {
$node = node_load(substr($menu_item['link_path'], 5));
if ($node) {
if (empty($node->xmlsitemap)) {
xmlsitemap_node_create_link($node);
}
if ($node->xmlsitemap['status'] && $node->xmlsitemap['access']) {
$menu_item['xmlsitemap']['status'] = FALSE;
}
}
}
return $menu_item['xmlsitemap'];
}

View File

@@ -2,13 +2,35 @@
/**
* @file
* Unit tests for the xmlsitemap_menu module.
* Unit tests for the xmlsitemap_menu project..
*/
/**
* Menu Functional Test.
*/
class XMLSitemapMenuFunctionalTest extends XMLSitemapTestHelper {
/**
* Normal User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $normal_user;
/**
* Menu Items.
*
* @var array
*/
protected $menu_items = array();
/**
* Get Info.
*
* @codingStandardsIgnoreEnd
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap menu',
@@ -17,7 +39,10 @@ class XMLSitemapMenuFunctionalTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_menu';
$modules[] = 'menu';
parent::setUp($modules);
@@ -26,7 +51,10 @@ class XMLSitemapMenuFunctionalTest extends XMLSitemapTestHelper {
$this->normal_user = $this->drupalCreateUser(array('access content'));
}
function testMenuSettings() {
/**
* Menu Settings.
*/
public function testMenuSettings() {
$this->drupalLogin($this->admin_user);
$edit = array(
@@ -36,7 +64,6 @@ class XMLSitemapMenuFunctionalTest extends XMLSitemapTestHelper {
'xmlsitemap[priority]' => '1.0',
);
$this->drupalPost('admin/structure/menu/add', $edit, 'Save');
$menu = menu_load($edit['menu_name']);
$this->clickLink('Add link');
$edit = array(
@@ -47,4 +74,5 @@ class XMLSitemapMenuFunctionalTest extends XMLSitemapTestHelper {
);
$this->drupalPost(NULL, $edit, 'Save');
}
}

View File

@@ -4,12 +4,10 @@ package = XML sitemap
core = 7.x
dependencies[] = xmlsitemap
dependencies[] = ctools
files[] = xmlsitemap_modal.module
hidden = TRUE
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -1,11 +1,16 @@
<?php
/**
* @file
* Main file for XML sitemap Modal.
*/
/**
* Implements hook_menu_alter().
*/
function xmlsitemap_modal_menu_alter(&$items) {
foreach ($items as $path => $item) {
if (!empty($item['modal']) && strpos($path, '%ctools_js') === FALSE && $item['page callback'] ==='drupal_get_form') {
if (!empty($item['modal']) && strpos($path, '%ctools_js') === FALSE && $item['page callback'] === 'drupal_get_form') {
$items["$path/%ctools_js"] = $item;
$items["$path/%ctools_js"]['page callback'] = 'xmlsitemap_modal_get_form';
$items["$path/%ctools_js"]['page arguments'][] = substr_count($path, '/') + 1;
@@ -73,7 +78,7 @@ function xmlsitemap_modal_xmlsitemap_operation_link_alter(array &$link) {
$link['href'] = trim($link['href'], '/');
}
// @todo Remove when http://drupal.org/node/565808 is fixed.
// @todo Remove when https://www.drupal.org/node/565808 is fixed.
if (substr($link['href'], -4) === 'nojs') {
$link['href'] .= '/';
}

View File

@@ -0,0 +1,81 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Recommended modules
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
The XML sitemap node module, part of the XML sitemap
(https://www.drupal.org/project/xmlsitemap) package, enables content nodes to
be in the sitemap. The XML sitemap module creates a sitemap that conforms to
the sitemaps.org specification. This helps search engines to more intelligently
crawl a website and keep their results up to date.
* For a full description of the module visit:
https://www.drupal.org/project/xmlsitemap
* To submit bug reports and feature suggestions, or to track changes visit:
https://www.drupal.org/project/issues/xmlsitemap
REQUIREMENTS
------------
This module requires the following modules:
* XML sitemap - (https://www.drupal.org/project/xmlsitemap)
RECOMMENDED MODULES
-------------------
* Ctools - (https://www.drupal.org/project/ctools)
* RobotsTxt - (https://www.drupal.org/project/robotstxt)
* Site Verification - (https://www.drupal.org/project/site_verify)
* Browscap - (https://www.drupal.org/project/browscap)
* Vertical Tabs - (https://www.drupal.org/project/vertical_tabs)
INSTALLATION
------------
* This is a submodule of the XML sitemap module. Install the XML sitemap module
as you would normally install a contributed Drupal module. Visit
https://www.drupal.org/node/895232 for further information.
CONFIGURATION
-------------
1. Install the XML sitemap module.
2. Enable the XML sitemap module.
3. To include nodes in the sitemap, enable the XML sitemap node submodule.
4. To add nodes to the sitemap, visit the Edit page of the Content Type which
you want to appear on the sitemap.
5. Select the XML sitemap horizontal tab.
6. Under "Inclusion" change "Excluded" to become "Included". Save.
7. If enabled, all content of the specific node type will be included.
Individual nodes can be excluded on their specific node edit page.
8. Once that is all complete, go to Configurations --> Search and Metadata -->
XML sitemap.
9. Select the Rebuild Links tab in the upper right.
10. Select on "Rebuild sitemap" even if the message says that you do not need
to.
11. Now you're taken back to the config page which shows you the link to your
XML sitemap which you can select and confirm that pages have been added.
MAINTAINERS
-----------
* Andrei Mateescu (amateescu) - https://www.drupal.org/u/amateescu
* Dave Reid - https://www.drupal.org/u/dave-reid
* Juampy NR (juampynr) - https://www.drupal.org/u/juampynr
* Tasya Rukmana (tadityar) - https://www.drupal.org/u/tadityar

View File

@@ -3,13 +3,10 @@ description = Adds content links to the sitemap.
package = XML sitemap
core = 7.x
dependencies[] = xmlsitemap
files[] = xmlsitemap_node.module
files[] = xmlsitemap_node.install
files[] = xmlsitemap_node.test
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* Default file for XML sitemap node.
*/
/**
* Implements hook_entity_info_alter().
*/
@@ -17,7 +22,32 @@ function xmlsitemap_node_entity_info_alter(array &$entity_info) {
* Process old nodes not found in the {xmlsitemap} table.
*/
function xmlsitemap_node_cron() {
xmlsitemap_node_xmlsitemap_index_links(xmlsitemap_var('batch_limit'));
$limit = xmlsitemap_var('batch_limit');
// Process nodes that have been queued in hook_node_update().
$queue = DrupalQueue::get('xmlsitemap_node');
while ($limit > 0 && $item = $queue->claimItem()) {
$limit--;
try {
$node = node_load($item->data);
// The node could have been deleted in the meantime, skip XML sitemap
// updates in this case.
if ($node) {
$link = xmlsitemap_node_create_link($node);
xmlsitemap_link_save($link, array($link['type'] => $node));
}
$queue->deleteItem($item);
}
catch (Exception $e) {
// In case of exception log it and leave the item in the queue
// to be processed again later.
watchdog_exception('xmlsitemap_node', $e);
}
}
// Add nodes that are missing from the {xmlsitemap} table.
// This catches nodes that were created prior to this module being enabled.
xmlsitemap_node_xmlsitemap_index_links($limit);
}
/**
@@ -33,14 +63,23 @@ function xmlsitemap_node_xmlsitemap_index_links($limit) {
/**
* Process node sitemap links.
*
* @param $nids
* @param array $nids
* An array of node IDs.
*/
function xmlsitemap_node_xmlsitemap_process_node_links(array $nids) {
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
$link = xmlsitemap_node_create_link($node);
xmlsitemap_link_save($link, array($link['type'] => $node));
// Load no more than 15 nodes at a time.
if (count($nids) >= 1) {
$nids_chunks = array_chunk($nids, 15);
foreach ($nids_chunks as $chunk) {
$nodes = node_load_multiple($chunk);
foreach ($nodes as $node) {
$link = xmlsitemap_node_create_link($node);
xmlsitemap_link_save($link, array($link['type'] => $node));
}
// Flush each entity from the load cache after processing, to avoid
// exceeding PHP memory limits if $nids is large.
entity_get_controller('node')->resetCache($chunk);
}
}
}
@@ -55,8 +94,15 @@ function xmlsitemap_node_node_insert(stdClass $node) {
* Implements hook_node_update().
*/
function xmlsitemap_node_node_update(stdClass $node) {
// Save a sitemap link with revoked access until the node permissions are
// checked in the cron.
$link = xmlsitemap_node_create_link($node);
xmlsitemap_link_save($link, array($link['type'] => $node));
xmlsitemap_link_presave($link, array($link['type'] => $node));
// Node access can not be accurately determined in hook_node_update() because
// node grants have not yet been written to the table, so we defer checking
// node access permissions and process the sitemap link during cron.
$queue = DrupalQueue::get('xmlsitemap_node');
$queue->createItem($node->nid);
}
/**
@@ -70,7 +116,7 @@ function xmlsitemap_node_node_delete(stdClass $node) {
* Implements hook_comment_update().
*/
function xmlsitemap_node_comment_update(stdClass $comment) {
if ($node = node_load($comment->nid, NULL, TRUE)) {
if ($node = entity_load_unchanged('node', $comment->nid)) {
xmlsitemap_node_node_update($node);
}
}
@@ -126,6 +172,8 @@ function xmlsitemap_node_form_node_type_form_alter(array &$form, array $form_sta
/**
* Implements hook_form_alter().
*
* @codingStandardsIgnoreLine
*
* Add the XML sitemap individual link options for a node.
*
* @see xmlsitemap_add_form_link_options()
@@ -140,9 +188,10 @@ function xmlsitemap_node_form_node_form_alter(array &$form, array &$form_state)
/**
* Fetch all the timestamps for when a node was changed.
*
* @param $node
* @param object $node
* A node object.
* @return
*
* @return array
* An array of UNIX timestamp integers.
*/
function xmlsitemap_node_get_timestamps(stdClass $node) {
@@ -164,7 +213,7 @@ function xmlsitemap_node_get_timestamps(stdClass $node) {
*
* The link will be saved as $node->xmlsitemap.
*
* @param $node
* @param object $node
* A node object.
*/
function xmlsitemap_node_create_link(stdClass $node) {
@@ -195,11 +244,6 @@ function xmlsitemap_node_create_link(stdClass $node) {
$node->xmlsitemap['changefreq'] = $node->nid ? xmlsitemap_calculate_changefreq($timestamps) : 0;
$node->xmlsitemap['changecount'] = $node->nid ? count($timestamps) - 1 : 0;
// Node access must be reset since it a user may have changed published status, etc.
//$access = &drupal_static('node_access');
//unset($access[0][$node->nid]);
//node_access_acquire_grants($node);
// The following values must always be checked because they are volatile.
$node->xmlsitemap['loc'] = $uri['path'];
$node->xmlsitemap['lastmod'] = count($timestamps) ? max($timestamps) : 0;
@@ -212,16 +256,18 @@ function xmlsitemap_node_create_link(stdClass $node) {
/**
* Determine whether a user may view the specified node.
*
* @param $node
* @param object $node
* The node object on which the operation is to be performed, or node type
* (e.g. 'forum') for "create" operation.
* @param $account
* @param object $account
* Optional, a user object representing the user for whom the operation is to
* be performed. Determines access for a user other than the current user.
* @return
*
* @return bool
* TRUE if the operation may be performed, FALSE otherwise.
*
* This is for all intesive purposes a copy of Drupal 7's node_access() function.
* This is for all intesive purposes a copy of Drupal 7's node_access()
* function.
*/
function xmlsitemap_node_view_access($node, $account = NULL) {
global $user;
@@ -241,8 +287,7 @@ function xmlsitemap_node_view_access($node, $account = NULL) {
// $node may be either an object or a node type. Since node types cannot be
// an integer, use either nid or type as the static cache id.
//$cid = is_object($node) ? $node->nid : $node;
// $cid = is_object($node) ? $node->nid : $node;
// If we've already checked access for this node, user and op, return from
// cache.
if (isset($rights[$account->uid][$node->nid])) {
@@ -294,7 +339,8 @@ function xmlsitemap_node_view_access($node, $account = NULL) {
$query->condition($nids);
$query->range(0, 1);
// Fetch the node grants and allow other modules to alter them (D7 backport).
// Fetch the node grants and allow other modules to alter them
// (D7 backport).
$grants = &drupal_static(__FUNCTION__ . ':grants', array());
if (!isset($grants[$account->uid][$op])) {
// Indicate that this is our special function in the grants.

View File

@@ -5,10 +5,30 @@
* Unit tests for the xmlsitemap_node module.
*/
/**
* Node Functional Test.
*/
class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
/**
* Normal User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $normal_user;
/**
* Nodes.
*
* @var array
*/
protected $nodes = array();
/**
* Get Info.
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap node',
@@ -17,21 +37,44 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_node';
$modules[] = 'comment';
parent::setUp($modules);
$this->admin_user = $this->drupalCreateUser(array('administer nodes', 'bypass node access', 'administer content types', 'administer xmlsitemap'));
$this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'access content', 'view own unpublished content'));
$this->admin_user = $this->drupalCreateUser(array(
'administer nodes',
'bypass node access',
'administer content types',
'administer xmlsitemap',
));
$this->normal_user = $this->drupalCreateUser(array(
'create page content',
'edit any page content',
'access content',
'view own unpublished content',
));
xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.5));
}
function testNodeSettings() {
/**
* Node Settings.
*/
public function testNodeSettings() {
$body_field = 'body[' . LANGUAGE_NONE . '][0][value]';
$node = $this->drupalCreateNode(array('status' => FALSE, 'uid' => $this->normal_user->uid));
$this->assertSitemapLinkValues('node', $node->nid, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0));
$this->cronRun();
$this->assertSitemapLinkValues('node', $node->nid, array(
'access' => 0,
'status' => 1,
'priority' => 0.5,
'status_override' => 0,
'priority_override' => 0,
));
$this->drupalLogin($this->normal_user);
$this->drupalGet('node/' . $node->nid . '/edit');
@@ -44,7 +87,14 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText('Basic page Test node title has been updated.');
$this->assertSitemapLinkValues('node', $node->nid, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0));
$this->cronRun();
$this->assertSitemapLinkValues('node', $node->nid, array(
'access' => 0,
'status' => 1,
'priority' => 0.5,
'status_override' => 0,
'priority_override' => 0,
));
$this->drupalLogin($this->admin_user);
$this->drupalGet('node/' . $node->nid . '/edit');
@@ -58,7 +108,14 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText('Basic page Test node title has been updated.');
$this->assertSitemapLinkValues('node', $node->nid, array('access' => 1, 'status' => 0, 'priority' => 0.9, 'status_override' => 1, 'priority_override' => 1));
$this->cronRun();
$this->assertSitemapLinkValues('node', $node->nid, array(
'access' => 1,
'status' => 0,
'priority' => 0.9,
'status_override' => 1,
'priority_override' => 1,
));
$edit = array(
'xmlsitemap[status]' => 'default',
@@ -67,16 +124,24 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText('Basic page Test node title has been updated.');
$this->assertSitemapLinkValues('node', $node->nid, array('access' => 0, 'status' => 1, 'priority' => 0.5, 'status_override' => 0, 'priority_override' => 0));
$this->cronRun();
$this->assertSitemapLinkValues('node', $node->nid, array(
'access' => 0,
'status' => 1,
'priority' => 0.5,
'status_override' => 0,
'priority_override' => 0,
));
}
/**
* Test the content type settings.
*/
function testTypeSettings() {
public function testTypeSettings() {
$this->drupalLogin($this->admin_user);
$node_old = $this->drupalCreateNode();
$this->cronRun();
$this->assertSitemapLinkValues('node', $node_old->nid, array('status' => 1, 'priority' => 0.5));
$edit = array(
@@ -87,6 +152,7 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
$this->assertText('The content type Basic page has been updated.');
$node = $this->drupalCreateNode();
$this->cronRun();
$this->assertSitemapLinkValues('node', $node->nid, array('status' => 0, 'priority' => 0.0));
$this->assertSitemapLinkValues('node', $node_old->nid, array('status' => 0, 'priority' => 0.0));
@@ -98,9 +164,18 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->assertText('Changed the content type of 2 posts from page to page2.');
$this->assertText('The content type Basic page has been updated.');
$this->cronRun();
$this->assertSitemapLinkValues('node', $node->nid, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5));
$this->assertSitemapLinkValues('node', $node_old->nid, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5));
$this->assertSitemapLinkValues('node', $node->nid, array(
'subtype' => 'page2',
'status' => 1,
'priority' => 0.5,
));
$this->assertSitemapLinkValues('node', $node_old->nid, array(
'subtype' => 'page2',
'status' => 1,
'priority' => 0.5,
));
$this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page'))), 0);
$this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page2'))), 2);
@@ -112,7 +187,7 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
/**
* Test the import of old nodes via cron.
*/
function testCron() {
public function testCron() {
$limit = 5;
variable_set('xmlsitemap_batch_limit', $limit);
@@ -127,17 +202,21 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
// Clear all the node link data so we can emulate 'old' nodes.
db_delete('xmlsitemap')
->condition('type', 'node')
->execute();
->condition('type', 'node')
->execute();
// Run cron to import old nodes.
xmlsitemap_node_cron();
for ($i = 1; $i <= ($limit + 1); $i++) {
$node = array_pop($nodes);
$node = array_shift($nodes);
if ($i <= $limit) {
// The first $limit nodes should be inserted.
$this->assertSitemapLinkValues('node', $node->nid, array('access' => 1, 'status' => 1, 'lastmod' => $node->changed));
$this->assertSitemapLinkValues('node', $node->nid, array(
'access' => 1,
'status' => 1,
'lastmod' => $node->changed,
));
}
else {
// Any beyond $limit should not be in the sitemap.
@@ -145,4 +224,5 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapTestHelper {
}
}
}
}

View File

@@ -0,0 +1,83 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Recommended modules
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
The XML sitemap taxonomy module, part of the XML sitemap
(https://www.drupal.org/project/xmlsitemap) package, adds taxonomy term links
to the sitemap. The XML sitemap module creates a sitemap that conforms to the
sitemaps.org specification. This helps search engines to more intelligently
crawl a website and keep their results up to date.
* For a full description of the module visit
https://www.drupal.org/documentation/modules/xmlsitemap
* To submit bug reports and feature suggestions, or to track changes visit
https://www.drupal.org/project/issues/xmlsitemap
REQUIREMENTS
------------
This module requires the following modules:
XML sitemap - (https://www.drupal.org/project/xmlsitemap)
RECOMMENDED MODULES
-------------------
* Ctools - (https://www.drupal.org/project/ctools)
* RobotsTxt - (https://www.drupal.org/project/robotstxt)
* Site Verification - (https://www.drupal.org/project/site_verify)
* Browscap - (https://www.drupal.org/project/browscap)
* Vertical Tabs - (https://www.drupal.org/project/vertical_tabs)
INSTALLATION
------------
This is a submodule of the XML sitemap module. Install the XML sitemap module as
you would normally install a contributed Drupal module. Visit
https://www.drupal.org/node/895232 for more information.
CONFIGURATION
-------------
1. Install the XML sitemap module.
2. Enable the XML sitemap module.
3. To include taxonomy terms in the sitemap, enable the XML sitemap taxonomy
submodule.
4. Navigate to Administration > Structure > Taxonomy.
5. To include a whole vocabulary in the sitemap, click "edit vocabulary".
Select the XML sitemap field set. Under "Inclusion" change "Excluded" to
become "Included". Save.
6. To include a single vocabulary term in the sitemap, select edit vocabulary.
Select the vocabulary term to be included. Select the XML sitemap field set.
Under "Inclusion" change "Excluded" to become "Included". Save.
7. Once that is all complete, go to Configurations > Search and Metadata > XML
Sitemap.
8. Select the Rebuild Links tab in the upper right.
9. Select "Rebuild sitemap" even if the message says that you do not need to.
10. Now you're taken back to the configuration page which shows you the link to
your XML sitemap which you can click and confirm that pages have been added.
MAINTAINERS
-----------
* Andrei Mateescu (amateescu) - https://www.drupal.org/u/amateescu
* Renato Gonçalves (RenatoG) - https://www.drupal.org/u/RenatoG
* Dave Reid - https://www.drupal.org/u/dave-reid
* Juampy NR (juampynr) - https://www.drupal.org/u/juampynr
* Tasya Rukmana (tadityar) - https://www.drupal.org/u/tadityar

View File

@@ -4,13 +4,10 @@ package = XML sitemap
core = 7.x
dependencies[] = xmlsitemap
dependencies[] = taxonomy
files[] = xmlsitemap_taxonomy.module
files[] = xmlsitemap_taxonomy.install
files[] = xmlsitemap_taxonomy.test
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -2,7 +2,7 @@
/**
* @file
* Install and uninstall schema and functions for the xmlsitemap_taxonomy module.
* Install and uninstall schema and functions for the xmlsitemap_taxonomy.
*/
/**

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* Main file for XML sitemap taxonomy.
*/
/**
* Implements hook_entity_info_alter().
*/
@@ -43,7 +48,7 @@ function xmlsitemap_taxonomy_xmlsitemap_index_links($limit) {
/**
* Process taxonomy term sitemap links.
*
* @param $tids
* @param array $tids
* An array of taxonomy term IDs.
*/
function xmlsitemap_taxonomy_xmlsitemap_process_taxonomy_term_links(array $tids) {
@@ -103,7 +108,7 @@ function xmlsitemap_taxonomy_vocabulary_update(stdClass $vocabulary) {
}
/**
* Implements hook_taxonomy_term_insert() {
* Implements hook_taxonomy_term_insert().
*/
function xmlsitemap_taxonomy_term_insert(stdClass $term) {
$link = xmlsitemap_taxonomy_create_link($term);
@@ -111,7 +116,7 @@ function xmlsitemap_taxonomy_term_insert(stdClass $term) {
}
/**
* Implements hook_taxonomy_term_update() {
* Implements hook_taxonomy_term_update().
*/
function xmlsitemap_taxonomy_term_update(stdClass $term) {
$link = xmlsitemap_taxonomy_create_link($term);
@@ -119,7 +124,7 @@ function xmlsitemap_taxonomy_term_update(stdClass $term) {
}
/**
* Implements hook_taxonomy_term_delete() {
* Implements hook_taxonomy_term_delete().
*/
function xmlsitemap_taxonomy_term_delete(stdClass $term) {
xmlsitemap_link_delete('taxonomy_term', $term->tid);
@@ -143,9 +148,10 @@ function xmlsitemap_taxonomy_field_extra_fields() {
/**
* Create a sitemap link from a taxonomy term.
*
* @param $term
* @param object $term
* A taxonomy term object.
* @return
*
* @return array
* An array representing a sitemap link.
*/
function xmlsitemap_taxonomy_create_link(stdClass &$term) {
@@ -182,20 +188,22 @@ function xmlsitemap_taxonomy_create_link(stdClass &$term) {
/**
* Calculate the priority of a taxonomy term based on depth and weight.
*
* Function xmlsitemap_taxonomy_calculate_term_priority(stdClass $term) {
* // Calculate priority.
* // Min weight = -128
* // Max weight = 127
* // Max depth = ?
* }
*/
//function xmlsitemap_taxonomy_calculate_term_priority(stdClass $term) {
// // Calculate priority.
// // Min weight = -128
// // Max weight = 127
// // Max depth = ?
//}
/**
* Find the tree depth of a taxonomy term.
*
* @param $term
* @param object $term
* A taxonomy term object.
* @return
*
* @return array
* The tree depth of the term.
*/
function xmlsitemap_taxonomy_get_term_depth(stdClass $term) {
@@ -221,12 +229,16 @@ function xmlsitemap_taxonomy_get_term_depth(stdClass $term) {
/**
* Find the number of nodes that are associated with a taxonomy term.
*
* @param $term
* @param obejct $term
* A taxonomy term object.
* @return
*
* @return int
* The number of nodes associated with the term.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_taxonomy_get_node_count(stdClass $term) {
// @codingStandardsIgnoreEnd
// @todo Use db_rewrite_sql() w/ switch user.
return db_query_range("SELECT COUNT(ti.nid) FROM {taxonomy_index} ti LEFT JOIN {node n} USING (nid) WHERE ti.tid = :tid AND n.status = 1", 0, 1, array(':tid' => $term->tid))->fetchField();
}
@@ -234,7 +246,7 @@ function xmlsitemap_taxonomy_get_node_count(stdClass $term) {
/**
* Implements hook_entity_query_alter().
*
* @todo Remove when http://drupal.org/node/1054162 is fixed.
* @todo Remove when https://www.drupal.org/node/1054162 is fixed.
*/
function xmlsitemap_taxonomy_entity_query_alter($query) {
$conditions = &$query->entityConditions;
@@ -243,7 +255,13 @@ function xmlsitemap_taxonomy_entity_query_alter($query) {
if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'taxonomy_term' && isset($conditions['bundle'])) {
// We can only support the operators that are explicit in values.
if (in_array($conditions['bundle']['operator'], array(NULL, '=', '!=', 'IN', 'NOT IN'))) {
if (in_array($conditions['bundle']['operator'], array(
NULL,
'=',
'!=',
'IN',
'NOT IN',
))) {
$vids = array();
// Convert vocabulary machine names to vocabulary IDs.

View File

@@ -5,10 +5,32 @@
* Unit tests for the xmlsitemap_taxonomy module.
*/
/**
* Functional Test.
*/
class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
/**
* Normal User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $normal_user;
/**
* Terms.
*
* @var array
*/
protected $terms = array();
/**
* Get Info.
*
* @codingStandardsIgnoreEnd
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap taxonomy',
@@ -17,7 +39,10 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* SetUp.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_taxonomy';
$modules[] = 'taxonomy';
parent::setUp($modules);
@@ -26,7 +51,10 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
$this->normal_user = $this->drupalCreateUser(array('access content'));
}
function testTaxonomySettings() {
/**
* TaxonomySettings.
*/
public function testTaxonomySettings() {
$this->drupalLogin($this->admin_user);
$edit = array(
@@ -46,4 +74,5 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
);
$this->drupalPost("admin/structure/taxonomy/{$vocabulary->machine_name}/add", $edit, 'Save');
}
}

View File

@@ -0,0 +1,82 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Recommended modules
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
The XML sitemap user module, part of the XML sitemap
(https://www.drupal.org/project/xmlsitemap) package, adds user profiles to the
site map. The XML sitemap module creates a sitemap that conforms to the
sitemaps.org specification. This helps search engines to more intelligently
crawl a website and keep their results up to date.
* For a full description of the module visit
https://www.drupal.org/documentation/modules/xmlsitemap
* To submit bug reports and feature suggestions, or to track changes visit
https://www.drupal.org/project/issues/xmlsitemap
REQUIREMENTS
------------
This module requires the following module:
* XML sitemap - https://www.drupal.org/project/xmlsitemap
RECOMMENDED MODULES
-------------------
* Ctools - https://www.drupal.org/project/ctools
* RobotsTxt - https://www.drupal.org/project/robotstxt
* Site Verification - https://www.drupal.org/project/site_verify
* Browscap - https://www.drupal.org/project/browscap
* Vertical Tabs - https://www.drupal.org/project/vertical_tabs
INSTALLATION
------------
This is a submodule of the XML sitemap module. Install the XML sitemap module as
you would normally install a contributed Drupal module. Visit
https://www.drupal.org/node/895232 for further information.
CONFIGURATION
-------------
1. Install the XML sitemap module.
2. Enable the XML sitemap module.
3. To include users in the sitemap, enable the XML sitemap user submodule.
4. To add individuals user to the site map navigate to Administration > People
and select edit on the user to be included in the sitemap.
5. Select the XML sitemap fieldset.
6. Under "Inclusion" change "Excluded" to become "Included". Save.
7. Once that is complete, navigate to Configurations > Search and Metadata > XML
Sitemap.
8. Select the Rebuild Links tab in the upper right.
9. Select "Rebuild sitemap" even if the message says that you do not need to.
10. Now you're taken back to the config page which shows you the link to your
XML sitemap which you can select and confirm that pages have been added.
TROUBLESHOOTING
---------------
In order to list user profiles in the site map, the anonymous user must have the
View user profiles permission.
MAINTAINERS
-----------
* Andrei Mateescu (amateescu) - https://www.drupal.org/u/amateescu
* Dave Reid - https://www.drupal.org/u/dave-reid
* Juampy NR (juampynr) - https://www.drupal.org/u/juampynr
* Tasya Rukmana (tadityar) - https://www.drupal.org/u/tadityar

View File

@@ -3,13 +3,10 @@ description = Adds user profile links to the sitemap.
package = XML sitemap
dependencies[] = xmlsitemap
core = 7.x
files[] = xmlsitemap_user.module
files[] = xmlsitemap_user.install
files[] = xmlsitemap_user.test
; Information added by Drupal.org packaging script on 2016-05-25
version = "7.x-2.3"
; Information added by Drupal.org packaging script on 2018-10-09
version = "7.x-2.6"
core = "7.x"
project = "xmlsitemap"
datestamp = "1464191061"
datestamp = "1539120486"

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* Default file for XML sitemap user.
*/
/**
* Implements hook_entity_info_alter().
*/
@@ -30,7 +35,7 @@ function xmlsitemap_user_xmlsitemap_index_links($limit) {
/**
* Process user sitemap links.
*
* @param $uids
* @param array $uids
* An array of user IDs.
*/
function xmlsitemap_user_xmlsitemap_process_user_links(array $uids) {
@@ -120,7 +125,7 @@ function xmlsitemap_user_form_user_admin_settings_alter(&$form, $form_state) {
*
* The link will be saved as $account->xmlsitemap.
*
* @param $account
* @param object $account
* A user object.
*/
function xmlsitemap_user_create_link(stdClass &$account) {
@@ -155,7 +160,7 @@ function xmlsitemap_user_create_link(stdClass &$account) {
}
/**
* Implementation of hook_variables().
* Implements hook_variables().
*/
function xmlsitemap_user_variables() {
$defaults = array();

View File

@@ -5,10 +5,32 @@
* Unit tests for the xmlsitemap_user module.
*/
/**
* Tests for User Functional.
*/
class XMLSitemapUserFunctionalTest extends XMLSitemapTestHelper {
/**
* Normal User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $normal_user;
/**
* Accounts.
*
* @var array
*/
protected $accounts = array();
/**
* Get Info.
*
* @codingStandardsIgnoreEnd
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap user',
@@ -17,15 +39,23 @@ class XMLSitemapUserFunctionalTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* Setup.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_user';
parent::setUp($modules);
// Save the user settings before creating the users.
xmlsitemap_link_bundle_settings_save('user', 'user', array('status' => 1, 'priority' => 0.5));
// Create the users
$this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions', 'administer xmlsitemap'));
// Create the users.
$this->admin_user = $this->drupalCreateUser(array(
'administer users',
'administer permissions',
'administer xmlsitemap',
));
$this->normal_user = $this->drupalCreateUser(array('access content'));
// Update the normal user to make its sitemap link visible.
@@ -33,7 +63,10 @@ class XMLSitemapUserFunctionalTest extends XMLSitemapTestHelper {
user_save($account, array('access' => 1, 'login' => 1));
}
function testBlockedUser() {
/**
* Blocked User().
*/
public function testBlockedUser() {
$this->drupalLogin($this->admin_user);
$this->assertSitemapLinkVisible('user', $this->normal_user->uid);
@@ -42,9 +75,10 @@ class XMLSitemapUserFunctionalTest extends XMLSitemapTestHelper {
'status' => 0,
);
// This will pass when http://drupal.org/node/360925 is fixed.
// This will pass when https://www.drupal.org/node/360925 is fixed.
$this->drupalPost('user/' . $this->normal_user->uid . '/edit', $edit, t('Save'));
$this->assertText('The changes have been saved.');
$this->assertSitemapLinkNotVisible('user', $this->normal_user->uid);
}
}

View File

@@ -12,6 +12,8 @@
*
*/
/**
*
* @codingStandardsIgnoreFile Ignore because it's code from another project.
*
* @description Create a sortable table with multi-column sorting capabilitys
*

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2010 Dave Reid <http://drupal.org/user/53892>
<!-- Copyright (c) 2010 Dave Reid <https://www.drupal.org/user/53892>
This file is free software: you may copy, redistribute and/or modify it
under the terms of the GNU General Public License as published by the
@@ -55,7 +56,7 @@
</xsl:choose>
<div id="footer">
<p>Generated by the <a href="http://drupal.org/project/xmlsitemap">Drupal XML sitemap module</a>.</p>
<p>Generated by the <a href="https://www.drupal.org/project/xmlsitemap">Drupal XML sitemap</a>.</p>
</div>
</body>
</html>

View File

@@ -1,6 +1,5 @@
body {
background-color: #FFF;
background-color: #fff;
font-family: Verdana,sans-serif;
font-size: 10pt;
}
@@ -8,15 +7,16 @@ h1 {
font-size: 1.25em;
}
table.tablesorter {
background-color: #CDCDCD;
margin:10px 0pt 15px;
background-color: #cdcdcd;
margin: 10px 0pt 15px;
font-size: 8pt;
width: 100%;
text-align: left;
}
table.tablesorter thead tr th, table.tablesorter tfoot tr th {
background-color: #E6EEEE;
border: 1px solid #FFF;
table.tablesorter thead tr th,
table.tablesorter tfoot tr th {
background-color: #e6eeee;
border: 1px solid #fff;
font-size: 8pt;
padding: 3px;
}
@@ -24,13 +24,13 @@ table.tablesorter thead tr .header {
cursor: pointer;
}
table.tablesorter tbody td {
color: #3D3D3D;
color: #3d3d3d;
padding: 3px;
background-color: #FFF;
background-color: #fff;
vertical-align: top;
}
table.tablesorter tbody tr.odd td {
background-color: #EFEFEF;
background-color: #efefef;
}
table.tablesorter thead tr .headerSortUp {
background: url(/misc/arrow-asc.png) no-repeat center right;
@@ -38,8 +38,9 @@ table.tablesorter thead tr .headerSortUp {
table.tablesorter thead tr .headerSortDown {
background: url(/misc/arrow-desc.png) no-repeat center right;
}
table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
background-color: #5050D3;
color: #FFF;
table.tablesorter thead tr .headerSortDown,
table.tablesorter thead tr .headerSortUp {
background-color: #5050d3;
color: #fff;
font-style: italic;
}