Commit a5c06c46 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Fixed maximum file size requirements check and added lastmod date format option.

parent 0cc3d63c
......@@ -46,7 +46,7 @@ function xmlsitemap_settings_form() {
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => !variable_get('xmlsitemap_developer_mode', FALSE),
'#collapsed' => !variable_get('xmlsitemap_developer_mode', 0),
'#weight' => 10,
);
//$form['advanced']['xmlsitemap_gz'] = array(
......@@ -92,11 +92,22 @@ function xmlsitemap_settings_form() {
'#description' => t('This is the base URL for links generated in the sitemap.'),
'#required' => TRUE,
);
$form['advanced']['xmlsitemap_lastmod_format'] = array(
'#type' => 'select',
'#title' => t('Last modification date format'),
'#options' => array(
'Y-m-d' => t('Short'),
DATE_W3C => t('Long'),
),
'#default_value' => DATE_W3C,
);
foreach ($form['advanced']['xmlsitemap_lastmod_format']['#options'] as $key => &$label) {
$label .= ' (' . gmdate($key, REQUEST_TIME) . ')';
}
$form['advanced']['xmlsitemap_developer_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Enable developer mode.'),
'#default_value' => variable_get('xmlsitemap_developer_mode', FALSE),
'#description' => t('Exposes additional settings intended for development.'),
'#title' => t('Enable developer mode to expose additional settings.'),
'#default_value' => variable_get('xmlsitemap_developer_mode', 0),
);
$form['xmlsitemap_settings'] = array(
......@@ -230,8 +241,8 @@ function xmlsitemap_rebuild_form() {
'#description' => t('If no link types are selected, the sitemap files will just be regenerated.'),
'#multiple' => TRUE,
'#options' => $options,
'#default_value' => xmlsitemap_var('rebuild_needed') || !xmlsitemap_var('developer_mode') ? array_keys($options) : array(),
'#access' => xmlsitemap_var('developer_mode'),
'#default_value' => variable_get('xmlsitemap_rebuild_needed', FALSE) || !variable_get('xmlsitemap_developer_mode', 0) ? array_keys($options) : array(),
'#access' => variable_get('xmlsitemap_developer_mode', 0),
);
$form['save_custom'] = array(
'#type' => 'checkbox',
......
......@@ -85,8 +85,8 @@ function _xmlsitemap_regenerate_before() {
xmlsitemap_check_directory();
// Clear the maximum chunk and file size variables.
variable_set('xmlsitemap_maximum_chunks', 0);
variable_set('xmlsitemap_maximum_filesize', 0);
variable_set('xmlsitemap_max_chunks', 0);
variable_set('xmlsitemap_max_filesize', 0);
}
function _xmlsitemap_get_memory_usage($start = FALSE) {
......@@ -257,8 +257,8 @@ function xmlsitemap_generate_chunk_header($type, $handle, &$status, $language) {
*/
function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
$last_url = '';
$url_options = xmlsitemap_get_url_options(array('alias' => TRUE));
$lastmod_format = variable_get('xmlsitemap_lastmod_format', DATE_W3C);
$query = db_select('xmlsitemap', 'x');
$query->fields('x', array('loc', 'lastmod', 'changefreq', 'changecount', 'priority', 'language', 'access', 'status'));
......@@ -295,7 +295,7 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
$link_output = '<url><loc>' . $link_url . '</loc>';
if ($link['lastmod']) {
$link_output .= '<lastmod>' . gmdate(DATE_W3C, $link['lastmod']) . '</lastmod>';
$link_output .= '<lastmod>' . gmdate($lastmod_format, $link['lastmod']) . '</lastmod>';
// If the link has a lastmod value, update the changefreq so that links
// with a short changefreq but updated two years ago show decay.
// We use abs() here just incase items were created on this same cron run
......@@ -333,6 +333,7 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
function xmlsitemap_generate_index($handle, &$status, $language) {
$url_options = xmlsitemap_get_url_options(array('language' => $language, 'alias' => TRUE));
$chunk_count = xmlsitemap_get_chunk_count(TRUE);
$lastmod_format = variable_get('xmlsitemap_lastmod_format', DATE_W3C);
// Add the XML header and XSL if desired.
xmlsitemap_generate_chunk_header('sitemapindex', $handle, $status, $language);
......@@ -341,7 +342,7 @@ function xmlsitemap_generate_index($handle, &$status, $language) {
$output = '<sitemap>';
$output .= '<loc>' . url('sitemap-' . $i . '.xml', $url_options) . '</loc>';
// @todo Use the actual lastmod value of the chunk file.
$output .= '<lastmod>' . gmdate(DATE_W3C, REQUEST_TIME) . '</lastmod>';
$output .= '<lastmod>' . gmdate($lastmod_format, REQUEST_TIME) . '</lastmod>';
$output .= '</sitemap>' . PHP_EOL;
$status &= (bool) fwrite($handle, $output);
}
......
......@@ -61,14 +61,19 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_chunk_count']['description'] .= ' ' . t('Please increase the number of links per page.');
}
}
// Check maximum file size.
$max_filesize = variable_get('xmlsitemap_max_filesize', 0);
$requirements['xmlsitemap_file_size'] = array(
'title' => $t('XML sitemap maximum file size'),
'value' => format_size($max_filesize),
);
if ($max_filesize > XMLSITEMAP_MAX_SITEMAP_FILESIZE) {
$requirements['xmlsitemap_file_size'] = array(
'title' => $t('XML sitemap file_size'),
'value' => format_size($max_filesize),
'description' => $t('You have exceeded the maximum sitemap file size of @size. If possible, decrease the number of links per sitemap page.', array('@size' => format_size(XMLSITEMAP_MAX_SITEMAP_FILESIZE))),
'severity' => REQUIREMENT_ERROR,
);
$requirements['xmlsitemap_file_size']['description'] = $t('You have exceeded the maximum sitemap file size of @size. If possible, decrease the number of links per sitemap page.', array('@size' => format_size(XMLSITEMAP_MAX_SITEMAP_FILESIZE)));
$requirements['xmlsitemap_file_size']['severity'] = REQUIREMENT_ERROR;
}
elseif (!variable_get('xmlsitemap_developer_mode', 0)) {
unset($requirements['xmlsitemap_file_size']);
}
// Check when the cached files were last generated.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment