OSDN Git Service

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