Porting multiping.module to Drupal 5
The built-in Ping module bundled with Drupal is not as good as I
expect to have on my site because it only notifies
Ping-o-Matic. I just want to ping to custom list of pinging
services. I have also found multiping which was initially
referred in a thread. Actually, I patched the built-in Ping module
to support custom Ping services, both ping and extendedPing.
Anyway, it is not as good as multiping provide to me. Unfortunately,
multiping has not been ported to Drupal 5 yet. That's why I have to
do it today.
Porting multiping is not easy like I expected at the first glance.
- Create
multiping.info. - Rename
module_exist()tomodule_exists(). - Change the usage of
drupal_get_form()which the form must be separated in a function with the same name to the form id.
The most difficult and time consumed process is the third one. The porting is not completely finished yet. I still would like to patch it more to make local tasks to be local tasks. Anyway, today is enough.
=== added file 'multiping.info' --- multiping.info 1970-01-01 00:00:00 +0000 +++ multiping.info 2007-01-14 14:52:55 +0000 @@ -0,0 +1,3 @@ +; $Id$ +name = Multi Ping +description = A replacement for the ping module of Drupal. It allows pinging of multiple sites. \ No newline at end of file === modified file 'multiping.module' --- multiping.module 2007-01-14 10:43:31 +0000 +++ multiping.module 2007-01-14 14:52:55 +0000 @@ -37,7 +37,9 @@ $items = array(); if ($may_cache) { - $items[] = array('path' => 'admin/settings/multiping', 'title' => t('multi ping'), + $items[] = array('path' => 'admin/settings/multiping', + 'title' => t('Multi ping'), + 'description' => t('Administer multi ping'), 'callback' => 'multiping_admin', 'access' => user_access('admin pings')); } @@ -60,7 +62,7 @@ if (strlen($slogan)>0) $name=$name.' - '.$slogan; // Determine rss url - if (module_exist('taxonomy') && $pingservice->whentoping==2 + if (module_exists('taxonomy') && $pingservice->whentoping==2 && count($pingservice->voc)>0 && $pingservice->submitmainrss==0) { // Taxonomy module exists, "ping only for nodes with taxonomy", // Some taxonomy elements are actually selected, "main rss" override is off @@ -98,7 +100,7 @@ $result = db_query('SELECT * FROM {multiping}'); while ($row = db_fetch_object($result)) { $sql_from=""; - if (module_exist('taxonomy') && $row->whentoping==2) { + if (module_exists('taxonomy') && $row->whentoping==2) { // Find most recent date for nodes with given taxonomy $voc=unserialize($row->voc); $sql_from="{term_node} t, {node} n WHERE n.status>0 AND". @@ -172,7 +174,7 @@ } -function _multiping_form($id) { +function multiping_edit_service($id) { $edit['id']=$id; $edit['name']=''; $edit['url']='http://'; @@ -237,7 +239,7 @@ '#required' => FALSE, ); $options = array('1' => t('Always ping'), '0' => t('Don\'t ping')); - if (module_exist('taxonomy')) { + if (module_exists('taxonomy')) { $options['2']=t('Ping only for nodes with the following taxonomy'); } $form['whentoping'] = array( @@ -247,7 +249,7 @@ '#options' => $options, '#description' => t('Determines the default settings for pinging this service'), ); - if (module_exist('taxonomy')) { + if (module_exists('taxonomy')) { $form['voc'] = array( '#type' => 'select', '#title' => t('Taxonomy terms when to ping'), @@ -267,7 +269,70 @@ '#type' => 'submit', '#value' => t('Submit'), ); - return drupal_get_form('multiping_edit_service', $form); + return $form; +} + + +function _multiping_form($id) { + return drupal_get_form('multiping_edit_service', $id); +} + + +function multiping_edit_service_submit($form_id, $form_values) { + return multiping_settings_submit($form_id, $form_values); +} + +function multiping_settings() { + $form=array(); + $settings=_multiping_get_settings(); + $form['global']['time_between_pings'] = array( + '#type' => 'textfield', + '#title' => t('Time between pings'), + '#default_value' => $settings['global']['time_between_pings'], + '#size' => 8, + '#maxlength' => 4, + '#description' => t('Minimum number of minutes between two pings to same site'), + '#attributes' => NULL, + '#required' => TRUE, + ); + $form['pingatonce'] = array( + '#type' => 'checkbox', + '#title' => t('Ping after post'), + '#default_value' => $settings['global']['pingatonce'], + '#description' => t('Ping directly after post/update (instead of pinging during the cron job runs)'), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + return $form; +} + + +function multiping_settings_submit($form_id, $form_values) { + $edit = $form_values; + if ($edit['form_id']=='multiping_edit_service') { + $edit['id'] = ($edit['id'] && is_numeric($edit['id'])) ? $edit['id'] : 0; + $edit['name'] = ($edit['name']) ? $edit['name'] : '(no name)'; + $edit['url'] = ($edit['url']) ? $edit['url'] : 'http://localhost/'; + $edit['method'] = ($edit['method']) ? $edit['method'] : ''; + $edit['submitmainrss'] = ($edit['submitmainrss']) ? $edit['submitmainrss'] : 0; // Not present if false! + if ($edit['submitmainrss']>0) $edit['submitmainrss']=1; + if ($edit['id']==0) { + db_query("INSERT INTO {multiping} (name,url,method,whentoping,submitmainrss,voc) ". + "VALUES ('%s','%s','%s','%s','%s','%s')",$edit['name'],$edit['url'], + $edit['method'],$edit['whentoping'],$edit['submitmainrss'],serialize($edit['voc'])); + } else { + db_query("UPDATE {multiping} SET name='%s',url='%s',method='%s',whentoping='%s',submitmainrss='%s',voc='%s' ". + "WHERE id=%d",$edit['name'],$edit['url'],$edit['method'],$edit['whentoping'],$edit['submitmainrss'],serialize($edit['voc']),$edit['id']); + } + } elseif ($edit['form_id']=='multiping_settings') { + $settings=_multiping_get_settings(); + $settings['global']['time_between_pings']=$edit['time_between_pings']; + $settings['global']['pingatonce']=$edit['pingatonce']; + variable_set('multiping', $settings); + } + drupal_goto("admin/settings/multiping"); } @@ -277,31 +342,7 @@ function multiping_admin() { if (!user_access('admin pings')) return; $output = ""; - if ($_POST['op']==t('Submit')) { - $edit = $_POST['edit']; - if ($edit['form_id']=='multiping_edit_service') { - $edit['id'] = ($edit['id'] && is_numeric($edit['id'])) ? $edit['id'] : 0; - $edit['name'] = ($edit['name']) ? $edit['name'] : '(no name)'; - $edit['url'] = ($edit['url']) ? $edit['url'] : 'http://localhost/'; - $edit['method'] = ($edit['method']) ? $edit['method'] : ''; - $edit['submitmainrss'] = ($edit['submitmainrss']) ? $edit['submitmainrss'] : 0; // Not present if false! - if ($edit['submitmainrss']>0) $edit['submitmainrss']=1; - if ($edit['id']==0) { - db_query("INSERT INTO {multiping} (name,url,method,whentoping,submitmainrss,voc) ". - "VALUES ('%s','%s','%s','%s','%s','%s')",$edit['name'],$edit['url'], - $edit['method'],$edit['whentoping'],$edit['submitmainrss'],serialize($edit['voc'])); - } else { - db_query("UPDATE {multiping} SET name='%s',url='%s',method='%s',whentoping='%s',submitmainrss='%s',voc='%s' ". - "WHERE id=%d",$edit['name'],$edit['url'],$edit['method'],$edit['whentoping'],$edit['submitmainrss'],serialize($edit['voc']),$edit['id']); - } - } elseif ($edit['form_id']=='multiping_settings') { - $settings=_multiping_get_settings(); - $settings['global']['time_between_pings']=$edit['time_between_pings']; - $settings['global']['pingatonce']=$edit['pingatonce']; - variable_set('multiping', $settings); - } - drupal_goto("admin/settings/multiping"); - } elseif (arg(3)=="new") { + if (arg(3)=="new") { $output .= _multiping_form(0); } elseif (arg(3)=="edit") { if (!is_numeric(arg(4))) return; @@ -322,28 +363,6 @@ $output .= "".l(t('Return'),"admin/settings/multiping").""; } else { // General settings - $form=array(); - $settings=_multiping_get_settings(); - $form['global']['time_between_pings'] = array( - '#type' => 'textfield', - '#title' => t('Time between pings'), - '#default_value' => $settings['global']['time_between_pings'], - '#size' => 8, - '#maxlength' => 4, - '#description' => t('Minimum number of minutes between two pings to same site'), - '#attributes' => NULL, - '#required' => TRUE, - ); - $form['pingatonce'] = array( - '#type' => 'checkbox', - '#title' => t('Ping after post'), - '#default_value' => $settings['global']['pingatonce'], - '#description' => t('Ping directly after post/update (instead of pinging during the cron job runs)'), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); $output .= drupal_get_form('multiping_settings', $form); // Table with services $header = array(t('Name'), t('Last update'), array('data' => t('Operations'), 'colspan' => '2'));
Note: multiping.module contains TAB so it would be better to download the patch directly here which made against multiping 4.7-1.1r3.
Tags: drupal, ping, multiping, patch
| Attachment | Size |
|---|---|
| multiping-4.7-1.1r3-drupal5.patch | 7.88 KB |
- sugree's blog
- 2333 reads

Thanks for your work!
me too
patching: rejected hunks
mismatch whitespace
That's my fault. I don't know why but the patch was invalid. Please get the correct patch again. In addition, you have to use
patch -lto ignore whitespace since it actually containsTAB.yay!
Thanks!
Just what I was looking for!
Post new comment