OSDN Git Service

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