[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/xmlsitemap/xmlsitemap_engines/ -> xmlsitemap_engines.module (source)

   1  <?php
   2  // $Id: xmlsitemap_engines.module,v 1.5.2.12.2.25 2010/04/15 16:12:30 davereid Exp $
   3  
   4  /**
   5   * Implements hook_help().
   6   */
   7  function xmlsitemap_engines_help($path, $arg) {
   8    $output = '';
   9    switch ($path) {
  10      case 'admin/settings/xmlsitemap/engines':
  11        if (!module_exists('site_verify')) {
  12          $output .= '<p>' . t('In order to verify site ownership with the search engines listed below, it is highly recommended to download and install the <a href="@site-verify">Site verification module</a>.', array('@site-verify' => 'http://drupal.org/project/site_verify')) . '</p>';
  13        }
  14        break;
  15    }
  16  
  17    return $output;
  18  }
  19  
  20  /**
  21   * Implements hook_menu().
  22   */
  23  function xmlsitemap_engines_menu() {
  24    $items['admin/settings/xmlsitemap/engines'] = array(
  25      'title' => 'Search Engines',
  26      'page callback' => 'drupal_get_form',
  27      'page arguments' => array('xmlsitemap_engines_settings_form'),
  28      'access arguments' => array('administer xmlsitemap'),
  29      'type' => MENU_LOCAL_TASK,
  30      'file' => 'xmlsitemap_engines.admin.inc',
  31    );
  32    //$items['admin/settings/xmlsitemap/engines/submit'] = array(
  33    //  'page callback' => 'xmlsitemap_engines_submit',
  34    //  'access callback' => 'xmlsitemap_engines_submit_access',
  35    //  'type' => MENU_CALLBACK,
  36    //);
  37  
  38    return $items;
  39  }
  40  
  41  /**
  42   * Implements hook_cron().
  43   */
  44  function xmlsitemap_engines_cron() {
  45    if (xmlsitemap_engines_submit_access()) {
  46      xmlsitemap_engines_submit_engines();
  47    }
  48  }
  49  
  50  function xmlsitemap_engines_can_submit() {
  51    // Skip if the site is offline since search engines will not be able to
  52    // access the site's content.
  53    if (variable_get('site_offline', 0)) {
  54      return FALSE;
  55    }
  56  
  57    if (!variable_get('xmlsitemap_engines_engines', array()) && !variable_get('xmlsitemap_engines_custom_urls', '')) {
  58      return FALSE;
  59    }
  60  
  61    return TRUE;
  62  }
  63  
  64  function xmlsitemap_engines_submit_access() {
  65    if (!xmlsitemap_engines_can_submit()) {
  66      return FALSE;
  67    }
  68  
  69    // Allow manual submissions to run.
  70    //if ($_GET['q'] == 'admin/settings/xmlsitemap/engines/submit' && user_access('administer xmlsitemap')) {
  71    //  return TRUE;
  72    //}
  73  
  74    $submit_updated = variable_get('xmlsitemap_engines_submit_updated', TRUE);
  75    $submitted_last = variable_get('xmlsitemap_engines_submit_last', 0);
  76    $minimum_lifetime = variable_get('xmlsitemap_engines_minimum_lifetime', 86400);
  77  
  78    // Skip if sitemap data has not been updated since last submission.
  79    if ($submit_updated && variable_get('xmlsitemap_generated_last', 0) <= $submitted_last) {
  80      return FALSE;
  81    }
  82  
  83    // Skip if the time since last submission is less than the minimum lifetime.
  84    if ((REQUEST_TIME - $submitted_last) < $minimum_lifetime) {
  85      return FALSE;
  86    }
  87  
  88    return TRUE;
  89  }
  90  
  91  /**
  92   * Submit the sitemaps to all the specified search engines.
  93   *
  94   * @param $smids
  95   *   An optional array of XML sitemap IDs. If not provided, it will load all
  96   *   existing XML sitemaps.
  97   */
  98  function xmlsitemap_engines_submit_engines(array $smids = array()) {
  99    if (empty($smids)) {
 100      $smids = xmlsitemap_sitemap_get_all_smids();
 101    }
 102  
 103    $sitemaps = xmlsitemap_sitemap_load_multiple($smids);
 104    $engines = variable_get('xmlsitemap_engines_engines', array());
 105    $engine_info = xmlsitemap_engines_get_engine_info();
 106  
 107    foreach ($engines as $engine) {
 108      xmlsitemap_engines_submit_sitemaps($engine_info[$engine]['url'], $sitemaps);
 109    }
 110  
 111    $custom_urls = variable_get('xmlsitemap_engines_custom_urls', '');
 112    $custom_urls = preg_split('/[\r\n]+/', $custom_urls, -1, PREG_SPLIT_NO_EMPTY);
 113    foreach ($custom_urls as $custom_url) {
 114      xmlsitemap_engines_submit_sitemaps($custom_url, $sitemaps);
 115    }
 116  
 117    variable_set('xmlsitemap_engines_submit_last', REQUEST_TIME);
 118  }
 119  
 120  /**
 121   * Submit the sitemaps to a specific URL.
 122   *
 123   * @param $url
 124   *   The URL for sitemap submission.
 125   * @param $sitemaps
 126   *   An array of URLs of the sitemaps to submit.
 127   */
 128  function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) {
 129    foreach ($sitemaps as $sitemap) {
 130      $sitemap['url'] = url($sitemap['uri']['path'], $sitemap['uri']['options']);
 131      $submit_url = xmlsitemap_engines_prepare_url($url, $sitemap['url']);
 132      $request = drupal_http_request($submit_url);
 133      watchdog('xmlsitemap', 'Submitted the sitemap to %url and received response @code.', array('%url' => $submit_url, '@code' => $request->code));
 134    }
 135  }
 136  
 137  /**
 138   * Replace valid tokens in the URL with their appropriate values.
 139   *
 140   * @param $url
 141   *   An un-tokenized URL.
 142   * @return
 143   *   A tokenized URL.
 144   */
 145  function xmlsitemap_engines_prepare_url($url, $sitemap) {
 146    return str_replace('[sitemap]', $sitemap, $url);
 147  }
 148  
 149  /**
 150   * Returns information about supported search engines.
 151   *
 152   * @param $engine
 153   *   (optional) The engine to return information for. If omitted, information
 154   *   for all engines is returned.
 155   * @param $reset
 156   *   (optional) Boolean whether to reset the static cache and do nothing. Only
 157   *   used for tests.
 158   *
 159   * @see hook_xmlsitemap_engines_info()
 160   * @see hook_xmlsitemap_engines_info_alter()
 161   */
 162  function xmlsitemap_engines_get_engine_info($engine = NULL) {
 163    global $language;
 164    $engines = &xmlsitemap_static(__FUNCTION__);
 165  
 166    if (!isset($engines)) {
 167      if ($cached = cache_get('xmlsitemap:engines:' . $language->language)) {
 168        $engines = $cached->data;
 169      }
 170      else {
 171        // Fetch the results of all hook_xmlsitemap_engine_info() implementations.
 172        $engines = module_invoke_all('xmlsitemap_engine_info');
 173        // Allow other modulse to alter the engine info.
 174        drupal_alter('xmlsitemap_engine_info', $engines);
 175        // Cache by language since engine names are translated.
 176        cache_set('xmlsitemap:engines:' . $language->language, $engines);
 177      }
 178    }
 179  
 180    if (isset($engine)) {
 181      return isset($engines[$engine]) ? $engines[$engine] : NULL;
 182    }
 183    else {
 184      return $engines;
 185    }
 186  }
 187  
 188  /**
 189   * Implements hook_xmlsitemap_engine_info().
 190   */
 191  function xmlsitemap_engines_xmlsitemap_engine_info() {
 192    $engines['google'] = array(
 193      'name' => t('Google'),
 194      'url' => 'http://www.google.com/webmasters/tools/ping?sitemap=[sitemap]',
 195      'help path' => 'http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156184',
 196    );
 197    $engines['yahoo'] = array(
 198      'name' => t('Yahoo!'),
 199      'url' => 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=[sitemap]',
 200      'help path' => 'http://help.yahoo.com/l/us/yahoo/search/siteexplorer/manage/siteexplorer-45.html',
 201    );
 202    $engines['ask'] = array(
 203      'name' => t('Ask.com'),
 204      'url' => 'http://submissions.ask.com/ping?sitemap=[sitemap]',
 205      'help path' => 'http://about.ask.com/en/docs/about/webmasters.shtml#22',
 206    );
 207    $engines['bing'] = array(
 208      'name' => t('Bing'),
 209      'url' => 'http://www.bing.com/webmaster/ping.aspx?siteMap=[sitemap]',
 210      'help path' => 'http://www.bing.com/webmaster',
 211    );
 212    $engines['moreover'] = array(
 213      'name' => t('Moreover'),
 214      'url' => 'http://api.moreover.com/ping?u=[sitemap]',
 215    );
 216    return $engines;
 217  }
 218  
 219  /**
 220   * Implements hook_variables().
 221   */
 222  function xmlsitemap_engines_variables() {
 223    $variables = array(
 224      'xmlsitemap_engines_engines' => array(),
 225      'xmlsitemap_engines_custom_urls' => '',
 226      'xmlsitemap_engines_minimum_lifetime' => 86400,
 227      'xmlsitemap_engines_submit_last' => 0,
 228      'xmlsitemap_engines_submit_updated' => TRUE,
 229    );
 230    return $variables;
 231  }
 232  
 233  /**
 234   * Implements hook_xmlsitemap_sitemap_operations().
 235   */
 236  function xmlsitemap_engines_xmlsitemap_sitemap_operations() {
 237    if (xmlsitemap_engines_can_submit()) {
 238      $operations['xmlsitemap_engines_submit'] = array(
 239        'label' => t('Submit to search engines'),
 240        'action past' => t('Submitted'),
 241        'callback' => 'xmlsitemap_engines_submit_engines',
 242      );
 243      return $operations;
 244    }
 245  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7