| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: multiping.module,v 1.7 2008/08/01 10:04:29 skyr Exp $ |
| 3 |
|
|
| 4 |
define("_multiping_when_active", 1); |
define("_multiping_when_active", 1); |
| 5 |
define("_multiping_when_taxonomy", 2); |
define("_multiping_when_taxonomy", 2); |
| 53 |
$items['admin/settings/multiping/pingall'] = array( |
$items['admin/settings/multiping/pingall'] = array( |
| 54 |
'title' => 'Ping all', |
'title' => 'Ping all', |
| 55 |
'page callback' => 'multiping_pingall', |
'page callback' => 'multiping_pingall', |
| 56 |
|
'access arguments' => array('admin pings'), |
| 57 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 58 |
); |
); |
| 59 |
$items['admin/settings/multiping/new'] = array( |
$items['admin/settings/multiping/new'] = array( |
| 60 |
'title' => 'New ping service', |
'title' => 'New ping service', |
| 61 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 62 |
'page arguments' => array('multiping_edit_service', '0'), |
'page arguments' => array('multiping_edit_service', '0'), |
| 63 |
|
'access arguments' => array('admin pings'), |
| 64 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 65 |
); |
); |
| 66 |
$items['admin/settings/multiping/%/edit'] = array( |
$items['admin/settings/multiping/%/edit'] = array( |
| 67 |
'title' => 'Edit ping service', |
'title' => 'Edit ping service', |
| 68 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 69 |
'page arguments' => array('multiping_edit_service', 3), |
'page arguments' => array('multiping_edit_service', 3), |
| 70 |
|
'access arguments' => array('admin pings'), |
| 71 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 72 |
); |
); |
| 73 |
$items['admin/settings/multiping/%/Ping'] = array( |
$items['admin/settings/multiping/%/ping'] = array( |
| 74 |
'title' => 'Ping service', |
'title' => 'Ping service', |
| 75 |
'page arguments' => array(3), |
'page arguments' => array(3), |
| 76 |
'page callback' => 'multiping_ping', |
'page callback' => 'multiping_ping', |
| 77 |
|
'access arguments' => array('admin pings'), |
| 78 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 79 |
); |
); |
| 80 |
$items['admin/settings/multiping/%/delete'] = array( |
$items['admin/settings/multiping/%/delete'] = array( |
| 81 |
'title' => 'Delete ping service', |
'title' => 'Delete ping service', |
| 82 |
'page arguments' => array(3), |
'page arguments' => array(3), |
| 83 |
'page callback' => 'multiping_delete', |
'page callback' => 'multiping_delete', |
| 84 |
|
'access arguments' => array('admin pings'), |
| 85 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 86 |
); |
); |
| 87 |
return $items; |
return $items; |
| 190 |
$retry_time=24*60; |
$retry_time=24*60; |
| 191 |
if ($row->lastping+60*$retry_time>time()) { |
if ($row->lastping+60*$retry_time>time()) { |
| 192 |
// Timeout not yet reached |
// Timeout not yet reached |
| 193 |
watchdog("Multiping","Timeout for service ".$row->name." not yet reached"); |
watchdog("Multiping", "Timeout for service @name not yet reached", array('@name' => $row->name)); |
| 194 |
} elseif (_multiping_doping($row)) { |
} elseif (_multiping_doping($row)) { |
| 195 |
watchdog("Multiping", t('Successfully notified %site.',array('%site' => $row->name))); |
watchdog("Multiping", 'Successfully notified %site.', array('%site' => $row->name)); |
| 196 |
db_query("UPDATE {multiping} SET failcount='0' WHERE id=%d",$row->id); |
db_query("UPDATE {multiping} SET failcount='0' WHERE id=%d",$row->id); |
| 197 |
} else { |
} else { |
| 198 |
watchdog("Multiping", t('Failed to notify %site.',array('%site' => $row->name)), WATCHDOG_WARNING); |
watchdog("Multiping", 'Failed to notify %site.', array('%site' => $row->name), WATCHDOG_WARNING); |
| 199 |
db_query("UPDATE {multiping} SET failcount='%d' WHERE id=%d", |
db_query("UPDATE {multiping} SET failcount='%d' WHERE id=%d", |
| 200 |
($row->failcount)+1,$row->id); |
($row->failcount)+1,$row->id); |
| 201 |
} |
} |
| 219 |
* If pingatonce is set, check pings. |
* If pingatonce is set, check pings. |
| 220 |
*/ |
*/ |
| 221 |
function multiping_nodeapi(&$node, $op, $a3=NULL, $a4=NULL) { |
function multiping_nodeapi(&$node, $op, $a3=NULL, $a4=NULL) { |
| 222 |
drupal_set_message("op=".$op); |
//drupal_set_message("op=".$op); |
| 223 |
watchdog("Multiping","op=$op"); |
//watchdog("Multiping","op=$op"); |
| 224 |
switch ($op) { |
switch ($op) { |
| 225 |
case 'insert': |
case 'insert': |
| 226 |
case 'update': |
case 'update': |
| 260 |
$edit['voc']=unserialize($row->voc); |
$edit['voc']=unserialize($row->voc); |
| 261 |
$edit['nodetype']=unserialize($row->nodetypes); |
$edit['nodetype']=unserialize($row->nodetypes); |
| 262 |
} else { |
} else { |
| 263 |
watchdog("Multiping","Query for id=$id returned 0 rows", WATCHDOG_WARNING); |
watchdog("Multiping","Query for id=@id returned 0 rows", array('@id' => $id), WATCHDOG_WARNING); |
| 264 |
$id=0; |
$id=0; |
| 265 |
} |
} |
| 266 |
} |
} |
| 366 |
|
|
| 367 |
|
|
| 368 |
function multiping_edit_service_submit($form_id, &$form_state) { |
function multiping_edit_service_submit($form_id, &$form_state) { |
|
if (!user_access('admin pings')) { |
|
|
drupal_not_found(); |
|
|
return; |
|
|
} |
|
| 369 |
$edit = $form_state['values']; // TODO: Is this ok? http://drupal.org/node/144132#process-params |
$edit = $form_state['values']; // TODO: Is this ok? http://drupal.org/node/144132#process-params |
| 370 |
if ($edit['form_id']=='multiping_edit_service') { |
if ($edit['form_id']=='multiping_edit_service') { |
| 371 |
$edit['id'] = ($edit['id'] && is_numeric($edit['id'])) ? $edit['id'] : 0; |
$edit['id'] = ($edit['id'] && is_numeric($edit['id'])) ? $edit['id'] : 0; |
| 422 |
|
|
| 423 |
|
|
| 424 |
function multiping_settings_submit($form_id, &$form_state) { |
function multiping_settings_submit($form_id, &$form_state) { |
|
if (!user_access('admin pings')) { |
|
|
drupal_not_found(); |
|
|
return; |
|
|
} |
|
| 425 |
$edit = $form_state['values']; // TODO: Is this ok? http://drupal.org/node/144132#process-params |
$edit = $form_state['values']; // TODO: Is this ok? http://drupal.org/node/144132#process-params |
| 426 |
if ($edit['form_id']=='multiping_settings') { |
if ($edit['form_id']=='multiping_settings') { |
| 427 |
$settings=_multiping_get_settings(); |
$settings=_multiping_get_settings(); |
| 439 |
* Menu callback: Admin page |
* Menu callback: Admin page |
| 440 |
*/ |
*/ |
| 441 |
function multiping_admin() { |
function multiping_admin() { |
|
if (!user_access('admin pings')) { |
|
|
drupal_not_found(); |
|
|
return; |
|
|
} |
|
| 442 |
$output = ""; |
$output = ""; |
| 443 |
// General settings |
// General settings |
| 444 |
$output .= drupal_get_form('multiping_settings', $form); |
$output .= drupal_get_form('multiping_settings', $form); |
| 465 |
|
|
| 466 |
|
|
| 467 |
function multiping_pingall() { |
function multiping_pingall() { |
|
if (!user_access('admin pings')) { |
|
|
drupal_not_found(); |
|
|
return; |
|
|
} |
|
| 468 |
$output = "<p>".t("Running all pings...")."</p>"; |
$output = "<p>".t("Running all pings...")."</p>"; |
| 469 |
$header = array(t('Name'), t('Status')); |
$header = array(t('Name'), t('Status')); |
| 470 |
$result = db_query('SELECT * FROM {multiping} ORDER BY id'); |
$result = db_query('SELECT * FROM {multiping} ORDER BY id'); |
| 478 |
|
|
| 479 |
|
|
| 480 |
function multiping_ping($id) { |
function multiping_ping($id) { |
| 481 |
if (!user_access('admin pings')) { |
watchdog("Multiping","ping @id", array('@id' => $id)); |
|
drupal_not_found(); |
|
|
return; |
|
|
} |
|
|
watchdog("Multiping","ping $id"); |
|
| 482 |
if (!is_numeric($id)) { |
if (!is_numeric($id)) { |
| 483 |
drupal_not_found(); |
drupal_not_found(); |
| 484 |
return; |
return; |
| 489 |
|
|
| 490 |
|
|
| 491 |
function multiping_delete($id) { |
function multiping_delete($id) { |
| 492 |
if (!user_access('admin pings')) { |
watchdog("Multiping","delete @id", array('@id' => $id)); |
|
drupal_not_found(); |
|
|
return; |
|
|
} |
|
|
watchdog("Multiping","delete $id"); |
|
| 493 |
if (!is_numeric($id)) { |
if (!is_numeric($id)) { |
| 494 |
drupal_not_found(); |
drupal_not_found(); |
| 495 |
return; |
return; |