OSDN Git Service

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