OSDN Git Service

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