Commit 28ea81cd authored by RenatoG's avatar RenatoG Committed by RenatoG

Issue #2906673 by RenatoG: Fix Drupal Sniffer and Best Practices for XML sitemap Main files

parent 27d8fc6f
...@@ -35,8 +35,8 @@ function xmlsitemap_sitemap_list_form() { ...@@ -35,8 +35,8 @@ function xmlsitemap_sitemap_list_form() {
$form['operations']['submit'] = array( $form['operations']['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Update'), '#value' => t('Update'),
//'#validate' => array('xmlsitemap_sitemap_list_form_validate'), // '#validate' => array('xmlsitemap_sitemap_list_form_validate'),
//'#submit' => array('xmlsitemap_sitemap_list_form_submit'), // '#submit' => array('xmlsitemap_sitemap_list_form_submit'),.
); );
$contexts = xmlsitemap_get_context_info(); $contexts = xmlsitemap_get_context_info();
...@@ -82,8 +82,7 @@ function xmlsitemap_sitemap_list_form() { ...@@ -82,8 +82,7 @@ function xmlsitemap_sitemap_list_form() {
$options[$smid]['chunks'] = $sitemap->updated ? $sitemap->chunks : '-'; $options[$smid]['chunks'] = $sitemap->updated ? $sitemap->chunks : '-';
// @todo Highlight sitemaps that need updating. // @todo Highlight sitemaps that need updating.
//$options[$smid]['#attributes']['class'][] = 'warning'; // $options[$smid]['#attributes']['class'][] = 'warning';
$operations = array(); $operations = array();
$operations['edit'] = xmlsitemap_get_operation_link('admin/config/search/xmlsitemap/edit/' . $smid, array('title' => t('Edit'), 'modal' => TRUE)); $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)); $operations['delete'] = xmlsitemap_get_operation_link('admin/config/search/xmlsitemap/delete/' . $smid, array('title' => t('Delete'), 'modal' => TRUE));
...@@ -151,12 +150,15 @@ function xmlsitemap_sitemap_list_form_submit($form, &$form_state) { ...@@ -151,12 +150,15 @@ function xmlsitemap_sitemap_list_form_submit($form, &$form_state) {
call_user_func_array($function, $args); call_user_func_array($function, $args);
$count = count($form_state['values']['sitemaps']); $count = count($form_state['values']['sitemaps']);
//watchdog('xmlsitemap', '@action @count XML sitemaps.', array('@action' => $operation['action past'], '@count' => $count)); // 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))); 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'; // $form_state['redirect'] = 'admin/config/search/xmlsitemap';.
} }
} }
/**
*
*/
function xmlsitemap_sitemap_edit_form(array $form, array &$form_state, stdClass $sitemap = NULL) { function xmlsitemap_sitemap_edit_form(array $form, array &$form_state, stdClass $sitemap = NULL) {
_xmlsitemap_set_breadcrumb(); _xmlsitemap_set_breadcrumb();
...@@ -196,6 +198,9 @@ function xmlsitemap_sitemap_edit_form(array $form, array &$form_state, stdClass ...@@ -196,6 +198,9 @@ function xmlsitemap_sitemap_edit_form(array $form, array &$form_state, stdClass
return $form; return $form;
} }
/**
*
*/
function xmlsitemap_sitemap_edit_form_pre_render($form) { function xmlsitemap_sitemap_edit_form_pre_render($form) {
$visible_children = element_get_visible_children($form['context']); $visible_children = element_get_visible_children($form['context']);
if (empty($visible_children)) { if (empty($visible_children)) {
...@@ -207,6 +212,9 @@ function xmlsitemap_sitemap_edit_form_pre_render($form) { ...@@ -207,6 +212,9 @@ function xmlsitemap_sitemap_edit_form_pre_render($form) {
return $form; return $form;
} }
/**
*
*/
function xmlsitemap_sitemap_edit_form_validate($form, &$form_state) { function xmlsitemap_sitemap_edit_form_validate($form, &$form_state) {
// If there are no context options, the $form_state['values']['context'] // If there are no context options, the $form_state['values']['context']
// disappears. // disappears.
...@@ -217,6 +225,9 @@ function xmlsitemap_sitemap_edit_form_validate($form, &$form_state) { ...@@ -217,6 +225,9 @@ function xmlsitemap_sitemap_edit_form_validate($form, &$form_state) {
} }
} }
/**
*
*/
function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) { function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) {
form_state_values_clean($form_state); form_state_values_clean($form_state);
$sitemap = (object) $form_state['values']; $sitemap = (object) $form_state['values'];
...@@ -225,6 +236,9 @@ function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) { ...@@ -225,6 +236,9 @@ function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/search/xmlsitemap'; $form_state['redirect'] = 'admin/config/search/xmlsitemap';
} }
/**
*
*/
function xmlsitemap_sitemap_delete_form(array $form, array &$form_state, stdClass $sitemap) { function xmlsitemap_sitemap_delete_form(array $form, array &$form_state, stdClass $sitemap) {
_xmlsitemap_set_breadcrumb(); _xmlsitemap_set_breadcrumb();
...@@ -248,6 +262,9 @@ function xmlsitemap_sitemap_delete_form(array $form, array &$form_state, stdClas ...@@ -248,6 +262,9 @@ function xmlsitemap_sitemap_delete_form(array $form, array &$form_state, stdClas
); );
} }
/**
*
*/
function xmlsitemap_sitemap_delete_form_submit($form, $form_state) { function xmlsitemap_sitemap_delete_form_submit($form, $form_state) {
xmlsitemap_sitemap_delete($form_state['values']['smid']); xmlsitemap_sitemap_delete($form_state['values']['smid']);
drupal_set_message(t('The sitemap has been deleted.')); drupal_set_message(t('The sitemap has been deleted.'));
...@@ -288,12 +305,12 @@ function xmlsitemap_settings_form($form, &$form_state) { ...@@ -288,12 +305,12 @@ function xmlsitemap_settings_form($form, &$form_state) {
'#collapsed' => !variable_get('xmlsitemap_developer_mode', 0), '#collapsed' => !variable_get('xmlsitemap_developer_mode', 0),
'#weight' => 10, '#weight' => 10,
); );
//$form['advanced']['xmlsitemap_gz'] = array( // $form['advanced']['xmlsitemap_gz'] = array(
// '#type' => 'checkbox', // '#type' => 'checkbox',
// '#title' => t('Generate additional compressed sitemaps using gzip.'), // '#title' => t('Generate additional compressed sitemaps using gzip.'),
// '#default_value' => xmlsitemap_var('gz'), // '#default_value' => xmlsitemap_var('gz'),
// '#disabled' => !function_exists('gzencode'), // '#disabled' => !function_exists('gzencode'),
//); // );.
$form['advanced']['xmlsitemap_chunk_size'] = array( $form['advanced']['xmlsitemap_chunk_size'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Number of links in each sitemap page'), '#title' => t('Number of links in each sitemap page'),
...@@ -425,7 +442,7 @@ function xmlsitemap_settings_form_validate($form, &$form_state) { ...@@ -425,7 +442,7 @@ function xmlsitemap_settings_form_validate($form, &$form_state) {
} }
/** /**
* Submit handler; * Submit handler;.
* *
* @see xmlsitemap_settings_form() * @see xmlsitemap_settings_form()
*/ */
...@@ -571,7 +588,7 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info) ...@@ -571,7 +588,7 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info)
function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $entity, $bundle) { function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $entity, $bundle) {
$entity_info = xmlsitemap_get_link_info($entity); $entity_info = xmlsitemap_get_link_info($entity);
//if (!isset($bundle) && isset($entity_info['bundle keys']['bundle'])) { // If (!isset($bundle) && isset($entity_info['bundle keys']['bundle'])) {
// $bundle_key = $entity_info['bundle keys']['bundle']; // $bundle_key = $entity_info['bundle keys']['bundle'];
// if (isset($form[$bundle_key]['#value'])) { // if (isset($form[$bundle_key]['#value'])) {
// $bundle = $form[$bundle_key]['#value']; // $bundle = $form[$bundle_key]['#value'];
...@@ -579,8 +596,7 @@ function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $ ...@@ -579,8 +596,7 @@ function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $
// elseif (isset($form[$bundle_key]['#default_value'])) { // elseif (isset($form[$bundle_key]['#default_value'])) {
// $bundle = $form[$bundle_key]['#default_value']; // $bundle = $form[$bundle_key]['#default_value'];
// } // }
//} // }.
$bundle_info = xmlsitemap_link_bundle_load($entity, $bundle); $bundle_info = xmlsitemap_link_bundle_load($entity, $bundle);
$form['xmlsitemap'] = array( $form['xmlsitemap'] = array(
...@@ -641,6 +657,9 @@ function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $ ...@@ -641,6 +657,9 @@ function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $
} }
} }
/**
*
*/
function xmlsitemap_link_bundle_settings_form(array $form, array &$form_state, array $bundle) { 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 (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. // If this is a non-ajax form, redirect to the bundle administration page.
...@@ -649,7 +668,7 @@ function xmlsitemap_link_bundle_settings_form(array $form, array &$form_state, a ...@@ -649,7 +668,7 @@ function xmlsitemap_link_bundle_settings_form(array $form, array &$form_state, a
drupal_goto($admin_path, array('query' => $destination)); drupal_goto($admin_path, array('query' => $destination));
} }
else { 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(); $form = array();
...@@ -756,7 +775,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) { ...@@ -756,7 +775,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
'#value' => $link['status_override'], '#value' => $link['status_override'],
); );
// Priority field // Priority field.
$form['xmlsitemap']['priority'] = array( $form['xmlsitemap']['priority'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Priority'), '#title' => t('Priority'),
...@@ -786,19 +805,18 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) { ...@@ -786,19 +805,18 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
); );
// Other persistent fields. // Other persistent fields.
//$form['xmlsitemap']['lastmod'] = array( // $form['xmlsitemap']['lastmod'] = array(
// '#type' => 'value', // '#type' => 'value',
// '#value' => $node->xmlsitemap['lastmod'], // '#value' => $node->xmlsitemap['lastmod'],
//); // );
//$form['xmlsitemap']['changefreq'] = array( // $form['xmlsitemap']['changefreq'] = array(
// '#type' => 'value', // '#type' => 'value',
// '#value' => $node->xmlsitemap['changefreq'], // '#value' => $node->xmlsitemap['changefreq'],
//); // );
//$form['xmlsitemap']['changecount'] = array( // $form['xmlsitemap']['changecount'] = array(
// '#type' => 'value', // '#type' => 'value',
// '#value' => $node->xmlsitemap['changecount'], // '#value' => $node->xmlsitemap['changecount'],
//); // );
// Add the submit handler to adjust the default values if selected. // Add the submit handler to adjust the default values if selected.
$form += array('#submit' => array()); $form += array('#submit' => array());
if (!in_array('xmlsitemap_process_form_link_options', $form['#submit'])) { if (!in_array('xmlsitemap_process_form_link_options', $form['#submit'])) {
...@@ -813,6 +831,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) { ...@@ -813,6 +831,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
* Include a 'default' option. * Include a 'default' option.
* @param $guides * @param $guides
* Add helpful indicators for the highest, middle and lowest values. * Add helpful indicators for the highest, middle and lowest values.
*
* @return * @return
* An array of options. * An array of options.
*/ */
...@@ -854,6 +873,7 @@ function xmlsitemap_get_priority_options($default = NULL, $guides = TRUE) { ...@@ -854,6 +873,7 @@ function xmlsitemap_get_priority_options($default = NULL, $guides = TRUE) {
* *
* @param $default * @param $default
* Include a 'default' option. * Include a 'default' option.
*
* @return * @return
* An array of options. * An array of options.
* *
......
...@@ -24,9 +24,9 @@ function hook_xmlsitemap_link_info() { ...@@ -24,9 +24,9 @@ function hook_xmlsitemap_link_info() {
'label' => 'My module', 'label' => 'My module',
'base table' => 'mymodule', 'base table' => 'mymodule',
'entity keys' => array( 'entity keys' => array(
// Primary ID key on {base table} // Primary ID key on {base table}.
'id' => 'myid', 'id' => 'myid',
// Subtype key on {base table} // Subtype key on {base table}.
'bundle' => 'mysubtype', 'bundle' => 'mysubtype',
), ),
'path callback' => 'mymodule_path', 'path callback' => 'mymodule_path',
...@@ -52,7 +52,7 @@ function hook_xmlsitemap_link_info() { ...@@ -52,7 +52,7 @@ function hook_xmlsitemap_link_info() {
'rebuild callback' => '', 'rebuild callback' => '',
// Callback function called from the XML sitemap settings page. // Callback function called from the XML sitemap settings page.
'settings callback' => '', 'settings callback' => '',
) ),
), ),
); );
} }
...@@ -136,7 +136,7 @@ function hook_xmlsitemap_index_links($limit) { ...@@ -136,7 +136,7 @@ function hook_xmlsitemap_index_links($limit) {
/** /**
* Provide information about contexts available to XML sitemap. * 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() { function hook_xmlsitemap_context_info() {
$info['vocabulary'] = array( $info['vocabulary'] = array(
...@@ -150,7 +150,7 @@ function hook_xmlsitemap_context_info() { ...@@ -150,7 +150,7 @@ function hook_xmlsitemap_context_info() {
/** /**
* Alter XML sitemap context info. * Alter XML sitemap context info.
* *
* @see hook_xmlsitemap_context_info(). * @see hook_xmlsitemap_context_info()
*/ */
function hook_xmlsitemap_context_info_alter(&$info) { function hook_xmlsitemap_context_info_alter(&$info) {
$info['vocabulary']['label'] = t('Site vocabularies'); $info['vocabulary']['label'] = t('Site vocabularies');
......
...@@ -77,6 +77,9 @@ function _xmlsitemap_regenerate_before() { ...@@ -77,6 +77,9 @@ function _xmlsitemap_regenerate_before() {
} }
} }
/**
*
*/
function _xmlsitemap_get_memory_usage($start = FALSE) { function _xmlsitemap_get_memory_usage($start = FALSE) {
static $memory_start; static $memory_start;
$current = memory_get_peak_usage(TRUE); $current = memory_get_peak_usage(TRUE);
...@@ -153,6 +156,9 @@ function xmlsitemap_generate_page(stdClass $sitemap, $page) { ...@@ -153,6 +156,9 @@ function xmlsitemap_generate_page(stdClass $sitemap, $page) {
return $writer->getSitemapElementCount(); return $writer->getSitemapElementCount();
} }
/**
*
*/
function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer, $chunk) { function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer, $chunk) {
$output_elements = drupal_map_assoc(variable_get('xmlsitemap_output_elements', array('lastmod', 'changefreq', 'priority'))); $output_elements = drupal_map_assoc(variable_get('xmlsitemap_output_elements', array('lastmod', 'changefreq', 'priority')));
$lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM); $lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);
...@@ -260,8 +266,7 @@ function xmlsitemap_generate_index(stdClass $sitemap) { ...@@ -260,8 +266,7 @@ function xmlsitemap_generate_index(stdClass $sitemap) {
return $writer->getSitemapElementCount(); return $writer->getSitemapElementCount();
} }
// BATCH OPERATIONS ------------------------------------------------------------ // BATCH OPERATIONS ------------------------------------------------------------.
/** /**
* Batch information callback for regenerating the sitemap files. * Batch information callback for regenerating the sitemap files.
* *
...@@ -269,15 +274,16 @@ function xmlsitemap_generate_index(stdClass $sitemap) { ...@@ -269,15 +274,16 @@ function xmlsitemap_generate_index(stdClass $sitemap) {
* An optional array of XML sitemap IDs. If not provided, it will load all * An optional array of XML sitemap IDs. If not provided, it will load all
* existing XML sitemaps. * existing XML sitemaps.
*/ */
function xmlsitemap_regenerate_batch(array $smids = array()) { function xmlsitemap_regenerate_batch(array $smids = array()) {
if (empty($smids)) { if (empty($smids)) {
$smids = db_query("SELECT smid FROM {xmlsitemap_sitemap}")->fetchCol(); $smids = db_query("SELECT smid FROM {xmlsitemap_sitemap}")->fetchCol();
} }
//$t = get_t(); // $t = get_t();
$batch = array( $batch = array(
'operations' => array(), 'operations' => array(),
//'error_message' => $t('An error has occurred.'), // 'error_message' => $t('An error has occurred.'),.
'finished' => 'xmlsitemap_regenerate_batch_finished', 'finished' => 'xmlsitemap_regenerate_batch_finished',
'title' => t('Regenerating Sitemap'), 'title' => t('Regenerating Sitemap'),
'file' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.generate.inc', 'file' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.generate.inc',
...@@ -361,7 +367,7 @@ function xmlsitemap_regenerate_batch_generate_index($smid, array &$context) { ...@@ -361,7 +367,7 @@ function xmlsitemap_regenerate_batch_generate_index($smid, array &$context) {
function xmlsitemap_regenerate_batch_finished($success, $results, $operations, $elapsed) { function xmlsitemap_regenerate_batch_finished($success, $results, $operations, $elapsed) {
if ($success && !variable_get('xmlsitemap_regenerate_needed', FALSE)) { if ($success && !variable_get('xmlsitemap_regenerate_needed', FALSE)) {
variable_set('xmlsitemap_generated_last', REQUEST_TIME); 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. // Show a watchdog message that the sitemap was regenerated.
watchdog('xmlsitemap', watchdog('xmlsitemap',
'Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.', 'Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.',
...@@ -468,7 +474,8 @@ function xmlsitemap_rebuild_batch_fetch($entity, &$context) { ...@@ -468,7 +474,8 @@ function xmlsitemap_rebuild_batch_fetch($entity, &$context) {
// PostgreSQL cannot have the ORDERED BY in the count query. // PostgreSQL cannot have the ORDERED BY in the count query.
$query->entityOrderBy('entity_id'); $query->entityOrderBy('entity_id');
$limit = 20; //variable_get('xmlsitemap_batch_limit', 100) // variable_get('xmlsitemap_batch_limit', 100)
$limit = 20;
$query->range(0, $limit); $query->range(0, $limit);
$result = $query->execute(); $result = $query->execute();
...@@ -499,6 +506,9 @@ function xmlsitemap_rebuild_batch_finished($success, $results, $operations, $ela ...@@ -499,6 +506,9 @@ function xmlsitemap_rebuild_batch_finished($success, $results, $operations, $ela
} }
} }
/**
*
*/
function xmlsitemap_get_rebuildable_link_types() { function xmlsitemap_get_rebuildable_link_types() {
$rebuild_types = array(); $rebuild_types = array();
$entities = xmlsitemap_get_link_info(); $entities = xmlsitemap_get_link_info();
......
...@@ -27,13 +27,16 @@ function _xmlsitemap_get_blurb($check_version = TRUE) { ...@@ -27,13 +27,16 @@ function _xmlsitemap_get_blurb($check_version = TRUE) {
); );
// Don't extract the following string for translation. // 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>'; $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; return $blurb;
} }
/**
*
*/
function _xmlsitemap_get_version() { function _xmlsitemap_get_version() {
static $version; static $version;
if (!isset($version)) { if (!isset($version)) {
......
...@@ -214,8 +214,8 @@ function xmlsitemap_schema() { ...@@ -214,8 +214,8 @@ function xmlsitemap_schema() {
'type' => 'float', 'type' => 'float',
'default' => NULL, 'default' => NULL,
// @todo Convert this field to non-nullable. // @todo Convert this field to non-nullable.
//'default' => 0.5, // 'default' => 0.5,
//'not null' => NULL, // 'not null' => NULL,
), ),
'priority_override' => array( 'priority_override' => array(
'description' => 'A boolean that if TRUE means that the priority field has been overridden from its default value.', 'description' => 'A boolean that if TRUE means that the priority field has been overridden from its default value.',
...@@ -286,13 +286,13 @@ function xmlsitemap_schema() { ...@@ -286,13 +286,13 @@ function xmlsitemap_schema() {
'not null' => TRUE, 'not null' => TRUE,
'default' => 0, 'default' => 0,
), ),
//'queued' => array( // 'queued' => array(
// 'type' => 'int', // 'type' => 'int',
// 'unsigned' => TRUE, // 'unsigned' => TRUE,
// 'not null' => TRUE, // 'not null' => TRUE,
// 'default' => 0, // 'default' => 0,
// 'description' => 'Time when this sitemap was queued for regeneration, 0 if not queued.', // 'description' => 'Time when this sitemap was queued for regeneration, 0 if not queued.',
//), // ),.
), ),
'primary key' => array('smid'), 'primary key' => array('smid'),
); );
...@@ -554,6 +554,9 @@ function xmlsitemap_update_7203() { ...@@ -554,6 +554,9 @@ function xmlsitemap_update_7203() {
_xmlsitemap_sitemap_rehash_all(); _xmlsitemap_sitemap_rehash_all();
} }
/**
*
*/
function _xmlsitemap_sitemap_rehash_all() { function _xmlsitemap_sitemap_rehash_all() {
// Reload the schema cache and reprocess all sitemap hashes into smids. // Reload the schema cache and reprocess all sitemap hashes into smids.
drupal_load('module', 'xmlsitemap'); drupal_load('module', 'xmlsitemap');
......
This diff is collapsed.
...@@ -74,14 +74,15 @@ function xmlsitemap_output_file($file, array $headers = array()) { ...@@ -74,14 +74,15 @@ 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_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) { if ($if_modified_since && $if_none_match && $if_none_match == $etag && $if_modified_since == $last_modified) {
header('HTTP/1.1 304 Not 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); header('Etag: ' . $etag);
exit; exit;
} }
$headers += array( $headers += array(
'Content-type' => 'text/xml; charset=utf-8', 'Content-type' => 'text/xml; charset=utf-8',
//'Content-length' => filesize($file), // 'Content-length' => filesize($file),
'Last-modified' => $last_modified, 'Last-modified' => $last_modified,
'Etag' => $etag, 'Etag' => $etag,
'Expires' => gmdate(DATE_RFC1123, $mtime + variable_get('xmlsitemap_minimum_lifetime', 0)), 'Expires' => gmdate(DATE_RFC1123, $mtime + variable_get('xmlsitemap_minimum_lifetime', 0)),
...@@ -115,7 +116,7 @@ function xmlsitemap_file_transfer($uri, $headers) { ...@@ -115,7 +116,7 @@ function xmlsitemap_file_transfer($uri, $headers) {
// Transfer file in 16 KB chunks to save memory usage. // Transfer file in 16 KB chunks to save memory usage.
if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) { if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) {
while (!feof($fd)) { while (!feof($fd)) {
print fread($fd, 1024*16); print fread($fd, 1024 * 16);
} }
fclose($fd); fclose($fd);
} }
......
This diff is collapsed.
...@@ -5,36 +5,69 @@ ...@@ -5,36 +5,69 @@
* XML sitemap integration functions for xmlsitemap.module. * XML sitemap integration functions for xmlsitemap.module.
*/ */
class XMLSitemapException extends Exception {} /**
* Class for XML Sitemap Exception.
*/
class XMLSitemapException extends Exception {
}
/**
* Class for XML Sitemap Generation Exception.
*/
class XMLSitemapGenerationException extends XMLSitemapException {
class XMLSitemapGenerationException extends XMLSitemapException {} }
/** /**
* Extended class for writing XML sitemap files. * Extended class for writing XML sitemap files.
*/ */
class XMLSitemapWriter extends XMLWriter { class XMLSitemapWriter extends XMLWriter {
protected $uri = NULL; protected $uri = NULL;
protected $sitemapElementCount = 0; protected $sitemapElementCount = 0;
protected $linkCountFlush = 500; protected $linkCountFlush = 500;
protected $sitemap = NULL; protected $sitemap = NULL;
/**
* Sitemap Page.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $sitemap_page = NULL; protected $sitemap_page = NULL;
/**
* Root Element.
*
* @var string.
*
* @codingStandardsIgnoreEnd
*/
protected $rootElement = 'urlset'; protected $rootElement = 'urlset';
/** /**
* Constructor. * Constructor.
* *
* @param $sitemap * @param array $sitemap
* The sitemap array. * The sitemap array.
* @param $page * @param string $page
* The current page of the sitemap being generated. * 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 = $sitemap;
$this->sitemap_page = $page; $this->sitemap_page = $page;
$this->uri = xmlsitemap_sitemap_get_file($sitemap, $page); $this->uri = xmlsitemap_sitemap_get_file($sitemap, $page);
$this->openUri($this->uri); $this->openUri($this->uri);
} }
/**
* Open URI.
*/
public function openUri($uri) { public function openUri($uri) {
$return = parent::openUri($uri); $return = parent::openUri($uri);
if (!$return) { if (!$return) {
...@@ -43,6 +76,9 @@ class XMLSitemapWriter extends XMLWriter { ...@@ -43,6 +76,9 @@ class XMLSitemapWriter extends XMLWriter {
return $return; return $return;
} }
/**
* Start Document.
*/
public function startDocument($version = '1.0', $encoding = 'UTF-8', $standalone = NULL) { public function startDocument($version = '1.0', $encoding = 'UTF-8', $standalone = NULL) {
$this->setIndent(FALSE); $this->setIndent(FALSE);
$result = parent::startDocument($version, $encoding); $result = parent::startDocument($version, $encoding);
...@@ -56,6 +92,9 @@ class XMLSitemapWriter extends XMLWriter { ...@@ -56,6 +92,9 @@ class XMLSitemapWriter extends XMLWriter {
return $result; return $result;
} }
/**
* Get Sitemap URL.
*/
public function getSitemapUrl($path, array $options = array()) { public function getSitemapUrl($path, array $options = array()) {
$options += $this->sitemap->uri['options']; $options += $this->sitemap->uri['options'];
$options += array( $options += array(
...@@ -72,8 +111,11 @@ class XMLSitemapWriter extends XMLWriter { ...@@ -72,8 +111,11 @@ class XMLSitemapWriter extends XMLWriter {
/** /**
* Add the XML stylesheet to the XML page. * Add the XML stylesheet to the XML page.
*
* @codingStandardsIgnoreStart
*/ */
public function writeXSL() { public function writeXSL() {
// @codingStandardsIgnoreEnd
$this->writePi('xml-stylesheet', 'type="text/xsl" href="' . $this->getSitemapUrl('sitemap.xsl', array('protocol_relative' => TRUE)) . '"'); $this->writePi('xml-stylesheet', 'type="text/xsl" href="' . $this->getSitemapUrl('sitemap.xsl', array('protocol_relative' => TRUE)) . '"');
$this->writeRaw(PHP_EOL); $this->writeRaw(PHP_EOL);
} }
...@@ -93,10 +135,19 @@ class XMLSitemapWriter extends XMLWriter { ...@@ -93,10 +135,19 @@ class XMLSitemapWriter extends XMLWriter {
return $attributes; return $attributes;
} }
/**
* Generate XML.
*
* @codingStandardsIgnoreStart
*/
public function generateXML() { public function generateXML() {
// @codingStandardsIgnoreEnd
return xmlsitemap_generate_chunk($this->sitemap, $this, $this->sitemap_page); return xmlsitemap_generate_chunk($this->sitemap, $this, $this->sitemap_page);
} }
/**
* Start Element.
*/
public function startElement($name, $root = FALSE) { public function startElement($name, $root = FALSE) {
parent::startElement($name); parent::startElement($name);
...@@ -111,9 +162,9 @@ class XMLSitemapWriter extends XMLWriter { ...@@ -111,9 +162,9 @@ class XMLSitemapWriter extends XMLWriter {