OSDN Git Service

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