You are here

function _xmlsitemap_engines_google in XML sitemap 5

Define actions for Google.

Related topics

1 call to _xmlsitemap_engines_google()
xmlsitemap_engines_xmlsitemap_engines in xmlsitemap_engines/xmlsitemap_engines.module
Implementation of hook_xmlsitemap_engines().

File

xmlsitemap_engines/xmlsitemap_engines.module, line 40
Define actions for Google, Yahoo!, Ask, and Bing.

Code

function _xmlsitemap_engines_google($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', 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=' . 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', 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.'));
        }
        else {
          watchdog('xmlsitemap', t('Error occurred submitting sitemap to Google: @code', array(
            '@code' => $result->code,
          )), WATCHDOG_ERROR);
        }
      }
      break;
    case 'access':
      return t('!sitemap downloaded by Google.', array(
        '!sitemap' => $type,
      ));
  }
}