OSDN Git Service

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