OSDN Git Service

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