00001 <?php 00002 /* 00003 Note: based on NP_PingPong, adapt for the new ping mechanism 00004 00005 History 00006 v1.0 - Initial version 00007 v1.1 - Add JustPosted event support 00008 v1.2 - JustPosted event handling in background 00009 v1.3 - pinged variable support 00010 v1.4 - language file support 00011 v1.5 - remove arg1 in exec() call 00012 */ 00013 00014 class NP_Ping extends NucleusPlugin { 00015 00016 function getName() { return 'Ping'; } 00017 00018 function getAuthor() { return 'admun (Edmond Hui)'; } 00019 function getURL() { return 'http://edmondhui.homeip.net/nudn'; } 00020 function getVersion() { return '1.5'; } 00021 00022 function getMinNucleusVersion() { return '330'; } 00023 00024 function getDescription() { 00025 return _PING_DESC; 00026 } 00027 00028 function supportsFeature($what) { 00029 switch($what) { 00030 case 'SqlTablePrefix': 00031 return 1; 00032 default: 00033 return 0; 00034 } 00035 } 00036 00037 function init() 00038 { 00039 $language = ereg_replace( '[\\|/]', '', getLanguageName()); 00040 if (file_exists($this->getDirectory() . $language . '.php')) { 00041 include_once($this->getDirectory() . $language . '.php'); 00042 }else { 00043 include_once($this->getDirectory() . 'english.php'); 00044 } 00045 } 00046 00047 function install() { 00048 $this->createOption('pingpong_pingomatic',_PING_PINGOM,'yesno','yes'); // Default, http://pingomatic.com 00049 $this->createOption('pingpong_weblogs',_PING_WEBLOGS,'yesno','no'); // http://weblogs.com 00050 $this->createOption('pingpong_technorati',_PING_TECHNOR,'yesno','no'); // http://www.technorati.com 00051 $this->createOption('pingpong_blogrolling',_PING_BLOGR,'yesno','no'); // http://www.blogrolling.com 00052 $this->createOption('pingpong_blogs',_PING_BLOGS,'yesno','no'); // http://blo.gs 00053 $this->createOption('pingpong_weblogues',_PING_WEBLOGUES,'yesno','no'); // http://weblogues.com/ 00054 $this->createOption('pingpong_bloggde',_PING_BLOGGDE,'yesno','no'); // http://blogg.de 00055 $this->createOption('ping_background',_PING_BG,'yesno','yes'); 00056 } 00057 00058 function getEventList() { 00059 return array('SendPing', 'JustPosted'); 00060 } 00061 00062 function event_JustPosted($data) { 00063 global $DIR_PLUGINS, $DIR_NUCLEUS; 00064 00065 // exit is another plugin already send ping 00066 if ($data['pinged'] == true) { 00067 return; 00068 } 00069 00070 if ($this->getOption('ping_background') == "yes") { 00071 exec("php $DIR_PLUGINS/ping/ping.php " . $data['blogid'] . " &"); 00072 } else { 00073 $this->sendPings($data['blogid']); 00074 00075 ACTIONLOG::add(INFO, 'NP_Ping: Sending ping (from foreground)'); 00076 } 00077 00078 // mark the ping has been sent 00079 $data['pinged'] = true; 00080 } 00081 00082 function event_SendPing($data) { 00083 $this->sendPings($data); 00084 } 00085 00086 function sendPings($data) { 00087 if (!class_exists('xmlrpcmsg')) { 00088 global $DIR_LIBS; 00089 include($DIR_LIBS . 'xmlrpc.inc.php'); 00090 } 00091 00092 $this->myBlogId = $data['blogid']; 00093 00094 if ($this->getOption('pingpong_pingomatic')=='yes') { 00095 echo _PINGING . "Ping-o-matic:<br/>"; 00096 echo $this->pingPingomatic(); 00097 echo "<br/>"; 00098 } 00099 00100 if ($this->getOption('pingpong_weblogs')=='yes') { 00101 echo _PINGING . "Weblogs.com:<br/>"; 00102 echo $this->pingWeblogs(); 00103 echo "<br/>"; 00104 } 00105 00106 if ($this->getOption('pingpong_technorati')=='yes') { 00107 echo _PINGING . "Technorati:<br/>"; 00108 echo $this->pingTechnorati(); 00109 echo "<br/>"; 00110 } 00111 00112 if ($this->getOption('pingpong_blogrolling')=='yes') { 00113 echo _PINGING . "Blogrolling.com:<br/>"; 00114 echo $this->pingBlogRollingDotCom(); 00115 echo "<br/>"; 00116 } 00117 00118 if ($this->getOption('pingpong_blogs')=='yes') { 00119 echo _PINGING . "Blog.gs:<br/>"; 00120 echo $this->pingBloGs(); 00121 echo "<br/>"; 00122 } 00123 00124 if ($this->getOption('pingpong_weblogues')=='yes') { 00125 echo _PINGING . "Weblogues.com:<br/>"; 00126 echo $this->pingWebloguesDotCom(); 00127 echo "<br/>"; 00128 } 00129 00130 if ($this->getOption('pingpong_bloggde')=='yes') { 00131 echo _PINGING . "Blog.de:<br/>"; 00132 echo $this->pingBloggDe(); 00133 echo "<br/>"; 00134 } 00135 } 00136 00137 function pingPingomatic() { 00138 $b = new BLOG($this->myBlogId); 00139 $message = new xmlrpcmsg( 00140 'weblogUpdates.ping', array( 00141 new xmlrpcval($b->getName(),'string'), 00142 new xmlrpcval($b->getURL(),'string') 00143 )); 00144 00145 $c = new xmlrpc_client('/', 'rpc.pingomatic.com', 80); 00146 //$c->setDebug(1); 00147 00148 $r = $c->send($message,30); // 30 seconds timeout... 00149 return $this->processPingResult($r); 00150 } 00151 00152 function pingWeblogs() { 00153 $b = new BLOG($this->myBlogId); 00154 $message = new xmlrpcmsg( 00155 'weblogupdates.ping',array( 00156 new xmlrpcval($b->getName(),'string'), 00157 new xmlrpcval($b->getUrl(),'string') 00158 )); 00159 00160 $c = new xmlrpc_client('/rpc2', 'rpc.weblogs.com', 80); 00161 //$c->setdebug(1); 00162 00163 $r = $c->send($message,30); // 30 seconds timeout... 00164 return $this->processPingResult($r); 00165 } 00166 00167 function pingTechnorati() { 00168 $b = new BLOG($this->myBlogId); 00169 $message = new xmlrpcmsg( 00170 'weblogUpdates.ping', array( 00171 new xmlrpcval($b->getName(),'string'), 00172 new xmlrpcval($b->getURL(),'string') 00173 )); 00174 00175 $c = new xmlrpc_client('/rpc/ping/', 'rpc.technorati.com', 80); 00176 //$c->setDebug(1); 00177 00178 $r = $c->send($message,30); // 30 seconds timeout... 00179 return $this->processPingResult($r); 00180 } 00181 00182 function pingBlogRollingDotCom() { 00183 $b = new BLOG($this->myBlogId); 00184 $message = new xmlrpcmsg( 00185 'weblogUpdates.ping', 00186 array( 00187 new xmlrpcval($b->getName(),'string'), // your blog title 00188 new xmlrpcval($b->getURL(),'string') // your blog url 00189 )); 00190 00191 $c = new xmlrpc_client('/pinger/', 'rpc.blogrolling.com', 80); 00192 //$c->setDebug(1); 00193 00194 $r = $c->send($message,30); // 30 seconds timeout... 00195 return $this->processPingResult($r); 00196 } 00197 00198 function pingBloGs() { 00199 $b = new BLOG($this->myBlogId); 00200 $message = new xmlrpcmsg( 00201 'weblogUpdates.extendedPing', array( 00202 new xmlrpcval($b->getName(),'string'), 00203 new xmlrpcval($b->getURL(),'string') 00204 )); 00205 00206 $c = new xmlrpc_client('/', 'ping.blo.gs', 80); 00207 //$c->setDebug(1); 00208 00209 $r = $c->send($message,30); // 30 seconds timeout... 00210 return $this->processPingResult($r); 00211 } 00212 00213 function pingWebloguesDotCom() { 00214 $b = new BLOG($this->myBlogId); 00215 $message = new xmlrpcmsg( 00216 'weblogUpdates.extendedPing', 00217 array( 00218 new xmlrpcval($b->getName(),'string'), // your blog title 00219 new xmlrpcval($b->getURL(),'string') // your blog url 00220 )); 00221 00222 $c = new xmlrpc_client('/RPC/', 'www.weblogues.com', 80); 00223 //$c->setDebug(1); 00224 00225 $r = $c->send($message,30); // 30 seconds timeout... 00226 return $this->processPingResult($r); 00227 } 00228 00229 function pingBloggDe() { 00230 $b = new BLOG($this->myBlogId); 00231 $message = new xmlrpcmsg( 00232 'bloggUpdates.ping', array( 00233 new xmlrpcval($b->getName(),'string'), 00234 new xmlrpcval($b->getURL(),'string') 00235 )); 00236 00237 $c = new xmlrpc_client('/', 'xmlrpc.blogg.de', 80); 00238 //$c->setDebug(1); 00239 00240 $r = $c->send($message,30); // 30 seconds timeout... 00241 return $this->processPingResult($r); 00242 } 00243 00244 function processPingResult($r) { 00245 global $php_errormsg; 00246 00247 if (($r == 0) && ($r->errno || $r->errstring)) { 00248 return _PING_ERROR . " " . $r->errno . ' : ' . $r->errstring; 00249 } elseif (($r == 0) && ($php_errormsg)) { 00250 return _PING_PHP_ERROR . $php_errormsg; 00251 } elseif ($r == 0) { 00252 return _PING_PHP_PING_ERROR; 00253 } elseif ($r->faultCode() != 0) { 00254 return _PING_ERROR . ': ' . $r->faultString(); 00255 } else { 00256 $r = $r->value(); // get response struct 00257 00258 // get values 00259 $flerror = $r->structmem('flerror'); 00260 $flerror = $flerror->scalarval(); 00261 00262 $message = $r->structmem('message'); 00263 $message = $message->scalarval(); 00264 00265 if ($flerror != 0) { 00266 return _PING_ERROR . ' (flerror=1): ' . $message; 00267 } 00268 else { 00269 return _PING_SUCCESS . ': ' . $message; 00270 } 00271 } 00272 } 00273 } 00274 00275 ?>