initial import from onelab svn codebase
[plewww.git] / modules / ping.module
1 <?php
2 // $Id: ping.module 144 2007-03-28 07:52:20Z thierry $
3
4 /**
5  * @file
6  * Alerts other sites that your site has been updated.
7  */
8
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 .= t('<p>You can:</p>
18 <ul>
19 <li> enable or disable the ping module at <a href="%admin-modules">administer &gt;&gt; modules</a>.</li>
20 <li>run your cron job at your sites <a href="%file-cron">cron page</a>.</li>
21 <li>read about <a href="%external-http-drupal-org-node-23714">configuring cron jobs</a>.</li>
22 </ul></p>
23 ', array('%admin-modules' => url('admin/modules'), '%file-cron' => 'cron.php', '%external-http-drupal-org-node-23714' => 'http://drupal.org/node/23714'));
24       $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>';
25       return $output;
26     case 'admin/modules#description':
27       return t('Alerts other sites when your site has been updated.');
28   }
29 }
30
31 /**
32  * Implementation of hook_cron().
33  *
34  * Fire off notifications of updates to remote sites.
35  */
36 function ping_cron() {
37   global $base_url;
38
39   if (variable_get('site_name', 0) && variable_get('site_slogan', 0)) {
40     if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get('cron_last', time()) ."' OR changed > '". variable_get('cron_last', time()) ."')"))) {
41       _ping_notify(variable_get('site_name', '') .' - '. variable_get('site_slogan', ''), $base_url);
42     }
43   }
44 }
45
46 /**
47  * Call hook_ping() in all modules to notify remote sites that there is
48  * new content at this one.
49  */
50 function _ping_notify($name, $url) {
51   module_invoke_all('ping', $name, $url);
52 }
53
54 /**
55  * Implementation of hook_ping().
56  *
57  * Notifies pingomatic.com, blo.gs, and technorati.com of changes at this site.
58  */
59 function ping_ping($name = '', $url = '') {
60
61   $result = xmlrpc('http://rpc.pingomatic.com', 'weblogUpdates.ping', $name, $url);
62
63   if ($result === FALSE) {
64     watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING);
65   }
66 }
67
68