1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Alerts other sites that your site has been updated. |
---|
6 | */ |
---|
7 | |
---|
8 | /** |
---|
9 | * Implementation of hook_help(). |
---|
10 | */ |
---|
11 | function ping_help($path, $arg) { |
---|
12 | switch ($path) { |
---|
13 | case 'admin/help#ping': |
---|
14 | $output = '<p>'. t('The ping module is useful for notifying interested sites that your site has changed. It automatically sends notifications, or "pings", to the <a href="@external-http-pingomatic-com">pingomatic</a> service about new or updated content. In turn, <a href="@external-http-pingomatic-com">pingomatic</a> notifies other popular services, including weblogs.com, Technorati, blo.gs, BlogRolling, Feedster.com, and Moreover.', array('@external-http-pingomatic-com' => 'http://pingomatic.com/')) .'</p>'; |
---|
15 | $output .= '<p>'. t('The ping module requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))) .'</p>'; |
---|
16 | $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@ping">Ping module</a>.', array('@ping' => 'http://drupal.org/handbook/modules/ping/')) .'</p>'; |
---|
17 | return $output; |
---|
18 | } |
---|
19 | } |
---|
20 | |
---|
21 | /** |
---|
22 | * Implementation of hook_cron(). |
---|
23 | * |
---|
24 | * Fire off notifications of updates to remote sites. |
---|
25 | */ |
---|
26 | function ping_cron() { |
---|
27 | global $base_url; |
---|
28 | |
---|
29 | if (variable_get('site_name', 0)) { |
---|
30 | $cron_last = variable_get('cron_last', time()); |
---|
31 | // Query changed first since usually changed >= created. |
---|
32 | if (db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND changed > %d', $cron_last)) || db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND created > %d', $cron_last))) { |
---|
33 | _ping_notify(variable_get('site_name', ''), $base_url); |
---|
34 | } |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * Call hook_ping() in all modules to notify remote sites that there is |
---|
40 | * new content at this one. |
---|
41 | */ |
---|
42 | function _ping_notify($name, $url) { |
---|
43 | module_invoke_all('ping', $name, $url); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Implementation of hook_ping(). |
---|
48 | * |
---|
49 | * Notifies pingomatic.com, blo.gs, and technorati.com of changes at this site. |
---|
50 | */ |
---|
51 | function ping_ping($name = '', $url = '') { |
---|
52 | |
---|
53 | $result = xmlrpc('http://rpc.pingomatic.com', 'weblogUpdates.ping', $name, $url); |
---|
54 | |
---|
55 | if ($result === FALSE) { |
---|
56 | watchdog('directory ping', 'Failed to notify pingomatic.com (site).', array(), WATCHDOG_WARNING); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | |
---|