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
36 public function getName()
41 public function getAuthor()
43 return 'admun (Edmond Hui)';
46 public function getURL()
48 return 'http://edmondhui.homeip.net/nudn';
51 public function getVersion()
56 public function getMinNucleusVersion()
61 public function getDescription()
66 public function supportsFeature($what)
68 return ( $what == 'SqlTablePrefix' );
71 public function getEventList()
73 return array('JustPosted', 'PostAddItem', 'PostUpdateItem');
76 public function init()
78 // include translation file for this plugin
79 if ( file_exists($this->getDirectory() . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php') )
81 include_once($this->getDirectory() . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php');
85 include_once($this->getDirectory().'en_Latn_US.UTF-8.php');
90 public function install()
92 // Default, http://pingomatic.com
93 $this->createOption('pingpong_pingomatic', '_PING_PINGOM', 'yesno', 'yes');
95 $this->createOption('pingpong_weblogs', '_PING_WEBLOGS', 'yesno', 'no');
96 // http://www.technorati.com
97 $this->createOption('pingpong_technorati', '_PING_TECHNOR', 'yesno', 'no');
98 // http://www.blogrolling.com
99 $this->createOption('pingpong_blogrolling', '_PING_BLOGR', 'yesno', 'no');
101 $this->createOption('pingpong_blogs', '_PING_BLOGS', 'yesno', 'no');
102 // http://weblogues.com/
103 $this->createOption('pingpong_weblogues', '_PING_WEBLOGUES', 'yesno', 'no');
105 $this->createOption('pingpong_bloggde', '_PING_BLOGGDE', 'yesno', 'no');
106 // Pinging on background
107 $this->createOption('ping_background', '_PING_BG', 'yesno', 'no');
109 // plugin weblog option
110 $this->createBlogOption('ping_sendping', '_PING_SENDPING', 'yesno', 'yes');
114 public function event_JustPosted($data)
116 global $DIR_PLUGINS, $DIR_NUCLEUS;
118 // exit is another plugin already send ping
119 if ( $data['pinged'] == true )
124 $bid = intval($data['blogid']);
125 if ( $this->getBlogOption($bid, 'ping_sendping') == "yes" )
127 if ( $this->getOption('ping_background') == "yes" )
129 exec("php $DIR_PLUGINS/ping/ping.php " . $data['blogid'] . " &");
133 $this->sendPings($data['blogid']);
136 // mark the ping has been sent
137 $data['pinged'] = true;
141 public function event_PostAddItem($data)
143 $this->_sendPingCheck($data['itemid']);
147 public function event_PostUpdateItem($data)
149 $this->_sendPingCheck($data['itemid']);
153 public function _sendPingCheck($itemid)
155 $iid = intval($itemid);
157 $item = $manager->getItem($iid,0,0);
160 $bid = intval(getBlogIDFromItemID($iid));
161 if ( $this->getBlogOption($bid, 'ping_sendping') == "yes" )
163 $this->sendPings(array('blogid' => $bid));
169 public function sendPings($data)
171 if ( !class_exists('xmlrpcmsg') )
173 include_libs('xmlrpc.inc.php');
175 $this->myBlogId = $data['blogid'];
179 if ( $this->getOption('pingpong_pingomatic') == 'yes' )
181 $ping_result .= _PINGING . "Ping-o-matic:\n";
182 $ping_result .= $this->pingPingomatic();
183 $ping_result .= " | ";
186 if ( $this->getOption('pingpong_weblogs') == 'yes' )
188 $ping_result .= _PINGING . "Weblogs.com:\n";
189 $ping_result .= $this->pingWeblogs();
190 $ping_result .= " | ";
193 if ( $this->getOption('pingpong_technorati') == 'yes' )
195 $ping_result .= _PINGING . "Technorati:\n";
196 $ping_result .= $this->pingTechnorati();
197 $ping_result .= " | ";
200 if ( $this->getOption('pingpong_blogrolling') == 'yes' )
202 $ping_result .= _PINGING . "Blogrolling.com:\n";
203 $ping_result .= $this->pingBlogRollingDotCom();
204 $ping_result .= " | ";
207 if ( $this->getOption('pingpong_blogs') == 'yes' )
209 $ping_result .= _PINGING . "Blog.gs:\n";
210 $ping_result .= $this->pingBloGs();
211 $ping_result .= " | ";
214 if ( $this->getOption('pingpong_weblogues') == 'yes' )
216 $ping_result .= _PINGING . "Weblogues.com:\n";
217 $ping_result .= $this->pingWebloguesDotCom();
218 $ping_result .= " | ";
221 if ( $this->getOption('pingpong_bloggde') == 'yes' )
223 $ping_result .= _PINGING . "Blog.de:\n";
224 $ping_result .= $this->pingBloggDe();
225 $ping_result .= " | ";
228 ActionLog::add(INFO, $ping_result);
232 public function pingPingomatic()
234 $b = new Blog($this->myBlogId);
235 $message = new xmlrpcmsg(
236 'weblogUpdates.ping',
238 new xmlrpcval($b->getName(), 'string'),
239 new xmlrpcval($b->getURL(), 'string')
243 $c = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
244 /* 30 seconds timeout... */
245 $r = $c->send($message,30);
246 return $this->processPingResult($r);
249 public function pingWeblogs()
251 $b = new Blog($this->myBlogId);
252 $message = new xmlrpcmsg(
253 'weblogupdates.ping',
255 new xmlrpcval($b->getName(), 'string'),
256 new xmlrpcval($b->getURL(), 'string')
260 $c = new xmlrpc_client('/rpc2', 'rpc.weblogs.com', 80);
261 /* 30 seconds timeout... */
262 $r = $c->send($message,30);
263 return $this->processPingResult($r);
266 public function pingTechnorati()
268 $b = new Blog($this->myBlogId);
269 $message = new xmlrpcmsg(
270 'weblogUpdates.ping',
272 new xmlrpcval($b->getName(),'string'),
273 new xmlrpcval($b->getURL(),'string')
277 $c = new xmlrpc_client('/rpc/ping/', 'rpc.technorati.com', 80);
278 /* 30 seconds timeout... */
279 $r = $c->send($message,30);
280 return $this->processPingResult($r);
283 public function pingBlogRollingDotCom()
285 $b = new Blog($this->myBlogId);
286 $message = new xmlrpcmsg(
287 'weblogUpdates.ping',
289 new xmlrpcval($b->getName(),'string'),
290 new xmlrpcval($b->getURL(),'string')
294 $c = new xmlrpc_client('/pinger/', 'rpc.blogrolling.com', 80);
295 /* 30 seconds timeout... */
296 $r = $c->send($message,30);
297 return $this->processPingResult($r);
300 public function pingBloGs()
302 $b = new Blog($this->myBlogId);
303 $message = new xmlrpcmsg(
304 'weblogUpdates.extendedPing',
306 new xmlrpcval($b->getName(),'string'),
307 new xmlrpcval($b->getURL(),'string')
311 $c = new xmlrpc_client('/', 'ping.blo.gs', 80);
312 /* 30 seconds timeout... */
313 $r = $c->send($message,30);
314 return $this->processPingResult($r);
317 public function pingWebloguesDotCom()
319 $b = new Blog($this->myBlogId);
320 $message = new xmlrpcmsg(
321 'weblogUpdates.extendedPing',
323 new xmlrpcval($b->getName(),'string'),
324 new xmlrpcval($b->getURL(),'string')
328 $c = new xmlrpc_client('/RPC/', 'www.weblogues.com', 80);
329 /* 30 seconds timeout... */
330 $r = $c->send($message,30);
331 return $this->processPingResult($r);
334 public function pingBloggDe()
336 $b = new Blog($this->myBlogId);
337 $message = new xmlrpcmsg(
340 new xmlrpcval($b->getName(),'string'),
341 new xmlrpcval($b->getURL(),'string')
345 $c = new xmlrpc_client('/', 'xmlrpc.blogg.de', 80);
346 /* 30 seconds timeout... */
347 $r = $c->send($message,30);
348 return $this->processPingResult($r);
351 public function processPingResult($r)
353 global $php_errormsg;
355 if ( ($r == 0) && ($r->errno || $r->errstring) )
357 return _PING_ERROR . " " . $r->errno . ' : ' . $r->errstring;
359 elseif ( ($r == 0) && ($php_errormsg) )
361 return _PING_PHP_ERROR . $php_errormsg;
365 return _PING_PHP_PING_ERROR;
367 elseif ( $r->faultCode() != 0 )
369 return _PING_ERROR . ': ' . $r->faultString();
373 // get response struct
377 $flerror = $r->structmem('flerror');
378 $flerror = $flerror->scalarval();
380 $message = $r->structmem('message');
381 $message = $message->scalarval();
385 return _PING_ERROR . ' (flerror=1): ' . $message;
389 return _PING_SUCCESS . ': ' . $message;