diff modules/ping/ping.module @ 1:c1f4ac30525a 6.0

Drupal 6.0
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:28:28 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/ping/ping.module	Tue Dec 23 14:28:28 2008 +0100
@@ -0,0 +1,59 @@
+<?php
+// $Id: ping.module,v 1.52 2007/12/19 17:45:42 goba Exp $
+
+/**
+ * @file
+ * Alerts other sites that your site has been updated.
+ */
+
+/**
+ * Implementation of hook_help().
+ */
+function ping_help($path, $arg) {
+  switch ($path) {
+    case 'admin/help#ping':
+      $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>';
+      $output .= '<p>'. t('The ping module requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))) .'</p>';
+      $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>';
+      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)) {
+    if (db_result(db_query("SELECT COUNT(*) FROM {node} WHERE status = 1 AND (created > '". variable_get('cron_last', time()) ."' OR changed > '". variable_get('cron_last', time()) ."')"))) {
+      _ping_notify(variable_get('site_name', ''), $base_url);
+    }
+  }
+}
+
+/**
+ * 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 = '') {
+
+  $result = xmlrpc('http://rpc.pingomatic.com', 'weblogUpdates.ping', $name, $url);
+
+  if ($result === FALSE) {
+    watchdog('directory ping', 'Failed to notify pingomatic.com (site).', array(), WATCHDOG_WARNING);
+  }
+}
+
+