ping.module

  1. drupal
    1. 4.6 modules/ping.module
    2. 4.7 modules/ping.module
    3. 5 modules/ping/ping.module
    4. 6 modules/ping/ping.module

Alerts other sites that your site has been updated.

Functions & methods

NameDescription
ping_cronImplementation of hook_cron().
ping_helpImplementation of hook_help().
ping_pingImplementation of hook_ping().
_ping_notifyCall hook_ping() in all modules to notify remote sites that there is new content at this one.

File

modules/ping.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Alerts other sites that your site has been updated.
  5. */
  6. /**
  7. * Implementation of hook_help().
  8. */
  9. function ping_help($section) {
  10. switch ($section) {
  11. case 'admin/help#ping':
  12. $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>';
  13. $output .= '<p>'. t('The ping module requires <code>cron</code> or a similar periodic job scheduler to be enabled.') .'</p>';
  14. $output .= t('<p>You can:</p>
  15. <ul>
  16. <li> enable or disable the ping module at <a href="%admin-modules">administer &gt;&gt; modules</a>.</li>
  17. <li>run your cron job at your sites <a href="%file-cron">cron page</a>.</li>
  18. <li>read about <a href="%external-http-drupal-org-node-23714">configuring cron jobs</a>.</li>
  19. </ul></p>
  20. ', array('%admin-modules' => url('admin/modules'), '%file-cron' => 'cron.php', '%external-http-drupal-org-node-23714' => 'http://drupal.org/node/23714'));
  21. $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>';
  22. return $output;
  23. case 'admin/modules#description':
  24. return t('Alerts other sites when your site has been updated.');
  25. }
  26. }
  27. /**
  28. * Implementation of hook_cron().
  29. *
  30. * Fire off notifications of updates to remote sites.
  31. */
  32. function ping_cron() {
  33. global $base_url;
  34. if (variable_get('site_name', 0) && variable_get('site_slogan', 0)) {
  35. 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()) ."')"))) {
  36. _ping_notify(variable_get('site_name', '') .' - '. variable_get('site_slogan', ''), $base_url);
  37. }
  38. }
  39. }
  40. /**
  41. * Call hook_ping() in all modules to notify remote sites that there is
  42. * new content at this one.
  43. */
  44. function _ping_notify($name, $url) {
  45. module_invoke_all('ping', $name, $url);
  46. }
  47. /**
  48. * Implementation of hook_ping().
  49. *
  50. * Notifies pingomatic.com, blo.gs, and technorati.com of changes at this site.
  51. */
  52. function ping_ping($name = '', $url = '') {
  53. $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. }
  57. }
Login or register to post comments