OSDN Git Service

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