OSDN Git Service

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