OSDN Git Service

Subversion由来のタグを削除
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / libs / ITEMACTIONS.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2012 The Nucleus Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  *
12  * This class is used to parse item templates
13  */
14 class ITEMACTIONS extends BaseActions {\r
15 \r
16         // contains an assoc array with parameters that need to be included when\r
17         // generating links to items/archives/... (e.g. catid)\r
18         var $linkparams;\r
19 \r
20         // true when the current user is a blog admin (and thus allowed to edit all items)\r
21         var $allowEditAll;\r
22 \r
23         // timestamp of last visit\r
24         var $lastVisit;\r
25 \r
26         // item currently being handled (mysql result object, see BLOG::showUsingQuery)\r
27         var $currentItem;\r
28 \r
29         // reference to the blog currently being displayed\r
30         var $blog;\r
31 \r
32         // associative array with template info (part name => contents)\r
33         var $template;\r
34 \r
35         // true when comments need to be displayed\r
36         var $showComments;\r
37 \r
38         function ITEMACTIONS(&$blog) {\r
39                 // call constructor of superclass first\r
40                 $this->BaseActions();\r
41 \r
42                 // extra parameters for created links\r
43                 global $catid;\r
44                 if ($catid)\r
45                         $this->linkparams = array('catid' => $catid);\r
46 \r
47                 // check if member is blog admin (and thus allowed to edit all items)\r
48                 global $member;\r
49                 $this->allowEditAll = ($member->isLoggedIn() && $member->blogAdminRights($blog->getID()));\r
50                 $this->setBlog($blog);\r
51         }\r
52 \r
53         /**\r
54           * Returns an array with the actions that are defined\r
55           * in the ITEMACTIONS class\r
56           */\r
57         function getDefinedActions() {\r
58                 return array(\r
59                         'blogid',\r
60                         'title',\r
61                         'body',\r
62                         'more',\r
63                         'smartbody',\r
64                         'itemid',\r
65                         'morelink',\r
66                         'category',\r
67                         'categorylink',\r
68                         'author',\r
69                         'authorid',\r
70                         'authorlink',\r
71                         'catid',\r
72                         'karma',\r
73                         'date',\r
74                         'time',\r
75                         'query',\r
76                         'itemlink',\r
77                         'blogurl',\r
78                         'closed',\r
79                         'syndicate_title',\r
80                         'syndicate_description',\r
81                         'karmaposlink',\r
82                         'karmaneglink',\r
83                         'new',\r
84                         'image',\r
85                         'popup',\r
86                         'media',\r
87                         'daylink',\r
88                         'query',\r
89                         'include',\r
90                         'phpinclude',\r
91                         'parsedinclude',\r
92                         'skinfile',\r
93                         'set',\r
94                         'plugin',\r
95                         'edit',\r
96                         'editlink',\r
97                         'editpopupcode',\r
98                         'comments',\r
99                         'relevance',\r
100                         'if',\r
101                         'else',\r
102                         'endif',\r
103                         'elseif',\r
104                         'ifnot',\r
105                         'elseifnot'\r
106                 );\r
107         }\r
108 \r
109         function setLastVisit($lastVisit) {\r
110                 $this->lastVisit = $lastVisit;\r
111         }\r
112 \r
113         function setParser(&$parser) {\r
114                 $this->parser =& $parser;\r
115         }\r
116         \r
117         function setCurrentItem(&$item) {
118                 $this->currentItem =& $item;
119                 global $currentitemid;
120                 if (is_array($this->currentItem)) {
121                         $currentitemid = $this->currentItem['itemid'];
122                 } else {
123                         $currentitemid = $this->currentItem->itemid;
124                 }
125         }
126         
127         function setBlog(&$blog) {\r
128                 $this->blog =& $blog;\r
129         }\r
130 \r
131         function setTemplate($template) {\r
132                 $this->template =& $template;\r
133         }\r
134 \r
135         function setShowComments($val) {\r
136                 $this->showComments = $val;\r
137         }\r
138 \r
139         // methods used by parser to insert content\r
140 \r
141 \r
142         /**\r
143          * Parse templatevar blogid\r
144          */\r
145         function parse_blogid() {\r
146                 echo $this->blog->getID();\r
147         }\r
148 \r
149         /**\r
150          * Parse templatevar body\r
151          */\r
152         function parse_body() {\r
153                 $this->highlightAndParse($this->currentItem->body);\r
154         }\r
155 \r
156         /**\r
157          * Parse templatevar more\r
158          */\r
159         function parse_more() {\r
160                 $this->highlightAndParse($this->currentItem->more);\r
161         }\r
162 \r
163         /**\r
164          * Parse templatevar itemid\r
165          */\r
166         function parse_itemid() {\r
167                 echo $this->currentItem->itemid;\r
168         }\r
169 \r
170         /**\r
171          * Parse templatevar category\r
172          */\r
173         function parse_category() {\r
174                 echo $this->currentItem->category;\r
175         }\r
176 \r
177         /**\r
178          * Parse templatevar categorylink\r
179          */\r
180         function parse_categorylink() {\r
181                 echo createLink('category', array('catid' => $this->currentItem->catid, 'name' => $this->currentItem->category));\r
182         }\r
183 \r
184         /**\r
185          * Parse templatevar catid\r
186          */\r
187         function parse_catid() {\r
188                 echo $this->currentItem->catid;\r
189         }\r
190 \r
191         /**\r
192          * Parse templatevar authorid\r
193          */\r
194         function parse_authorid() {\r
195                 echo $this->currentItem->authorid;\r
196         }\r
197 \r
198         /**\r
199          * Parse templatevar authorlink\r
200          */\r
201         function parse_authorlink() {\r
202                 echo createLink(\r
203                         'member',\r
204                         array(\r
205                                 'memberid' => $this->currentItem->authorid,\r
206                                 'name' => $this->currentItem->author,\r
207                                 'extra' => $this->linkparams\r
208                         )\r
209                 );\r
210         }\r
211 \r
212         /**\r
213          * Parse templatevar query\r
214          */\r
215         function parse_query() {\r
216                 echo $this->strHighlight;\r
217         }\r
218 \r
219         /**\r
220          * Parse templatevar itemlink\r
221          */\r
222         function parse_itemlink() {\r
223                 echo createLink(\r
224                         'item',\r
225                         array(\r
226                                 'itemid' => $this->currentItem->itemid,\r
227                                 'title' => $this->currentItem->title,\r
228                                 'timestamp' => $this->currentItem->timestamp,\r
229                                 'extra' => $this->linkparams\r
230                         )\r
231                 );\r
232         }\r
233 \r
234         /**\r
235          * Parse templatevar blogurl\r
236          */\r
237         function parse_blogurl() {\r
238                 echo $this->blog->getURL();\r
239         }\r
240 \r
241         /**\r
242          * Parse templatevar closed\r
243          */\r
244         function parse_closed() {\r
245                 echo $this->currentItem->closed;\r
246         }\r
247 \r
248         /**\r
249          * Parse templatevar relevance\r
250          */\r
251         function parse_relevance() {\r
252                 echo round($this->currentItem->score,2);\r
253         }\r
254 \r
255         /**\r
256          * Parse templatevar title\r
257          *\r
258          * @param string $format defines in which format the title is shown\r
259          */\r
260         function parse_title($format = '') {\r
261                 if (is_array($this->currentItem)) {\r
262                         $itemtitle = $this->currentItem['title'];\r
263                 } elseif (is_object($this->currentItem)) {\r
264                         $itemtitle = $this->currentItem->title;\r
265                 }\r
266                 switch ($format) {\r
267                         case 'xml':\r
268 //                              echo stringToXML ($this->currentItem->title);\r
269                                 echo stringToXML ($itemtitle);\r
270                                 break;\r
271                         case 'attribute':\r
272 //                              echo stringToAttribute ($this->currentItem->title);\r
273                                 echo stringToAttribute ($itemtitle);\r
274                                 break;\r
275                         case 'raw':\r
276 //                              echo $this->currentItem->title;\r
277                                 echo $itemtitle;\r
278                                 break;\r
279                         default:\r
280 //                              $this->highlightAndParse($this->currentItem->title);\r
281                                 $this->highlightAndParse($itemtitle);\r
282                                 break;\r
283                 }\r
284         }\r
285 \r
286         /**\r
287          * Parse templatevar karma\r
288          */\r
289         function parse_karma($type = 'totalscore') {\r
290                 global $manager;\r
291 \r
292                 // get karma object\r
293                 $karma =& $manager->getKarma($this->currentItem->itemid);\r
294 \r
295                 switch($type) {\r
296                         case 'pos':\r
297                                 echo $karma->getNbPosVotes();\r
298                                 break;\r
299                         case 'neg':\r
300                                 echo $karma->getNbNegVotes();\r
301                                 break;\r
302                         case 'votes':\r
303                                 echo $karma->getNbOfVotes();\r
304                                 break;\r
305                         case 'posp':\r
306                                 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbPosVotes() / $karma->getNbOfVotes()) : 50;\r
307                                 echo number_format($percentage,2), '%';\r
308                                 break;\r
309                         case 'negp':\r
310                                 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbNegVotes() / $karma->getNbOfVotes()) : 50;\r
311                                 echo number_format($percentage,2), '%';\r
312                                 break;\r
313                         case 'totalscore':\r
314                         default:\r
315                                 echo $karma->getTotalScore();\r
316                                 break;\r
317                 }\r
318 \r
319         }\r
320 \r
321         /**\r
322          * Parse templatevar author\r
323          */\r
324         function parse_author($which = '') {\r
325                 switch($which)\r
326                 {\r
327                         case 'realname':\r
328                                 echo $this->currentItem->authorname;\r
329                                 break;\r
330                         case 'id':\r
331                                 echo $this->currentItem->authorid;\r
332                                 break;\r
333                         case 'email':\r
334                                 echo $this->currentItem->authormail;\r
335                                 break;\r
336                         case 'url':\r
337                                 echo $this->currentItem->authorurl;\r
338                                 break;\r
339                         case 'name':\r
340                         default:\r
341                                 echo $this->currentItem->author;\r
342                 }\r
343         }\r
344 \r
345         /**\r
346          * Parse templatevar smartbody\r
347          */\r
348         function parse_smartbody() {\r
349                 if (!$this->currentItem->more) {\r
350                         $this->highlightAndParse($this->currentItem->body);\r
351                 } else {\r
352                         $this->highlightAndParse($this->currentItem->more);\r
353                 }\r
354         }\r
355 \r
356         /**\r
357          * Parse templatevar morelink\r
358          */\r
359         function parse_morelink() {\r
360                 if ($this->currentItem->more)\r
361                         $this->parser->parse($this->template['MORELINK']);\r
362         }\r
363 \r
364         /**\r
365          * Parse templatevar date\r
366          *\r
367          * @param format optional strftime format\r
368          */\r
369         function parse_date($format = '') {\r
370                 if (!isset($this->template['FORMAT_DATE'])) $this->template['FORMAT_DATE'] = '';
371                 echo formatDate($format, $this->currentItem->timestamp, $this->template['FORMAT_DATE'], $this->blog);\r
372         }\r
373 \r
374         /**\r
375           * Parse templatevar time\r
376           *\r
377           * @param format optional strftime format\r
378           */\r
379         function parse_time($format = '') {\r
380                 if (!isset($this->template['FORMAT_TIME'])) $this->template['FORMAT_TIME'] = '';
381                 echo strftimejp($format ? $format : $this->template['FORMAT_TIME'],$this->currentItem->timestamp);\r
382         }\r
383 \r
384         /**\r
385           * Parse templatevar syndicate_title\r
386           *\r
387           * @param maxLength optional maximum length\r
388           */\r
389         function parse_syndicate_title($maxLength = 100) {\r
390                 $syndicated = strip_tags($this->currentItem->title);\r
391                 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES);\r
392         }\r
393 \r
394         /**\r
395           * Parse templatevar syndicate_description\r
396           *\r
397           * @param maxLength optional maximum length\r
398           */\r
399         function parse_syndicate_description($maxLength = 250, $addHighlight = 0) {\r
400                 $syndicated = strip_tags($this->currentItem->body);\r
401                 if ($addHighlight) {\r
402                         $tmp_highlight = htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES);\r
403                         echo $this->highlightAndParse($tmp_highlight);\r
404                 } else {\r
405                         echo htmlspecialchars(shorten($syndicated,$maxLength,'...'),ENT_QUOTES);\r
406                 }\r
407         }\r
408 \r
409         /**\r
410           * Parse templatevar karmaposlink\r
411           *\r
412           * @param string text\r
413           */\r
414         function parse_karmaposlink($text = '') {\r
415                 global $CONF;\r
416                 $link = $CONF['ActionURL'] . '?action=votepositive&amp;itemid='.$this->currentItem->itemid;\r
417                 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link;\r
418         }\r
419 \r
420         /**\r
421           * Parse templatevar karmaneglink\r
422           *\r
423           * @param string text\r
424           */\r
425         function parse_karmaneglink($text = '') {\r
426                 global $CONF;\r
427                 $link = $CONF['ActionURL'] . '?action=votenegative&amp;itemid='.$this->currentItem->itemid;\r
428                 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link;\r
429         }\r
430 \r
431         /**\r
432           * Parse templatevar new\r
433           */\r
434         function parse_new() {\r
435                 if (($this->lastVisit != 0) && ($this->currentItem->timestamp > $this->lastVisit))\r
436                         echo $this->template['NEW'];\r
437         }\r
438 \r
439         /**\r
440           * Parse templatevar daylink\r
441           */\r
442         function parse_daylink() {\r
443                 echo createArchiveLink($this->blog->getID(), strftime('%Y-%m-%d',$this->currentItem->timestamp), $this->linkparams);\r
444         }\r
445 \r
446         /**\r
447           * Parse templatevar comments\r
448           */\r
449         function parse_comments($maxToShow = 0) {\r
450                 if ($maxToShow == 0)\r
451                         $maxToShow = $this->blog->getMaxComments();\r
452 \r
453                 // add comments\r
454                 if ($this->showComments && $this->blog->commentsEnabled()) {\r
455                         $comments = new COMMENTS($this->currentItem->itemid);\r
456                         $comments->setItemActions($this);\r
457                         $comments->showComments($this->template, $maxToShow, $this->currentItem->closed ? 0 : 1, $this->strHighlight);\r
458                 }\r
459         }\r
460 \r
461         /**\r
462           * Executes a plugin templatevar\r
463           *\r
464           * @param pluginName name of plugin (without the NP_)\r
465           *\r
466           * extra parameters can be added\r
467           */\r
468         function parse_plugin($pluginName) {\r
469                 global $manager;\r
470 \r
471                 // should be already tested from the parser (PARSER.php)\r
472                 // only continue when the plugin is really installed\r
473                 /*if (!$manager->pluginInstalled('NP_' . $pluginName))\r
474                         return;*/\r
475 \r
476                 $plugin =& $manager->getPlugin('NP_' . $pluginName);\r
477                 if (!$plugin) return;\r
478 \r
479                 // get arguments\r
480                 $params = func_get_args();\r
481 \r
482                 // remove plugin name\r
483                 array_shift($params);\r
484 \r
485                 // add item reference (array_unshift didn't work)\r
486                 $params = array_merge(array(&$this->currentItem),$params);\r
487 \r
488                 call_user_func_array(array($plugin,'doTemplateVar'), $params);\r
489         }\r
490 \r
491         /**\r
492           * Parse templatevar edit\r
493           */\r
494         function parse_edit() {\r
495                 global $member, $CONF;\r
496                 if ($this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem->authorid)) ) {\r
497                         $this->parser->parse($this->template['EDITLINK']);\r
498                 }\r
499         }\r
500 \r
501         /**\r
502           * Parse templatevar editlink\r
503           */\r
504         function parse_editlink() {\r
505                 global $CONF;\r
506                 echo $CONF['AdminURL'],'bookmarklet.php?action=edit&amp;itemid=',$this->currentItem->itemid;\r
507         }\r
508 \r
509         /**\r
510           * Parse templatevar editpopupcode\r
511           */\r
512         function parse_editpopupcode() {\r
513                 echo "if (event &amp;&amp; event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=no,width=710,height=550,left=10,top=10,status=no,resizable=yes');winbm.focus();return false;";\r
514         }\r
515 \r
516         // helper functions\r
517 \r
518         /**\r
519          * Parses highlighted text, with limited actions only (to prevent not fully trusted team members\r
520          * from hacking your weblog.\r
521          * 'plugin variables in items' implementation by Andy\r
522          */\r
523         function highlightAndParse(&$data) {\r
524                 $actions = new BODYACTIONS($this->blog);\r
525                 $parser = new PARSER($actions->getDefinedActions(), $actions);\r
526                 $actions->setTemplate($this->template);\r
527                 $actions->setHighlight($this->strHighlight);\r
528                 $actions->setCurrentItem($this->currentItem);\r
529                 //$actions->setParser($parser);\r
530                 $parser->parse($actions->highlight($data));\r
531         }\r
532 \r
533         /*\r
534         // this is the function previous to the 'plugin variables in items' implementation by Andy\r
535         function highlightAndParse(&$data) {\r
536                 // allow only a limited subset of actions (do not allow includes etc, they might be evil)\r
537                 $this->parser->actions = array('image','media','popup');\r
538                 $tmp_highlight = $this->highlight($data);\r
539                 $this->parser->parse($tmp_highlight);\r
540                 $this->parser->actions = $this->getDefinedActions();\r
541         }\r
542         */\r
543         \r
544         // function to enable if-else-elseif-elseifnot-ifnot-endif to item template fields
545         
546                 /**
547          * Checks conditions for if statements
548          *
549          * @param string $field type of <%if%>
550          * @param string $name property of field
551          * @param string $value value of property
552          */
553         function checkCondition($field, $name='', $value = '') {
554                 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
555
556                 $condition = 0;
557                 switch($field) {
558                         case 'category':
559                                 $condition = ($blog && $this->_ifCategory($name,$value));
560                                 break;
561                         case 'itemcategory':
562                                 $condition = ($this->_ifItemCategory($name,$value));
563                                 break;
564                         case 'blogsetting':
565                                 $condition = ($blog && ($blog->getSetting($name) == $value));
566                                 break;
567                         case 'itemblogsetting':
568                                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
569                                 $condition = ($b && ($b->getSetting($name) == $value));
570                                 break;
571                         case 'loggedin':
572                                 $condition = $member->isLoggedIn();
573                                 break;
574                         case 'onteam':
575                                 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
576                                 break;
577                         case 'admin':
578                                 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
579                                 break;
580                         case 'author':
581                                 $condition = ($this->_ifAuthor($name,$value));
582                                 break;
583 /*                      case 'nextitem':
584                                 $condition = ($itemidnext != '');
585                                 break;
586                         case 'previtem':
587                                 $condition = ($itemidprev != '');
588                                 break;
589                         case 'archiveprevexists':
590                                 $condition = ($archiveprevexists == true);
591                                 break;
592                         case 'archivenextexists':
593                                 $condition = ($archivenextexists == true);
594                                 break; 
595                         case 'skintype':
596                                 $condition = ($name == $this->skintype);
597                                 break; */
598                         case 'hasplugin':
599                                 $condition = $this->_ifHasPlugin($name, $value);
600                                 break;
601                         default:
602                                 $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
603                                 break;
604                 }
605                 return $condition;
606         }       
607         
608         /**
609          *  Different checks for a category
610          */
611         function _ifCategory($name = '', $value='') {
612                 global $blog, $catid;
613
614                 // when no parameter is defined, just check if a category is selected
615                 if (($name != 'catname' && $name != 'catid') || ($value == ''))
616                         return $blog->isValidCategory($catid);
617
618                 // check category name
619                 if ($name == 'catname') {
620                         $value = $blog->getCategoryIdFromName($value);
621                         if ($value == $catid)
622                                 return $blog->isValidCategory($catid);
623                 }
624
625                 // check category id
626                 if (($name == 'catid') && ($value == $catid))
627                         return $blog->isValidCategory($catid);
628
629                 return false;
630         }
631         
632                 
633         /**
634          *  Different checks for an author
635          */
636         function _ifAuthor($name = '', $value='') {
637                 global $member, $manager;
638                 
639                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
640
641                 // when no parameter is defined, just check if author is current visitor
642                 if (($name != 'isadmin' && $name != 'name') || ($name == 'name' && $value == '')) {
643                         return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem->authorid));
644                 }
645
646                 // check author name
647                 if ($name == 'name') {
648                         $value = strtolower($value);
649                         if ($value == strtolower($this->currentItem->author))
650                                 return true;
651                 }
652
653                 // check if author is admin
654                 if (($name == 'isadmin')) {                     
655                         $aid = intval($this->currentItem->authorid);
656                         $blogid = intval($b->getID());                  
657                         $amember =& $manager->getMember($aid);
658                         if ($amember->isAdmin())
659                                 return true;
660                                 
661                         return $amember->isBlogAdmin($blogid);
662                 }
663
664                 return false;
665         }
666         
667         /**
668          *  Different checks for a category
669          */
670         function _ifItemCategory($name = '', $value='') {
671                 global $catid, $manager;
672                 
673                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
674
675                 // when no parameter is defined, just check if a category is selected
676                 if (($name != 'catname' && $name != 'catid') || ($value == ''))
677                         return $b->isValidCategory($catid);
678                         
679                 $icatid = $this->currentItem->catid;
680                 //$icategory = $this->currentItem->category;
681
682                 // check category name
683                 if ($name == 'catname') {
684                         $value = $b->getCategoryIdFromName($value);
685                         if ($value == $icatid)
686                                 return $b->isValidCategory($icatid);
687                 }
688
689                 // check category id
690                 if (($name == 'catid') && ($value == $icatid))
691                         return $b->isValidCategory($icatid);
692
693                 return false;
694         }
695
696         
697         /**
698          *  Checks if a member is on the team of a blog and return his rights
699          */
700         function _ifOnTeam($blogName = '') {
701                 global $blog, $member, $manager;
702
703                 // when no blog found
704                 if (($blogName == '') && (!is_object($blog)))
705                         return 0;
706
707                 // explicit blog selection
708                 if ($blogName != '')
709                         $blogid = getBlogIDFromName($blogName);
710
711                 if (($blogName == '') || !$manager->existsBlogID($blogid))
712                         // use current blog
713                         $blogid = $blog->getID();
714
715                 return $member->teamRights($blogid);
716         }
717
718         /**
719          *  Checks if a member is admin of a blog
720          */
721         function _ifAdmin($blogName = '') {
722                 global $blog, $member, $manager;
723
724                 // when no blog found
725                 if (($blogName == '') && (!is_object($blog)))
726                         return 0;
727
728                 // explicit blog selection
729                 if ($blogName != '')
730                         $blogid = getBlogIDFromName($blogName);
731
732                 if (($blogName == '') || !$manager->existsBlogID($blogid))
733                         // use current blog
734                         $blogid = $blog->getID();
735
736                 return $member->isBlogAdmin($blogid);
737         }
738
739         
740         /**
741          *      hasplugin,PlugName
742          *         -> checks if plugin exists
743          *      hasplugin,PlugName,OptionName
744          *         -> checks if the option OptionName from plugin PlugName is not set to 'no'
745          *      hasplugin,PlugName,OptionName=value
746          *         -> checks if the option OptionName from plugin PlugName is set to value
747          */
748         function _ifHasPlugin($name, $value) {
749                 global $manager;
750                 $condition = false;
751                 // (pluginInstalled method won't write a message in the actionlog on failure)
752                 if ($manager->pluginInstalled('NP_'.$name)) {
753                         $plugin =& $manager->getPlugin('NP_' . $name);
754                         if ($plugin != NULL) {
755                                 if ($value == "") {
756                                         $condition = true;
757                                 } else {
758                                         list($name2, $value2) = explode('=', $value, 2);
759                                         if ($value2 == "" && $plugin->getOption($name2) != 'no') {
760                                                 $condition = true;
761                                         } else if ($plugin->getOption($name2) == $value2) {
762                                                 $condition = true;
763                                         }
764                                 }
765                         }
766                 }
767                 return $condition;
768         }
769
770         /**
771          * Checks if a plugin exists and call its doIf function
772          */
773         function _ifPlugin($name, $key = '', $value = '') {
774                 global $manager;
775
776                 $plugin =& $manager->getPlugin('NP_' . $name);
777                 if (!$plugin) return;
778
779                 $params = func_get_args();
780                 array_shift($params);
781
782                 return call_user_func_array(array($plugin, 'doIf'), $params);
783         }
784 }\r
785 ?>