Commit 7de70475 authored by Darren Oh's avatar Darren Oh

#157533 by Freso, DenRaf, hswong3i, chantra, wayland76: Updated to work with Drupal 6.

parent aa71d265
......@@ -8,7 +8,11 @@ Installation Instructions:
1. Place the xmlsitemap directory in sites/all/modules.
2. Enable this module at Administer -> Site building -> Modules.
2. Go to the XML Sitemap section at
http://www.example.com/?q=admin/build/modules and enable the modules for the
types of links you want in your site map. Enable XML Sitemap: Engines if you
want to be able to automatically submit your site map to search engines.
3. The sitemap is now operational at ?q=sitemap.xml. Configure advanced
options at Administer -> Site configuration -> XML Sitemap.
3. The sitemap is now operational at http://www.example.com/?q=sitemap.xml.
Configure advanced options at
http://www.example.com/?q=admin/settings/xmlsitemap.
......@@ -5,28 +5,36 @@ 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.
The XML Sitemap module creates an XML site map at
http://www.example.com/?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.
SPECIALIZED SITE MAPS
---------------------
You can create specialized site maps using Views. To do so, enable both Views
and XML Sitemap: Node and create a new view. In the Page settings, choose XML
Sitemap: Sitemap as the view type for a regular site map or XML Sitemap: News
for a Google News site map.
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.
configured at http://www.example.com/?q=admin/settings/xmlsitemap/engines.
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
http://webmaster.live.com/
http://www.google.com/webmasters/sitemap (Google)
http://developer.yahoo.com/search/siteexplorer/V1/ping.html (Yahoo!)
http://webmaster.live.com/ (Windows Live)
......@@ -173,10 +173,10 @@ function hook_xmlsitemap_engines($op, $type = NULL) {
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.'));
watchdog('xmlsitemap', 'Sitemap successfully submitted to Google.');
}
else {
watchdog('xmlsitemap', t('Error occurred submitting sitemap to Google: @code', array('@code' => $result->code)), WATCHDOG_ERROR);
watchdog('xmlsitemap', 'Error occurred submitting sitemap to Google: @code', array('@code' => $result->code), WATCHDOG_ERROR);
}
}
break;
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,4 +2,4 @@
name = XML Sitemap
description = Creates an XML site map in accordance with the sitemaps.org specification.
package = XML Sitemap
core = 6.x
<?php
// $Id$
/**
* Implementation of hook_schema().
*/
function xmlsitemap_schema() {
$schema['xmlsitemap_additional'] = array(
'description' => t('The base table for xmlsitemap.'),
'fields' => array(
'path' => array(
'description' => t('The path of this node.'),
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'pid' => array(
'description' => t('The id of the path.'),
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
),
'last_changed' => array(
'description' => t('Keeps track of new changes.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'previously_changed' => array(
'description' => t('Keeps track of old changes.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'priority' => array(
'description' => t('Stores the index value.'),
'type' => 'float',
'not null' => FALSE,
),
),
'indexes' => array(
'pid' => array('pid'),
),
'primary key' => array('path'),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function xmlsitemap_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {xmlsitemap_additional} (
path varchar(128) NOT NULL default '',
pid int,
last_changed int(11),
previously_changed int(11),
priority float,
PRIMARY KEY (path)
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {xmlsitemap_additional} (
path varchar(128) NOT NULL default '',
pid integer,
last_changed integer,
previously_changed integer,
priority real,
PRIMARY KEY (path)
);");
break;
}
// Create my tables.
db_query("DELETE FROM {url_alias} WHERE dst LIKE 'sitemap%.xml'");
drupal_install_schema('xmlsitemap');
}
/**
* Implementation of hook_uninstall().
*/
function xmlsitemap_uninstall() {
// Drop my tables.
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'xmlsitemap\_%'");
while ($variable = db_fetch_object($settings)) {
variable_del($variable->name);
}
drupal_uninstall_schema('xmlsitemap');
}
/**
......@@ -49,6 +89,52 @@ function xmlsitemap_enable() {
if (file_check_directory(($path = file_directory_path() .'/xmlsitemap'), FILE_CREATE_DIRECTORY)) {
file_save_data($xsl, "$path/gss.xsl", FILE_EXISTS_REPLACE);
}
_xmlsitemap_gsitemap_replace();
}
/**
* Replace Google Sitemap if it is installed.
*/
function _xmlsitemap_gsitemap_replace() {
if (db_result(db_query("
SELECT 1 FROM {system}
WHERE type = 'module' AND name = 'gsitemap' AND (status = 1 OR schema_version >= 0)
"))) {
db_query("
INSERT INTO {xmlsitemap_additional} (path, pid, last_changed, previously_changed, priority)
SELECT path, pid, last_changed, previously_changed, priority FROM {gsitemap_additional}
");
$modules = array('xmlsitemap_node', 'xmlsitemap_engines');
if (variable_get('gsitemap_showterms', FALSE)) {
$modules[] = 'xmlsitemap_term';
variable_del('gsitemap_showterms');
}
if (variable_get('gsitemap_showusers', FALSE)) {
$modules[] = 'xmlsitemap_user';
variable_del('gsitemap_showusers');
}
drupal_install_modules($modules);
$settings = db_query("SELECT * FROM {variable} WHERE name LIKE 'gsitemap\_%'");
while ($variable = db_fetch_object($settings)) {
switch ($variable->name) {
case 'gsitemap_frontpage':
$name = 'xmlsitemap_front_page_priority';
break;
case 'gsitemap_priority':
$name = 'xmlsitemap_additional_links_priority';
break;
case 'gsitemap_logacc':
$name = 'xmlsitemap_log_access';
break;
default:
$name = 'xmlsitemap'. strstr($variable->name, '_');
break;
}
variable_set($name, (float) unserialize($variable->value));
}
module_disable(array('gsitemap'));
drupal_uninstall_module('gsitemap');
}
}
/**
......@@ -66,15 +152,3 @@ function xmlsitemap_disable() {
rmdir($path);
}
}
/**
* Implementation of hook_uninstall().
*/
function xmlsitemap_uninstall() {
db_query("DROP TABLE {xmlsitemap_additional}");
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'xmlsitemap\_%'");
while ($variable = db_fetch_object($settings)) {
variable_del($variable->name);
}
}
This diff is collapsed.
......@@ -2,5 +2,5 @@
name = XML Sitemap: Engines
description = Submits site map to search engines.
package = XML Sitemap
dependencies = xmlsitemap
dependencies[] = xmlsitemap
core = "6.x"
<?php
// $Id$
/**
* Implementation of hook_install().
*/
function xmlsitemap_engines_install() {
if (db_result(db_query("
SELECT 1 FROM {system}
WHERE type = 'module' AND name = 'gsitemap' AND (status = 1 OR schema_version >= 0)
"))) {
$settings = db_query("SELECT * FROM {variable} WHERE name LIKE 'gsitemap\_%\_submit'");
while ($variable = db_fetch_object($settings)) {
$ts = strlen('gsitemap_');
$tl = strpos($variable->name, '_com_submit') === FALSE ? strlen('_submit') : strlen('_com_submit');
variable_set('xmlsitemap_engines_'. substr($variable->name, $ts, -$tl) .'_submit', unserialize($variable->value));
variable_del($variable->name);
}
$settings = db_query("SELECT * FROM {variable} WHERE name LIKE 'gsitemap\_%\_url'");
while ($variable = db_fetch_object($settings)) {
$ts = strlen('gsitemap_');
$tl = strpos($variable->name, '_com_url') === FALSE ? strlen('_url') : strlen('_com_url');
variable_set('xmlsitemap_engines_'. substr($variable->name, $ts, -$tl) .'_url', unserialize($variable->value));
variable_del($variable->name);
}
$settings = db_query("SELECT * FROM {variable} WHERE name LIKE 'gsitemap\_%verify%'");
while ($variable = db_fetch_object($settings)) {
$ts = strlen('gsitemap_');
$tl = strpos($variable->name, '_verify');
$engine = $tl === FALSE ? 'google' : substr($variable->name, $ts, $tl - $ts);
variable_set("xmlsitemap_engines_${engine}". strstr($variable->name, '_verify'), unserialize($variable->value));
variable_del($variable->name);
}
}
}
/**
* Implementation of hook_uninstall().
*/
......@@ -11,3 +44,21 @@ function xmlsitemap_engines_uninstall() {
}
}
/**
* Implementation of hook_update_N().
*
* Replace Moreover with Windows Live.
*/
function xmlsitemap_engines_update_1() {
$ret = array();
$submit = db_result(db_query("SELECT value FROM {variable} WHERE name = 'xmlsitemap_engines_moreover_submit'"));
if ($submit !== FALSE) {
variable_set('xmlsitemap_engines_live_submit', $submit);
}
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'xmlsitemap\_engines\_moreover\_'");
while ($variable = db_fetch_object($settings)) {
variable_del($variable->name);
}
return $ret;
}
......@@ -64,10 +64,10 @@ function _xmlsitemap_engines_google($op, $type = NULL) {
if (variable_get('xmlsitemap_engines_google_submit', FALSE)) {
$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.'));
watchdog('xmlsitemap', 'Sitemap successfully submitted to Google.');
}
else {
watchdog('xmlsitemap', t('Error occurred submitting sitemap to Google: @code', array('@code' => $result->code)), WATCHDOG_ERROR);
watchdog('xmlsitemap', 'Error occurred submitting sitemap to Google: @code', array('@code' => $result->code), WATCHDOG_ERROR);
}
}
break;
......@@ -77,7 +77,7 @@ function _xmlsitemap_engines_google($op, $type = NULL) {
}
/**
* Define actions for Yahoo!
* Define actions for Yahoo!.
*/
function _xmlsitemap_engines_yahoo($op) {
switch ($op) {
......@@ -90,7 +90,7 @@ function _xmlsitemap_engines_yahoo($op) {
);
$form['yahoo']['xmlsitemap_engines_yahoo_submit'] = array(
'#type' => 'checkbox',
'#title' => t('Submit site map to Yahoo!.'),
'#title' => t('Submit site map to Yahoo!'),
'#default_value' => variable_get('xmlsitemap_engines_yahoo_submit', FALSE),
);
$form['yahoo']['xmlsitemap_engines_yahoo_url'] = array(
......@@ -116,10 +116,10 @@ function _xmlsitemap_engines_yahoo($op) {
if (variable_get('xmlsitemap_engines_yahoo_submit', FALSE)) {
$result = drupal_http_request(variable_get('xmlsitemap_engines_yahoo_url', 'http://search.yahooapis.com/SiteExplorerService/V1/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('Site map successfully submitted to Yahoo!.'));
watchdog('xmlsitemap', 'Site map successfully submitted to Yahoo!.');
}
else {
watchdog('xmlsitemap', t('Error occurred submitting site map to Yahoo!: @code', array('@code' => $result->code)), WATCHDOG_ERROR);
watchdog('xmlsitemap', 'Error occurred submitting site map to Yahoo!: @code', array('@code' => $result->code), WATCHDOG_ERROR);
}
}
break;
......@@ -154,10 +154,10 @@ function _xmlsitemap_engines_ask($op) {
if (variable_get('xmlsitemap_engines_ask_submit', FALSE)) {
$result = drupal_http_request(variable_get('xmlsitemap_engines_ask_url', 'http://submissions.ask.com/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('Site map successfully submitted to Ask.com.'));
watchdog('xmlsitemap', 'Site map successfully submitted to Ask.com.');
}
else {
watchdog('xmlsitemap', t('Error occurred submitting site map to Ask.com: @code', array('@code' => $result->code)), WATCHDOG_ERROR);
watchdog('xmlsitemap', 'Error occurred submitting site map to Ask.com: @code', array('@code' => $result->code), WATCHDOG_ERROR);
}
}
break;
......@@ -204,10 +204,10 @@ function _xmlsitemap_engines_live($op) {
if (variable_get('xmlsitemap_engines_live_submit', FALSE)) {
$result = drupal_http_request(variable_get('xmlsitemap_engines_live_url', 'http://webmaster.live.com/ping.aspx?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('Site map successfully submitted to Windows Live.'));
watchdog('xmlsitemap', 'Site map successfully submitted to Windows Live.');
}
else {
watchdog('xmlsitemap', t('Error occurred submitting site map to Windows Live: @code', array('@code' => $result->code)), WATCHDOG_ERROR);
watchdog('xmlsitemap', 'Error occurred submitting site map to Windows Live: @code', array('@code' => $result->code), WATCHDOG_ERROR);
}
}
break;
......@@ -217,41 +217,37 @@ function _xmlsitemap_engines_live($op) {
/**
* Implementation of hook_menu().
*/
function xmlsitemap_engines_menu($may_cache) {
function xmlsitemap_engines_menu() {
$items = array();
$access_content = user_access('access content');
if ($may_cache) {
if ($verify = variable_get('xmlsitemap_engines_google_verify', '')) {
$items[] = array(
'path' => $verify,
'title' => t('Google verification page'),
'callback' => '_xmlsitemap_engines_verify',
'callback arguments' => array('google'),
'type' => MENU_CALLBACK,
'access' => $access_content,
);
}
if (($verify = variable_get('xmlsitemap_engines_yahoo_verify', '')) != '') {
$items[] = array(
'path' => $verify,
'title' => t('Yahoo! verification page'),
'callback' => '_xmlsitemap_engines_verify',
'callback arguments' => array('yahoo'),
'type' => MENU_CALLBACK,
'access' => $access_content,
);
}
if (($verify = variable_get('xmlsitemap_engines_live_verify', 'LiveSearchSiteAuth.xml')) != '') {
$items[] = array(
'path' => $verify,
'title' => t('Windows Live verification page'),
'callback' => '_xmlsitemap_engines_verify',
'callback arguments' => array('live'),
'type' => MENU_CALLBACK,
'access' => $access_content,
);
}
$access_content = array('access content');
if ($verify = variable_get('xmlsitemap_engines_google_verify', '')) {
$items[$verify] = array(
'title' => 'Google verification page',
'page callback' => '_xmlsitemap_engines_verify',
'page arguments' => array('google'),
'type' => MENU_CALLBACK,
'access arguments' => $access_content,
);
}
if (($verify = variable_get('xmlsitemap_engines_yahoo_verify', '')) != '') {
$items[$verify] = array(
'title' => 'Yahoo! verification page',
'page callback' => '_xmlsitemap_engines_verify',
'page arguments' => array('yahoo'),
'type' => MENU_CALLBACK,
'access arguments' => $access_content,
);
}
if (($verify = variable_get('xmlsitemap_engines_live_verify', 'LiveSearchSiteAuth.xml')) != '') {
$items[$verify] = array(
'title' => 'Windows Live verification page',
'page callback' => '_xmlsitemap_engines_verify',
'page arguments' => array('live'),
'type' => MENU_CALLBACK,
'access arguments' => $access_content,
);
}
return $items;
}
......@@ -261,7 +257,14 @@ function xmlsitemap_engines_menu($may_cache) {
function _xmlsitemap_engines_verify($engine) {
switch ($engine) {
case 'google':
print 'Hello, Google!';
print '<html>'."\n";
print ' <head>'."\n";
print ' <title>Hello, Google!</title>'."\n";
print ' </head>'."\n";
print ' <body>'."\n";
print ' <p>Hello, Google!</p>'."\n";
print ' </body>'."\n";
print '</html>'."\n";
break;
case 'yahoo':
print variable_get('xmlsitemap_engines_yahoo_verify_string', '');
......
......@@ -2,5 +2,5 @@
name = XML Sitemap: Node
description = Adds nodes to the site map.
package = XML Sitemap
dependencies = xmlsitemap
dependencies[] = xmlsitemap
core = "6.x"
<?php
// $Id$
/**
* Implementation of hook_requirements().
*/
function xmlsitemap_node_requirements($phase) {
$t = get_t();
$requirements = array();
if (in_array($GLOBALS['db_type'], array('mysql', 'mysqli')) && version_compare(db_version(), '4.0.14') < 0) {
$requirements['xmlsitemap_node_sql'] = array(
'title' => $t('XML Sitemap: Node'),
'value' => $t('Your MySQL version is too low. &ldquo;XML Sitemap: Node&rdquo; requires MySQL 4.0.14 or higher.'),
'severity' => REQUIREMENT_ERROR,
);
}
return $requirements;
}
/**
* Implementation of hook_install().
*/
function xmlsitemap_node_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {xmlsitemap_node} (
nid int,
pid int,
last_changed int(11),
previously_changed int(11),
last_comment int(11),
previous_comment int(11),
priority_override float,
PRIMARY KEY (nid)
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {xmlsitemap_node} (
nid integer,
pid integer,
last_changed integer,
previously_changed integer,
last_comment integer,
previous_comment integer,
priority_override real,
PRIMARY KEY (nid)
);");
break;
drupal_install_schema('xmlsitemap_node');
_xmlsitemap_node_gsitemap_replace();
}
/**
* Implementation of hook_schema().
*/
function xmlsitemap_node_schema() {
$schema['xmlsitemap_node'] = array(
'description' => t('The base table for xmlsitemap.'),
'fields' => array(
'nid' => array(
'description' => t('The path of this node.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'pid' => array(
'description' => t('The id of the path.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
),
'last_changed' => array(
'description' => t('Keeps track of new changes.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'previously_changed' => array(
'description' => t('Keeps track of old changes.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'last_comment' => array(
'description' => t('Link to last comment.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'previous_comment' => array(
'description' => t('Link to previous comment.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
),
'priority_override' => array(
'description' => t('Stores the index value.'),
'type' => 'float',
'not null' => FALSE,
),
),
'indexes' => array(
'pid' => array('pid'),
),
'primary key' => array('nid'),
);
return $schema;
}
/**
* Transfer data from Google Sitemap if it is installed.
*/
function _xmlsitemap_node_gsitemap_replace() {
if (db_result(db_query("
SELECT 1 FROM {system}
WHERE type = 'module' AND name = 'gsitemap' AND (status = 1 OR schema_version >= 0)
"))) {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("
UPDATE {xmlsitemap_node} xn, {url_alias} ua SET xn.pid = ua.pid
WHERE xn.pid IS NULL AND ua.src = CONCAT('node/', CAST(xn.nid AS CHAR))
");
break;
case 'pgsql':
db_query("
UPDATE {xmlsitemap_node} SET pid = {url_alias}.pid FROM {url_alias}
WHERE {xmlsitemap_node}.pid IS NULL AND {url_alias}.src = CONCAT('node/', CAST(nid AS VARCHAR))
");
break;
}
db_query("
INSERT INTO {xmlsitemap_node} (nid, pid, last_changed, previously_changed, last_comment, previous_comment, priority_override)
SELECT nid, pid, last_changed, previously_changed, last_comment, previous_comment, priority_override FROM {gsitemap}
");
$settings = db_query("SELECT * FROM {variable} WHERE name LIKE 'gsitemap\_%wt'");
while ($variable = db_fetch_object($settings)) {
$ts = strlen('gsitemap_');
$tl = strlen('wt');
$type = substr($variable->name, $ts, -$tl);