OSDN Git Service

CHANGE/REMOVE: <%text%>タグをスキンのどのコンテクストでも利用可能に。NP_Textの廃止。
[nucleus-jp/nucleus-next.git] / nucleus / libs / ACTIONS.php
1 <?php
2 /**
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2012 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 contains the functions that get called by using
14  * the special tags in the skins
15  *
16  * The allowed tags for a type of skinpart are defined by the
17  * Skin::getAllowedActionsForType($type) method
18  *
19  * @license http://nucleuscms.org/license.txt GNU General Public License
20  * @copyright Copyright (C) 2002-2012 The Nucleus Group
21  * @version $Id: ACTIONS.php 1784 2012-04-22 04:28:30Z sakamocchi $
22  */
23
24 class Actions extends BaseActions
25 {
26         // part of the skin currently being parsed ('index', 'item', 'archive',
27         // 'archivelist', 'member', 'search', 'error', 'imagepopup')
28         private $skintype;
29         
30         // contains an assoc array with parameters that need to be included when
31         // generating links to items/archives/... (e.g. catid)
32         private $linkparams;
33         
34         // reference to the skin object for which a part is being parsed
35         private $skin;
36         
37         // used when including templated forms from the include/ dir. The $formdata var
38         // contains the values to fill out in there (assoc array name -> value)
39         private $formdata;
40         
41         // filled out with the number of displayed items after calling one of the
42         // (other)blog/(other)searchresults skinvars.
43         private $amountfound;
44         
45         /**
46          * Actions::$default_actions
47          * list of whole action names with which this class can deal
48          */
49         static private $default_actions = array(
50                 'addlink',
51                 'addpopupcode',
52                 'adminurl',
53                 'archivelink',
54                 'bloglist',
55                 'category',
56                 'charset',
57                 'loginform',
58                 'member',
59                 'nucleusbutton',
60                 'otherarchivedaylist',
61                 'otherarchivelist',
62                 'otherarchiveyearlist',
63                 'otherblog',
64                 'plugin',
65                 'referer',
66                 'searchform',
67                 'self',
68                 'sitevar',
69                 'skinname',
70                 'sticky',
71                 'todaylink',
72                 'version',
73                 // deprecated (Nucleus v2.0)
74                 /* TODO: remove this */
75                 'ifcat'
76         );
77         
78         /**
79          * Actions::$skin_type_friendly_names
80          * friendly name for wrapped page types
81          */
82         static public $default_skin_types = array(
83                 'index'                 => _SKIN_PART_MAIN,
84                 'item'                  => _SKIN_PART_ITEM,
85                 'archivelist'   => _SKIN_PART_ALIST,
86                 'archive'               => _SKIN_PART_ARCHIVE,
87                 'search'                => _SKIN_PART_SEARCH,
88                 'error'                 => _SKIN_PART_ERROR,
89                 'member'                => _SKIN_PART_MEMBER,
90                 'imagepopup'    => _SKIN_PART_POPUP
91         );
92         
93         /**
94          * Actions::getDefinedActions()
95          * 
96          * @static
97          * @param       string  $type   page type
98          * @return      array   allowed actions for the page type
99          */
100         static public function getDefinedActions($type='')
101         {
102                 $extra_actions = array();
103                 
104                 switch ( $type )
105                 {
106                         case 'index':
107                                 $extra_actions = array(
108                                         'blog',
109                                         'blogsetting',
110                                         'preview',
111                                         'additemform',
112                                         'categorylist',
113                                         'archivelist',
114                                         'archivedaylist',
115                                         'archiveyearlist',
116                                         'nextlink',
117                                         'prevlink'
118                                 );
119                                 break;
120                         case 'archive':
121                                 $extra_actions = array(
122                                         'blog',
123                                         'archive',
124                                         'otherarchive',
125                                         'categorylist',
126                                         'archivelist',
127                                         'archivedaylist',
128                                         'archiveyearlist',
129                                         'blogsetting',
130                                         'archivedate',
131                                         'nextarchive',
132                                         'prevarchive',
133                                         'nextlink',
134                                         'prevlink',
135                                         'archivetype'
136                                 );
137                                 break;
138                         case 'archivelist':
139                                 $extra_actions = array(
140                                         'blog',
141                                         'archivelist',
142                                         'archivedaylist',
143                                         'archiveyearlist',
144                                         'categorylist',
145                                         'blogsetting'
146                                 );
147                                 break;
148                         case 'search':
149                                 $extra_actions = array(
150                                         'blog',
151                                         'archivelist',
152                                         'archivedaylist',
153                                         'archiveyearlist',
154                                         'categorylist',
155                                         'searchresults',
156                                         'othersearchresults',
157                                         'blogsetting',
158                                         'query',
159                                         'nextlink',
160                                         'prevlink'
161                                 );
162                                 break;
163                         case 'imagepopup':
164                                 $extra_actions = array(
165                                         'image',
166                                         // deprecated (Nucleus v2.0)
167                                         /* TODO: remove this */
168                                         'imagetext'
169                                 );
170                                 break;
171                         case 'member':
172                                 $extra_actions = array(
173                                         'membermailform',
174                                         'blogsetting',
175                                         'nucleusbutton',
176                                         'categorylist'
177                                 );
178                                 break;
179                         case 'item':
180                                 $extra_actions = array(
181                                         'blog',
182                                         'item',
183                                         'comments',
184                                         'commentform',
185                                         'vars',
186                                         'blogsetting',
187                                         'nextitem',
188                                         'previtem',
189                                         'nextlink',
190                                         'prevlink',
191                                         'nextitemtitle',
192                                         'previtemtitle',
193                                         'categorylist',
194                                         'archivelist',
195                                         'archivedaylist',
196                                         'archiveyearlist',
197                                         'itemtitle',
198                                         'itemid',
199                                         'itemlink'
200                                 );
201                                 break;
202                         case 'error':
203                                 $extra_actions = array(
204                                         'errormessage',
205                                         'categorylist'
206                                 );
207                                 break;
208                         default:
209                                         $extra_actions = array(
210                                                 'blog',
211                                                 'blogsetting',
212                                                 'preview',
213                                                 'additemform',
214                                                 'categorylist',
215                                                 'archivelist',
216                                                 'archivedaylist',
217                                                 'archiveyearlist',
218                                                 'nextlink',
219                                                 'prevlink',
220                                                 'membermailform',
221                                                 'nucleusbutton',
222                                                 'categorylist'
223                                         );
224                                 break;
225                 }
226                 
227                 $defined_actions = array_merge(self::$default_actions, $extra_actions);
228                 
229                 return array_merge($defined_actions, parent::getDefinedActions());
230         }
231         
232         /**
233          * Actions::getDefaultSkinTypes()
234          * 
235          * @static
236          * @param       void
237          * @return      array   list of friendly names for page actions
238          */
239         static public function getDefaultSkinTypes()
240         {
241                 return self::$default_skin_types;
242         }
243         
244         /**
245          * Actions::__construct()
246          * Constructor for a new Actions object
247          * 
248          * @param       string  $type
249          * @return      void
250          */
251         public function __construct($type)
252         {
253                 global $catid;
254                 
255                 // call constructor of superclass first
256                 parent::__construct();
257                 $this->skintype = $type;
258                 
259                 if ( $catid )
260                 {
261                         $this->linkparams = array('catid' => $catid);
262                 }
263                 return;
264         }
265         
266         /**
267          * Actions::setSkin()
268          * Set the skin
269          * @param       object  $skin   an instance of Skin class
270          * @return      void
271          */
272         public function setSkin(&$skin)
273         {
274                 $this->skin =& $skin;
275                 return;
276         }
277         
278         /**
279          * Actions::setParser()
280          * Set the parser
281          * 
282          * @param       object  $parser an instance of Parser class
283          * @return      void
284          */
285         public function setParser(&$parser)
286         {
287                 $this->parser =& $parser;
288                 return;
289         }
290         
291         /**
292          * Actions::doForm()
293          * Forms get parsedincluded now, using an extra <formdata> skinvar
294          *
295          * @param       string  $filename
296          * @return      void
297          */
298         public function doForm($filename)
299         {
300                 global $DIR_NUCLEUS;
301                 array_push($this->parser->actions,'formdata', 'callback','errordiv','ticket');
302                 
303                 $oldIncludeMode = Parser::getProperty('IncludeMode');
304                 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
305                 Parser::setProperty('IncludeMode','normal');
306                 Parser::setProperty('IncludePrefix','');
307                 
308                 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
309                 Parser::setProperty('IncludeMode',$oldIncludeMode);
310                 Parser::setProperty('IncludePrefix',$oldIncludePrefix);
311                 
312                 array_pop($this->parser->actions);      // errordiv
313                 array_pop($this->parser->actions);      // callback
314                 array_pop($this->parser->actions);      // formdata
315                 array_pop($this->parser->actions);      // ticket
316                 return;
317         }
318
319         /**
320          * Actions::checkCondition()
321          * Checks conditions for if statements
322          *
323          * @param       string  $field  type of <%if%>
324          * @param       string  $name   property of field
325          * @param       string  $value  value of property
326          * @return      boolean condition
327          */
328         protected function checkCondition($field, $name='', $value = '')
329         {
330                 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
331                 
332                 $condition = 0;
333                 switch ( $field )
334                 {
335                         case 'category':
336                                 $condition = ($blog && $this->ifCategory($name,$value));
337                                 break;
338                         case 'blogsetting':
339                                 $condition = ($blog && ($blog->getSetting($name) == $value));
340                                 break;
341                         case 'loggedin':
342                                 $condition = $member->isLoggedIn();
343                                 break;
344                         case 'onteam':
345                                 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
346                                 break;
347                         case 'admin':
348                                 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
349                                 break;
350                         case 'nextitem':
351                                 $condition = ($itemidnext != '');
352                                 break;
353                         case 'previtem':
354                                 $condition = ($itemidprev != '');
355                                 break;
356                         case 'archiveprevexists':
357                                 $condition = ($archiveprevexists == true);
358                                 break;
359                         case 'archivenextexists':
360                                 $condition = ($archivenextexists == true);
361                                 break;
362                         case 'skintype':
363                                 $condition = (($name == $this->skintype) || ($name == requestVar('action')));
364                                 break;
365                         case 'hasplugin':
366                                 $condition = $this->ifHasPlugin($name, $value);
367                                 break;
368                         default:
369                                 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);
370                                 break;
371                 }
372                 return $condition;
373         }
374         
375         /**
376          * Actions::_ifHasPlugin()
377          *      hasplugin,PlugName
378          *         -> checks if plugin exists
379          *      hasplugin,PlugName,OptionName
380          *         -> checks if the option OptionName from plugin PlugName is not set to 'no'
381          *      hasplugin,PlugName,OptionName=value
382          *         -> checks if the option OptionName from plugin PlugName is set to value
383          *
384          * @param       string  $name   name of plugin
385          * @param       string  $value  
386          * @return      
387          */
388         private function ifHasPlugin($name, $value)
389         {
390                 global $manager;
391                 $condition = false;
392                 // (pluginInstalled method won't write a message in the actionlog on failure)
393                 if ( $manager->pluginInstalled("NP_{$name}") )
394                 {
395                         $plugin =& $manager->getPlugin("NP_{$name}");
396                         if ( $plugin != NULL )
397                         {
398                                 if ( $value == "" )
399                                 {
400                                         $condition = true;
401                                 }
402                                 else
403                                 {
404                                         list($name2, $value2) = preg_split('#=#', $value, 2);
405                                         if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
406                                         {
407                                                 $condition = true;
408                                         }
409                                         else if ( $plugin->getOption($name2) == $value2 )
410                                         {
411                                                 $condition = true;
412                                         }
413                                 }
414                         }
415                 }
416                 return $condition;
417         }
418         
419         /**
420          * Actions::ifPlugin()
421          * Checks if a plugin exists and call its doIf function
422          * 
423          * @param       string  $name   name of plugin
424          * @param       string  $key    name of plugin option
425          * @param       string  $value  value of plugin option
426          * @return      void
427          */
428         private function ifPlugin($name, $key = '', $value = '')
429         {
430                 global $manager;
431                 
432                 $plugin =& $manager->getPlugin("NP_{$name}");
433                 if ( !$plugin )
434                 {
435                         return;
436                 }
437                 
438                 $params = func_get_args();
439                 array_shift($params);
440                 
441                 return call_user_func_array(array(&$plugin, 'doIf'), $params);
442         }
443         
444         /**
445          * Actions::ifCategory()
446          * Different checks for a category
447          * 
448          * @param       string  $name   
449          * @param       string  $value  
450          * @return      boolean 
451          */
452         private function ifCategory($name = '', $value='')
453         {
454                 global $blog, $catid;
455                 
456                 // when no parameter is defined, just check if a category is selected
457                 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )
458                 {
459                         return $blog->isValidCategory($catid);
460                 }
461                 
462                 // check category name
463                 if ( $name == 'catname' )
464                 {
465                         $value = $blog->getCategoryIdFromName($value);
466                         if ( $value == $catid )
467                         {
468                                 return $blog->isValidCategory($catid);
469                         }
470                 }
471                 
472                 // check category id
473                 if ( ($name == 'catid') && ($value == $catid) )
474                 {
475                         return $blog->isValidCategory($catid);
476                 }
477                 return FALSE;
478         }
479         
480         /**
481          * Actions::ifOnTeam()
482          * Checks if a member is on the team of a blog and return his rights
483          * 
484          * @param       string  $blogName       name of weblog
485          * @return      mixed
486          */
487         private function ifOnTeam($blogName = '')
488         {
489                 global $blog, $member, $manager;
490                 
491                 // when no blog found
492                 if ( ($blogName == '') && !is_object($blog) )
493                 {
494                         return 0;
495                 }
496                 
497                 // explicit blog selection
498                 if ( $blogName != '' )
499                 {
500                         $blogid = getBlogIDFromName($blogName);
501                 }
502                 
503                 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
504                 {
505                         // use current blog
506                         $blogid = $blog->getID();
507                 }
508                 
509                 return $member->teamRights($blogid);
510         }
511
512         /**
513          * Actions::ifAdmin()
514          * Checks if a member is admin of a blog
515          * 
516          * @param       string  $blogName       name of weblog
517          * @return      mixed
518          */
519         private function ifAdmin($blogName = '')
520         {
521                 global $blog, $member, $manager;
522                 
523                 // when no blog found
524                 if ( ($blogName == '') && (!is_object($blog)) )
525                 {
526                         return 0;
527                 }
528                 
529                 // explicit blog selection
530                 if ( $blogName != '' )
531                 {
532                         $blogid = getBlogIDFromName($blogName);
533                 }
534                 
535                 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
536                 {
537                         // use current blog
538                         $blogid = $blog->getID();
539                 }
540                 
541                 return $member->isBlogAdmin($blogid);
542         }
543         
544         /**
545          * Actions::link()
546          * returns either
547          *      - a raw link (html/xml encoded) when no linktext is provided
548          *      - a (x)html <a href... link when a text is present (text htmlencoded)
549          * 
550          * @param       string  $url            URL for href attribute of anchor element
551          * @param       string  $linktext       content of anchor element
552          * @return      
553          */
554         private function link($url, $linktext = '')
555         {
556                 $u = Entity::hsc($url);
557                 // fix URLs that already had encoded ampersands
558                 $u = preg_replace("#&amp;amp;#", '&amp;', $u);
559                 if ( $linktext != '' )
560                 {
561                         $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';
562                 }
563                 else
564                 {
565                         $l = $u;
566                 }
567                 return $l;
568         }
569         
570         /**
571          * Actions::searchlink()
572          * Outputs a next/prev link
573          *
574          * @param $maxresults
575          *              The maximum amount of items shown per page (e.g. 10)
576          * @param $startpos
577          *              Current start position (requestVar('startpos'))
578          * @param $direction
579          *              either 'prev' or 'next'
580          * @param $linktext
581          *              When present, the output will be a full <a href...> link. When empty,
582          *              only a raw link will be outputted
583          */
584         private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')
585         {
586                 global $CONF, $blog, $query, $amount;
587                 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
588                 $startpos       = (integer) $startpos;
589                 $parsed         = parse_url(serverVar('REQUEST_URI'));
590                 $path           = $parsed['path'];
591                 $parsed         = $parsed['query'];
592                 $url            = '';
593                 
594                 if ( $direction == 'prev' )
595                 {
596                         if ( intval($startpos) - intval($maxresults) >= 0 )
597                         {
598                                 $startpos       = intval($startpos) - intval($maxresults);
599                                 
600                                 if ( $this->skintype == 'index' )
601                                 {
602                                         $url = $path;
603                                 }
604                                 else if ( $this->skintype == 'search' )
605                                 {
606                                         $url = $CONF['SearchURL'];
607                                 }
608                                 $url .= '?' . alterQueryStr($parsed,'startpos',$startpos);
609                         }
610                 }
611                 else if ( $direction == 'next' )
612                 {
613                         global $navigationItems;
614                         if ( !isset($navigationItems) )
615                         {
616                                 $navigationItems = 0;
617                         }
618                         
619                         if ( $recount )
620                         {
621                                 $iAmountOnPage = 0;
622                         }
623                         else 
624                         {
625                                 $iAmountOnPage = $this->amountfound;
626                         }
627                         
628                         if ( intval($navigationItems) > 0 )
629                         {
630                                 $iAmountOnPage = intval($navigationItems) - intval($startpos);
631                         }
632                         elseif ( $iAmountOnPage == 0 )
633                         {
634                                 /*
635                                  * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
636                                  * try a count query
637                                  */
638                                 if ( $this->skintype == 'index' )
639                                 {
640                                         $sqlquery = $blog->getSqlBlog('', 'count');
641                                         $url = $path;
642                                 }
643                                 else if ( $this->skintype == 'search' )
644                                 {
645                                         $unused_highlight = '';
646                                         $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
647                                         $url = $CONF['SearchURL'];
648                                 }
649                                 if ( $sqlquery )
650                                 {
651                                         $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
652                                 }
653                         }
654                         
655                         $url = '';
656                         if ( intval($iAmountOnPage) >= intval($maxresults) )
657                         {
658                                 $startpos        = intval($startpos) + intval($maxresults);
659                                 $url            .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
660                         }
661                 }
662                 
663                 if ( $url != '' )
664                 {
665                         echo $this->link($url, $linktext);
666                 }
667                 return;
668         }
669         
670         /**
671          * Actions::itemlink()
672          * Creates an item link and if no id is given a todaylink 
673          * 
674          * @param       integer $id     id for link
675          * @param       string  $linktext       text for link
676          * @return      void
677          */
678         private function itemlink($id, $linktext = '')
679         {
680                 global $CONF;
681                 if ( $id != 0 )
682                 {
683                         echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);
684                 }
685                 else
686                 {
687                         $this->parse_todaylink($linktext);
688                 }
689                 return;
690         }
691         
692         /**
693          * Actions::archivelink)
694          * Creates an archive link and if no id is given a todaylink 
695          * 
696          * @param       integer $id     id for link
697          * @param       string  $linktext       text for link
698          * @return      void
699          */
700         private function archivelink($id, $linktext = '')
701         {
702                 global $CONF, $blog;
703                 if ( $id != 0 )
704                 {
705                         echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
706                 }
707                 else
708                 {
709                         $this->parse_todaylink($linktext);
710                 }
711                 return;
712         }
713         
714         /**
715          * Actions:setBlogCategory()
716          * Helper function that sets the category that a blog will need to use
717          *
718          * @param       string  $blog           An object of the blog class, passed by reference (we want to make changes to it)
719          * @param       string  $catname        The name of the category to use
720          * @return      void
721          */
722         private function setBlogCategory(&$blog, $catname)
723         {
724                 global $catid;
725                 if ( $catname != '' )
726                 {
727                         $blog->setSelectedCategoryByName($catname);
728                 }
729                 else
730                 {
731                         $blog->setSelectedCategory($catid);
732                 }
733                 return;
734         }
735         
736         /**
737          * Actions::preBlogContent()
738          * Notifies the Manager that a PreBlogContent event occurs
739          * 
740          * @param       string  $type   type of skin
741          * @param       object  $blog   an instance of Blog class
742          * @return      void
743          */
744         private function preBlogContent($type, &$blog)
745         {
746                 global $manager;
747                 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
748                 return;
749         }
750
751         /**
752          * Actions::postBlogContent()
753          * Notifies the Manager that a PostBlogContent event occurs
754          * 
755          * @param       string  $type   type of skin
756          * @param       objecct $blog   an instance of Blog class
757          * @return      void
758          */
759         private function postBlogContent($type, &$blog)
760         {
761                 global $manager;
762                 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
763                 return;
764         }
765         
766         /**
767          * Actions::parse_additemform()
768          * Parse skinvar additemform
769          * 
770          * @param       void
771          * @return      void
772          */
773         public function parse_additemform()
774         {
775                 global $blog, $CONF;
776                 $this->formdata = array(
777                         'adminurl'      => Entity::hsc($CONF['AdminURL']),
778                         'catid'         => $blog->getDefaultCategory()
779                 );
780                 $blog->InsertJavaScriptInfo();
781                 $this->doForm('additemform');
782                 return;
783         }
784         
785         /**
786          * Actions::parse_addlink()
787          * Parse skinvar addlink
788          * A Link that allows to open a bookmarklet to add an item
789          */
790         public function parse_addlink()
791         {
792                 global $CONF, $member, $blog;
793                 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
794                 {
795                         echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
796                 }
797                 return;
798         }
799         
800         /**
801          * Actions::parse_addpopupcode()
802          * Parse skinvar addpopupcode
803          * Code that opens a bookmarklet in an popup window
804          * 
805          * @param       void
806          * @return      void
807          */
808         public function parse_addpopupcode()
809         {
810                 echo "if (event &amp;&amp; event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=yes,width=600,height=500,left=10,top=10,status=yes,resizable=yes');winbm.focus();return false;";
811                 return;
812         }
813         
814         /**
815          * Parse skinvar adminurl
816          * (shortcut for admin url)
817          * 
818          * @param       void
819          * @return      void
820          */
821         public function parse_adminurl()
822         {
823                 $this->parse_sitevar('adminurl');
824                 return;
825         }
826         
827         /**
828          * Actions::parse_archive()
829          * Parse skinvar archive
830          * 
831          * @param       string  $template       name of template
832          * @param       string  $category       name of category
833          * @return      
834          */
835         public function parse_archive($template, $category = '')
836         {
837                 global $blog, $archive;
838                 // can be used with either yyyy-mm or yyyy-mm-dd
839                 sscanf($archive,'%d-%d-%d', $y, $m, $d);
840                 $this->setBlogCategory($blog, $category);
841                 $this->preBlogContent('achive',$blog);
842                 $blog->showArchive($template, $y, $m, $d);
843                 $this->postBlogContent('achive',$blog);
844                 return;
845         }
846         
847         /**
848          * Actions::parse_archivedate()
849          * %archivedate(locale,date format)%
850          * 
851          * @param       string  $locale
852          * @return      void
853          */
854         public function parse_archivedate($locale = '-def-')
855         {
856                 global $archive;
857                 
858                 /* 
859                  * TODO: these lines are no meaning because there is no $template.
860                 if ( $locale == '-def-' )
861                 {
862                         setlocale(LC_TIME, $template['LOCALE']);
863                 }
864                 else
865                 {
866                         setlocale(LC_TIME, $locale);
867                 }
868                  */
869                 
870                 // get archive date
871                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
872                 
873                 // get format
874                 $args = func_get_args();
875                 // format can be spread over multiple parameters
876                 if ( sizeof($args) > 1 )
877                 {
878                         // take away locale
879                         array_shift($args);
880                         // implode
881                         $format=implode(',',$args);
882                 }
883                 elseif ( $d == 0 && $m !=0 )
884                 {
885                         $format = '%B %Y';
886                 }
887                 elseif ( $m == 0 )
888                 {
889                         $format = '%Y';
890                 }
891                 else
892                 {
893                         $format = '%d %B %Y';
894                 }
895                 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
896                 return;
897         }
898         
899         /**
900          * Actions::parse_archivedaylist()
901          * Parse skinvar archivedaylist
902          * 
903          * @param       string  $template       name of template
904          * @param       string  $category       name of category
905          * @param       integer $limit          the number of items in a display
906          * @return      void
907          */
908         public function parse_archivedaylist($template, $category = 'all', $limit = 0)
909         {
910                 global $blog;
911                 if ( $category == 'all' )
912                 {
913                         $category = '';
914                 }
915                 $this->preBlogContent('archivelist',$blog);
916                 $this->setBlogCategory($blog, $category);
917                 $blog->showArchiveList($template, 'day', $limit);
918                 $this->postBlogContent('archivelist',$blog);
919                 return;
920         }
921         
922         /**
923          * Actions::parse_archivelink()
924          * A link to the archives for the current blog (or for default blog)
925          * 
926          * @param       string  $linktext       text for link
927          * @return      void
928          */
929         public function parse_archivelink($linktext = '')
930         {
931                 global $blog, $CONF;
932                 if ( $blog )
933                 {
934                         echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
935                 }
936                 else
937                 {
938                         echo $this->link(Link::create_archivelist_link(), $linktext);
939                 }
940                 return;
941         }
942         
943         /**
944          * Actions::parse_archivelist()
945          * 
946          * @param       string  $template       name of template
947          * @param       string  $category       name of category
948          * @param       integer $limit          the number of items in a display
949          * @return      void
950          */
951         public function parse_archivelist($template, $category = 'all', $limit = 0)
952         {
953                 global $blog;
954                 if ( $category == 'all' )
955                 {
956                         $category = '';
957                 }
958                 $this->preBlogContent('archivelist',$blog);
959                 $this->setBlogCategory($blog, $category);
960                 $blog->showArchiveList($template, 'month', $limit);
961                 $this->postBlogContent('archivelist',$blog);
962                 return;
963         }
964         
965         /**
966          * Actions::parse_archiveyearlist()
967          * 
968          * @param       string  $template       name of template
969          * @param       string  $category       name of category
970          * @param       integer $limit          the number of items in a display
971          */
972         public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
973         {
974                 global $blog;
975                 if ( $category == 'all' )
976                 {
977                         $category = '';
978                 }
979                 $this->preBlogContent('archivelist',$blog);
980                 $this->setBlogCategory($blog, $category);
981                 $blog->showArchiveList($template, 'year', $limit);
982                 $this->postBlogContent('archivelist',$blog);
983                 return;
984         }
985         
986         /**
987          * Actions::parse_archivetype()
988          * Parse skinvar archivetype
989          * 
990          * @param       void
991          * @return      void
992          */
993         public function parse_archivetype()
994         {
995                 global $archivetype;
996                 echo $archivetype;
997                 return;
998         }
999         
1000         /**
1001          * Actions::parse_blog()
1002          * Parse skinvar blog
1003          * 
1004          * @param       string  $template       name of template
1005          * @param       mixed   $amount         the number of items in a display, in case it includes the beginning
1006          * @param       string  $category       name of category
1007          * @return      void
1008          */
1009         public function parse_blog($template, $amount = 10, $category = '')
1010         {
1011                 global $blog, $startpos;
1012                 
1013                 list($limit, $offset) = sscanf($amount, '%d(%d)');
1014                 $this->setBlogCategory($blog, $category);
1015                 $this->preBlogContent('blog',$blog);
1016                 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
1017                 $this->postBlogContent('blog',$blog);
1018                 return;
1019         }
1020         
1021         /**
1022          * Actions::parse_bloglist()
1023          * Parse skinvar bloglist
1024          * Shows a list of all blogs
1025          * 
1026          * @param       string  $template       name of template
1027          * @param       string  $bnametype      whether 'name' or 'shortname' is used for the link text
1028          * @param       string  $orderby        order criteria
1029          * @param       string  $direction      order ascending or descending             
1030          * @return      void
1031          */
1032         public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
1033         {
1034                 Blog::showBlogList($template, $bnametype, $orderby, $direction);
1035                 return;
1036         }
1037         
1038         /**
1039          * Actions::parse_blogsetting()
1040          * Parse skinvar blogsetting
1041          * 
1042          * @param       string  $which  key of weblog settings
1043          * @return      void
1044          */
1045         public function parse_blogsetting($which)
1046         {
1047                 global $blog;
1048                 switch( $which )
1049                 {
1050                         case 'id':
1051                                 echo Entity::hsc($blog->getID());
1052                                 break;
1053                         case 'url':
1054                                 echo Entity::hsc($blog->getURL());
1055                                 break;
1056                         case 'name':
1057                                 echo Entity::hsc($blog->getName());
1058                                 break;
1059                         case 'desc':
1060                                 echo Entity::hsc($blog->getDescription());
1061                                 break;
1062                         case 'short':
1063                                 echo Entity::hsc($blog->getShortName());
1064                                 break;
1065                 }
1066                 return;
1067         }
1068         
1069         /**
1070          * Actions::parse_callback()
1071          * Parse callback
1072          * 
1073          * @param       string  $eventName      name of event
1074          * @param       string  $type   type of skin
1075          * @return      void
1076          */
1077         public function parse_callback($eventName, $type)
1078         {
1079                 global $manager;
1080                 $manager->notify($eventName, array('type' => $type));
1081                 return;
1082         }
1083         
1084         /**
1085          * Actions::parse_category()
1086          * Parse skinvar category
1087          * 
1088          * @param       string  $type   key of category settings
1089          * @return      void
1090          */
1091         public function parse_category($type = 'name')
1092         {
1093                 global $catid, $blog;
1094                 if ( !$blog->isValidCategory($catid) )
1095                 {
1096                         return;
1097                 }
1098                 
1099                 switch ( $type )
1100                 {
1101                         case 'name':
1102                                 echo $blog->getCategoryName($catid);
1103                                 break;
1104                         case 'desc':
1105                                 echo $blog->getCategoryDesc($catid);
1106                                 break;
1107                         case 'id':
1108                                 echo $catid;
1109                                 break;
1110                 }
1111                 return;
1112         }
1113         
1114         /**
1115          * Actions::parse_categorylist()
1116          * Parse categorylist
1117          * 
1118          * @param       string  $template       name of template
1119          * @param       string  $blogname       name of weblog
1120          * @return      void
1121          */
1122         public function parse_categorylist($template, $blogname = '')
1123         {
1124                 global $blog, $manager;
1125                 
1126                 // when no blog found
1127                 if ( ($blogname == '') && (!is_object($blog)) )
1128                 {
1129                         return 0;
1130                 }
1131                         
1132                 if ( $blogname == '' )
1133                 {
1134                         $this->preBlogContent('categorylist',$blog);
1135                         $blog->showCategoryList($template);
1136                         $this->postBlogContent('categorylist',$blog);
1137                 }
1138                 else
1139                 {
1140                         $b =& $manager->getBlog(getBlogIDFromName($blogname));
1141                         $this->preBlogContent('categorylist',$b);
1142                         $b->showCategoryList($template);
1143                         $this->postBlogContent('categorylist',$b);
1144                 }
1145                 return;
1146         }
1147         
1148         /**
1149          * Actions::parse_charset()
1150          * Parse skinvar charset
1151          * 
1152          * @param       void
1153          * @return      void
1154          */
1155         public function parse_charset()
1156         {
1157                 echo i18n::get_current_charset();
1158                 return;
1159         }
1160         
1161         /**
1162          * Actions::parse_commentform()
1163          * Parse skinvar commentform
1164          * 
1165          * @param       string  $destinationurl URI for redirection
1166          * @return      void
1167          */
1168         public function parse_commentform($destinationurl = '')
1169         {
1170                 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
1171                 
1172                 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
1173                 if ( stristr($destinationurl, 'action.php') )
1174                 {
1175                         $args = func_get_args();
1176                         $destinationurl = $args[1];
1177                         ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
1178                 }
1179                 
1180                 $actionurl = $CONF['ActionURL'];
1181                 
1182                 // if item is closed, show message and do nothing
1183                 $item =& $manager->getItem($itemid,0,0);
1184                 if ( $item['closed'] || !$blog->commentsEnabled() )
1185                 {
1186                         $this->doForm('commentform-closed');
1187                         return;
1188                 }
1189                 
1190                 if ( !$blog->isPublic() && !$member->isLoggedIn() )
1191                 {
1192                         $this->doForm('commentform-closedtopublic');
1193                         return;
1194                 }
1195                 
1196                 if ( !$destinationurl )
1197                 {
1198                         // note: createLink returns an HTML encoded URL
1199                         $destinationurl = Link::create_link(
1200                                 'item',
1201                                 array(
1202                                         'itemid' => $itemid,
1203                                         'title' => $item['title'],
1204                                         'timestamp' => $item['timestamp'],
1205                                         'extra' => $this->linkparams
1206                                 )
1207                         );
1208                 }
1209                 else
1210                 {
1211                         // HTML encode URL
1212                         $destinationurl = Entity::hsc($destinationurl);
1213                 }
1214                 
1215                 // values to prefill
1216                 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
1217                 if ( !$user )
1218                 {
1219                         $user = postVar('user');
1220                 }
1221                 
1222                 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
1223                 if ( !$userid )
1224                 {
1225                         $userid = postVar('userid');
1226                 }
1227                 
1228                 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
1229                 if (!$email)
1230                 {
1231                         $email = postVar('email');
1232                 }
1233                 
1234                 $body = postVar('body');
1235                 
1236                 $this->formdata = array(
1237                         'destinationurl' => $destinationurl,    // url is already HTML encoded
1238                         'actionurl' => Entity::hsc($actionurl),
1239                         'itemid' => $itemid,
1240                         'user' => Entity::hsc($user),
1241                         'userid' => Entity::hsc($userid),
1242                         'email' => Entity::hsc($email),
1243                         'body' => Entity::hsc($body),
1244                         'membername' => $member->getDisplayName(),
1245                         'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
1246                 );
1247                 
1248                 if ( !$member->isLoggedIn() )
1249                 {
1250                         $this->doForm('commentform-notloggedin');
1251                 }
1252                 else
1253                 {
1254                         $this->doForm('commentform-loggedin');
1255                 }
1256                 return;
1257         }
1258         
1259         /**
1260          * Actions::parse_comments()
1261          * Parse skinvar comments
1262          * include comments for one item
1263          * 
1264          * @param       string  $template       name of template
1265          * @return      void
1266          */
1267         public function parse_comments($template)
1268         {
1269                 global $itemid, $manager, $blog, $highlight;
1270                 $template =& $manager->getTemplate($template);
1271                 
1272                 // create parser object & action handler
1273                 $actions = new ItemActions($blog);
1274                 $parser = new Parser($actions->getDefinedActions(),$actions);
1275                 $actions->setTemplate($template);
1276                 $actions->setParser($parser);
1277                 $item = Item::getitem($itemid, 0, 0);
1278                 $actions->setCurrentItem($item);
1279                 
1280                 $comments = new Comments($itemid);
1281                 $comments->setItemActions($actions);
1282                 // shows ALL comments
1283                 $comments->showComments($template, -1, 1, $highlight);
1284                 return;
1285         }
1286         
1287         /**
1288          * Actions::parse_errordiv()
1289          * Parse errordiv
1290          * 
1291          * @param       void
1292          * @return      void
1293          */
1294         public function parse_errordiv()
1295         {
1296                 global $errormessage;
1297                 if ( $errormessage )
1298                 {
1299                         echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
1300                 }
1301                 return;
1302         }
1303         
1304         /**
1305          * Actions::parse_errormessage()
1306          * Parse skinvar errormessage
1307          * 
1308          * @param       void
1309          * @return      void
1310          */
1311         public function parse_errormessage()
1312         {
1313                 global $errormessage;
1314                 echo $errormessage;
1315                 return;
1316         }
1317         
1318         /**
1319          * Actions::parse_formdata()
1320          * Parse formdata
1321          * 
1322          * @param       string  $what   key of format data
1323          * @return      void
1324          */
1325         public function parse_formdata($what)
1326         {
1327                 echo $this->formdata[$what];
1328                 return;
1329         }
1330         
1331         /**
1332          * Actions::parse_ifcat()
1333          * Parse ifcat
1334          * 
1335          * @param       string  $text
1336          * @return      void
1337          */
1338         public function parse_ifcat($text = '')
1339         {
1340                 if ( $text == '' )
1341                 {
1342                         // new behaviour
1343                         $this->parse_if('category');
1344                 }
1345                 else
1346                 {
1347                         // old behaviour
1348                         global $catid, $blog;
1349                         if ( $blog->isValidCategory($catid) )
1350                         {
1351                                 echo $text;
1352                         }
1353                 }
1354                 return;
1355         }
1356         
1357         /**
1358          * Actions::parse_image()
1359          * Parse skinvar image
1360          * 
1361          * @param       string  $what   name of tag
1362          * @return      void
1363          */
1364         public function parse_image($what = 'imgtag')
1365         {
1366                 global $CONF;
1367                 
1368                 $imagetext      = Entity::hsc(requestVar('imagetext'));
1369                 $imagepopup = requestVar('imagepopup');
1370                 $width          = intRequestVar('width');
1371                 $height         = intRequestVar('height');
1372                 $fullurl        = Entity::hsc($CONF['MediaURL'] . $imagepopup);
1373                 
1374                 switch ( $what )
1375                 {
1376                         case 'url':
1377                                 echo $fullurl;
1378                                 break;
1379                         case 'width':
1380                                 echo $width;
1381                                 break;
1382                         case 'height':
1383                                 echo $height;
1384                                 break;
1385                         case 'caption':
1386                         case 'text':
1387                                 echo $imagetext;
1388                                 break;
1389                         case 'imgtag':
1390                         default:
1391                                 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
1392                                 break;
1393                 }
1394                 return;
1395         }
1396         
1397         /**
1398          * Actions::parse_imagetext()
1399          * Parse skinvar imagetext
1400          * 
1401          * @param       void
1402          * @return      void
1403          */
1404         public function parse_imagetext()
1405         {
1406                 $this->parse_image('imagetext');
1407                 return;
1408         }
1409
1410         /**
1411          * Actions::parse_item()
1412          * Parse skinvar item
1413          * include one item (no comments)
1414          * 
1415          * @param       void
1416          * @return      void
1417          */
1418         public function parse_item($template)
1419         {
1420                 global $blog, $itemid, $highlight;
1421                 
1422                 // need this to select default category
1423                 $this->setBlogCategory($blog, '');
1424                 $this->preBlogContent('item',$blog);
1425                 $r = $blog->showOneitem($itemid, $template, $highlight);
1426                 if ( $r == 0 )
1427                 {
1428                         echo _ERROR_NOSUCHITEM;
1429                 }
1430                 $this->postBlogContent('item',$blog);
1431                 return;
1432         }
1433
1434         /**
1435          * Actions::parse_itemid()
1436          * Parse skinvar itemid
1437          * 
1438          * @param       void
1439          * @return      void
1440          */
1441         public function parse_itemid()
1442         {
1443                 global $itemid;
1444                 echo $itemid;
1445                 return;
1446         }
1447         
1448         /**
1449          * Actions::parseitemlink()
1450          * Parse skinvar itemlink
1451          * 
1452          * @param       void
1453          * @return      void
1454          */
1455         public function parse_itemlink($linktext = '')
1456         {
1457                 global $itemid;
1458                 $this->itemlink($itemid, $linktext);
1459                 return;
1460         }
1461         
1462         /**
1463          * Actions::parse_itemtitle()
1464          * Parse itemtitle
1465          * 
1466          * @param       void
1467          * @return      void
1468          */
1469         public function parse_itemtitle($format = '')
1470         {
1471                 global $manager, $itemid;
1472                 $item =& $manager->getItem($itemid,0,0);
1473                 
1474                 switch ( $format )
1475                 {
1476                         case 'xml':
1477                                 echo Entity::hen($item['title']);
1478                                 break;
1479                         case 'raw':
1480                                 echo $item['title'];
1481                                 break;
1482                         case 'attribute':
1483                         default:
1484                                 echo Entity::hsc(strip_tags($item['title']));
1485                                 break;
1486                 }
1487                 return;
1488         }
1489         
1490         /**
1491          * Actions::parse_loginform()
1492          * Parse skinvar loginform
1493          * 
1494          * @param       void
1495          * @return      void
1496          */
1497         public function parse_loginform()
1498         {
1499                 global $member, $CONF;
1500                 if ( !$member->isLoggedIn() )
1501                 {
1502                         $filename = 'loginform-notloggedin';
1503                         $this->formdata = array();
1504                 }
1505                 else
1506                 {
1507                         $filename = 'loginform-loggedin';
1508                         $this->formdata = array(
1509                                 'membername' => $member->getDisplayName(),
1510                         );
1511                 }
1512                 $this->doForm($filename);
1513                 return;
1514         }
1515         
1516         /**
1517          * Actions::parse_member()
1518          * Parse skinvar member
1519          * (includes a member info thingie)
1520          * 
1521          * @param       string  $what   which memberdata is needed
1522          * @return      void
1523          */
1524         public function parse_member($what)
1525         {
1526                 global $memberinfo, $member, $CONF;
1527                 
1528                 // 1. only allow the member-details-page specific variables on member pages
1529                 if ( $this->skintype == 'member' )
1530                 {
1531                         switch( $what )
1532                         {
1533                                 case 'name':
1534                                         echo Entity::hsc($memberinfo->getDisplayName());
1535                                         break;
1536                                 case 'realname':
1537                                         echo Entity::hsc($memberinfo->getRealName());
1538                                         break;
1539                                 case 'notes':
1540                                         echo Entity::hsc($memberinfo->getNotes());
1541                                         break;
1542                                 case 'url':
1543                                         echo Entity::hsc($memberinfo->getURL());
1544                                         break;
1545                                 case 'email':
1546                                         echo Entity::hsc($memberinfo->getEmail());
1547                                         break;
1548                                 case 'id':
1549                                         echo Entity::hsc($memberinfo->getID());
1550                                         break;
1551                         }
1552                 }
1553                 
1554                 // 2. the next bunch of options is available everywhere, as long as the user is logged in
1555                 if ( $member->isLoggedIn() )
1556                 {
1557                         switch( $what )
1558                         {
1559                                 case 'yourname':
1560                                         echo $member->getDisplayName();
1561                                         break;
1562                                 case 'yourrealname':
1563                                         echo $member->getRealName();
1564                                         break;
1565                                 case 'yournotes':
1566                                         echo $member->getNotes();
1567                                         break;
1568                                 case 'yoururl':
1569                                         echo $member->getURL();
1570                                         break;
1571                                 case 'youremail':
1572                                         echo $member->getEmail();
1573                                         break;
1574                                 case 'yourid':
1575                                         echo $member->getID();
1576                                         break;
1577                                 case 'yourprofileurl':
1578                                         if ($CONF['URLMode'] == 'pathinfo')
1579                                                 echo Link::create_member_link($member->getID());
1580                                         else
1581                                                 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
1582                                         break;
1583                         }
1584                 }
1585                 return;
1586         }
1587         
1588         /**
1589          * Link::parse_membermailform()
1590          * Parse skinvar membermailform
1591          * 
1592          * @param       integer $rows   the height for textarea
1593          * @param       integer $cols   the width for textarea
1594          * @param       string  $desturl        URI to redirect
1595          * @return      void
1596          */
1597         public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
1598         {
1599                 global $member, $CONF, $memberid;
1600                 
1601                 if ( $desturl == '' )
1602                 {
1603                         if ( $CONF['URLMode'] == 'pathinfo' )
1604                         {
1605                                 $desturl = Link::create_member_link($memberid);
1606                         }
1607                         else
1608                         {
1609                                 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
1610                         }
1611                 }
1612                 
1613                 $message = postVar('message');
1614                 $frommail = postVar('frommail');
1615                 
1616                 $this->formdata = array(
1617                         'url' => Entity::hsc($desturl),
1618                         'actionurl' => Entity::hsc($CONF['ActionURL']),
1619                         'memberid' => $memberid,
1620                         'rows' => $rows,
1621                         'cols' => $cols,
1622                         'message' => Entity::hsc($message),
1623                         'frommail' => Entity::hsc($frommail)
1624                 );
1625                 
1626                 if ( $member->isLoggedIn() )
1627                 {
1628                         $this->doForm('membermailform-loggedin');
1629                 }
1630                 else if ( $CONF['NonmemberMail'] )
1631                 {
1632                         $this->doForm('membermailform-notloggedin');
1633                 }
1634                 else
1635                 {
1636                         $this->doForm('membermailform-disallowed');
1637                 }
1638                 return;
1639         }
1640         
1641         /**
1642          * Actions::parse_nextarchive()
1643          * Parse skinvar nextarchive
1644          * 
1645          * @param       void
1646          * @return      void
1647          */
1648         public function parse_nextarchive()
1649         {
1650                 global $archivenext;
1651                 echo $archivenext;
1652                 return;
1653         }
1654         
1655         /**
1656          * Parse skinvar nextitem
1657          * (include itemid of next item)
1658          * 
1659          * @param       void
1660          * @return      void
1661          */
1662         public function parse_nextitem()
1663         {
1664                 global $itemidnext;
1665                 if ( isset($itemidnext) )
1666                 {
1667                         echo (int)$itemidnext;
1668                 }
1669                 return;
1670         }
1671         
1672         /**
1673          * Actions::parse_nextitemtitle()
1674          * Parse skinvar nextitemtitle
1675          * (include itemtitle of next item)
1676          * 
1677          * @param       string  $format format of text
1678          * @return      void
1679          */
1680         public function parse_nextitemtitle($format = '')
1681         {
1682                 global $itemtitlenext;
1683                 
1684                 switch ( $format )
1685                 {
1686                         case 'xml':
1687                                 echo Entity::hen($itemtitlenext);
1688                                 break;
1689                         case 'raw':
1690                                 echo $itemtitlenext;
1691                                 break;
1692                         case 'attribute':
1693                         default:
1694                                 echo Entity::hsc($itemtitlenext);
1695                                 break;
1696                 }
1697                 return;
1698         }
1699         
1700         /**
1701          * Actions::parse_nextlink()
1702          * Parse skinvar nextlink
1703          * 
1704          * @param       string  $linktext       text for content of anchor element
1705          * @param       integer $amount         the amount of items in a display
1706          * @param       integer $recount        increment from this value
1707          * @return      void
1708          */
1709         public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
1710         {
1711                 global $itemidnext, $archivenext, $startpos;
1712                 if ( $this->skintype == 'item' )
1713                 {
1714                         $this->itemlink($itemidnext, $linktext);
1715                 }
1716                 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
1717                 {
1718                         $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
1719                 }
1720                 else
1721                 {
1722                         $this->archivelink($archivenext, $linktext);
1723                 }
1724                 return;
1725         }
1726
1727         /**
1728          * Actions::parse_nucleusbutton()
1729          * Parse skinvar nucleusbutton
1730          * 
1731          * @param       string  $imgurl URL  for image
1732          * @param       integer $imgwidth       width of image
1733          * @param       integer $imgheidht      height of image
1734          */
1735         public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
1736         {
1737                 global $CONF;
1738                 if ( $imgurl == '' )
1739                 {
1740                         $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
1741                 }
1742                 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
1743                 {
1744                         // when skindit IncludeMode is used: start from skindir
1745                         $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
1746                 }
1747                 
1748                 $this->formdata = array(
1749                         'imgurl' => $imgurl,
1750                         'imgwidth' => $imgwidth,
1751                         'imgheight' => $imgheight,
1752                 );
1753                 $this->doForm('nucleusbutton');
1754                 return;
1755         }
1756         
1757         /**
1758          * Actions::parse_otherarchive()
1759          * Parse skinvar otherarchive
1760          * 
1761          * @param       string  $blogname       name of weblog
1762          * @param       string  $template       name of template
1763          * @param       string  $category       name of category
1764          * @return      void
1765          */     
1766         public function parse_otherarchive($blogname, $template, $category = '')
1767         {
1768                 global $archive, $manager;
1769                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
1770                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1771                 $this->setBlogCategory($b, $category);
1772                 $this->preBlogContent('otherachive',$b);
1773                 $b->showArchive($template, $y, $m, $d);
1774                 $this->postBlogContent('otherachive',$b);
1775                 return;
1776         }
1777         
1778         /**
1779          * Actions::parse_otherarchivedaylist()
1780          * Parse skinvar otherarchivedaylist
1781          * 
1782          * @param       string  $blogname       name of weblog
1783          * @param       string  $template       name of template
1784          * @param       string  $category       name of category
1785          * @param       integer $limit          the amount of items in a display
1786          * @return      void
1787          */
1788         public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
1789         {
1790                 global $manager;
1791                 if ( $category == 'all')
1792                 {
1793                         $category = '';
1794                 }
1795                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1796                 $this->setBlogCategory($b, $category);
1797                 $this->preBlogContent('otherarchivelist',$b);
1798                 $b->showArchiveList($template, 'day', $limit);
1799                 $this->postBlogContent('otherarchivelist',$b);
1800                 return;
1801         }
1802         
1803         /**
1804          * Actions::parse_otherarchivelist()
1805          * Parse skinvar otherarchivelist
1806          * 
1807          * @param       string  $blogname       name of weblog
1808          * @param       string  $template       name of template
1809          * @param       string  $category       name of category
1810          * @param       integer $limit          the amount of items in a display
1811          * @return      void
1812          */
1813         public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
1814         {
1815                 global $manager;
1816                 if ( $category == 'all' )
1817                 {
1818                         $category = '';
1819                 }
1820                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1821                 $this->setBlogCategory($b, $category);
1822                 $this->preBlogContent('otherarchivelist',$b);
1823                 $b->showArchiveList($template, 'month', $limit);
1824                 $this->postBlogContent('otherarchivelist',$b);
1825                 return;
1826         }
1827         
1828         /**
1829          * Actions::parse_otherarchiveyearlist()
1830          * Parse skinvar otherarchiveyearlist
1831          * 
1832          * @param       string  $blogname       name of weblog
1833          * @param       string  $template       name of template
1834          * @param       string  $category       name of category
1835          * @limit       integer $limit          the amount of items in a display
1836          */
1837         public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
1838         {
1839                 global $manager;
1840                 if ( $category == 'all' )
1841                 {
1842                         $category = '';
1843                 }
1844                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1845                 $this->setBlogCategory($b, $category);
1846                 $this->preBlogContent('otherarchivelist',$b);
1847                 $b->showArchiveList($template, 'year', $limit);
1848                 $this->postBlogContent('otherarchivelist',$b);
1849                 return;
1850         }
1851         
1852         /**
1853          * Actions::parse_otherblog()
1854          * Parse skinvar otherblog
1855          * 
1856          * @param       string  $blogname       name of weblog
1857          * @param       string  $template       name of template
1858          * @param       mixed   $amount         the amount of items, in case it includes the beginning
1859          * @param       string  $category       name of category
1860          * @return      void
1861          */
1862         public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
1863         {
1864                 global $manager;
1865                 
1866                 list($limit, $offset) = sscanf($amount, '%d(%d)');
1867                 
1868                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1869                 $this->setBlogCategory($b, $category);
1870                 $this->preBlogContent('otherblog',$b);
1871                 $this->amountfound = $b->readLog($template, $limit, $offset);
1872                 $this->postBlogContent('otherblog',$b);
1873                 return;
1874         }
1875         
1876         /**
1877          * Actions::parse_othersearchresults()
1878          * Parse skinvar othersearchresults
1879          * 
1880          * @param       string  $blogname       name of weblog
1881          * @param       string  $template       name of template
1882          * @param       integer $maxresults     the amount of results
1883          * @return      void
1884          */
1885         public function parse_othersearchresults($blogname, $template, $maxresults = 50)
1886         {
1887                 global $query, $amount, $manager, $startpos;
1888                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1889                 // need this to select default category
1890                 $this->setBlogCategory($b, '');
1891                 $this->preBlogContent('othersearchresults',$b);
1892                 $b->search($query, $template, $amount, $maxresults, $startpos);
1893                 $this->postBlogContent('othersearchresults',$b);
1894                 return;
1895         }
1896         
1897         /**
1898          * Actions::parse_plugin()
1899          * Executes a plugin skinvar
1900          * extra parameters can be added
1901          * 
1902          * @param       string  $pluginName     name of plugin (without the NP_)
1903          * @return      void
1904          */
1905         public function parse_plugin($pluginName)
1906         {
1907                 global $manager;
1908                 
1909                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
1910                 if ( !$plugin )
1911                 {
1912                         return;
1913                 }
1914                 
1915                 // get arguments
1916                 $params = func_get_args();
1917                 
1918                 // remove plugin name
1919                 array_shift($params);
1920                 
1921                 // add skin type on front
1922                 array_unshift($params, $this->skintype);
1923                 
1924                 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
1925                 return;
1926         }
1927         
1928         /**
1929          * Actions::parse_prevarchive()
1930          * Parse skinvar prevarchive
1931          * 
1932          * @param       void
1933          * @return      void
1934          */
1935         public function parse_prevarchive()
1936         {
1937                 global $archiveprev;
1938                 echo $archiveprev;
1939         }
1940         
1941         /**
1942          * Actions::parse_preview()
1943          * Parse skinvar preview
1944          * 
1945          * @param       string  $template       name of tempalte
1946          * @return      void
1947          */
1948         public function parse_preview($template)
1949         {
1950                 global $blog, $CONF, $manager;
1951                 
1952                 $template =& $manager->getTemplate($template);
1953                 
1954                 $row['body'] = '<span id="prevbody"></span>';
1955                 $row['title'] = '<span id="prevtitle"></span>';
1956                 $row['more'] = '<span id="prevmore"></span>';
1957                 $row['itemlink'] = '';
1958                 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
1959                 
1960                 echo Template::fill($template['ITEM_HEADER'],$row);
1961                 echo Template::fill($template['ITEM'],$row);
1962                 echo Template::fill($template['ITEM_FOOTER'],$row);
1963                 return;
1964         }
1965         
1966         /**
1967          * Actions::parse_previtem()
1968          * Parse skinvar previtem
1969          * (include itemid of prev item)
1970          * 
1971          * @param       void
1972          * @return      void
1973          */
1974         public function parse_previtem()
1975         {
1976                 global $itemidprev;
1977                 if ( isset($itemidprev) )
1978                 {
1979                         echo (integer) $itemidprev;
1980                 }
1981                 return;
1982         }
1983         
1984         /**
1985          * Actions::parse_previtemtitle()
1986          * Parse skinvar previtemtitle
1987          * (include itemtitle of prev item)
1988          * 
1989          * @param       String  $format string format
1990          * @return      String  formatted string
1991          */
1992         public function parse_previtemtitle($format = '')
1993         {
1994                 global $itemtitleprev;
1995                 
1996                 switch ( $format )
1997                 {
1998                         case 'xml':
1999                                 echo Entity::hen($itemtitleprev);
2000                                 break;
2001                         case 'raw':
2002                                 echo $itemtitleprev;
2003                                 break;
2004                         case 'attribute':
2005                         default:
2006                                 echo Entity::hsc($itemtitleprev);
2007                                 break;
2008                 }
2009                 return;
2010         }
2011         
2012         /**
2013          * Actions::parse_prevlink()
2014          * Parse skinvar prevlink
2015          * 
2016          * @param       string  $linktext       text as a content of anchor element
2017          * @param       integer the amount of links
2018          * @return      void
2019          */
2020         public function parse_prevlink($linktext = '', $amount = 10)
2021         {
2022                 global $itemidprev, $archiveprev, $startpos;
2023                 
2024                 if ( $this->skintype == 'item' )
2025                 {
2026                         $this->itemlink($itemidprev, $linktext);
2027                 }
2028                 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
2029                 {
2030                         $this->searchlink($amount, $startpos, 'prev', $linktext);
2031                 }
2032                 else
2033                 {
2034                         $this->archivelink($archiveprev, $linktext);
2035                 }
2036                 return;
2037         }
2038         
2039         /**
2040          * Actions::parse_query()
2041          * Parse skinvar query
2042          * (includes the search query)   
2043          * 
2044          * @param       void
2045          * @return      void
2046          */
2047         public function parse_query()
2048         {
2049                 global $query;
2050                 echo Entity::hsc($query);
2051                 return;
2052         }
2053         
2054         /**
2055          * Actions::parse_referer()
2056          * Parse skinvar referer
2057          * 
2058          * @param       void
2059          * @return      void
2060          */
2061         public function parse_referer()
2062         {
2063                 echo Entity::hsc(serverVar('HTTP_REFERER'));
2064                 return;
2065         }
2066         
2067         /**
2068          * Actions::parse_searchform()
2069          * Parse skinvar searchform
2070          * 
2071          * @param       string  $blogname       name of weblog
2072          * @return      void
2073          */
2074         public function parse_searchform($blogname = '')
2075         {
2076                 global $CONF, $manager, $maxresults;
2077                 if ( $blogname )
2078                 {
2079                         $blog =& $manager->getBlog(getBlogIDFromName($blogname));
2080                 }
2081                 else
2082                 {
2083                         global $blog;
2084                 }
2085                 // use default blog when no blog is selected
2086                 $this->formdata = array(
2087                         'id'    => $blog?$blog->getID():$CONF['DefaultBlog'],
2088                         'query' => Entity::hsc(getVar('query')),
2089                 );
2090                 $this->doForm('searchform');
2091                 return;
2092         }
2093         
2094         /**
2095          * Actions::parse_searchresults()
2096          * Parse skinvar searchresults
2097          * 
2098          * @param       string  $template       name of tempalte
2099          * @param       integer $maxresults     searched items in a display
2100          * @return      void;
2101          */
2102         public function parse_searchresults($template, $maxresults = 50 )
2103         {
2104                 global $blog, $query, $amount, $startpos;
2105                 
2106                 $this->setBlogCategory($blog, '');      // need this to select default category
2107                 $this->preBlogContent('searchresults',$blog);
2108                 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
2109                 $this->postBlogContent('searchresults',$blog);
2110                 return;
2111         }
2112         
2113         /**
2114          * Actions::parse_self()
2115          * Parse skinvar self
2116          * 
2117          * @param       void
2118          * @return      void
2119          */
2120         public function parse_self()
2121         {
2122                 global $CONF;
2123                 echo $CONF['Self'];
2124                 return;
2125         }
2126         
2127         /**
2128          * Actions::parse_sitevar()
2129          * Parse skinvar sitevar
2130          * (include a sitevar)
2131          * 
2132          * @param       string  $which
2133          * @return      void
2134          */
2135         public function parse_sitevar($which)
2136         {
2137                 global $CONF;
2138                 switch ( $which )
2139                 {
2140                         case 'url':
2141                                 echo $CONF['IndexURL'];
2142                                 break;
2143                         case 'name':
2144                                 echo $CONF['SiteName'];
2145                                 break;
2146                         case 'admin':
2147                                 echo $CONF['AdminEmail'];
2148                                 break;
2149                         case 'adminurl':
2150                                 echo $CONF['AdminURL'];
2151                 }
2152                 return;
2153         }
2154         
2155         /**
2156          * Actions::parse_skinname()
2157          * Parse skinname
2158          * 
2159          * @param       void
2160          * @return      void
2161          */
2162         public function parse_skinname()
2163         {
2164                 echo $this->skin->getName();
2165                 return;
2166         }
2167         
2168         /**
2169          * Actions::parse_skintype()
2170          * Parse skintype (experimental)
2171          * 
2172          * @param       void
2173          * @return      void
2174          */
2175         public function parse_skintype()
2176         {
2177                 echo $this->skintype;
2178                 return;
2179         }
2180         
2181         /**
2182          * Actions::parse_ticket()
2183          * Parse ticket
2184          * 
2185          * @param       void
2186          * @return      void
2187          */
2188         public function parse_ticket()
2189         {
2190                 global $manager;
2191                 $manager->addTicketHidden();
2192                 return;
2193         }
2194
2195         /**
2196          * Actions::parse_todaylink()
2197          * Parse skinvar todaylink
2198          * A link to the today page (depending on selected blog, etc...)
2199          *
2200          * @param       string  $linktext       text for link
2201          * @return      void
2202          */
2203         public function parse_todaylink($linktext = '')
2204         {
2205                 global $blog, $CONF;
2206                 if ( $blog )
2207                 {
2208                         echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
2209                 }
2210                 else
2211                 {
2212                         echo $this->link($CONF['SiteUrl'], $linktext);
2213                 }
2214                 return;
2215         }
2216         
2217         /**
2218          * Parse vars
2219          * When commentform is not used, to include a hidden field with itemid   
2220          * 
2221          * @param       void
2222          * @return      void
2223          */
2224         public function parse_vars()
2225         {
2226                 global $itemid;
2227                 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
2228                 return;
2229         }
2230
2231         /**
2232          * Actions::parse_version()
2233          * Parse skinvar version
2234          * (include nucleus versionnumber)       
2235          * 
2236          * @param       void
2237          * @return      void
2238          */
2239         public function parse_version()
2240         {
2241                 global $nucleus;
2242                 echo 'Nucleus CMS ' . $nucleus['version'];
2243                 return;
2244         }
2245         
2246         /**
2247          * Actions::parse_sticky()
2248          * Parse skinvar sticky
2249          * 
2250          * @param       integer $itemnumber     id of item
2251          * @param       string  $template       name of template
2252          * @return      void
2253          */
2254         public function parse_sticky($itemnumber = 0, $template = '')
2255         {
2256                 global $manager;
2257                 
2258                 $itemnumber = intval($itemnumber);
2259                 $itemarray = array($itemnumber);
2260                 
2261                 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
2262                 $this->preBlogContent('sticky',$b);
2263                 $this->amountfound = $b->readLogFromList($itemarray, $template);
2264                 $this->postBlogContent('sticky',$b);
2265                 return;
2266         }
2267 }