summaryrefslogtreecommitdiff
path: root/modules/ping/ping.module
blob: 5e500fc2642b0be3fe5270d0567f7a6e66ea02bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
// $Id$

/**
 * @file
 * Alerts other sites that your site has been updated.
 */

/**
 * Implementation of hook_help().
 */
function ping_help($section) {
  switch ($section) {
    case 'admin/help#ping':
      $output .= t("
      <p>Drupal can automatically send notifications (called \"pings\") to the %pingomatic to tell them that your site has changed.  In turn pingomatic.com will ping other services like weblogs.com, Technorati, blo.gs, BlogRolling, Feedster.com, Moreover, etc.</p>
      <p>The ping feature requires crontab.</p>", array('%pingomatic' => '<a href="http://pingomatic.com/">http://pingomatic.com/</a>'));
      break;

    case 'admin/modules#description':
      $output = t('Alerts other sites that your site has been updated.');
      break;
  }

  return $output;
}

/**
 * Implementation of hook_cron().
 *
 * Fire off notifications of updates to remote sites.
 */
function ping_cron() {
  global $base_url;

  if (variable_get('site_name', 0) && variable_get('site_slogan', 0)) {
    if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get('ping_cron_last', time()) ."' OR changed > '". variable_get('ping_cron_last', time()) ."')"), 1)) {
      _ping_notify(variable_get('site_name', '') .' - '. variable_get('site_slogan', ''), $base_url);
    }

    variable_set('ping_cron_last', time());
  }
}

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

/**
 * Implementation of hook_ping().
 *
 * Notifies pingomatic.com, blo.gs, and technorati.com of changes at this site.
 */
function ping_ping($name = '', $url = '') {

  $feed = url('node/feed', NULL, NULL, TRUE);
  $client = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
  $message = new xmlrpcmsg('weblogUpdates.ping', array(new xmlrpcval($name), new xmlrpcval($url)));
  $result = $client->send($message);

  if (!$result || $result->faultCode()) {
    watchdog('error', t('Failed to notify pingomatic.com (site).'));
  }
}

?>