OSDN Git Service

* Still, the human sacrifice test version.
[nucleus-jp/nucleus-plugins.git] / trunk / NP_EzComment2 / NP_EzComment2.php
1 <?php
2 /**
3  * SHOW Comment Form/List PLUG-IN FOR NucleusCMS
4  * PHP versions 5
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  *
12  * @author    shizuki
13  * @copyright 2008 shizuki
14  * @license   http://www.gnu.org/licenses/gpl.txt  GNU GENERAL PUBLIC LICENSE Version 2, June 1991
15  * @version   $Date: 2008-07-07 10:24:00 $ $Revision: 1.7 $
16  * @link      http://japan.nucleuscms.org/wiki/plugins:showblogs
17  * @since     File available since Release 1.0
18  */
19
20 /**
21  * version history
22  *
23  * $Log: not supported by cvs2svn $
24  **/
25
26 class NP_EzComment2 extends NucleusPlugin
27 {
28         // {{{ properties
29
30         /**
31          * The calling number of times by the index page.
32          *
33          * @var integer
34          */
35         var $numcalled;
36
37         /**
38          * OpenID authentication module.
39          *
40          * @var object
41          */
42         var $authOpenID;
43
44         // }}}
45         // {{{ getName()
46
47         /**
48          * Plugin Name
49          *
50          * @return string
51          */
52         function getName()
53         {
54                 return 'Ez Comment II';
55         }
56
57         // }}}
58         // {{{ getAuthor()
59
60         /**
61          * Author Name
62          *
63          * @return string
64          */
65         function getAuthor()
66         {
67                 return 'shizuki';
68         }
69
70         // }}}
71         // {{{ getURL()
72
73         /**
74          * I get a plug-in, the address of the possible site or author's mail address.
75          *
76          * @return string
77          */
78         function getURL()
79         {
80                 return 'http://japan.nucleuscms.org/wiki/plugins:ezcomment2';
81         }
82
83         // }}}
84         // {{{ getPluginDep()
85
86         /**
87          * Plugin Dependency.
88          *
89          * @return array
90          */
91         function getPluginDep()
92         {
93                 return array(
94                         'NP_OpenIdt',
95                         'NP_znSpecialTemplateParts',
96                 );
97         }
98
99         // }}}
100         // {{{ getVersion()
101
102         /**
103          * Plugin Version.
104          *
105          * @return string
106          */
107         function getVersion()
108         {
109                 return '$Date: 2008-07-07 10:24:00 $ $Revision: 1.7 $';
110         }
111
112         // }}}
113         // {{{ getDescription()
114
115         /**
116          * Plugin Description
117          *
118          * @return string
119          */
120         function getDescription()
121         {
122                 return  _NP_EZCOMMENT2_DESC;
123         }
124
125         // }}}
126         // {{{ supportsFeature($what)
127
128         /**
129          * Supports Nucleus Feature
130          *
131          * @param  string
132          * @return boolean
133          */
134         function supportsFeature($what)
135         {
136                 switch ($what) {
137                         case 'SqlTablePrefix':
138                                 return 1;
139                         default:
140                                 return 0;
141                 }
142         }
143
144         // }}}
145         // {{{ getEventList()
146
147         /**
148          * List of feature event
149          *
150          * @return array
151          */
152         function getEventList()
153         {
154                 global $manager;
155                 return array(
156                         'FormExtra',
157                         'PostAddComment',
158                 );
159         }
160
161         // }}}
162         // {{{ getTableList()
163
164         /**
165           * Database tables for plugin used
166           *
167           * @return array
168           **/
169         function getTableList()
170         {
171                 return array(
172                         sql_table('plug_ezcomment2'),
173                         );
174         }
175
176         // }}}
177         // {{{ install()
178
179         /**
180          * Install function
181          *
182          * @return void.
183          */
184         function install()
185         {
186                 if (!TEMPLATE::exists('EzCommentTemplate')) {
187                         global $DIR_LIBS;
188                         include_once($DIR_LIBS . 'skinie.php');
189                         $importer = new SKINIMPORT();
190                         $importer->reset();
191                         $template = $this->getDirectory() . 'skinbackup.xml';
192                         if (!@file_exists($template)) {
193                                 $aErrors[] = 'Unable to import ' . $template . ' : file does not exist';
194                                 continue;
195                         }
196                         $error = $importer->readFile($template);
197                         if ($error) {
198                                 $aErrors[] = 'Unable to import ' . $template . ' : ' . $error;
199                                 continue;
200                         }
201                         $error = $importer->writeToDatabase(1);
202                         if ($error) {
203                                 $aErrors[] = 'Unable to import ' . $template . ' : ' . $error;
204                                 continue;
205                         }
206                         if ($aErrors) {
207                                 $message = implode("<br />\n", $aErrors);
208                                 doError($message);
209                         }
210                         $this->createBlogOption('secret',     _NP_EZCOMMENT2_OP_SECRETMODE,  'yesno', 'no');
211                         $this->createBlogOption('secComment', _NP_EZCOMMENT2_OP_SUBSTIUTION, 'text',  _NP_EZCOMMENT2_OP_SUBSTIUTION_VAL);
212                         $this->createBlogOption('secLabel',   _NP_EZCOMMENT2_OP_CHECKLABEL,  'text',  _NP_EZCOMMENT2_OP_CHECKLABEL_VAL);
213                         $this->createOption('tabledel',       _NP_EZCOMMENT2_OP_DROPTABLE,   'yesno', 'no');
214                         $sql = 'CREATE TABLE IF NOT EXISTS %s ('
215                                  . '`comid`  int(11)  NOT NULL, '
216                                  . '`secflg` tinyint(1)   NULL, '
217                                  . '`module` varchar(15)  NULL, '
218                                  . '`userID` varchar(255) NULL, '
219                                  . 'PRIMARY KEY(`comid`) );';
220                         sql_query(sprintf($sql, sql_table('plug_ezcomment2')));
221                         $this->updateTable();
222                 }
223         }
224
225         // }}}
226         // {{{ uninstall()
227
228         /**
229          * Un Install function
230          *
231          * @return void.
232          */
233         function uninstall()
234         {
235                 if ($this->getOption('tabledel') == 'yes')
236                         sql_query('DROP TABLE '.sql_table('plug_ezcomment2'));
237         }
238
239         // }}}
240         // {{{ init()
241
242         /**
243          * Initialize
244          *
245          * @return void.
246          */
247         function init()
248         {
249                 $this->languageInclude();
250                 $this->numcalled  = 0;
251                 global $manager;
252                 if ($manager->pluginInstalled('NP_OpenId') && !$this->authOpenID) {
253                         $this->authOpenID = $manager->getPlugin('NP_OpenId');
254                 }
255         }
256
257         // }}}
258         // {{{ event_PostAddComment($data)
259
260         /**
261          * After adding a comment to the database.
262          *
263          * @param  array
264          *                      commentid integer
265          *                      comment   array
266          *                      spamcheck array
267          * @return void.
268          */
269         function event_PostAddComment($data)
270         {
271                 global $member;
272                 switch (true) {
273                         case $member->isLoggedin():
274                                 $userID = $member->getID();
275                                 $module = 'Nucleus';
276                                 break;
277                         case ($this->authOpenID && $this->authOpenID->isLoggedin()):
278                                 $userID = $this->authOpenID->loggedinUser['identity'];
279                                 $module = 'OpenID';
280                                 break;
281                         default:
282                                 break;
283                 }
284                 if (postVar('EzComment2_Secret')) {
285                         $secCheck = 1;
286                 } else {
287                         $secCheck = null;
288                 }
289                 $sql = 'INSERT INTO ' . sql_table('plug_ezcomment2')
290                          . ' (`comid`, `secflg`, `module`, `userID`) VALUES (%d, %d, %s, %s)';
291                 sql_query(sprintf($sql, $data['commentid'], $secCheck, $module, $userID));
292         }
293
294         // }}}
295         // {{{ event_FormExtra(&$data)
296
297         /**
298          * Inside one of the comment, membermail or account activation forms.
299          *
300          * @param  array
301          *                      type string
302          * @return void.
303          */
304         function event_FormExtra(&$data)
305         {
306                 global $blogid;
307                 $this->numcalled++;
308                 if ($blogid && $this->getBlogOption($blogid, 'secret') == 'yes') {
309                         echo '<br /><input type="checkbox" value="1" name="EzComment2_Secret" id="EzComment2_Secret_' . $this->numcalled . '" />';
310                         echo '<label for="EzComment2_Secret_' . $this->numcalled . '">'.$this->getBlogOption($bid, 'secLabel').'</label><br />';
311                 }
312         }
313
314         // }}}
315         // {{{ doTemplateVar()
316
317         /**
318          * Basically the same as doSkinVar,
319          * but this time for calls of the <%plugin(...)%>-var in templates (item header/body/footer and dateheader/footer).
320          *
321          * @param  object item object(refarence)
322          * @param  string
323          * @param  string
324          * @param  string
325          * @param  string
326          * @param  string
327          * @return void.
328          */
329         function doTemplateVar(&$item,
330                                                         $showType       = '',
331                                                         $showMode       = '5/1/1',
332                                                         $destinationurl = '',
333                                                         $formTemplate   = 'EzCommentTemplate',
334                                                         $listTemplate   = 'EzCommentTemplate')
335         {
336                 $this->doSkinVar('template', $showType, $showMode, $destinationurl, $formTemplate, $listTemplate, $item);
337         }
338
339         // }}}
340         // {{{ doSkinVar()
341
342         /**
343          * When plugins are called using the <%plugin(...)%>-skinvar, this method will be called. 
344          *
345          * @param  string
346          * @param  string
347          * @param  string
348          * @param  string
349          * @param  string
350          * @param  string
351          * @param  object item object(refarence)
352          * @return void.
353          */
354         function doSkinVar($skinType,
355                                            $showType       = '',
356                                            $showMode       = '5/1/1',
357                                            $destinationurl = '',
358                                            $formTemplate   = 'EzCommentTemplate',
359                                            $listTemplate   = 'EzCommentTemplate',
360                                           &$commentItem    = '')
361         {
362                 if ($skinType != 'item' && $skinType != 'template') return;
363                 global $manager, $member, $itemid;
364                 if (!$commentItem && $itemid) {
365                         $commentItem = $manager->getItem($itemid, 0, 0);
366                         if (is_array($commentItem)) {
367                                 $commentItem = (object)$commentItem;
368                         }
369                 }
370                 if (!$commentItem || $commentItem->closed) {
371                         echo _ERROR_ITEMCLOSED;
372                         return 0;
373                 }
374
375                 if (is_numeric($showType) || strpos($showType, '/') !== false) $showMode = $showType;
376                 if ($showType != 'list' && $showType != 'form') {
377                         $showType = '';
378                 }
379                 if (!$showMode) {
380                         $showMode = '5/1/1';
381                 }
382                 list($maxToShow, $sortOrder, $commentOrder) = explode('/', $showMode);
383                 if (!$maxToShow) $maxToShow = 5;
384                 if (!$sortOrder) $sortOrder = 1;
385                 if ($commentOrder > 0) {
386                         $commentOrder = true;
387                 } else {
388                         $commentOrder = false;
389                 }
390                 if (!$formTemplate) $formTemplate = 'EzCommentTemplate';
391                 if (!$listTemplate) $listTemplate = 'EzCommentTemplate';
392
393                 switch ($showType) {
394                         case 'list':
395                                 $listTemplate = TEMPLATE::read($listTemplate);
396                                 $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
397                                 break;
398                         case 'form':
399                                 $formTemplate = TEMPLATE::read($formTemplate);
400                                 $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
401                                 break;
402                         default:
403                                 $listTemplate = TEMPLATE::read($listTemplate);
404                                 $formTemplate = TEMPLATE::read($formTemplate);
405                                 if ($sortOrder) {
406                                         $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
407                                         $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
408                                 } else {
409                                         $this->showForm($commentItem, $formTemplate, $destinationurl, $skinType);
410                                         $this->showComment($commentItem, $listTemplate, $maxToShow, $commentOrder, $skinType);
411                                 }
412                                 break;
413                 }
414         }
415
416         // }}}
417         // {{{ languageInclude()
418
419         /**
420          * Include language file
421          *
422          * @return void.
423          */
424         function languageInclude()
425         {
426                 $language = ereg_replace( '[\\|/]', '', getLanguageName());
427                 if (file_exists($this->getDirectory() . 'language/' . $language . '.php')) {
428                         include_once($this->getDirectory() . 'language/' . $language . '.php');
429                 } else {
430                         include_once($this->getDirectory() . 'language/english.php');
431                 }
432         }
433
434         // }}}
435         // {{{ updateTable()
436
437         /**
438          * Update database table
439          *
440          * @return void.
441          */
442         function updateTable()
443         {
444                 $sql = 'SELECT cnumber FROM ' . sql_table('comment') . ' ORDER BY cnumber';
445                 $res = sql_query($sql);
446                 $sql = 'REPLACE INTO ' . sql_table('plug_ezcomment2') . '(`comid`) VALUES (%d)';
447                 while ($cid = mysql_fetch_assoc($res)) {
448                         sql_query(sprintf($sql, $cid['cnumber']));
449                 }
450         }
451
452         // }}}
453         // {{{ plugOpenIDdoSkinVar()
454
455         /**
456          * Overwride NP_OpenId's doSkinVar()
457          * 
458          * @param  string
459          * @param  integer
460          * @return void.
461          */
462         function plugOpenIDdoSkinVar($skinType, $iid = 0)
463         {
464                 global $CONF, $manager, $member;
465                 if ($member->isLoggedIn()) return;
466                 $authOpenID   = $this->authOpenID;
467                 if (!$authOpenID) return;
468                 $externalauth = array ( 'source' => $authOpenID->getName() );
469                 $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
470                 if (isset($externalauth['result']) && $externalauth['result'] == true) return;
471                 $templateEngine     = $authOpenID->_getTemplateEngine();
472                 $aVars              = array();
473                 $aVars['PluginURL'] = $CONF['PluginURL'];
474                 if ($authOpenID->isLoggedin()) {
475                         // Loggedin
476                         if ($skinType == 'template') {
477                                 require_once 'cles/Template.php';
478                                 $templateDirectory           =  rtrim($this->getDirectory(), '/');
479                                 $templateEngine              =& new cles_Template($templateDirectory);
480                                 $templateEngine->defaultLang =  'english';
481                                 $aVars['itemid'] = intval($iid);
482                         }
483                         $nowURL             = 'http://' . serverVar("HTTP_HOST")
484                                                                 . serverVar("REQUEST_URI");
485                         $aVars['url']       = $authOpenID->getAdminURL() . 'rd.php?action=rd'
486                                                                 . '&url=' . urlencode($nowURL);
487                         $aVars['nick']      = $authOpenID->loggedinUser['nick'];
488                         $aVars['email']     = $authOpenID->loggedinUser['email'];
489                         $aVars['ts']        = $authOpenID->loggedinUser['ts'];
490                         $aVars['identity']  = $authOpenID->loggedinUser['identity'];
491                         $aVars['visible']   = $aVars['nick'] ? 'false' : 'true' ;
492                         $actionUrl          = parse_url($CONF['ActionURL']);
493                         $aVars['updateUrl'] = $actionUrl['path'];
494                         echo $templateEngine->fetchAndFill('yui',         $aVars, 'np_openid');
495                         echo $templateEngine->fetchAndFill('loggedin',    $aVars, 'np_openid');
496                         echo $templateEngine->fetchAndFill('form',        $aVars, 'np_openid');
497                 } elseif (!$authOpenID->isLoggedin()) {
498                         // Not loggedin
499                         $aVars['url']       = $authOpenID->getAdminURL() . 'rd.php?action=doauth'
500                                                             . '&return_url=' . urlencode(createItemLink(intval($iid)));
501                         echo $templateEngine->fetchAndFill('notloggedin', $aVars, 'np_openid');
502                 }
503         }
504
505         // }}}
506         // {{{ checkDestinationurl($destinationurl)
507
508         /**
509          * Destinationurl check
510          *
511          * @param  string
512          * @return string
513          */
514         function checkDestinationurl($destinationurl)
515         {
516                 if (stristr($destinationurl, 'action.php') || empty($destinationurl)) {
517                         if (stristr($destinationurl, 'action.php')) {
518                                 $logMessage = 'actionurl is not longer a parameter on commentform skinvars.'
519                                                         . ' Moved to be a global setting instead.';
520                                 ACTIONLOG::add(WARNING, $logMessage);
521                         }
522                         if ($catid) {
523                                 $linkparams['catid'] = intval($catid);
524                         }
525                         if ($manager->pluginInstalled('NP_MultipleCategories') && $subcatid) {
526                                 $linkparams['subcatid'] = intval($subcatid);
527                         }
528                         $destinationurl = createItemLink($commentItem->itemid, $linkparams);
529                 } else {
530                         $destinationurl = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $destinationurl);
531                 }
532                 return $destinationurl;
533         }
534
535         // }}}
536         // {{{ getCommentatorInfo()
537
538         /**
539          * Get commentator info.
540          *
541          * @return array
542          */
543         function getCommentatorInfo()
544         {
545                 global $CONF;
546                 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
547                 if (!$user) {
548                         $user = postVar('user');
549                 }
550                 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
551                 if (!$userid) {
552                         $userid = postVar('userid');
553                 }
554                 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
555                 if (!$email) {
556                         $email = postVar('email');
557                 }
558                 $body    = postVar('body');
559                 return array(
560                         $user,
561                         $userid,
562                         $email,
563                         $body
564                 );
565         }
566         // {{{ showForm()
567
568         /**
569          * Show comment form
570          *
571          * @param  object
572          * @param  string
573          * @param  string
574          * @param  string
575          * @return void.
576          */
577         function showForm($commentItem, $template, $destinationurl, $skinType)
578         {
579                 global $CONF, $manager, $member, $catid, $subcatid;
580                 $bid =  getBlogIDFromItemID($commentItem->itemid);
581                 $b   =& $manager->getBlog($bid);
582                 $b->readSettings();
583                 if (!$member->isLoggedIn() && !$b->commentsEnabled()) {
584                         return;
585                 }
586                 $destinationurl = $this->checkDestinationurl($destinationurl);
587                 list($user, $userid, $email, $body) = $this->getCommentatorInfo();
588
589                 $checked = cookieVar($CONF['CookiePrefix'] .'comment_user') ? 'checked="checked" ' : '';
590
591                 $formdata = array(
592                         'self'            => $this->_hsc(serverVar('REQUEST_URI')),
593                         'destinationurl'  => $this->_hsc($destinationurl),
594                         'actionurl'       => $this->_hsc($CONF['ActionURL']),
595                         'itemid'          => intval($commentItem->itemid),
596                         'user'            => $this->_hsc($user),
597                         'userid'          => $this->_hsc($userid),
598                         'email'           => $this->_hsc($email),
599                         'body'            => $this->_hsc($body),
600 //                      'membername'      => $this->_hsc($membername),
601                         'rememberchecked' => $checked
602                 );
603                 if ($skinType == 'item') {
604                         $formFlg = '_ITM';
605                 } else {
606                         $formFlg = '_IDX';
607                 }
608                 if ($member && $member->isLoggedIn()) {
609                         $formType = 'FORM_LOGGEDIN' . $formFlg;
610                         $loginMember = $member->createFromID($member->getID());
611                         $formdata['membername'] = $this->_hsc($loginMember->getDisplayName());
612                 } else {
613                         $formType = 'FORM_NOTLOGGEDIN' . $formFlg;
614                 }
615                 if ($this->authOpenID && ($skinType == 'item' || $this->numcalled == 0)) {
616                         $this->plugOpenIDdoSkinVar($skinType, intval($commentItem->itemid));
617                 }
618                 $contents   = $template[$formType];
619                 include_once($this->getDirectory() . 'EzCommentActions.php');
620                 $formAction =& new EzCommentFormActions($commentItem, $formdata, $loginMember);
621                 $parser     =& new PARSER($formAction->getAllowedActions(), $formAction);
622                 $parser->parse(&$contents);
623         }
624
625         // }}}
626         // {{{ showComment()
627
628         /**
629          * Show comments
630          *
631          * @param  object
632          * @param  string
633          * @param  string
634          * @param  string
635          * @param  string
636          * @return void.
637          */
638         function showComment($commentItem, $template, $maxToShow, $commentOrder, $skinType)
639         {
640                 global $manager, $member;
641                 $bid =  getBlogIDFromItemID($commentItem->itemid);
642                 $b   =& $manager->getBlog($bid);
643                 if (!$b->commentsEnabled()) return;
644                 if (!$maxToShow) {
645                         $maxToShow = $b->getMaxComments();
646                 }
647                 $itemActions =& new ITEMACTIONS($b);
648                 $itemActions->setCurrentItem($commentItem);
649                 $commentObj =& new COMMENTS($commentItem->itemid);
650                 $commentObj->setItemActions($itemActions);
651                 $commentObj->commentcount = $commentObj->amountComments();
652                 // create parser object & action handler
653                 include_once($this->getDirectory() . 'EzCommentActions.php');
654                 $actions =& new EzCommentActions($commentObj);
655                 $parser  =& new PARSER($actions->getAllowedActions(), $actions);
656                 $actions->setTemplate($template);
657                 $actions->setParser($parser);
658                 if ($commentObj->commentcount == 0) {
659                         $parser->parse($template['COMMENTS_NONE']);
660                         return 0;
661                 }
662                 $actions->setPostnum($commentObj->commentcount);
663                 if ($maxToShow && $maxToShow < $commentObj->commentcount && $commentOrder) {
664                         $startnum = $commentObj->commentcount - $maxToShow;
665                 } else {
666                         $startnum = 0;
667                 }
668                 $comments = $this->getComments($commentOrder, intval($commentItem->itemid), $maxToShow, $startnum);
669                 $viewnum  = mysql_num_rows($comments);
670                 $actions->setViewnum($viewnum);
671                 if ($this->getBlogOption($bid, 'secret') == 'yes') {
672                         $secret = $this->setSecretJudge($bid, $member, $b);
673                 }
674
675                 $templateType = '';
676                 if ($skinType == 'index') $templateType = '_IDX';
677                 $blogURL      = $b->getURL();
678                 $substitution = $this->getBlogOption($bid, 'secComment');
679                 
680                 $parser->parse($template['COMMENTS_HEADER' . $templateType]);
681
682                 while ($comment = mysql_fetch_assoc($comments)) {
683                         $comment['timestamp'] = strtotime($comment['ctime']);
684                         if ($secret) {
685                                         $comment = $this->JudgementCommentSecrets($comment, $secret, $blogURL, $substitution);
686                         }
687                         $actions->setCurrentComment($comment);
688                         $manager->notify('PreComment', array('comment' => &$comment));
689                         $parser->parse($template['COMMENTS_BODY' . $templateType]);
690                         $manager->notify('PostComment', array('comment' => &$comment));
691                 }
692
693                 $parser->parse($template['COMMENTS_FOOTER' . $templateType]);
694
695                 mysql_free_result($comments);
696
697         }
698
699         // }}}
700         // {{{ setSecretJudge($bid)
701
702         /**
703          * Setting for judgment of whether it's a comment of a secret.
704          *
705          * @param  intgre
706          * @param  object
707          * @param  object
708          * @return array
709          */
710         function setSecretJudge($bid, $member, $b)
711         {
712                 $memberLoggedin = $member->isLoggedin();
713                 $loginUser      = $member->getID();
714                 $blogAdmin      = $member->blogAdminRights($bid);
715                 $blogURL        = $b->getURL();
716                 $substitution   = $this->getBlogOption($bid, 'secComment');
717                 if ($this->authOpenID) {
718                         $openIDLoggedin = $this->authOpenID->isLoggedin();
719                         $openIDUser     = $this->authOpenID->loggedinUser['identity'];
720                 }
721                 return array(
722                         'memberLoggedin' => $memberLoggedin,
723                         'loginUser'      => $loginUser,
724                         'blogAdmin'      => $blogAdmin,
725                         'blogURL'        => $blogURL,
726                         'substitution'   => $substitution,
727                         'openIDLoggedin' => $openIDLoggedin,
728                         'openIDUser'     => $openIDUser,
729                 );
730         }
731
732         // }}}
733         // {{{ JudgementCommentSecrets($comment, $judge)
734
735         /**
736          * Comment is secret ?
737          *
738          * @param  array
739          * @param  array
740          * @param  string
741          * @param  string
742          * @return array
743          */
744         function JudgementCommentSecrets($comment, $judge, $blogURL, $substitution)
745         {
746                 if (!(($judge['memberLoggedin'] && ($judge['loginUser']  == intval($comment['identity']) || $blogAdmin)) ||
747                         ($judge['openIDLoggedin'] && $judge['openIDUser'] == $comment['identity'])) && $comment['secret']) {
748                                 $this->changeCommentSet($comment, $blogURL, $substitution);
749                         }
750                 return $comment;
751         }
752
753         // }}}
754         // {{{ changeCommentSet($comment, $blogURL, $substitution)
755
756         /**
757          * Change secret comment contents
758          *
759          * @param  array
760          * @param  string
761          * @param  string
762          * @return array
763          */
764         function changeCommentSet($comment, $blogURL, $substitution)
765         {
766                 $comment['body']     = $substitution;
767                 $comment['userid']   = $blogURL;
768                 $comment['memberid'] = 0;
769                 $comment['user']     = '#';
770                 $comment['email']    = '#';
771                 $comment['host']     = '127.0.0.1';
772                 $comment['ip']       = '127.0.0.1';
773                 return $comment;
774         }
775         // {{{ getComments($comment, $judge)
776
777         /**
778          * Change in the comment contents.
779          *
780          * @param  boolean
781          * @param  integre
782          * @param  integre
783          * @param  integre
784          * @return resouce
785          */
786         function getComments($commentOrder, $iid, $maxToShow, $startnum)
787         {
788                 $order = ($commentOrder) ? "DESC" : "ASC";
789                 $query = 'SELECT '
790                            . 'c.citem   as itemid, '
791                            . 'c.cnumber as commentid, '
792                            . 'c.cbody   as body, '
793                            . 'c.cuser   as user, '
794                            . 'c.cmail   as userid, '
795                            . 'c.cemail  as email, '
796                            . 'c.cmember as memberid, '
797                            . 'c.ctime, '
798                            . 'c.chost   as host, '
799                            . 'c.cip     as ip, '
800                            . 'c.cblog   as blogid, '
801                            . 's.comid   as cid, '
802                            . 's.secflg  as secret, '
803                            . 's.module  as modname, '
804                            . 's.userID  as identity '
805                            . ' FROM ' . sql_table('comment') . ' as c '
806                            . ' LEFT OUTER JOIN ' . sql_table('plug_ezcomment2') . ' as s '
807                            . ' p ON c.cnumber = s.comid '
808                            . ' WHERE c.citem = ' . intval($iid)
809                            . ' ORDER BY c.ctime '
810                            . $order;
811                 if ($maxToShow) {
812                         if ($order == "DESC") {
813                                 $query .=' LIMIT ' . intval($maxToShow);
814                         } else {
815                                 $query .=' LIMIT ' . intval($startnum) . ',' . intval($maxToShow);
816                         }
817                 }
818                 return sql_query($query);
819                 
820         }
821
822         // }}}
823         // {{{ getTemplateParts()
824
825         /**
826          * Comment form/list template via NP_znSpecialTemplateParts
827          *
828          * @return array
829          */
830         function getTemplateParts()
831         {
832                 $this->languageInclude();
833                 return array(
834                         'FORM_LOGGEDIN_IDX'    => _NP_EZCOMMENT2_FORM_LOGGEDIN_IDX, 
835                         'FORM_NOTLOGGEDIN_IDX' => _NP_EZCOMMENT2_FORM_NOTLOGGEDIN_IDX, 
836                         'FORM_LOGGEDIN_ITM'    => _NP_EZCOMMENT2_FORM_LOGGEDIN_ITM,
837                         'FORM_NOTLOGGEDIN_ITM' => _NP_EZCOMMENT2_FORM_NOTLOGGEDIN_ITM, 
838                         'COMMENTS_BODY_IDX'    => _NP_EZCOMMENT2_COMMENTS_BODY_IDX, 
839                         'COMMENTS_FOOTER_IDX'  => _NP_EZCOMMENT2_COMMENTS_FOOTER_IDX, 
840                         'COMMENTS_HEADER_IDX'  => _NP_EZCOMMENT2_COMMENTS_HEADER_IDX,
841                 );
842         }
843
844         // }}}
845         // {{{ _hsc()
846
847         /**
848          * HTML entity
849          *
850          * @param  string
851          * @return string
852          */
853         function _hsc($str)
854         {
855                 return htmlspecialchars($str, ENT_QUOTES, _CHARSET);
856         }
857         // }}}
858         
859 }
860
861
862