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