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() {
$form['operations']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
//'#validate' => array('xmlsitemap_sitemap_list_form_validate'),
//'#submit' => array('xmlsitemap_sitemap_list_form_submit'),
// '#validate' => array('xmlsitemap_sitemap_list_form_validate'),
// '#submit' => array('xmlsitemap_sitemap_list_form_submit'),.
);
$contexts = xmlsitemap_get_context_info();
......@@ -82,8 +82,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 +150,15 @@ 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));
// 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';
// $form_state['redirect'] = 'admin/config/search/xmlsitemap';.
}
}
/**
*
*/
function xmlsitemap_sitemap_edit_form(array $form, array &$form_state, stdClass $sitemap = NULL) {
_xmlsitemap_set_breadcrumb();
......@@ -196,6 +198,9 @@ function xmlsitemap_sitemap_edit_form(array $form, array &$form_state, stdClass
return $form;
}
/**
*
*/
function xmlsitemap_sitemap_edit_form_pre_render($form) {
$visible_children = element_get_visible_children($form['context']);
if (empty($visible_children)) {
......@@ -207,6 +212,9 @@ function xmlsitemap_sitemap_edit_form_pre_render($form) {
return $form;
}
/**
*
*/
function xmlsitemap_sitemap_edit_form_validate($form, &$form_state) {
// If there are no context options, the $form_state['values']['context']
// disappears.
......@@ -217,6 +225,9 @@ function xmlsitemap_sitemap_edit_form_validate($form, &$form_state) {
}
}
/**
*
*/
function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) {
form_state_values_clean($form_state);
$sitemap = (object) $form_state['values'];
......@@ -225,6 +236,9 @@ function xmlsitemap_sitemap_edit_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/search/xmlsitemap';
}
/**
*
*/
function xmlsitemap_sitemap_delete_form(array $form, array &$form_state, stdClass $sitemap) {
_xmlsitemap_set_breadcrumb();
......@@ -248,6 +262,9 @@ function xmlsitemap_sitemap_delete_form(array $form, array &$form_state, stdClas
);
}
/**
*
*/
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.'));
......@@ -288,12 +305,12 @@ function xmlsitemap_settings_form($form, &$form_state) {
'#collapsed' => !variable_get('xmlsitemap_developer_mode', 0),
'#weight' => 10,
);
//$form['advanced']['xmlsitemap_gz'] = array(
// $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'),
......@@ -425,7 +442,7 @@ function xmlsitemap_settings_form_validate($form, &$form_state) {
}
/**
* Submit handler;
* Submit handler;.
*
* @see xmlsitemap_settings_form()
*/
......@@ -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) {
$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'];
// if (isset($form[$bundle_key]['#value'])) {
// $bundle = $form[$bundle_key]['#value'];
......@@ -579,8 +596,7 @@ function xmlsitemap_add_link_bundle_settings(array &$form, array &$form_state, $
// 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 +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) {
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 +668,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();
......@@ -756,7 +775,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'),
......@@ -786,19 +805,18 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
);
// Other persistent fields.
//$form['xmlsitemap']['lastmod'] = array(
// $form['xmlsitemap']['lastmod'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['lastmod'],
//);
//$form['xmlsitemap']['changefreq'] = array(
// );
// $form['xmlsitemap']['changefreq'] = array(
// '#type' => 'value',
// '#value' => $node->xmlsitemap['changefreq'],
//);
//$form['xmlsitemap']['changecount'] = array(
// );
// $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'])) {
......@@ -813,6 +831,7 @@ function xmlsitemap_add_form_link_options(array &$form, $entity, $bundle, $id) {
* Include a 'default' option.
* @param $guides
* Add helpful indicators for the highest, middle and lowest values.
*
* @return
* An array of options.
*/
......@@ -854,6 +873,7 @@ function xmlsitemap_get_priority_options($default = NULL, $guides = TRUE) {
*
* @param $default
* Include a 'default' option.
*
* @return
* An array of options.
*
......
......@@ -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,7 +52,7 @@ function hook_xmlsitemap_link_info() {
'rebuild callback' => '',
// Callback function called from the XML sitemap settings page.
'settings callback' => '',
)
),
),
);
}
......@@ -136,7 +136,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 +150,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');
......
......@@ -77,6 +77,9 @@ function _xmlsitemap_regenerate_before() {
}
}
/**
*
*/
function _xmlsitemap_get_memory_usage($start = FALSE) {
static $memory_start;
$current = memory_get_peak_usage(TRUE);
......@@ -153,6 +156,9 @@ function xmlsitemap_generate_page(stdClass $sitemap, $page) {
return $writer->getSitemapElementCount();
}
/**
*
*/
function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer, $chunk) {
$output_elements = drupal_map_assoc(variable_get('xmlsitemap_output_elements', array('lastmod', 'changefreq', 'priority')));
$lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);
......@@ -260,8 +266,7 @@ function xmlsitemap_generate_index(stdClass $sitemap) {
return $writer->getSitemapElementCount();
}
// BATCH OPERATIONS ------------------------------------------------------------
// BATCH OPERATIONS ------------------------------------------------------------.
/**
* Batch information callback for regenerating the sitemap files.
*
......@@ -269,15 +274,16 @@ function xmlsitemap_generate_index(stdClass $sitemap) {
* An optional array of XML sitemap IDs. If not provided, it will load all
* existing XML sitemaps.
*/
function xmlsitemap_regenerate_batch(array $smids = array()) {
if (empty($smids)) {
$smids = db_query("SELECT smid FROM {xmlsitemap_sitemap}")->fetchCol();
}
//$t = get_t();
// $t = get_t();
$batch = array(
'operations' => array(),
//'error_message' => $t('An error has occurred.'),
// '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 +367,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.',
......@@ -468,7 +474,8 @@ 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)
// variable_get('xmlsitemap_batch_limit', 100)
$limit = 20;
$query->range(0, $limit);
$result = $query->execute();
......@@ -499,6 +506,9 @@ function xmlsitemap_rebuild_batch_finished($success, $results, $operations, $ela
}
}
/**
*
*/
function xmlsitemap_get_rebuildable_link_types() {
$rebuild_types = array();
$entities = xmlsitemap_get_link_info();
......
......@@ -27,13 +27,16 @@ function _xmlsitemap_get_blurb($check_version = TRUE) {
);
// 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;
}
/**
*
*/
function _xmlsitemap_get_version() {
static $version;
if (!isset($version)) {
......
......@@ -214,8 +214,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 +286,13 @@ function xmlsitemap_schema() {
'not null' => TRUE,
'default' => 0,
),
//'queued' => array(
// 'queued' => array(
// 'type' => 'int',
// 'unsigned' => TRUE,
// 'not null' => TRUE,
// 'default' => 0,
// 'description' => 'Time when this sitemap was queued for regeneration, 0 if not queued.',
//),
// ),.
),
'primary key' => array('smid'),
);
......@@ -554,6 +554,9 @@ function xmlsitemap_update_7203() {
_xmlsitemap_sitemap_rehash_all();
}
/**
*
*/
function _xmlsitemap_sitemap_rehash_all() {
// Reload the schema cache and reprocess all sitemap hashes into smids.
drupal_load('module', 'xmlsitemap');
......
This diff is collapsed.
......@@ -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 ($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),
// 'Content-length' => filesize($file),
'Last-modified' => $last_modified,
'Etag' => $etag,
'Expires' => gmdate(DATE_RFC1123, $mtime + variable_get('xmlsitemap_minimum_lifetime', 0)),
......@@ -115,7 +116,7 @@ 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);
}
......
This diff is collapsed.
......@@ -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 for XML Sitemap Generation Exception.
*/
class XMLSitemapGenerationException extends XMLSitemapException {
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,6 +92,9 @@ class XMLSitemapWriter extends XMLWriter {
return $result;
}
/**
* Get Sitemap URL.
*/
public function getSitemapUrl($path, array $options = array()) {
$options += $this->sitemap->uri['options'];
$options += array(
......@@ -72,8 +111,11 @@ class XMLSitemapWriter extends XMLWriter {
/**
* Add the XML stylesheet to the XML page.
*
* @codingStandardsIgnoreStart
*/
public function writeXSL() {
// @codingStandardsIgnoreEnd
$this->writePi('xml-stylesheet', 'type="text/xsl" href="' . $this->getSitemapUrl('sitemap.xsl', array('protocol_relative' => TRUE)) . '"');
$this->writeRaw(PHP_EOL);
}
......@@ -93,10 +135,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 +162,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 +203,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 +230,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 +270,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 +288,7 @@ class XMLSitemapIndexWriter extends XMLSitemapWriter {
$this->writeSitemapElement('sitemap', $element);
}
}
}
/**
......@@ -285,7 +367,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()
......
......@@ -129,9 +129,10 @@ function xmlsitemap_node_form_node_type_form_alter(array &$form, array $form_sta
}
/**
* @codingStandardsIgnoreLine
* Implements hook_form_alter().
*
* @codingStandardsIgnoreLine
*
* Add the XML sitemap individual link options for a node.
*
* @see xmlsitemap_add_form_link_options()
......
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;
}
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