OSDN Git Service

FIX:変数名の誤記を修正
[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 1863 2012-05-19 10:50: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::$skin_type_friendly_names
73          * friendly name for wrapped page types
74          */
75         static public $default_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::getAvailableSkinTypes()
88          * 
89          * @static
90          * @param       void
91          * @return      array   list of friendly names for page actions
92          */
93         static public function getAvailableSkinTypes()
94         {
95                 return self::$default_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           = $parsed['path'];
556                 $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                 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
713                 return;
714         }
715
716         /**
717          * Actions::postBlogContent()
718          * Notifies the Manager that a PostBlogContent event occurs
719          * 
720          * @param       string  $type   type of skin
721          * @param       objecct $blog   an instance of Blog class
722          * @return      void
723          */
724         private function postBlogContent($type, &$blog)
725         {
726                 global $manager;
727                 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
728                 return;
729         }
730         
731         /**
732          * Actions::parse_additemform()
733          * Parse skinvar additemform
734          * 
735          * @param       void
736          * @return      void
737          */
738         public function parse_additemform()
739         {
740                 global $blog, $CONF;
741                 $this->formdata = array(
742                         'adminurl'      => Entity::hsc($CONF['AdminURL']),
743                         'catid'         => $blog->getDefaultCategory()
744                 );
745                 $blog->InsertJavaScriptInfo();
746                 $this->doForm('additemform');
747                 return;
748         }
749         
750         /**
751          * Actions::parse_addlink()
752          * Parse skinvar addlink
753          * A Link that allows to open a bookmarklet to add an item
754          */
755         public function parse_addlink()
756         {
757                 global $CONF, $member, $blog;
758                 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
759                 {
760                         echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
761                 }
762                 return;
763         }
764         
765         /**
766          * Actions::parse_addpopupcode()
767          * Parse skinvar addpopupcode
768          * Code that opens a bookmarklet in an popup window
769          * 
770          * @param       void
771          * @return      void
772          */
773         public function parse_addpopupcode()
774         {
775                 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;";
776                 return;
777         }
778         
779         /**
780          * Parse skinvar adminurl
781          * (shortcut for admin url)
782          * 
783          * @param       void
784          * @return      void
785          */
786         public function parse_adminurl()
787         {
788                 $this->parse_sitevar('adminurl');
789                 return;
790         }
791         
792         /**
793          * Actions::parse_archive()
794          * Parse skinvar archive
795          * 
796          * @param       string  $template       name of template
797          * @param       string  $category       name of category
798          * @return      
799          */
800         public function parse_archive($template, $category = '')
801         {
802                 global $blog, $archive;
803                 // can be used with either yyyy-mm or yyyy-mm-dd
804                 sscanf($archive,'%d-%d-%d', $y, $m, $d);
805                 $this->setBlogCategory($blog, $category);
806                 $this->preBlogContent('achive',$blog);
807                 $blog->showArchive($template, $y, $m, $d);
808                 $this->postBlogContent('achive',$blog);
809                 return;
810         }
811         
812         /**
813          * Actions::parse_archivedate()
814          * %archivedate(locale,date format)%
815          * 
816          * @param       string  $locale
817          * @return      void
818          */
819         public function parse_archivedate($locale = '-def-')
820         {
821                 global $archive;
822                 
823                 /* 
824                  * TODO: these lines are no meaning because there is no $template.
825                 if ( $locale == '-def-' )
826                 {
827                         setlocale(LC_TIME, $template['LOCALE']);
828                 }
829                 else
830                 {
831                         setlocale(LC_TIME, $locale);
832                 }
833                  */
834                 
835                 // get archive date
836                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
837                 
838                 // get format
839                 $args = func_get_args();
840                 // format can be spread over multiple parameters
841                 if ( sizeof($args) > 1 )
842                 {
843                         // take away locale
844                         array_shift($args);
845                         // implode
846                         $format=implode(',',$args);
847                 }
848                 elseif ( $d == 0 && $m !=0 )
849                 {
850                         $format = '%B %Y';
851                 }
852                 elseif ( $m == 0 )
853                 {
854                         $format = '%Y';
855                 }
856                 else
857                 {
858                         $format = '%d %B %Y';
859                 }
860                 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
861                 return;
862         }
863         
864         /**
865          * Actions::parse_archivedaylist()
866          * Parse skinvar archivedaylist
867          * 
868          * @param       string  $template       name of template
869          * @param       string  $category       name of category
870          * @param       integer $limit          the number of items in a display
871          * @return      void
872          */
873         public function parse_archivedaylist($template, $category = 'all', $limit = 0)
874         {
875                 global $blog;
876                 if ( $category == 'all' )
877                 {
878                         $category = '';
879                 }
880                 $this->preBlogContent('archivelist',$blog);
881                 $this->setBlogCategory($blog, $category);
882                 $blog->showArchiveList($template, 'day', $limit);
883                 $this->postBlogContent('archivelist',$blog);
884                 return;
885         }
886         
887         /**
888          * Actions::parse_archivelink()
889          * A link to the archives for the current blog (or for default blog)
890          * 
891          * @param       string  $linktext       text for link
892          * @return      void
893          */
894         public function parse_archivelink($linktext = '')
895         {
896                 global $blog, $CONF;
897                 if ( $blog )
898                 {
899                         echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
900                 }
901                 else
902                 {
903                         echo $this->link(Link::create_archivelist_link(), $linktext);
904                 }
905                 return;
906         }
907         
908         /**
909          * Actions::parse_archivelist()
910          * 
911          * @param       string  $template       name of template
912          * @param       string  $category       name of category
913          * @param       integer $limit          the number of items in a display
914          * @return      void
915          */
916         public function parse_archivelist($template, $category = 'all', $limit = 0)
917         {
918                 global $blog;
919                 if ( $category == 'all' )
920                 {
921                         $category = '';
922                 }
923                 $this->preBlogContent('archivelist',$blog);
924                 $this->setBlogCategory($blog, $category);
925                 $blog->showArchiveList($template, 'month', $limit);
926                 $this->postBlogContent('archivelist',$blog);
927                 return;
928         }
929         
930         /**
931          * Actions::parse_archiveyearlist()
932          * 
933          * @param       string  $template       name of template
934          * @param       string  $category       name of category
935          * @param       integer $limit          the number of items in a display
936          */
937         public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
938         {
939                 global $blog;
940                 if ( $category == 'all' )
941                 {
942                         $category = '';
943                 }
944                 $this->preBlogContent('archivelist',$blog);
945                 $this->setBlogCategory($blog, $category);
946                 $blog->showArchiveList($template, 'year', $limit);
947                 $this->postBlogContent('archivelist',$blog);
948                 return;
949         }
950         
951         /**
952          * Actions::parse_archivetype()
953          * Parse skinvar archivetype
954          * 
955          * @param       void
956          * @return      void
957          */
958         public function parse_archivetype()
959         {
960                 global $archivetype;
961                 echo $archivetype;
962                 return;
963         }
964         
965         /**
966          * Actions::parse_blog()
967          * Parse skinvar blog
968          * 
969          * @param       string  $template       name of template
970          * @param       mixed   $amount         the number of items in a display, in case it includes the beginning
971          * @param       string  $category       name of category
972          * @return      void
973          */
974         public function parse_blog($template, $amount = 10, $category = '')
975         {
976                 global $blog, $startpos;
977                 
978                 list($limit, $offset) = sscanf($amount, '%d(%d)');
979                 $this->setBlogCategory($blog, $category);
980                 $this->preBlogContent('blog',$blog);
981                 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
982                 $this->postBlogContent('blog',$blog);
983                 return;
984         }
985         
986         /**
987          * Actions::parse_bloglist()
988          * Parse skinvar bloglist
989          * Shows a list of all blogs
990          * 
991          * @param       string  $template       name of template
992          * @param       string  $bnametype      whether 'name' or 'shortname' is used for the link text
993          * @param       string  $orderby        order criteria
994          * @param       string  $direction      order ascending or descending             
995          * @return      void
996          */
997         public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
998         {
999                 Blog::showBlogList($template, $bnametype, $orderby, $direction);
1000                 return;
1001         }
1002         
1003         /**
1004          * Actions::parse_blogsetting()
1005          * Parse skinvar blogsetting
1006          * 
1007          * @param       string  $which  key of weblog settings
1008          * @return      void
1009          */
1010         public function parse_blogsetting($which)
1011         {
1012                 global $blog;
1013                 switch( $which )
1014                 {
1015                         case 'id':
1016                                 echo Entity::hsc($blog->getID());
1017                                 break;
1018                         case 'url':
1019                                 echo Entity::hsc($blog->getURL());
1020                                 break;
1021                         case 'name':
1022                                 echo Entity::hsc($blog->getName());
1023                                 break;
1024                         case 'desc':
1025                                 echo Entity::hsc($blog->getDescription());
1026                                 break;
1027                         case 'short':
1028                                 echo Entity::hsc($blog->getShortName());
1029                                 break;
1030                 }
1031                 return;
1032         }
1033         
1034         /**
1035          * Actions::parse_callback()
1036          * Parse callback
1037          * 
1038          * @param       string  $eventName      name of event
1039          * @param       string  $type   type of skin
1040          * @return      void
1041          */
1042         public function parse_callback($eventName, $type)
1043         {
1044                 global $manager;
1045                 $manager->notify($eventName, array('type' => $type));
1046                 return;
1047         }
1048         
1049         /**
1050          * Actions::parse_category()
1051          * Parse skinvar category
1052          * 
1053          * @param       string  $type   key of category settings
1054          * @return      void
1055          */
1056         public function parse_category($type = 'name')
1057         {
1058                 global $catid, $blog;
1059                 if ( !$blog->isValidCategory($catid) )
1060                 {
1061                         return;
1062                 }
1063                 
1064                 switch ( $type )
1065                 {
1066                         case 'name':
1067                                 echo $blog->getCategoryName($catid);
1068                                 break;
1069                         case 'desc':
1070                                 echo $blog->getCategoryDesc($catid);
1071                                 break;
1072                         case 'id':
1073                                 echo $catid;
1074                                 break;
1075                 }
1076                 return;
1077         }
1078         
1079         /**
1080          * Actions::parse_categorylist()
1081          * Parse categorylist
1082          * 
1083          * @param       string  $template       name of template
1084          * @param       string  $blogname       name of weblog
1085          * @return      void
1086          */
1087         public function parse_categorylist($template, $blogname = '')
1088         {
1089                 global $blog, $manager;
1090                 
1091                 // when no blog found
1092                 if ( ($blogname == '') && (!is_object($blog)) )
1093                 {
1094                         return 0;
1095                 }
1096                         
1097                 if ( $blogname == '' )
1098                 {
1099                         $this->preBlogContent('categorylist',$blog);
1100                         $blog->showCategoryList($template);
1101                         $this->postBlogContent('categorylist',$blog);
1102                 }
1103                 else
1104                 {
1105                         $b =& $manager->getBlog(getBlogIDFromName($blogname));
1106                         $this->preBlogContent('categorylist',$b);
1107                         $b->showCategoryList($template);
1108                         $this->postBlogContent('categorylist',$b);
1109                 }
1110                 return;
1111         }
1112         
1113         /**
1114          * Actions::parse_commentform()
1115          * Parse skinvar commentform
1116          * 
1117          * @param       string  $destinationurl URI for redirection
1118          * @return      void
1119          */
1120         public function parse_commentform($destinationurl = '')
1121         {
1122                 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
1123                 
1124                 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
1125                 if ( stristr($destinationurl, 'action.php') )
1126                 {
1127                         $args = func_get_args();
1128                         $destinationurl = $args[1];
1129                         ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
1130                 }
1131                 
1132                 $actionurl = $CONF['ActionURL'];
1133                 
1134                 // if item is closed, show message and do nothing
1135                 $item =& $manager->getItem($itemid,0,0);
1136                 if ( $item['closed'] || !$blog->commentsEnabled() )
1137                 {
1138                         $this->doForm('commentform-closed');
1139                         return;
1140                 }
1141                 
1142                 if ( !$blog->isPublic() && !$member->isLoggedIn() )
1143                 {
1144                         $this->doForm('commentform-closedtopublic');
1145                         return;
1146                 }
1147                 
1148                 if ( !$destinationurl )
1149                 {
1150                         // note: createLink returns an HTML encoded URL
1151                         $destinationurl = Link::create_link(
1152                                 'item',
1153                                 array(
1154                                         'itemid' => $itemid,
1155                                         'title' => $item['title'],
1156                                         'timestamp' => $item['timestamp'],
1157                                         'extra' => $this->linkparams
1158                                 )
1159                         );
1160                 }
1161                 else
1162                 {
1163                         // HTML encode URL
1164                         $destinationurl = Entity::hsc($destinationurl);
1165                 }
1166                 
1167                 // values to prefill
1168                 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
1169                 if ( !$user )
1170                 {
1171                         $user = postVar('user');
1172                 }
1173                 
1174                 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
1175                 if ( !$userid )
1176                 {
1177                         $userid = postVar('userid');
1178                 }
1179                 
1180                 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
1181                 if (!$email)
1182                 {
1183                         $email = postVar('email');
1184                 }
1185                 
1186                 $body = postVar('body');
1187                 
1188                 $this->formdata = array(
1189                         'destinationurl' => $destinationurl,    // url is already HTML encoded
1190                         'actionurl' => Entity::hsc($actionurl),
1191                         'itemid' => $itemid,
1192                         'user' => Entity::hsc($user),
1193                         'userid' => Entity::hsc($userid),
1194                         'email' => Entity::hsc($email),
1195                         'body' => Entity::hsc($body),
1196                         'membername' => $member->getDisplayName(),
1197                         'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
1198                 );
1199                 
1200                 if ( !$member->isLoggedIn() )
1201                 {
1202                         $this->doForm('commentform-notloggedin');
1203                 }
1204                 else
1205                 {
1206                         $this->doForm('commentform-loggedin');
1207                 }
1208                 return;
1209         }
1210         
1211         /**
1212          * Actions::parse_comments()
1213          * Parse skinvar comments
1214          * include comments for one item
1215          * 
1216          * @param       string  $template       name of template
1217          * @return      void
1218          */
1219         public function parse_comments($template)
1220         {
1221                 global $manager, $blog, $highlight, $itemid;
1222                 
1223                 $template =& $manager->getTemplate($template);
1224                 $item =& $manager->getItem($itemid, 0, 0);
1225                 
1226                 // create parser object & action handler
1227                 $handler = new ItemActions($blog);
1228                 $handler->setTemplate($template);
1229                 $handler->setCurrentItem($item);
1230                 
1231                 $parser = new Parser($handler);
1232                 
1233                 $comments = new Comments($itemid);
1234                 $comments->setItemActions($handler);
1235                 // shows ALL comments
1236                 $comments->showComments($template, -1, 1, $highlight);
1237                 return;
1238         }
1239         
1240         /**
1241          * Actions::parse_errordiv()
1242          * Parse errordiv
1243          * 
1244          * @param       void
1245          * @return      void
1246          */
1247         public function parse_errordiv()
1248         {
1249                 global $errormessage;
1250                 if ( $errormessage )
1251                 {
1252                         echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
1253                 }
1254                 return;
1255         }
1256         
1257         /**
1258          * Actions::parse_errormessage()
1259          * Parse skinvar errormessage
1260          * 
1261          * @param       void
1262          * @return      void
1263          */
1264         public function parse_errormessage()
1265         {
1266                 global $errormessage;
1267                 echo $errormessage;
1268                 return;
1269         }
1270         
1271         /**
1272          * Actions::parse_formdata()
1273          * Parse formdata
1274          * 
1275          * @param       string  $what   key of format data
1276          * @return      void
1277          */
1278         public function parse_formdata($what)
1279         {
1280                 echo $this->formdata[$what];
1281                 return;
1282         }
1283         
1284         /**
1285          * Actions::parse_ifcat()
1286          * Parse ifcat
1287          * 
1288          * @param       string  $text
1289          * @return      void
1290          */
1291         public function parse_ifcat($text = '')
1292         {
1293                 if ( $text == '' )
1294                 {
1295                         // new behaviour
1296                         $this->parse_if('category');
1297                 }
1298                 else
1299                 {
1300                         // old behaviour
1301                         global $catid, $blog;
1302                         if ( $blog->isValidCategory($catid) )
1303                         {
1304                                 echo $text;
1305                         }
1306                 }
1307                 return;
1308         }
1309         
1310         /**
1311          * Actions::parse_image()
1312          * Parse skinvar image
1313          * 
1314          * @param       string  $what   name of tag
1315          * @return      void
1316          */
1317         public function parse_image($what = 'imgtag')
1318         {
1319                 global $CONF;
1320                 
1321                 $imagetext      = Entity::hsc(requestVar('imagetext'));
1322                 $imagepopup = requestVar('imagepopup');
1323                 $width          = intRequestVar('width');
1324                 $height         = intRequestVar('height');
1325                 $fullurl        = Entity::hsc($CONF['MediaURL'] . $imagepopup);
1326                 
1327                 switch ( $what )
1328                 {
1329                         case 'url':
1330                                 echo $fullurl;
1331                                 break;
1332                         case 'width':
1333                                 echo $width;
1334                                 break;
1335                         case 'height':
1336                                 echo $height;
1337                                 break;
1338                         case 'caption':
1339                         case 'text':
1340                                 echo $imagetext;
1341                                 break;
1342                         case 'imgtag':
1343                         default:
1344                                 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
1345                                 break;
1346                 }
1347                 return;
1348         }
1349         
1350         /**
1351          * Actions::parse_imagetext()
1352          * Parse skinvar imagetext
1353          * 
1354          * @param       void
1355          * @return      void
1356          */
1357         public function parse_imagetext()
1358         {
1359                 $this->parse_image('imagetext');
1360                 return;
1361         }
1362
1363         /**
1364          * Actions::parse_item()
1365          * Parse skinvar item
1366          * include one item (no comments)
1367          * 
1368          * @param       void
1369          * @return      void
1370          */
1371         public function parse_item($template)
1372         {
1373                 global $blog, $itemid, $highlight;
1374                 
1375                 // need this to select default category
1376                 $this->setBlogCategory($blog, '');
1377                 $this->preBlogContent('item',$blog);
1378                 $r = $blog->showOneitem($itemid, $template, $highlight);
1379                 if ( $r == 0 )
1380                 {
1381                         echo _ERROR_NOSUCHITEM;
1382                 }
1383                 $this->postBlogContent('item',$blog);
1384                 return;
1385         }
1386
1387         /**
1388          * Actions::parse_itemid()
1389          * Parse skinvar itemid
1390          * 
1391          * @param       void
1392          * @return      void
1393          */
1394         public function parse_itemid()
1395         {
1396                 global $itemid;
1397                 echo $itemid;
1398                 return;
1399         }
1400         
1401         /**
1402          * Actions::parseitemlink()
1403          * Parse skinvar itemlink
1404          * 
1405          * @param       void
1406          * @return      void
1407          */
1408         public function parse_itemlink($linktext = '')
1409         {
1410                 global $itemid;
1411                 $this->itemlink($itemid, $linktext);
1412                 return;
1413         }
1414         
1415         /**
1416          * Actions::parse_itemtitle()
1417          * Parse itemtitle
1418          * 
1419          * @param       void
1420          * @return      void
1421          */
1422         public function parse_itemtitle($format = '')
1423         {
1424                 global $manager, $itemid;
1425                 $item =& $manager->getItem($itemid,0,0);
1426                 
1427                 switch ( $format )
1428                 {
1429                         case 'xml':
1430                                 echo Entity::hen($item['title']);
1431                                 break;
1432                         case 'raw':
1433                                 echo $item['title'];
1434                                 break;
1435                         case 'attribute':
1436                         default:
1437                                 echo Entity::hsc(strip_tags($item['title']));
1438                                 break;
1439                 }
1440                 return;
1441         }
1442         
1443         /**
1444          * Actions::parse_loginform()
1445          * Parse skinvar loginform
1446          * 
1447          * @param       void
1448          * @return      void
1449          */
1450         public function parse_loginform()
1451         {
1452                 global $member, $CONF;
1453                 if ( !$member->isLoggedIn() )
1454                 {
1455                         $filename = 'loginform-notloggedin';
1456                         $this->formdata = array();
1457                 }
1458                 else
1459                 {
1460                         $filename = 'loginform-loggedin';
1461                         $this->formdata = array(
1462                                 'membername' => $member->getDisplayName(),
1463                         );
1464                 }
1465                 $this->doForm($filename);
1466                 return;
1467         }
1468         
1469         /**
1470          * Actions::parse_member()
1471          * Parse skinvar member
1472          * (includes a member info thingie)
1473          * 
1474          * @param       string  $what   which memberdata is needed
1475          * @return      void
1476          */
1477         public function parse_member($what)
1478         {
1479                 global $memberinfo, $member, $CONF;
1480                 
1481                 // 1. only allow the member-details-page specific variables on member pages
1482                 if ( $this->skintype == 'member' )
1483                 {
1484                         switch( $what )
1485                         {
1486                                 case 'name':
1487                                         echo Entity::hsc($memberinfo->getDisplayName());
1488                                         break;
1489                                 case 'realname':
1490                                         echo Entity::hsc($memberinfo->getRealName());
1491                                         break;
1492                                 case 'notes':
1493                                         echo Entity::hsc($memberinfo->getNotes());
1494                                         break;
1495                                 case 'url':
1496                                         echo Entity::hsc($memberinfo->getURL());
1497                                         break;
1498                                 case 'email':
1499                                         echo Entity::hsc($memberinfo->getEmail());
1500                                         break;
1501                                 case 'id':
1502                                         echo Entity::hsc($memberinfo->getID());
1503                                         break;
1504                         }
1505                 }
1506                 
1507                 // 2. the next bunch of options is available everywhere, as long as the user is logged in
1508                 if ( $member->isLoggedIn() )
1509                 {
1510                         switch( $what )
1511                         {
1512                                 case 'yourname':
1513                                         echo $member->getDisplayName();
1514                                         break;
1515                                 case 'yourrealname':
1516                                         echo $member->getRealName();
1517                                         break;
1518                                 case 'yournotes':
1519                                         echo $member->getNotes();
1520                                         break;
1521                                 case 'yoururl':
1522                                         echo $member->getURL();
1523                                         break;
1524                                 case 'youremail':
1525                                         echo $member->getEmail();
1526                                         break;
1527                                 case 'yourid':
1528                                         echo $member->getID();
1529                                         break;
1530                                 case 'yourprofileurl':
1531                                         if ($CONF['URLMode'] == 'pathinfo')
1532                                                 echo Link::create_member_link($member->getID());
1533                                         else
1534                                                 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
1535                                         break;
1536                         }
1537                 }
1538                 return;
1539         }
1540         
1541         /**
1542          * Link::parse_membermailform()
1543          * Parse skinvar membermailform
1544          * 
1545          * @param       integer $rows   the height for textarea
1546          * @param       integer $cols   the width for textarea
1547          * @param       string  $desturl        URI to redirect
1548          * @return      void
1549          */
1550         public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
1551         {
1552                 global $member, $CONF, $memberid;
1553                 
1554                 if ( $desturl == '' )
1555                 {
1556                         if ( $CONF['URLMode'] == 'pathinfo' )
1557                         {
1558                                 $desturl = Link::create_member_link($memberid);
1559                         }
1560                         else
1561                         {
1562                                 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
1563                         }
1564                 }
1565                 
1566                 $message = postVar('message');
1567                 $frommail = postVar('frommail');
1568                 
1569                 $this->formdata = array(
1570                         'url' => Entity::hsc($desturl),
1571                         'actionurl' => Entity::hsc($CONF['ActionURL']),
1572                         'memberid' => $memberid,
1573                         'rows' => $rows,
1574                         'cols' => $cols,
1575                         'message' => Entity::hsc($message),
1576                         'frommail' => Entity::hsc($frommail)
1577                 );
1578                 
1579                 if ( $member->isLoggedIn() )
1580                 {
1581                         $this->doForm('membermailform-loggedin');
1582                 }
1583                 else if ( $CONF['NonmemberMail'] )
1584                 {
1585                         $this->doForm('membermailform-notloggedin');
1586                 }
1587                 else
1588                 {
1589                         $this->doForm('membermailform-disallowed');
1590                 }
1591                 return;
1592         }
1593         
1594         /**
1595          * Actions::parse_nextarchive()
1596          * Parse skinvar nextarchive
1597          * 
1598          * @param       void
1599          * @return      void
1600          */
1601         public function parse_nextarchive()
1602         {
1603                 global $archivenext;
1604                 echo $archivenext;
1605                 return;
1606         }
1607         
1608         /**
1609          * Parse skinvar nextitem
1610          * (include itemid of next item)
1611          * 
1612          * @param       void
1613          * @return      void
1614          */
1615         public function parse_nextitem()
1616         {
1617                 global $itemidnext;
1618                 if ( isset($itemidnext) )
1619                 {
1620                         echo (int)$itemidnext;
1621                 }
1622                 return;
1623         }
1624         
1625         /**
1626          * Actions::parse_nextitemtitle()
1627          * Parse skinvar nextitemtitle
1628          * (include itemtitle of next item)
1629          * 
1630          * @param       string  $format format of text
1631          * @return      void
1632          */
1633         public function parse_nextitemtitle($format = '')
1634         {
1635                 global $itemtitlenext;
1636                 
1637                 switch ( $format )
1638                 {
1639                         case 'xml':
1640                                 echo Entity::hen($itemtitlenext);
1641                                 break;
1642                         case 'raw':
1643                                 echo $itemtitlenext;
1644                                 break;
1645                         case 'attribute':
1646                         default:
1647                                 echo Entity::hsc($itemtitlenext);
1648                                 break;
1649                 }
1650                 return;
1651         }
1652         
1653         /**
1654          * Actions::parse_nextlink()
1655          * Parse skinvar nextlink
1656          * 
1657          * @param       string  $linktext       text for content of anchor element
1658          * @param       integer $amount         the amount of items in a display
1659          * @param       integer $recount        increment from this value
1660          * @return      void
1661          */
1662         public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
1663         {
1664                 global $itemidnext, $archivenext, $startpos;
1665                 if ( $this->skintype == 'item' )
1666                 {
1667                         $this->itemlink($itemidnext, $linktext);
1668                 }
1669                 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
1670                 {
1671                         $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
1672                 }
1673                 else
1674                 {
1675                         $this->archivelink($archivenext, $linktext);
1676                 }
1677                 return;
1678         }
1679
1680         /**
1681          * Actions::parse_nucleusbutton()
1682          * Parse skinvar nucleusbutton
1683          * 
1684          * @param       string  $imgurl URL  for image
1685          * @param       integer $imgwidth       width of image
1686          * @param       integer $imgheidht      height of image
1687          */
1688         public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
1689         {
1690                 global $CONF;
1691                 if ( $imgurl == '' )
1692                 {
1693                         $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
1694                 }
1695                 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
1696                 {
1697                         // when skindit IncludeMode is used: start from skindir
1698                         $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
1699                 }
1700                 
1701                 $this->formdata = array(
1702                         'imgurl' => $imgurl,
1703                         'imgwidth' => $imgwidth,
1704                         'imgheight' => $imgheight,
1705                 );
1706                 $this->doForm('nucleusbutton');
1707                 return;
1708         }
1709         
1710         /**
1711          * Actions::parse_otherarchive()
1712          * Parse skinvar otherarchive
1713          * 
1714          * @param       string  $blogname       name of weblog
1715          * @param       string  $template       name of template
1716          * @param       string  $category       name of category
1717          * @return      void
1718          */     
1719         public function parse_otherarchive($blogname, $template, $category = '')
1720         {
1721                 global $archive, $manager;
1722                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
1723                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1724                 $this->setBlogCategory($b, $category);
1725                 $this->preBlogContent('otherachive',$b);
1726                 $b->showArchive($template, $y, $m, $d);
1727                 $this->postBlogContent('otherachive',$b);
1728                 return;
1729         }
1730         
1731         /**
1732          * Actions::parse_otherarchivedaylist()
1733          * Parse skinvar otherarchivedaylist
1734          * 
1735          * @param       string  $blogname       name of weblog
1736          * @param       string  $template       name of template
1737          * @param       string  $category       name of category
1738          * @param       integer $limit          the amount of items in a display
1739          * @return      void
1740          */
1741         public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
1742         {
1743                 global $manager;
1744                 if ( $category == 'all')
1745                 {
1746                         $category = '';
1747                 }
1748                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1749                 $this->setBlogCategory($b, $category);
1750                 $this->preBlogContent('otherarchivelist',$b);
1751                 $b->showArchiveList($template, 'day', $limit);
1752                 $this->postBlogContent('otherarchivelist',$b);
1753                 return;
1754         }
1755         
1756         /**
1757          * Actions::parse_otherarchivelist()
1758          * Parse skinvar otherarchivelist
1759          * 
1760          * @param       string  $blogname       name of weblog
1761          * @param       string  $template       name of template
1762          * @param       string  $category       name of category
1763          * @param       integer $limit          the amount of items in a display
1764          * @return      void
1765          */
1766         public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
1767         {
1768                 global $manager;
1769                 if ( $category == 'all' )
1770                 {
1771                         $category = '';
1772                 }
1773                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1774                 $this->setBlogCategory($b, $category);
1775                 $this->preBlogContent('otherarchivelist',$b);
1776                 $b->showArchiveList($template, 'month', $limit);
1777                 $this->postBlogContent('otherarchivelist',$b);
1778                 return;
1779         }
1780         
1781         /**
1782          * Actions::parse_otherarchiveyearlist()
1783          * Parse skinvar otherarchiveyearlist
1784          * 
1785          * @param       string  $blogname       name of weblog
1786          * @param       string  $template       name of template
1787          * @param       string  $category       name of category
1788          * @limit       integer $limit          the amount of items in a display
1789          */
1790         public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
1791         {
1792                 global $manager;
1793                 if ( $category == 'all' )
1794                 {
1795                         $category = '';
1796                 }
1797                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1798                 $this->setBlogCategory($b, $category);
1799                 $this->preBlogContent('otherarchivelist',$b);
1800                 $b->showArchiveList($template, 'year', $limit);
1801                 $this->postBlogContent('otherarchivelist',$b);
1802                 return;
1803         }
1804         
1805         /**
1806          * Actions::parse_otherblog()
1807          * Parse skinvar otherblog
1808          * 
1809          * @param       string  $blogname       name of weblog
1810          * @param       string  $template       name of template
1811          * @param       mixed   $amount         the amount of items, in case it includes the beginning
1812          * @param       string  $category       name of category
1813          * @return      void
1814          */
1815         public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
1816         {
1817                 global $manager;
1818                 
1819                 list($limit, $offset) = sscanf($amount, '%d(%d)');
1820                 
1821                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1822                 $this->setBlogCategory($b, $category);
1823                 $this->preBlogContent('otherblog',$b);
1824                 $this->amountfound = $b->readLog($template, $limit, $offset);
1825                 $this->postBlogContent('otherblog',$b);
1826                 return;
1827         }
1828         
1829         /**
1830          * Actions::parse_othersearchresults()
1831          * Parse skinvar othersearchresults
1832          * 
1833          * @param       string  $blogname       name of weblog
1834          * @param       string  $template       name of template
1835          * @param       integer $maxresults     the amount of results
1836          * @return      void
1837          */
1838         public function parse_othersearchresults($blogname, $template, $maxresults = 50)
1839         {
1840                 global $query, $amount, $manager, $startpos;
1841                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1842                 // need this to select default category
1843                 $this->setBlogCategory($b, '');
1844                 $this->preBlogContent('othersearchresults',$b);
1845                 $b->search($query, $template, $amount, $maxresults, $startpos);
1846                 $this->postBlogContent('othersearchresults',$b);
1847                 return;
1848         }
1849         
1850         /**
1851          * Actions::parse_plugin()
1852          * Executes a plugin skinvar
1853          * extra parameters can be added
1854          * 
1855          * @param       string  $pluginName     name of plugin (without the NP_)
1856          * @return      void
1857          */
1858         public function parse_plugin($pluginName)
1859         {
1860                 global $manager;
1861                 
1862                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
1863                 if ( !$plugin )
1864                 {
1865                         return;
1866                 }
1867                 
1868                 // get arguments
1869                 $params = func_get_args();
1870                 
1871                 // remove plugin name
1872                 array_shift($params);
1873                 
1874                 // add skin type on front
1875                 array_unshift($params, $this->skintype);
1876                 
1877                 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
1878                 return;
1879         }
1880         
1881         /**
1882          * Actions::parse_prevarchive()
1883          * Parse skinvar prevarchive
1884          * 
1885          * @param       void
1886          * @return      void
1887          */
1888         public function parse_prevarchive()
1889         {
1890                 global $archiveprev;
1891                 echo $archiveprev;
1892         }
1893         
1894         /**
1895          * Actions::parse_preview()
1896          * Parse skinvar preview
1897          * 
1898          * @param       string  $template       name of tempalte
1899          * @return      void
1900          */
1901         public function parse_preview($template)
1902         {
1903                 global $blog, $CONF, $manager;
1904                 
1905                 $template =& $manager->getTemplate($template);
1906                 
1907                 $row['body'] = '<span id="prevbody"></span>';
1908                 $row['title'] = '<span id="prevtitle"></span>';
1909                 $row['more'] = '<span id="prevmore"></span>';
1910                 $row['itemlink'] = '';
1911                 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
1912                 
1913                 echo Template::fill($template['ITEM_HEADER'],$row);
1914                 echo Template::fill($template['ITEM'],$row);
1915                 echo Template::fill($template['ITEM_FOOTER'],$row);
1916                 return;
1917         }
1918         
1919         /**
1920          * Actions::parse_previtem()
1921          * Parse skinvar previtem
1922          * (include itemid of prev item)
1923          * 
1924          * @param       void
1925          * @return      void
1926          */
1927         public function parse_previtem()
1928         {
1929                 global $itemidprev;
1930                 if ( isset($itemidprev) )
1931                 {
1932                         echo (integer) $itemidprev;
1933                 }
1934                 return;
1935         }
1936         
1937         /**
1938          * Actions::parse_previtemtitle()
1939          * Parse skinvar previtemtitle
1940          * (include itemtitle of prev item)
1941          * 
1942          * @param       String  $format string format
1943          * @return      String  formatted string
1944          */
1945         public function parse_previtemtitle($format = '')
1946         {
1947                 global $itemtitleprev;
1948                 
1949                 switch ( $format )
1950                 {
1951                         case 'xml':
1952                                 echo Entity::hen($itemtitleprev);
1953                                 break;
1954                         case 'raw':
1955                                 echo $itemtitleprev;
1956                                 break;
1957                         case 'attribute':
1958                         default:
1959                                 echo Entity::hsc($itemtitleprev);
1960                                 break;
1961                 }
1962                 return;
1963         }
1964         
1965         /**
1966          * Actions::parse_prevlink()
1967          * Parse skinvar prevlink
1968          * 
1969          * @param       string  $linktext       text as a content of anchor element
1970          * @param       integer the amount of links
1971          * @return      void
1972          */
1973         public function parse_prevlink($linktext = '', $amount = 10)
1974         {
1975                 global $itemidprev, $archiveprev, $startpos;
1976                 
1977                 if ( $this->skintype == 'item' )
1978                 {
1979                         $this->itemlink($itemidprev, $linktext);
1980                 }
1981                 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
1982                 {
1983                         $this->searchlink($amount, $startpos, 'prev', $linktext);
1984                 }
1985                 else
1986                 {
1987                         $this->archivelink($archiveprev, $linktext);
1988                 }
1989                 return;
1990         }
1991         
1992         /**
1993          * Actions::parse_query()
1994          * Parse skinvar query
1995          * (includes the search query)   
1996          * 
1997          * @param       void
1998          * @return      void
1999          */
2000         public function parse_query()
2001         {
2002                 global $query;
2003                 echo Entity::hsc($query);
2004                 return;
2005         }
2006         
2007         /**
2008          * Actions::parse_referer()
2009          * Parse skinvar referer
2010          * 
2011          * @param       void
2012          * @return      void
2013          */
2014         public function parse_referer()
2015         {
2016                 echo Entity::hsc(serverVar('HTTP_REFERER'));
2017                 return;
2018         }
2019         
2020         /**
2021          * Actions::parse_searchform()
2022          * Parse skinvar searchform
2023          * 
2024          * @param       string  $blogname       name of weblog
2025          * @return      void
2026          */
2027         public function parse_searchform($blogname = '')
2028         {
2029                 global $CONF, $manager, $maxresults;
2030                 if ( $blogname )
2031                 {
2032                         $blog =& $manager->getBlog(getBlogIDFromName($blogname));
2033                 }
2034                 else
2035                 {
2036                         global $blog;
2037                 }
2038                 // use default blog when no blog is selected
2039                 $this->formdata = array(
2040                         'id'    => $blog?$blog->getID():$CONF['DefaultBlog'],
2041                         'query' => Entity::hsc(getVar('query')),
2042                 );
2043                 $this->doForm('searchform');
2044                 return;
2045         }
2046         
2047         /**
2048          * Actions::parse_searchresults()
2049          * Parse skinvar searchresults
2050          * 
2051          * @param       string  $template       name of tempalte
2052          * @param       integer $maxresults     searched items in a display
2053          * @return      void;
2054          */
2055         public function parse_searchresults($template, $maxresults = 50 )
2056         {
2057                 global $blog, $query, $amount, $startpos;
2058                 
2059                 $this->setBlogCategory($blog, '');      // need this to select default category
2060                 $this->preBlogContent('searchresults',$blog);
2061                 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
2062                 $this->postBlogContent('searchresults',$blog);
2063                 return;
2064         }
2065         
2066         /**
2067          * Actions::parse_self()
2068          * Parse skinvar self
2069          * 
2070          * @param       void
2071          * @return      void
2072          */
2073         public function parse_self()
2074         {
2075                 global $CONF;
2076                 echo $CONF['Self'];
2077                 return;
2078         }
2079         
2080         /**
2081          * Actions::parse_sitevar()
2082          * Parse skinvar sitevar
2083          * (include a sitevar)
2084          * 
2085          * @param       string  $which
2086          * @return      void
2087          */
2088         public function parse_sitevar($which)
2089         {
2090                 global $CONF;
2091                 switch ( $which )
2092                 {
2093                         case 'url':
2094                                 echo $CONF['IndexURL'];
2095                                 break;
2096                         case 'name':
2097                                 echo $CONF['SiteName'];
2098                                 break;
2099                         case 'admin':
2100                                 echo $CONF['AdminEmail'];
2101                                 break;
2102                         case 'adminurl':
2103                                 echo $CONF['AdminURL'];
2104                 }
2105                 return;
2106         }
2107         
2108         /**
2109          * Actions::parse_skinname()
2110          * Parse skinname
2111          * 
2112          * @param       void
2113          * @return      void
2114          */
2115         public function parse_skinname()
2116         {
2117                 echo $this->parser->skin->getName();
2118                 return;
2119         }
2120         
2121         /**
2122          * Actions::parse_skintype()
2123          * Parse skintype (experimental)
2124          * 
2125          * @param       void
2126          * @return      void
2127          */
2128         public function parse_skintype()
2129         {
2130                 echo $this->skintype;
2131                 return;
2132         }
2133         
2134         /**
2135          * Actions::parse_ticket()
2136          * Parse ticket
2137          * 
2138          * @param       void
2139          * @return      void
2140          */
2141         public function parse_ticket()
2142         {
2143                 global $manager;
2144                 $manager->addTicketHidden();
2145                 return;
2146         }
2147
2148         /**
2149          * Actions::parse_todaylink()
2150          * Parse skinvar todaylink
2151          * A link to the today page (depending on selected blog, etc...)
2152          *
2153          * @param       string  $linktext       text for link
2154          * @return      void
2155          */
2156         public function parse_todaylink($linktext = '')
2157         {
2158                 global $blog, $CONF;
2159                 if ( $blog )
2160                 {
2161                         echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
2162                 }
2163                 else
2164                 {
2165                         echo $this->link($CONF['SiteUrl'], $linktext);
2166                 }
2167                 return;
2168         }
2169         
2170         /**
2171          * Parse vars
2172          * When commentform is not used, to include a hidden field with itemid   
2173          * 
2174          * @param       void
2175          * @return      void
2176          */
2177         public function parse_vars()
2178         {
2179                 global $itemid;
2180                 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
2181                 return;
2182         }
2183
2184         /**
2185          * Actions::parse_version()
2186          * Parse skinvar version
2187          * (include nucleus versionnumber)       
2188          * 
2189          * @param       void
2190          * @return      void
2191          */
2192         public function parse_version()
2193         {
2194                 global $nucleus;
2195                 echo 'Nucleus CMS ' . $nucleus['version'];
2196                 return;
2197         }
2198         
2199         /**
2200          * Actions::parse_sticky()
2201          * Parse skinvar sticky
2202          * 
2203          * @param       integer $itemnumber     id of item
2204          * @param       string  $template       name of template
2205          * @return      void
2206          */
2207         public function parse_sticky($itemnumber = 0, $template = '')
2208         {
2209                 global $manager;
2210                 
2211                 $itemnumber = intval($itemnumber);
2212                 $itemarray = array($itemnumber);
2213                 
2214                 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
2215                 $this->preBlogContent('sticky',$b);
2216                 $this->amountfound = $b->readLogFromList($itemarray, $template);
2217                 $this->postBlogContent('sticky',$b);
2218                 return;
2219         }
2220 }