xmlsitemap_engines.module in XML sitemap 5.2
Same filename and directory in other branches
Defines actions for Google, Yahoo!, Ask, and Windows Live.
File
xmlsitemap_engines/xmlsitemap_engines.moduleView source
<?php
/**
* @file
* Defines actions for Google, Yahoo!, Ask, and Windows Live.
*/
/**
* @addtogroup xmlsitemap
* @{
*/
/**
* Implementation of hook_menu().
*/
function xmlsitemap_engines_menu($may_cache) {
$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,
);
}
}
return $items;
}
/**
* Implementation of hook_xmlsitemap_engines().
*/
function xmlsitemap_engines_xmlsitemap_engines($op) {
switch ($op) {
case 'form':
$form = array();
// Ask.com form.
$form['ask'] = array(
'#type' => 'fieldset',
'#title' => t('Ask.com'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['ask']['xmlsitemap_engines_ask_submit'] = array(
'#type' => 'checkbox',
'#title' => t('Submit the sitemap to Ask.com'),
'#default_value' => variable_get('xmlsitemap_engines_ask_submit', FALSE),
);
$form['ask']['xmlsitemap_engines_ask_url'] = array(
'#type' => 'textfield',
'#title' => t('Submission URL'),
'#default_value' => variable_get('xmlsitemap_engines_ask_url', 'http://submissions.ask.com/ping?sitemap=[sitemap]'),
'#description' => t('The URL to submit the sitemap to. Use %placeholder like placeholder for the sitemap URL.', array(
'%placeholder' => '[sitemap]',
)),
);
// Google 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 the sitemap to Google'),
'#default_value' => variable_get('xmlsitemap_engines_google_submit', FALSE),
);
$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=[sitemap]'),
'#description' => t('The URL to submit the sitemap to. Use %placeholder like placeholder for the sitemap URL.', array(
'%placeholder' => '[sitemap]',
)),
);
$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.'),
);
// Moreover.com form.
$form['moreover'] = array(
'#type' => 'fieldset',
'#title' => t('Moreover.com'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['moreover']['xmlsitemap_engines_moreover_submit'] = array(
'#type' => 'checkbox',
'#title' => t('Submit the sitemap to Moreover.com'),
'#default_value' => variable_get('xmlsitemap_engines_moreover_submit', FALSE),
);
$form['moreover']['xmlsitemap_engines_moreover_url'] = array(
'#type' => 'textfield',
'#title' => t('Submission URL'),
'#default_value' => variable_get('xmlsitemap_engines_moreover_url', 'http://api.moreover.com/ping?u=[sitemap]'),
'#description' => t('The URL to submit the sitemap to. Use %placeholder like placeholder for the sitemap URL.', array(
'%placeholder' => '[sitemap]',
)),
);
// Windows Live form.
$form['live'] = array(
'#type' => 'fieldset',
'#title' => t('Windows Live'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['live']['xmlsitemap_engines_live_submit'] = array(
'#type' => 'checkbox',
'#title' => t('Submit the sitemap to Windows Live'),
'#default_value' => variable_get('xmlsitemap_engines_live_submit', FALSE),
);
$form['live']['xmlsitemap_engines_live_url'] = array(
'#type' => 'textfield',
'#title' => t('Submission URL'),
'#default_value' => variable_get('xmlsitemap_engines_live_url', 'http://webmaster.live.com/ping.aspx?siteMap=[sitemap]'),
'#description' => t('The URL to submit the sitemap to. Use %placeholder like placeholder for the sitemap URL.', array(
'%placeholder' => '[sitemap]',
)),
);
$form['live']['xmlsitemap_engines_live_verify'] = array(
'#type' => 'textfield',
'#title' => t('Authentication file'),
'#default_value' => variable_get('xmlsitemap_engines_live_verify', 'LiveSearchSiteAuth.xml'),
'#description' => t('Before allowing you to view additional information, Windows Live will ask you to verify that you control this site by creating a file with a certain name. Enter that name here, and XML sitemap will create a path to that file name. This will only work if you have clean URLs enabled.'),
);
$form['live']['xmlsitemap_engines_live_verify_string'] = array(
'#type' => 'textfield',
'#title' => t('Authentication tag'),
'#default_value' => variable_get('xmlsitemap_engines_live_verify_string', ''),
'#description' => t('Windows Live will give you an authentication tag.'),
);
// Yahoo! form.
$form['yahoo'] = array(
'#type' => 'fieldset',
'#title' => t('Yahoo!'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['yahoo']['xmlsitemap_engines_yahoo_submit'] = array(
'#type' => 'checkbox',
'#title' => t('Submit the sitemap to Yahoo!'),
'#default_value' => variable_get('xmlsitemap_engines_yahoo_submit', FALSE),
);
$form['yahoo']['xmlsitemap_engines_yahoo_url'] = array(
'#type' => 'textfield',
'#title' => t('Submission URL'),
'#default_value' => variable_get('xmlsitemap_engines_yahoo_url', 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=[sitemap]'),
'#description' => t('The URL to submit the sitemap to. Use %placeholder like placeholder for the sitemap URL.', array(
'%placeholder' => '[sitemap]',
)),
);
$form['yahoo']['xmlsitemap_engines_yahoo_verify'] = array(
'#type' => 'textfield',
'#title' => t('Verification link'),
'#default_value' => variable_get('xmlsitemap_engines_yahoo_verify', ''),
'#description' => t('Before allowing you to view additional information, Yahoo! will ask you to verify that you control this site by creating a file with a certain name. Enter that name here, and XML sitemap will create a path to that file name. This will only work if you have clean URLs enabled.'),
);
$form['yahoo']['xmlsitemap_engines_yahoo_verify_string'] = array(
'#type' => 'textfield',
'#title' => t('Authentication key'),
'#default_value' => variable_get('xmlsitemap_engines_yahoo_verify_string', ''),
'#description' => t('Yahoo! will ask you to put an authentication key in the verification file.'),
);
return $form;
case 'ping':
// Ask.com.
if (variable_get('xmlsitemap_engines_ask_submit', FALSE)) {
xmlsitemap_engines_submit_sitemap('Ask.com', 'xmlsitemap_engines_ask_url', 'http://submissions.ask.com/ping?sitemap=[sitemap]');
}
// Google.
if (variable_get('xmlsitemap_engines_google_submit', FALSE)) {
xmlsitemap_engines_submit_sitemap('Google', 'xmlsitemap_engines_google_url', 'http://www.google.com/webmasters/tools/ping?sitemap=[sitemap]');
}
// Moreover.com.
if (variable_get('xmlsitemap_engines_moreover_submit', FALSE)) {
xmlsitemap_engines_submit_sitemap('Moreover.com', 'xmlsitemap_engines_moreover_url', 'http://api.moreover.com/ping?u=[sitemap]');
}
// Windows Live.
if (variable_get('xmlsitemap_engines_ask_submit', FALSE)) {
xmlsitemap_engines_submit_sitemap('Windows Live', 'xmlsitemap_engines_live_url', 'http://webmaster.live.com/ping.aspx?siteMap=[sitemap]');
}
// Yahoo!.
if (variable_get('xmlsitemap_engines_yahoo_submit', FALSE)) {
xmlsitemap_engines_submit_sitemap('Yahoo!', 'xmlsitemap_engines_yahoo_url', 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=[sitemap]');
}
break;
case 'access':
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== FALSE) {
return 'Sitemap downloaded by Google.';
}
}
}
/*****************************************************************************
* Menu callbaks / form builders.
****************************************************************************/
/*
* Menu callback; display verification page.
*/
function xmlsitemap_engines_verify($engine) {
switch ($engine) {
case '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', '');
break;
case 'live':
print '<?xml version="1.0"?>' . "\n";
print "<users>\n";
print ' <user>' . variable_get('xmlsitemap_engines_live_verify_string', '') . "</user>\n";
print "</users>\n";
break;
}
drupal_page_footer();
exit;
}
/*****************************************************************************
* Public functions.
****************************************************************************/
/**
* Submit the sitemap to the selected engine, and log the result.
*
* @param $engine
* The identifier for the search engine.
* @param $url_var
* The variable name containing the submission URL used by the search engine.
* @param $default_url
* The default submission URL.
*/
function xmlsitemap_engines_submit_sitemap($engine, $url_var, $default_url) {
$url = strtr(variable_get($url_var, $default_url), array(
'[sitemap]' => url('sitemap.xml', NULL, NULL, TRUE),
));
$result = drupal_http_request($url);
if ($result->code == 200) {
watchdog('xmlsitemap', t('The sitemap has been successfully submitted to !engine.', array(
'!engine' => $engine,
)));
}
else {
watchdog('xmlsitemap', t('An error occurred while submitting the sitemap to !engine: !code', array(
'!engine' => $engine,
'!code' => 0 + $result->code,
)), WATCHDOG_ERROR);
}
}
/**
* @} End of "addtogroup xmlsitemap".
*/
Functions
Name![]() |
Description |
---|---|
xmlsitemap_engines_menu | Implementation of hook_menu(). |
xmlsitemap_engines_submit_sitemap | Submit the sitemap to the selected engine, and log the result. |
xmlsitemap_engines_verify | |
xmlsitemap_engines_xmlsitemap_engines | Implementation of hook_xmlsitemap_engines(). |