Imported drupal-5.3
[drupal.git] / modules / ping / ping.module
blob0e98ea43f10968ebdd732c053a4d669b46dfae72
1 <?php
2 // $Id: ping.module,v 1.45 2006/11/21 20:14:18 dries Exp $
4 /**
5  * @file
6  * Alerts other sites that your site has been updated.
7  */
9 /**
10  * Implementation of hook_help().
11  */
12 function ping_help($section) {
13   switch ($section) {
14     case 'admin/help#ping':
15       $output = '<p>'. t('The ping module is useful for notifying interested sites that your site has changed. It automatically sends notifications (called "pings") to the <a href="@external-http-pingomatic-com">pingomatic</a> service to tell it that your site has changed. In turn pingomatic will ping other services such as weblogs.com, Technorati, blo.gs, BlogRolling, Feedster.com, Moreover, etc.', array('@external-http-pingomatic-com' => 'http://pingomatic.com/')) .'</p>';
16       $output .= '<p>'. t('The ping module requires <code>cron</code> or a similar periodic job scheduler to be enabled.') .'</p>';
17       $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@ping">Ping page</a>.', array('@ping' => 'http://drupal.org/handbook/modules/ping/')) .'</p>';
18       return $output;
19   }
22 /**
23  * Implementation of hook_cron().
24  *
25  * Fire off notifications of updates to remote sites.
26  */
27 function ping_cron() {
28   global $base_url;
30   if (variable_get('site_name', 0)) {
31     if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND (created > '". variable_get('cron_last', time()) ."' OR changed > '". variable_get('cron_last', time()) ."')"))) {
32       _ping_notify(variable_get('site_name', ''), $base_url);
33     }
34   }
37 /**
38  * Call hook_ping() in all modules to notify remote sites that there is
39  * new content at this one.
40  */
41 function _ping_notify($name, $url) {
42   module_invoke_all('ping', $name, $url);
45 /**
46  * Implementation of hook_ping().
47  *
48  * Notifies pingomatic.com, blo.gs, and technorati.com of changes at this site.
49  */
50 function ping_ping($name = '', $url = '') {
52   $result = xmlrpc('http://rpc.pingomatic.com', 'weblogUpdates.ping', $name, $url);
54   if ($result === FALSE) {
55     watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING);
56   }