hook_xmlsitemap_engines($op, $type = NULL)
contributions/modules/xmlsitemap/docs/xmlsitemap.php, line 171
Define actions for search engines.
$op:
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
| XML Sitemap | Notify search engines of site updates. |
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));
}
break;
}
}