Commit 130d0c0a authored by Darren Oh's avatar Darren Oh

Replacement for gsitemap

parents
$Id$
XML Sitemap Module
If you are upgrading from Google Sitemap, make sure you are using the latest
version.
Installation Instructions:
1. Place the xmlsitemap directory in sites/all/modules.
2. Enable this module at Administer -> Site building -> Modules.
3. The sitemap is now operational at ?q=sitemap.xml. Configure advanced
options at Administer -> Site configuration -> XML Sitemap.
$Id$
XML Sitemap Module
Author: Matthew Loar <matthew at loar dot name>
This module was originally written as part of Google Summer of Code 2005.
DESCRIPTION
-----------
The XML Sitemap module creates an XML site map at ?q=sitemap.xml that
conforms to the sitemaps.org specification. It provides many options for
customizing the data reported in the site map.
INSTALLATION
------------
See INSTALL.txt in this directory.
KNOWN ISSUES
------------
Users who have not enabled clean URLs have reported receiving an
"Unsupported file format" error from Google. The solution is to replace
"?q=sitemap.xml" at the end of the submission URL with
"index.php?q=sitemap.xml". Submission URLs for each search engine can be
configured at Administer -> Site configuration -> XML Sitemap.
MORE INFORMATION
----------------
The Sitemap protocol: http://sitemaps.org.
Search engines:
http://www.google.com/webmasters/sitemap
http://developer.yahoo.com/search/siteexplorer/V1/ping.html
Site maps may be manually submitted to MSN by visiting
http://search.msn.com/docs/submit.aspx and submitting the URL of the site
map.
<?php
// $Id$
/**
* @addtogroup hooks
* @{
*/
/**
* Define additional links to add to the site map.
*
* This hook allows modules to add additional links to the site map. Links
* may be associated with nodes, terms, or users, as shown in the example.
* @param $type:
* If set, a string specifying the type of additional links to return.
* - node:
* Links associated with nodes
* - term:
* Links associated with terms
* - user:
* Links associated with users
* - xml:
* An XML site map (for including site maps from other modules)
* You can define additional types by adding them to the switch statement.
* @param $excludes:
* Depends on the type of links being requested.
* - For "node", an array of excluded node types
* - For "term", an array of excluded vocabularies
* - For "user", an array of included roles
* @return
* If $type is xml, return an XML site map. Otherwise, return an array of
* links or an empty array. Each link should be an array with the
* following keys:
* - nid, tid, or uid:
* ID to associate with this link (if $type is set)
* - #loc:
* The URL of the page
* - #lastmod:
* Timestamp of last modification
* - #changefreq:
* Number of seconds between changes
* - #priority:
* A number between 0 and 1 indicating the link's priority
* If you have defined your own link type, use the ID key to group related
* links together.
*/
function hook_xmlsitemap_links($type = NULL, $excludes = array()) {
$links = array();
switch ($type) {
case 'node':
break;
case 'term':
break;
case 'user':
// Load profiles.
$result = db_query("
SELECT u.uid, xu.last_changed, xu.previously_changed, xu.priority_override, SUM(xur.priority), ua.dst AS alias
FROM {users} u
LEFT JOIN {users_roles} ur ON ur.uid = u.uid
LEFT JOIN {xmlsitemap_user_role} xur ON xur.rid = ur.rid
LEFT JOIN {xmlsitemap_user} xu ON xu.uid = u.uid
LEFT JOIN {url_alias} ua ON ua.pid = xu.pid
WHERE (xu.priority_override IS NULL OR xu.priority_override >= 0)
AND u.uid <> %d
GROUP BY u.uid HAVING MIN(xur.priority) <> -1
", _xmlsitemap_user_frontpage());
// Create link array for each profile.
while ($user = db_fetch_object($result)) {
$age = time() - $user->last_changed;
$interval = empty($user->previously_changed) ? 0 : $user->last_changed - $user->previously_changed;
$links[] = array(
'uid' => $user->uid,
'#loc' => xmlsitemap_url("user/$user->uid", $user->alias, NULL, NULL, TRUE),
'#lastmod' => $user->last_changed,
'#changefreq' => max($age, $interval),
'#priority' => _xmlsitemap_user_priority($user),
);
}
// Add other user links to the links array.
$links = array_merge($links, module_invoke_all('xmlsitemap_links', 'user'));
// Sort links by user ID and URL.
foreach ($links as $key => $link) {
$uid[$key] = $link['uid'];
$loc[$key] = $link['#loc'];
}
array_multisort($uid, $loc, $links);
case 'xml':
// Retrieve an XML site map.
$links = example_sitemap();
break;
default:
// Add arbitrary additional links.
$result = db_query("
SELECT xa.*, ua.dst AS alias FROM {xmlsitemap_additional} xa
LEFT JOIN {url_alias} ua ON xa.pid = ua.pid
");
while ($link = db_fetch_object($result)) {
$age = time() - $link->last_changed;
if (!empty($link->previously_changed)) {
$interval = $link->last_changed - $link->previously_changed;
}
else {
$interval = 0;
}
$entry = array(
'#loc' => xmlsitemap_url($link->path, $link->alias, NULL, NULL, TRUE),
'#lastmod' => $link->last_changed,
'#changefreq' => max($age, $interval),
'#priority' => $link->priority,
);
$additional[] = $entry;
}
break;
}
return $links;
}
/**
* Define actions for search engines.
* @param $op:
* - form:
* Add search engine to form at admin/settings/xmlsitemap.
* - ping:
* Submit site map to search engine.
* - access:
* Log search engine access.
* @param $type:
* If $op is 'access', one of the following strings will indicate what was
* downloaded:
* - Site map:
* The site map was downloaded.
* - Site map index
* The site map index was downloaded.
* - Site map $chunk
* Chunk $chunk was downloaded.
* @return
* - form:
* Array of form elements for search engine settings
* - ping:
* Nothing
* - access:
* Message string for access log
*/
function hook_xmlsitemap_engines($op, $type = NULL) {
switch ($op) {
case 'form':
$form['google'] = array(
'#type' => 'fieldset',
'#title' => t('Google'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['google']['xmlsitemap_engines_google_submit'] = array(
'#type' => 'checkbox',
'#title' => t('Submit site map to Google.'),
'#default_value' => variable_get('xmlsitemap_engines_google_submit', TRUE),
);
$form['google']['xmlsitemap_engines_google_url'] = array(
'#type' => 'textfield',
'#title' => t('Submission URL'),
'#default_value' => variable_get('xmlsitemap_engines_google_url', 'http://www.google.com/webmasters/tools/ping?sitemap='. xmlsitemap_url('sitemap.xml', drupal_lookup_path('alias', 'sitemap.xml') ? drupal_lookup_path('alias', 'sitemap.xml') : NULL, NULL, NULL, TRUE)),
'#description' => t('The URL to submit the site map to.'),
);
$form['google']['xmlsitemap_engines_google_verify'] = array(
'#type' => 'textfield',
'#title' => t('Verification link'),
'#default_value' => variable_get('xmlsitemap_engines_google_verify', ''),
'#description' => t('In order to show statistics, Google will ask you to verify that you control this site by creating a file with a certain name. Enter that name here and the XML Sitemap module will create a path to that file name. This will only work if you have clean URLs enabled.'),
);
return $form;
case 'ping':
if (variable_get('xmlsitemap_engines_google_submit', TRUE)) {
$result = drupal_http_request(variable_get('xmlsitemap_engines_google_url', 'http://www.google.com/webmasters/tools/ping?sitemap='. xmlsitemap_url('sitemap.xml', drupal_lookup_path('alias', 'sitemap.xml') ? drupal_lookup_path('alias', 'sitemap.xml') : NULL, NULL, NULL, TRUE)));
if ($result->code == 200) {
watchdog('xmlsitemap', t('Sitemap successfully submitted to Google.'));
}
else {
watchdog('xmlsitemap', t('Error occurred submitting sitemap to Google: @code', array('@code' => $result->code)), WATCHDOG_ERROR);
}
}
break;
case 'access':
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== FALSE) {
return t('!sitemap downloaded by Google.', array('!sitemap' => $type));
}
}
}
/**
* @} End of "addtogroup hooks".
*/
/* $Id$ */
body {
margin-top: 0;
background-color: #fff;
}
body, td, th {
font-family: arial,sans-serif;
font-size: 13px;
}
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(sortup.gif);
background-repeat: no-repeat;
font-style: italic;
white-space: pre;
}
.sortdown {
background-position: right center;
background-image: url(sortdown.gif);
background-repeat: no-repeat;
font-style: italic;
white-space: pre;
}
// $Id$
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, 1, 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 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';
}
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 = "";
}
}
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 = "";
}
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;
}
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="iso-8859-1" indent="yes"/>
<!-- Root template -->
<xsl:template match="/">
<html>
<head>
<title>Site map file</title>
<link href="gss.css" type="text/css" rel="stylesheet"/>
<script src="gss.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:choose>
</xsl:variable>
<!-- Body -->
<body onLoad="initXsl('table0','{$fileType}');">
<!-- Text and table -->
<h1 id="head1">Site map 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>
</html>
</xsl:template>
<!-- siteindexTable template -->
<xsl:template name="siteindexTable">
<h2>Number of site maps 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>Site map 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>
</table>
</xsl:template>
<!-- sitemapTable template -->
<xsl:template name="sitemapTable">
<h2>Number of URLs in this site map: <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>Site map URL</td>
<td>Last modification date</td>
<td>Change freq.</td>
<td>Priority</td>
</tr>
<xsl:apply-templates select="sitemap:urlset/sitemap:url">
<xsl:sort select="sitemap:priority" order="descending"/>
</xsl:apply-templates>
</table>
</xsl:template>
<!-- sitemap:url template -->
<xsl:template match="sitemap:url">
<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>
</td>
<td><xsl:value-of select="sitemap:lastmod"/></td>
<td><xsl:value-of select="sitemap:changefreq"/></td>
<td><xsl:value-of select="sitemap:priority"/></td>
</tr>
</xsl:template>
<!-- sitemap:sitemap template -->
<xsl:template match="sitemap:sitemap">
<tr>
<td>
<xsl:variable name="sitemapURL"><xsl:value-of select="sitemap:loc"/></xsl:variable>
<a href="{$sitemapURL}"><xsl:value-of select="$sitemapURL"></xsl:value-of></a>
</td>
<td><xsl:value-of select="sitemap:lastmod"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
# Danish translation of Drupal (gsitemap.module)
# Copyright 2006 Morten Wulff <wulff@tem.dtu.dk>
msgid ""
msgstr ""
"Project-Id-Version: Danish translation of Drupal (gsitemap.module) $Id$\n"
"POT-Creation-Date: 2006-04-07 15:29+0200\n"
"PO-Revision-Date: 2006-04-07 15:58+0100\n"
"Last-Translator: Morten Wulff <wulff@psyke.org>\n"
"Language-Team: Danish <dansk@dansk-gruppen.dk>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-Language: Danish\n"
"X-Poedit-Country: DENMARK\n"
#: gsitemap.module:15
msgid "Creates a Google Sitemap at q=gsitemap"
msgstr "Opretter et Google Sitemap på q=gsitemap"
#: gsitemap.module:17
msgid "The following options allow you to alter the behavior of the Google Sitemap module."
msgstr "De følgende indstillinger lader dig ændre hvordan Google Sitemap-modulet opfører sig."
#: gsitemap.module:37;402;405;443;446;0
msgid "gsitemap"
msgstr "gsitemap"
#: gsitemap.module:43
msgid "gsitemap verification page"
msgstr "Efterprøv gsitemap"
#: gsitemap.module:59
msgid "gsitemap Settings"
msgstr "Indstillinger for gsitemap"
#: gsitemap.module:65
msgid "Priority override"
msgstr "Tilsidesæt prioritet"
#: gsitemap.module:69
msgid "Optionally specify a value for the priority in the Google Sitemap, or -1 to prevent it from appearing in the sitemap."
msgstr "Angiv en værdi for prioriteten i Google Sitemap (valgfrit) eller -1 for at forhindre at indholdet optræder på sidekortet."
#: gsitemap.module:132
msgid "Priority must be a number between 0.0 and 1.0, inclusive, or -1 to prevent this node from appearing in the sitemap."
msgstr "Prioriteten skal være et tal mellem 0.0 og 1.0, inklusive, eller -1 for at forhindre at dette indhold optræder på sidekortet."
#: gsitemap.module:187
msgid "Priority Settings"
msgstr "Prioritetsindstillinger"
#: gsitemap.module:192
msgid "Front page priority"
msgstr "Forsideprioritet"
#: gsitemap.module:196
msgid "This is the absolute priority for the front page. Values can range between 0.0 and 1.0."
msgstr "Forsidens absolutte prioritet. Værdier kan være mellem 0.0 og 1.0."
#: gsitemap.module:200
msgid "Promotion adjustment"
msgstr "Juster forfremmelse"
#: gsitemap.module:204
msgid "This number will be added to the priority of each node that is promoted to the front page."