OSDN Git Service

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