OSDN Git Service

MERGE: リビジョン1802。変数名の変更。
[nucleus-jp/nucleus-next.git] / nucleus / libs / ITEMACTIONS.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2009 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-2009 The Nucleus Group
17  * @version $Id: ITEMACTIONS.php 1757 2012-04-15 09:02:32Z sakamocchi $
18  */
19 class ItemActions extends BaseActions
20 {
21         /**
22          * ItemActions::$currentItem
23          * item currently being handled (mysql result object, see Blog::showUsingQuery)
24          */
25         public $currentItem;
26         
27         /**
28          * ItemActions::$linkparams
29          * contains an assoc array with parameters that need to be included when
30          * generating links to items/archives/... (e.g. catid)
31          */
32         public $linkparams;
33         
34         /**
35          * ItemActions::$allowEditAll
36          * true when the current user is a blog admin (and thus allowed to edit all items) 
37          */
38         private $allowEditAll;
39         
40         /**
41          * ItemActions::$lastVisit
42          * timestamp of last visit
43          */
44         private $lastVisit;
45         
46         /**
47          * ItemActions::$blog
48          * reference to the blog currently being displayed
49          */
50         public $blog;
51         
52         /**
53          * ItemActions::$template
54          * associative array with template info (part name => contents)
55          */
56         private $template;
57         
58         /**
59          * ItemActions::$showComments
60          * true when comments need to be displayed
61          */
62         private $showComments;
63         
64         /**
65          * ItemActions::$defined_actions
66          * defined actions in this class
67          */
68         static private $defined_actions = array(
69                 'author',
70                 'authorid',
71                 'authorlink',
72                 'blogid',
73                 'blogurl',
74                 'body',
75                 'category',
76                 'categorylink',
77                 'catid',
78                 'closed',
79                 'comments',
80                 'date',
81                 'daylink',
82                 'edit',
83                 'editlink',
84                 'editpopupcode',
85                 'itemid',
86                 'itemlink',
87                 'karma',
88                 'karmaneglink',
89                 'karmaposlink',
90                 'more',
91                 'morelink',
92                 'new',
93                 'plugin',
94                 'query',
95                 'relevance',
96                 'smartbody',
97                 'syndicate_description',
98                 'syndicate_title',
99                 'time',
100                 'title',
101         /* actions defined in BodyAction class */
102                 'image',
103                 'media',
104                 'popup',
105                 );
106         
107         /**
108          * ItemActions::__construct
109          * Enter description here ...
110          * @param unknown_type $blog
111          */
112         public function __construct(&$blog)
113         {
114                 global $catid, $member;
115                 
116                 // call constructor of superclass first
117                 parent::__construct();
118                 
119                 // extra parameters for created links
120                 if ( $catid )
121                 {
122                         $this->linkparams = array('catid' => $catid);
123                 }
124                 
125                 // check if member is blog admin (and thus allowed to edit all items)
126                 $this->allowEditAll = ($member->isLoggedIn() && $member->blogAdminRights($blog->getID()));
127                 $this->setBlog($blog);
128                 return;
129         }
130         
131         /**
132          * ItemActions::getDefinedActions()
133          * Returns an array with the actions that are defined
134          * in the ItemActions class
135          * 
136          * @static
137          * @param       void
138          * @return      void
139          */
140         static public function getDefinedActions()
141         {
142                 return array_merge(self::$defined_actions, parent::getDefinedActions());
143         }
144         
145         /**
146          * ItemActions::setLastVisit()
147          * 
148          * @param       timestamp       $lastVisit      timestamp of latest visit
149          * @return      void
150          */
151         public function setLastVisit($lastVisit)
152         {
153                 $this->lastVisit = $lastVisit;
154                 return;
155         }
156         
157         /**
158          * ItemActions::setParser()
159          * 
160          * @param       object  &$parser        instance of Parser class
161          * @return      void
162          */
163         public function setParser(&$parser)
164         {
165                 $this->parser =& $parser;
166                 return;
167         }
168         
169         /**
170          * ItemActions::setCurrentItem()
171          * 
172          * @param       object  $item   instance of Item class
173          * @return      void
174          */
175         public function setCurrentItem(&$item)
176         {
177                 global $currentitemid;
178                 $this->currentItem =& $item;
179                 $currentitemid = $this->currentItem['itemid'];
180                 return;
181         }
182         
183         /**
184          * ItemActions::setBlog()
185          * 
186          * @param       object  &$blog  instance of Blog class
187          * @return      void
188          */
189         public function setBlog(&$blog)
190         {
191                 $this->blog =& $blog;
192                 return;
193         }
194         
195         /**
196          * ItemActions::setTemplate()
197          * 
198          * @param       array   $template       array including templates
199          * @return      void
200          */
201         public function setTemplate($template)
202         {
203                 $this->template =& $template;
204                 return;
205         }
206         
207         /**
208          * ItemActions::setShowComments()
209          * 
210          * @param       boolean $val    need to be displayed or not
211          * @return      void
212          */
213         public function setShowComments($val)
214         {
215                 $this->showComments = (boolean) $val;
216                 return;
217         }
218         
219         /**
220          * ItemActions::parse_blogid()
221          * Parse templatevar blogid
222          * 
223          * @param       void
224          * @return      void
225          */
226         public function parse_blogid()
227         {
228                 echo $this->blog->getID();
229         }
230
231         /**
232          * ItemActions::parse_body()
233          * Parse templatevar body
234          * 
235          * @param       void
236          * @return      void
237          */
238         public function parse_body()
239         {
240                 $this->highlightAndParse($this->currentItem['body']);
241                 return;
242         }
243         
244         /**
245          * ItemActions::parse_more()
246          * Parse templatevar more
247          * 
248          * @param       void
249          * @return      void
250          */
251         public function parse_more()
252         {
253                 $this->highlightAndParse($this->currentItem['more']);
254                 return;
255         }
256         
257         /**
258          * ItemActions::parse_itemid()
259          * Parse templatevar itemid
260          * 
261          * @param       void
262          * @return      void
263          */
264         public function parse_itemid()
265         {
266                 echo $this->currentItem['itemid'];
267                 return;
268         }
269         
270         /**
271          * ItemActions::parse_category()
272          * Parse templatevar category
273          * 
274          * @param       void
275          * @return      void
276          */
277         public function parse_category()
278         {
279                 echo $this->currentItem['category'];
280                 return;
281         }
282         
283         /**
284          * ItemActions::parse_categorylink()
285          * Parse templatevar categorylink
286          * 
287          * @param       void
288          * @return      void
289          */
290         public function parse_categorylink()
291         {
292                 echo Link::create_link('category', array('catid' => $this->currentItem['catid'], 'name' => $this->currentItem['category']));
293                 return;
294         }
295         
296         /**
297          * ItemActions::parse_catid()
298          * Parse templatevar catid
299          * 
300          * @param       void
301          * @return      void
302          */
303         public function parse_catid()
304         {
305                 echo $this->currentItem['catid'];
306                 return;
307         }
308         
309         /**
310          * ItemActions::parse_authorid()
311          * Parse templatevar authorid
312          * 
313          * @param       void
314          * @return      void
315          */
316         public function parse_authorid()
317         {
318                 echo $this->currentItem['authorid'];
319                 return;
320         }
321         
322         /**
323          * ItemActions::parse_authorlink()
324          * Parse templatevar authorlink
325          * 
326          * @param       void
327          * @return      void
328          */
329         public function parse_authorlink()
330         {
331                 $data = array(
332                                 'memberid' => $this->currentItem['authorid'],
333                                 'name' => $this->currentItem['author'],
334                                 'extra' => $this->linkparams
335                         );
336                 
337                 echo Link::create_link('member', $data);
338                 return;
339         }
340         
341         /**
342          * ItemActions::parse_query()
343          * Parse templatevar query
344          * 
345          * @param       void
346          * @return      void
347          */
348         public function parse_query()
349         {
350                 echo $this->strHighlight;
351                 return;
352         }
353         
354         /**
355          * ItemActions::parse_itemlink()
356          * Parse templatevar itemlink
357          * 
358          * @param       void
359          * @return      void
360          */
361         public function parse_itemlink()
362         {
363                 $data = array(
364                         'itemid'        => $this->currentItem['itemid'],
365                         'title'         => $this->currentItem['title'],
366                         'timestamp'     => $this->currentItem['timestamp'],
367                         'extra'         => $this->linkparams
368                 );
369                 
370                 echo Link::create_link('item', $data);
371                 return;
372         }
373         
374         /**
375          * ItemActions::parse_blogurl()
376          * Parse templatevar blogurl
377          * 
378          * @param       void
379          * @return      void
380          */
381         public function parse_blogurl()
382         {
383                 echo $this->blog->getURL();
384                 return;
385         }
386         
387         /**
388          * ItemActions::parse_closed()
389          * Parse templatevar closed
390          * 
391          * @param       void
392          * @return      void
393          */
394         public function parse_closed()
395         {
396                 echo $this->currentItem['closed'];
397                 return;
398         }
399         
400         /**
401          * ItemActions::parse_relevance()
402          * Parse templatevar relevance
403          * 
404          * @param       void
405          * @return      void
406          */
407         public function parse_relevance()
408         {
409                 echo round($this->currentItem['score'], 2);
410                 return;
411         }
412         
413         /**
414          * ItemActions::parse_title()
415          * Parse templatevar title
416          *
417          * @param       string  $format defines in which format the title is shown
418          * @return      void
419          */
420         public function parse_title($format = '')
421         {
422                 if ( is_array($this->currentItem) )
423                 {
424                         $itemtitle = $this->currentItem['title'];
425                 }
426                 switch ( $format )
427                 {
428                         case 'xml':
429                                 echo Entity::hen($itemtitle);
430                                 break;
431                         case 'attribute':
432                                 echo Entity::hsc($itemtitle);
433                                 break;
434                         case 'raw':
435                                 echo $itemtitle;
436                                 break;
437                         default:
438                                 $this->highlightAndParse($itemtitle);
439                                 break;
440                 }
441                 return;
442         }
443         
444         /**
445          * ItemActions::parse_karma()
446          * Parse templatevar karma
447          * 
448          * @param       string  $type   type of data for karma
449          * @return      void
450          */
451         public function parse_karma($type = 'totalscore')
452         {
453                 global $manager;
454                 
455                 // get karma object
456                 $karma =& $manager->getKarma($this->currentItem['itemid']);
457                 
458                 switch ( $type )
459                 {
460                         case 'pos':
461                                 echo $karma->getNbPosVotes();
462                                 break;
463                         case 'neg':
464                                 echo $karma->getNbNegVotes();
465                                 break;
466                         case 'votes':
467                                 echo $karma->getNbOfVotes();
468                                 break;
469                         case 'posp':
470                                 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbPosVotes() / $karma->getNbOfVotes()) : 50;
471                                 echo number_format($percentage,2), '%';
472                                 break;
473                         case 'negp':
474                                 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbNegVotes() / $karma->getNbOfVotes()) : 50;
475                                 echo number_format($percentage,2), '%';
476                                 break;
477                         case 'totalscore':
478                         default:
479                                 echo $karma->getTotalScore();
480                                 break;
481                 }
482                 return;
483         }
484         
485         /**
486          * ItemActions::parse_author()
487          * Parse templatevar author
488          * 
489          * @param       string  $which  key of data for author
490          * @return      void
491          */
492         public function parse_author($which = '')
493         {
494                 switch ( $which )
495                 {
496                         case 'realname':
497                                 echo $this->currentItem['authorname'];
498                                 break;
499                         case 'id':
500                                 echo $this->currentItem['authorid'];
501                                 break;
502                         case 'email':
503                                 echo $this->currentItem['authormail'];
504                                 break;
505                         case 'url':
506                                 echo $this->currentItem['authorurl'];
507                                 break;
508                         case 'name':
509                         default:
510                                 echo $this->currentItem['author'];
511                 }
512                 return;
513         }
514         
515         /**
516          * ItemActions::parse_smartbody()
517          * Parse templatevar smartbody
518          * 
519          * @param       void
520          * @return      void
521          */
522         public function parse_smartbody()
523         {
524                 if ( !$this->currentItem['more'] )
525                 {
526                         $this->highlightAndParse($this->currentItem['body']);
527                 }
528                 else
529                 {
530                         $this->highlightAndParse($this->currentItem['more']);
531                 }
532                 return;
533         }
534         
535         /**
536          * ItemActions::parse_morelink()
537          * Parse templatevar morelink
538          */
539         public function parse_morelink()
540         {
541                 if ( $this->currentItem['more'] )
542                 {
543                         $this->parser->parse($this->template['MORELINK']);
544                 }
545                 return;
546         }
547         
548         /**
549          * ItemActions::parse_date()
550          * Parse templatevar date
551          *
552          * @param       string  $format format optional strftime format
553          * @return      void
554          */
555         public function parse_date($format = '')
556         {
557                 if ( $format !== '' )
558                 {
559                         /* do nothing */
560                         ;
561                 }
562                 else if ( !array_key_exists('FORMAT_DATE', $this->template) || $this->template['FORMAT_DATE'] === '' )
563                 {
564                         /* depends on the PHP's current locale */
565                         $format = '%X';
566                 }
567                 else
568                 {
569                         $format = $this->template['FORMAT_DATE'];
570                 }
571                 
572                 $offset = 0;
573                 if ( $this->blog )
574                 {
575                         $offset = $this->blog->getTimeOffset() * 3600;
576                 }
577                 
578                 echo i18n::formatted_datetime($format, $this->currentItem['timestamp'], $offset);
579                 return;
580         }
581         
582         /**
583          * ItemActions::parse_time()
584          * Parse templatevar time
585          *
586          * @param       string  $format format optional strftime format
587          * @return      void
588          */
589         public function parse_time($format = '')
590         {
591                 if ( $format !== '' )
592                 {
593                         /* do nothing */
594                         ;
595                 }
596                 else if ( !array_key_exists('FORMAT_TIME', $this->template) || $this->template['FORMAT_TIME'] === '' )
597                 {
598                         /* depends on the PHP's current locale */
599                         $format = '%x';
600                 }
601                 else
602                 {
603                         $format = $this->template['FORMAT_TIME'];
604                 }
605                 echo i18n::formatted_datetime($format, $this->currentItem['timestamp']);
606                 return;
607         }
608         
609         /**
610          * ItemActions::parse_syndicate_title()
611          * Parse templatevar syndicate_title
612          *
613          * @param       string  $maxLength      maxLength optional maximum length
614          * @return      string  syndicated      title
615          */
616         public function parse_syndicate_title($maxLength = 100) {
617                 $syndicated = strip_tags($this->currentItem['title']);
618                 echo Entity::hsc(Entity::shorten($syndicated,$maxLength,'...'));
619         }
620         
621         /**
622          * ItemActions::parse_syndicate_description()
623          * Parse templatevar syndicate_description
624          *
625          * @param       stromg  $maxLength              maxlength optional maximum length
626          * @param       string  $addHighlight   highlighted string
627          * @return      void
628          */
629         public function parse_syndicate_description($maxLength = 250, $addHighlight = 0)
630         {
631                 $syndicated = strip_tags($this->currentItem['body']);
632                 if ( $addHighlight )
633                 {
634                         $tmp_highlight = Entity::hsc(Entity::shorten($syndicated,$maxLength,'...'));
635                         echo $this->highlightAndParse($tmp_highlight);
636                 }
637                 else
638                 {
639                         echo Entity::hsc(Entity::shorten($syndicated,$maxLength,'...'));
640                 }
641                 return;
642         }
643         
644         /**
645          * ItemActions::parse_karmaposlink()
646          * Parse templatevar karmaposlink
647          *
648          * @param       string  $text   text element for anchor element
649          * @return      void
650          */
651         public function parse_karmaposlink($text = '')
652         {
653                 global $CONF;
654                 $link = $CONF['ActionURL'] . '?action=votepositive&amp;itemid=' . $this->currentItem['itemid'];
655                 if ( !$text )
656                 {
657                         echo '<a href="'.$link.'">' . $text . '</a>';
658                 }
659                 else
660                 {
661                         echo $link;
662                 }
663                 
664                 return;
665         }
666         
667         /**
668          * ItemActions::parse_karmaneglink()
669          * Parse templatevar karmaneglink
670          *
671          * @param       string $text    text element for anchor element
672          * @return      void
673          */
674         public function parse_karmaneglink($text = '')
675         {
676                 global $CONF;
677                 $link = $CONF['ActionURL'] . '?action=votenegative&amp;itemid='.$this->currentItem['itemid'];
678                 
679                 if ( !$text )
680                 {
681                         echo '<a href="'.$link.'">' . $text . '</a>';
682                 }
683                 else
684                 {
685                         echo $link;
686                 }
687                 
688                 return;
689         }
690
691         /**
692          * ItemActions::parse_new()
693          * Parse templatevar new
694          * 
695          * @param       void
696          * @return      void
697          */
698         public function parse_new()
699         {
700                 if ( ($this->lastVisit != 0) && ($this->currentItem['timestamp'] > $this->lastVisit) )
701                 {
702                         echo $this->template['NEW'];
703                 }
704                 return;
705         }
706         
707         /**
708          * ItemActions::parse_daylink()
709          * Parse templatevar daylink
710          * 
711          * @param       void
712          * @return      void
713          */
714         public function parse_daylink()
715         {
716                 echo Link::create_archive_link($this->blog->getID(), i18n::formatted_datetime('%Y-%m-%d', $this->currentItem['timestamp']), $this->linkparams);
717                 return;
718         }
719         
720         /**
721          * ItemActions::parse_comments(
722          * Parse templatevar comments
723          * 
724          * @param       integer $maxToShow      maximum number of comments in a display
725          * @return      void
726          */
727         public function parse_comments($maxToShow = 0)
728         {
729                 if ( $maxToShow == 0 )
730                 {
731                         $maxToShow = $this->blog->getMaxComments();
732                 }
733                 
734                 // add comments
735                 if ( $this->showComments && $this->blog->commentsEnabled() )
736                 {
737                         $comments = new Comments($this->currentItem['itemid']);
738                         $comments->setItemActions($this);
739                         $comments->showComments($this->template, $maxToShow, $this->currentItem['closed'] ? 0 : 1, $this->strHighlight);
740                 }
741                 return;
742         }
743         
744         /**
745          * ItemActions::parse_plugin()
746          * Executes a plugin templatevar
747          *
748          * @param       string  $pluginName     name of plugin (without the NP_)
749          * @param       extra parameters can be added
750          * @return      void
751          */
752         public function parse_plugin($pluginName)
753         {
754                 global $manager;
755                 
756                 $plugin =& $manager->getPlugin("NP_{$pluginName}");
757                 if ( !$plugin )
758                 {
759                         return;
760                 }
761                 
762                 // get arguments
763                 $params = func_get_args();
764                 
765                 // remove plugin name
766                 array_shift($params);
767                 
768                 // add item reference (array_unshift didn't work)
769                 $params = array_merge(array(&$this->currentItem),$params);
770                 
771                 call_user_func_array(array(&$plugin,'doTemplateVar'), $params);
772                 return;
773         }
774         
775         /**
776          * ItemActions::parse_edit()
777          * Parse templatevar edit
778          * 
779          * @param       void
780          * @return      void
781          */
782         public function parse_edit()
783         {
784                 global $member, $CONF;
785                 if ( $this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem['authorid'])) )
786                 {
787                         $this->parser->parse($this->template['EDITLINK']);
788                 }
789                 return;
790         }
791         
792         /**
793          * ItemActions::parse_editlink()
794          * Parse templatevar editlink
795          */
796         public function parse_editlink()
797         {
798                 global $CONF;
799                 echo $CONF['AdminURL'] . 'bookmarklet.php?action=edit&amp;itemid=' . $this->currentItem['itemid'];
800                 return;
801         }
802         
803         /**
804          * ItemActions::parse_editpopupcode()
805          * Parse templatevar editpopupcode
806          * 
807          * @param       void
808          * @return      void
809          */
810         public function parse_editpopupcode()
811         {
812                 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;";
813                 return;
814         }
815         
816         /**
817          * ItemActions::highlightAndParse()
818          * Parses highlighted text, with limited actions only (to prevent not fully trusted team members
819          * from hacking your weblog.
820          * 'plugin variables in items' implementation by Andy
821          * 
822          * @param       array   $data   
823          * @return      void
824          */
825         public function highlightAndParse(&$data)
826         {
827                 $handler = new BodyActions($this->blog);
828                 $parser = new Parser($handler->getDefinedActions(), $handler);
829                 $handler->setTemplate($this->template);
830                 $handler->setHighlight($this->strHighlight);
831                 $handler->setCurrentItem($this->currentItem);
832                 $parser->parse($handler->highlight($data));
833                 return;
834         }
835         
836         /**
837          * ItemActions::checkCondition()
838          * Checks conditions for if statements
839          *
840          * @param       string  $field  type of <%if%>
841          * @param       string  $name   property of field
842          * @param       string  $value  value of property
843          * @return      boolean
844          */
845         protected function checkCondition($field, $name='', $value = '')
846         {
847                 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
848                 
849                 $condition = 0;
850                 switch ( $field )
851                 {
852                         case 'category':
853                                 $condition = ($blog && $this->ifCategory($name,$value));
854                                 break;
855                         case 'itemcategory':
856                                 $condition = ($this->ifItemCategory($name,$value));
857                                 break;
858                         case 'blogsetting':
859                                 $condition = ($blog && ($blog->getSetting($name) == $value));
860                                 break;
861                         case 'itemblogsetting':
862                                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid']));
863                                 $condition = ($b && ($b->getSetting($name) == $value));
864                                 break;
865                         case 'loggedin':
866                                 $condition = $member->isLoggedIn();
867                                 break;
868                         case 'onteam':
869                                 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
870                                 break;
871                         case 'admin':
872                                 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
873                                 break;
874                         case 'author':
875                                 $condition = ($this->ifAuthor($name,$value));
876                                 break;
877                         case 'hasplugin':
878                                 $condition = $this->ifHasPlugin($name, $value);
879                                 break;
880                         default:
881                                 $condition = $manager->pluginInstalled('NP_' . $field) && $this->ifPlugin($field, $name, $value);
882                                 break;
883                 }
884                 return $condition;
885         }       
886         
887         /**
888          * ItemActions::ifCategory()
889          *  Different checks for a category
890          *  
891          * @param       string  $key    key of category
892          * @param       string  $value  value for key of category
893          * @return      boolean
894          */
895         private function ifCategory($key = '', $value = '')
896         {
897                 global $blog, $catid;
898                 
899                 // when no parameter is defined, just check if a category is selected
900                 if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
901                 {
902                         return (boolean) $blog->isValidCategory($catid);
903                 }
904                 
905                 // check category name
906                 if ( $key == 'catname' )
907                 {
908                         $value = $blog->getCategoryIdFromName($value);
909                         if ( $value == $catid )
910                         {
911                                 return (boolean) $blog->isValidCategory($catid);
912                         }
913                 }
914                 
915                 // check category id
916                 if ( ($key == 'catid') && ($value == $catid) )
917                 {
918                         return (boolean) $blog->isValidCategory($catid);
919                 }
920                 return FALSE;
921         }
922         
923         /**
924          * ItemActions::ifAuthor()
925          * Different checks for an author
926          * 
927          * @param       string  $key    key of data for author
928          * @param       string  $value  value of data for author
929          * @return      boolean correct or not
930          */
931         private function ifAuthor($key = '', $value = '')
932         {
933                 global $member, $manager;
934                 
935                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid']));
936                 
937                 // when no parameter is defined, just check if author is current visitor
938                 if ( ($key != 'isadmin' && $key != 'name') || ($key == 'name' && $value == '') )
939                 {
940                         return (boolean) ((integer) $member->getID() > 0 && (integer) $member->getID() == (integer) $this->currentItem['authorid']);
941                 }
942                 
943                 // check author name
944                 if ( $key == 'name' )
945                 {
946                         $value = strtolower($value);
947                         if ( $value == strtolower($this->currentItem['author']) )
948                         {
949                                 return TRUE;
950                         }
951                 }
952                 
953                 // check if author is admin
954                 if ( ($key == 'isadmin') )
955                 {
956                         $aid = intval($this->currentItem['authorid']);
957                         $blogid = intval($b->getID());                  
958                         $amember =& $manager->getMember($aid);
959                         if ( $amember->isAdmin() )
960                         {
961                                 return TRUE;
962                         }
963                         return (boolean) $amember->isBlogAdmin($blogid);
964                 }
965                 
966                 return FALSE;
967         }
968         
969         /**
970          * ItemActions::ifItemCategory()
971          * Different checks for a category
972          * 
973          * @param       string  $key    key of data for category to which item belongs
974          * @param       string  $value  value of data for category to which item belongs
975          * @return boolean      correct or not
976          */
977         private function ifItemCategory($key = '', $value='')
978         {
979                 global $catid, $manager;
980                 
981                 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid']));
982                 
983                 // when no parameter is defined, just check if a category is selected
984                 if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
985                 {
986                         return (boolean) $b->isValidCategory($catid);
987                 }
988                 
989                 $icatid = $this->currentItem['catid'];
990                 
991                 // check category name
992                 if ( $key == 'catname' )
993                 {
994                         $value = $b->getCategoryIdFromName($value);
995                         if ( $value == $icatid )
996                         {
997                                 return (boolean) $b->isValidCategory($icatid);
998                         }
999                 }
1000                 
1001                 // check category id
1002                 if ( ($key == 'catid') && ($value == $icatid) )
1003                 {
1004                         return (boolean) $b->isValidCategory($icatid);
1005                 }
1006                 return FALSE;
1007         }
1008
1009         
1010         /**
1011          * ItemActions::ifOnTeam()
1012          * Checks if a member is on the team of a blog and return his rights
1013          * 
1014          * @param       string  $blogName       name of weblog
1015          * @return      boolean correct or not
1016          */
1017         private function ifOnTeam($blogName = '')
1018         {
1019                 global $blog, $member, $manager;
1020                 
1021                 // when no blog found
1022                 if ( ($blogName == '') && (!is_object($blog)) )
1023                 {
1024                         return 0;
1025                 }
1026                 
1027                 // explicit blog selection
1028                 if ( $blogName != '' )
1029                 {
1030                         $blogid = getBlogIDFromName($blogName);
1031                 }
1032                 
1033                 // use current blog
1034                 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
1035                 {
1036                         $blogid = $blog->getID();
1037                 }
1038                 return (boolean) $member->teamRights($blogid);
1039         }
1040         
1041         /**
1042          * ItemActions::ifAdmin()
1043          * Checks if a member is admin of a blog
1044          * 
1045          * @param       string  $blogName       name of weblog
1046          * @return      boolean correct or not
1047          */
1048         private function ifAdmin($blogName = '')
1049         {
1050                 global $blog, $member, $manager;
1051                 
1052                 // when no blog found
1053                 if ( ($blogName == '') && (!is_object($blog)) )
1054                 {
1055                         return 0;
1056                 }
1057                 
1058                 // explicit blog selection
1059                 if ( $blogName != '' )
1060                 {
1061                         $blogid = getBlogIDFromName($blogName);
1062                 }
1063                 
1064                 // use current blog
1065                 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
1066                 {
1067                         $blogid = $blog->getID();
1068                 }
1069                 return (boolean) $member->isBlogAdmin($blogid);
1070         }
1071         
1072         
1073         /**
1074          * ItemActions::ifHasPlugin()
1075          *      hasplugin,PlugName
1076          *         -> checks if plugin exists
1077          *      hasplugin,PlugName,OptionName
1078          *         -> checks if the option OptionName from plugin PlugName is not set to 'no'
1079          *      hasplugin,PlugName,OptionName=value
1080          *         -> checks if the option OptionName from plugin PlugName is set to value
1081          *
1082          * @param       string  $name   name of plugin
1083          * @param       string  $value  key (and value) of plugin option
1084          * @return      boolean correct or not
1085          */
1086         private function ifHasPlugin($name, $value)
1087         {
1088                 global $manager;
1089                 $condition = FALSE;
1090                 // (pluginInstalled method won't write a message in the actionlog on failure)
1091                 if ( $manager->pluginInstalled("NP_{$name}"))
1092                 {
1093                         $plugin =& $manager->getPlugin('NP_' . $name);
1094                         if ( $plugin != NULL )
1095                         {
1096                                 if ( $value == "" )
1097                                 {
1098                                         $condition = TRUE;
1099                                 }
1100                                 else
1101                                 {
1102                                         list($name2, $value2) = preg_split('#=#', $value, 2);
1103                                         if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
1104                                         {
1105                                                 $condition = TRUE;
1106                                         }
1107                                         else if ( $plugin->getOption($name2) == $value2 )
1108                                         {
1109                                                 $condition = TRUE;
1110                                         }
1111                                 }
1112                         }
1113                 }
1114                 return (boolean) $condition;
1115         }
1116         
1117         /**
1118          * ItemActions::ifPlugin()
1119          * Checks if a plugin exists and call its doIf function
1120          * 
1121          * @param       string  $name   name of plugin
1122          * @param       string  $key    key of plugin option
1123          * @param       string  $value  value of plugin option
1124          * @return      boolean callback output from plugin
1125          */
1126         private function ifPlugin($name, $key = '', $value = '')
1127         {
1128                 global $manager;
1129                 
1130                 $plugin =& $manager->getPlugin("NP_{$name}");
1131                 if ( !$plugin )
1132                 {
1133                         return;
1134                 }
1135                 $params = func_get_args();
1136                 array_shift($params);
1137                 
1138                 return (boolean) call_user_func_array(array(&$plugin, 'doIf'), $params);
1139         }
1140 }