ping.module 2.71 KB
Newer Older
1 2 3
<?php
// $Id$

4 5 6 7 8
/**
 * @file
 * Alerts other sites that your site has been updated.
 */

9 10 11 12
/**
 * Implementation of hook_help().
 */
function ping_help($section) {
13
  switch ($section) {
14
    case 'admin/help#ping':
15 16 17 18 19 20 21 22 23 24 25
      $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>';
      $output .= '<p>'. t('The ping module requires <code>cron</code> or a similar periodic job scheduler to be enabled.') .'</p>';
      $output .= t('<p>You can:</p>
<ul>
<li> enable or disable the ping module at <a href="%admin-modules">administer &gt;&gt; modules</a>.</li>
<li>run your cron job at your sites <a href="%file-cron">cron page</a>.</li>
<li>read about <a href="%external-http-drupal-org-node-23714">configuring cron jobs</a>.</li>
</ul></p>
', array('%admin-modules' => url('admin/modules'), '%file-cron' => 'cron.php', '%external-http-drupal-org-node-23714' => 'http://drupal.org/node/23714'));
      $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%ping">Ping page</a>.', array('%ping' => 'http://www.drupal.org/handbook/modules/ping/')) .'</p>';
      return $output;
Dries's avatar
Dries committed
26
    case 'admin/modules#description':
27
      return('Alerts other sites when your site has been updated.');
28
  }
29 30
}

31 32 33 34 35
/**
 * Implementation of hook_cron().
 *
 * Fire off notifications of updates to remote sites.
 */
36
function ping_cron() {
37 38
  global $base_url;

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()) ."')"), 1)) {
41
      _ping_notify(variable_get('site_name', '') .' - '. variable_get('site_slogan', ''), $base_url);
42 43 44 45
    }
  }
}

46 47 48 49
/**
 * Call hook_ping() in all modules to notify remote sites that there is
 * new content at this one.
 */
50
function _ping_notify($name, $url) {
51
  module_invoke_all('ping', $name, $url);
52 53
}

54 55 56
/**
 * Implementation of hook_ping().
 *
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);
Dries's avatar
Dries committed
62

63
  if ($result === FALSE) {
64
    watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING);
Dries's avatar
Dries committed
65
  }
66
}
Dries's avatar
Dries committed
67

68