OSDN Git Service

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