NP_Ping Tweaks - Code
Posted on 18/02/08 00:29
I posted about some tweaks I'd made to NP_Ping, and someone asked what they were. I'm not entirely convinced whoever asked was doing so for reasons other than more sophisticated comment spam, but in case they were genuine, or anyone else it truly interested, read on for the full changes.
So, there are two main changes. The first was changing the URL to the Technorati API, to remove the trailing slash. To be honest, I'm not 100% sure it matters, but they give the URL without it, the original (v1.5) code had the slash, and at the time I was having problems. It now works, and it didn't before - even if I suspect it was due to Technorati, not the NP_Ping code.
The second change was to enable logging of Pings in the Action Log - something I'd done previously for NP_PingPong. Mostly this is for debug purposes - NP_PingPong didn't, if I recall correctly, tell you whether it worked or not. NP_Ping does that after posting the article, but I don't think it tells you any more if the ping fails, whereas I write the errors to the log. I can't claim the code's pretty or efficient (the only serious coding I ever did was ANSI C and C64 BASIC - a long time ago, and quite frankly, I wasn't very good at either of them), but it works. There's a new option added to allow you to choose whether you want pings logged or not, and two new functions to log either a fail or success. These functions are called within the functions to ping each blog tracking service based on whether the ping succeeded or not.
The easiest way to spot the changes is to do a diff against v1.5 of NP_Ping, but I have provided comments, so you may spot them too. As for how it works, it should be fairly obvious - I managed to write it after all! If not, check the Nucleus plugin API documentation.
Finally, a big thanks to admun (Edmond Hui) for all the work writing NP_Ping (and many other useful plugins, and I suspect a large part of Nucleus CMS too) in the first place so that I could hack it about to fit my needs.
To install, you still need ping.php and english.php in the ping directory within your plugin directory (ie don't change anything here!), but use the code below to replace NP_Ping.php. When you've updated the file in your plugin directory, go to the Nucleus Admin area, select plugins, and you should be able to (re-)install NP_Ping. It should be listed a version 1.5.1KW, and in it's options, you should now have a new option to log each ping to the Action Log, which defaults to 'no'.
<?
/*
Note: based on NP_PingPong, adapt for the new ping mechanism
History
v1.0 - Initial version
v1.1 - Add JustPosted event support
v1.2 - JustPosted event handling in background
v1.3 - pinged variable support
v1.4 - language file support
v1.5 - remove arg1 in exec() call
v1.5.1KW - Added logging of success (or error + message) to ActionLog,
as current logging doesn't seem to work.
Also changed Technorati RPC URL to remove trailing slash.
*/
class NP_Ping extends NucleusPlugin {
function getName() { return 'Ping'; }
function getAuthor() { return 'admun (Edmond Hui)'; }
function getURL() { return 'http://edmondhui.homeip.net/nudn'; }
function getVersion() { return '1.5.1KW'; }
function getMinNucleusVersion() { return '330'; }
function getDescription() {
return _PING_DESC;
}
function supportsFeature($what) {
switch($what) {
case 'SqlTablePrefix':
return 1;
default:
return 0;
}
}
function init()
{
$language = ereg_replace( '[\\|/]', '', getLanguageName());
if (file_exists($this->getDirectory() . $language . '.php')) {
include_once($this->getDirectory() . $language . '.php');
}else {
include_once($this->getDirectory() . 'english.php');
}
}
function install() {
$this->createOption('pingpong_pingomatic',_PING_PINGOM,'yesno','yes'); // Default, http://pingomatic.com
$this->createOption('pingpong_weblogs',_PING_WEBLOGS,'yesno','no'); // http://weblogs.com
$this->createOption('pingpong_technorati',_PING_TECHNOR,'yesno','no'); // http://www.technorati.com
$this->createOption('pingpong_blogrolling',_PING_BLOGR,'yesno','no'); // http://www.blogrolling.com
$this->createOption('pingpong_blogs',_PING_BLOGS,'yesno','no'); // http://blo.gs
$this->createOption('pingpong_weblogues',_PING_WEBLOGUES,'yesno','no'); // http://weblogues.com/
$this->createOption('pingpong_bloggde',_PING_BLOGGDE,'yesno','no'); // http://blogg.de
$this->createOption('ping_background',_PING_BG,'yesno','yes');
$this->createOption('pingpong_log', 'Log each ping to Action Log?', 'yesno', 'no'); // Enables Action Log logging of each ping (added by KW 08-01-2008)
}
function getEventList() {
return array('SendPing', 'JustPosted');
}
function event_JustPosted($data) {
global $DIR_PLUGINS, $DIR_NUCLEUS;
// exit is another plugin already send ping
if ($data['pinged'] == true) {
return;
}
if ($this->getOption('ping_background') == "yes") {
exec("php $DIR_PLUGINS/ping/ping.php " . $data['blogid'] . " &");
} else {
$this->sendPings($data['blogid']);
ACTIONLOG::add(INFO, 'NP_Ping: Sending ping (from foreground)');
}
// mark the ping has been sent
$data['pinged'] = true;
}
function event_SendPing($data) {
$this->sendPings($data);
}
function sendPings($data) {
if (!class_exists('xmlrpcmsg')) {
global $DIR_LIBS;
include($DIR_LIBS . 'xmlrpc.inc.php');
}
$this->myBlogId = $data['blogid'];
if ($this->getOption('pingpong_pingomatic')=='yes') {
echo _PINGING . "Ping-o-matic:<br/>";
echo $this->pingPingomatic();
echo "<br/>";
}
if ($this->getOption('pingpong_weblogs')=='yes') {
echo _PINGING . "Weblogs.com:<br/>";
echo $this->pingWeblogs();
echo "<br/>";
}
if ($this->getOption('pingpong_technorati')=='yes') {
echo _PINGING . "Technorati:<br/>";
echo $this->pingTechnorati();
echo "<br/>";
}
if ($this->getOption('pingpong_blogrolling')=='yes') {
echo _PINGING . "Blogrolling.com:<br/>";
echo $this->pingBlogRollingDotCom();
echo "<br/>";
}
if ($this->getOption('pingpong_blogs')=='yes') {
echo _PINGING . "Blog.gs:<br/>";
echo $this->pingBloGs();
echo "<br/>";
}
if ($this->getOption('pingpong_weblogues')=='yes') {
echo _PINGING . "Weblogues.com:<br/>";
echo $this->pingWebloguesDotCom();
echo "<br/>";
}
if ($this->getOption('pingpong_bloggde')=='yes') {
echo _PINGING . "Blog.de:<br/>";
echo $this->pingBloggDe();
echo "<br/>";
}
}
function pingPingomatic() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.ping', array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getURL(),'string')
));
$c = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("Pingomatic");
} else {
$this->logPingFail("Pingomatic", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingWeblogs() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogupdates.ping',array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getUrl(),'string')
));
$c = new xmlrpc_client('/rpc2', 'rpc.weblogs.com', 80);
//$c->setdebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("Weblogs");
} else {
$this->logPingFail("Weblogs", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingTechnorati() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.ping', array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getURL(),'string')
));
$c = new xmlrpc_client('/rpc/ping', 'rpc.technorati.com', 80); // Note - removed trailing slash (/rpc/ping/) KW 08-01-2008
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("Technorati");
} else {
$this->logPingFail("Technorati", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingBlogRollingDotCom() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.ping',
array(
new xmlrpcval($b->getName(),'string'), // your blog title
new xmlrpcval($b->getURL(),'string') // your blog url
));
$c = new xmlrpc_client('/pinger/', 'rpc.blogrolling.com', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("BlogRollingDotCom");
} else {
$this->logPingFail("BlogRollingDotCom", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingBloGs() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.extendedPing', array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getURL(),'string')
));
$c = new xmlrpc_client('/', 'ping.blo.gs', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("BloGs");
} else {
$this->logPingFail("BloGs", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingWebloguesDotCom() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.extendedPing',
array(
new xmlrpcval($b->getName(),'string'), // your blog title
new xmlrpcval($b->getURL(),'string') // your blog url
));
$c = new xmlrpc_client('/RPC/', 'www.weblogues.com', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("WebloguesDotCom");
} else {
$this->logPingFail("WebloguesDotCom", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingBloggDe() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'bloggUpdates.ping', array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getURL(),'string')
));
$c = new xmlrpc_client('/', 'xmlrpc.blogg.de', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("BloggDe");
} else {
$this->logPingFail("BloggDe", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function processPingResult($r) {
global $php_errormsg;
if (($r == 0) && ($r->errno || $r->errstring)) {
return _PING_ERROR . " " . $r->errno . ' : ' . $r->errstring;
} elseif (($r == 0) && ($php_errormsg)) {
return _PING_PHP_ERROR . $php_errormsg;
} elseif ($r == 0) {
return _PING_PHP_PING_ERROR;
} elseif ($r->faultCode() != 0) {
return _PING_ERROR . ': ' . $r->faultString();
} else {
$r = $r->value(); // get response struct
// get values
$flerror = $r->structmem('flerror');
$flerror = $flerror->scalarval();
$message = $r->structmem('message');
$message = $message->scalarval();
if ($flerror != 0) {
return _PING_ERROR . ' (flerror=1): ' . $message;
}
else {
return _PING_SUCCESS . ': ' . $message;
}
}
}
function logPingSuccess($sitename) {
/*
This function logs successful pings to the action log,
recording the site name (passed in function call)
*/
ACTIONLOG::add(INFO, "Successfully pinged " . $sitename . ".");
}
function logPingFail($sitename, $fcode, $fstring) {
/*
This function logs failed pings to the action log,
recording the site name and the fault code and
string (passed in function call)
*/
ACTIONLOG::add(WARNING, "Failed to ping " . $sitename . ". Code: " . $fcode . " Reason: " . $fstring);
}
}
?>
So, there are two main changes. The first was changing the URL to the Technorati API, to remove the trailing slash. To be honest, I'm not 100% sure it matters, but they give the URL without it, the original (v1.5) code had the slash, and at the time I was having problems. It now works, and it didn't before - even if I suspect it was due to Technorati, not the NP_Ping code.
The second change was to enable logging of Pings in the Action Log - something I'd done previously for NP_PingPong. Mostly this is for debug purposes - NP_PingPong didn't, if I recall correctly, tell you whether it worked or not. NP_Ping does that after posting the article, but I don't think it tells you any more if the ping fails, whereas I write the errors to the log. I can't claim the code's pretty or efficient (the only serious coding I ever did was ANSI C and C64 BASIC - a long time ago, and quite frankly, I wasn't very good at either of them), but it works. There's a new option added to allow you to choose whether you want pings logged or not, and two new functions to log either a fail or success. These functions are called within the functions to ping each blog tracking service based on whether the ping succeeded or not.
The easiest way to spot the changes is to do a diff against v1.5 of NP_Ping, but I have provided comments, so you may spot them too. As for how it works, it should be fairly obvious - I managed to write it after all! If not, check the Nucleus plugin API documentation.
Finally, a big thanks to admun (Edmond Hui) for all the work writing NP_Ping (and many other useful plugins, and I suspect a large part of Nucleus CMS too) in the first place so that I could hack it about to fit my needs.
To install, you still need ping.php and english.php in the ping directory within your plugin directory (ie don't change anything here!), but use the code below to replace NP_Ping.php. When you've updated the file in your plugin directory, go to the Nucleus Admin area, select plugins, and you should be able to (re-)install NP_Ping. It should be listed a version 1.5.1KW, and in it's options, you should now have a new option to log each ping to the Action Log, which defaults to 'no'.
<?
/*
Note: based on NP_PingPong, adapt for the new ping mechanism
History
v1.0 - Initial version
v1.1 - Add JustPosted event support
v1.2 - JustPosted event handling in background
v1.3 - pinged variable support
v1.4 - language file support
v1.5 - remove arg1 in exec() call
v1.5.1KW - Added logging of success (or error + message) to ActionLog,
as current logging doesn't seem to work.
Also changed Technorati RPC URL to remove trailing slash.
*/
class NP_Ping extends NucleusPlugin {
function getName() { return 'Ping'; }
function getAuthor() { return 'admun (Edmond Hui)'; }
function getURL() { return 'http://edmondhui.homeip.net/nudn'; }
function getVersion() { return '1.5.1KW'; }
function getMinNucleusVersion() { return '330'; }
function getDescription() {
return _PING_DESC;
}
function supportsFeature($what) {
switch($what) {
case 'SqlTablePrefix':
return 1;
default:
return 0;
}
}
function init()
{
$language = ereg_replace( '[\\|/]', '', getLanguageName());
if (file_exists($this->getDirectory() . $language . '.php')) {
include_once($this->getDirectory() . $language . '.php');
}else {
include_once($this->getDirectory() . 'english.php');
}
}
function install() {
$this->createOption('pingpong_pingomatic',_PING_PINGOM,'yesno','yes'); // Default, http://pingomatic.com
$this->createOption('pingpong_weblogs',_PING_WEBLOGS,'yesno','no'); // http://weblogs.com
$this->createOption('pingpong_technorati',_PING_TECHNOR,'yesno','no'); // http://www.technorati.com
$this->createOption('pingpong_blogrolling',_PING_BLOGR,'yesno','no'); // http://www.blogrolling.com
$this->createOption('pingpong_blogs',_PING_BLOGS,'yesno','no'); // http://blo.gs
$this->createOption('pingpong_weblogues',_PING_WEBLOGUES,'yesno','no'); // http://weblogues.com/
$this->createOption('pingpong_bloggde',_PING_BLOGGDE,'yesno','no'); // http://blogg.de
$this->createOption('ping_background',_PING_BG,'yesno','yes');
$this->createOption('pingpong_log', 'Log each ping to Action Log?', 'yesno', 'no'); // Enables Action Log logging of each ping (added by KW 08-01-2008)
}
function getEventList() {
return array('SendPing', 'JustPosted');
}
function event_JustPosted($data) {
global $DIR_PLUGINS, $DIR_NUCLEUS;
// exit is another plugin already send ping
if ($data['pinged'] == true) {
return;
}
if ($this->getOption('ping_background') == "yes") {
exec("php $DIR_PLUGINS/ping/ping.php " . $data['blogid'] . " &");
} else {
$this->sendPings($data['blogid']);
ACTIONLOG::add(INFO, 'NP_Ping: Sending ping (from foreground)');
}
// mark the ping has been sent
$data['pinged'] = true;
}
function event_SendPing($data) {
$this->sendPings($data);
}
function sendPings($data) {
if (!class_exists('xmlrpcmsg')) {
global $DIR_LIBS;
include($DIR_LIBS . 'xmlrpc.inc.php');
}
$this->myBlogId = $data['blogid'];
if ($this->getOption('pingpong_pingomatic')=='yes') {
echo _PINGING . "Ping-o-matic:<br/>";
echo $this->pingPingomatic();
echo "<br/>";
}
if ($this->getOption('pingpong_weblogs')=='yes') {
echo _PINGING . "Weblogs.com:<br/>";
echo $this->pingWeblogs();
echo "<br/>";
}
if ($this->getOption('pingpong_technorati')=='yes') {
echo _PINGING . "Technorati:<br/>";
echo $this->pingTechnorati();
echo "<br/>";
}
if ($this->getOption('pingpong_blogrolling')=='yes') {
echo _PINGING . "Blogrolling.com:<br/>";
echo $this->pingBlogRollingDotCom();
echo "<br/>";
}
if ($this->getOption('pingpong_blogs')=='yes') {
echo _PINGING . "Blog.gs:<br/>";
echo $this->pingBloGs();
echo "<br/>";
}
if ($this->getOption('pingpong_weblogues')=='yes') {
echo _PINGING . "Weblogues.com:<br/>";
echo $this->pingWebloguesDotCom();
echo "<br/>";
}
if ($this->getOption('pingpong_bloggde')=='yes') {
echo _PINGING . "Blog.de:<br/>";
echo $this->pingBloggDe();
echo "<br/>";
}
}
function pingPingomatic() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.ping', array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getURL(),'string')
));
$c = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("Pingomatic");
} else {
$this->logPingFail("Pingomatic", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingWeblogs() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogupdates.ping',array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getUrl(),'string')
));
$c = new xmlrpc_client('/rpc2', 'rpc.weblogs.com', 80);
//$c->setdebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("Weblogs");
} else {
$this->logPingFail("Weblogs", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingTechnorati() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.ping', array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getURL(),'string')
));
$c = new xmlrpc_client('/rpc/ping', 'rpc.technorati.com', 80); // Note - removed trailing slash (/rpc/ping/) KW 08-01-2008
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("Technorati");
} else {
$this->logPingFail("Technorati", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingBlogRollingDotCom() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.ping',
array(
new xmlrpcval($b->getName(),'string'), // your blog title
new xmlrpcval($b->getURL(),'string') // your blog url
));
$c = new xmlrpc_client('/pinger/', 'rpc.blogrolling.com', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("BlogRollingDotCom");
} else {
$this->logPingFail("BlogRollingDotCom", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingBloGs() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.extendedPing', array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getURL(),'string')
));
$c = new xmlrpc_client('/', 'ping.blo.gs', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("BloGs");
} else {
$this->logPingFail("BloGs", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingWebloguesDotCom() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'weblogUpdates.extendedPing',
array(
new xmlrpcval($b->getName(),'string'), // your blog title
new xmlrpcval($b->getURL(),'string') // your blog url
));
$c = new xmlrpc_client('/RPC/', 'www.weblogues.com', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("WebloguesDotCom");
} else {
$this->logPingFail("WebloguesDotCom", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function pingBloggDe() {
$b = new BLOG($this->myBlogId);
$message = new xmlrpcmsg(
'bloggUpdates.ping', array(
new xmlrpcval($b->getName(),'string'),
new xmlrpcval($b->getURL(),'string')
));
$c = new xmlrpc_client('/', 'xmlrpc.blogg.de', 80);
//$c->setDebug(1);
$r = $c->send($message,30); // 30 seconds timeout...
/* Log the event in the action log (added by KW 08-01-2008) */
if (!$r->faultcode() && $this->getOption('pingpong_log')) {
$this->logPingSuccess("BloggDe");
} else {
$this->logPingFail("BloggDe", $r->faultcode(), $r->faultstring());
}
/* end of event logging */
return $this->processPingResult($r);
}
function processPingResult($r) {
global $php_errormsg;
if (($r == 0) && ($r->errno || $r->errstring)) {
return _PING_ERROR . " " . $r->errno . ' : ' . $r->errstring;
} elseif (($r == 0) && ($php_errormsg)) {
return _PING_PHP_ERROR . $php_errormsg;
} elseif ($r == 0) {
return _PING_PHP_PING_ERROR;
} elseif ($r->faultCode() != 0) {
return _PING_ERROR . ': ' . $r->faultString();
} else {
$r = $r->value(); // get response struct
// get values
$flerror = $r->structmem('flerror');
$flerror = $flerror->scalarval();
$message = $r->structmem('message');
$message = $message->scalarval();
if ($flerror != 0) {
return _PING_ERROR . ' (flerror=1): ' . $message;
}
else {
return _PING_SUCCESS . ': ' . $message;
}
}
}
function logPingSuccess($sitename) {
/*
This function logs successful pings to the action log,
recording the site name (passed in function call)
*/
ACTIONLOG::add(INFO, "Successfully pinged " . $sitename . ".");
}
function logPingFail($sitename, $fcode, $fstring) {
/*
This function logs failed pings to the action log,
recording the site name and the fault code and
string (passed in function call)
*/
ACTIONLOG::add(WARNING, "Failed to ping " . $sitename . ". Code: " . $fcode . " Reason: " . $fstring);
}
}
?>

