OSDN Git Service

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