OSDN Git Service

Avoid fatal error in parse_bloglist() when the blog is not defined.
[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.5 2007-02-26 23:42:01 kmorimatsu Exp $
22  * @version $NucleusJP: ACTIONS.php,v 1.4 2007/02/04 06:28:45 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                 BLOG::showBlogList($template, $bnametype);
474         }
475         
476         /**
477          * Parse skinvar blogsetting
478          */
479         function parse_blogsetting($which) {
480                 global $blog;
481                 switch($which) {
482                         case 'id':
483                                 echo htmlspecialchars($blog->getID());
484                                 break;
485                         case 'url':
486                                 echo htmlspecialchars($blog->getURL());
487                                 break;
488                         case 'name':
489                                 echo htmlspecialchars($blog->getName());
490                                 break;
491                         case 'desc':
492                                 echo htmlspecialchars($blog->getDescription());
493                                 break;
494                         case 'short':
495                                 echo htmlspecialchars($blog->getShortName());
496                                 break;
497                 }
498         }
499         
500         /**
501          * Parse callback
502          */
503         function parse_callback($eventName, $type)
504         {
505                 global $manager;
506                 $manager->notify($eventName, array('type' => $type));
507         }
508         
509         /**
510          * Parse skinvar category
511          */     
512         function parse_category($type = 'name') {
513                 global $catid, $blog;
514                 if (!$blog->isValidCategory($catid))
515                         return;
516
517                 switch($type) {
518                         case 'name':
519                                 echo $blog->getCategoryName($catid);
520                                 break;
521                         case 'desc':
522                                 echo $blog->getCategoryDesc($catid);
523                                 break;
524                         case 'id':
525                                 echo $catid;
526                                 break;
527                 }
528         }
529         
530         /**
531          * Parse categorylist
532          */     
533         function parse_categorylist($template, $blogname = '') {
534                 global $blog, $manager;
535
536                 if ($blogname == '') {
537                         $this->_preBlogContent('categorylist',$blog);
538                         $blog->showCategoryList($template);
539                         $this->_postBlogContent('categorylist',$blog);
540                 } else {
541                         $b =& $manager->getBlog(getBlogIDFromName($blogname));
542                         $this->_preBlogContent('categorylist',$b);
543                         $b->showCategoryList($template);
544                         $this->_postBlogContent('categorylist',$b);
545                 }
546         }
547         
548         /**
549          * Parse skinvar charset
550          */
551         function parse_charset() {
552                 echo _CHARSET;
553         }
554         
555         /**
556          * Parse skinvar commentform
557          */
558         function parse_commentform($destinationurl = '') {
559                 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
560
561                 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
562                 if (stristr($destinationurl, 'action.php')) {
563                         $args = func_get_args();
564                         $destinationurl = $args[1];
565                         ACTIONLOG::add(WARNING,'actionurl is not longer a parameter on commentform skinvars. Moved to be a global setting instead.');
566                 }
567
568                 $actionurl = $CONF['ActionURL'];
569
570                 // if item is closed, show message and do nothing
571                 $item =& $manager->getItem($itemid,0,0);
572                 if ($item['closed'] || !$blog->commentsEnabled()) {
573                         $this->doForm('commentform-closed');
574                         return;
575                 }
576
577                 if (!$destinationurl)
578                 {
579                         $destinationurl = createLink(
580                                 'item',
581                                 array(
582                                         'itemid' => $itemid,
583                                         'title' => $item['title'],
584                                         'timestamp' => $item['timestamp'],
585                                         'extra' => $this->linkparams
586                                 )
587                         );
588
589                         // note: createLink returns an HTML encoded URL
590                 } else {
591                         // HTML encode URL
592                         $destinationurl = htmlspecialchars($destinationurl);
593                 }
594
595                 // values to prefill
596                 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
597                 if (!$user) $user = postVar('user');
598                 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
599                 if (!$userid) $userid = postVar('userid');
600                 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
601                 if (!$email) {
602                         $email = postVar('email');
603                 }
604                 $body = postVar('body');
605
606                 $this->formdata = array(
607                         'destinationurl' => $destinationurl,    // url is already HTML encoded
608                         'actionurl' => htmlspecialchars($actionurl),
609                         'itemid' => $itemid,
610                         'user' => htmlspecialchars($user),
611                         'userid' => htmlspecialchars($userid),
612                         'email' => htmlspecialchars($email),
613                         'body' => htmlspecialchars($body),
614                         'membername' => $member->getDisplayName(),
615                         'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
616                 );
617
618                 if (!$member->isLoggedIn()) {
619                         $this->doForm('commentform-notloggedin');
620                 } else {
621                         $this->doForm('commentform-loggedin');
622                 }
623         }
624         
625         /**
626          * Parse skinvar comments
627          * include comments for one item         
628          */     
629         function parse_comments($template) {
630                 global $itemid, $manager, $blog, $highlight;
631                 $template =& $manager->getTemplate($template);
632
633                 // create parser object & action handler
634                 $actions =& new ITEMACTIONS($blog);
635                 $parser =& new PARSER($actions->getDefinedActions(),$actions);
636                 $actions->setTemplate($template);
637                 $actions->setParser($parser);
638                 $item = ITEM::getitem($itemid, 0, 0);
639                 $actions->setCurrentItem($item);
640
641                 $comments =& new COMMENTS($itemid);
642                 $comments->setItemActions($actions);
643                 $comments->showComments($template, -1, 1, $highlight);  // shows ALL comments
644         }
645
646         /**
647          * Parse errordiv
648          */
649         function parse_errordiv() {
650                 global $errormessage;
651                 if ($errormessage)
652                         echo '<div class="error">', htmlspecialchars($errormessage),'</div>';
653         }
654         
655         /**
656          * Parse skinvar errormessage
657          */
658         function parse_errormessage() {
659                 global $errormessage;
660                 echo $errormessage;
661         }
662         
663         /**
664          * Parse formdata
665          */
666         function parse_formdata($what) {
667                 echo $this->formdata[$what];
668         }
669         
670         /**
671          * Parse ifcat
672          */
673         function parse_ifcat($text = '') {
674                 if ($text == '') {
675                         // new behaviour
676                         $this->parse_if('category');
677                 } else {
678                         // old behaviour
679                         global $catid, $blog;
680                         if ($blog->isValidCategory($catid))
681                                 echo $text;
682                 }
683         }
684
685         /**
686          * Parse skinvar image
687          */
688         function parse_image($what = 'imgtag') {
689                 global $CONF;
690
691                 $imagetext      = htmlspecialchars(requestVar('imagetext'));
692                 $imagepopup = requestVar('imagepopup');
693                 $width          = intRequestVar('width');
694                 $height         = intRequestVar('height');
695                 $fullurl        = htmlspecialchars($CONF['MediaURL'] . $imagepopup);
696
697                 switch($what)
698                 {
699                         case 'url':
700                                 echo $fullurl;
701                                 break;
702                         case 'width':
703                                 echo $width;
704                                 break;
705                         case 'height':
706                                 echo $height;
707                                 break;
708                         case 'caption':
709                         case 'text':
710                                 echo $imagetext;
711                                 break;
712                         case 'imgtag':
713                         default:
714                                 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
715                                 break;
716                 }
717         }
718         
719         /**
720          * Parse skinvar imagetext
721          */
722         function parse_imagetext() {
723                 echo htmlspecialchars(requestVar('imagetext'));
724         }
725
726         /**
727          * Parse skinvar item
728          * include one item (no comments)        
729          */     
730         function parse_item($template) {
731                 global $blog, $itemid, $highlight;
732                 $this->_setBlogCategory($blog, '');     // need this to select default category
733                 $this->_preBlogContent('item',$blog);
734                 $r = $blog->showOneitem($itemid, $template, $highlight);
735                 if ($r == 0)
736                         echo _ERROR_NOSUCHITEM;
737                 $this->_postBlogContent('item',$blog);
738         }
739
740         /**
741          * Parse skinvar itemid
742          */     
743         function parse_itemid() {
744                 global $itemid;
745                 echo $itemid;
746         }
747         
748         /**
749          * Parse skinvar itemlink
750          */     
751         function parse_itemlink($linktext = '') {
752                 global $itemid;
753                 $this->_itemlink($itemid, $linktext);
754         }
755
756         /**
757          * Parse itemtitle
758          */     
759         function parse_itemtitle($format = '') {
760                 global $manager, $itemid;
761                 $item =& $manager->getItem($itemid,0,0);
762
763                 switch ($format) {
764                         case 'xml':
765                                 echo stringToXML ($item['title']);
766                                 break;
767                         case 'attribute':
768                                 echo stringToAttribute ($item['title']);
769                                 break;
770                         case 'raw':
771                                 echo $item['title'];
772                                 break;
773                         default:
774                                 echo htmlspecialchars(strip_tags($item['title']));
775                                 break;
776                 }
777         }
778
779         /**
780          * Parse skinvar loginform
781          */
782         function parse_loginform() {
783                 global $member, $CONF;
784                 if (!$member->isLoggedIn()) {
785                         $filename = 'loginform-notloggedin';
786                         $this->formdata = array();
787                 } else {
788                         $filename = 'loginform-loggedin';
789                         $this->formdata = array(
790                                 'membername' => $member->getDisplayName(),
791                         );
792                 }
793                 $this->doForm($filename);
794         }
795
796         /**
797          * Parse skinvar member
798          * (includes a member info thingie)      
799          */
800         function parse_member($what) {
801                 global $memberinfo, $member;
802
803                 // 1. only allow the member-details-page specific variables on member pages
804                 if ($this->skintype == 'member') {
805
806                         switch($what) {
807                                 case 'name':
808                                         echo htmlspecialchars($memberinfo->getDisplayName());
809                                         break;
810                                 case 'realname':
811                                         echo htmlspecialchars($memberinfo->getRealName());
812                                         break;
813                                 case 'notes':
814                                         echo htmlspecialchars($memberinfo->getNotes());
815                                         break;
816                                 case 'url':
817                                         echo htmlspecialchars($memberinfo->getURL());
818                                         break;
819                                 case 'email':
820                                         echo htmlspecialchars($memberinfo->getEmail());
821                                         break;
822                                 case 'id':
823                                         echo htmlspecialchars($memberinfo->getID());
824                                         break;                                  
825                         }
826                 }
827
828                 // 2. the next bunch of options is available everywhere, as long as the user is logged in
829                 if ($member->isLoggedIn())
830                 {
831                         switch($what) {
832                                 case 'yourname':
833                                         echo $member->getDisplayName();
834                                         break;
835                                 case 'yourrealname':
836                                         echo $member->getRealName();
837                                         break;
838                                 case 'yournotes':
839                                         echo $member->getNotes();
840                                         break;
841                                 case 'yoururl':
842                                         echo $member->getURL();
843                                         break;
844                                 case 'youremail':
845                                         echo $member->getEmail();
846                                         break;
847                                 case 'yourid':
848                                         echo $member->getID();
849                                         break;
850                         }
851                 }
852
853         }
854
855         /**
856          * Parse skinvar membermailform
857          */
858         function parse_membermailform($rows = 10, $cols = 40, $desturl = '') {
859                 global $member, $CONF, $memberid;
860
861                 if ($desturl == '') {
862                         if ($CONF['URLMode'] == 'pathinfo')
863                                 $desturl = createMemberLink($memberid);
864                         else
865                                 $desturl = $CONF['IndexURL'] . createMemberLink($memberid);
866                 }
867
868                 $message = postVar('message');
869                 $frommail = postVar('frommail');
870
871                 $this->formdata = array(
872                         'url' => htmlspecialchars($desturl),
873                         'actionurl' => htmlspecialchars($CONF['ActionURL']),
874                         'memberid' => $memberid,
875                         'rows' => $rows,
876                         'cols' => $cols,
877                         'message' => htmlspecialchars($message),
878                         'frommail' => htmlspecialchars($frommail)
879                 );
880                 if ($member->isLoggedIn()) {
881                         $this->doForm('membermailform-loggedin');
882                 } else if ($CONF['NonmemberMail']) {
883                         $this->doForm('membermailform-notloggedin');
884                 } else {
885                         $this->doForm('membermailform-disallowed');
886                 }
887
888         }
889         
890         /**
891          * Parse skinvar nextarchive
892          */     
893         function parse_nextarchive() {
894                 global $archivenext;
895                 echo $archivenext;
896         }
897
898         /**
899          * Parse skinvar nextitem
900          * (include itemid of next item)
901          */      
902         function parse_nextitem() {
903                 global $itemidnext;
904                 echo $itemidnext;
905         }
906
907         /**
908          * Parse skinvar nextitemtitle
909          * (include itemtitle of next item)
910          */      
911         function parse_nextitemtitle($format = '') {
912                 global $itemtitlenext;
913
914                 switch ($format) {
915                         case 'xml':
916                                 echo stringToXML ($itemtitlenext);
917                                 break;
918                         case 'attribute':
919                                 echo stringToAttribute ($itemtitlenext);
920                                 break;
921                         case 'raw':
922                                 echo $itemtitlenext;
923                                 break;
924                         default:
925                                 echo htmlspecialchars($itemtitlenext);
926                                 break;
927                 }
928         }
929
930         /**
931          * Parse skinvar nextlink
932          */     
933         function parse_nextlink($linktext = '', $amount = 10) {
934                 global $itemidnext, $archivenext, $startpos;
935                 if ($this->skintype == 'item')
936                         $this->_itemlink($itemidnext, $linktext);
937                 else if ($this->skintype == 'search' || $this->skintype == 'index')
938                         $this->_searchlink($amount, $startpos, 'next', $linktext);
939                 else
940                         $this->_archivelink($archivenext, $linktext);
941         }
942
943         /**
944          * Parse skinvar nucleusbutton
945          */
946         function parse_nucleusbutton($imgurl = '',
947                                                                  $imgwidth = '85',
948                                                                  $imgheight = '31') {
949                 global $CONF;
950                 if ($imgurl == '') {
951                         $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
952                 } else if (PARSER::getProperty('IncludeMode') == 'skindir'){
953                         // when skindit IncludeMode is used: start from skindir
954                         $imgurl = $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $imgurl;
955                 }
956
957                 $this->formdata = array(
958                         'imgurl' => $imgurl,
959                         'imgwidth' => $imgwidth,
960                         'imgheight' => $imgheight,
961                 );
962                 $this->doForm('nucleusbutton');
963         }
964         
965         function parse_otherarchive($blogname, $template, $category = '') {
966                 global $archive, $manager;
967                 sscanf($archive,'%d-%d-%d',$y,$m,$d);
968                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
969                 $this->_setBlogCategory($b, $category);
970                 $this->_preBlogContent('otherachive',$b);
971                 $b->showArchive($template, $y, $m, $d);
972                 $this->_postBlogContent('otherachive',$b);
973         }
974         
975         /**
976          * Parse skinvar otherarchivedaylist
977          */     
978         function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0) {
979                 global $manager;
980                 if ($category == 'all') $category = '';
981                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
982                 $this->_setBlogCategory($b, $category);
983                 $this->_preBlogContent('otherarchivelist',$b);
984                 $b->showArchiveList($template, 'day', $limit);
985                 $this->_postBlogContent('otherarchivelist',$b);
986         }
987         
988         /**
989          * Parse skinvar otherarchivelist
990          */     
991         function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0) {
992                 global $manager;
993                 if ($category == 'all') $category = '';
994                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
995                 $this->_setBlogCategory($b, $category);
996                 $this->_preBlogContent('otherarchivelist',$b);
997                 $b->showArchiveList($template, 'month', $limit);
998                 $this->_postBlogContent('otherarchivelist',$b);
999         }
1000         
1001         /**
1002          * Parse skinvar otherblog
1003          */     
1004         function parse_otherblog($blogname, $template, $amount = 10, $category = '') {
1005                 global $manager;
1006
1007                 list($limit, $offset) = sscanf($amount, '%d(%d)');
1008
1009                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1010                 $this->_setBlogCategory($b, $category);
1011                 $this->_preBlogContent('otherblog',$b);
1012                 $this->amountfound = $b->readLog($template, $limit, $offset);
1013                 $this->_postBlogContent('otherblog',$b);
1014         }
1015
1016         /**
1017          * Parse skinvar othersearchresults
1018          */     
1019         function parse_othersearchresults($blogname, $template, $maxresults = 50) {
1020                 global $query, $amount, $manager, $startpos;
1021                 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1022                 $this->_setBlogCategory($b, '');        // need this to select default category
1023                 $this->_preBlogContent('othersearchresults',$b);
1024                 $b->search($query, $template, $amount, $maxresults, $startpos);
1025                 $this->_postBlogContent('othersearchresults',$b);
1026         }
1027
1028         /**
1029           * Executes a plugin skinvar
1030           *
1031           * @param pluginName name of plugin (without the NP_)
1032           *
1033           * extra parameters can be added
1034           */
1035         function parse_plugin($pluginName) {
1036                 global $manager;
1037
1038                 // only continue when the plugin is really installed
1039                 if (!$manager->pluginInstalled('NP_' . $pluginName))
1040                         return;
1041
1042                 $plugin =& $manager->getPlugin('NP_' . $pluginName);
1043                 if (!$plugin) return;
1044
1045                 // get arguments
1046                 $params = func_get_args();
1047
1048                 // remove plugin name
1049                 array_shift($params);
1050
1051                 // add skin type on front
1052                 array_unshift($params, $this->skintype);
1053
1054                 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
1055         }
1056         
1057         /**
1058          * Parse skinvar prevarchive
1059          */     
1060         function parse_prevarchive() {
1061                 global $archiveprev;
1062                 echo $archiveprev;
1063         }
1064
1065         /**
1066          * Parse skinvar preview
1067          */
1068         function parse_preview($template) {
1069                 global $blog, $CONF, $manager;
1070
1071                 $template =& $manager->getTemplate($template);
1072                 $row['body'] = '<span id="prevbody"></span>';
1073                 $row['title'] = '<span id="prevtitle"></span>';
1074                 $row['more'] = '<span id="prevmore"></span>';
1075                 $row['itemlink'] = '';
1076                 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
1077                 echo TEMPLATE::fill($template['ITEM_HEADER'],$row);
1078                 echo TEMPLATE::fill($template['ITEM'],$row);
1079                 echo TEMPLATE::fill($template['ITEM_FOOTER'],$row);
1080         }
1081
1082         /*
1083          * Parse skinvar previtem
1084          * (include itemid of prev item)                 
1085          */       
1086         function parse_previtem() {
1087                 global $itemidprev;
1088                 echo $itemidprev;
1089         }
1090
1091         /**
1092          * Parse skinvar previtemtitle
1093          * (include itemtitle of prev item)
1094          */      
1095         function parse_previtemtitle($format = '') {
1096                 global $itemtitleprev;
1097
1098                 switch ($format) {
1099                         case 'xml':
1100                                 echo stringToXML ($itemtitleprev);
1101                                 break;
1102                         case 'attribute':
1103                                 echo stringToAttribute ($itemtitleprev);
1104                                 break;
1105                         case 'raw':
1106                                 echo $itemtitleprev;
1107                                 break;
1108                         default:
1109                                 echo htmlspecialchars($itemtitleprev);
1110                                 break;
1111                 }
1112         }
1113
1114         /**
1115          * Parse skinvar prevlink
1116          */     
1117         function parse_prevlink($linktext = '', $amount = 10) {
1118                 global $itemidprev, $archiveprev, $startpos;
1119
1120                 if ($this->skintype == 'item')
1121                         $this->_itemlink($itemidprev, $linktext);
1122                 else if ($this->skintype == 'search' || $this->skintype == 'index')
1123                         $this->_searchlink($amount, $startpos, 'prev', $linktext);
1124                 else
1125                         $this->_archivelink($archiveprev, $linktext);
1126         }
1127
1128         /**
1129          * Parse skinvar query
1130          * (includes the search query)   
1131          */     
1132         function parse_query() {
1133                 global $query;
1134                 echo htmlspecialchars($query);
1135         }
1136         
1137         /**
1138          * Parse skinvar referer
1139          */
1140         function parse_referer() {
1141                 echo htmlspecialchars(serverVar('HTTP_REFERER'));
1142         }
1143
1144         /**
1145          * Parse skinvar searchform
1146          */
1147         function parse_searchform($blogname = '') {
1148                 global $CONF, $manager, $maxresults;
1149                 if ($blogname) {
1150                         $blog =& $manager->getBlog(getBlogIDFromName($blogname));
1151                 } else {
1152                         global $blog;
1153                 }
1154                 // use default blog when no blog is selected
1155                 $this->formdata = array(
1156                         'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
1157                         'query' => htmlspecialchars(getVar('query')),
1158                 );
1159                 $this->doForm('searchform');
1160         }
1161
1162         /**
1163          * Parse skinvar searchresults
1164          */     
1165         function parse_searchresults($template, $maxresults = 50 ) {
1166                 global $blog, $query, $amount, $startpos;
1167
1168                 $this->_setBlogCategory($blog, '');     // need this to select default category
1169                 $this->_preBlogContent('searchresults',$blog);
1170                 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
1171                 $this->_postBlogContent('searchresults',$blog);
1172         }
1173
1174         /**
1175          * Parse skinvar self
1176          */
1177         function parse_self() {
1178                 global $CONF;
1179                 echo $CONF['Self'];
1180         }
1181
1182         /**
1183          * Parse skinvar sitevar
1184          * (include a sitevar)   
1185          */
1186         function parse_sitevar($which) {
1187                 global $CONF;
1188                 switch($which) {
1189                         case 'url':
1190                                 echo $CONF['IndexURL'];
1191                                 break;
1192                         case 'name':
1193                                 echo $CONF['SiteName'];
1194                                 break;
1195                         case 'admin':
1196                                 echo $CONF['AdminEmail'];
1197                                 break;
1198                         case 'adminurl':
1199                                 echo $CONF['AdminURL'];
1200                 }
1201         }
1202
1203         /**
1204          * Parse skinname
1205          */
1206         function parse_skinname() {
1207                 echo $this->skin->getName();
1208         }
1209
1210         /**
1211          * Parse text
1212          */
1213         function parse_text($which) {
1214                 // constant($which) only available from 4.0.4 :(
1215                 if (defined($which)) {
1216                         eval("echo $which;");
1217                 }
1218         }
1219         
1220         /**
1221          * Parse ticket
1222          */
1223         function parse_ticket() {
1224                 global $manager;
1225                 $manager->addTicketHidden();
1226         }
1227
1228         /**
1229          *      Parse skinvar todaylink
1230          *      A link to the today page (depending on selected blog, etc...)
1231          */     
1232         function parse_todaylink($linktext = '') {
1233                 global $blog, $CONF;
1234                 if ($blog)
1235                         echo $this->_link(createBlogidLink($blog->getID(),$this->linkparams), $linktext);
1236                 else
1237                         echo $this->_link($CONF['SiteUrl'], $linktext);
1238         }
1239
1240         /**
1241          * Parse vars
1242          * When commentform is not used, to include a hidden field with itemid   
1243          */
1244         function parse_vars() {
1245                 global $itemid;
1246                 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />';
1247         }
1248
1249         /**
1250          * Parse skinvar version
1251          * (include nucleus versionnumber)       
1252          */
1253         function parse_version() {
1254                 global $nucleus;
1255                 echo 'Nucleus CMS ' . $nucleus['version'];
1256         }
1257
1258 }
1259 ?>