diff -upr stock/multiping/multiping.install modified/multiping/multiping.install --- stock/multiping/multiping.install 2008-02-25 02:37:08.000000000 -0600 +++ modified/multiping/multiping.install 2008-04-01 11:00:52.000000000 -0500 @@ -10,11 +10,11 @@ function _multiping_create_table1() { '`url` VARCHAR( 255 ) NOT NULL ,'. '`method` VARCHAR( 50 ) ,'. '`lastping` int(11) default \'0\','. - '`whentoping` INT default \'1\','. - '`submitmainrss` INT default \'0\','. - '`voc` text,'. - '`nodetypes` text,'. - '`failcount` INT default \'0\','. + '`whentoping` INT default \'1\','. + '`submitmainrss` INT default \'0\','. + '`voc` text,'. + '`nodetypes` text,'. + '`failcount` INT default \'0\','. 'PRIMARY KEY ( `id` )'. ') TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */'); break; @@ -26,11 +26,11 @@ function _multiping_create_table1() { '`url` VARCHAR( 255 ) NOT NULL ,'. '`method` VARCHAR( 50 ) ,'. '`lastping` int(11) default \'0\','. - '`whentoping` INT default \'1\','. - '`submitmainrss` INT default \'0\','. - '`voc` text,'. - '`nodetypes` text,'. - '`failcount` INT default \'0\','. + '`whentoping` INT default \'1\','. + '`submitmainrss` INT default \'0\','. + '`voc` text,'. + '`nodetypes` text,'. + '`failcount` INT default \'0\','. 'PRIMARY KEY ( `id` )'. ')'); break; @@ -43,7 +43,8 @@ function multiping_install() { if ($ret) { db_query("INSERT INTO {multiping} VALUES (1, 'Ping-o-matic', 'http://rpc.pingomatic.com', 'weblogUpdates.ping', 0, 9, 1, 'N;', 'N;', 0);"); drupal_set_message(t('Multiping module installed succesfully.')); - } else { + } + else { drupal_set_message(t('Multiping module installation was unsuccessful. The necessary database table may have to be created by hand.', 'error')); } @@ -51,11 +52,12 @@ function multiping_install() { } function multiping_update_1() { - $result = db_query('SELECT * FROM {multiping} LIMIT 1'); + $result = db_query_range('SELECT * FROM {multiping}', 0, 1); if (db_num_rows($result) == 0) { $items[] = update_sql('DROP TABLE {multiping}'); $items[] = _multiping_create_table1(); - } else { + } + else { $row = db_fetch_array($result); if (!isset($row['whentoping'])) { $items[] = _system_update_utf8(array('multiping')); @@ -70,7 +72,7 @@ function multiping_update_1() { function multiping_update_2() { $items=multiping_update_1(); - $result = db_query('SELECT * FROM {multiping} LIMIT 1'); + $result = db_query_range('SELECT * FROM {multiping}', 0, 1); $row = db_fetch_array($result); if (!isset($row['nodetypes'])) { // Add new column @@ -79,6 +81,4 @@ function multiping_update_2() { $items[] = update_sql("UPDATE `multiping` SET whentoping=3 WHERE whentoping=2"); } return $items; -} - -?> +} \ No newline at end of file diff -upr stock/multiping/multiping.module modified/multiping/multiping.module --- stock/multiping/multiping.module 2008-02-25 02:37:08.000000000 -0600 +++ modified/multiping/multiping.module 2008-04-01 10:43:22.000000000 -0500 @@ -1,9 +1,9 @@ 'admin/settings/multiping', + $items[] = array('path' => 'admin/settings/multiping', 'title' => t('Multiping'), 'description' => t('Configure when to ping which sites'), 'callback' => 'multiping_admin', - /*'callback' => 'drupal_get_form', - 'callback arguments' => array('multiping_admin'),*/ + /* 'callback' => 'drupal_get_form', + 'callback arguments' => array('multiping_admin'), */ 'access' => user_access('admin pings')); //} @@ -67,39 +67,42 @@ function _multiping_doping($pingservice) $name=variable_get('site_name', ''); $slogan=variable_get('site_slogan', ''); if (strlen($slogan)>0) - $name=$name.' - '.$slogan; + $name=$name .' - '. $slogan; // Determine rss url - if (module_exists('taxonomy') + if (module_exists('taxonomy') && ($pingservice->whentoping & _multiping_when_taxonomy) && 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 $voc=unserialize($pingservice->voc); - $rss_url=$base_url."/taxonomy/term/".implode("+",$voc)."/0/feed"; - } else { - $rss_url=$base_url."/node/feed"; + $rss_url=$base_url ."/taxonomy/term/". implode("+", $voc) ."/0/feed"; + } + else { + $rss_url=$base_url ."/node/feed"; } // Ping! Check service method if ($pingservice->method && strlen($pingservice->method)>0) { //watchdog("Multiping","XML ping: ".$pingservice->url); - $result = xmlrpc($pingservice->url, $pingservice->method, $name, $base_url,$rss_url); - } else { - $pingurl=strtr($pingservice->url,array( + $result = xmlrpc($pingservice->url, $pingservice->method, $name, $base_url, $rss_url); + } + else { + $pingurl=strtr($pingservice->url, array( "%name" => urlencode($name), - "%url" => urlencode($base_url."/"), + "%url" => urlencode($base_url ."/"), "%rss" => urlencode($rss_url)) ); $result = drupal_http_request($pingurl); //watchdog("Multiping","Non-XML ping: ".$pingurl." Result: ".$result->code." Data: '".$result->data."'"); if ($result->code==200) { - if (strpos($result->data,"1")==0) + if (strpos($result->data, "1")==0) $result = TRUE; else $result = FALSE; - } else $result = FALSE; + } + else $result = FALSE; } // On success: Update timestamp if ($result) - db_query("UPDATE {multiping} SET lastping=%d WHERE id=%d",time(),$pingservice->id); + db_query("UPDATE {multiping} SET lastping=%d WHERE id=%d", time(), $pingservice->id); return $result; } @@ -118,26 +121,26 @@ function _multiping_checkpings() { if (module_exists('taxonomy') && ($row->whentoping & _multiping_when_taxonomy)) { // Find most recent date for nodes with given taxonomy $voc=unserialize($row->voc); - $sql_from=$sql_from.", {term_node} t"; - $sql_where=$sql_where." AND t.nid=n.nid AND (t.tid=".implode(" OR t.tid=",$voc).")"; + $sql_from=$sql_from .", {term_node} t"; + $sql_where=$sql_where ." AND t.nid=n.nid AND (t.tid=". implode(" OR t.tid=", $voc) .")"; } // Nodetype selection if ($row->whentoping & _multiping_when_nodetype) { $nodetype=unserialize($row->nodetypes); - $sql_where=$sql_where." AND (n.type='".implode("' OR n.type='",$nodetype)."')"; + $sql_where=$sql_where ." AND (n.type='". implode("' OR n.type='", $nodetype) ."')"; } // Promoted to front page? if ($row->whentoping & _multiping_when_frontpage) { - $sql_where=$sql_where." AND n.promote>0"; + $sql_where=$sql_where ." AND n.promote>0"; } //watchdog("debug","Multiping ".$row->name.": SELECT * FROM ".$sql_from." WHERE ".$sql_where); // Get max creation and modification time $max_created = 0; - $res_time = db_query('SELECT max(created) FROM '.$sql_from.' WHERE '.$sql_where); + $res_time = db_query('SELECT max(created) FROM {'. $sql_from .'} WHERE '. $sql_where); $row_time = db_fetch_array($res_time); if ($row_time) $max_created=$row_time['max(created)']; $max_changed = 0; - $res_time = db_query('SELECT max(changed) FROM '.$sql_from.' WHERE '.$sql_where); + $res_time = db_query('SELECT max(changed) FROM {'. $sql_from .'} WHERE '. $sql_where); $row_time = db_fetch_array($res_time); if ($row_time) $max_changed=$row_time['max(changed)']; if ($max_created>$max_changed) @@ -147,19 +150,20 @@ function _multiping_checkpings() { // Check wether to ping service if ($lastmodified>$row->lastping) { // With every failure, exponentially increase retry time - $retry_time=$settings['global']['time_between_pings']*pow(1.5,$row->failcount); + $retry_time=$settings['global']['time_between_pings']*pow(1.5, $row->failcount); if ($retry_time>24*60) // Retry at least once a day $retry_time=24*60; if ($row->lastping+60*$retry_time>time()) { // Timeout not yet reached - watchdog("Multiping","Timeout for service ".$row->name." not yet reached"); - } elseif (_multiping_doping($row)) { - watchdog("Multiping", t('Successfully notified %site.',array('%site' => $row->name))); - db_query("UPDATE {multiping} SET failcount='0' WHERE id=%d",$row->id); - } else { - watchdog("Multiping", t('Failed to notify %site.',array('%site' => $row->name)), WATCHDOG_WARNING); - db_query("UPDATE {multiping} SET failcount='%d' WHERE id=%d", - ($row->failcount)+1,$row->id); + watchdog("Multiping", "Timeout for service ". $row->name ." not yet reached"); + } + elseif (_multiping_doping($row)) { + watchdog("Multiping", t('Successfully notified %site.', array('%site' => $row->name))); + db_query("UPDATE {multiping} SET failcount='0' WHERE id=%d", $row->id); + } + else { + watchdog("Multiping", t('Failed to notify %site.', array('%site' => $row->name)), WATCHDOG_WARNING); + db_query("UPDATE {multiping} SET failcount='%d' WHERE id=%d", ($row->failcount)+1, $row->id); } } } @@ -205,7 +209,7 @@ function multiping_edit_service($id) { $edit['voc']=''; $edit['nodetype']=''; if ($id>0) { - $result = db_query('SELECT * FROM {multiping} WHERE id=%d',$id); + $result = db_query('SELECT * FROM {multiping} WHERE id=%d', $id); $row = db_fetch_object($result); if ($row) { $edit['name']=$row->name; @@ -218,8 +222,9 @@ function multiping_edit_service($id) { $edit['submitmainrss']=$row->submitmainrss; $edit['voc']=unserialize($row->voc); $edit['nodetype']=unserialize($row->nodetypes); - } else { - watchdog("Multiping","Query for id=$id returned 0 rows", WATCHDOG_WARNING); + } + else { + watchdog("Multiping", "Query for id=$id returned 0 rows", WATCHDOG_WARNING); $id=0; } } @@ -252,8 +257,10 @@ function multiping_edit_service($id) { '#attributes' => NULL, '#required' => TRUE, ); - /* Todo: Welcher RSS-Feed soll übergeben werden? Default (alle) oder nur + /* Todo: Welcher RSS-Feed soll übergeben werden? Default (alle) oder nur für bestimmte Taxonomie? */ + /* Todo: Which RSS Feed should be given over? Default (all) or only for + for particular taxonomies? */ $form['method'] = array( '#type' => 'textfield', '#title' => t('Method name'), @@ -266,7 +273,7 @@ function multiping_edit_service($id) { ); $options = array('1' => t('Always ping'), '0' => t('Don\'t ping')); if (module_exists('taxonomy')) { - $options['2']=t('Ping only for nodes with the following taxonomy'); + $options['2']=t('Ping only for nodes with the following taxonomy'); } $form['when_active'] = array( '#type' => 'checkbox', @@ -325,10 +332,10 @@ function multiping_edit_service($id) { function _multiping_form($id) { - /*$bcrumb=drupal_get_breadcrumb(); - $bcrumb[]=array('path' => 'admin/settings/multiping', + /* $bcrumb=drupal_get_breadcrumb(); + $bcrumb[]=array('path' => 'admin/settings/multiping', 'title' => 'Multiping'); - drupal_set_breadcrumb($bcrumb);*/ + drupal_set_breadcrumb($bcrumb); */ return drupal_get_form('multiping_edit_service', $id); } @@ -380,14 +387,15 @@ function multiping_settings_submit($form $edit['when_frontpage']*_multiping_when_frontpage; if ($edit['id']==0) { db_query("INSERT INTO {multiping} (name,url,method,whentoping,submitmainrss,voc,nodetypes) ". - "VALUES ('%s','%s','%s','%s','%s','%s','%s')",$edit['name'],$edit['url'], - $edit['method'],$whentoping,$edit['submitmainrss'], - serialize($edit['voc']),serialize($edit['nodetype'])); - } else { - db_query("UPDATE {multiping} SET name='%s',url='%s',method='%s',whentoping='%s',submitmainrss='%s',voc='%s',nodetypes='%s' ". - "WHERE id=%d",$edit['name'],$edit['url'],$edit['method'],$whentoping,$edit['submitmainrss'],serialize($edit['voc']),serialize($edit['nodetype']),$edit['id']); + "VALUES ('%s','%s','%s','%s','%s','%s','%s')", $edit['name'], $edit['url'], + $edit['method'], $whentoping, $edit['submitmainrss'], + serialize($edit['voc']), serialize($edit['nodetype'])); } - } elseif ($edit['form_id']=='multiping_settings') { + else { + db_query("UPDATE {multiping} SET name='%s',url='%s',method='%s',whentoping='%s',submitmainrss='%s',voc='%s',nodetypes='%s' "."WHERE id=%d", $edit['name'], $edit['url'], $edit['method'], $whentoping, $edit['submitmainrss'], serialize($edit['voc']), serialize($edit['nodetype']), $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']; @@ -404,24 +412,28 @@ function multiping_admin() { $output = ""; if (arg(3)=="new") { $output .= _multiping_form(0); - } elseif (arg(3)=="edit") { + } + elseif (arg(3)=="edit") { if (!is_numeric(arg(4))) return; $output .= _multiping_form(intval(arg(4))); - } elseif (arg(3)=="delete") { + } + elseif (arg(3)=="delete") { if (!is_numeric(arg(4))) return; - db_query("DELETE FROM {multiping} WHERE id=%d",intval(arg(4))); + db_query("DELETE FROM {multiping} WHERE id=%d", intval(arg(4))); drupal_goto("admin/settings/multiping"); return; - } elseif (arg(3)=="pingnow") { - $output .= "

".t("Running all pings...")."

"; + } + elseif (arg(3)=="pingnow") { + $output .= "

". t("Running all pings...") ."

"; $header = array(t('Name'), t('Status')); $result = db_query('SELECT * FROM {multiping} ORDER BY id'); while ($row = db_fetch_object($result)) { - $rows[] = array($row->name,_multiping_doping($row) ? t('Ok') : t('Failed')); + $rows[] = array($row->name, _multiping_doping($row) ? t('Ok') : t('Failed')); } - $output .= theme('table',$header,$rows); - $output .= "

".l(t('Return'),"admin/settings/multiping")."

"; - } else { + $output .= theme('table', $header, $rows); + $output .= "

". l(t('Return'), "admin/settings/multiping") ."

"; + } + else { // General settings $output .= drupal_get_form('multiping_settings', $form); // Table with services @@ -430,12 +442,12 @@ function multiping_admin() { while ($row = db_fetch_object($result)) { if ($row->lastping==0) $lastping=t('never'); else - $lastping=format_date($row->lastping,'small'); - $rows[] = array($row->name,$lastping,l(t('edit'),"admin/settings/multiping/edit/".$row->id),l(t('delete'),"admin/settings/multiping/delete/".$row->id)); + $lastping=format_date($row->lastping, 'small'); + $rows[] = array($row->name, $lastping, l(t('edit'), "admin/settings/multiping/edit/". $row->id), l(t('delete'), "admin/settings/multiping/delete/". $row->id)); } - $output .= theme('table',$header,$rows); - $output .= "

".l(t('Add service'),"admin/settings/multiping/new")."

"; - $output .= "

".l(t('Ping now!'),"admin/settings/multiping/pingnow")."

"; + $output .= theme('table', $header, $rows); + $output .= "

". l(t('Add service'), "admin/settings/multiping/new") ."

"; + $output .= "

". l(t('Ping now!'), "admin/settings/multiping/pingnow") ."

"; } return $output; }