OSDN Git Service

1b6b5cfd0ea05f00749dfd2a78851b567dc81869
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / libs / ACTIONS.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2009 The Nucleus Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  */
12 /**
13  * This class contains the functions that get called by using
14  * the special tags in the skins
15  *
16  * The allowed tags for a type of skinpart are defined by the
17  * SKIN::getAllowedActionsForType($type) method
18  *
19  * @license http://nucleuscms.org/license.txt GNU General Public License
20  * @copyright Copyright (C) 2002-2009 The Nucleus Group
21  * @version $Id$
22  * @version $NucleusJP: ACTIONS.php,v 1.8 2007/04/19 06:05:55 kimitake Exp $
23  */
24
25 class ACTIONS extends BaseActions {
26
27         // part of the skin currently being parsed ('index', 'item', 'archive',
28         // 'archivelist', 'member', 'search', 'error', 'imagepopup')
29         var $skintype;
30
31         // contains an assoc array with parameters that need to be included when
32         // generating links to items/archives/... (e.g. catid)
33         var $linkparams;
34
35         // reference to the skin object for which a part is being parsed
36         var $skin;
37
38         // used when including templated forms from the include/ dir. The $formdata var
39         // contains the values to fill out in there (assoc array name -> value)
40         var $formdata;
41
42         // filled out with the number of displayed items after calling one of the
43         // (other)blog/(other)searchresults skinvars.
44         var $amountfound;
45
46         /**
47          * Constructor for a new ACTIONS object
48          */
49         function ACTIONS($type) {
50                 // call constructor of superclass first
51                 $this->BaseActions();
52
53                 $this->skintype = $type;
54
55                 global $catid;
56                 if ($catid)
57                         $this->linkparams = array('catid' => $catid);
58         }
59
60         /**
61          *  Set the skin
62          */
63         function setSkin(&$skin) {
64                 $this->skin =& $skin;
65         }
66
67         /**
68          *  Set the parser
69          */
70         function setParser(&$parser) {
71                 $this->parser =& $parser;
72         }
73
74         /**
75          *      Forms get parsedincluded now, using an extra <formdata> skinvar
76         */
77         function doForm($filename) {
78                 global $DIR_NUCLEUS;
79                 array_push($this->parser->actions,'formdata','text','callback','errordiv','ticket');
80                 $oldIncludeMode = PARSER::getProperty('IncludeMode');
81                 $oldIncludePrefix = PARSER::getProperty('IncludePrefix');
82                 PARSER::setProperty('IncludeMode','normal');
83                 PARSER::setProperty('IncludePrefix','');
84                 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
85                 PARSER::setProperty('IncludeMode',$oldIncludeMode);
86                 PARSER::setProperty('IncludePrefix',$oldIncludePrefix);
87                 array_pop($this->parser->actions);              // errordiv
88                 array_pop($this->parser->actions);              // callback
89                 array_pop($this->parser->actions);              // text
90                 array_pop($this->parser->actions);              // formdata
91                 array_pop($this->parser->actions);              // ticket
92         }
93
94         /**
95          * Checks conditions for if statements
96          *
97          * @param string $field type of <%if%>
98          * @param string $name property of field
99          * @param string $value value of property
100          */
101         function checkCondition($field, $name='', $value = '') {
102                 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
103
104                 $condition = 0;
105                 switch($field) {
106                         case 'category':
107                                 $condition = ($blog && $this->_ifCategory($name,$value));
108                                 break;
109                         case 'blogsetting':
110                                 $condition = ($blog && ($blog->getSetting($name) == $value));
111                                 break;
112                         case 'loggedin':
113                                 $condition = $member->isLoggedIn();
114                                 break;
115                         case 'onteam':
116                                 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
117                                 break;
118                         case 'admin':
119                                 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
120                                 break;
121                         case 'nextitem':
122                                 $condition = ($itemidnext != '');
123                                 break;
124                         case 'previtem':
125                                 $condition = ($itemidprev != '');
126                                 break;
127                         case 'archiveprevexists':
128                                 $condition = ($archiveprevexists == true);
129                                 break;
130                         case 'archivenextexists':
131                                 $condition = ($archivenextexists == true);
132                                 break;
133                         case 'skintype':
134                                 $condition = ($name == $this->skintype);
135                                 break;
136                         case 'hasplugin':
137                                 $condition = $this->_ifHasPlugin($name, $value);
138                                 break;
139                         default:
140                                 $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
141                                 break;
142                 }
143                 return $condition;
144         }
145
146         /**
147          *      hasplugin,PlugName
148          *         -> checks if plugin exists
149          *      hasplugin,PlugName,OptionName
150          *         -> checks if the option OptionName from plugin PlugName is not set to 'no'
151          *      hasplugin,PlugName,OptionName=value
152          *         -> checks if the option OptionName from plugin PlugName is set to value
153          */
154         function _ifHasPlugin($name, $value) {
155                 global $manager;
156                 $condition = false;
157                 // (pluginInstalled method won't write a message in the actionlog on failure)
158                 if ($manager->pluginInstalled('NP_'.$name)) {
159                         $plugin =& $manager->getPlugin('NP_' . $name);
160                         if ($plugin != NULL) {
161                                 if ($value == "") {
162                                         $condition = true;
163                                 } else {
164                                         list($name2, $value2) = explode('=', $value, 2);
165                                         if ($value2 == "" && $plugin->getOption($name2) != 'no') {
166                                                 $condition = true;
167                                         } else if ($plugin->getOption($name2) == $value2) {
168                                                 $condition = true;
169                                         }
170                                 }
171                         }
172                 }
173                 return $condition;
174         }
175
176         /**
177          * Checks if a plugin exists and call its doIf function
178          */
179         function _ifPlugin($name, $key = '', $value = '') {
180                 global $manager;
181
182                 $plugin =& $manager->getPlugin('NP_' . $name);
183                 if (!$plugin) return;
184
185                 $params = func_get_args();
186                 array_shift($params);
187
188                 return call_user_func_array(array(&$plugin, 'doIf'), $params);
189         }
190
191         /**
192          *  Different checks for a category
193          */
194         function _ifCategory($name = '', $value='') {
195                 global $blog, $catid;
196
197                 // when no parameter is defined, just check if a category is selected
198                 if (($name != 'catname' && $name != 'catid') || ($value == ''))
199                         return $blog->isValidCategory($catid);
200
201                 // check category name
202                 if ($name == 'catname') {
203                         $value = $blog->getCategoryIdFromName($value);
204                         if ($value == $catid)
205                                 return $blog->isValidCategory($catid);
206                 }
207
208                 // check category id
209                 if (($name == 'catid') && ($value == $catid))
210                         return $blog->isValidCategory($catid);
211
212                 return false;
213         }
214
215         /**
216          *  Checks if a member is on the team of a blog and return his rights
217          */
218         function _ifOnTeam($blogName = '') {
219                 global $blog, $member, $manager;
220
221                 // when no blog found
222                 if (($blogName == '') && (!is_object($blog)))
223                         return 0;
224
225                 // explicit blog selection
226                 if ($blogName != '')
227                         $blogid = getBlogIDFromName($blogName);
228
229                 if (($blogName == '') || !$manager->existsBlogID($blogid))
230                         // use current blog
231                         $blogid = $blog->getID();
232
233                 return $member->teamRights($blogid);
234         }
235
236         /**
237          *  Checks if a member is admin of a blog
238          */
239         function _ifAdmin($blogName = '') {
240                 global $blog, $member, $manager;
241
242                 // when no blog found
243                 if (($blogName == '') && (!is_object($blog)))
244                         return 0;
245
246                 // explicit blog selection
247                 if ($blogName != '')
248                         $blogid = getBlogIDFromName($blogName);
249
250                 if (($blogName == '') || !$manager->existsBlogID($blogid))
251                         // use current blog
252                         $blogid = $blog->getID();
253
254                 return $member->isBlogAdmin($blogid);
255         }
256         
257         /**
258          * returns either
259          *              - a raw link (html/xml encoded) when no linktext is provided
260          *              - a (x)html <a href... link when a text is present (text htmlencoded)
261          */
262         function _link($url, $linktext = '')
263         {
264                 $u = htmlspecialchars($url);
265                 $u = preg_replace("/&amp;amp;/",'&amp;',$u); // fix URLs that already had encoded ampersands
266                 if ($linktext != '')
267                         $l = '<a href="' . $u .'">'.htmlspecialchars($linktext).'</a>';
268                 else
269                         $l = $u;
270                 return $l;
271         }
272         
273         /**
274          * Outputs a next/prev link
275          *
276          * @param $maxresults
277          *              The maximum amount of items shown per page (e.g. 10)
278          * @param $startpos
279          *              Current start position (requestVar('startpos'))
280          * @param $direction
281          *              either 'prev' or 'next'
282          * @param $linktext
283          *              When present, the output will be a full <a href...> link. When empty,
284          *              only a raw link will be outputted
285          */
286         function _searchlink($maxresults, $startpos, $direction, $linktext = '') {
287                 global $CONF, $blog, $query, $amount;
288                 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
289                 $startpos       = intval($startpos);            // will be 0 when empty.
290                 $parsed         = parse_url(serverVar('REQUEST_URI'));
291                 $parsed         = $parsed['query'];
292                 $url            = '';
293
294                 switch ($direction) {
295                         case 'prev':
296                                 if ( intval($startpos) - intval($maxresults) >= 0) {
297                                         $startpos       = intval($startpos) - intval($maxresults);
298                                         $url            = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);
299                                 }
300                                 break;
301                         case 'next':
302                                 $iAmountOnPage = $this->amountfound;
303                                 if ($iAmountOnPage == 0)
304                                 {
305                                         // [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
306                                         // try a count query
307                                         switch ($this->skintype)
308                                         {
309                                                 case 'index':
310                                                         $sqlquery = $blog->getSqlBlog('', 'count');
311                                                         break;
312                                                 case 'search':
313                                                         $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
314                                                         break;
315                                         }
316                                         if ($sqlquery)
317                                                 $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
318                                 }
319                                 if (intval($iAmountOnPage) >= intval($maxresults)) {
320                                         $startpos       = intval($startpos) + intval($maxresults);
321                                         $url            = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);
322                                 }
323                                 break;
324                         default:
325                                 break;
326                 } // switch($direction)
327
328                 if ($url != '')
329                         echo $this->_link($url, $linktext);
330         }
331
332         /**
333          *  Creates an item link and if no id is given a todaylink 
334          */
335         function _itemlink($id, $linktext = '') {
336                 global $CONF;
337                 if ($id)
338                         echo $this->_link(createItemLink($id, $this->linkparams), $linktext);
339                 else
340                         $this->parse_todaylink($linktext);
341         }
342         
343         /**
344          *  Creates an archive link and if no id is given a todaylink 
345          */
346         function _archivelink($id, $linktext = '') {
347                 global $CONF, $blog;
348                 if ($id)
349                         echo $this->_link(createArchiveLink($blog->getID(), $id, $this->linkparams), $linktext);
350                 else
351                         $this->parse_todaylink($linktext);
352         }
353         
354         /**
355           * Helper function that sets the category that a blog will need to use
356           *
357           * @param $blog
358           *             An object of the blog class, passed by reference (we want to make changes to it)
359           * @param $catname
360           *             The name of the category to use
361           */
362         function _setBlogCategory(&$blog, $catname) {
363                 global $catid;
364                 if ($catname != '')
365                         $blog->setSelectedCategoryByName($catname);
366                 else
367                         $blog->setSelectedCategory($catid);
368         }
369
370         /**
371          *  Notifies the Manager that a PreBlogContent event occurs
372          */
373         function _preBlogContent($type, &$blog) {
374                 global $manager;
375                 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
376         }
377
378         /**
379          *  Notifies the Manager that a PostBlogContent event occurs
380          */
381         function _postBlogContent($type, &$blog) {
382                 global $manager;
383                 $manager->notify('PostBlogContent',array('blog' => &$blog, 'type' => $type));
384         }
385         
386         /**
387          * Parse skinvar additemform
388          */
389         function parse_additemform() {
390                 global $blog, $CONF;
391                 $this->formdata = array(
392                         'adminurl' => htmlspecialchars($CONF['AdminURL'],ENT_QUOTES),
393                         'catid' => $blog->getDefaultCategory()
394                 );
395                 $blog->InsertJavaScriptInfo();
396                 $this->doForm('additemform');
397         }
398         \r
399         /**\r
400          * Parse skinvar addlink\r
401          * A Link that allows to open a bookmarklet to add an item\r
402          */\r
403         function parse_addlink() {\r
404                 global $CONF, $member, $blog;\r
405                 if ($member->isLoggedIn() && $member->isTeamMember($blog->blogid) ) {\r
406                         echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;\r
407                 }\r
408         }\r
409         \r
410         /**\r
411          * Parse skinvar addpopupcode\r
412          * Code that opens a bookmarklet in an popup window\r
413          */\r
414         function parse_addpopupcode() {\r
415                 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;";\r
416         }\r
417         
418         /**
419          * Parse skinvar adminurl
420          * (shortcut for admin url)      
421          */
422         function parse_adminurl() {
423                 $this->parse_sitevar('adminurl');
424         }
425
426         /**
427          * Parse skinvar archive
428          */
429         function parse_archive($template, $category = '') {
430                 global $blog, $archive;
431                 // can be used with either yyyy-mm or yyyy-mm-dd
432                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
433                 $this->_setBlogCategory($blog, $category);
434                 $this->_preBlogContent('achive',$blog);
435                 $blog->showArchive($template, $y, $m, $d);
436                 $this->_postBlogContent('achive',$blog);
437
438         }
439
440         /**
441           * %archivedate(locale,date format)%
442           */
443         function parse_archivedate($locale = '-def-') {
444                 global $archive;
445
446                 if ($locale == '-def-')
447                         setlocale(LC_TIME,$template['LOCALE']);
448                 else
449                         setlocale(LC_TIME,$locale);
450
451                 // get archive date
452                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
453
454                 // get format
455                 $args = func_get_args();
456                 // format can be spread over multiple parameters
457                 if (sizeof($args) > 1) {
458                         // take away locale
459                         array_shift($args);
460                         // implode
461                         $format=implode(',',$args);
462                 } elseif ($d == 0) {
463                         $format = '%B %Y';
464                 } else {
465                         $format = '%d %B %Y';
466                 }
467
468                 echo strftime($format,mktime(0,0,0,$m,$d?$d:1,$y));
469         }
470
471         /**
472          *  Parse skinvar archivedaylist
473          */             
474         function parse_archivedaylist($template, $category = 'all', $limit = 0) {
475                 global $blog;
476                 if ($category == 'all') $category = '';
477                 $this->_preBlogContent('archivelist',$blog);
478                 $this->_setBlogCategory($blog, $category);
479                 $blog->showArchiveList($template, 'day', $limit);
480                 $this->_postBlogContent('archivelist',$blog);
481         }
482         
483         /**
484          *      A link to the archives for the current blog (or for default blog)
485          */
486         function parse_archivelink($linktext = '') {
487                 global $blog, $CONF;
488                 if ($blog)
489                         echo $this->_link(createArchiveListLink($blog->getID(),$this->linkparams), $linktext);
490                 else
491                         echo $this->_link(createArchiveListLink(), $linktext);
492         }
493
494         function parse_archivelist($template, $category = 'all', $limit = 0) {
495                 global $blog;
496                 if ($category == 'all') $category = '';
497                 $this->_preBlogContent('archivelist',$blog);
498                 $this->_setBlogCategory($blog, $category);
499                 $blog->showArchiveList($template, 'month', $limit);
500                 $this->_postBlogContent('archivelist',$blog);
501         }
502
503         /**
504          * Parse skinvar archivetype
505          */
506         function parse_archivetype() {
507                 global $archivetype;
508                 echo $archivetype;
509         }
510
511         /**
512          * Parse skinvar blog
513          */
514         function parse_blog($template, $amount = 10, $category = '') {
515                 global $blog, $startpos;
516
517                 list($limit, $offset) = sscanf($amount, '%d(%d)');
518                 $this->_setBlogCategory($blog, $category);
519                 $this->_preBlogContent('blog',$blog);
520                 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
521                 $this->_postBlogContent('blog',$blog);
522         }
523         
524         /*
525         *       Parse skinvar bloglist
526         *       Shows a list of all blogs
527         *       bnametype: whether 'name' or 'shortname' is used for the link text        
528         *       orderby: order criteria\r
529         *       direction: order ascending or descending                  \r
530         */
531         function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc') {\r
532                 BLOG::showBlogList($template, $bnametype, $orderby, $direction);\r
533         }
534         
535         /**
536          * Parse skinvar blogsetting
537          */
538         function parse_blogsetting($which) {
539                 global $blog;
540                 switch($which) {
541                         case 'id':
542                                 echo htmlspecialchars($blog->getID(),ENT_QUOTES);
543                                 break;
544                         case 'url':
545                                 echo htmlspecialchars($blog->getURL(),ENT_QUOTES);
546                                 break;
547                         case 'name':
548                                 echo htmlspecialchars($blog->getName(),ENT_QUOTES);
549                                 break;
550                         case 'desc':
551                                 echo htmlspecialchars($blog->getDescription(),ENT_QUOTES);
552                                 break;
553                         case 'short':
554                                 echo htmlspecialchars($blog->getShortName(),ENT_QUOTES);
555                                 break;
556                 }
557         }
558         
559         /**
560          * Parse callback
561          */
562         function parse_callback($eventName, $type)
563         {
564                 global $manager;
565                 $manager->notify($eventName, array('type' => $type));
566         }
567         
568         /**
569          * Parse skinvar category
570          */
571         function parse_category($type = 'name') {
572                 global $catid, $blog;
573                 if (!$blog->isValidCategory($catid))
574                         return;
575
576                 switch($type) {
577                         case 'name':
578                                 echo $blog->getCategoryName($catid);
579                                 break;
580                         case 'desc':
581                                 echo $blog->getCategoryDesc($catid);
582                                 break;
583                         case 'id':
584                                 echo $catid;
585                                 break;
586                 }
587         }
588         
589         /**
590          * Parse categorylist
591          */
592         function parse_categorylist($template, $blogname = '') {
593                 global $blog, $manager;
594
595                 if ($blogname == '') {
596                         $this->_preBlogContent('categorylist',$blog);
597                         $blog->showCategoryList($template);
598                         $this->_postBlogContent('categorylist',$blog);
599                 } else {
600                         $b =& $manager->getBlog(getBlogIDFromName($blogname));
601                         $this->_preBlogContent('categorylist',$b);
602                         $b->showCategoryList($template);
603                         $this->_postBlogContent('categorylist',$b);
604                 }
605         }
606         
607         /**
608          * Parse skinvar charset
609          */
610         function parse_charset() {
611                 echo _CHARSET;
612         }
613         
614         /**
615          * Parse skinvar commentform
616          */
617         function parse_commentform($destinationurl = '') {
618                 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
619
620                 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
621                 if (stristr($destinationurl, 'action.php')) {
622                         $args = func_get_args();
623                         $destinationurl = $args[1];
624                         ACTIONLOG::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);\r
625                 }
626
627                 $actionurl = $CONF['ActionURL'];
628
629                 // if item is closed, show message and do nothing
630                 $item =& $manager->getItem($itemid,0,0);
631                 if ($item['closed'] || !$blog->commentsEnabled()) {
632                         $this->doForm('commentform-closed');
633                         return;
634                 }
635
636                 if (!$destinationurl)
637                 {
638                         $destinationurl = createLink(
639                                 'item',
640                                 array(
641                                         'itemid' => $itemid,
642                                         'title' => $item['title'],
643                                         'timestamp' => $item['timestamp'],
644                                         'extra' => $this->linkparams
645                                 )
646                         );
647
648                         // note: createLink returns an HTML encoded URL
649                 } else {
650                         // HTML encode URL
651                         $destinationurl = htmlspecialchars($destinationurl,ENT_QUOTES);
652                 }
653
654                 // values to prefill
655                 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
656                 if (!$user) $user = postVar('user');
657                 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
658                 if (!$userid) $userid = postVar('userid');
659                 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
660                 if (!$email) {
661                         $email = postVar('email');
662                 }
663                 $body = postVar('body');
664
665                 $this->formdata = array(
666                         'destinationurl' => $destinationurl,    // url is already HTML encoded
667                         'actionurl' => htmlspecialchars($actionurl,ENT_QUOTES),
668                         'itemid' => $itemid,
669                         'user' => htmlspecialchars($user,ENT_QUOTES),
670                         'userid' => htmlspecialchars($userid,ENT_QUOTES),
671                         'email' => htmlspecialchars($email,ENT_QUOTES),
672                         'body' => htmlspecialchars($body,ENT_QUOTES),
673                         'membername' => $member->getDisplayName(),
674                         'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
675                 );
676
677                 if (!$member->isLoggedIn()) {
678                         $this->doForm('commentform-notloggedin');
679                 } else {
680                         $this->doForm('commentform-loggedin');
681                 }
682         }
683         
684         /**
685          * Parse skinvar comments
686          * include comments for one item         
687          */
688         function parse_comments($template) {
689                 global $itemid, $manager, $blog, $highlight;
690                 $template =& $manager->getTemplate($template);
691
692                 // create parser object & action handler
693                 $actions =& new ITEMACTIONS($blog);
694                 $parser =& new PARSER($actions->getDefinedActions(),$actions);
695                 $actions->setTemplate($template);
696                 $actions->setParser($parser);
697                 $item = ITEM::getitem($itemid, 0, 0);
698                 $actions->setCurrentItem($item);
699
700                 $comments =& new COMMENTS($itemid);
701                 $comments->setItemActions($actions);
702                 $comments->showComments($template, -1, 1, $highlight);  // shows ALL comments
703         }
704
705         /**
706          * Parse errordiv
707          */
708         function parse_errordiv() {
709                 global $errormessage;
710                 if ($errormessage)
711                         echo '<div class="error">', htmlspecialchars($errormessage),'</div>';
712         }
713         
714         /**
715          * Parse skinvar errormessage
716          */
717         function parse_errormessage() {
718                 global $errormessage;
719                 echo $errormessage;
720         }
721         
722         /**
723          * Parse formdata
724          */
725         function parse_formdata($what) {
726                 echo $this->formdata[$what];
727         }
728         
729         /**
730          * Parse ifcat
731          */
732         function parse_ifcat($text = '') {
733                 if ($text == '') {
734                         // new behaviour
735                         $this->parse_if('category');
736                 } else {
737                         // old behaviour
738                         global $catid, $blog;
739                         if ($blog->isValidCategory($catid))
740                                 echo $text;
741                 }
742         }
743
744         /**
745          * Parse skinvar image
746          */
747         function parse_image($what = 'imgtag') {
748                 global $CONF;
749
750                 $imagetext      = htmlspecialchars(requestVar('imagetext'));
751                 $imagepopup = requestVar('imagepopup');
752                 $width          = intRequestVar('width');
753                 $height         = intRequestVar('height');
754                 $fullurl        = htmlspecialchars($CONF['MediaURL'] . $imagepopup);
755
756                 switch($what)
757                 {
758                         case 'url':
759                                 echo $fullurl;
760                                 break;
761                         case 'width':
762                                 echo $width;
763                                 break;
764                         case 'height':
765                                 echo $height;
766                                 break;
767                         case 'caption':
768                         case 'text':
769                                 echo $imagetext;
770                                 break;
771                         case 'imgtag':
772                         default:
773                                 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
774                                 break;
775                 }
776         }
777         
778         /**
779          * Parse skinvar imagetext
780          */
781         function parse_imagetext() {
782                 echo htmlspecialchars(requestVar('imagetext'),ENT_QUOTES);
783         }
784
785         /**
786          * Parse skinvar item
787          * include one item (no comments)        
788          */
789         function parse_item($template) {
790                 global $blog, $itemid, $highlight;
791                 $this->_setBlogCategory($blog, '');     // need this to select default category
792                 $this->_preBlogContent('item',$blog);
793                 $r = $blog->showOneitem($itemid, $template, $highlight);
794                 if ($r == 0)
795                         echo _ERROR_NOSUCHITEM;
796                 $this->_postBlogContent('item',$blog);
797         }
798
799         /**
800          * Parse skinvar itemid
801          */
802         function parse_itemid() {
803                 global $itemid;
804                 echo $itemid;
805         }
806         
807         /**
808          * Parse skinvar itemlink
809          */
810         function parse_itemlink($linktext = '') {
811                 global $itemid;
812                 $this->_itemlink($itemid, $linktext);
813         }
814
815         /**
816          * Parse itemtitle
817          */
818         function parse_itemtitle($format = '') {
819                 global $manager, $itemid;
820                 $item =& $manager->getItem($itemid,0,0);
821
822                 switch ($format) {
823                         case 'xml':
824                                 echo stringToXML ($item['title']);
825                                 break;
826                         case 'attribute':
827                                 echo stringToAttribute ($item['title']);
828                                 break;
829                         case 'raw':
830                                 echo $item['title'];
831                                 break;
832                         default:
833                                 echo htmlspecialchars(strip_tags($item['title']),ENT_QUOTES);
834                                 break;
835                 }
836         }
837
838         /**
839          * Parse skinvar loginform
840          */
841         function parse_loginform() {
842                 global $member, $CONF;
843                 if (!$member->isLoggedIn()) {
844                         $filename = 'loginform-notloggedin';
845                         $this->formdata = array();
846                 } else {
847                         $filename = 'loginform-loggedin';
848                         $this->formdata = array(
849                                 'membername' => $member->getDisplayName(),
850                         );
851                 }
852                 $this->doForm($filename);
853         }
854
855         /**
856          * Parse skinvar member
857          * (includes a member info thingie)      
858          */
859         function parse_member($what) {
860                 global $memberinfo, $member;
861
862                 // 1. only allow the member-details-page specific variables on member pages
863                 if ($this->skintype == 'member') {
864
865                         switch($what) {
866                                 case 'name':
867                                         echo htmlspecialchars($memberinfo->getDisplayName(),ENT_QUOTES);
868                                         break;
869                                 case 'realname':
870                                         echo htmlspecialchars($memberinfo->getRealName(),ENT_QUOTES);
871                                         break;
872                                 case 'notes':
873                                         echo htmlspecialchars($memberinfo->getNotes(),ENT_QUOTES);
874                                         break;
875                                 case 'url':
876                                         echo htmlspecialchars($memberinfo->getURL(),ENT_QUOTES);
877                                         break;
878                                 case 'email':
879                                         echo htmlspecialchars($memberinfo->getEmail(),ENT_QUOTES);
880                                         break;
881                                 case 'id':
882                                         echo htmlspecialchars($memberinfo->getID(),ENT_QUOTES);
883                                         break;
884                         }
885                 }
886
887                 // 2. the next bunch of options is available everywhere, as long as the user is logged in
888                 if ($member->isLoggedIn())
889                 {
890                         switch($what) {
891                                 case 'yourname':
892                                         echo $member->getDisplayName();
893                                         break;
894                                 case 'yourrealname':
895                                         echo $member->getRealName();
896                                         break;
897                                 case 'yournotes':
898                                         echo $member->getNotes();
899                                         break;
900                                 case 'yoururl':
901                                         echo $member->getURL();
902                                         break;
903                                 case 'youremail':
904                                         echo $member->getEmail();
905                                         break;
906                                 case 'yourid':
907                                         echo $member->getID();
908                                         break;
909                         }
910                 }
911
912         }
913
914         /**
915          * Parse skinvar membermailform
916          */
917         function parse_membermailform($rows = 10, $cols = 40, $desturl = '') {
918                 global $member, $CONF, $memberid;
919
920                 if ($desturl == '') {
921                         if ($CONF['URLMode'] == 'pathinfo')
922                                 $desturl = createMemberLink($memberid);
923                         else
924                                 $desturl = $CONF['IndexURL'] . createMemberLink($memberid);
925                 }
926
927                 $message = postVar('message');
928                 $frommail = postVar('frommail');
929
930                 $this->formdata = array(
931                         'url' => htmlspecialchars($desturl),
932                         'actionurl' => htmlspecialchars($CONF['ActionURL'],ENT_QUOTES),
933                         'memberid' => $memberid,
934                         'rows' => $rows,
935                         'cols' => $cols,
936                         'message' => htmlspecialchars($message,ENT_QUOTES),
937                         'frommail' => htmlspecialchars($frommail,ENT_QUOTES)
938                 );
939                 if ($member->isLoggedIn()) {
940                         $this->doForm('membermailform-loggedin');
941                 } else if ($CONF['NonmemberMail']) {
942                         $this->doForm('membermailform-notloggedin');
943                 } else {
944                         $this->doForm('membermailform-disallowed');
945                 }
946
947         }
948         
949         /**
950          * Parse skinvar nextarchive
951          */
952         function parse_nextarchive() {
953                 global $archivenext;
954                 echo $archivenext;
955         }
956
957         /**
958          * Parse skinvar nextitem
959          * (include itemid of next item)
960          */
961         function parse_nextitem() {
962                 global $itemidnext;
963                 if (isset($itemidnext)) echo (int)$itemidnext;
964         }
965
966         /**
967          * Parse skinvar nextitemtitle
968          * (include itemtitle of next item)
969          */
970         function parse_nextitemtitle($format = '') {
971                 global $itemtitlenext;
972
973                 switch ($format) {
974                         case 'xml':
975                                 echo stringToXML ($itemtitlenext);
976                                 break;
977                         case 'attribute':
978                                 echo stringToAttribute ($itemtitlenext);
979                                 break;
980                         case 'raw':
981                                 echo $itemtitlenext;
982                                 break;
983                         default:
984                                 echo htmlspecialchars($itemtitlenext,ENT_QUOTES);
985                                 break;
986                 }
987         }
988
989         /**
990          * Parse skinvar nextlink
991          */
992         function parse_nextlink($linktext = '', $amount = 10) {
993                 global $itemidnext, $archivenext, $startpos;
994                 if ($this->skintype == 'item')
995                         $this->_itemlink($itemidnext, $linktext);
996                 else if ($this->skintype == 'search' || $this->skintype == 'index')
997                         $this->_searchlink($amount, $startpos, 'next', $linktext);
998                 else
999                         $this->_archivelink($archivenext, $linktext);
1000         }
1001
1002         /**
1003          * Parse skinvar nucleusbutton
1004          */
1005         function parse_nucleusbutton($imgurl = '',
1006                                                                  $imgwidth = '85',
1007                                                                  $imgheight = '31') {
1008                 global $CONF;
1009                 if ($imgurl == '') {
1010                         $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
1011                 } else if (PARSER::getProperty('IncludeMode') == 'skindir'){
1012                         // when skindit IncludeMode is used: start from skindir
1013                         $imgurl = $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $imgurl;
1014                 }
1015
1016                 $this->formdata = array(
1017                         'imgurl' => $imgurl,
1018                         'imgwidth' => $imgwidth,
1019                         'imgheight' => $imgheight,
1020                 );
1021                 $this->doForm('nucleusbutton');
1022         }
1023         
1024         /**
1025          * Parse skinvar otherarchive
1026          */     
1027         function parse_otherarchive($blogname, $template, $category = '') {
1028                 global $archive, $manager;
1029                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
1030                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1031                 $this->_setBlogCategory($b, $category);
1032                 $this->_preBlogContent('otherachive',$b);
1033                 $b->showArchive($template, $y, $m, $d);
1034                 $this->_postBlogContent('otherachive',$b);
1035         }
1036         
1037         /**
1038          * Parse skinvar otherarchivedaylist
1039          */
1040         function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0) {
1041                 global $manager;
1042                 if ($category == 'all') $category = '';
1043                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1044                 $this->_setBlogCategory($b, $category);
1045                 $this->_preBlogContent('otherarchivelist',$b);
1046                 $b->showArchiveList($template, 'day', $limit);
1047                 $this->_postBlogContent('otherarchivelist',$b);
1048         }
1049         
1050         /**
1051          * Parse skinvar otherarchivelist
1052          */
1053         function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0) {
1054                 global $manager;
1055                 if ($category == 'all') $category = '';
1056                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1057                 $this->_setBlogCategory($b, $category);
1058                 $this->_preBlogContent('otherarchivelist',$b);
1059                 $b->showArchiveList($template, 'month', $limit);
1060                 $this->_postBlogContent('otherarchivelist',$b);
1061         }
1062         
1063         /**
1064          * Parse skinvar otherblog
1065          */
1066         function parse_otherblog($blogname, $template, $amount = 10, $category = '') {
1067                 global $manager;
1068
1069                 list($limit, $offset) = sscanf($amount, '%d(%d)');
1070
1071                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1072                 $this->_setBlogCategory($b, $category);
1073                 $this->_preBlogContent('otherblog',$b);
1074                 $this->amountfound = $b->readLog($template, $limit, $offset);
1075                 $this->_postBlogContent('otherblog',$b);
1076         }
1077
1078         /**
1079          * Parse skinvar othersearchresults
1080          */
1081         function parse_othersearchresults($blogname, $template, $maxresults = 50) {
1082                 global $query, $amount, $manager, $startpos;
1083                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1084                 $this->_setBlogCategory($b, '');        // need this to select default category
1085                 $this->_preBlogContent('othersearchresults',$b);
1086                 $b->search($query, $template, $amount, $maxresults, $startpos);
1087                 $this->_postBlogContent('othersearchresults',$b);
1088         }
1089
1090         /**
1091           * Executes a plugin skinvar
1092           *
1093           * @param pluginName name of plugin (without the NP_)
1094           *
1095           * extra parameters can be added
1096           */
1097         function parse_plugin($pluginName) {
1098                 global $manager;
1099
1100                 // should be already tested from the parser (PARSER.php)\r
1101                 // only continue when the plugin is really installed\r
1102                 /*if (!$manager->pluginInstalled('NP_' . $pluginName))\r
1103                         return;*/
1104
1105                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
1106                 if (!$plugin) return;
1107
1108                 // get arguments
1109                 $params = func_get_args();
1110
1111                 // remove plugin name
1112                 array_shift($params);
1113
1114                 // add skin type on front
1115                 array_unshift($params, $this->skintype);
1116
1117                 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
1118         }
1119         
1120         /**
1121          * Parse skinvar prevarchive
1122          */
1123         function parse_prevarchive() {
1124                 global $archiveprev;
1125                 echo $archiveprev;
1126         }
1127
1128         /**
1129          * Parse skinvar preview
1130          */
1131         function parse_preview($template) {
1132                 global $blog, $CONF, $manager;
1133
1134                 $template =& $manager->getTemplate($template);
1135                 $row['body'] = '<span id="prevbody"></span>';
1136                 $row['title'] = '<span id="prevtitle"></span>';
1137                 $row['more'] = '<span id="prevmore"></span>';
1138                 $row['itemlink'] = '';
1139                 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
1140                 echo TEMPLATE::fill($template['ITEM_HEADER'],$row);
1141                 echo TEMPLATE::fill($template['ITEM'],$row);
1142                 echo TEMPLATE::fill($template['ITEM_FOOTER'],$row);
1143         }
1144
1145         /*
1146          * Parse skinvar previtem
1147          * (include itemid of prev item)                 
1148          */
1149         function parse_previtem() {
1150                 global $itemidprev;
1151                 if (isset($itemidprev)) echo (int)$itemidprev;
1152         }
1153
1154         /**
1155          * Parse skinvar previtemtitle
1156          * (include itemtitle of prev item)
1157          */
1158         function parse_previtemtitle($format = '') {
1159                 global $itemtitleprev;
1160
1161                 switch ($format) {
1162                         case 'xml':
1163                                 echo stringToXML ($itemtitleprev);
1164                                 break;
1165                         case 'attribute':
1166                                 echo stringToAttribute ($itemtitleprev);
1167                                 break;
1168                         case 'raw':
1169                                 echo $itemtitleprev;
1170                                 break;
1171                         default:
1172                                 echo htmlspecialchars($itemtitleprev,ENT_QUOTES);
1173                                 break;
1174                 }
1175         }
1176
1177         /**
1178          * Parse skinvar prevlink
1179          */
1180         function parse_prevlink($linktext = '', $amount = 10) {
1181                 global $itemidprev, $archiveprev, $startpos;
1182
1183                 if ($this->skintype == 'item')
1184                         $this->_itemlink($itemidprev, $linktext);
1185                 else if ($this->skintype == 'search' || $this->skintype == 'index')
1186                         $this->_searchlink($amount, $startpos, 'prev', $linktext);
1187                 else
1188                         $this->_archivelink($archiveprev, $linktext);
1189         }
1190
1191         /**
1192          * Parse skinvar query
1193          * (includes the search query)   
1194          */
1195         function parse_query() {
1196                 global $query;
1197                 echo htmlspecialchars($query,ENT_QUOTES);
1198         }
1199         
1200         /**
1201          * Parse skinvar referer
1202          */
1203         function parse_referer() {
1204                 echo htmlspecialchars(serverVar('HTTP_REFERER'),ENT_QUOTES);
1205         }
1206
1207         /**
1208          * Parse skinvar searchform
1209          */
1210         function parse_searchform($blogname = '') {
1211                 global $CONF, $manager, $maxresults;
1212                 if ($blogname) {
1213                         $blog =& $manager->getBlog(getBlogIDFromName($blogname));
1214                 } else {
1215                         global $blog;
1216                 }
1217                 // use default blog when no blog is selected
1218                 $this->formdata = array(
1219                         'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
1220                         'query' => htmlspecialchars(getVar('query'),ENT_QUOTES),
1221                 );
1222                 $this->doForm('searchform');
1223         }
1224
1225         /**
1226          * Parse skinvar searchresults
1227          */
1228         function parse_searchresults($template, $maxresults = 50 ) {
1229                 global $blog, $query, $amount, $startpos;
1230
1231                 $this->_setBlogCategory($blog, '');     // need this to select default category
1232                 $this->_preBlogContent('searchresults',$blog);
1233                 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
1234                 $this->_postBlogContent('searchresults',$blog);
1235         }
1236
1237         /**
1238          * Parse skinvar self
1239          */
1240         function parse_self() {
1241                 global $CONF;
1242                 echo $CONF['Self'];
1243         }
1244
1245         /**
1246          * Parse skinvar sitevar
1247          * (include a sitevar)   
1248          */
1249         function parse_sitevar($which) {
1250                 global $CONF;
1251                 switch($which) {
1252                         case 'url':
1253                                 echo $CONF['IndexURL'];
1254                                 break;
1255                         case 'name':
1256                                 echo $CONF['SiteName'];
1257                                 break;
1258                         case 'admin':
1259                                 echo $CONF['AdminEmail'];
1260                                 break;
1261                         case 'adminurl':
1262                                 echo $CONF['AdminURL'];
1263                 }
1264         }
1265
1266         /**
1267          * Parse skinname
1268          */
1269         function parse_skinname() {
1270                 echo $this->skin->getName();
1271         }
1272         
1273         /**
1274          * Parse skintype (experimental)
1275          */
1276         function parse_skintype() {
1277                 echo $this->skintype;
1278         }
1279
1280         /**
1281          * Parse text
1282          */
1283         function parse_text($which) {
1284                 // constant($which) only available from 4.0.4 :(
1285                 if (defined($which)) {
1286                         eval("echo $which;");
1287                 }
1288         }
1289         
1290         /**
1291          * Parse ticket
1292          */
1293         function parse_ticket() {
1294                 global $manager;
1295                 $manager->addTicketHidden();
1296         }
1297
1298         /**
1299          *      Parse skinvar todaylink
1300          *      A link to the today page (depending on selected blog, etc...)
1301          */
1302         function parse_todaylink($linktext = '') {
1303                 global $blog, $CONF;
1304                 if ($blog)
1305                         echo $this->_link(createBlogidLink($blog->getID(),$this->linkparams), $linktext);
1306                 else
1307                         echo $this->_link($CONF['SiteUrl'], $linktext);
1308         }
1309
1310         /**
1311          * Parse vars
1312          * When commentform is not used, to include a hidden field with itemid   
1313          */
1314         function parse_vars() {
1315                 global $itemid;
1316                 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />';
1317         }
1318
1319         /**
1320          * Parse skinvar version
1321          * (include nucleus versionnumber)       
1322          */
1323         function parse_version() {
1324                 global $nucleus;
1325                 echo 'Nucleus CMS ' . $nucleus['version'];
1326         }
1327
1328 }
1329 ?>