Configurable ping.module in Drupal

Ping is one of the most a-must mechanism for interactive web community and blogging platform. Drupal comes with ping.module which periodically pings to pingomatic.com. However, sometimes you might want to specify a list of pinger URLs that pingomatic don"t support or pingomatic may be too busy for you. To satisfy this requiremnt, David Herron suggested to modify ping.module directly.

Fortunately, Richard Eriksson submitted a patch for configurable settings. That patch is for Drupal 4.6.x so I adapted that patch to work properly on Drupal 4.7.x. Download the patch from the drupal site or see below.

Technorati Tags: , , , , , , ,

--- ping.module.orig    2005-12-31 21:18:22.000000000 +0700
+++ ping.module 2006-01-16 13:01:29.000000000 +0700
@@ -44,6 +44,25 @@
 }
 
 /**
+ * Implemetaion of hook_settings
+ */
+function ping_settings() {
+  $form[’ping’] = array(
+    ’#type’ => ’fieldset’,
+    ’#title’ => t(’Ping settings’),
+    ’#collapsible’ => TRUE,
+  );
+  $form[’ping’][’ping_pinger_list’] = array(
+    ’#type’ => ’textarea’,
+    ’#title’ => t(’URLs to ping’),
+    ’#default_value’ => variable_get(’ping_pinger_list’, ’http://rpc.pingomatic.com’),
+    ’#width’ => 40,
+    ’#height’ => 10,
+  );
+  return $form;
+}
+
+/**
  * Call hook_ping() in all modules to notify remote sites that there is
  * new content at this one.
  */
@@ -58,11 +77,19 @@
  */
 function ping_ping($name = ’’, $url = ’’) {
 
-  $result = xmlrpc(’http://rpc.pingomatic.com’, ’weblogUpdates.ping’, $name, $url);
-
-  if ($result === FALSE) {
-    watchdog(’directory ping’, t(’Failed to notify pingomatic.com (site).’), WATCHDOG_WARNING);
+  $pingers = explode("\n", variable_get(’ping_pinger_list’, ’http://rpc.pingomatic.com’));
+  foreach ($pingers as $pinger) {
+    $pinger = trim($pinger);
+    if (empty($pinger)) {
+      continue;
+    }
+    $result = xmlrpc($pinger, ’weblogUpdates.ping’, $name, $url);
+
+    if ($result === FALSE) {
+      watchdog(’directory ping’, t(’Failed to notify %pinger (site). %message’, array(’%pinger’ => $pinger, ’%message’ => xmlrpc_error_msg())), WATCHDOG_WARNING);
+    }
   }
 }
 
 
+?>

Post new comment