OSDN Git Service

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