OSDN Git Service

MERGE: リビジョン1817。派生クラスからsetParser()メソッドを基底クラスであるBaseActionsに移動
[nucleus-jp/nucleus-next.git] / nucleus / libs / COMMENTACTIONS.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2009 The Nucleus Group
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 /**
13  * This class is used when parsing comment templates
14  *
15  * @license http://nucleuscms.org/license.txt GNU General Public License
16  * @copyright Copyright (C) 2002-2009 The Nucleus Group
17  * @version $Id: CommentActions.php 1626 2012-01-09 15:46:54Z sakamocchi $
18  */
19
20 class CommentActions extends BaseActions
21 {
22         /**
23          * CommentsActions::$commentsObj
24          * ref to COMMENTS object which is using this object to handle its templatevars
25          */
26         private $commentsObj;
27         
28         /**
29          * CommentsActions::$template
30          * template to use to parse the comments
31          */
32         private $template;
33         
34         /**
35          * CommentsActions::$currentComment
36          * comment currenlty being handled (mysql result assoc array; see Comments::showComments())
37          */
38         private $currentComment;
39         
40         /**
41          * CommentsActions::$defined_actions
42          * defined actions in this class
43          */
44         static private $defined_actions = array(
45                 'authtext',
46                 'blogid',
47                 'blogurl',
48                 'body',
49                 'commentcount',
50                 'commentid',
51                 'commentword',
52                 'date',
53                 'email',
54                 'excerpt',
55                 'host',
56                 'ip',
57                 'itemid',
58                 'itemlink',
59                 'itemtitle',
60                 'memberid',
61                 'plugin',
62                 'short',
63                 'time',
64                 'timestamp',
65                 'user',
66                 'useremail',
67                 'userid',
68                 'userlink',
69                 'userlinkraw',
70                 'userwebsite',
71                 'userwebsitelink'
72         );
73         
74         /**
75          * CommentActions::__construct()
76          * 
77          * @param       object  $comments       instance of Comments class
78          * @return      void
79          */
80         public function __construct(&$comments)
81         {
82                 // call constructor of superclass first
83                 parent::__construct();
84                 
85                 // reference to the comments object
86                 $this->setCommentsObj($comments);
87                 return;
88         }
89         
90         /**
91          * CommentActions::getDefinedActions()
92          * 
93          * @static
94          * @param       void
95          * @return array        actions array
96          */
97         static public function getDefinedActions()
98         {
99                 return array_merge(self::$defined_actions, parent::getDefinedActions());
100         }
101         
102         /**
103          * 
104          * CommentActions::setCommentsObj()
105          * 
106          * @param       object  $commentsObj    instance of Comments class
107          * @return      void
108          */
109         public function setCommentsObj(&$commentsObj)
110         {
111                 $this->commentsObj =& $commentsObj;
112                 return;
113         }
114         
115         /**
116          * CommentActions::setTemplate()
117          * 
118          * @param       array   $template       array includes templates
119          * @return      void
120          */
121         public function setTemplate($template)
122         {
123                 $this->template =& $template;
124                 return;
125         }
126         
127         /**
128          * CommentActions::setCurrentComment()
129          * Set $currentcommentid and $currentcommentarray
130          * 
131          * @param       array   $comment        associated array includes comment information
132          * @return      void
133          */
134         public function setCurrentComment(&$comment)
135         {
136                 global $currentcommentid, $currentcommentarray, $manager;
137                 
138                 if ( $comment['memberid'] != 0 )
139                 {
140                         if ( !array_key_exists('COMMENTS_AUTH', $this->template) )
141                         {
142                                 $comment['authtext'] = '';
143                         }
144                         else
145                         {
146                                 $comment['authtext'] = $this->template['COMMENTS_AUTH'];
147                         }
148                         
149                         $mem =& $manager->getMember($comment['memberid']);
150                         $comment['user'] = $mem->getDisplayName();
151                         
152                         if ( $mem->getURL() )
153                         {
154                                 $comment['userid'] = $mem->getURL();
155                         }
156                         else
157                         {
158                                 $comment['userid'] = $mem->getEmail();
159                         }
160                         
161                         $data = array(
162                                 'memberid'      => $comment['memberid'],
163                                 'name'          => $mem->getDisplayName(),
164                                 'extra'         => $this->commentsObj->itemActions->linkparams
165                         );
166                         
167                         $comment['userlinkraw'] = Link::create_link('member', $data);
168                 }
169                 else
170                 {
171                         // create smart links
172                         if ( !array_key_exists('userid', $comment) || !empty($comment['userid']) )
173                         {
174                                 if ( (i18n::strpos($comment['userid'], 'http://') === 0) || (i18n::strpos($comment['userid'], 'https://') === 0) )
175                                 {
176                                         $comment['userlinkraw'] = $comment['userid'];
177                                 }
178                                 else
179                                 {
180                                         $comment['userlinkraw'] = 'http://' . $comment['userid'];
181                                 }
182                         }
183                         else if ( NOTIFICATION::address_validation($comment['email']) )
184                         {
185                                 $comment['userlinkraw'] = 'mailto:' . $comment['email'];
186                         }
187                         else if ( NOTIFICATION::address_validation($comment['userid']) )
188                         {
189                                 $comment['userlinkraw'] = 'mailto:' . $comment['userid'];
190                         }
191                 }
192                 
193                 $this->currentComment =& $comment;
194                 $currentcommentid = $comment['commentid'];
195                 $currentcommentarray = $comment;
196                 return;
197         }
198         
199         /**
200          * CommentActions::parse_authtext()
201          * Parse templatevar authtext
202          * 
203          * @param       void
204          * @return      void
205          */
206         public function parse_authtext()
207         {
208                 if ( $this->currentComment['memberid'] != 0 )
209                 {
210                         $this->parser->parse($this->template['COMMENTS_AUTH']);
211                 }
212                 return;
213         }
214         
215         /**
216          * CommentActions::parse_blogid()
217          * Parse templatevar blogid
218          * 
219          * @param       void
220          * @return      void
221          */
222         public function parse_blogid() {
223                 echo $this->currentComment['blogid'];
224         }
225         
226         /**
227          * CommentActions::parse_blogurl()
228          * Parse templatevar blogurl
229          * 
230          * @param       void
231          * @return      void
232          */
233         public function parse_blogurl()
234         {
235                 global $manager;
236                 $blogid = getBlogIDFromItemID($this->commentsObj->itemid);
237                 $blog =& $manager->getBlog($blogid);
238                 echo $blog->getURL();
239                 return;
240         }
241         
242         /**
243          * CommentActions::parse_body()
244          * Parse templatevar body
245          * 
246          * @param       void
247          * @return      void
248          */
249         public function parse_body() {
250                 echo $this->highlight($this->currentComment['body']);
251                 return;
252         }
253         
254         /**
255          * CommentActions::parse_commentcount()
256          * Parse templatevar commentcount
257          * 
258          * @param       void
259          * @return      void
260          */
261         public function parse_commentcount()
262         {
263                 echo $this->commentsObj->commentcount;
264                 return;
265         }
266         
267         /**
268          * CommentActions::parse_commentid()
269          * Parse templatevar commentid
270          * 
271          * @param       void
272          * @return      void
273          */
274         public function parse_commentid()
275         {
276                 echo $this->currentComment['commentid'];
277                 return;
278         }
279         
280         /**
281          * CommentActions::parse_commentword()
282          * Parse templatevar commentword
283          * 
284          * @param       void
285          * @return      void
286          */
287         public function parse_commentword()
288         {
289                 if ( $this->commentsObj->commentcount == 1 )
290                 {
291                         echo $this->template['COMMENTS_ONE'];
292                 }
293                 else
294                 {
295                         echo $this->template['COMMENTS_MANY'];
296                 }
297                 return;
298         }
299         
300         /**
301          * CommentActions::parse_date()
302          * Parse templatevar date
303          * 
304          * @format      String  $format Date format according to PHP
305          * @return      void
306          */
307         public function parse_date($format = '')
308         {
309                 if ( $format !== '' )
310                 {
311                         /* do nothing */
312                         ;
313                 }
314                 else if ( !array_key_exists('FORMAT_DATE', $this->template) || $this->template['FORMAT_DATE'] === '' )
315                 {
316                         $format = '%X';
317                 }
318                 else
319                 {
320                         $format = $this->template['FORMAT_DATE'];
321                 }
322                 
323                 $offset = $this->commentsObj->itemActions->blog->getTimeOffset() * 3600;
324                 
325                 echo i18n::formatted_datetime($format, $this->currentComment['timestamp'], $offset);
326                 return;
327         }
328         
329         /**
330          * CommentActions::parse_excerpt()
331          * Parse templatevar email
332          * 
333          * @param       void
334          * @return      void
335          */
336         public function parse_email()
337         {
338                 $email = $this->currentComment['email'];
339                 $email = str_replace('@', ' (at) ', $email);
340                 $email = str_replace('.', ' (dot) ', $email);
341                 echo $email;
342                 return;
343         }
344         
345         /**
346          * CommentActions::parse_excerpt()
347          * Parse templatevar excerpt
348          * 
349          * @param       void
350          * @return      void
351          */
352         public function parse_excerpt()
353         {
354                 echo Entity::hen(Entity::shorten($this->currentComment['body'], 60, '...'));
355                 return;
356         }
357         
358         /**
359          * CommentActions::parse_host()
360          * Parse templatevar host
361          * 
362          * @param       void
363          * @return      void
364          */
365         public function parse_host()
366         {
367                 echo $this->currentComment['host'];
368                 return;
369         }
370         
371         /**
372          * CommentActions::parse_ip()
373          * Parse templatevar ip
374          * 
375          * @param       void
376          * @return      void
377          */
378         public function parse_ip()
379         {
380                 echo $this->currentComment['ip'];
381                 return;
382         }
383         
384         /**
385          * CommentActions::parse_itemid()
386          * Parse templatevar itemid
387          * 
388          * @param       void
389          * @return      void
390          */
391         public function parse_itemid()
392         {
393                 echo $this->commentsObj->itemid;
394                 return;
395         }
396         
397         /**
398          * CommentActions::parse_itemlink()
399          * Parse templatevar itemlink
400          * 
401          * @param       void
402          * @return      void
403          */
404         public function parse_itemlink()
405         {
406                 $data = array(
407                         'itemid'        => $this->commentsObj->itemid,
408                         'timestamp'     => $this->commentsObj->itemActions->currentItem['timestamp'],
409                         'title'         => $this->commentsObj->itemActions->currentItem['title'],
410                         'extra'         => $this->commentsObj->itemActions->linkparams
411                 );
412                 
413                 echo Link::create_link('item', $data);
414                 return;
415         }
416         
417         /**
418          * CommentActions::parse_itemtitle()
419          * Parse templatevar itemtitle
420          * 
421          * @param       integer $maxLength      maximum length for item title
422          * @return      void
423          */
424         public function parse_itemtitle($maxLength = 0)
425         {
426                 if ( $maxLength == 0 )
427                 {
428                         $this->commentsObj->itemActions->parse_title();
429                 }
430                 else
431                 {
432                         $this->commentsObj->itemActions->parse_syndicate_title($maxLength);
433                 }
434                 return;
435         }
436         
437         /**
438          * CommentActions::parse_memberid()
439          * Parse templatevar memberid
440          * 
441          * @param       void
442          * @return      void
443          */
444         public function parse_memberid()
445         {
446                 echo $this->currentComment['memberid'];
447                 return;
448         }
449         
450         /**
451          * CommentActions::parse_short()
452          * Parse templatevar short
453          * 
454          * @param       void
455          * @return      void
456          */
457         public function parse_short()
458         {
459                 $tmp = strtok($this->currentComment['body'], "\n");
460                 $tmp = str_replace('<br />', '', $tmp);
461                 echo $tmp;
462                 if ( $tmp != $this->currentComment['body'] )
463                 {
464                         $this->parser->parse($this->template['COMMENTS_CONTINUED']);
465                 }
466                 return;
467         }
468         
469         /**
470          * CommentActions::parse_time()
471          * Parse templatevar time
472          * 
473          * @param       string  $format datetime format referring to strftime() in PHP's built-in function
474          * @return      void
475          */
476         public function parse_time($format = '')
477         {
478                 if ( $format !== '' )
479                 {
480                         /* do nothing */
481                         ;
482                 }
483                 else if ( !array_key_exists('FORMAT_TIME', $this->template) || $this->template['FORMAT_TIME'] === '' )
484                 {
485                         $format = '%x';
486                 }
487                 else
488                 {
489                         $format = $this->template['FORMAT_TIME'];
490                 }
491                 
492                 echo i18n::formatted_datetime($format, $this->currentComment['timestamp']);
493                 return;
494         }
495         
496         /**
497          * CommentActions::parse_timestamp()
498          * Parse templatevar timestamp
499          * 
500          * @param       void
501          * @return      void
502          * 
503          */
504         public function parse_timestamp()
505         {
506                 echo $this->currentComment['timestamp'];
507                 return;
508         }
509         
510         /**
511          * CommentActions::parse_plugin()
512          * Executes a plugin templatevar
513          *
514          * @param       string  $pluginName     name of plugin (without the NP_)
515          * @param       extra parameters can be added
516          * @return      void
517          */
518         public function parse_plugin($pluginName)
519         {
520                 global $manager;
521                 
522                 // only continue when the plugin is really installed
523                 if ( !$manager->pluginInstalled("NP_{$pluginName}") )
524                 {
525                         return;
526                 }
527                 
528                 $plugin =& $manager->getPlugin("NP_{$pluginName}");
529                 if ( !$plugin )
530                 {
531                         return;
532                 }
533                 
534                 // get arguments
535                 $params = func_get_args();
536                 
537                 // remove plugin name
538                 array_shift($params);
539                 
540                 // pass info on current item and current comment as well
541                 $params = array_merge(array(&$this->currentComment), $params);
542                 $params = array_merge(array(&$this->commentsObj->itemActions->currentItem), $params);
543                 
544                 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);
545                 return;
546         }
547         
548         /**
549          * CommentActions::parse_user()
550          * Parse templatevar user
551          * 
552          * @param       string  $mode   realname or else
553          * @return      void
554          */
555         public function parse_user($mode = '')
556         {
557                 global $manager;
558                 
559                 if ( $mode == 'realname' && $this->currentComment['memberid'] > 0 )
560                 {
561                         $member =& $manager->getMember($this->currentComment['memberid']);
562                         echo $member->getRealName();
563                 }
564                 else
565                 {
566                         echo Entity::hsc($this->currentComment['user']);
567                 }
568                 return;
569         }
570         
571         /**
572          * CommentActions::parse_useremail()
573          * Output mail address
574          * 
575          * @param       void
576          * @return      void
577          */
578         public function parse_useremail() {
579                 global $manager;
580                 if ( $this->currentComment['memberid'] > 0 )
581                 {
582                         $member =& $manager->getMember($this->currentComment['memberid']);
583                         
584                         if ( $member->email != '' )
585                         {
586                                 echo $member->email;
587                         }
588                 }
589                 else
590                 {
591                         if ( NOTIFICATION::address_validation($this->currentComment['email']) )
592                         {
593                                 echo $this->currentComment['email'];
594                         }
595                         elseif ( NOTIFICATION::address_validation($this->currentComment['userid']) )
596                         {
597                                 echo $this->currentComment['userid'];
598                         }
599                 }
600                 return;
601         }
602         
603         /**
604          * CommentActions::parse_userid()
605          * Parse templatevar userid
606          * 
607          * @param       void
608          * @return      void
609          */
610         public function parse_userid()
611         {
612                 echo $this->currentComment['userid'];
613                 return;
614         }
615         
616         /**
617          * CommentActions::parse_userlink()
618          * Parse templatevar userlink
619          * 
620          * @param       void
621          * @return      void
622          */
623         public function parse_userlink()
624         {
625                 if ( $this->currentComment['userlinkraw'] )
626                 {
627                         echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
628                 }
629                 else
630                 {
631                         echo $this->currentComment['user'];
632                 }
633                 return;
634         }
635         
636         /**
637          * CommentActions::parse_userlinkraw()
638          * Parse templatevar userlinkraw
639          * 
640          * @param       void
641          * @return      void
642          */
643         public function parse_userlinkraw()
644         {
645                 echo $this->currentComment['userlinkraw'];
646                 return;
647         }
648         
649         /**
650          * CommentActions::parse_userwebsite()
651          * Parse templatevar userwebsite
652          * 
653          * @param       void
654          * @return      void
655          */
656         public function parse_userwebsite()
657         {
658                 if ( !(i18n::strpos($this->currentComment['userlinkraw'], 'http://') === false) )
659                 {
660                         echo $this->currentComment['userlinkraw'];
661                 }
662                 return;
663         }
664         
665         /**
666          * CommentActions::parse_userwebsitelink()
667          * Parse templatevar userwebsitelink
668          * 
669          * @param       void
670          * @return      void
671          */
672         public function parse_userwebsitelink()
673         {
674                 if ( !(i18n::strpos($this->currentComment['userlinkraw'], 'http://') === false) )
675                 {
676                         echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
677                 }
678                 else
679                 {
680                         echo $this->currentComment['user'];
681                 }
682                 return;
683         }
684         
685         /**
686          * CommentActions::checkCondition()
687          * Checks conditions for if statements
688          *
689          * @param       string  $field  type of <%if%>
690          * @param       string  $name   property of field
691          * @param       string  $value  value of property
692          * @return      boolean
693          */
694         protected function checkCondition($field, $name='', $value = '') {
695                 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
696                 $condition = 0;
697                 switch ( $field )
698                 {
699                         case 'category':
700                                 $condition = ($blog && $this->ifCategory($name,$value));
701                                 break;
702                         case 'itemcategory':
703                                 $condition = ($this->ifItemCategory($name,$value));
704                                 break;
705                         case 'blogsetting':
706                                 $condition = ($blog && ($blog->getSetting($name) == $value));
707                                 break;
708                         case 'itemblogsetting':
709                                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));
710                                 $condition = ($b && ($b->getSetting($name) == $value));
711                                 break;
712                         case 'loggedin':
713                                 $condition = $member->isLoggedIn();
714                                 break;
715                         case 'onteam':
716                                 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
717                                 break;
718                         case 'admin':
719                                 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
720                                 break;
721                         case 'author':
722                                 $condition = ($this->ifAuthor($name,$value));
723                                 break;
724                         case 'hasplugin':
725                                 $condition = $this->ifHasPlugin($name, $value);
726                                 break;
727                         default:
728                                 $condition = $manager->pluginInstalled('NP_' . $field) && $this->ifPlugin($field, $name, $value);
729                         break;
730                 }
731                 return $condition;
732         }
733         
734         /**
735          * CommentActions::ifCategory()
736          * Different checks for a category
737          * 
738          * @param       string  $key    key of category
739          * @param       string  $value  value for key of category
740          * @return      boolean
741          */
742         private function ifCategory($key = '', $value = '')
743         {
744                 global $blog, $catid;
745                 
746                 // when no parameter is defined, just check if a category is selected
747                 if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
748                 {
749                         return $blog->isValidCategory($catid);
750                 }
751                 
752                 // check category name
753                 if ( $key == 'catname' )
754                 {
755                         $value = $blog->getCategoryIdFromName($value);
756                         if ($value == $catid)
757                         return $blog->isValidCategory($catid);
758                 }
759                 
760                 // check category id
761                 if ( ($key == 'catid') && ($value == $catid) )
762                 {
763                         return $blog->isValidCategory($catid);
764                 }
765                 return FALSE;
766         }
767         
768         /**
769          * CommentActions::ifAuthor()
770          * Different checks for an author
771          *
772          * @param       string  $key    key of data for author
773          * @param       string  $value  value of data for author
774          * @return      boolean correct or not
775          */
776         private function ifAuthor($key = '', $value = '')
777         {
778                 global $member, $manager;
779                 
780                 if ( $this->currentComment['memberid'] == 0 )
781                 {
782                         return FALSE;
783                 }
784                 
785                 $mem =& $manager->getMember($this->currentComment['memberid']);
786                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));
787                 $citem =& $manager->getItem($this->currentComment['itemid'], 1, 1);
788                 
789                 // when no parameter is defined, just check if item author is current visitor
790                 if (($key != 'isadmin' && $key != 'name' && $key != 'isauthor' && $key != 'isonteam')) {
791                         return (intval($member->getID()) > 0 && intval($member->getID()) == intval($citem['authorid']));
792                 }
793                 
794                 // check comment author name
795                 if ( $key == 'name' )
796                 {
797                         $value = trim(strtolower($value));
798                         if ( $value == '' )
799                         {
800                                 return FALSE;
801                         }
802                         if ( $value == strtolower($mem->getDisplayName()) )
803                         {
804                                 return TRUE;
805                         }
806                 }
807                 
808                 // check if comment author is admin
809                 if ( $key == 'isadmin' )
810                 {
811                         $blogid = intval($b->getID());
812                         if ( $mem->isAdmin() )
813                         {
814                                 return TRUE;
815                         }
816                         return $mem->isBlogAdmin($blogid);
817                 }
818                 
819                 // check if comment author is item author
820                 if ( $key == 'isauthor' )
821                 {
822                         return (intval($citem['authorid']) == intval($this->currentComment['memberid']));
823                 }
824                 
825                 // check if comment author is on team
826                 if ( $key == 'isonteam' )
827                 {
828                         return $mem->teamRights(intval($b->getID()));
829                 }
830                 return FALSE;
831         }
832         
833         /**
834          * CommentActions::ifItemCategory()
835          * Different checks for a category
836          *
837          * @param       string  $key    key of data for category to which item belongs
838          * @param       string  $value  value of data for category to which item belongs
839          * @return boolean      correct or not
840          */
841         private function ifItemCategory($key = '', $value = '')
842         {
843                 global $catid, $manager;
844         
845                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));
846                 $citem =& $manager->getItem($this->currentComment['itemid'],1,1);
847                 $icatid = $citem['catid'];
848         
849                 // when no parameter is defined, just check if a category is selected
850                 if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
851                 {
852                         return $b->isValidCategory($icatid);
853                 }
854         
855                 // check category name
856                 if ( $key == 'catname' )
857                 {
858                         $value = $b->getCategoryIdFromName($value);
859                         if ( $value == $icatid )
860                         {
861                                 return $b->isValidCategory($icatid);
862                         }
863                 }
864         
865                 // check category id
866                 if ( ($key == 'catid') && ($value == $icatid) )
867                 {
868                         return $b->isValidCategory($icatid);
869                 }
870                 return FALSE;
871         }
872         
873         /**
874          * CommentActions::ifOnTeam()
875          * Checks if a member is on the team of a blog and return his rights
876          * 
877          * @param       string  $blogName       name of weblog
878          * @return      boolean correct or not
879          */
880         private function ifOnTeam($blogName = '')
881         {
882                 global $blog, $member, $manager;
883                 
884                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));
885                 
886                 // when no blog found
887                 if ( ($blogName == '') && (!is_object($b)) )
888                 {
889                         return 0;
890                 }
891                 
892                 // explicit blog selection
893                 if ( $blogName != '' )
894                 {
895                         $blogid = getBlogIDFromName($blogName);
896                 }
897                 
898                 // use current blog
899                 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
900                 {
901                         $blogid = $b->getID();
902                 }
903                 
904                 return $member->teamRights($blogid);
905         }
906         
907         /**
908          * CommentActions::ifAdmin()
909          * Checks if a member is admin of a blog
910          * 
911          * @param       string  $blogName       name of weblog
912          * @return      boolean correct or not
913          */
914         private function ifAdmin($blogName = '')
915         {
916                 global $blog, $member, $manager;
917                 
918                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));
919                 
920                 // when no blog found
921                 if ( ($blogName == '') && (!is_object($b)) )
922                 {
923                         return 0;
924                 }
925                 
926                 // explicit blog selection
927                 if ( $blogName != '' )
928                 {
929                         $blogid = getBlogIDFromName($blogName);
930                 }
931                 
932                 // use current blog
933                 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
934                 {
935                         $blogid = $b->getID();
936                 }
937                 
938                 return $member->isBlogAdmin($blogid);
939         }
940         
941         /**
942          * CommentActions::ifHasPlugin()
943          *      hasplugin,PlugName
944          *         -> checks if plugin exists
945          *      hasplugin,PlugName,OptionName
946          *         -> checks if the option OptionName from plugin PlugName is not set to 'no'
947          *      hasplugin,PlugName,OptionName=value
948          *         -> checks if the option OptionName from plugin PlugName is set to value
949          *
950          * @param       string  $name   name of plugin
951          * @param       string  $value  key (and value) of plugin option
952          * @return      boolean correct or not
953          */
954         private function ifHasPlugin($name, $value)
955         {
956                 global $manager;
957                 $condition = FALSE;
958                 
959                 // (pluginInstalled method won't write a message in the actionlog on failure)
960                 if ( $manager->pluginInstalled('NP_'.$name) )
961                 {
962                         $plugin =& $manager->getPlugin("NP_{$name}");
963                         if ( $plugin != NULL )
964                         {
965                                 if ( $value == "" )
966                                 {
967                                         $condition = true;
968                                 }
969                                 else
970                                 {
971                                         list($name2, $value2) = preg_split('#=#', $value, 2);
972                                         if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
973                                         {
974                                                 $condition = true;
975                                         }
976                                         else if ( $plugin->getOption($name2) == $value2 )
977                                         {
978                                                 $condition = true;
979                                         }
980                                 }
981                         }
982                 }
983                 return $condition;
984         }
985         
986         /**
987          * CommentActions::ifPlugin()
988          * Checks if a plugin exists and call its doIf function
989          * 
990          * @param       string  $name   name of plugin
991          * @param       string  $key    key of plugin option
992          * @param       string  $value  value of plugin option
993          * @return      boolean callback output from plugin
994          */
995         private function ifPlugin($name, $key = '', $value = '')
996         {
997                 global $manager;
998                 
999                 $plugin =& $manager->getPlugin("NP_{$name}");
1000                 if ( !$plugin )
1001                 {
1002                         return;
1003                 }
1004                 
1005                 $params = func_get_args();
1006                 array_shift($params);
1007                 
1008                 return call_user_func_array(array(&$plugin, 'doIf'), $params);
1009         }
1010 }