• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revisioned39ebe29bb05194f69f8aa96a2e7991ca28f58b (tree)
Time2009-03-16 00:47:03
Authorshizuki <shizuki@1ca2...>
Commitershizuki

Log Message

Ignored 'SendPing' and 'JustPosted' events!

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@975 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- a/NP_PingJP/trunk/NP_PingJP.php
+++ b/NP_PingJP/trunk/NP_PingJP.php
@@ -37,6 +37,7 @@
3737 * v1.66 - Typo fix
3838 * v1.67 - Bug fix
3939 * v1.68 - Debug development
40+ * v1.69 - Ignored 'SendPing' and 'JustPosted' events!
4041 *
4142 * NP_PingJP.php ($Revision: 1.16 $)
4243 * $Id$
@@ -54,7 +55,7 @@ class NP_PingJP extends NucleusPlugin
5455
5556 var $ahttp;
5657 var $debug = false;
57-var $bgping = false;
58+//var $bgping = false;
5859 var $servers;
5960 var $faltMessageSet;
6061
@@ -110,7 +111,7 @@ var $faltMessageSet;
110111 */
111112 function getVersion()
112113 {
113- return '1.68';
114+ return '1.69';
114115 }
115116
116117 // }}}
@@ -171,7 +172,10 @@ var $faltMessageSet;
171172 */
172173 function install()
173174 {
174- // Default, http://pingomatic.com
175+ // Send update ping ?
176+ $this->createBlogOption('pingjp_sendping', _EBLOG_PING, 'yesno', 'yes');
177+ // Default servers
178+ // http://pingomatic.com
175179 $this->createBlogOption('pingjp_pingomatic', _PINGJP_PINGOM, 'yesno', 'yes');
176180 // http://weblogs.com
177181 $this->createBlogOption('pingjp_weblogs', _PINGJP_WEBLOGS, 'yesno', 'no');
@@ -199,6 +203,21 @@ var $faltMessageSet;
199203 $this->createBlogOption('pingjp_updateurl', _PINGJP_UPDURL, 'text', '');
200204 // Your RSS URL
201205 $this->createBlogOption('pingjp_feedurl', _PINGJP_UPDFEED, 'text', '');
206+
207+ $query = 'CREATE TABLE IF NOT EXISTS '
208+ . sql_table('plug_pingjp') . ' ('
209+ . ' `pingid` int(11) NOT NULL auto_increment, '
210+ . ' `itemid` int(11) NOT NULL default "0", '
211+ . ' `posted` tinyint(2) NOT NULL default "1", '
212+ . ' PRIMARY KEY (`pingid`), '
213+ . ' UNIQUE KEY `mname` (`itemid`)'
214+ . ') ';
215+ if (_CHARSET == 'UTF-8') {
216+ $query .= ' DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci';
217+ } else {
218+ $query .= ' DEFAULT CHARACTER SET ujis COLLATE ujis_japanese_ci';
219+ }
220+ sql_query($query);
202221 }
203222
204223 // }}}
@@ -211,6 +230,7 @@ var $faltMessageSet;
211230 */
212231 function init()
213232 {
233+ global $CONF;
214234 $language = ereg_replace( '[\\|/]', '', getLanguageName());
215235 if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
216236 include_once($this->getDirectory() . 'language/' . $language . '.php');
@@ -279,6 +299,111 @@ var $faltMessageSet;
279299 'method' => 'weblogUpdates.extendedPing',
280300 ),
281301 );
302+ if ($CONF['DebugVars']) {
303+ $this->debug = true;
304+ }
305+ }
306+
307+ // }}}
308+ // {{{ function extraInputField($check)
309+
310+ /**
311+ * Add extra inout field for item add/edit form.
312+ *
313+ * @param bool
314+ */
315+ function extraInputField($checked)
316+ {
317+ $check = $checked ? ' checked="checked"' : '';
318+ $title = _EBLOG_PING;
319+ echo <<<___PINGCHECK___
320+ <h3>Ping</h3>
321+
322+ <p>
323+ <label for="plug_ping_check">{$title}</label>
324+ <input type="checkbox" value="1" id="plug_ping_check" name="plug_ping_check"{$check} /><br />
325+ </p>
326+___PINGCHECK___;
327+ }
328+
329+ // }}}
330+ // {{{ function goSendPing($itemid)
331+
332+ /**
333+ * Send Ping Go !
334+ *
335+ * @param intger
336+ */
337+ function goSendPing($itemid)
338+ {
339+ $bid = getBlogIDFromItemID(intval($itemid));
340+ if ($this->getBlogOption(intval($bid), 'pingjp_sendping') != 'yes') return;
341+ global $manager;
342+ $item = &$manager->getItem(intval($itemid), 1, 1);
343+ $blog = &$manager->getBlog(intval($bid));
344+ if($this->pingCheck($bid) && requestVar('plug_ping_check') == 1) {
345+ if (!$item || $item['draft'] || $item['timestamp'] > $blog->getCorrectTime()) {
346+ return $item;
347+ } elseif ($this->getBlogOption(intval($bid), 'pingjp_background') == 'yes') {
348+ register_shutdown_function(array($this, 'sendPingBackground'), intval($bid));
349+ } else {
350+ $this->sendPing(intval($bid), 1);
351+ }
352+ }
353+ return $item;
354+ }
355+
356+ // }}}
357+ // {{{ function pingCheck($bid)
358+
359+ /**
360+ * Send update ping ?
361+ *
362+ * @param intger value
363+ * @return bool
364+ */
365+ function pingCheck($bid)
366+ {
367+ foreach ($this->servers as $key => $server) {
368+ $serverName = 'pingjp_' . $server['server'];
369+ $info = $this->getBlogOption(intval($bid), $serverName);
370+ if ($info == 'yes') {
371+ return true;
372+ }
373+ }
374+ return ($this->getBlogOption(intval($bid), 'pingjp_otherurl'));
375+ }
376+
377+ // }}}
378+ // {{{ function event_AddItemFormExtras($data)
379+
380+ /**
381+ * Extra input field for add item
382+ *
383+ * @param array
384+ */
385+ function event_AddItemFormExtras($data)
386+ {
387+ $bid = $data['blog']->getID();
388+ if ($this->getBlogOption(intval($bid), 'pingjp_sendping') == 'yes') {
389+ $this->extraInputField(1);
390+ }
391+ }
392+
393+ // }}}
394+ // {{{ function event_EditItemFormExtras($data)
395+
396+ /**
397+ * Extra input field for edit item
398+ *
399+ * @param array
400+ */
401+ function event_EditItemFormExtras($data)
402+ {
403+ $bid = $data['blog']->getID();
404+ if ($this->getBlogOption(intval($bid), 'pingjp_sendping') == 'yes') {
405+ $this->extraInputField(0);
406+ }
282407 }
283408
284409 // }}}
@@ -293,61 +418,103 @@ var $faltMessageSet;
293418 function getEventList()
294419 {
295420 return array(
296- 'SendPing',
297- 'JustPosted',
421+// 'SendPing',
422+// 'JustPosted',
423+ 'PostAddItem',
424+ 'PostUpdateItem',
425+ 'AddItemFormExtras',
426+ 'EditItemFormExtras',
427+ 'PostSkinParse',
298428 );
299429 }
300430
301431 // }}}
302- // {{{ function event_JustPosted($data)
432+ // {{{ function event_PostAddItem($data)
303433
304434 /**
305- * Event ITEM timstamp as now send update ping or etc.
435+ * After item is added
306436 *
307- * @param array
308- * blogid : value intger
309- * blog ID
310- * pinged : reference boolean
311- * Update ping completed as true
312- * @return void
437+ * @param array
438+ * itemid : value intger
313439 */
314- function event_JustPosted($data)
440+ function event_PostAddItem($data)
315441 {
316- if ($data['pinged'] == true) {
442+ $item = $this->goSendPing(intval($data['itemid']));
443+ if (!$item) {
317444 return;
318445 }
319- if ($this->getBlogOption($data['blogid'], 'pingjp_background') == "yes") {
320-// $directory = $this->getDirectory();
321-// // TODO: Check
322-// if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
323-// system("start /b php " . $directory . "ping.php " . $data['blogid'] . " > nul" );
324-// } else {
325-// exec("php " . $directory . "ping.php " . $data['blogid'] . " > /dev/null &");
326-// }
327- register_shutdown_function(array($this, 'SendPingBackground'), $data['blogid'], 2);
328- } else {
329- $this->sendPings($data['blogid'], 1);
446+ global $manager;
447+ $blog = &$manager->getBlog(intval($item['blogid']));
448+ if ($item['timestamp'] > $blog->getCorrectTime() || $item['draft']) {
449+ $query = 'INSERT INTO %s (`itemid`, `posted`) VALUES (%d, 0)';
450+ $query = sprintf($query, sql_table('plug_pingjp'), intval($data['itemid']));
451+ sql_query($query);
330452 }
331- $data['pinged'] = true;
332453 }
333454
334455 // }}}
335- // {{{ function event_SendPing($data)
456+ // {{{ function event_PostUpdateItem($data)
336457
337458 /**
338- * Event send weblog updates ping when add ITEM
459+ * After item is updated
339460 *
340- * @param array
341- * blogid : value intger
342- * blog ID
343- * @return void
461+ * @param array
462+ * itemid : value intger
344463 */
345- function event_SendPing($data)
464+ function event_PostUpdateItem($data)
465+ {
466+ $item = $this->goSendPing(intval($data['itemid']));
467+ if (!$item) {
468+ return;
469+ }
470+ global $manager;
471+ $blog = &$manager->getBlog(intval($item['blogid']));
472+ if ($item['timestamp'] > $blog->getCorrectTime() || $item['draft']) {
473+ $query = 'SELECT `pingid` as result FROM %s WHERE `itemid` = %d';
474+ $query = sprintf($query, sql_table('plug_pingjp'), intval($data['itemid']));
475+ if ($pingid = intval(quickQuery($query))) {
476+ $query = 'UPDATE %s SET `itemid` = %d, `posted` = 0 WHERE `pingid` = %d';
477+ $query = sprintf($query, sql_table('plug_pingjp'), intval($data['itemid']), intval($pingid));
478+ sql_query($query);
479+ }
480+ }
481+ }
482+
483+ // }}}
484+ // {{{ function event_PostSkinParse($data)
485+
486+ /**
487+ * After item is updated
488+ *
489+ * @param array
490+ * skin : ref object
491+ * type : value string
492+ */
493+ function event_PostSkinParse($data)
346494 {
347- if ($this->bgping)
348- register_shutdown_function(array($this, 'SendPingBackground'), $data['blogid']);
349- else
350- $this->sendPing($data['blogid']);
495+ $query = 'SELECT * FROM '
496+ . sql_table('plug_pingjp') . ' as p, '
497+ . sql_table('item') . ' as i '
498+ . ' WHERE '
499+ . ' i.itime < NOW() '
500+ . ' AND p.posted = 0 '
501+ . ' AND i.inumber = p.itemid ';
502+ $res = sql_query($query);
503+ if (mysql_num_rows($res) > 0) {
504+ $pings = array();
505+ while ($item = mysql_fetch_assoc($res)) {
506+ if (!$item['idraft']) {
507+ $bid = getBlogIDFromItemID(intval($item['itemid']));
508+ $this->sendPingBackground($bid);
509+ $pings[] = intval($item['pingid']);
510+ }
511+ }
512+ if (count($pings) > 0) {
513+ $query = 'UPDATE %s SET `posted` = 1 WHERE `pingid` IN (%s)';
514+ $query = sprintf($query, sql_table('plug_pingjp'), implode(',', $pings));
515+ sql_query($query);
516+ }
517+ }
351518 }
352519
353520 // }}}
@@ -360,7 +527,7 @@ var $faltMessageSet;
360527 * blog ID
361528 * @return void
362529 */
363- function SendPingBackground($bid)
530+ function sendPingBackground($bid)
364531 {
365532 while( @ob_end_flush() ) ;
366533 sql_connect();
@@ -648,4 +815,45 @@ var $faltMessageSet;
648815 // print_r($targets);
649816 return $targets;
650817 }
818+
819+ // {{{ function event_JustPosted($data)
820+
821+ /**
822+ * Event ITEM timstamp as now send update ping or etc.
823+ *
824+ * @param array
825+ * blogid : value intger
826+ * blog ID
827+ * pinged : reference boolean
828+ * Update ping completed as true
829+ * @return void
830+ *
831+ function event_JustPosted($data)
832+ {
833+ if ($data['pinged'] == true) {
834+ return;
835+ } else {
836+ $data['pinged'] = true;
837+ return;
838+ }
839+ }
840+
841+ // }}}
842+ // {{{ function event_SendPing($data)
843+
844+ /**
845+ * Event send weblog updates ping when add ITEM
846+ *
847+ * @param array
848+ * blogid : value intger
849+ * blog ID
850+ * @return void
851+ *
852+ function event_SendPing($data)
853+ {
854+ return;
855+ }
856+*/
857+ // }}}
858+
651859 }
Show on old repository browser