OSDN Git Service

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