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 {
35 public function getName() { return 'Ping'; }
36 public function getAuthor() { return 'admun (Edmond Hui)'; }
37 public function getURL() { return 'http://edmondhui.homeip.net/nudn'; }
38 public function getVersion() { return '1.81JP'; }
39 public function getMinNucleusVersion() { return '330'; }
40 public function getDescription() { return _PING_DESC; }
41 public function supportsFeature($feature) { return in_array ($feature, array ('SqlTablePrefix', 'SqlApi'));}
42 public function getEventList() { return array('JustPosted', 'PostAddItem', 'PostUpdateItem', 'PrePluginOptionsEdit'); }
44 public function init() {
45 $language = preg_replace( '#\\\\|/#', '', getLanguageName());
46 if (file_exists($this->getDirectory() . $language . '.php')) {
47 include_once($this->getDirectory() . $language . '.php');
49 include_once($this->getDirectory() . 'english.php');
54 public function install() {
55 // Default, http://pingomatic.com
56 $this->createOption('pingpong_pingomatic', '_PING_PINGOM', 'yesno', 'yes');
58 $this->createOption('pingpong_weblogs', '_PING_WEBLOGS', 'yesno', 'no');
59 // http://www.technorati.com
60 $this->createOption('pingpong_technorati', '_PING_TECHNOR', 'yesno', 'no');
61 // http://www.blogrolling.com
62 $this->createOption('pingpong_blogrolling', '_PING_BLOGR', 'yesno', 'no');
64 $this->createOption('pingpong_blogs', '_PING_BLOGS', 'yesno', 'no');
65 // http://weblogues.com/
66 $this->createOption('pingpong_weblogues', '_PING_WEBLOGUES', 'yesno', 'no');
68 $this->createOption('pingpong_bloggde', '_PING_BLOGGDE', 'yesno', 'no');
70 // Pinging on background
71 $this->createOption('ping_background', '_PING_BG', 'yesno', 'no');
73 $this->createBlogOption('ping_sendping', '_PING_SENDPING', 'yesno', 'yes');
77 public function unInstall() {
81 public function event_JustPosted($data) {
82 global $DIR_PLUGINS, $DIR_NUCLEUS;
84 if ($data['pinged'] == true) {
88 $bid = intval($data['blogid']);
89 if ($this->getBlogOption($bid, 'ping_sendping') == "yes") {
90 if ($this->getOption('ping_background') == "yes") {
91 exec("php $DIR_PLUGINS/ping/ping.php " . $data['blogid'] . " &");
93 $this->sendPings($data['blogid']);
96 // mark the ping has been sent
97 $data['pinged'] = true;
101 public function event_PostAddItem($data) {
103 // $blogId = getBlogIDFromItemID($data['itemid']);
104 // $item =& ITEM::getitem($data['itemid'], 0, 0); // draft or future post return 0
106 // if ($this->getBlogOption($blogId, 'ping_sendping') == "yes") {
107 // $this->sendPings(array('blogid' => $blogId));
110 $this->_sendPingCheck($data['itemid']);
114 public function event_PostUpdateItem($data) {
116 // $blogId = getBlogIDFromItemID($data['itemid']);
117 // $blog =& $manager->getBlog($blogId); // <- why?
118 // $item =& ITEM::getitem($data['itemid'], 0, 0); // draft or future post return 0
120 // if ($this->getBlogOption($blogId,'ping_sendping') == "yes" ) {
121 // $this->sendPings(array('blogid' => $blogId));
124 $this->_sendPingCheck($data['itemid']);
128 public function event_PrePluginOptionsEdit($data) {
129 if ($data['plugid'] === $this->getID()) {
130 foreach($data['options'] as $key => $value){
131 if (defined($value['description'])) {
132 $data['options'][$key]['description'] = constant($value['description']);
134 if (!strcmp($value['type'], 'select') && defined($value['typeinfo'])) {
135 $data['options'][$key]['typeinfo'] = constant($value['typeinfo']);
142 private function _sendPingCheck($itemid) {
143 $iid = intval($itemid);
145 $item = $manager->getItem($iid,0,0);
147 $bid = intval(getBlogIDFromItemID($iid));
148 if ($this->getBlogOption($bid, 'ping_sendping') == "yes" ) {
149 $this->sendPings(array('blogid' => $bid));
155 public function sendPings($data) {
156 if (!class_exists('xmlrpcmsg')) {
157 include_libs('xmlrpc.inc.php');
160 $this->myBlogId = $data['blogid'];
164 if ($this->getOption('pingpong_pingomatic') == 'yes') {
165 $ping_result .= _PINGING . "Ping-o-matic:\n";
166 $ping_result .= $this->pingPingomatic();
167 $ping_result .= " | ";
170 if ($this->getOption('pingpong_weblogs') == 'yes') {
171 $ping_result .= _PINGING . "Weblogs.com:\n";
172 $ping_result .= $this->pingWeblogs();
173 $ping_result .= " | ";
176 if ($this->getOption('pingpong_technorati') == 'yes') {
177 $ping_result .= _PINGING . "Technorati:\n";
178 $ping_result .= $this->pingTechnorati();
179 $ping_result .= " | ";
182 if ($this->getOption('pingpong_blogrolling') == 'yes') {
183 $ping_result .= _PINGING . "Blogrolling.com:\n";
184 $ping_result .= $this->pingBlogRollingDotCom();
185 $ping_result .= " | ";
188 if ($this->getOption('pingpong_blogs') == 'yes') {
189 $ping_result .= _PINGING . "Blog.gs:\n";
190 $ping_result .= $this->pingBloGs();
191 $ping_result .= " | ";
194 if ($this->getOption('pingpong_weblogues') == 'yes') {
195 $ping_result .= _PINGING . "Weblogues.com:\n";
196 $ping_result .= $this->pingWebloguesDotCom();
197 $ping_result .= " | ";
200 if ($this->getOption('pingpong_bloggde') == 'yes') {
201 $ping_result .= _PINGING . "Blog.de:\n";
202 $ping_result .= $this->pingBloggDe();
203 $ping_result .= " | ";
206 ACTIONLOG::add(INFO, $ping_result);
210 public function pingPingomatic() {
211 $b = new BLOG($this->myBlogId);
212 $message = new xmlrpcmsg(
213 'weblogUpdates.ping',
215 new xmlrpcval($b->getName(), 'string'),
216 new xmlrpcval($b->getURL(), 'string')
220 $c = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
223 // 30 seconds timeout...
224 $r = $c->send($message,30);
225 return $this->processPingResult($r);
228 public function pingWeblogs() {
229 $b = new BLOG($this->myBlogId);
230 $message = new xmlrpcmsg(
231 'weblogupdates.ping',
233 new xmlrpcval($b->getName(), 'string'),
234 new xmlrpcval($b->getURL(), 'string')
238 $c = new xmlrpc_client('/rpc2', 'rpc.weblogs.com', 80);
241 // 30 seconds timeout...
242 $r = $c->send($message,30);
243 return $this->processPingResult($r);
246 public function pingTechnorati() {
247 $b = new BLOG($this->myBlogId);
248 $message = new xmlrpcmsg(
249 'weblogUpdates.ping',
251 new xmlrpcval($b->getName(),'string'),
252 new xmlrpcval($b->getURL(),'string')
256 $c = new xmlrpc_client('/rpc/ping/', 'rpc.technorati.com', 80);
259 // 30 seconds timeout...
260 $r = $c->send($message,30);
261 return $this->processPingResult($r);
264 public function pingBlogRollingDotCom() {
265 $b = new BLOG($this->myBlogId);
266 $message = new xmlrpcmsg(
267 'weblogUpdates.ping',
269 new xmlrpcval($b->getName(),'string'),
270 new xmlrpcval($b->getURL(),'string')
274 $c = new xmlrpc_client('/pinger/', 'rpc.blogrolling.com', 80);
277 // 30 seconds timeout...
278 $r = $c->send($message,30);
279 return $this->processPingResult($r);
282 public function pingBloGs() {
283 $b = new BLOG($this->myBlogId);
284 $message = new xmlrpcmsg(
285 'weblogUpdates.extendedPing',
287 new xmlrpcval($b->getName(),'string'),
288 new xmlrpcval($b->getURL(),'string')
292 $c = new xmlrpc_client('/', 'ping.blo.gs', 80);
295 // 30 seconds timeout...
296 $r = $c->send($message,30);
297 return $this->processPingResult($r);
300 public function pingWebloguesDotCom() {
301 $b = new BLOG($this->myBlogId);
302 $message = new xmlrpcmsg(
303 'weblogUpdates.extendedPing',
305 new xmlrpcval($b->getName(),'string'),
306 new xmlrpcval($b->getURL(),'string')
310 $c = new xmlrpc_client('/RPC/', 'www.weblogues.com', 80);
313 // 30 seconds timeout...
314 $r = $c->send($message,30);
315 return $this->processPingResult($r);
318 public function pingBloggDe() {
319 $b = new BLOG($this->myBlogId);
320 $message = new xmlrpcmsg(
323 new xmlrpcval($b->getName(),'string'),
324 new xmlrpcval($b->getURL(),'string')
328 $c = new xmlrpc_client('/', 'xmlrpc.blogg.de', 80);
331 // 30 seconds timeout...
332 $r = $c->send($message,30);
333 return $this->processPingResult($r);
336 public function processPingResult($r) {
337 global $php_errormsg;
339 if (($r == 0) && ($r->errno || $r->errstring)) {
340 return _PING_ERROR . " " . $r->errno . ' : ' . $r->errstring;
341 } elseif (($r == 0) && ($php_errormsg)) {
342 return _PING_PHP_ERROR . $php_errormsg;
344 return _PING_PHP_PING_ERROR;
345 } elseif ($r->faultCode() != 0) {
346 return _PING_ERROR . ': ' . $r->faultString();
348 // get response struct
352 $flerror = $r->structmem('flerror');
353 $flerror = $flerror->scalarval();
355 $message = $r->structmem('message');
356 $message = $message->scalarval();
359 return _PING_ERROR . ' (flerror=1): ' . $message;
361 return _PING_SUCCESS . ': ' . $message;