OSDN Git Service

FIX:条件判定の否定演算子が二重に記述されていたためmemberテーブルの値が不正に書き換えられてしまう不具合を修正
[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-2012 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-2012 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         // ref to COMMENTS object which is using this object to handle\r
24         // its templatevars\r
25         var $commentsObj;\r
26 \r
27         // template to use to parse the comments\r
28         var $template;\r
29 \r
30         // comment currenlty being handled (mysql result assoc array; see Comments::showComments())\r
31         var $currentComment;\r
32 \r
33         function __construct(&$comments) {\r
34                 // call constructor of superclass first\r
35                 $this->BaseActions();\r
36 \r
37                 // reference to the comments object\r
38                 $this->setCommentsObj($comments);\r
39         }\r
40 \r
41         function getDefinedActions() {\r
42                 return array(\r
43                         'blogurl',\r
44                         'commentcount',\r
45                         'commentword',\r
46                         'email',\r
47                         'itemlink',\r
48                         'itemid',\r
49                         'itemtitle',\r
50                         'date',\r
51                         'time',\r
52                         'commentid',\r
53                         'body',\r
54                         'memberid',\r
55                         'timestamp',\r
56                         'host',\r
57                         'ip',\r
58                         'blogid',\r
59                         'authtext',\r
60                         'user',\r
61                         'userid',\r
62                         'userlinkraw',\r
63                         'userlink',\r
64                         'useremail',\r
65                         'userwebsite',\r
66                         'userwebsitelink',\r
67                         'excerpt',\r
68                         'short',\r
69                         'skinfile',\r
70                         'set',\r
71                         'plugin',\r
72                         'include',\r
73                         'phpinclude',\r
74                         'parsedinclude',\r
75                         'if',\r
76                         'else',\r
77                         'endif',\r
78                         'elseif',\r
79                         'ifnot',\r
80                         'elseifnot'\r
81                 );\r
82         }\r
83 \r
84         function setParser(&$parser) {\r
85                 $this->parser =& $parser;\r
86         }\r
87 \r
88         function setCommentsObj(&$commentsObj) {\r
89                 $this->commentsObj =& $commentsObj;\r
90         }\r
91 \r
92         function setTemplate($template) {\r
93                 $this->template =& $template;\r
94         }\r
95         \r
96         /**\r
97          * CommentActions::setCurrentComment()\r
98          * Set $currentcommentid and $currentcommentarray\r
99          * \r
100          * @param       Array   $comment        array with comment elements\r
101          * @return      void\r
102          * \r
103          */\r
104         function setCurrentComment(&$comment)\r
105         {\r
106                 global $currentcommentid, $currentcommentarray, $manager;\r
107                 \r
108                 if ( $comment['memberid'] != 0 )\r
109                 {\r
110                         if ( !array_key_exists('COMMENTS_AUTH', $this->template) )\r
111                         {\r
112                                 $comment['authtext'] = '';\r
113                         }\r
114                         else\r
115                         {\r
116                                 $comment['authtext'] = $this->template['COMMENTS_AUTH'];\r
117                         }\r
118                         \r
119                         $mem =& $manager->getMember($comment['memberid']);\r
120                         $comment['user'] = $mem->getDisplayName();\r
121                         \r
122                         if ( $mem->getURL() )\r
123                         {\r
124                                 $comment['userid'] = $mem->getURL();\r
125                         }\r
126                         else\r
127                         {\r
128                                 $comment['userid'] = $mem->getEmail();\r
129                         }\r
130                         \r
131                         $comment['userlinkraw'] = Link::create_link(\r
132                                                                                 'member',\r
133                                                                                 array(\r
134                                                                                         'memberid' => $comment['memberid'],\r
135                                                                                         'name' => $mem->getDisplayName(),\r
136                                                                                         'extra' => $this->commentsObj->itemActions->linkparams\r
137                                                                                 )\r
138                                                                         );\r
139                 }\r
140                 else\r
141                 {\r
142                         // create smart links\r
143                         if ( !array_key_exists('userid', $comment) || !empty($comment['userid']) )\r
144                         {\r
145                                 if ( (i18n::strpos($comment['userid'], 'http://') === 0) || (i18n::strpos($comment['userid'], 'https://') === 0) )\r
146                                 {\r
147                                         $comment['userlinkraw'] = $comment['userid'];\r
148                                 }\r
149                                 else\r
150                                 {\r
151                                         $comment['userlinkraw'] = 'http://' . $comment['userid'];\r
152                                 }\r
153                         }\r
154                         else if ( NOTIFICATION::address_validation($comment['email']) )\r
155                         {\r
156                                 $comment['userlinkraw'] = 'mailto:' . $comment['email'];\r
157                         }\r
158                         else if ( NOTIFICATION::address_validation($comment['userid']) )\r
159                         {\r
160                                 $comment['userlinkraw'] = 'mailto:' . $comment['userid'];\r
161                         }\r
162                 }\r
163                 \r
164                 $this->currentComment =& $comment;\r
165                 $currentcommentid = $comment['commentid'];\r
166                 $currentcommentarray = $comment;\r
167                 return;\r
168         }\r
169 \r
170         /**\r
171          * Parse templatevar authtext\r
172          */\r
173         function parse_authtext() {\r
174                 if ($this->currentComment['memberid'] != 0)\r
175                         $this->parser->parse($this->template['COMMENTS_AUTH']);\r
176         }\r
177 \r
178         /**\r
179          * Parse templatevar blogid\r
180          */\r
181         function parse_blogid() {\r
182                 echo $this->currentComment['blogid'];\r
183         }\r
184 \r
185         /**\r
186          * Parse templatevar blogurl\r
187          */\r
188         function parse_blogurl() {\r
189                 global $manager;\r
190                 $blogid = getBlogIDFromItemID($this->commentsObj->itemid);\r
191                 $blog =& $manager->getBlog($blogid);\r
192                 echo $blog->getURL();\r
193         }\r
194 \r
195         /**\r
196          * Parse templatevar body\r
197          */\r
198         function parse_body() {\r
199                 echo $this->highlight($this->currentComment['body']);\r
200         }\r
201 \r
202         /**\r
203          * Parse templatevar commentcount\r
204          */\r
205         function parse_commentcount() {\r
206                         echo $this->commentsObj->commentcount;\r
207         }\r
208 \r
209         /**\r
210          * Parse templatevar commentid\r
211          */\r
212         function parse_commentid() {\r
213                 echo $this->currentComment['commentid'];\r
214         }\r
215 \r
216         /**\r
217          * Parse templatevar commentword\r
218          */\r
219         function parse_commentword() {\r
220                 if ($this->commentsObj->commentcount == 1)\r
221                         echo $this->template['COMMENTS_ONE'];\r
222                 else\r
223                         echo $this->template['COMMENTS_MANY'];\r
224         }\r
225         \r
226         /**\r
227          * CommentActions::parse_date()\r
228          * Parse templatevar date\r
229          * \r
230          * @format      String  $format Date format according to PHP\r
231          * @return      void\r
232          * \r
233          */\r
234         function parse_date($format = '')\r
235         {\r
236                 if ( $format !== '' )\r
237                 {\r
238                         /* do nothing */\r
239                         ;\r
240                 }\r
241                 else if ( !array_key_exists('FORMAT_DATE', $this->template) || $this->template['FORMAT_DATE'] === '' )\r
242                 {\r
243                         $format = '%X';\r
244                 }\r
245                 else\r
246                 {\r
247                         $format = $this->template['FORMAT_DATE'];\r
248                 }\r
249                 \r
250                 $offset = $this->commentsObj->itemActions->blog->getTimeOffset() * 3600;\r
251                 \r
252                 echo i18n::formatted_datetime($format, $this->currentComment['timestamp'], $offset);\r
253                 return;\r
254         }\r
255         \r
256         /**\r
257          * Parse templatevar email\r
258          */\r
259         function parse_email() {\r
260                 $email = $this->currentComment['email'];\r
261                 $email = str_replace('@', ' (at) ', $email);\r
262                 $email = str_replace('.', ' (dot) ', $email);\r
263                 echo $email;\r
264         }\r
265 \r
266         /**\r
267          * CommentActions::parse_excerpt()\r
268          * Parse templatevar excerpt\r
269          * \r
270          * @param       Void\r
271          * @return      String  templatevar excerpt\r
272          */\r
273         function parse_excerpt()\r
274         {\r
275                 echo Entity::hen(Entity::shorten($this->currentComment['body'], 60, '...'));\r
276         }\r
277 \r
278         /**\r
279          * Parse templatevar host\r
280          */\r
281         function parse_host() {\r
282                 echo $this->currentComment['host'];\r
283         }\r
284 \r
285         /**\r
286          * Parse templatevar ip\r
287          */\r
288         function parse_ip() {\r
289                 echo $this->currentComment['ip'];\r
290         }\r
291 \r
292         /**\r
293          * Parse templatevar itemid\r
294          */\r
295         function parse_itemid() {\r
296                 echo $this->commentsObj->itemid;\r
297         }\r
298         \r
299         /**\r
300          * CommentActions::parse_itemlink()\r
301          * Parse templatevar itemlink\r
302          * \r
303          * @param       Void\r
304          * @return      Void\r
305          */\r
306         function parse_itemlink()\r
307         {\r
308                 echo Link::create_link(\r
309                         'item',\r
310                         array(\r
311                                 'itemid' => $this->commentsObj->itemid,\r
312                                 'timestamp' => $this->commentsObj->itemActions->currentItem->timestamp,\r
313                                 'title' => $this->commentsObj->itemActions->currentItem->title,\r
314                                 'extra' => $this->commentsObj->itemActions->linkparams\r
315                         )\r
316                 );\r
317                 return;\r
318         }\r
319         \r
320         /**\r
321          * Parse templatevar itemtitle\r
322          */\r
323         function parse_itemtitle($maxLength = 0) {\r
324                 if ($maxLength == 0)\r
325                         $this->commentsObj->itemActions->parse_title();\r
326                 else\r
327                         $this->commentsObj->itemActions->parse_syndicate_title($maxLength);\r
328         }\r
329 \r
330         /**\r
331          * Parse templatevar memberid\r
332          */\r
333         function parse_memberid() {\r
334                 echo $this->currentComment['memberid'];\r
335         }\r
336 \r
337         /**\r
338          * Parse templatevar short\r
339          */\r
340         function parse_short() {\r
341                 $tmp = strtok($this->currentComment['body'],"\n");\r
342                 $tmp = str_replace('<br />','',$tmp);\r
343                 echo $tmp;\r
344                 if ($tmp != $this->currentComment['body'])\r
345                         $this->parser->parse($this->template['COMMENTS_CONTINUED']);\r
346         }\r
347         \r
348         /**\r
349          * CommentActions::parse_time()\r
350          * Parse templatevar time\r
351          * \r
352          * @param       string  $format datetime format referring to strftime() in PHP's built-in function\r
353          * @return      void\r
354          * \r
355          */\r
356         function parse_time($format = '')\r
357         {\r
358                 if ( $format === '' )\r
359                 {\r
360                         /* do nothing */\r
361                         ;\r
362                 }\r
363                 else if ( !array_key_exists('FORMAT_TIME', $this->template) || $this->template['FORMAT_TIME'] === '' )\r
364                 {\r
365                         $format = '%x';\r
366                 }\r
367                 else\r
368                 {\r
369                         $format = $this->template['FORMAT_TIME'];\r
370                 }\r
371                 \r
372                 echo i18n::formatted_datetime($format, $this->currentComment['timestamp']);\r
373                 return;\r
374         }\r
375         \r
376         /**\r
377          * Parse templatevar timestamp\r
378          */\r
379         function parse_timestamp() {\r
380                 echo $this->currentComment['timestamp'];\r
381         }\r
382 \r
383         /**\r
384           * Executes a plugin templatevar\r
385           *\r
386           * @param pluginName name of plugin (without the NP_)\r
387           *\r
388           * extra parameters can be added\r
389           */\r
390         function parse_plugin($pluginName) {\r
391                 global $manager;\r
392 \r
393                 // only continue when the plugin is really installed\r
394                 if (!$manager->pluginInstalled('NP_' . $pluginName))\r
395                         return;\r
396 \r
397                 $plugin =& $manager->getPlugin('NP_' . $pluginName);\r
398                 if (!$plugin) return;\r
399 \r
400                 // get arguments\r
401                 $params = func_get_args();\r
402 \r
403                 // remove plugin name\r
404                 array_shift($params);\r
405 \r
406                 // pass info on current item and current comment as well\r
407                 $params = array_merge(array(&$this->currentComment),$params);\r
408                 $params = array_merge(array(&$this->commentsObj->itemActions->currentItem),$params);\r
409 \r
410                 call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);\r
411         }\r
412 \r
413         /**\r
414          * Parse templatevar user\r
415          * @param string $mode\r
416          */\r
417         function parse_user($mode = '')\r
418         {\r
419                 global $manager;\r
420 \r
421                 if ( $mode == 'realname' && $this->currentComment['memberid'] > 0 )\r
422                 {\r
423                         $member =& $manager->getMember($this->currentComment['memberid']);\r
424                         echo $member->getRealName();\r
425                 }\r
426                 else\r
427                 {\r
428                         echo Entity::hsc($this->currentComment['user']);\r
429                 }\r
430         }\r
431 \r
432         /**\r
433          * CommentActions::parse_useremail()\r
434          * Output mail address\r
435          * \r
436          * @param       void\r
437          * @return      void\r
438          */\r
439         function parse_useremail() {\r
440                 global $manager;\r
441                 if ( $this->currentComment['memberid'] > 0 )\r
442                 {\r
443                         $member =& $manager->getMember($this->currentComment['memberid']);\r
444                         \r
445                         if ( $member->email != '' )\r
446                         {\r
447                                 echo $member->email;\r
448                         }\r
449                 }\r
450                 else\r
451                 {\r
452                         if ( NOTIFICATION::address_validation($this->currentComment['email']) )\r
453                         {\r
454                                 echo $this->currentComment['email'];\r
455                         }\r
456                         elseif ( NOTIFICATION::address_validation($this->currentComment['userid']) )\r
457                         {\r
458                                 echo $this->currentComment['userid'];\r
459                         }\r
460                 }\r
461                 return;\r
462         }\r
463         \r
464         /**\r
465          * Parse templatevar userid\r
466          */\r
467         function parse_userid() {\r
468                         echo $this->currentComment['userid'];\r
469         }\r
470 \r
471 \r
472         /**\r
473          * Parse templatevar userlink\r
474          */\r
475         function parse_userlink() {\r
476                 if ($this->currentComment['userlinkraw']) {\r
477                         echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';\r
478                 } else {\r
479                         echo $this->currentComment['user'];\r
480                 }\r
481         }\r
482 \r
483         /**\r
484          * Parse templatevar userlinkraw\r
485          */\r
486         function parse_userlinkraw() {\r
487                 echo $this->currentComment['userlinkraw'];\r
488         }\r
489 \r
490         /**\r
491          * Parse templatevar userwebsite\r
492          */\r
493         function parse_userwebsite() {\r
494                 if (!(i18n::strpos($this->currentComment['userlinkraw'], 'http://') === false))\r
495                         echo $this->currentComment['userlinkraw'];\r
496         }\r
497 \r
498         /**\r
499          * Parse templatevar userwebsitelink\r
500          */\r
501         function parse_userwebsitelink() {\r
502                 if (!(i18n::strpos($this->currentComment['userlinkraw'], 'http://') === false)) {\r
503                         echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';\r
504                 } else {\r
505                         echo $this->currentComment['user'];\r
506                 }\r
507         }\r
508 \r
509         // function to enable if-else-elseif-elseifnot-ifnot-endif to comment template fields\r
510 \r
511         /**\r
512          * Checks conditions for if statements\r
513          *\r
514          * @param string $field type of <%if%>\r
515          * @param string $name property of field\r
516          * @param string $value value of property\r
517          */\r
518         function checkCondition($field, $name='', $value = '') {\r
519                 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;\r
520 \r
521                 $condition = 0;\r
522                 switch($field) {\r
523                         case 'category':\r
524                                 $condition = ($blog && $this->_ifCategory($name,$value));\r
525                                 break;\r
526                         case 'itemcategory':\r
527                                 $condition = ($this->_ifItemCategory($name,$value));\r
528                                 break;\r
529                         case 'blogsetting':\r
530                                 $condition = ($blog && ($blog->getSetting($name) == $value));\r
531                                 break;\r
532                         case 'itemblogsetting':\r
533                                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));\r
534                                 $condition = ($b && ($b->getSetting($name) == $value));\r
535                                 break;\r
536                         case 'loggedin':\r
537                                 $condition = $member->isLoggedIn();\r
538                                 break;\r
539                         case 'onteam':\r
540                                 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);\r
541                                 break;\r
542                         case 'admin':\r
543                                 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);\r
544                                 break;\r
545                         case 'author':\r
546                                 $condition = ($this->_ifAuthor($name,$value));\r
547                                 break;\r
548 /*                      case 'nextitem':\r
549                                 $condition = ($itemidnext != '');\r
550                                 break;\r
551                         case 'previtem':\r
552                                 $condition = ($itemidprev != '');\r
553                                 break;\r
554                         case 'archiveprevexists':\r
555                                 $condition = ($archiveprevexists == true);\r
556                                 break;\r
557                         case 'archivenextexists':\r
558                                 $condition = ($archivenextexists == true);\r
559                                 break;\r
560                         case 'skintype':\r
561                                 $condition = ($name == $this->skintype);\r
562                                 break; */\r
563                         case 'hasplugin':\r
564                                 $condition = $this->_ifHasPlugin($name, $value);\r
565                                 break;\r
566                         default:\r
567                                 $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);\r
568                                 break;\r
569                 }\r
570                 return $condition;\r
571         }\r
572 \r
573         /**\r
574          *  Different checks for a category\r
575          */\r
576         function _ifCategory($name = '', $value='') {\r
577                 global $blog, $catid;\r
578 \r
579                 // when no parameter is defined, just check if a category is selected\r
580                 if (($name != 'catname' && $name != 'catid') || ($value == ''))\r
581                         return $blog->isValidCategory($catid);\r
582 \r
583                 // check category name\r
584                 if ($name == 'catname') {\r
585                         $value = $blog->getCategoryIdFromName($value);\r
586                         if ($value == $catid)\r
587                                 return $blog->isValidCategory($catid);\r
588                 }\r
589 \r
590                 // check category id\r
591                 if (($name == 'catid') && ($value == $catid))\r
592                         return $blog->isValidCategory($catid);\r
593 \r
594                 return false;\r
595         }\r
596 \r
597 \r
598         /**\r
599          *  Different checks for an author\r
600          */\r
601         function _ifAuthor($name = '', $value='') {\r
602                 global $member, $manager;\r
603 \r
604                 if ($this->currentComment['memberid'] == 0) return false;\r
605 \r
606                 $mem =& $manager->getMember($this->currentComment['memberid']);\r
607                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));\r
608                 $citem =& $manager->getItem($this->currentComment['itemid'],1,1);\r
609 \r
610                 // when no parameter is defined, just check if item author is current visitor\r
611                 if (($name != 'isadmin' && $name != 'name' && $name != 'isauthor' && $name != 'isonteam')) {\r
612                         return (intval($member->getID()) > 0 && intval($member->getID()) == intval($citem['authorid']));\r
613                 }\r
614 \r
615                 // check comment author name\r
616                 if ($name == 'name') {\r
617                         $value = trim(strtolower($value));\r
618                         if ($value == '')\r
619                                 return false;\r
620                         if ($value == strtolower($mem->getDisplayName()))\r
621                                 return true;\r
622                 }\r
623 \r
624                 // check if comment author is admin\r
625                 if ($name == 'isadmin') {\r
626                         $blogid = intval($b->getID());\r
627                         if ($mem->isAdmin())\r
628                                 return true;\r
629 \r
630                         return $mem->isBlogAdmin($blogid);\r
631                 }\r
632 \r
633                 // check if comment author is item author\r
634                 if ($name == 'isauthor') {\r
635                         return (intval($citem['authorid']) == intval($this->currentComment['memberid']));\r
636                 }\r
637 \r
638                 // check if comment author is on team\r
639                 if ($name == 'isonteam') {\r
640                         return $mem->teamRights(intval($b->getID()));\r
641                 }\r
642 \r
643                 return false;\r
644         }\r
645 \r
646         /**\r
647          *  Different checks for a category\r
648          */\r
649         function _ifItemCategory($name = '', $value='') {\r
650                 global $catid, $manager;\r
651 \r
652                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));\r
653                 $citem =& $manager->getItem($this->currentComment['itemid'],1,1);\r
654                 $icatid = $citem['catid'];\r
655 \r
656                 // when no parameter is defined, just check if a category is selected\r
657                 if (($name != 'catname' && $name != 'catid') || ($value == ''))\r
658                         return $b->isValidCategory($icatid);\r
659 \r
660                 // check category name\r
661                 if ($name == 'catname') {\r
662                         $value = $b->getCategoryIdFromName($value);\r
663                         if ($value == $icatid)\r
664                                 return $b->isValidCategory($icatid);\r
665                 }\r
666 \r
667                 // check category id\r
668                 if (($name == 'catid') && ($value == $icatid))\r
669                         return $b->isValidCategory($icatid);\r
670 \r
671                 return false;\r
672         }\r
673 \r
674 \r
675         /**\r
676          *  Checks if a member is on the team of a blog and return his rights\r
677          */\r
678         function _ifOnTeam($blogName = '') {\r
679                 global $blog, $member, $manager;\r
680 \r
681                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));\r
682 \r
683                 // when no blog found\r
684                 if (($blogName == '') && (!is_object($b)))\r
685                         return 0;\r
686 \r
687                 // explicit blog selection\r
688                 if ($blogName != '')\r
689                         $blogid = getBlogIDFromName($blogName);\r
690 \r
691                 if (($blogName == '') || !$manager->existsBlogID($blogid))\r
692                         // use current blog\r
693                         $blogid = $b->getID();\r
694 \r
695                 return $member->teamRights($blogid);\r
696         }\r
697 \r
698         /**\r
699          *  Checks if a member is admin of a blog\r
700          */\r
701         function _ifAdmin($blogName = '') {\r
702                 global $blog, $member, $manager;\r
703 \r
704                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentComment['itemid']));\r
705 \r
706                 // when no blog found\r
707                 if (($blogName == '') && (!is_object($b)))\r
708                         return 0;\r
709 \r
710                 // explicit blog selection\r
711                 if ($blogName != '')\r
712                         $blogid = getBlogIDFromName($blogName);\r
713 \r
714                 if (($blogName == '') || !$manager->existsBlogID($blogid))\r
715                         // use current blog\r
716                         $blogid = $b->getID();\r
717 \r
718                 return $member->isBlogAdmin($blogid);\r
719         }\r
720 \r
721 \r
722         /**\r
723          *      hasplugin,PlugName\r
724          *         -> checks if plugin exists\r
725          *      hasplugin,PlugName,OptionName\r
726          *         -> checks if the option OptionName from plugin PlugName is not set to 'no'\r
727          *      hasplugin,PlugName,OptionName=value\r
728          *         -> checks if the option OptionName from plugin PlugName is set to value\r
729          */\r
730         function _ifHasPlugin($name, $value) {\r
731                 global $manager;\r
732                 $condition = false;\r
733                 // (pluginInstalled method won't write a message in the actionlog on failure)\r
734                 if ($manager->pluginInstalled('NP_'.$name)) {\r
735                         $plugin =& $manager->getPlugin('NP_' . $name);\r
736                         if ($plugin != NULL) {\r
737                                 if ($value == "") {\r
738                                         $condition = true;\r
739                                 } else {\r
740                                         list($name2, $value2) = preg_split('#=#', $value, 2);\r
741                                         if ($value2 == "" && $plugin->getOption($name2) != 'no') {\r
742                                                 $condition = true;\r
743                                         } else if ($plugin->getOption($name2) == $value2) {\r
744                                                 $condition = true;\r
745                                         }\r
746                                 }\r
747                         }\r
748                 }\r
749                 return $condition;\r
750         }\r
751 \r
752         /**\r
753          * Checks if a plugin exists and call its doIf function\r
754          */\r
755         function _ifPlugin($name, $key = '', $value = '') {\r
756                 global $manager;\r
757 \r
758                 $plugin =& $manager->getPlugin('NP_' . $name);\r
759                 if (!$plugin) return;\r
760 \r
761                 $params = func_get_args();\r
762                 array_shift($params);\r
763 \r
764                 return call_user_func_array(array(&$plugin, 'doIf'), $params);\r
765         }\r
766 \r
767 }\r