OSDN Git Service

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