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

@@ -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();