| [ Index ] |
PHP Cross Reference of Nucleus CMS v3.51 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 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 7 * PHP versions 4 and 5 8 * 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) 14 * 15 * @author admun (Edmond Hui) 16 * @license http://www.gnu.org/licenses/gpl.txt GNU GENERAL PUBLIC LICENSE Version 2, June 1991 17 * @version 1.8 18 * @link http://edmondhui.homeip.net/nudn 19 * $id$ 20 * History 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 */ 32 33 class NP_Ping extends NucleusPlugin 34 { 35 36 function getName() 37 { 38 return 'Ping'; 39 } 40 41 function getAuthor() 42 { 43 return 'admun (Edmond Hui)'; 44 } 45 46 function getURL() 47 { 48 return 'http://edmondhui.homeip.net/nudn'; 49 } 50 51 function getVersion() 52 { 53 return '1.8'; 54 } 55 56 function getMinNucleusVersion() 57 { 58 return '330'; 59 } 60 61 function getDescription() 62 { 63 return _PING_DESC; 64 } 65 66 function supportsFeature($what) 67 { 68 switch($what) { 69 case 'SqlTablePrefix': 70 return 1; 71 default: 72 return 0; 73 } 74 } 75 76 function init() 77 { 78 // $language = ereg_replace( '[\\|/]', '', getLanguageName()); 79 $language = preg_replace( '@\\|/@', '', getLanguageName()); 80 if (file_exists($this->getDirectory() . $language . '.php')) { 81 include_once($this->getDirectory() . $language . '.php'); 82 } else { 83 include_once($this->getDirectory() . 'english.php'); 84 } 85 } 86 87 function install() 88 { 89 // Default, http://pingomatic.com 90 $this->createOption('pingpong_pingomatic', _PING_PINGOM, 'yesno', 'yes'); 91 // http://weblogs.com 92 $this->createOption('pingpong_weblogs', _PING_WEBLOGS, 'yesno', 'no'); 93 // http://www.technorati.com 94 $this->createOption('pingpong_technorati', _PING_TECHNOR, 'yesno', 'no'); 95 // http://www.blogrolling.com 96 $this->createOption('pingpong_blogrolling', _PING_BLOGR, 'yesno', 'no'); 97 // http://blo.gs 98 $this->createOption('pingpong_blogs', _PING_BLOGS, 'yesno', 'no'); 99 // http://weblogues.com/ 100 $this->createOption('pingpong_weblogues', _PING_WEBLOGUES, 'yesno', 'no'); 101 // http://blogg.de 102 $this->createOption('pingpong_bloggde', _PING_BLOGGDE, 'yesno', 'no'); 103 104 // Pinging on background 105 $this->createOption('ping_background', _PING_BG, 'yesno', 'no'); 106 107 $this->createBlogOption('ping_sendping', _PING_SENDPING, 'yesno', 'yes'); 108 } 109 110 function getEventList() 111 { 112 return array( 113 'JustPosted', 114 'PostAddItem', 115 'PostUpdateItem' 116 ); 117 } 118 119 function event_JustPosted($data) 120 { 121 global $DIR_PLUGINS, $DIR_NUCLEUS; 122 123 // exit is another plugin already send ping 124 if ($data['pinged'] == true) { 125 return; 126 } 127 128 $bid = intval($data['blogid']); 129 if ($this->getBlogOption($bid, 'ping_sendping') == "yes") { 130 if ($this->getOption('ping_background') == "yes") { 131 exec("php $DIR_PLUGINS/ping/ping.php " . $data['blogid'] . " &"); 132 } else { 133 $this->sendPings($data['blogid']); 134 } 135 } 136 // mark the ping has been sent 137 $data['pinged'] = true; 138 } 139 140 function event_PostAddItem($data) 141 { 142 // global $manager; 143 // $blogId = getBlogIDFromItemID($data['itemid']); 144 // $item =& ITEM::getitem($data['itemid'], 0, 0); // draft or future post return 0 145 // if ($item != 0) { 146 // if ($this->getBlogOption($blogId, 'ping_sendping') == "yes") { 147 // $this->sendPings(array('blogid' => $blogId)); 148 // } 149 // } 150 $this->_sendPingCheck($data['itemid']); 151 } 152 153 function event_PostUpdateItem($data) 154 { 155 // global $manager; 156 // $blogId = getBlogIDFromItemID($data['itemid']); 157 // $blog =& $manager->getBlog($blogId); // <- why? 158 // $item =& ITEM::getitem($data['itemid'], 0, 0); // draft or future post return 0 159 // if ($item != 0) { 160 // if ($this->getBlogOption($blogId,'ping_sendping') == "yes" ) { 161 // $this->sendPings(array('blogid' => $blogId)); 162 // } 163 // } 164 $this->_sendPingCheck($data['itemid']); 165 } 166 167 function _sendPingCheck($itemid) 168 { 169 $iid = intval($itemid); 170 $item = ITEM::getitem($iid, 0, 0); // draft or future post return 0 171 if ($item) { 172 $bid = intval(getBlogIDFromItemID($iid)); 173 if ($this->getBlogOption($bid, 'ping_sendping') == "yes" ) { 174 $this->sendPings(array('blogid' => $bid)); 175 } 176 } 177 } 178 179 function sendPings($data) { 180 181 if (!class_exists('xmlrpcmsg')) { 182 global $DIR_LIBS; 183 include ($DIR_LIBS . 'xmlrpc.inc.php'); 184 } 185 $this->myBlogId = $data['blogid']; 186 187 $ping_result = ''; 188 189 if ($this->getOption('pingpong_pingomatic') == 'yes') { 190 $ping_result .= _PINGING . "Ping-o-matic:\n"; 191 $ping_result .= $this->pingPingomatic(); 192 $ping_result .= " | "; 193 } 194 195 if ($this->getOption('pingpong_weblogs') == 'yes') { 196 $ping_result .= _PINGING . "Weblogs.com:\n"; 197 $ping_result .= $this->pingWeblogs(); 198 $ping_result .= " | "; 199 } 200 201 if ($this->getOption('pingpong_technorati') == 'yes') { 202 $ping_result .= _PINGING . "Technorati:\n"; 203 $ping_result .= $this->pingTechnorati(); 204 $ping_result .= " | "; 205 } 206 207 if ($this->getOption('pingpong_blogrolling') == 'yes') { 208 $ping_result .= _PINGING . "Blogrolling.com:\n"; 209 $ping_result .= $this->pingBlogRollingDotCom(); 210 $ping_result .= " | "; 211 } 212 213 if ($this->getOption('pingpong_blogs') == 'yes') { 214 $ping_result .= _PINGING . "Blog.gs:\n"; 215 $ping_result .= $this->pingBloGs(); 216 $ping_result .= " | "; 217 } 218 219 if ($this->getOption('pingpong_weblogues') == 'yes') { 220 $ping_result .= _PINGING . "Weblogues.com:\n"; 221 $ping_result .= $this->pingWebloguesDotCom(); 222 $ping_result .= " | "; 223 } 224 225 if ($this->getOption('pingpong_bloggde') == 'yes') { 226 $ping_result .= _PINGING . "Blog.de:\n"; 227 $ping_result .= $this->pingBloggDe(); 228 $ping_result .= " | "; 229 } 230 231 ACTIONLOG::add(INFO, $ping_result); 232 } 233 234 function pingPingomatic() { 235 $b = new BLOG($this->myBlogId); 236 $message = new xmlrpcmsg( 237 'weblogUpdates.ping', 238 array( 239 new xmlrpcval($b->getName(), 'string'), 240 new xmlrpcval($b->getURL(), 'string') 241 ) 242 ); 243 244 $c = new xmlrpc_client('/', 'rpc.pingomatic.com', 80); 245 //$c->setDebug(1); 246 247 $r = $c->send($message,30); // 30 seconds timeout... 248 return $this->processPingResult($r); 249 } 250 251 function pingWeblogs() { 252 $b = new BLOG($this->myBlogId); 253 $message = new xmlrpcmsg( 254 'weblogupdates.ping', 255 array( 256 new xmlrpcval($b->getName(), 'string'), 257 new xmlrpcval($b->getURL(), 'string') 258 ) 259 ); 260 261 $c = new xmlrpc_client('/rpc2', 'rpc.weblogs.com', 80); 262 //$c->setdebug(1); 263 264 $r = $c->send($message,30); // 30 seconds timeout... 265 return $this->processPingResult($r); 266 } 267 268 function pingTechnorati() { 269 $b = new BLOG($this->myBlogId); 270 $message = new xmlrpcmsg( 271 'weblogUpdates.ping', 272 array( 273 new xmlrpcval($b->getName(),'string'), 274 new xmlrpcval($b->getURL(),'string') 275 ) 276 ); 277 278 $c = new xmlrpc_client('/rpc/ping/', 'rpc.technorati.com', 80); 279 //$c->setDebug(1); 280 281 $r = $c->send($message,30); // 30 seconds timeout... 282 return $this->processPingResult($r); 283 } 284 285 function pingBlogRollingDotCom() { 286 $b = new BLOG($this->myBlogId); 287 $message = new xmlrpcmsg( 288 'weblogUpdates.ping', 289 array( 290 new xmlrpcval($b->getName(),'string'), 291 new xmlrpcval($b->getURL(),'string') 292 ) 293 ); 294 295 $c = new xmlrpc_client('/pinger/', 'rpc.blogrolling.com', 80); 296 //$c->setDebug(1); 297 298 $r = $c->send($message,30); // 30 seconds timeout... 299 return $this->processPingResult($r); 300 } 301 302 function pingBloGs() { 303 $b = new BLOG($this->myBlogId); 304 $message = new xmlrpcmsg( 305 'weblogUpdates.extendedPing', 306 array( 307 new xmlrpcval($b->getName(),'string'), 308 new xmlrpcval($b->getURL(),'string') 309 ) 310 ); 311 312 $c = new xmlrpc_client('/', 'ping.blo.gs', 80); 313 //$c->setDebug(1); 314 315 $r = $c->send($message,30); // 30 seconds timeout... 316 return $this->processPingResult($r); 317 } 318 319 function pingWebloguesDotCom() { 320 $b = new BLOG($this->myBlogId); 321 $message = new xmlrpcmsg( 322 'weblogUpdates.extendedPing', 323 array( 324 new xmlrpcval($b->getName(),'string'), 325 new xmlrpcval($b->getURL(),'string') 326 ) 327 ); 328 329 $c = new xmlrpc_client('/RPC/', 'www.weblogues.com', 80); 330 //$c->setDebug(1); 331 332 $r = $c->send($message,30); // 30 seconds timeout... 333 return $this->processPingResult($r); 334 } 335 336 function pingBloggDe() { 337 $b = new BLOG($this->myBlogId); 338 $message = new xmlrpcmsg( 339 'bloggUpdates.ping', 340 array( 341 new xmlrpcval($b->getName(),'string'), 342 new xmlrpcval($b->getURL(),'string') 343 ) 344 ); 345 346 $c = new xmlrpc_client('/', 'xmlrpc.blogg.de', 80); 347 //$c->setDebug(1); 348 349 $r = $c->send($message,30); // 30 seconds timeout... 350 return $this->processPingResult($r); 351 } 352 353 function processPingResult($r) { 354 global $php_errormsg; 355 356 if (($r == 0) && ($r->errno || $r->errstring)) { 357 return _PING_ERROR . " " . $r->errno . ' : ' . $r->errstring; 358 } elseif (($r == 0) && ($php_errormsg)) { 359 return _PING_PHP_ERROR . $php_errormsg; 360 } elseif ($r == 0) { 361 return _PING_PHP_PING_ERROR; 362 } elseif ($r->faultCode() != 0) { 363 return _PING_ERROR . ': ' . $r->faultString(); 364 } else { 365 $r = $r->value(); // get response struct 366 367 // get values 368 $flerror = $r->structmem('flerror'); 369 $flerror = $flerror->scalarval(); 370 371 $message = $r->structmem('message'); 372 $message = $message->scalarval(); 373 374 if ($flerror != 0) { 375 return _PING_ERROR . ' (flerror=1): ' . $message; 376 } else { 377 return _PING_SUCCESS . ': ' . $message; 378 } 379 } 380 } 381 } 382 383 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 03:56:06 2010 |