OSDN Git Service

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