OSDN Git Service

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