diff -r fcf75e232c5b -r 0ff3ba646492 web/drupal/modules/xmlsitemap/xmlsitemap_engines/xmlsitemap_engines.module --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/drupal/modules/xmlsitemap/xmlsitemap_engines/xmlsitemap_engines.module Fri Aug 21 16:26:26 2009 +0000 @@ -0,0 +1,207 @@ += $frequency); + if ($ping_engines) { + xmlsitemap_engines_ping_sitemap(); + variable_set('xmlsitemap_sitemap_is_changed', FALSE); + variable_set('xmlsitemap_engines_cron_timestamp_submit', REQUEST_TIME); + } +} + +/** + * Implementation of hook_menu(). + */ +function xmlsitemap_engines_menu() { + $items = array(); + $items['admin/settings/xmlsitemap/engines'] = array( + 'title' => 'Search engines', + 'description' => 'Configure the submission settings of the XML sitemap to the search engines.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('xmlsitemap_engines_settings'), + 'access arguments' => array('administer site configuration'), + 'type' => MENU_LOCAL_TASK, + 'file' => 'xmlsitemap_engines.admin.inc', + ); + if ($verify = variable_get("xmlsitemap_engines_google_verify", '')) { + $items[$verify] = array( + 'title' => 'Google verification page', + 'page callback' => 'xmlsitemap_engines_verify', + 'page arguments' => array('google'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'xmlsitemap_engines.pages.inc', + ); + } + if ($verify = variable_get("xmlsitemap_engines_yahoo_verify", '')) { + $items[$verify] = array( + 'title' => 'Yahoo! verification page', + 'page callback' => 'xmlsitemap_engines_verify', + 'page arguments' => array('yahoo'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'xmlsitemap_engines.pages.inc', + ); + } + if ($verify = variable_get("xmlsitemap_engines_bing_verify", '')) { + $items[$verify] = array( + 'title' => 'Bing verification page', + 'page callback' => 'xmlsitemap_engines_verify', + 'page arguments' => array('bing'), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'xmlsitemap_engines.pages.inc', + ); + } + return $items; +} + +/** + * Implementation of hook_xmlsitemap_operations(). + */ +function xmlsitemap_engines_xmlsitemap_operations() { + return array( + 'submit_to_all' => array( + 'label' => t('Submit the sitemap to all the active search engines'), + 'callback' => 'xmlsitemap_engines_ping_sitemap', + ), + 'submit_to_askcom' => array( + 'label' => t('Submit the sitemap to Ask.com'), + 'callback' => 'xmlsitemap_engines_ping_sitemap', + 'callback arguments' => array('engine' => 'ask'), + ), + 'submit_to_bing' => array( + 'label' => t('Submit the sitemap to Bing'), + 'callback' => 'xmlsitemap_engines_ping_sitemap', + 'callback arguments' => array('engine' => 'bing'), + ), + 'submit_to_google' => array( + 'label' => t('Submit the sitemap to Google'), + 'callback' => 'xmlsitemap_engines_ping_sitemap', + 'callback arguments' => array('engine' => 'google'), + ), + 'submit_to_moreovercom' => array( + 'label' => t('Submit the sitemap to Moreover.com'), + 'callback' => 'xmlsitemap_engines_ping_sitemap', + 'callback arguments' => array('engine' => 'moreover'), + ), + 'submit_to_yahoo' => array( + 'label' => t('Submit the sitemap to Yahoo!'), + 'callback' => 'xmlsitemap_engines_ping_sitemap', + 'callback arguments' => array('engine' => 'yahoo'), + ), + ); +} + +/***************************************************************************** + * Public functions. + ****************************************************************************/ + +/** + * Submit the sitemap to the selected engines. + */ +function xmlsitemap_engines_ping_sitemap($engine = NULL) { + $engines = array( + 'ask' => array( + 'Ask.com', + 'http://submissions.ask.com/ping?sitemap=[sitemap]', + ), + 'bing' => array( + 'Bing (formerly Live Search)', + 'http://www.bing.com/webmaster/ping.aspx?siteMap=[sitemap]', + ), + 'google' => array( + 'Google', + 'http://www.google.com/webmasters/tools/ping?sitemap=[sitemap]' + ), + 'moreover' => array( + 'Moreover.com', + 'http://api.moreover.com/ping?u=[sitemap]' + ), + 'yahoo' => array( + 'Yahoo!', + 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=[sitemap]' + ), + ); + + // Get a list of enabled languages. + $languages = language_list('enabled'); + $languages = $languages[1]; + + foreach ($languages as $language) { + if (!isset($engine)) { + foreach ($engines as $id => $info) { + if (variable_get("xmlsitemap_engines_{$id}_submit", FALSE)) { + xmlsitemap_engines_submit_sitemap($info[0], "xmlsitemap_engines_{$id}_url", $info[1], $language); + } + } + } + elseif (isset($engines[$engine])) { + xmlsitemap_engines_submit_sitemap($engines[$engine][0], "xmlsitemap_engines_{$engine}_url", $engines[$engine][1], $language); + } + } +} + +/** + * Helper function for xmlsitemap_engines_ping_sitemap(). + * Submit the sitemap to the engine passed as argument, and write a message in + * Drupal log. + * + * @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, $language = null) { + $url_options = array ('absolute' => TRUE); + if (!is_null($language)) { + $url_options['language'] = $language; + } + + $url = url('sitemap.xml', $url_options); + $url = strtr(variable_get($url_var, $default_url), array('[sitemap]' => $url)); + + $result = drupal_http_request($url); + if ($result->code == 200) { + watchdog('xmlsitemap', 'Sitemap successfully submitted to !engine.', + array('!engine' => $engine) + ); + } + else { + watchdog('xmlsitemap', 'Error occurred submitting sitemap to !engine: !code.', + array('!engine' => $engine, '!code' => 0 + $result->code), WATCHDOG_ERROR + ); + } +} + +/** + * @} End of "addtogroup xmlsitemap". + */