OSDN Git Service

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