Commit 90c10f2b authored by Dave Reid's avatar Dave Reid

#666300 by Dave Reid: Converted the XSL JavaScript to use jQuery and the Tablesorter plugin.

parent a8e4cc87
......@@ -321,24 +321,6 @@ function xmlsitemap_calculate_changefreq($timestamps) {
return $count > 0 ? round($diff / $count) : 0;
}
/**
* Given an table and field, return the field type.
*
* @param $table
* The table name.
* @param $field
* The field name.
* @return
* The schema type of {table}.field.
*/
function _xmlsitemap_get_field_type($table, $field) {
static $schema;
if (!isset($schema[$table])) {
$schema[$table] = drupal_get_schema($table);
}
return $schema[$table]['fields'][$field]['type'];
}
/**
* Check if there is a visible sitemap link given a certain set of conditions.
*
......@@ -355,9 +337,13 @@ function _xmlsitemap_check_changed_links(array $conditions = array(), array $upd
$conditions['status'] = (!empty($updates['status']) && empty($condition['status'])) ? 0 : 1;
$conditions['access'] = (!empty($updates['access']) && empty($condition['access'])) ? 0 : 1;
$args = _xmlsitemap_build_conditions($conditions);
$sql = "SELECT 1 FROM {xmlsitemap} WHERE ". implode(' AND ', $conditions);
$changed = db_query_range($sql, 0, 1, $args)->fetchField();
$query = db_select('xmlsitemap');
$query->addExpression('1');
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
}
$query->range(0, 1);
$changed = $query->execute()->fetchField();
if ($changed && $flag) {
variable_set('xmlsitemap_regenerate_needed', TRUE);
......@@ -413,27 +399,6 @@ function _xmlsitemap_check_changed_link(array $link, $original_link = NULL, $fla
return $changed;
}
/**
* Condition builder for queries.
*
* @todo (Drupal7) Replace with DBTNG
*/
function _xmlsitemap_build_conditions(array &$conditions = array(), array &$args = array(), $operator = '=', $null_operator = 'IS') {
foreach ($conditions as $field => $value) {
if (is_int($field)) {
continue;
}
elseif ($value === NULL) {
$conditions[$field] = "$field $null_operator NULL";
}
else {
$conditions[$field] = "$field $operator :$field";
$args[':' . $field] = $value;
}
}
return $args;
}
/**
* Load a specific sitemap link.
*
......@@ -445,8 +410,13 @@ function _xmlsitemap_build_conditions(array &$conditions = array(), array &$args
* @todo Convert to use $type and $id as parameters.
*/
function xmlsitemap_load_link(array $conditions) {
$args = _xmlsitemap_build_conditions($conditions);
$link = db_query_range("SELECT * FROM {xmlsitemap} WHERE ". implode(' AND ', $conditions), 0, 1, $args)->fetchAssoc();
$query = db_select('xmlsitemap', 'x');
$query->fields('x');
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
}
$query->range(0, 1);
$link = $query->execute()->fetchAssoc();
// Allow other modules to respond after loading the link.
//module_invoke_all('xmlsitemap_load_link', $link, $conditions, $args);
......@@ -532,6 +502,7 @@ function xmlsitemap_update_links($updates = array(), $conditions = array()) {
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
}
return $query->execute();
}
......@@ -555,6 +526,7 @@ function xmlsitemap_delete_link(array $conditions) {
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
}
return $query->execute();
}
......@@ -922,7 +894,7 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
$module_link_info[$type] += array(
'type' => $type,
'module' => $module,
'purge' => TRUE, //module_hook($module, 'xmlsitemap_link_data'),
'purge' => TRUE,
'table' => FALSE,
);
}
......
......@@ -49,13 +49,13 @@ function xmlsitemap_output_file($file, array $headers = array()) {
}
$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)),
'Cache-Control: must-revalidate',
'X-Robots-Tag: noindex, follow',
'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)),
'Cache-Control' => 'must-revalidate',
'X-Robots-Tag' => 'noindex, follow',
);
// Transfer the file as output.
......@@ -67,32 +67,27 @@ function xmlsitemap_output_file($file, array $headers = array()) {
*
* @see file_transfer()
*/
function xmlsitemap_file_transfer($source, $headers) {
function xmlsitemap_file_transfer($uri, $headers) {
if (ob_get_level()) {
ob_end_clean();
}
foreach ($headers as $header) {
// To prevent HTTP header injection, we delete new lines that are
// not followed by a space or a tab.
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
$header = preg_replace('/\r?\n(?!\t| )/', '', $header);
drupal_set_header($header);
foreach ($headers as $name => $value) {
drupal_add_http_header($name, $value);
}
drupal_send_headers();
$scheme = $scheme = variable_get('file_default_scheme', 'public');
// Transfer file in 1024 byte chunks to save memory usage.
if ($handle = fopen($source, 'rb')) {
while (!feof($handle)) {
print fread($handle, 1024);
if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) {
while (!feof($fd)) {
print fread($fd, 1024);
}
fclose($handle);
fclose($fd);
}
else {
drupal_not_found();
}
module_invoke_all('exit');
exit();
drupal_exit();
}
/**
......@@ -115,13 +110,15 @@ function xmlsitemap_output_xsl() {
'URL location' => t('URL location'),
'Change frequency' => t('Change frequency'),
'Priority' => t('Priority'),
'[xsl-css]' => base_path() . $module_path . '/xsl/xmlsitemap.xsl.css',
'[jquery]' => base_path() . 'misc/jquery.js',
'[jquery-tablesort]' => base_path() . $module_path . '/xsl/jquery.tablesorter.min.js',
'[xsl-js]' => base_path() . $module_path . '/xsl/xmlsitemap.xsl.js',
'[xsl-css]' => base_path() . $module_path . '/xsl/xmlsitemap.xsl.css',
);
$xsl_content = strtr($xsl_content, $replacements);
// Output the XSL content.
drupal_set_header('Content-type: application/xml; charset=utf-8');
drupal_set_header('X-Robots-Tag: noindex, follow');
drupal_add_http_header('Content-type', 'application/xml; charset=utf-8');
drupal_add_http_header('X-Robots-Tag', 'noindex, follow');
echo $xsl_content;
}
This diff is collapsed.
This diff is collapsed.
......@@ -15,65 +15,73 @@
<html>
<head>
<title>Sitemap file</title>
<script type="text/javascript" src="[jquery]"></script>
<script type="text/javascript" src="[jquery-tablesort]"></script>
<script type="text/javascript" src="[xsl-js]"></script>
<link href="[xsl-css]" type="text/css" rel="stylesheet"/>
<script src="[xsl-js]"></script>
</head>
<!-- Store in $fileType if we are in a sitemap or in a siteindex -->
<xsl:variable name="fileType">
<xsl:choose>
<xsl:when test="//sitemap:url">sitemap</xsl:when>
<xsl:otherwise>siteindex</xsl:otherwise>
<xsl:when test="//sitemap:url">sitemap</xsl:when>
<xsl:otherwise>siteindex</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Body -->
<body onLoad="initXsl('table0','{$fileType}');">
<!-- Text and table -->
<h1 id="head1">Sitemap file:</h1>
<xsl:choose>
<xsl:when test="$fileType='sitemap'"><xsl:call-template name="sitemapTable"/></xsl:when>
<xsl:otherwise><xsl:call-template name="siteindexTable"/></xsl:otherwise>
</xsl:choose>
<body>
<h1>Sitemap file</h1>
<xsl:choose>
<xsl:when test="$fileType='sitemap'"><xsl:call-template name="sitemapTable"/></xsl:when>
<xsl:otherwise><xsl:call-template name="siteindexTable"/></xsl:otherwise>
</xsl:choose>
<br/>
<p id="copyright">
Generated by the <a href="http://drupal.org/project/xmlsitemap">Drupal XML sitemap module</a>.
</p>
<div id="footer">
<p>Generated by the <a href="http://drupal.org/project/xmlsitemap">Drupal XML sitemap module</a>.</p>
</div>
</body>
</html>
</xsl:template>
<!-- siteindexTable template -->
<xsl:template name="siteindexTable">
<h2>Number of sitemaps in this index: <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"></xsl:value-of></h2>
<p class="sml">Click on the table headers to change sorting.</p>
<table border="1" width="100%" class="data" id="table0">
<tr class="header">
<td>Sitemap URL</td>
<td>Last modification date</td>
</tr>
<xsl:apply-templates select="sitemap:sitemapindex/sitemap:sitemap">
<xsl:sort select="sitemap:lastmod" order="descending"/>
</xsl:apply-templates>
<div id="information">
<p>Number of sitemaps in this index: <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"></xsl:value-of></p>
</div>
<table class="tablesorter siteindex">
<thead>
<tr>
<td>Sitemap URL</td>
<td>Last modification date</td>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="sitemap:sitemapindex/sitemap:sitemap">
<xsl:sort select="sitemap:lastmod" order="descending"/>
</xsl:apply-templates>
</tbody>
</table>
</xsl:template>
<!-- sitemapTable template -->
<xsl:template name="sitemapTable">
<h2>Number of URLs in this sitemap: <xsl:value-of select="count(sitemap:urlset/sitemap:url)"></xsl:value-of></h2>
<p class="sml">Click on the table headers to change sorting.</p>
<table border="1" width="100%" class="data" id="table0">
<tr class="header">
<td>URL location</td>
<td>Last modification date</td>
<td>Change frequency</td>
<td>Priority</td>
</tr>
<xsl:apply-templates select="sitemap:urlset/sitemap:url">
<xsl:sort select="sitemap:priority" order="descending"/>
</xsl:apply-templates>
<div id="information">
<p>Number of URLs in this sitemap: <xsl:value-of select="count(sitemap:urlset/sitemap:url)"></xsl:value-of></p>
</div>
<table class="tablesorter sitemap">
<thead>
<tr>
<th>URL location</th>
<th>Last modification date</th>
<th><xsl:attribute name="class">{sorter: 'changefreq'}</xsl:attribute>Change frequency</th>
<th>Priority</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="sitemap:urlset/sitemap:url">
<xsl:sort select="sitemap:priority" order="descending"/>
</xsl:apply-templates>
</tbody>
</table>
</xsl:template>
......@@ -82,7 +90,7 @@
<tr>
<td>
<xsl:variable name="sitemapURL"><xsl:value-of select="sitemap:loc"/></xsl:variable>
<a href="{$sitemapURL}" target="_blank" ref="nofollow"><xsl:value-of select="$sitemapURL"></xsl:value-of></a>
<a href="{$sitemapURL}" ref="nofollow"><xsl:value-of select="$sitemapURL"></xsl:value-of></a>
</td>
<td><xsl:value-of select="sitemap:lastmod"/></td>
<td><xsl:value-of select="sitemap:changefreq"/></td>
......
/* $Id$ */
/**
* Google Sitmaps Stylesheets (GSStylesheets) CSS
* License http://www.gnu.org/copyleft/lesser.html GNU/LGPL
*/
body {
margin-top: 0;
background-color: #fff;
}
body, td, th {
font-family: arial,sans-serif;
font-size: 13px;
background-color: #FFF;
font-family: Verdana,sans-serif;
font-size: 10pt;
}
h1 {
font-size: 1.2em;
margin-bottom: 1em;
margin-top: 0;
}
h1 a {
font-size: 0.8em;
font-weight: normal;
}
h2 {
font-weight: bold;
font-size: 1.0em;
color: #707070;
padding-bottom: .5em;
padding-top: 0px;
margin: 1.5em 0 .5em 0;
}
h2 a {
font-size: 1.0em;
font-weight: normal;
}
p.sml {
font-size: 0.8em;
margin-top: 0;
}
a {
color: #0000cc;
text-decoration: none;
}
a:visited {
color: #551a8b;
}
.header {
font-weight: bold;
font-size: 1.3em;
margin-top: 30px;
padding-left: 4px;
border-bottom: 1px solid #dbe6de;
}
.data {
border-collapse: collapse;
border: 1px solid #BFC7D9;
margin-top: 3px;
width: 100%;
_word-wrap: break-word;
}
.data td {
border-bottom: 1px solid #BFC7D9;
text-align: left;
padding: 3px;
}
.sortup {
background-position: right center;
background-image: url(/misc/arrow-asc.png);
background-repeat: no-repeat;
font-style: italic;
white-space: pre;
}
.sortdown {
background-position: right center;
background-image: url(/misc/arrow-desc.png);
background-repeat: no-repeat;
font-size: 1.25em;
}
table.tablesorter {
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;
font-size: 8pt;
padding: 3px;
}
table.tablesorter thead tr .header {
cursor: pointer;
}
table.tablesorter tbody td {
color: #3D3D3D;
padding: 3px;
background-color: #FFF;
vertical-align: top;
}
table.tablesorter tbody tr.odd td {
background-color: #EFEFEF;
}
table.tablesorter thead tr .headerSortUp {
background: url(/misc/arrow-asc.png) no-repeat center right;
}
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;
font-style: italic;
white-space: pre;
}
// $Id$
/**
* Google Sitmaps Stylesheets (GSStylesheets) JavaScript
* License http://www.gnu.org/copyleft/lesser.html GNU/LGPL
*/
var selectedColor = "blue";
var defaultColor = "black";
var hdrRows = 1;
var numeric = '..';
var desc = '..';
var html = '..';
var freq = '..';
function initXsl(tabName,fileType) {
hdrRows = 1;
if(fileType=="sitemap") {
numeric = ".3.";
desc = ".1.";
html = ".0.";
freq = ".2.";
initTable(tabName);
//setSort(tabName, 3, 1);
}
else {
desc = ".1.";
html = ".0.";
initTable(tabName);
//setSort(tabName, 0, 1);
}
var theURL = document.getElementById("head1");
theURL.innerHTML += ' ' + location;
document.title += ': ' + location;
}
function initTable(tabName) {
var theTab = document.getElementById(tabName);
for(r=0;r<hdrRows;r++)
for(c=0;c<theTab.rows[r].cells.length;c++)
if((r+theTab.rows[r].cells[c].rowSpan)>hdrRows)
hdrRows=r+theTab.rows[r].cells[c].rowSpan;
for(r=0;r<hdrRows; r++){
colNum = 0;
for(c=0;c<theTab.rows[r].cells.length;c++, colNum++){
if(theTab.rows[r].cells[c].colSpan<2){
theCell = theTab.rows[r].cells[c];
rTitle = theCell.innerHTML.replace(/<[^>]+>|&nbsp;/g,'');
if(rTitle>""){
theCell.title = "Change sort order for " + rTitle;
theCell.onmouseover = function(){setCursor(this, "selected")};
theCell.onmouseout = function(){setCursor(this, "default")};
var sortParams = 15; // bitmapped: numeric|desc|html|freq
if(numeric.indexOf("."+colNum+".")>-1) sortParams -= 1;
if(desc.indexOf("."+colNum+".")>-1) sortParams -= 2;
if(html.indexOf("."+colNum+".")>-1) sortParams -= 4;
if(freq.indexOf("."+colNum+".")>-1) sortParams -= 8;
theCell.onclick = new Function("sortTable(this,"+(colNum+r)+","+hdrRows+","+sortParams+")");
}
} else {
colNum = colNum+theTab.rows[r].cells[c].colSpan-1;
}
(function($){
/*$.tablesorter.addParser({
// set a unique id
id: 'changefreq',
is: function(s) {
return false;
},
format: function(s) {
switch (s) {
case 'always':
return 0;
case 'hourly':
return 1;
case 'daily':
return 2;
case 'weekly':
return 3;
case 'monthly':
return 4;
case 'yearly':
return 5;
default:
return 6;
}
}
}
function setSort(tabName, colNum, sortDir) {
var theTab = document.getElementById(tabName);
theTab.rows[0].sCol = colNum;
theTab.rows[0].sDir = sortDir;
if (sortDir)
theTab.rows[0].cells[colNum].className='sortdown'
else
theTab.rows[0].cells[colNum].className='sortup';
}
},
type: 'numeric'
});*/
function setCursor(theCell, mode){
rTitle = theCell.innerHTML.replace(/<[^>]+>|&nbsp;|\W/g,'');
if(mode=="selected"){
if(theCell.style.color!=selectedColor)
defaultColor = theCell.style.color;
theCell.style.color = selectedColor;
theCell.style.cursor = "hand";
window.status = "Click to sort by '"+rTitle+"'";
} else {
theCell.style.color = defaultColor;
theCell.style.cursor = "";
window.status = "";
}
}
$(document).ready(function() {
// Set some location variales.
$('h1').append(': ' + location);
document.title += ': ' + location;
function sortTable(theCell, colNum, hdrRows, sortParams){
var typnum = !(sortParams & 1);
sDir = !(sortParams & 2);
var typhtml = !(sortParams & 4);
var typfreq = !(sortParams & 8);
var tBody = theCell.parentNode;
while(tBody.nodeName!="TBODY"){
tBody = tBody.parentNode;
}
var tabOrd = new Array();
if(tBody.rows[0].sCol==colNum) sDir = !tBody.rows[0].sDir;
if (tBody.rows[0].sCol>=0)
tBody.rows[0].cells[tBody.rows[0].sCol].className='';
tBody.rows[0].sCol = colNum;
tBody.rows[0].sDir = sDir;
if (sDir)
tBody.rows[0].cells[colNum].className='sortdown'
else
tBody.rows[0].cells[colNum].className='sortup';
for(i=0,r=hdrRows;r<tBody.rows.length;i++,r++){
colCont = tBody.rows[r].cells[colNum].innerHTML;
if(typhtml) colCont = colCont.replace(/<[^>]+>/g,'');
if(typnum) {
colCont*=1;
if(isNaN(colCont)) colCont = 0;
}
if(typfreq) {
switch(colCont.toLowerCase()) {
case "always": { colCont=0; break; }
case "hourly": { colCont=1; break; }
case "daily": { colCont=2; break; }
case "weekly": { colCont=3; break; }
case "monthly": { colCont=4; break; }
case "yearly": { colCont=5; break; }
case "never": { colCont=6; break; }
}
}
tabOrd[i] = [r, tBody.rows[r], colCont];
}
tabOrd.sort(compRows);
for(i=0,r=hdrRows;r<tBody.rows.length;i++,r++){
tBody.insertBefore(tabOrd[i][1],tBody.rows[r]);
}
window.status = "";
}
$('table').tablesorter({
sortList: [[0,0]],
widgets: ['zebra']
});
});
function compRows(a, b){
if(sDir){
if(a[2]>b[2]) return -1;
if(a[2]<b[2]) return 1;
} else {
if(a[2]>b[2]) return 1;
if(a[2]<b[2]) return -1;
}
return 0;
}
})(jQuery);
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