OSDN Git Service

MERGE: リビジョン1672から1680にかけて行われた修正のうち、反映されてないものを追加。
[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          * ACTIONS::_itemlink()
361          * Creates an item link and if no id is given a todaylink 
362          * 
363          * @param       Integer $id     id for link
364          * @param       String  $linktext       text for link
365          * @return      Void
366          */
367         function _itemlink($id, $linktext = '')
368         {
369                 global $CONF;
370                 if ( $id )
371                 {
372                         echo $this->_link(LINK::create_item_link($id, $this->linkparams), $linktext);
373                 }
374                 else
375                 {
376                         $this->parse_todaylink($linktext);
377                 }
378                 return;
379         }
380         
381         /**
382          * ACTIONS::_archivelink)
383          * Creates an archive link and if no id is given a todaylink 
384          * 
385          * @param       Integer $id     id for link
386          * @param       String  $linktext       text for link
387          * @return      Void
388          */
389         function _archivelink($id, $linktext = '')
390         {
391                 global $CONF, $blog;
392                 if ( $id )
393                 {
394                         echo $this->_link(LINK::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
395                 }
396                 else
397                 {
398                         $this->parse_todaylink($linktext);
399                 }
400                 return;
401         }
402         
403         /**
404           * Helper function that sets the category that a blog will need to use
405           *
406           * @param $blog
407           *             An object of the blog class, passed by reference (we want to make changes to it)
408           * @param $catname
409           *             The name of the category to use
410           */
411         function _setBlogCategory(&$blog, $catname) {
412                 global $catid;
413                 if ($catname != '')
414                         $blog->setSelectedCategoryByName($catname);
415                 else
416                         $blog->setSelectedCategory($catid);
417         }
418
419         /**
420          *  Notifies the Manager that a PreBlogContent event occurs
421          */
422         function _preBlogContent($type, &$blog) {
423                 global $manager;
424                 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
425         }
426
427         /**
428          *  Notifies the Manager that a PostBlogContent event occurs
429          */
430         function _postBlogContent($type, &$blog) {
431                 global $manager;
432                 $manager->notify('PostBlogContent',array('blog' => &$blog, 'type' => $type));
433         }
434         
435         /**
436          * Parse skinvar additemform
437          */
438         function parse_additemform() {
439                 global $blog, $CONF;
440                 $this->formdata = array(
441                         'adminurl' => ENTITY::hsc($CONF['AdminURL']),
442                         'catid' => $blog->getDefaultCategory()
443                 );
444                 $blog->InsertJavaScriptInfo();
445                 $this->doForm('additemform');
446         }
447         
448         /**
449          * Parse skinvar addlink
450          * A Link that allows to open a bookmarklet to add an item
451          */
452         function parse_addlink() {
453                 global $CONF, $member, $blog;
454                 if ($member->isLoggedIn() && $member->isTeamMember($blog->blogid) ) {
455                         echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
456                 }
457         }
458         
459         /**
460          * Parse skinvar addpopupcode
461          * Code that opens a bookmarklet in an popup window
462          */
463         function parse_addpopupcode() {
464                 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;";
465         }
466         
467         /**
468          * Parse skinvar adminurl
469          * (shortcut for admin url)      
470          */
471         function parse_adminurl() {
472                 $this->parse_sitevar('adminurl');
473         }
474
475         /**
476          * Parse skinvar archive
477          */
478         function parse_archive($template, $category = '') {
479                 global $blog, $archive;
480                 // can be used with either yyyy-mm or yyyy-mm-dd
481                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
482                 $this->_setBlogCategory($blog, $category);
483                 $this->_preBlogContent('achive',$blog);
484                 $blog->showArchive($template, $y, $m, $d);
485                 $this->_postBlogContent('achive',$blog);
486
487         }
488
489         /**
490           * %archivedate(locale,date format)%
491           */
492         function parse_archivedate($locale = '-def-') {
493                 global $archive;
494
495                 if ($locale == '-def-')
496                         setlocale(LC_TIME,$template['LOCALE']);
497                 else
498                         setlocale(LC_TIME,$locale);
499
500                 // get archive date
501                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
502
503                 // get format
504                 $args = func_get_args();
505                 // format can be spread over multiple parameters
506                 if (sizeof($args) > 1) {
507                         // take away locale
508                         array_shift($args);
509                         // implode
510                         $format=implode(',',$args);
511                 } elseif ($d == 0 && $m !=0) {
512                         $format = '%B %Y';
513                 } elseif ($m == 0) {
514                         $format = '%Y';                 
515                 } else {
516                         $format = '%d %B %Y';
517                 }
518
519                 echo i18n::strftime($format,mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
520         }
521
522         /**
523          *  Parse skinvar archivedaylist
524          */             
525         function parse_archivedaylist($template, $category = 'all', $limit = 0) {
526                 global $blog;
527                 if ($category == 'all') $category = '';
528                 $this->_preBlogContent('archivelist',$blog);
529                 $this->_setBlogCategory($blog, $category);
530                 $blog->showArchiveList($template, 'day', $limit);
531                 $this->_postBlogContent('archivelist',$blog);
532         }
533         
534         /**
535          * ACTIONS::parse_archivelink()
536          *      A link to the archives for the current blog (or for default blog)
537          *
538          * @param       String  $linktext       text for link
539          * @return      Void
540          */
541         function parse_archivelink($linktext = '')
542         {
543                 global $blog, $CONF;
544                 if ( $blog )
545                 {
546                         echo $this->_link(LINK::create_archivelist_link($blog->getID(),$this->linkparams), $linktext);
547                 }
548                 else
549                 {
550                         echo $this->_link(LINK::create_archivelist_link(), $linktext);
551                 }
552                 return;
553         }
554         
555         function parse_archivelist($template, $category = 'all', $limit = 0) {
556                 global $blog;
557                 if ($category == 'all') $category = '';
558                 $this->_preBlogContent('archivelist',$blog);
559                 $this->_setBlogCategory($blog, $category);
560                 $blog->showArchiveList($template, 'month', $limit);
561                 $this->_postBlogContent('archivelist',$blog);
562         }
563                 
564         function parse_archiveyearlist($template, $category = 'all', $limit = 0) {
565                 global $blog;
566                 if ($category == 'all') $category = '';
567                 $this->_preBlogContent('archivelist',$blog);
568                 $this->_setBlogCategory($blog, $category);
569                 $blog->showArchiveList($template, 'year', $limit);
570                 $this->_postBlogContent('archivelist',$blog);
571         }
572         
573         /**
574          * Parse skinvar archivetype
575          */
576         function parse_archivetype() {
577                 global $archivetype;
578                 echo $archivetype;
579         }
580
581         /**
582          * Parse skinvar blog
583          */
584         function parse_blog($template, $amount = 10, $category = '') {
585                 global $blog, $startpos;
586
587                 list($limit, $offset) = sscanf($amount, '%d(%d)');
588                 $this->_setBlogCategory($blog, $category);
589                 $this->_preBlogContent('blog',$blog);
590                 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
591                 $this->_postBlogContent('blog',$blog);
592         }
593         
594         /*
595         *       Parse skinvar bloglist
596         *       Shows a list of all blogs
597         *       bnametype: whether 'name' or 'shortname' is used for the link text        
598         *       orderby: order criteria
599         *       direction: order ascending or descending                  
600         */
601         function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc') {
602                 BLOG::showBlogList($template, $bnametype, $orderby, $direction);
603         }
604         
605         /**
606          * Parse skinvar blogsetting
607          */
608         function parse_blogsetting($which) {
609                 global $blog;
610                 switch($which) {
611                         case 'id':
612                                 echo ENTITY::hsc($blog->getID());
613                                 break;
614                         case 'url':
615                                 echo ENTITY::hsc($blog->getURL());
616                                 break;
617                         case 'name':
618                                 echo ENTITY::hsc($blog->getName());
619                                 break;
620                         case 'desc':
621                                 echo ENTITY::hsc($blog->getDescription());
622                                 break;
623                         case 'short':
624                                 echo ENTITY::hsc($blog->getShortName());
625                                 break;
626                 }
627         }
628         
629         /**
630          * Parse callback
631          */
632         function parse_callback($eventName, $type)
633         {
634                 global $manager;
635                 $manager->notify($eventName, array('type' => $type));
636         }
637         
638         /**
639          * Parse skinvar category
640          */
641         function parse_category($type = 'name') {
642                 global $catid, $blog;
643                 if (!$blog->isValidCategory($catid))
644                         return;
645
646                 switch($type) {
647                         case 'name':
648                                 echo $blog->getCategoryName($catid);
649                                 break;
650                         case 'desc':
651                                 echo $blog->getCategoryDesc($catid);
652                                 break;
653                         case 'id':
654                                 echo $catid;
655                                 break;
656                 }
657         }
658         
659         /**
660          * Parse categorylist
661          */
662         function parse_categorylist($template, $blogname = '') {
663                 global $blog, $manager;
664
665                 // when no blog found
666                 if (($blogname == '') && (!is_object($blog)))
667                         return 0;
668                         
669                 if ($blogname == '') {
670                         $this->_preBlogContent('categorylist',$blog);
671                         $blog->showCategoryList($template);
672                         $this->_postBlogContent('categorylist',$blog);
673                 } else {
674                         $b =& $manager->getBlog(getBlogIDFromName($blogname));
675                         $this->_preBlogContent('categorylist',$b);
676                         $b->showCategoryList($template);
677                         $this->_postBlogContent('categorylist',$b);
678                 }
679         }
680         
681         /**
682          * Parse skinvar charset
683          */
684         function parse_charset() {
685                 echo i18n::get_current_charset();
686         }
687         
688         /**
689          * ACTIONS::parse_commentform()
690          * Parse skinvar commentform
691          * 
692          * @param       String  $destinationurl URI for redirection
693          * @return      Void
694          */
695         function parse_commentform($destinationurl = '')
696         {
697                 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
698                 
699                 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
700                 if ( stristr($destinationurl, 'action.php') )
701                 {
702                         $args = func_get_args();
703                         $destinationurl = $args[1];
704                         ACTIONLOG::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
705                 }
706                 
707                 $actionurl = $CONF['ActionURL'];
708                 
709                 // if item is closed, show message and do nothing
710                 $item =& $manager->getItem($itemid,0,0);
711                 if ( $item['closed'] || !$blog->commentsEnabled() )
712                 {
713                         $this->doForm('commentform-closed');
714                         return;
715                 }
716                 
717                 if ( !$blog->isPublic() && !$member->isLoggedIn() )
718                 {
719                         $this->doForm('commentform-closedtopublic');
720                         return;
721                 }
722                 
723                 if ( !$destinationurl )
724                 {
725                         // note: createLink returns an HTML encoded URL
726                         $destinationurl = LINK::create_link(
727                                 'item',
728                                 array(
729                                         'itemid' => $itemid,
730                                         'title' => $item['title'],
731                                         'timestamp' => $item['timestamp'],
732                                         'extra' => $this->linkparams
733                                 )
734                         );
735                 }
736                 else
737                 {
738                         // HTML encode URL
739                         $destinationurl = ENTITY::hsc($destinationurl);
740                 }
741                 
742                 // values to prefill
743                 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
744                 if ( !$user )
745                 {
746                         $user = postVar('user');
747                 }
748                 
749                 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
750                 if ( !$userid )
751                 {
752                         $userid = postVar('userid');
753                 }
754                 
755                 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
756                 if (!$email)
757                 {
758                         $email = postVar('email');
759                 }
760                 
761                 $body = postVar('body');
762                 
763                 $this->formdata = array(
764                         'destinationurl' => $destinationurl,    // url is already HTML encoded
765                         'actionurl' => ENTITY::hsc($actionurl),
766                         'itemid' => $itemid,
767                         'user' => ENTITY::hsc($user),
768                         'userid' => ENTITY::hsc($userid),
769                         'email' => ENTITY::hsc($email),
770                         'body' => ENTITY::hsc($body),
771                         'membername' => $member->getDisplayName(),
772                         'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
773                 );
774                 
775                 if ( !$member->isLoggedIn() )
776                 {
777                         $this->doForm('commentform-notloggedin');
778                 }
779                 else
780                 {
781                         $this->doForm('commentform-loggedin');
782                 }
783                 return;
784         }
785         
786         /**
787          * Parse skinvar comments
788          * include comments for one item         
789          */
790         function parse_comments($template) {
791                 global $itemid, $manager, $blog, $highlight;
792                 $template =& $manager->getTemplate($template);
793
794                 // create parser object & action handler
795                 $actions = new ITEMACTIONS($blog);
796                 $parser = new PARSER($actions->getDefinedActions(),$actions);
797                 $actions->setTemplate($template);
798                 $actions->setParser($parser);
799                 $item = ITEM::getitem($itemid, 0, 0);
800                 $actions->setCurrentItem($item);
801
802                 $comments = new COMMENTS($itemid);
803                 $comments->setItemActions($actions);
804                 $comments->showComments($template, -1, 1, $highlight);  // shows ALL comments
805         }
806
807         /**
808          * Parse errordiv
809          */
810         function parse_errordiv() {
811                 global $errormessage;
812                 if ($errormessage)
813                         echo '<div class="error">', ENTITY::hsc($errormessage),'</div>';
814         }
815         
816         /**
817          * Parse skinvar errormessage
818          */
819         function parse_errormessage() {
820                 global $errormessage;
821                 echo $errormessage;
822         }
823         
824         /**
825          * Parse formdata
826          */
827         function parse_formdata($what) {
828                 echo $this->formdata[$what];
829         }
830         
831         /**
832          * Parse ifcat
833          */
834         function parse_ifcat($text = '') {
835                 if ($text == '') {
836                         // new behaviour
837                         $this->parse_if('category');
838                 } else {
839                         // old behaviour
840                         global $catid, $blog;
841                         if ($blog->isValidCategory($catid))
842                                 echo $text;
843                 }
844         }
845
846         /**
847          * Parse skinvar image
848          */
849         function parse_image($what = 'imgtag') {
850                 global $CONF;
851
852                 $imagetext      = ENTITY::hsc(requestVar('imagetext'));
853                 $imagepopup = requestVar('imagepopup');
854                 $width          = intRequestVar('width');
855                 $height         = intRequestVar('height');
856                 $fullurl        = ENTITY::hsc($CONF['MediaURL'] . $imagepopup);
857
858                 switch($what)
859                 {
860                         case 'url':
861                                 echo $fullurl;
862                                 break;
863                         case 'width':
864                                 echo $width;
865                                 break;
866                         case 'height':
867                                 echo $height;
868                                 break;
869                         case 'caption':
870                         case 'text':
871                                 echo $imagetext;
872                                 break;
873                         case 'imgtag':
874                         default:
875                                 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
876                                 break;
877                 }
878         }
879         
880         /**
881          * Parse skinvar imagetext
882          */
883         function parse_imagetext() {
884                 echo ENTITY::hsc(requestVar('imagetext'));
885         }
886
887         /**
888          * Parse skinvar item
889          * include one item (no comments)        
890          */
891         function parse_item($template) {
892                 global $blog, $itemid, $highlight;
893                 $this->_setBlogCategory($blog, '');     // need this to select default category
894                 $this->_preBlogContent('item',$blog);
895                 $r = $blog->showOneitem($itemid, $template, $highlight);
896                 if ($r == 0)
897                         echo _ERROR_NOSUCHITEM;
898                 $this->_postBlogContent('item',$blog);
899         }
900
901         /**
902          * Parse skinvar itemid
903          */
904         function parse_itemid() {
905                 global $itemid;
906                 echo $itemid;
907         }
908         
909         /**
910          * Parse skinvar itemlink
911          */
912         function parse_itemlink($linktext = '') {
913                 global $itemid;
914                 $this->_itemlink($itemid, $linktext);
915         }
916
917         /**
918          * Parse itemtitle
919          */
920         function parse_itemtitle($format = '') {
921                 global $manager, $itemid;
922                 $item =& $manager->getItem($itemid,0,0);
923
924                 switch ($format) {
925                         case 'xml':
926                                 echo ENTITY::hen($item['title']);
927                                 break;
928                         case 'raw':
929                                 echo $item['title'];
930                                 break;
931                         case 'attribute':
932                         default:
933                                 echo ENTITY::hsc(strip_tags($item['title']));
934                                 break;
935                 }
936         }
937
938         /**
939          * Parse skinvar loginform
940          */
941         function parse_loginform() {
942                 global $member, $CONF;
943                 if (!$member->isLoggedIn()) {
944                         $filename = 'loginform-notloggedin';
945                         $this->formdata = array();
946                 } else {
947                         $filename = 'loginform-loggedin';
948                         $this->formdata = array(
949                                 'membername' => $member->getDisplayName(),
950                         );
951                 }
952                 $this->doForm($filename);
953         }
954
955         /**
956          * ACTIONS::parse_member()
957          * Parse skinvar member
958          * (includes a member info thingie)
959          * 
960          * @param       String  $what   which memberdata is needed
961          * @return      Void
962          */
963         function parse_member($what)
964         {
965                 global $memberinfo, $member, $CONF;
966                 
967                 // 1. only allow the member-details-page specific variables on member pages
968                 if ($this->skintype == 'member')
969                 {
970                         switch( $what )
971                         {
972                                 case 'name':
973                                         echo ENTITY::hsc($memberinfo->getDisplayName());
974                                         break;
975                                 case 'realname':
976                                         echo ENTITY::hsc($memberinfo->getRealName());
977                                         break;
978                                 case 'notes':
979                                         echo ENTITY::hsc($memberinfo->getNotes());
980                                         break;
981                                 case 'url':
982                                         echo ENTITY::hsc($memberinfo->getURL());
983                                         break;
984                                 case 'email':
985                                         echo ENTITY::hsc($memberinfo->getEmail());
986                                         break;
987                                 case 'id':
988                                         echo ENTITY::hsc($memberinfo->getID());
989                                         break;
990                         }
991                 }
992                 
993                 // 2. the next bunch of options is available everywhere, as long as the user is logged in
994                 if ( $member->isLoggedIn() )
995                 {
996                         switch( $what )
997                         {
998                                 case 'yourname':
999                                         echo $member->getDisplayName();
1000                                         break;
1001                                 case 'yourrealname':
1002                                         echo $member->getRealName();
1003                                         break;
1004                                 case 'yournotes':
1005                                         echo $member->getNotes();
1006                                         break;
1007                                 case 'yoururl':
1008                                         echo $member->getURL();
1009                                         break;
1010                                 case 'youremail':
1011                                         echo $member->getEmail();
1012                                         break;
1013                                 case 'yourid':
1014                                         echo $member->getID();
1015                                         break;
1016                                 case 'yourprofileurl':
1017                                         if ($CONF['URLMode'] == 'pathinfo')
1018                                                 echo LINK::create_member_link($member->getID());
1019                                         else
1020                                                 echo $CONF['IndexURL'] . LINK::create_member_link($member->getID());
1021                                         break;
1022                         }
1023                 }
1024                 return;
1025         }
1026
1027         /**
1028          * LINK::parse_membermailform()
1029          * Parse skinvar membermailform
1030          * 
1031          * @param       Integer $rows   the height for textarea
1032          * @param       Integer $cols   the width for textarea
1033          * @param       String  $desturl        URI to redirect
1034          * @return      Void
1035          */
1036         function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
1037         {
1038                 global $member, $CONF, $memberid;
1039                 
1040                 if ( $desturl == '' )
1041                 {
1042                         if ( $CONF['URLMode'] == 'pathinfo' )
1043                         {
1044                                 $desturl = LINK::create_member_link($memberid);
1045                         }
1046                         else
1047                         {
1048                                 $desturl = $CONF['IndexURL'] . LINK::create_member_link($memberid);
1049                         }
1050                 }
1051                 
1052                 $message = postVar('message');
1053                 $frommail = postVar('frommail');
1054                 
1055                 $this->formdata = array(
1056                         'url' => ENTITY::hsc($desturl),
1057                         'actionurl' => ENTITY::hsc($CONF['ActionURL']),
1058                         'memberid' => $memberid,
1059                         'rows' => $rows,
1060                         'cols' => $cols,
1061                         'message' => ENTITY::hsc($message),
1062                         'frommail' => ENTITY::hsc($frommail)
1063                 );
1064                 
1065                 if ( $member->isLoggedIn() )
1066                 {
1067                         $this->doForm('membermailform-loggedin');
1068                 }
1069                 else if ( $CONF['NonmemberMail'] )
1070                 {
1071                         $this->doForm('membermailform-notloggedin');
1072                 }
1073                 else
1074                 {
1075                         $this->doForm('membermailform-disallowed');
1076                 }
1077                 return;
1078         }
1079         
1080         /**
1081          * Parse skinvar nextarchive
1082          */
1083         function parse_nextarchive() {
1084                 global $archivenext;
1085                 echo $archivenext;
1086         }
1087
1088         /**
1089          * Parse skinvar nextitem
1090          * (include itemid of next item)
1091          */
1092         function parse_nextitem() {
1093                 global $itemidnext;
1094                 if (isset($itemidnext)) echo (int)$itemidnext;
1095         }
1096
1097         /**
1098          * Parse skinvar nextitemtitle
1099          * (include itemtitle of next item)
1100          */
1101         function parse_nextitemtitle($format = '') {
1102                 global $itemtitlenext;
1103
1104                 switch ( $format )
1105                 {
1106                         case 'xml':
1107                                 echo ENTITY::hen($itemtitlenext);
1108                                 break;
1109                         case 'raw':
1110                                 echo $itemtitlenext;
1111                                 break;
1112                         case 'attribute':
1113                         default:
1114                                 echo ENTITY::hsc($itemtitlenext);
1115                                 break;
1116                 }
1117         }
1118
1119         /**
1120          * Parse skinvar nextlink
1121          */
1122         function parse_nextlink($linktext = '', $amount = 10, $recount = '') {
1123                 global $itemidnext, $archivenext, $startpos;
1124                 if ($this->skintype == 'item')
1125                         $this->_itemlink($itemidnext, $linktext);
1126                 else if ($this->skintype == 'search' || $this->skintype == 'index')
1127                         $this->_searchlink($amount, $startpos, 'next', $linktext, $recount);
1128                 else
1129                         $this->_archivelink($archivenext, $linktext);
1130         }
1131
1132         /**
1133          * Parse skinvar nucleusbutton
1134          */
1135         function parse_nucleusbutton($imgurl = '',
1136                                                                  $imgwidth = '85',
1137                                                                  $imgheight = '31') {
1138                 global $CONF;
1139                 if ($imgurl == '') {
1140                         $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
1141                 } else if (PARSER::getProperty('IncludeMode') == 'skindir'){
1142                         // when skindit IncludeMode is used: start from skindir
1143                         $imgurl = $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $imgurl;
1144                 }
1145
1146                 $this->formdata = array(
1147                         'imgurl' => $imgurl,
1148                         'imgwidth' => $imgwidth,
1149                         'imgheight' => $imgheight,
1150                 );
1151                 $this->doForm('nucleusbutton');
1152         }
1153         
1154         /**
1155          * Parse skinvar otherarchive
1156          */     
1157         function parse_otherarchive($blogname, $template, $category = '') {
1158                 global $archive, $manager;
1159                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
1160                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1161                 $this->_setBlogCategory($b, $category);
1162                 $this->_preBlogContent('otherachive',$b);
1163                 $b->showArchive($template, $y, $m, $d);
1164                 $this->_postBlogContent('otherachive',$b);
1165         }
1166         
1167         /**
1168          * Parse skinvar otherarchivedaylist
1169          */
1170         function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0) {
1171                 global $manager;
1172                 if ($category == 'all') $category = '';
1173                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1174                 $this->_setBlogCategory($b, $category);
1175                 $this->_preBlogContent('otherarchivelist',$b);
1176                 $b->showArchiveList($template, 'day', $limit);
1177                 $this->_postBlogContent('otherarchivelist',$b);
1178         }
1179         
1180         /**
1181          * Parse skinvar otherarchivelist
1182          */
1183         function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0) {
1184                 global $manager;
1185                 if ($category == 'all') $category = '';
1186                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1187                 $this->_setBlogCategory($b, $category);
1188                 $this->_preBlogContent('otherarchivelist',$b);
1189                 $b->showArchiveList($template, 'month', $limit);
1190                 $this->_postBlogContent('otherarchivelist',$b);
1191         }
1192                 
1193         /**
1194          * Parse skinvar otherarchiveyearlist
1195          */
1196         function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0) {
1197                 global $manager;
1198                 if ($category == 'all') $category = '';
1199                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1200                 $this->_setBlogCategory($b, $category);
1201                 $this->_preBlogContent('otherarchivelist',$b);
1202                 $b->showArchiveList($template, 'year', $limit);
1203                 $this->_postBlogContent('otherarchivelist',$b);
1204         }       
1205         
1206         /**
1207          * Parse skinvar otherblog
1208          */
1209         function parse_otherblog($blogname, $template, $amount = 10, $category = '') {
1210                 global $manager;
1211
1212                 list($limit, $offset) = sscanf($amount, '%d(%d)');
1213
1214                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1215                 $this->_setBlogCategory($b, $category);
1216                 $this->_preBlogContent('otherblog',$b);
1217                 $this->amountfound = $b->readLog($template, $limit, $offset);
1218                 $this->_postBlogContent('otherblog',$b);
1219         }
1220
1221         /**
1222          * Parse skinvar othersearchresults
1223          */
1224         function parse_othersearchresults($blogname, $template, $maxresults = 50) {
1225                 global $query, $amount, $manager, $startpos;
1226                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1227                 $this->_setBlogCategory($b, '');        // need this to select default category
1228                 $this->_preBlogContent('othersearchresults',$b);
1229                 $b->search($query, $template, $amount, $maxresults, $startpos);
1230                 $this->_postBlogContent('othersearchresults',$b);
1231         }
1232
1233         /**
1234           * Executes a plugin skinvar
1235           *
1236           * @param pluginName name of plugin (without the NP_)
1237           *
1238           * extra parameters can be added
1239           */
1240         function parse_plugin($pluginName) {
1241                 global $manager;
1242
1243                 // should be already tested from the parser (PARSER.php)
1244                 // only continue when the plugin is really installed
1245                 /*if (!$manager->pluginInstalled('NP_' . $pluginName))
1246                         return;*/
1247
1248                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
1249                 if (!$plugin) return;
1250
1251                 // get arguments
1252                 $params = func_get_args();
1253
1254                 // remove plugin name
1255                 array_shift($params);
1256
1257                 // add skin type on front
1258                 array_unshift($params, $this->skintype);
1259
1260                 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
1261         }
1262         
1263         /**
1264          * Parse skinvar prevarchive
1265          */
1266         function parse_prevarchive() {
1267                 global $archiveprev;
1268                 echo $archiveprev;
1269         }
1270
1271         /**
1272          * Parse skinvar preview
1273          */
1274         function parse_preview($template) {
1275                 global $blog, $CONF, $manager;
1276
1277                 $template =& $manager->getTemplate($template);
1278                 $row['body'] = '<span id="prevbody"></span>';
1279                 $row['title'] = '<span id="prevtitle"></span>';
1280                 $row['more'] = '<span id="prevmore"></span>';
1281                 $row['itemlink'] = '';
1282                 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
1283                 echo TEMPLATE::fill($template['ITEM_HEADER'],$row);
1284                 echo TEMPLATE::fill($template['ITEM'],$row);
1285                 echo TEMPLATE::fill($template['ITEM_FOOTER'],$row);
1286         }
1287
1288         /*
1289          * Parse skinvar previtem
1290          * (include itemid of prev item)                 
1291          */
1292         function parse_previtem() {
1293                 global $itemidprev;
1294                 if (isset($itemidprev)) echo (int)$itemidprev;
1295         }
1296         
1297         /**
1298          * ACTIONS::parse_previtemtitle()
1299          * Parse skinvar previtemtitle
1300          * (include itemtitle of prev item)
1301          * 
1302          * @param       String  $format string format
1303          * @return      String  formatted string
1304          */
1305         function parse_previtemtitle($format = '')
1306         {
1307                 global $itemtitleprev;
1308                 
1309                 switch ( $format )
1310                 {
1311                         case 'xml':
1312                                 echo ENTITY::hen($itemtitleprev);
1313                                 break;
1314                         case 'raw':
1315                                 echo $itemtitleprev;
1316                                 break;
1317                         case 'attribute':
1318                         default:
1319                                 echo ENTITY::hsc($itemtitleprev);
1320                                 break;
1321                 }
1322                 return;
1323         }
1324         
1325         /**
1326          * Parse skinvar prevlink
1327          */
1328         function parse_prevlink($linktext = '', $amount = 10) {
1329                 global $itemidprev, $archiveprev, $startpos;
1330
1331                 if ($this->skintype == 'item')
1332                         $this->_itemlink($itemidprev, $linktext);
1333                 else if ($this->skintype == 'search' || $this->skintype == 'index')
1334                         $this->_searchlink($amount, $startpos, 'prev', $linktext);
1335                 else
1336                         $this->_archivelink($archiveprev, $linktext);
1337         }
1338
1339         /**
1340          * Parse skinvar query
1341          * (includes the search query)   
1342          */
1343         function parse_query() {
1344                 global $query;
1345                 echo ENTITY::hsc($query);
1346         }
1347         
1348         /**
1349          * Parse skinvar referer
1350          */
1351         function parse_referer() {
1352                 echo ENTITY::hsc(serverVar('HTTP_REFERER'));
1353         }
1354
1355         /**
1356          * Parse skinvar searchform
1357          */
1358         function parse_searchform($blogname = '') {
1359                 global $CONF, $manager, $maxresults;
1360                 if ($blogname) {
1361                         $blog =& $manager->getBlog(getBlogIDFromName($blogname));
1362                 } else {
1363                         global $blog;
1364                 }
1365                 // use default blog when no blog is selected
1366                 $this->formdata = array(
1367                         'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
1368                         'query' => ENTITY::hsc(getVar('query')),
1369                 );
1370                 $this->doForm('searchform');
1371         }
1372
1373         /**
1374          * Parse skinvar searchresults
1375          */
1376         function parse_searchresults($template, $maxresults = 50 ) {
1377                 global $blog, $query, $amount, $startpos;
1378
1379                 $this->_setBlogCategory($blog, '');     // need this to select default category
1380                 $this->_preBlogContent('searchresults',$blog);
1381                 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
1382                 $this->_postBlogContent('searchresults',$blog);
1383         }
1384
1385         /**
1386          * Parse skinvar self
1387          */
1388         function parse_self() {
1389                 global $CONF;
1390                 echo $CONF['Self'];
1391         }
1392
1393         /**
1394          * Parse skinvar sitevar
1395          * (include a sitevar)   
1396          */
1397         function parse_sitevar($which) {
1398                 global $CONF;
1399                 switch($which) {
1400                         case 'url':
1401                                 echo $CONF['IndexURL'];
1402                                 break;
1403                         case 'name':
1404                                 echo $CONF['SiteName'];
1405                                 break;
1406                         case 'admin':
1407                                 echo $CONF['AdminEmail'];
1408                                 break;
1409                         case 'adminurl':
1410                                 echo $CONF['AdminURL'];
1411                 }
1412         }
1413
1414         /**
1415          * Parse skinname
1416          */
1417         function parse_skinname() {
1418                 echo $this->skin->getName();
1419         }
1420         
1421         /**
1422          * Parse skintype (experimental)
1423          */
1424         function parse_skintype() {
1425                 echo $this->skintype;
1426         }
1427
1428         /**
1429          * Parse text
1430          */
1431         function parse_text($which) {
1432                 // constant($which) only available from 4.0.4 :(
1433                 if (defined($which)) {
1434                         eval("echo $which;");
1435                 }
1436         }
1437         
1438         /**
1439          * Parse ticket
1440          */
1441         function parse_ticket() {
1442                 global $manager;
1443                 $manager->addTicketHidden();
1444         }
1445
1446         /**
1447          * ACTIONS::parse_todaylink()
1448          * Parse skinvar todaylink
1449          * A link to the today page (depending on selected blog, etc...)
1450          *
1451          * @param       String  $linktext       text for link
1452          * @return      Void
1453          */
1454         function parse_todaylink($linktext = '')
1455         {
1456                 global $blog, $CONF;
1457                 if ( $blog )
1458                 {
1459                         echo $this->_link(LINK::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
1460                 }
1461                 else
1462                 {
1463                         echo $this->_link($CONF['SiteUrl'], $linktext);
1464                 }
1465                 return;
1466         }
1467         
1468         /**
1469          * Parse vars
1470          * When commentform is not used, to include a hidden field with itemid   
1471          */
1472         function parse_vars() {
1473                 global $itemid;
1474                 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />';
1475         }
1476
1477         /**
1478          * Parse skinvar version
1479          * (include nucleus versionnumber)       
1480          */
1481         function parse_version() {
1482                 global $nucleus;
1483                 echo 'Nucleus CMS ' . $nucleus['version'];
1484         }
1485         
1486         /**
1487          * Parse skinvar sticky
1488          */
1489         function parse_sticky($itemnumber = 0, $template = '') {
1490                 global $manager;
1491                 
1492                 $itemnumber = intval($itemnumber);
1493                 $itemarray = array($itemnumber);
1494
1495                 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
1496                 $this->_preBlogContent('sticky',$b);
1497                 $this->amountfound = $b->readLogFromList($itemarray, $template);
1498                 $this->_postBlogContent('sticky',$b);
1499         }
1500
1501
1502 }
1503 ?>