4 * Send weblog updates ping
5 * plugin for NucleusCMS(version 3.30 or lator)
6 * Note: based on NP_PingPong, adapt for the new ping mechanism
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * (see nucleus/documentation/index.html#license for more info)
15 * @author admun (Edmond Hui)
16 * @license http://www.gnu.org/licenses/gpl.txt GNU GENERAL PUBLIC LICENSE Version 2, June 1991
18 * @link http://edmondhui.homeip.net/nudn
21 * v1.0 - Initial version
22 * v1.1 - Add JustPosted event support
23 * v1.2 - JustPosted event handling in background
24 * v1.3 - pinged variable support
25 * v1.4 - language file support
26 * v1.5 - remove arg1 in exec() call
27 * v1.6 - move send update ping override option to plugin
28 * v1.7 - move send ping option from blog to plugin/blog level
29 * - remove ping override option
30 * v1.8 - remove sendPing event handle, switch to use PostAddItem and PostUpdateItem event for new item ping
31 * v1.81 - fix bug in _sendPingCheck() where ITEM class not found when creating new weblog
34 class NP_Ping extends NucleusPlugin
44 return 'admun (Edmond Hui)';
49 return 'http://edmondhui.homeip.net/nudn';
57 function getMinNucleusVersion()
62 function getDescription()
67 function supportsFeature($what)
70 case 'SqlTablePrefix':
79 // $language = ereg_replace( '[\\|/]', '', getLanguageName());
80 $language = preg_replace( '@\\|/@', '', getLanguageName());
81 if (file_exists($this->getDirectory() . $language . '.php')) {
82 include_once($this->getDirectory() . $language . '.php');
84 include_once($this->getDirectory() . 'english.php');
90 // Default, http://pingomatic.com
91 $this->createOption('pingpong_pingomatic', _PING_PINGOM, 'yesno', 'yes');
93 $this->createOption('pingpong_weblogs', _PING_WEBLOGS, 'yesno', 'no');
94 // http://www.technorati.com
95 $this->createOption('pingpong_technorati', _PING_TECHNOR, 'yesno', 'no');
96 // http://www.blogrolling.com
97 $this->createOption('pingpong_blogrolling', _PING_BLOGR, 'yesno', 'no');
99 $this->createOption('pingpong_blogs', _PING_BLOGS, 'yesno', 'no');
100 // http://weblogues.com/
101 $this->createOption('pingpong_weblogues', _PING_WEBLOGUES, 'yesno', 'no');
103 $this->createOption('pingpong_bloggde', _PING_BLOGGDE, 'yesno', 'no');
105 // Pinging on background
106 $this->createOption('ping_background', _PING_BG, 'yesno', 'no');
108 $this->createBlogOption('ping_sendping', _PING_SENDPING, 'yesno', 'yes');
111 function getEventList()
120 function event_JustPosted($data)
122 global $DIR_PLUGINS, $DIR_NUCLEUS;
124 // exit is another plugin already send ping
125 if ($data['pinged'] == true) {
129 $bid = intval($data['blogid']);
130 if ($this->getBlogOption($bid, 'ping_sendping') == "yes") {
131 if ($this->getOption('ping_background') == "yes") {
132 exec("php $DIR_PLUGINS/ping/ping.php " . $data['blogid'] . " &");
134 $this->sendPings($data['blogid']);
137 // mark the ping has been sent
138 $data['pinged'] = true;
141 function event_PostAddItem($data)
144 // $blogId = getBlogIDFromItemID($data['itemid']);
145 // $item =& ITEM::getitem($data['itemid'], 0, 0); // draft or future post return 0
147 // if ($this->getBlogOption($blogId, 'ping_sendping') == "yes") {
148 // $this->sendPings(array('blogid' => $blogId));
151 $this->_sendPingCheck($data['itemid']);
154 function event_PostUpdateItem($data)
157 // $blogId = getBlogIDFromItemID($data['itemid']);
158 // $blog =& $manager->getBlog($blogId); // <- why?
159 // $item =& ITEM::getitem($data['itemid'], 0, 0); // draft or future post return 0
161 // if ($this->getBlogOption($blogId,'ping_sendping') == "yes" ) {
162 // $this->sendPings(array('blogid' => $blogId));
165 $this->_sendPingCheck($data['itemid']);
168 function _sendPingCheck($itemid)
170 $iid = intval($itemid);
172 $item = $manager->getItem($iid,0,0);
174 $bid = intval(getBlogIDFromItemID($iid));
175 if ($this->getBlogOption($bid, 'ping_sendping') == "yes" ) {
176 $this->sendPings(array('blogid' => $bid));
181 function sendPings($data) {
183 if (!class_exists('xmlrpcmsg')) {
184 include_libs('xmlrpc.inc.php');
186 $this->myBlogId = $data['blogid'];
190 if ($this->getOption('pingpong_pingomatic') == 'yes') {
191 $ping_result .= _PINGING . "Ping-o-matic:\n";
192 $ping_result .= $this->pingPingomatic();
193 $ping_result .= " | ";
196 if ($this->getOption('pingpong_weblogs') == 'yes') {
197 $ping_result .= _PINGING . "Weblogs.com:\n";
198 $ping_result .= $this->pingWeblogs();
199 $ping_result .= " | ";
202 if ($this->getOption('pingpong_technorati') == 'yes') {
203 $ping_result .= _PINGING . "Technorati:\n";
204 $ping_result .= $this->pingTechnorati();
205 $ping_result .= " | ";
208 if ($this->getOption('pingpong_blogrolling') == 'yes') {
209 $ping_result .= _PINGING . "Blogrolling.com:\n";
210 $ping_result .= $this->pingBlogRollingDotCom();
211 $ping_result .= " | ";
214 if ($this->getOption('pingpong_blogs') == 'yes') {
215 $ping_result .= _PINGING . "Blog.gs:\n";
216 $ping_result .= $this->pingBloGs();
217 $ping_result .= " | ";
220 if ($this->getOption('pingpong_weblogues') == 'yes') {
221 $ping_result .= _PINGING . "Weblogues.com:\n";
222 $ping_result .= $this->pingWebloguesDotCom();
223 $ping_result .= " | ";
226 if ($this->getOption('pingpong_bloggde') == 'yes') {
227 $ping_result .= _PINGING . "Blog.de:\n";
228 $ping_result .= $this->pingBloggDe();
229 $ping_result .= " | ";
232 ACTIONLOG::add(INFO, $ping_result);
235 function pingPingomatic() {
236 $b = new BLOG($this->myBlogId);
237 $message = new xmlrpcmsg(
238 'weblogUpdates.ping',
240 new xmlrpcval($b->getName(), 'string'),
241 new xmlrpcval($b->getURL(), 'string')
245 $c = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
248 $r = $c->send($message,30); // 30 seconds timeout...
249 return $this->processPingResult($r);
252 function pingWeblogs() {
253 $b = new BLOG($this->myBlogId);
254 $message = new xmlrpcmsg(
255 'weblogupdates.ping',
257 new xmlrpcval($b->getName(), 'string'),
258 new xmlrpcval($b->getURL(), 'string')
262 $c = new xmlrpc_client('/rpc2', 'rpc.weblogs.com', 80);
265 $r = $c->send($message,30); // 30 seconds timeout...
266 return $this->processPingResult($r);
269 function pingTechnorati() {
270 $b = new BLOG($this->myBlogId);
271 $message = new xmlrpcmsg(
272 'weblogUpdates.ping',
274 new xmlrpcval($b->getName(),'string'),
275 new xmlrpcval($b->getURL(),'string')
279 $c = new xmlrpc_client('/rpc/ping/', 'rpc.technorati.com', 80);
282 $r = $c->send($message,30); // 30 seconds timeout...
283 return $this->processPingResult($r);
286 function pingBlogRollingDotCom() {
287 $b = new BLOG($this->myBlogId);
288 $message = new xmlrpcmsg(
289 'weblogUpdates.ping',
291 new xmlrpcval($b->getName(),'string'),
292 new xmlrpcval($b->getURL(),'string')
296 $c = new xmlrpc_client('/pinger/', 'rpc.blogrolling.com', 80);
299 $r = $c->send($message,30); // 30 seconds timeout...
300 return $this->processPingResult($r);
303 function pingBloGs() {
304 $b = new BLOG($this->myBlogId);
305 $message = new xmlrpcmsg(
306 'weblogUpdates.extendedPing',
308 new xmlrpcval($b->getName(),'string'),
309 new xmlrpcval($b->getURL(),'string')
313 $c = new xmlrpc_client('/', 'ping.blo.gs', 80);
316 $r = $c->send($message,30); // 30 seconds timeout...
317 return $this->processPingResult($r);
320 function pingWebloguesDotCom() {
321 $b = new BLOG($this->myBlogId);
322 $message = new xmlrpcmsg(
323 'weblogUpdates.extendedPing',
325 new xmlrpcval($b->getName(),'string'),
326 new xmlrpcval($b->getURL(),'string')
330 $c = new xmlrpc_client('/RPC/', 'www.weblogues.com', 80);
333 $r = $c->send($message,30); // 30 seconds timeout...
334 return $this->processPingResult($r);
337 function pingBloggDe() {
338 $b = new BLOG($this->myBlogId);
339 $message = new xmlrpcmsg(
342 new xmlrpcval($b->getName(),'string'),
343 new xmlrpcval($b->getURL(),'string')
347 $c = new xmlrpc_client('/', 'xmlrpc.blogg.de', 80);
350 $r = $c->send($message,30); // 30 seconds timeout...
351 return $this->processPingResult($r);
354 function processPingResult($r) {
355 global $php_errormsg;
357 if (($r == 0) && ($r->errno || $r->errstring)) {
358 return _PING_ERROR . " " . $r->errno . ' : ' . $r->errstring;
359 } elseif (($r == 0) && ($php_errormsg)) {
360 return _PING_PHP_ERROR . $php_errormsg;
362 return _PING_PHP_PING_ERROR;
363 } elseif ($r->faultCode() != 0) {
364 return _PING_ERROR . ': ' . $r->faultString();
366 $r = $r->value(); // get response struct
369 $flerror = $r->structmem('flerror');
370 $flerror = $flerror->scalarval();
372 $message = $r->structmem('message');
373 $message = $message->scalarval();
376 return _PING_ERROR . ' (flerror=1): ' . $message;
378 return _PING_SUCCESS . ': ' . $message;