OSDN Git Service

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