OSDN Git Service

MERGE: リビジョン1721をマージ。主要なクラス名をUpperCamelCaseに統一。
[nucleus-jp/nucleus-next.git] / nucleus / libs / ITEMACTIONS.php
1 <?php\r
2 /*\r
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
4  * Copyright (C) 2002-2009 The Nucleus Group\r
5  *\r
6  * This program is free software; you can redistribute it and/or\r
7  * modify it under the terms of the GNU General Public License\r
8  * as published by the Free Software Foundation; either version 2\r
9  * of the License, or (at your option) any later version.\r
10  * (see nucleus/documentation/index.html#license for more info)\r
11  */\r
12 /**\r
13  * This class is used to parse item templates\r
14  *\r
15  * @license http://nucleuscms.org/license.txt GNU General Public License\r
16  * @copyright Copyright (C) 2002-2009 The Nucleus Group\r
17  * @version $Id: ITEMACTIONS.php 1699 2012-03-10 15:46:32Z sakamocchi $\r
18  */\r
19 class ItemActions extends BaseActions\r
20 {\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 __construct(&$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) {\r
124                 $this->currentItem =& $item;\r
125                 global $currentitemid;\r
126                 $currentitemid = $this->currentItem->itemid;\r
127         }\r
128 \r
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          * ItemActions::parse_categorylink()\r
181          * Parse templatevar categorylink\r
182          * \r
183          * @param       Void\r
184          * @return      Void\r
185          */\r
186         function parse_categorylink()\r
187         {\r
188                 echo Link::create_link('category', array('catid' => $this->currentItem->catid, 'name' => $this->currentItem->category));\r
189                 return;\r
190         }\r
191 \r
192         /**\r
193          * Parse templatevar catid\r
194          */\r
195         function parse_catid() {\r
196                 echo $this->currentItem->catid;\r
197         }\r
198 \r
199         /**\r
200          * Parse templatevar authorid\r
201          */\r
202         function parse_authorid() {\r
203                 echo $this->currentItem->authorid;\r
204         }\r
205 \r
206         /**\r
207          * ItemActions::parse_authorlink()\r
208          * Parse templatevar authorlink\r
209          * \r
210          * @param       Void\r
211          * @return      Void\r
212          */\r
213         function parse_authorlink()\r
214         {\r
215                 echo Link::create_link(\r
216                         'member',\r
217                         array(\r
218                                 'memberid' => $this->currentItem->authorid,\r
219                                 'name' => $this->currentItem->author,\r
220                                 'extra' => $this->linkparams\r
221                         )\r
222                 );\r
223                 return;\r
224         }\r
225 \r
226         /**\r
227          * Parse templatevar query\r
228          */\r
229         function parse_query() {\r
230                 echo $this->strHighlight;\r
231         }\r
232 \r
233         /**\r
234          * ItemActions::parse_itemlink()\r
235          * Parse templatevar itemlink\r
236          * \r
237          * @param       Void\r
238          * @return      Void\r
239          */\r
240         function parse_itemlink()\r
241         {\r
242                 echo Link::create_link(\r
243                         'item',\r
244                         array(\r
245                                 'itemid' => $this->currentItem->itemid,\r
246                                 'title' => $this->currentItem->title,\r
247                                 'timestamp' => $this->currentItem->timestamp,\r
248                                 'extra' => $this->linkparams\r
249                         )\r
250                 );\r
251                 return;\r
252         }\r
253         \r
254         /**\r
255          * Parse templatevar blogurl\r
256          */\r
257         function parse_blogurl() {\r
258                 echo $this->blog->getURL();\r
259         }\r
260 \r
261         /**\r
262          * Parse templatevar closed\r
263          */\r
264         function parse_closed() {\r
265                 echo $this->currentItem->closed;\r
266         }\r
267 \r
268         /**\r
269          * Parse templatevar relevance\r
270          */\r
271         function parse_relevance() {\r
272                 echo round($this->currentItem->score,2);\r
273         }\r
274 \r
275         /**\r
276          * Parse templatevar title\r
277          *\r
278          * @param string $format defines in which format the title is shown\r
279          */\r
280         function parse_title($format = '')\r
281         {\r
282                 if ( is_array($this->currentItem) )\r
283                 {\r
284                         $itemtitle = $this->currentItem['title'];\r
285                 }\r
286                 elseif ( is_object($this->currentItem) )\r
287                 {\r
288                         $itemtitle = $this->currentItem->title;\r
289                 }\r
290                 switch ( $format )\r
291                 {\r
292                         case 'xml':\r
293                                 echo Entity::hen($itemtitle);\r
294                                 break;\r
295                         case 'attribute':\r
296                                 echo Entity::hsc($itemtitle);\r
297                                 break;\r
298                         case 'raw':\r
299                                 echo $itemtitle;\r
300                                 break;\r
301                         default:\r
302                                 $this->highlightAndParse($itemtitle);\r
303                                 break;\r
304                 }\r
305                 return;\r
306         }\r
307 \r
308         /**\r
309          * Parse templatevar karma\r
310          */\r
311         function parse_karma($type = 'totalscore') {\r
312                 global $manager;\r
313 \r
314                 // get karma object\r
315                 $karma =& $manager->getKarma($this->currentItem->itemid);\r
316 \r
317                 switch($type) {\r
318                         case 'pos':\r
319                                 echo $karma->getNbPosVotes();\r
320                                 break;\r
321                         case 'neg':\r
322                                 echo $karma->getNbNegVotes();\r
323                                 break;\r
324                         case 'votes':\r
325                                 echo $karma->getNbOfVotes();\r
326                                 break;\r
327                         case 'posp':\r
328                                 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbPosVotes() / $karma->getNbOfVotes()) : 50;\r
329                                 echo number_format($percentage,2), '%';\r
330                                 break;\r
331                         case 'negp':\r
332                                 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbNegVotes() / $karma->getNbOfVotes()) : 50;\r
333                                 echo number_format($percentage,2), '%';\r
334                                 break;\r
335                         case 'totalscore':\r
336                         default:\r
337                                 echo $karma->getTotalScore();\r
338                                 break;\r
339                 }\r
340 \r
341         }\r
342 \r
343         /**\r
344          * Parse templatevar author\r
345          */\r
346         function parse_author($which = '') {\r
347                 switch($which)\r
348                 {\r
349                         case 'realname':\r
350                                 echo $this->currentItem->authorname;\r
351                                 break;\r
352                         case 'id':\r
353                                 echo $this->currentItem->authorid;\r
354                                 break;\r
355                         case 'email':\r
356                                 echo $this->currentItem->authormail;\r
357                                 break;\r
358                         case 'url':\r
359                                 echo $this->currentItem->authorurl;\r
360                                 break;\r
361                         case 'name':\r
362                         default:\r
363                                 echo $this->currentItem->author;\r
364                 }\r
365         }\r
366 \r
367         /**\r
368          * Parse templatevar smartbody\r
369          */\r
370         function parse_smartbody() {\r
371                 if (!$this->currentItem->more) {\r
372                         $this->highlightAndParse($this->currentItem->body);\r
373                 } else {\r
374                         $this->highlightAndParse($this->currentItem->more);\r
375                 }\r
376         }\r
377 \r
378         /**\r
379          * Parse templatevar morelink\r
380          */\r
381         function parse_morelink() {\r
382                 if ($this->currentItem->more)\r
383                         $this->parser->parse($this->template['MORELINK']);\r
384         }\r
385         \r
386         /**\r
387          * ItemActions::parse_date()\r
388          * Parse templatevar date\r
389          *\r
390          * @param       string  $format format optional strftime format\r
391          * @return      void\r
392          */\r
393         function parse_date($format = '')\r
394         {\r
395                 if ( $format !== '' )\r
396                 {\r
397                         /* do nothing */\r
398                         ;\r
399                 }\r
400                 else if ( !array_key_exists('FORMAT_DATE', $this->template) || $this->template['FORMAT_DATE'] === '' )\r
401                 {\r
402                         /* depends on the PHP's current locale */\r
403                         $format = '%X';\r
404                 }\r
405                 else\r
406                 {\r
407                         $format = $this->template['FORMAT_DATE'];\r
408                 }\r
409                 \r
410                 $offset = 0;\r
411                 if ( $this->blog )\r
412                 {\r
413                         $offset = $this->blog->getTimeOffset() * 3600;\r
414                 }\r
415                 \r
416                 echo i18n::formatted_datetime($format, $this->currentItem->timestamp, $offset);\r
417                 return;\r
418         }\r
419         \r
420         /**\r
421          * ItemActions::parse_time()\r
422          * Parse templatevar time\r
423          *\r
424          * @param string        $format format optional strftime format\r
425          * @return      void\r
426          * \r
427          */\r
428         function parse_time($format = '')\r
429         {\r
430                 if ( $format !== '' )\r
431                 {\r
432                         /* do nothing */\r
433                         ;\r
434                 }\r
435                 else if ( !array_key_exists('FORMAT_TIME', $this->template) || $this->template['FORMAT_TIME'] === '' )\r
436                 {\r
437                         /* depends on the PHP's current locale */\r
438                         $format = '%x';\r
439                 }\r
440                 else\r
441                 {\r
442                         $format = $this->template['FORMAT_TIME'];\r
443                 }\r
444                 echo i18n::formatted_datetime($format, $this->currentItem->timestamp);\r
445                 return;\r
446         }\r
447 \r
448         /**\r
449          * ItemActions::parse_syndicate_title()\r
450          * Parse templatevar syndicate_title\r
451          *\r
452          * @param String        $maxLength      maxLength optional maximum length\r
453          * @return      String  syndicated title\r
454          */\r
455         function parse_syndicate_title($maxLength = 100) {\r
456                 $syndicated = strip_tags($this->currentItem->title);\r
457                 echo Entity::hsc(Entity::shorten($syndicated,$maxLength,'...'));\r
458         }\r
459         \r
460         /**\r
461          * ItemActions::parse_syndicate_description()\r
462          * Parse templatevar syndicate_description\r
463          *\r
464          * @param Stromg        $maxLength      maxlength optional maximum length\r
465          * @param       String  $addHighlight   highlighted string\r
466          * @return      Void\r
467          */\r
468         function parse_syndicate_description($maxLength = 250, $addHighlight = 0)\r
469         {\r
470                 $syndicated = strip_tags($this->currentItem->body);\r
471                 if ( $addHighlight )\r
472                 {\r
473                         $tmp_highlight = Entity::hsc(Entity::shorten($syndicated,$maxLength,'...'));\r
474                         echo $this->highlightAndParse($tmp_highlight);\r
475                 }\r
476                 else\r
477                 {\r
478                         echo Entity::hsc(Entity::shorten($syndicated,$maxLength,'...'));\r
479                 }\r
480                 return;\r
481         }\r
482         \r
483         /**\r
484           * Parse templatevar karmaposlink\r
485           *\r
486           * @param string text\r
487           */\r
488         function parse_karmaposlink($text = '') {\r
489                 global $CONF;\r
490                 $link = $CONF['ActionURL'] . '?action=votepositive&amp;itemid='.$this->currentItem->itemid;\r
491                 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link;\r
492         }\r
493 \r
494         /**\r
495           * Parse templatevar karmaneglink\r
496           *\r
497           * @param string text\r
498           */\r
499         function parse_karmaneglink($text = '') {\r
500                 global $CONF;\r
501                 $link = $CONF['ActionURL'] . '?action=votenegative&amp;itemid='.$this->currentItem->itemid;\r
502                 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link;\r
503         }\r
504 \r
505         /**\r
506           * Parse templatevar new\r
507           */\r
508         function parse_new() {\r
509                 if (($this->lastVisit != 0) && ($this->currentItem->timestamp > $this->lastVisit))\r
510                         echo $this->template['NEW'];\r
511         }\r
512         \r
513         /**\r
514          * ItemActions::parse_daylink()\r
515          * Parse templatevar daylink\r
516          * \r
517          * @param       Void\r
518          * @return      Void\r
519          */\r
520         function parse_daylink()\r
521         {\r
522                 echo Link::create_archive_link($this->blog->getID(), i18n::formatted_datetime('%Y-%m-%d',$this->currentItem->timestamp), $this->linkparams);\r
523                 return;\r
524         }\r
525         \r
526         /**\r
527           * Parse templatevar comments\r
528           */\r
529         function parse_comments($maxToShow = 0) {\r
530                 if ($maxToShow == 0)\r
531                         $maxToShow = $this->blog->getMaxComments();\r
532 \r
533                 // add comments\r
534                 if ($this->showComments && $this->blog->commentsEnabled()) {\r
535                         $comments = new Comments($this->currentItem->itemid);\r
536                         $comments->setItemActions($this);\r
537                         $comments->showComments($this->template, $maxToShow, $this->currentItem->closed ? 0 : 1, $this->strHighlight);\r
538                 }\r
539         }\r
540 \r
541         /**\r
542           * Executes a plugin templatevar\r
543           *\r
544           * @param pluginName name of plugin (without the NP_)\r
545           *\r
546           * extra parameters can be added\r
547           */\r
548         function parse_plugin($pluginName) {\r
549                 global $manager;\r
550 \r
551                 // should be already tested from the parser (PARSER.php)\r
552                 // only continue when the plugin is really installed\r
553                 /*if (!$manager->pluginInstalled('NP_' . $pluginName))\r
554                         return;*/\r
555 \r
556                 $plugin =& $manager->getPlugin('NP_' . $pluginName);\r
557                 if (!$plugin) return;\r
558 \r
559                 // get arguments\r
560                 $params = func_get_args();\r
561 \r
562                 // remove plugin name\r
563                 array_shift($params);\r
564 \r
565                 // add item reference (array_unshift didn't work)\r
566                 $params = array_merge(array(&$this->currentItem),$params);\r
567 \r
568                 call_user_func_array(array(&$plugin,'doTemplateVar'), $params);\r
569         }\r
570 \r
571         /**\r
572           * Parse templatevar edit\r
573           */\r
574         function parse_edit() {\r
575                 global $member, $CONF;\r
576                 if ($this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem->authorid)) ) {\r
577                         $this->parser->parse($this->template['EDITLINK']);\r
578                 }\r
579         }\r
580 \r
581         /**\r
582           * Parse templatevar editlink\r
583           */\r
584         function parse_editlink() {\r
585                 global $CONF;\r
586                 echo $CONF['AdminURL'],'bookmarklet.php?action=edit&amp;itemid=',$this->currentItem->itemid;\r
587         }\r
588 \r
589         /**\r
590           * Parse templatevar editpopupcode\r
591           */\r
592         function parse_editpopupcode() {\r
593                 echo "if (event &amp;&amp; event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=yes,width=600,height=550,left=10,top=10,status=yes,resizable=yes');winbm.focus();return false;";\r
594         }\r
595 \r
596         // helper functions\r
597 \r
598         /**\r
599          * Parses highlighted text, with limited actions only (to prevent not fully trusted team members\r
600          * from hacking your weblog.\r
601          * 'plugin variables in items' implementation by Andy\r
602          */\r
603         function highlightAndParse(&$data) {\r
604                 $actions = new BodyActions($this->blog);\r
605                 $parser = new Parser($actions->getDefinedActions(), $actions);\r
606                 $actions->setTemplate($this->template);\r
607                 $actions->setHighlight($this->strHighlight);\r
608                 $actions->setCurrentItem($this->currentItem);\r
609                 //$actions->setParser($parser);\r
610                 $parser->parse($actions->highlight($data));\r
611         }\r
612 \r
613         /*\r
614         // this is the function previous to the 'plugin variables in items' implementation by Andy\r
615         function highlightAndParse(&$data) {\r
616                 // allow only a limited subset of actions (do not allow includes etc, they might be evil)\r
617                 $this->parser->actions = array('image','media','popup');\r
618                 $tmp_highlight = $this->highlight($data);\r
619                 $this->parser->parse($tmp_highlight);\r
620                 $this->parser->actions = $this->getDefinedActions();\r
621         }\r
622         */\r
623         \r
624         // function to enable if-else-elseif-elseifnot-ifnot-endif to item template fields\r
625         \r
626                 /**\r
627          * Checks conditions for if statements\r
628          *\r
629          * @param string $field type of <%if%>\r
630          * @param string $name property of field\r
631          * @param string $value value of property\r
632          */\r
633         function checkCondition($field, $name='', $value = '') {\r
634                 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;\r
635 \r
636                 $condition = 0;\r
637                 switch($field) {\r
638                         case 'category':\r
639                                 $condition = ($blog && $this->_ifCategory($name,$value));\r
640                                 break;\r
641                         case 'itemcategory':\r
642                                 $condition = ($this->_ifItemCategory($name,$value));\r
643                                 break;\r
644                         case 'blogsetting':\r
645                                 $condition = ($blog && ($blog->getSetting($name) == $value));\r
646                                 break;\r
647                         case 'itemblogsetting':\r
648                                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));\r
649                                 $condition = ($b && ($b->getSetting($name) == $value));\r
650                                 break;\r
651                         case 'loggedin':\r
652                                 $condition = $member->isLoggedIn();\r
653                                 break;\r
654                         case 'onteam':\r
655                                 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);\r
656                                 break;\r
657                         case 'admin':\r
658                                 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);\r
659                                 break;\r
660                         case 'author':\r
661                                 $condition = ($this->_ifAuthor($name,$value));\r
662                                 break;\r
663 /*                      case 'nextitem':\r
664                                 $condition = ($itemidnext != '');\r
665                                 break;\r
666                         case 'previtem':\r
667                                 $condition = ($itemidprev != '');\r
668                                 break;\r
669                         case 'archiveprevexists':\r
670                                 $condition = ($archiveprevexists == true);\r
671                                 break;\r
672                         case 'archivenextexists':\r
673                                 $condition = ($archivenextexists == true);\r
674                                 break; \r
675                         case 'skintype':\r
676                                 $condition = ($name == $this->skintype);\r
677                                 break; */\r
678                         case 'hasplugin':\r
679                                 $condition = $this->_ifHasPlugin($name, $value);\r
680                                 break;\r
681                         default:\r
682                                 $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);\r
683                                 break;\r
684                 }\r
685                 return $condition;\r
686         }       \r
687         \r
688         /**\r
689          *  Different checks for a category\r
690          */\r
691         function _ifCategory($name = '', $value='') {\r
692                 global $blog, $catid;\r
693 \r
694                 // when no parameter is defined, just check if a category is selected\r
695                 if (($name != 'catname' && $name != 'catid') || ($value == ''))\r
696                         return $blog->isValidCategory($catid);\r
697 \r
698                 // check category name\r
699                 if ($name == 'catname') {\r
700                         $value = $blog->getCategoryIdFromName($value);\r
701                         if ($value == $catid)\r
702                                 return $blog->isValidCategory($catid);\r
703                 }\r
704 \r
705                 // check category id\r
706                 if (($name == 'catid') && ($value == $catid))\r
707                         return $blog->isValidCategory($catid);\r
708 \r
709                 return false;\r
710         }\r
711         \r
712                 \r
713         /**\r
714          *  Different checks for an author\r
715          */\r
716         function _ifAuthor($name = '', $value='') {\r
717                 global $member, $manager;\r
718                 \r
719                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));\r
720 \r
721                 // when no parameter is defined, just check if author is current visitor\r
722                 if (($name != 'isadmin' && $name != 'name') || ($name == 'name' && $value == '')) {\r
723                         return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem->authorid));\r
724                 }\r
725 \r
726                 // check author name\r
727                 if ($name == 'name') {\r
728                         $value = strtolower($value);\r
729                         if ($value == strtolower($this->currentItem->author))\r
730                                 return true;\r
731                 }\r
732 \r
733                 // check if author is admin\r
734                 if (($name == 'isadmin')) {                     \r
735                         $aid = intval($this->currentItem->authorid);\r
736                         $blogid = intval($b->getID());                  \r
737                         $amember =& $manager->getMember($aid);\r
738                         if ($amember->isAdmin())\r
739                                 return true;\r
740                                 \r
741                         return $amember->isBlogAdmin($blogid);\r
742                 }\r
743 \r
744                 return false;\r
745         }\r
746         \r
747         /**\r
748          *  Different checks for a category\r
749          */\r
750         function _ifItemCategory($name = '', $value='') {\r
751                 global $catid, $manager;\r
752                 \r
753                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));\r
754 \r
755                 // when no parameter is defined, just check if a category is selected\r
756                 if (($name != 'catname' && $name != 'catid') || ($value == ''))\r
757                         return $b->isValidCategory($catid);\r
758                         \r
759                 $icatid = $this->currentItem->catid;\r
760                 //$icategory = $this->currentItem->category;\r
761 \r
762                 // check category name\r
763                 if ($name == 'catname') {\r
764                         $value = $b->getCategoryIdFromName($value);\r
765                         if ($value == $icatid)\r
766                                 return $b->isValidCategory($icatid);\r
767                 }\r
768 \r
769                 // check category id\r
770                 if (($name == 'catid') && ($value == $icatid))\r
771                         return $b->isValidCategory($icatid);\r
772 \r
773                 return false;\r
774         }\r
775 \r
776         \r
777         /**\r
778          *  Checks if a member is on the team of a blog and return his rights\r
779          */\r
780         function _ifOnTeam($blogName = '') {\r
781                 global $blog, $member, $manager;\r
782 \r
783                 // when no blog found\r
784                 if (($blogName == '') && (!is_object($blog)))\r
785                         return 0;\r
786 \r
787                 // explicit blog selection\r
788                 if ($blogName != '')\r
789                         $blogid = getBlogIDFromName($blogName);\r
790 \r
791                 if (($blogName == '') || !$manager->existsBlogID($blogid))\r
792                         // use current blog\r
793                         $blogid = $blog->getID();\r
794 \r
795                 return $member->teamRights($blogid);\r
796         }\r
797 \r
798         /**\r
799          *  Checks if a member is admin of a blog\r
800          */\r
801         function _ifAdmin($blogName = '') {\r
802                 global $blog, $member, $manager;\r
803 \r
804                 // when no blog found\r
805                 if (($blogName == '') && (!is_object($blog)))\r
806                         return 0;\r
807 \r
808                 // explicit blog selection\r
809                 if ($blogName != '')\r
810                         $blogid = getBlogIDFromName($blogName);\r
811 \r
812                 if (($blogName == '') || !$manager->existsBlogID($blogid))\r
813                         // use current blog\r
814                         $blogid = $blog->getID();\r
815 \r
816                 return $member->isBlogAdmin($blogid);\r
817         }\r
818 \r
819         \r
820         /**\r
821          *      hasplugin,PlugName\r
822          *         -> checks if plugin exists\r
823          *      hasplugin,PlugName,OptionName\r
824          *         -> checks if the option OptionName from plugin PlugName is not set to 'no'\r
825          *      hasplugin,PlugName,OptionName=value\r
826          *         -> checks if the option OptionName from plugin PlugName is set to value\r
827          */\r
828         function _ifHasPlugin($name, $value) {\r
829                 global $manager;\r
830                 $condition = false;\r
831                 // (pluginInstalled method won't write a message in the actionlog on failure)\r
832                 if ($manager->pluginInstalled('NP_'.$name)) {\r
833                         $plugin =& $manager->getPlugin('NP_' . $name);\r
834                         if ($plugin != NULL) {\r
835                                 if ($value == "") {\r
836                                         $condition = true;\r
837                                 } else {\r
838                                         list($name2, $value2) = i18n::explode('=', $value, 2);\r
839                                         if ($value2 == "" && $plugin->getOption($name2) != 'no') {\r
840                                                 $condition = true;\r
841                                         } else if ($plugin->getOption($name2) == $value2) {\r
842                                                 $condition = true;\r
843                                         }\r
844                                 }\r
845                         }\r
846                 }\r
847                 return $condition;\r
848         }\r
849 \r
850         /**\r
851          * Checks if a plugin exists and call its doIf function\r
852          */\r
853         function _ifPlugin($name, $key = '', $value = '') {\r
854                 global $manager;\r
855 \r
856                 $plugin =& $manager->getPlugin('NP_' . $name);\r
857                 if (!$plugin) return;\r
858 \r
859                 $params = func_get_args();\r
860                 array_shift($params);\r
861 \r
862                 return call_user_func_array(array(&$plugin, 'doIf'), $params);\r
863         }\r
864 \r
865 }\r
866 \r
867 ?>\r