OSDN Git Service

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