OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/tags/release...
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / plugins / NP_Ping.php
1 <?php
2 /*
3   Note: based on NP_PingPong, adapt for the new ping mechanism
4
5   History
6     v1.0 - Initial version
7     v1.1 - Add JustPosted event support
8     v1.2 - JustPosted event handling in background
9     v1.3 - pinged variable support
10     v1.4 - language file support
11     v1.5 - remove arg1 in exec() call
12     v1.6 - move send update ping override option to plugin
13  */
14
15 class NP_Ping extends NucleusPlugin {
16
17         function getName() { return 'Ping'; }
18
19         function getAuthor() { return 'admun (Edmond Hui)'; }
20         function getURL()    { return 'http://edmondhui.homeip.net/nudn'; }
21         function getVersion() { return '1.6'; }
22
23         function getMinNucleusVersion() { return '330'; }
24
25         function getDescription() {
26                 return _PING_DESC;
27         }
28
29         function supportsFeature($what) {
30                 switch($what) {
31                         case 'SqlTablePrefix':
32                                 return 1;
33                         default:
34                                 return 0;
35                 }
36         }
37
38         function init()
39         {
40                 $language = ereg_replace( '[\\|/]', '', getLanguageName());
41                 if (file_exists($this->getDirectory()  . $language . '.php')) {
42                         include_once($this->getDirectory() . $language . '.php');
43                 }else {
44                         include_once($this->getDirectory() . 'english.php');
45                 }
46         }
47
48         function install() {
49                 $this->createOption('pingpong_pingomatic',_PING_PINGOM,'yesno','yes');  // Default, http://pingomatic.com
50                 $this->createOption('pingpong_weblogs',_PING_WEBLOGS,'yesno','no'); // http://weblogs.com
51                 $this->createOption('pingpong_technorati',_PING_TECHNOR,'yesno','no'); // http://www.technorati.com
52                 $this->createOption('pingpong_blogrolling',_PING_BLOGR,'yesno','no'); // http://www.blogrolling.com
53                 $this->createOption('pingpong_blogs',_PING_BLOGS,'yesno','no'); // http://blo.gs
54                 $this->createOption('pingpong_weblogues',_PING_WEBLOGUES,'yesno','no'); // http://weblogues.com/
55                 $this->createOption('pingpong_bloggde',_PING_BLOGGDE,'yesno','no'); // http://blogg.de
56                 $this->createOption('ping_background',_PING_BG,'yesno','yes');
57         }
58
59         function getEventList() {
60                 return array(
61                         'SendPing',
62                         'JustPosted'
63                         'AddItemFormExtras',
64                         'EditItemFormExtras');
65         }
66
67         function event_JustPosted($data) {
68                 global $DIR_PLUGINS, $DIR_NUCLEUS;
69
70                 // exit is another plugin already send ping
71                 if ($data['pinged'] == true) {
72                         return;
73                 }
74
75                 if ($this->getOption('ping_background') == "yes") {
76                         exec("php $DIR_PLUGINS/ping/ping.php " . $data['blogid'] . " &");
77                 } else {
78                         $this->sendPings($data['blogid']);
79
80                         ACTIONLOG::add(INFO, 'NP_Ping: Sending ping (from foreground)');
81                 }
82
83                 // mark the ping has been sent
84                 $data['pinged'] = true;
85         }
86
87         function event_SendPing($data) {
88                 $this->sendPings($data);
89         }
90
91         function DisplayFormOptions($sendping) {
92                 if ($sendping) {
93                         $check = 'checked="checked"';
94                 } else {
95                         $check = '';
96                 }
97                 $output = '<h3>' . _PING_EXTRA_PLUGIN_OPTION . '</h3>
98                 <p><input id="dosendping" name="dosendping" value="1" type="checkbox" ' . $check . '><label for="dosendping">' . _UPDATEDPING_GOSENDPING . '</label> </p>';
99                 echo $output;
100         }
101
102         function event_AddItemFormExtras($data){
103                 $this->DisplayFormOptions($data['blog']->sendPing());
104         }
105
106         function event_EditItemFormExtras($data){
107                 // we are not sending ping by default after edit an item
108                 $this->DisplayFormOptions(0);
109         }
110
111         function sendPings($data) {
112                 if (!class_exists('xmlrpcmsg')) {
113                         global $DIR_LIBS;
114                         include($DIR_LIBS . 'xmlrpc.inc.php');
115                 }
116
117                 $this->myBlogId = $data['blogid'];
118
119                 if ($this->getOption('pingpong_pingomatic')=='yes') {
120                         echo _PINGING . "Ping-o-matic:<br/>";
121                         echo $this->pingPingomatic();
122                         echo "<br/>";
123                 }
124
125                 if ($this->getOption('pingpong_weblogs')=='yes') { 
126                         echo _PINGING . "Weblogs.com:<br/>";
127                         echo $this->pingWeblogs();
128                         echo "<br/>";
129                 }
130
131                 if ($this->getOption('pingpong_technorati')=='yes') {
132                         echo _PINGING . "Technorati:<br/>";
133                         echo $this->pingTechnorati();
134                         echo "<br/>";
135                 }
136
137                 if ($this->getOption('pingpong_blogrolling')=='yes') {
138                         echo _PINGING . "Blogrolling.com:<br/>";
139                         echo $this->pingBlogRollingDotCom();
140                         echo "<br/>";
141                 }
142
143                 if ($this->getOption('pingpong_blogs')=='yes') {
144                         echo _PINGING . "Blog.gs:<br/>";
145                         echo $this->pingBloGs();
146                         echo "<br/>";
147                 }
148
149                 if ($this->getOption('pingpong_weblogues')=='yes') {
150                         echo _PINGING . "Weblogues.com:<br/>";
151                         echo $this->pingWebloguesDotCom();
152                         echo "<br/>";
153                 }
154
155                 if ($this->getOption('pingpong_bloggde')=='yes') {
156                         echo _PINGING . "Blog.de:<br/>";
157                         echo $this->pingBloggDe();
158                         echo "<br/>";
159                 }
160         }
161
162         function pingPingomatic() {
163                 $b = new BLOG($this->myBlogId);
164                 $message = new xmlrpcmsg(
165                                         'weblogUpdates.ping', array(
166                                         new xmlrpcval($b->getName(),'string'),
167                                         new xmlrpcval($b->getURL(),'string')
168                                         ));
169
170                 $c = new xmlrpc_client('/', 'rpc.pingomatic.com', 80);
171                 //$c->setDebug(1);
172
173                 $r = $c->send($message,30); // 30 seconds timeout...
174                 return $this->processPingResult($r);
175         }
176
177         function pingWeblogs() {
178                 $b = new BLOG($this->myBlogId);
179                 $message = new xmlrpcmsg(
180                                         'weblogupdates.ping',array(
181                                         new xmlrpcval($b->getName(),'string'),
182                                         new xmlrpcval($b->getUrl(),'string')
183                                         ));
184
185                 $c = new xmlrpc_client('/rpc2', 'rpc.weblogs.com', 80);
186                 //$c->setdebug(1);
187
188                 $r = $c->send($message,30); // 30 seconds timeout...
189                 return $this->processPingResult($r);
190         } 
191
192         function pingTechnorati() {
193                 $b = new BLOG($this->myBlogId);
194                 $message = new xmlrpcmsg(
195                                         'weblogUpdates.ping', array(
196                                         new xmlrpcval($b->getName(),'string'),
197                                         new xmlrpcval($b->getURL(),'string')
198                                         ));
199
200                 $c = new xmlrpc_client('/rpc/ping/', 'rpc.technorati.com', 80);
201                 //$c->setDebug(1);
202
203                 $r = $c->send($message,30); // 30 seconds timeout...
204                 return $this->processPingResult($r);
205         }
206
207         function pingBlogRollingDotCom() {
208                 $b = new BLOG($this->myBlogId);         
209                 $message = new xmlrpcmsg(
210                                         'weblogUpdates.ping',
211                                         array(
212                                         new xmlrpcval($b->getName(),'string'), // your blog title
213                                         new xmlrpcval($b->getURL(),'string')  // your blog url
214                                         ));
215
216                 $c = new xmlrpc_client('/pinger/', 'rpc.blogrolling.com', 80);
217                 //$c->setDebug(1);
218
219                 $r = $c->send($message,30); // 30 seconds timeout...     
220                 return $this->processPingResult($r);
221         } 
222
223         function pingBloGs() {
224                 $b = new BLOG($this->myBlogId);
225                 $message = new xmlrpcmsg(
226                                         'weblogUpdates.extendedPing', array(
227                                         new xmlrpcval($b->getName(),'string'),
228                                         new xmlrpcval($b->getURL(),'string')
229                                         ));
230
231                 $c = new xmlrpc_client('/', 'ping.blo.gs', 80);
232                 //$c->setDebug(1);
233
234                 $r = $c->send($message,30); // 30 seconds timeout...    
235                 return $this->processPingResult($r);
236         } 
237
238         function pingWebloguesDotCom() {
239                 $b = new BLOG($this->myBlogId);
240                 $message = new xmlrpcmsg(
241                                         'weblogUpdates.extendedPing',
242                                         array(
243                                         new xmlrpcval($b->getName(),'string'), // your blog title
244                                         new xmlrpcval($b->getURL(),'string')  // your blog url
245                                         ));
246
247                 $c = new xmlrpc_client('/RPC/', 'www.weblogues.com', 80);
248                 //$c->setDebug(1);
249
250                 $r = $c->send($message,30); // 30 seconds timeout...     
251                 return $this->processPingResult($r);
252         }
253
254         function pingBloggDe() {
255                 $b = new BLOG($this->myBlogId);
256                 $message = new xmlrpcmsg(
257                                         'bloggUpdates.ping', array(
258                                         new xmlrpcval($b->getName(),'string'),
259                                         new xmlrpcval($b->getURL(),'string')
260                                         ));
261
262                 $c = new xmlrpc_client('/', 'xmlrpc.blogg.de', 80);
263                 //$c->setDebug(1);
264
265                 $r = $c->send($message,30); // 30 seconds timeout...   
266                 return $this->processPingResult($r);
267         } 
268
269         function processPingResult($r) {
270                 global $php_errormsg;
271
272                 if (($r == 0) && ($r->errno || $r->errstring)) {
273                         return _PING_ERROR . " " . $r->errno . ' : ' . $r->errstring;
274                 } elseif (($r == 0) && ($php_errormsg)) {
275                         return _PING_PHP_ERROR . $php_errormsg;
276                 } elseif ($r == 0) {
277                         return _PING_PHP_PING_ERROR;
278                 } elseif ($r->faultCode() != 0) {
279                         return _PING_ERROR . ': ' . $r->faultString();
280                 } else {
281                         $r = $r->value();       // get response struct
282
283                         // get values
284                         $flerror = $r->structmem('flerror');
285                         $flerror = $flerror->scalarval();
286
287                         $message = $r->structmem('message');
288                         $message = $message->scalarval();
289
290                         if ($flerror != 0) {
291                                 return _PING_ERROR . ' (flerror=1): ' . $message;
292                         }
293                         else {
294                                 return _PING_SUCCESS . ': ' . $message;
295                         }
296                 }
297         }
298 }
299
300 ?>