4 * Send weblog updates ping
5 * plugin for NucleusCMS(version 3.31 or lator)
6 * Note: based on NP_Ping v1.5
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)
16 * @copyright 2007 shizuki
17 * @license http://www.gnu.org/licenses/gpl.txt GNU GENERAL PUBLIC LICENSE Version 2, June 1991
19 * @link http://shizuki.kinezumi.net/
22 * v1.0 - Initial version
23 * v1.1 - Add JustPosted event support
24 * v1.2 - JustPosted event handling in background
25 * v1.3 - pinged variable support
26 * v1.4 - language file support
27 * v1.5 - remove arg1 in exec() call
29 * History of NP_PingJP
30 * v1.6 - Modified NP_Ping v1.5
31 * merge NP_SendPing(by Tokitake) code
36 class NP_PingJP extends NucleusPlugin
41 // {{{ function getName()
49 * The name easy to understand for man of the plugin
57 // {{{ function getAuthor()
60 * Author of the plugin
65 * The name of the plugin author
69 return 'admun (Edmond Hui)+ Tokitake + shizuki';
73 // {{{ function getURL()
76 * URL of the site which can download a plugin
81 * URL of the site which can download a plugin
85 return 'http://shizuki.kinezumi.net/';
89 // {{{ function getVersion()
92 * Version of the plugin
97 * Version of the plugin
105 // {{{ function getMinNucleusVersion()
108 * Requier NucleusCMS version of the plugin
113 * Requier NucleusCMS version of a plugin
115 function getMinNucleusVersion()
121 // {{{ function getDescription()
124 * Description of the plugin
129 * Description of a plugin
131 function getDescription()
137 // {{{ function supportsFeature($what)
140 * Check whether the feature is being supported.
149 function supportsFeature($what)
152 case 'SqlTablePrefix':
160 // {{{ function install()
163 * Plugin installing action
171 // Default, http://pingomatic.com
172 $this->createBlogOption('pingjp_pingomatic', _PINGJP_PINGOM, 'yesno', 'yes');
173 // http://weblogs.com
174 $this->createBlogOption('pingjp_weblogs', _PINGJP_WEBLOGS, 'yesno', 'no');
175 // http://www.technorati.com
176 $this->createBlogOption('pingjp_technorati', _PINGJP_TECHNOR, 'yesno', 'no');
177 // http://www.blogrolling.com
178 $this->createBlogOption('pingjp_blogrolling', _PINGJP_BLOGR, 'yesno', 'no');
179 // http://www.google.com
180 $this->createBlogOption('pingjp_google', _PINGJP_GOOGLE, 'yesno', 'yes');
181 // http://www.yahoo.co.jp
182 $this->createBlogOption('pingjp_yahoo', _PINGJP_YAHOO, 'yesno', 'yes');
183 // http://www.goo.ne.jp
184 $this->createBlogOption('pingjp_goo', _PINGJP_GOO, 'yesno', 'no');
186 $this->createBlogOption('pingjp_ask', _PINGJP_ASK, 'yesno', 'no');
188 $this->createBlogOption('pingjp_blog360', _PINGJP_BLOG360, 'yesno', 'yes');
190 $this->createBlogOption('pingjp_pingoo', _PINGJP_PINGOO, 'yesno', 'no');
192 $this->createBlogOption('pingjp_blogs', _PINGJP_BLOGS, 'yesno', 'no');
193 // http://weblogues.com/
194 $this->createBlogOption('pingjp_weblogues', _PINGJP_WEBLOGUES, 'yesno', 'no');
196 $this->createBlogOption('pingjp_bloggde', _PINGJP_BLOGGDE, 'yesno', 'no');
198 $this->createBlogOption('pingjp_otherurl', _PINGJP_OTHER, 'textarea', '');
200 $this->createBlogOption('pingjp_background', _PINGJP_BG, 'yesno', 'yes');
202 $this->createBlogOption('pingjp_updateurl', _PINGJP_UPDURL, 'text', '');
204 $this->createBlogOption('pingjp_feedsurl', _PINGJP_UPDFEED, 'text', '');
208 // {{{ function init()
211 * Plugin initialize action
219 $language = ereg_replace( '[\\|/]', '', getLanguageName());
220 if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
221 include_once($this->getDirectory() . 'language/' . $language . '.php');
223 include_once($this->getDirectory() . 'language/english.php');
228 // {{{ function getEventList()
231 * Event list plugin exist
238 function getEventList()
243 'EditItemFormExtras',
249 // {{{ function event_PostUpdateItem($data)
257 * itemid : value intger
262 function event_PostUpdateItem($data) {
264 if (requestVar('np_pingjp_check') == 1) {
265 $iid = intval($data['itemid']);
266 $item =& $manager->getItem($iid, 0, 0);
267 // don't ping on draft or future items
268 if (!$item || $item['draft']) return;
269 $this->sendPing(getBlogIDFromItemID($iid));
274 // {{{ function event_EditItemFormExtras($data)
277 * Event display ITEM edit form
278 * adding plugin specify for ITEM edit form
283 * blog : reference object
285 * variables : value array
286 * containing all sorts of information on the item that's being edited
289 * draft : intger(boolean)
293 * closed : intger(boolean)
294 * ITEM comments status
315 * itemid : value intger
320 function event_EditItemFormExtras($data)
323 <div style="display:block">
326 <label for="np_pingjp_check">Send Ping ?:</label>
327 <input type="checkbox" value="1" id="np_pingjp_check" name="np_pingjp_check" />
334 // {{{ function event_JustPosted($data)
337 * Event ITEM timstamp as now
338 * send update ping or etc.
343 * blogid : value intger
345 * pinged : reference boolean
346 * Update ping completed as true
350 function event_JustPosted($data)
352 if ($data['pinged'] == true) {
355 if ($this->getBlogOption($data['blogid'], 'pingjp_background') == "yes") {
356 $this->sendPings($data['blogid'], true);
358 $this->sendPings($data['blogid']);
360 $data['pinged'] = true;
364 // {{{ function event_SendPing($data)
367 * Event send weblog updates ping
373 * blogid : value intger
378 function event_SendPing($data)
380 $this->sendPing($data['blogid']);
384 // {{{ function sendPing($myBlogId, $background = false)
387 * Setting ping servers
394 * Send ping background or foreground
398 function sendPing($myBlogId, $background = false)
401 if ($this->getBlogOption($myBlogId, 'pingjp_pingomatic') == 'yes') {
402 $pinging[]['target'] = _PINGJP_PINGOM;
403 $pinging[]['host'] = 'rpc.pingomatic.com';
404 $pinging[]['path'] = '/';
405 $pinging[]['port'] = 80;
406 $pinging[]['method'] = 'weblogUpdates.ping';
409 if ($this->getBlogOption($myBlogId, 'pingjp_weblogs') == 'yes') {
410 $pinging[]['target'] = _PINGJP_WEBLOGS;
411 $pinging[]['host'] = 'rpc.weblogs.com';
412 $pinging[]['path'] = '/rpc2';
413 $pinging[]['port'] = 80;
414 $pinging[]['method'] = 'weblogUpdates.extendedPing';
417 if ($this->getBlogOption($myBlogId, 'pingjp_technorati') == 'yes') {
418 $pinging[]['target'] = _PINGJP_TECHNOR;
419 $pinging[]['host'] = 'rpc.technorati.com';
420 $pinging[]['path'] = '/rpc/ping';
421 $pinging[]['port'] = 80;
422 $pinging[]['method'] = 'weblogUpdates.ping';
425 if ($this->getBlogOption($myBlogId, 'pingjp_blogrolling') == 'yes') {
426 $pinging[]['target'] = _PINGJP_BLOGR;
427 $pinging[]['host'] = 'rpc.blogrolling.com';
428 $pinging[]['path'] = '/pinger/';
429 $pinging[]['port'] = 80;
430 $pinging[]['method'] = 'weblogUpdates.ping';
433 if ($this->getBlogOption($myBlogId, 'pingjp_google') == 'yes') {
434 $pinging[]['target'] = _PINGJP_GOOGLE;
435 $pinging[]['host'] = 'blogsearch.google.co.jp';
436 $pinging[]['path'] = '/ping/RPC2';
437 $pinging[]['port'] = 80;
438 $pinging[]['method'] = 'weblogUpdates.extendedPing';
441 if ($this->getBlogOption($myBlogId, 'pingjp_yahoo') == 'yes') {
442 $pinging[]['target'] = _PINGJP_YAHOO;
443 $pinging[]['host'] = 'api.my.yahoo.co.jp';
444 $pinging[]['path'] = '/RPC2';
445 $pinging[]['port'] = 80;
446 $pinging[]['method'] = 'weblogUpdates.ping';
449 if ($this->getBlogOption($myBlogId, 'pingjp_goo') == 'yes') {
450 $pinging[]['target'] = _PINGJP_GOO;
451 $pinging[]['host'] = 'blog.goo.ne.jp';
452 $pinging[]['path'] = '/XMLRPC';
453 $pinging[]['port'] = 80;
454 $pinging[]['method'] = 'weblogUpdates.ping';
457 if ($this->getBlogOption($myBlogId, 'pingjp_ask') == 'yes') {
458 $pinging[]['target'] = _PINGJP_ASK;
459 $pinging[]['host'] = 'ping.ask.jp';
460 $pinging[]['path'] = '/xmlrpc.m';
461 $pinging[]['port'] = 80;
462 $pinging[]['method'] = 'weblogUpdates.ping';
465 if ($this->getBlogOption($myBlogId, 'pingjp_blog360') == 'yes') {
466 $pinging[]['target'] = _PINGJP_BLOG360;
467 $pinging[]['host'] = 'ping.blog360.jp';
468 $pinging[]['path'] = '/rpc';
469 $pinging[]['port'] = 80;
470 $pinging[]['method'] = 'weblogUpdates.ping';
473 if ($this->getBlogOption($myBlogId, 'pingjp_pingoo') == 'yes') {
474 $pinging[]['target'] = _PINGJP_PINGOO;
475 $pinging[]['host'] = 'pingoo.jp';
476 $pinging[]['path'] = '/ping';
477 $pinging[]['port'] = 80;
478 $pinging[]['method'] = 'weblogUpdates.ping';
481 if ($this->getBlogOption($myBlogId, 'pingjp_blogs') == 'yes') {
482 $pinging[]['target'] = _PINGJP_BLOGS;
483 $pinging[]['host'] = 'ping.blo.gs';
484 $pinging[]['path'] = '/';
485 $pinging[]['port'] = 80;
486 $pinging[]['method'] = 'weblogUpdates.extendedPing';
489 if ($this->getBlogOption($myBlogId, 'pingjp_weblogues') == 'yes') {
490 $pinging[]['target'] = _PINGJP_WEBLOGUES;
491 $pinging[]['host'] = 'www.weblogues.com';
492 $pinging[]['path'] = '/RPC/';
493 $pinging[]['port'] = 80;
494 $pinging[]['method'] = 'weblogUpdates.extendedPing';
497 if ($this->getBlogOption($myBlogId, 'pingjp_bloggde') == 'yes') {
498 $pinging[]['target'] = _PINGJP_BLOGGDE;
499 $pinging[]['host'] = 'xmlrpc.blogg.de';
500 $pinging[]['path'] = '/ping';
501 $pinging[]['port'] = 80;
502 $pinging[]['method'] = 'bloggUpdates.ping';
505 if ($this->getBlogOption($myBlogId, 'pingjp_otherurl') != '') {
506 $others = $this->getBlogOption($myBlogId, 'pingjp_otherurl')
507 $servers = preg_split("/[\s,]+/", $others);
508 foreach ($servers as $target) {
509 if (strpos($target), ',') {
510 list($url, $method) = explode(',', $target);
511 $parsed = parse_url($url);
512 if ($method == 'ex') {
513 $method = 'weblogUpdates.extendedPing';
516 $parsed = parse_url($target);
517 $method = 'weblogUpdates.ping';
519 $pinging[]['target'] = $parsed['host'];
520 $pinging[]['host'] = $parsed['host'];
521 $pinging[]['path'] = $parsed['path'];
522 $pinging[]['port'] = (!$parsed['port']) ? 80 : $parsed['port'];
523 $pinging[]['method'] = $method;
526 foreach ($pinging as $sendPing) {
527 $this->sendUpdatePing($myBlogId, $sendPing, $background);
532 // {{{ function sendUpdatePing($myBlogId, $sendPing, $background = false)
535 * Setting ping servers
542 * ping server settigs
543 * target : name of ping server
544 * host : host of ping server
545 * path : path of ping server
546 * port : port of ping server
547 * method : method of ping server accept
549 * Send ping background or foreground
553 function sendUpdatePing($myBlogId, $sendPing, $background = false)
555 global $manager, $DIR_LIBS;
556 if (!class_exists('xmlrpcmsg')) {
558 include($DIR_LIBS . 'xmlrpc.inc.php');
561 echo _PINGJP_PINGING . $parsed['target'] . ':<br />';
563 $logMsg = 'NP_PingJP: Sending ping (from background):' . $parsed['target'];
564 ACTIONLOG::add(INFO, $logMsg);
566 $b =& $manager->getBlog($myBlogId);
567 $name = $b->getName();
568 $burl = $this->getBlogOption($myBlogId, 'pingjp_updateurl');
570 $burl = $b->getURL();
572 if (_CHARSET != 'ISO-8859-1' &&
573 _CHARSET != 'US-ASCII' &&
574 _CHARSET != 'UTF-8' &&
575 function_exists('mb_convert_encoding')
577 mb_convert_encoding($name, 'UTF-8', _CHARSET);
580 new xmlrpcval($name),
583 if ($sendPing['method'] == 'weblogUpdates.extendedPing') {
584 $feedURL = $this->getBlogOption($myBlogid, 'pingjp_feedsurl');
586 if (substr($burl, -1) != '/') {
591 $feedURL = $base . 'xml-rss2.php?blogid=' . $myBlogId;
593 $data[3] = new xmlrpcval($burl);
594 $data[4] = new xmlrpcval($feedURL);
596 $message = new xmlrpcmsg($sendPing['method'], $data);
597 $connect = new xmlrpc_client($sendPing['path'], $sendPing['host'], $sendPing['port']);
598 $response = $connect->send($message, 30); // 30 seconds timeout...
599 $results = $this->processPingResult($response);
600 if ($results['error']) {
601 $logMsg = 'NP_PingJP Errror: ' . $results['message'];
602 ACTIONLOG::add(WARNING, $logMsg);
603 } elseif ($this->debug) {
604 $logMsg = 'NP_PingJP: ' . $results['message'];
605 ACTIONLOG::add(INFO, $logMsg);
608 echo $results['message'] . '<br />';
613 // {{{ function processPingResult($response)
621 * weblog updates ping response
625 * ping response status
627 * ping response messages
629 function processPingResult($response)
631 global $php_errormsg;
632 if (($response == 0) && ($response->errno || $response->errstring)) {
633 $ret['error'] = true;
634 $ret['message'] = _PINGJP_ERROR
635 . ' ' . $response->errno
636 . ' : ' . $response->errstring;
637 } elseif (($response == 0) && ($php_errormsg)) {
638 $ret['error'] = true;
639 $ret['message'] = _PINGJP_PHP_ERROR . $php_errormsg;
640 } elseif ($response == 0) {
641 $ret['error'] = true;
642 $ret['message'] = _PINGJP_PHP_PING_ERROR;
643 } elseif ($response->faultCode() != 0) {
644 $ret['error'] = true;
645 $ret['message'] = _PINGJP_ERROR . ': ' . $response->faultString();
647 $response = $response->value(); // get response struct
649 $flerror = $response->structmem('flerror');
650 $flerror = $flerror->scalarval();
651 $message = $response->structmem('message');
652 $message = $message->scalarval();
654 $ret['error'] = true;
655 $ret['message'] = _PINGJP_ERROR . ' (flerror=1): ' . $message;
657 $ret['error'] = false;
658 $ret['message'] = _PINGJP_SUCCESS . ' : ' . $message;