You are here

function hook_xmlsitemap_engines in XML sitemap 5

Define actions for search engines.

Parameters

$op::

  • form: Add search engine to form at admin/settings/xmlsitemap.
  • ping: Submit site map to search engine.
  • access: Log search engine access.

$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 value

  • form: Array of form elements for search engine settings
  • ping: None
  • access: Message string for access log

Related topics

1 function implements hook_xmlsitemap_engines()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

xmlsitemap_engines_xmlsitemap_engines in xmlsitemap_engines/xmlsitemap_engines.module
Implementation of hook_xmlsitemap_engines().
3 invocations of hook_xmlsitemap_engines()
xmlsitemap_settings_engines in ./xmlsitemap.module
Menu callback; return search engine settings form.
_xmlsitemap_output in ./xmlsitemap.module
Menu callback; display the site map.
_xmlsitemap_ping in ./xmlsitemap.module
Submit the site map to search engines.

File

docs/xmlsitemap.php, line 154
XML Sitemap API documentation

Code

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;
  }
}