OSDN Git Service

MERGE: リビジョン1734のマージ。Actionsクラスから不要行を削除。
[nucleus-jp/nucleus-next.git] / nucleus / libs / ACTIONS.php
1 <?php\r
2 /**\r
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
4  * Copyright (C) 2002-2012 The Nucleus Group\r
5  *\r
6  * This program is free software; you can redistribute it and/or\r
7  * modify it under the terms of the GNU General Public License\r
8  * as published by the Free Software Foundation; either version 2\r
9  * of the License, or (at your option) any later version.\r
10  * (see nucleus/documentation/index.html#license for more info)\r
11  */\r
12 /**\r
13  * This class contains the functions that get called by using\r
14  * the special tags in the skins\r
15  *\r
16  * The allowed tags for a type of skinpart are defined by the\r
17  * Skin::getAllowedActionsForType($type) method\r
18  *\r
19  * @license http://nucleuscms.org/license.txt GNU General Public License\r
20  * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
21  * @version $Id: ACTIONS.php 1725 2012-04-07 02:21:32Z sakamocchi $\r
22  */\r
23 \r
24 class Actions extends BaseActions\r
25 {\r
26         // part of the skin currently being parsed ('index', 'item', 'archive',\r
27         // 'archivelist', 'member', 'search', 'error', 'imagepopup')\r
28         var $skintype;\r
29         \r
30         // contains an assoc array with parameters that need to be included when\r
31         // generating links to items/archives/... (e.g. catid)\r
32         var $linkparams;\r
33         \r
34         // reference to the skin object for which a part is being parsed\r
35         var $skin;\r
36         \r
37         // used when including templated forms from the include/ dir. The $formdata var\r
38         // contains the values to fill out in there (assoc array name -> value)\r
39         var $formdata;\r
40         \r
41         // filled out with the number of displayed items after calling one of the\r
42         // (other)blog/(other)searchresults skinvars.\r
43         var $amountfound;\r
44         \r
45         /**\r
46          * Actions::__construct()\r
47          * Constructor for a new Actions object\r
48          * \r
49          * @param       string  $type\r
50          * @return      void\r
51          */\r
52         public function __construct($type)\r
53         {\r
54                 global $catid;\r
55                 \r
56                 // call constructor of superclass first\r
57                 $this->BaseActions();\r
58                 $this->skintype = $type;\r
59                 \r
60                 if ( $catid )\r
61                 {\r
62                         $this->linkparams = array('catid' => $catid);\r
63                 }\r
64                 return;\r
65         }\r
66         \r
67         /**\r
68          * Actions::setSkin()\r
69          * Set the skin\r
70          * @param       object  $skin   an instance of Skin class\r
71          * @return      void\r
72          */\r
73         public function setSkin(&$skin)\r
74         {\r
75                 $this->skin =& $skin;\r
76                 return;\r
77         }\r
78         \r
79         /**\r
80          * Actions::setParser()\r
81          * Set the parser\r
82          * \r
83          * @param       object  $parser an instance of Parser class\r
84          * @return      void\r
85          */\r
86         public function setParser(&$parser)\r
87         {\r
88                 $this->parser =& $parser;\r
89                 return;\r
90         }\r
91         \r
92         /**\r
93          * Actions::doForm()\r
94          * Forms get parsedincluded now, using an extra <formdata> skinvar\r
95          *\r
96          * @param       string  $filename\r
97          * @return      void\r
98          */\r
99         public function doForm($filename)\r
100         {\r
101                 global $DIR_NUCLEUS;\r
102                 array_push($this->parser->actions,'formdata','text','callback','errordiv','ticket');\r
103                 \r
104                 $oldIncludeMode = Parser::getProperty('IncludeMode');\r
105                 $oldIncludePrefix = Parser::getProperty('IncludePrefix');\r
106                 Parser::setProperty('IncludeMode','normal');\r
107                 Parser::setProperty('IncludePrefix','');\r
108                 \r
109                 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');\r
110                 Parser::setProperty('IncludeMode',$oldIncludeMode);\r
111                 Parser::setProperty('IncludePrefix',$oldIncludePrefix);\r
112                 \r
113                 array_pop($this->parser->actions);      // errordiv\r
114                 array_pop($this->parser->actions);      // callback\r
115                 array_pop($this->parser->actions);      // text\r
116                 array_pop($this->parser->actions);      // formdata\r
117                 array_pop($this->parser->actions);      // ticket\r
118                 return;\r
119         }\r
120 \r
121         /**\r
122          * Actions::checkCondition()\r
123          * Checks conditions for if statements\r
124          *\r
125          * @param       string  $field  type of <%if%>\r
126          * @param       string  $name   property of field\r
127          * @param       string  $value  value of property\r
128          * @return      boolean condition\r
129          */\r
130         public function checkCondition($field, $name='', $value = '')\r
131         {\r
132                 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;\r
133                 \r
134                 $condition = 0;\r
135                 switch ( $field )\r
136                 {\r
137                         case 'category':\r
138                                 $condition = ($blog && $this->ifCategory($name,$value));\r
139                                 break;\r
140                         case 'blogsetting':\r
141                                 $condition = ($blog && ($blog->getSetting($name) == $value));\r
142                                 break;\r
143                         case 'loggedin':\r
144                                 $condition = $member->isLoggedIn();\r
145                                 break;\r
146                         case 'onteam':\r
147                                 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);\r
148                                 break;\r
149                         case 'admin':
150                                 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
151                                 break;
152                         case 'nextitem':\r
153                                 $condition = ($itemidnext != '');\r
154                                 break;\r
155                         case 'previtem':\r
156                                 $condition = ($itemidprev != '');\r
157                                 break;\r
158                         case 'archiveprevexists':\r
159                                 $condition = ($archiveprevexists == true);\r
160                                 break;\r
161                         case 'archivenextexists':\r
162                                 $condition = ($archivenextexists == true);\r
163                                 break;\r
164                         case 'skintype':\r
165                                 $condition = (($name == $this->skintype) || ($name == requestVar('action')));\r
166                                 break;\r
167                         case 'hasplugin':\r
168                                 $condition = $this->ifHasPlugin($name, $value);\r
169                                 break;\r
170                         default:\r
171                                 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);\r
172                                 break;\r
173                 }\r
174                 return $condition;\r
175         }\r
176         \r
177         /**\r
178          * Actions::_ifHasPlugin()\r
179          *      hasplugin,PlugName\r
180          *         -> checks if plugin exists\r
181          *      hasplugin,PlugName,OptionName\r
182          *         -> checks if the option OptionName from plugin PlugName is not set to 'no'\r
183          *      hasplugin,PlugName,OptionName=value\r
184          *         -> checks if the option OptionName from plugin PlugName is set to value\r
185          *\r
186          * @param       string  $name   name of plugin\r
187          * @param       string  $value  \r
188          * @return      \r
189          */\r
190         private function ifHasPlugin($name, $value)\r
191         {\r
192                 global $manager;\r
193                 $condition = false;\r
194                 // (pluginInstalled method won't write a message in the actionlog on failure)\r
195                 if ( $manager->pluginInstalled("NP_{$name}") )\r
196                 {\r
197                         $plugin =& $manager->getPlugin("NP_{$name}");\r
198                         if ( $plugin != NULL )\r
199                         {\r
200                                 if ( $value == "" )\r
201                                 {\r
202                                         $condition = true;\r
203                                 }\r
204                                 else\r
205                                 {\r
206                                         list($name2, $value2) = preg_split('#=#', $value, 2);\r
207                                         if ( $value2 == "" && $plugin->getOption($name2) != 'no' )\r
208                                         {\r
209                                                 $condition = true;\r
210                                         }\r
211                                         else if ( $plugin->getOption($name2) == $value2 )\r
212                                         {\r
213                                                 $condition = true;\r
214                                         }\r
215                                 }\r
216                         }\r
217                 }\r
218                 return $condition;\r
219         }\r
220         \r
221         /**\r
222          * Actions::ifPlugin()\r
223          * Checks if a plugin exists and call its doIf function\r
224          * \r
225          * @param       string  $name   name of plugin\r
226          * @param       string  $key    name of plugin option\r
227          * @param       string  $value  value of plugin option\r
228          * @return      void\r
229          */\r
230         private function ifPlugin($name, $key = '', $value = '')\r
231         {\r
232                 global $manager;\r
233                 \r
234                 $plugin =& $manager->getPlugin("NP_{$name}");\r
235                 if ( !$plugin )\r
236                 {\r
237                         return;\r
238                 }\r
239                 \r
240                 $params = func_get_args();\r
241                 array_shift($params);\r
242                 \r
243                 return call_user_func_array(array(&$plugin, 'doIf'), $params);\r
244         }\r
245         \r
246         /**\r
247          * Actions::ifCategory()\r
248          * Different checks for a category\r
249          * \r
250          * @param       string  $name   \r
251          * @param       string  $value  \r
252          * @return      boolean \r
253          */\r
254         private function ifCategory($name = '', $value='')\r
255         {\r
256                 global $blog, $catid;\r
257                 \r
258                 // when no parameter is defined, just check if a category is selected\r
259                 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )\r
260                 {\r
261                         return $blog->isValidCategory($catid);\r
262                 }\r
263                 \r
264                 // check category name\r
265                 if ( $name == 'catname' )\r
266                 {\r
267                         $value = $blog->getCategoryIdFromName($value);\r
268                         if ( $value == $catid )\r
269                         {\r
270                                 return $blog->isValidCategory($catid);\r
271                         }\r
272                 }\r
273                 \r
274                 // check category id\r
275                 if ( ($name == 'catid') && ($value == $catid) )\r
276                 {\r
277                         return $blog->isValidCategory($catid);\r
278                 }\r
279                 return FALSE;\r
280         }\r
281         \r
282         /**\r
283          * Actions::ifOnTeam()\r
284          * Checks if a member is on the team of a blog and return his rights\r
285          * \r
286          * @param       string  $blogName       name of weblog\r
287          * @return      mixed\r
288          */\r
289         private function ifOnTeam($blogName = '')\r
290         {\r
291                 global $blog, $member, $manager;\r
292                 \r
293                 // when no blog found\r
294                 if ( ($blogName == '') && !is_object($blog) )\r
295                 {\r
296                         return 0;\r
297                 }\r
298                 \r
299                 // explicit blog selection\r
300                 if ( $blogName != '' )\r
301                 {\r
302                         $blogid = getBlogIDFromName($blogName);\r
303                 }\r
304                 \r
305                 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )\r
306                 {\r
307                         // use current blog\r
308                         $blogid = $blog->getID();\r
309                 }\r
310                 \r
311                 return $member->teamRights($blogid);\r
312         }\r
313 \r
314         /**\r
315          * Actions::ifAdmin()\r
316          * Checks if a member is admin of a blog\r
317          * \r
318          * @param       string  $blogName       name of weblog\r
319          * @return      mixed\r
320          */\r
321         private function ifAdmin($blogName = '')\r
322         {\r
323                 global $blog, $member, $manager;\r
324                 \r
325                 // when no blog found\r
326                 if ( ($blogName == '') && (!is_object($blog)) )\r
327                 {\r
328                         return 0;\r
329                 }\r
330                 \r
331                 // explicit blog selection\r
332                 if ( $blogName != '' )\r
333                 {\r
334                         $blogid = getBlogIDFromName($blogName);\r
335                 }\r
336                 \r
337                 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )\r
338                 {\r
339                         // use current blog\r
340                         $blogid = $blog->getID();\r
341                 }\r
342                 \r
343                 return $member->isBlogAdmin($blogid);\r
344         }\r
345         \r
346         /**\r
347          * Actions::link()\r
348          * returns either\r
349          *      - a raw link (html/xml encoded) when no linktext is provided\r
350          *      - a (x)html <a href... link when a text is present (text htmlencoded)\r
351          * \r
352          * @param       string  $url            URL for href attribute of anchor element\r
353          * @param       string  $linktext       content of anchor element\r
354          * @return      \r
355          */\r
356         private function link($url, $linktext = '')\r
357         {\r
358                 $u = Entity::hsc($url);\r
359                 // fix URLs that already had encoded ampersands\r
360                 $u = preg_replace("#&amp;amp;#", '&amp;', $u);\r
361                 if ( $linktext != '' )\r
362                 {\r
363                         $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';\r
364                 }\r
365                 else\r
366                 {\r
367                         $l = $u;\r
368                 }\r
369                 return $l;\r
370         }\r
371         \r
372         /**\r
373          * Actions::searchlink()\r
374          * Outputs a next/prev link\r
375          *\r
376          * @param $maxresults\r
377          *              The maximum amount of items shown per page (e.g. 10)\r
378          * @param $startpos\r
379          *              Current start position (requestVar('startpos'))\r
380          * @param $direction\r
381          *              either 'prev' or 'next'\r
382          * @param $linktext\r
383          *              When present, the output will be a full <a href...> link. When empty,\r
384          *              only a raw link will be outputted\r
385          */\r
386         private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')\r
387         {\r
388                 global $CONF, $blog, $query, $amount;\r
389                 // TODO: Move request uri to linkparams. this is ugly. sorry for that.\r
390                 $startpos       = (integer) $startpos;\r
391                 $parsed         = parse_url(serverVar('REQUEST_URI'));\r
392                 $path           = $parsed['path'];\r
393                 $parsed         = $parsed['query'];\r
394                 $url            = '';\r
395                 \r
396                 if ( $direction == 'prev' )\r
397                 {\r
398                         if ( intval($startpos) - intval($maxresults) >= 0 )\r
399                         {\r
400                                 $startpos       = intval($startpos) - intval($maxresults);\r
401                                 \r
402                                 if ( $this->skintype == 'index' )\r
403                                 {\r
404                                         $url = $path;\r
405                                 }\r
406                                 else if ( $this->skintype == 'search' )\r
407                                 {\r
408                                         $url = $CONF['SearchURL'];\r
409                                 }\r
410                                 $url .= '?' . alterQueryStr($parsed,'startpos',$startpos);\r
411                         }\r
412                 }\r
413                 else if ( $direction == 'next' )\r
414                 {\r
415                         global $navigationItems;\r
416                         if ( !isset($navigationItems) )\r
417                         {\r
418                                 $navigationItems = 0;\r
419                         }\r
420                         \r
421                         if ( $recount )\r
422                         {\r
423                                 $iAmountOnPage = 0;\r
424                         }\r
425                         else \r
426                         {\r
427                                 $iAmountOnPage = $this->amountfound;\r
428                         }\r
429                         \r
430                         if ( intval($navigationItems) > 0 )\r
431                         {\r
432                                 $iAmountOnPage = intval($navigationItems) - intval($startpos);\r
433                         }\r
434                         elseif ( $iAmountOnPage == 0 )\r
435                         {\r
436                                 /*\r
437                                  * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]\r
438                                  * try a count query\r
439                                  */\r
440                                 if ( $this->skintype == 'index' )\r
441                                 {\r
442                                         $sqlquery = $blog->getSqlBlog('', 'count');\r
443                                         $url = $path;\r
444                                 }\r
445                                 else if ( $this->skintype == 'search' )\r
446                                 {\r
447                                         $unused_highlight = '';\r
448                                         $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');\r
449                                         $url = $CONF['SearchURL'];\r
450                                 }\r
451                                 if ( $sqlquery )\r
452                                 {\r
453                                         $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);\r
454                                 }\r
455                         }\r
456                         \r
457                         $url = '';\r
458                         if ( intval($iAmountOnPage) >= intval($maxresults) )\r
459                         {\r
460                                 $startpos        = intval($startpos) + intval($maxresults);\r
461                                 $url            .= '?' . alterQueryStr($parsed, 'startpos', $startpos);\r
462                         }\r
463                 }\r
464                 \r
465                 if ( $url != '' )\r
466                 {\r
467                         echo $this->link($url, $linktext);\r
468                 }\r
469                 return;\r
470         }\r
471         \r
472         /**\r
473          * Actions::itemlink()\r
474          * Creates an item link and if no id is given a todaylink \r
475          * \r
476          * @param       integer $id     id for link\r
477          * @param       string  $linktext       text for link\r
478          * @return      void\r
479          */\r
480         private function itemlink($id, $linktext = '')\r
481         {\r
482                 global $CONF;\r
483                 if ( $id != 0 )\r
484                 {\r
485                         echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);\r
486                 }\r
487                 else\r
488                 {\r
489                         $this->parse_todaylink($linktext);\r
490                 }\r
491                 return;\r
492         }\r
493         \r
494         /**\r
495          * Actions::archivelink)\r
496          * Creates an archive link and if no id is given a todaylink \r
497          * \r
498          * @param       integer $id     id for link\r
499          * @param       string  $linktext       text for link\r
500          * @return      void\r
501          */\r
502         private function archivelink($id, $linktext = '')\r
503         {\r
504                 global $CONF, $blog;\r
505                 if ( $id != 0 )\r
506                 {\r
507                         echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);\r
508                 }\r
509                 else\r
510                 {\r
511                         $this->parse_todaylink($linktext);\r
512                 }\r
513                 return;\r
514         }\r
515         \r
516         /**\r
517          * Actions:setBlogCategory()\r
518          * Helper function that sets the category that a blog will need to use\r
519          *\r
520          * @param       string  $blog           An object of the blog class, passed by reference (we want to make changes to it)\r
521          * @param       string  $catname        The name of the category to use\r
522          * @return      void\r
523          */\r
524         private function setBlogCategory(&$blog, $catname)\r
525         {\r
526                 global $catid;\r
527                 if ( $catname != '' )\r
528                 {\r
529                         $blog->setSelectedCategoryByName($catname);\r
530                 }\r
531                 else\r
532                 {\r
533                         $blog->setSelectedCategory($catid);\r
534                 }\r
535                 return;\r
536         }\r
537         \r
538         /**\r
539          * Actions::preBlogContent()\r
540          * Notifies the Manager that a PreBlogContent event occurs\r
541          * \r
542          * @param       string  $type   type of skin\r
543          * @param       object  $blog   an instance of Blog class\r
544          * @return      void\r
545          */\r
546         private function preBlogContent($type, &$blog)\r
547         {\r
548                 global $manager;\r
549                 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));\r
550                 return;\r
551         }\r
552 \r
553         /**\r
554          * Actions::postBlogContent()\r
555          * Notifies the Manager that a PostBlogContent event occurs\r
556          * \r
557          * @param       string  $type   type of skin\r
558          * @param       objecct $blog   an instance of Blog class\r
559          * @return      void\r
560          */\r
561         private function postBlogContent($type, &$blog)\r
562         {\r
563                 global $manager;\r
564                 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));\r
565                 return;\r
566         }\r
567         \r
568         /**\r
569          * Actions::parse_additemform()\r
570          * Parse skinvar additemform\r
571          * \r
572          * @param       void\r
573          * @return      void\r
574          */\r
575         public function parse_additemform()\r
576         {\r
577                 global $blog, $CONF;\r
578                 $this->formdata = array(\r
579                         'adminurl'      => Entity::hsc($CONF['AdminURL']),\r
580                         'catid'         => $blog->getDefaultCategory()\r
581                 );\r
582                 $blog->InsertJavaScriptInfo();\r
583                 $this->doForm('additemform');\r
584                 return;\r
585         }\r
586         \r
587         /**\r
588          * Actions::parse_addlink()\r
589          * Parse skinvar addlink\r
590          * A Link that allows to open a bookmarklet to add an item\r
591          */\r
592         public function parse_addlink()\r
593         {\r
594                 global $CONF, $member, $blog;\r
595                 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )\r
596                 {\r
597                         echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;\r
598                 }\r
599                 return;\r
600         }\r
601         \r
602         /**\r
603          * Actions::parse_addpopupcode()\r
604          * Parse skinvar addpopupcode\r
605          * Code that opens a bookmarklet in an popup window\r
606          * \r
607          * @param       void\r
608          * @return      void\r
609          */\r
610         public function parse_addpopupcode()\r
611         {\r
612                 echo "if (event &amp;&amp; event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=yes,width=600,height=500,left=10,top=10,status=yes,resizable=yes');winbm.focus();return false;";\r
613                 return;\r
614         }\r
615         \r
616         /**\r
617          * Parse skinvar adminurl\r
618          * (shortcut for admin url)\r
619          * \r
620          * @param       void\r
621          * @return      void\r
622          */\r
623         public function parse_adminurl()\r
624         {\r
625                 $this->parse_sitevar('adminurl');\r
626                 return;\r
627         }\r
628         \r
629         /**\r
630          * Actions::parse_archive()\r
631          * Parse skinvar archive\r
632          * \r
633          * @param       string  $template       name of template\r
634          * @param       string  $category       name of category\r
635          * @return      \r
636          */\r
637         public function parse_archive($template, $category = '')\r
638         {\r
639                 global $blog, $archive;\r
640                 // can be used with either yyyy-mm or yyyy-mm-dd\r
641                 sscanf($archive,'%d-%d-%d', $y, $m, $d);\r
642                 $this->setBlogCategory($blog, $category);\r
643                 $this->preBlogContent('achive',$blog);\r
644                 $blog->showArchive($template, $y, $m, $d);\r
645                 $this->postBlogContent('achive',$blog);\r
646                 return;\r
647         }\r
648         \r
649         /**\r
650          * Actions::parse_archivedate()\r
651          * %archivedate(locale,date format)%\r
652          * \r
653          * @param       string  $locale\r
654          * @return      void\r
655          */\r
656         public function parse_archivedate($locale = '-def-')\r
657         {\r
658                 global $archive;\r
659                 \r
660                 /* \r
661                  * TODO: these lines are no meaning because there is no $template.\r
662                 if ( $locale == '-def-' )\r
663                 {\r
664                         setlocale(LC_TIME, $template['LOCALE']);\r
665                 }\r
666                 else\r
667                 {\r
668                         setlocale(LC_TIME, $locale);\r
669                 }\r
670                  */\r
671                 \r
672                 // get archive date\r
673                 sscanf($archive,'%d-%d-%d',$y,$m,$d);\r
674                 \r
675                 // get format\r
676                 $args = func_get_args();\r
677                 // format can be spread over multiple parameters\r
678                 if ( sizeof($args) > 1 )\r
679                 {\r
680                         // take away locale\r
681                         array_shift($args);\r
682                         // implode\r
683                         $format=implode(',',$args);\r
684                 }\r
685                 elseif ( $d == 0 && $m !=0 )\r
686                 {\r
687                         $format = '%B %Y';\r
688                 }\r
689                 elseif ( $m == 0 )\r
690                 {\r
691                         $format = '%Y';\r
692                 }\r
693                 else\r
694                 {\r
695                         $format = '%d %B %Y';\r
696                 }\r
697                 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));\r
698                 return;\r
699         }\r
700         \r
701         /**\r
702          * Actions::parse_archivedaylist()\r
703          * Parse skinvar archivedaylist\r
704          * \r
705          * @param       string  $template       name of template\r
706          * @param       string  $category       name of category\r
707          * @param       integer $limit          the number of items in a display\r
708          * @return      void\r
709          */\r
710         public function parse_archivedaylist($template, $category = 'all', $limit = 0)\r
711         {\r
712                 global $blog;\r
713                 if ( $category == 'all' )\r
714                 {\r
715                         $category = '';\r
716                 }\r
717                 $this->preBlogContent('archivelist',$blog);\r
718                 $this->setBlogCategory($blog, $category);\r
719                 $blog->showArchiveList($template, 'day', $limit);\r
720                 $this->postBlogContent('archivelist',$blog);\r
721                 return;\r
722         }\r
723         \r
724         /**\r
725          * Actions::parse_archivelink()\r
726          * A link to the archives for the current blog (or for default blog)\r
727          * \r
728          * @param       string  $linktext       text for link\r
729          * @return      void\r
730          */\r
731         public function parse_archivelink($linktext = '')\r
732         {\r
733                 global $blog, $CONF;\r
734                 if ( $blog )\r
735                 {\r
736                         echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);\r
737                 }\r
738                 else\r
739                 {\r
740                         echo $this->link(Link::create_archivelist_link(), $linktext);\r
741                 }\r
742                 return;\r
743         }\r
744         \r
745         /**\r
746          * Actions::parse_archivelist()\r
747          * \r
748          * @param       string  $template       name of template\r
749          * @param       string  $category       name of category\r
750          * @param       integer $limit          the number of items in a display\r
751          * @return      void\r
752          */\r
753         public function parse_archivelist($template, $category = 'all', $limit = 0)\r
754         {\r
755                 global $blog;\r
756                 if ( $category == 'all' )\r
757                 {\r
758                         $category = '';\r
759                 }\r
760                 $this->preBlogContent('archivelist',$blog);\r
761                 $this->setBlogCategory($blog, $category);\r
762                 $blog->showArchiveList($template, 'month', $limit);\r
763                 $this->postBlogContent('archivelist',$blog);\r
764                 return;\r
765         }\r
766         \r
767         /**\r
768          * Actions::parse_archiveyearlist()\r
769          * \r
770          * @param       string  $template       name of template\r
771          * @param       string  $category       name of category\r
772          * @param       integer $limit          the number of items in a display\r
773          */\r
774         public function parse_archiveyearlist($template, $category = 'all', $limit = 0)\r
775         {\r
776                 global $blog;\r
777                 if ( $category == 'all' )\r
778                 {\r
779                         $category = '';\r
780                 }\r
781                 $this->preBlogContent('archivelist',$blog);\r
782                 $this->setBlogCategory($blog, $category);\r
783                 $blog->showArchiveList($template, 'year', $limit);\r
784                 $this->postBlogContent('archivelist',$blog);\r
785                 return;\r
786         }\r
787         \r
788         /**\r
789          * Actions::parse_archivetype()\r
790          * Parse skinvar archivetype\r
791          * \r
792          * @param       void\r
793          * @return      void\r
794          */\r
795         public function parse_archivetype()\r
796         {\r
797                 global $archivetype;\r
798                 echo $archivetype;\r
799                 return;\r
800         }\r
801         \r
802         /**\r
803          * Actions::parse_blog()\r
804          * Parse skinvar blog\r
805          * \r
806          * @param       string  $template       name of template\r
807          * @param       mixed   $amount         the number of items in a display, in case it includes the beginning\r
808          * @param       string  $category       name of category\r
809          * @return      void\r
810          */\r
811         public function parse_blog($template, $amount = 10, $category = '')\r
812         {\r
813                 global $blog, $startpos;\r
814                 \r
815                 list($limit, $offset) = sscanf($amount, '%d(%d)');\r
816                 $this->setBlogCategory($blog, $category);\r
817                 $this->preBlogContent('blog',$blog);\r
818                 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);\r
819                 $this->postBlogContent('blog',$blog);\r
820                 return;\r
821         }\r
822         \r
823         /**\r
824          * Actions::parse_bloglist()\r
825          * Parse skinvar bloglist\r
826          * Shows a list of all blogs\r
827          * \r
828          * @param       string  $template       name of template\r
829          * @param       string  $bnametype      whether 'name' or 'shortname' is used for the link text\r
830          * @param       string  $orderby        order criteria\r
831          * @param       string  $direction      order ascending or descending             \r
832          * @return      void\r
833          */\r
834         public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')\r
835         {\r
836                 Blog::showBlogList($template, $bnametype, $orderby, $direction);\r
837                 return;\r
838         }\r
839         \r
840         /**\r
841          * Actions::parse_blogsetting()\r
842          * Parse skinvar blogsetting\r
843          * \r
844          * @param       string  $which  key of weblog settings\r
845          * @return      void\r
846          */\r
847         public function parse_blogsetting($which)\r
848         {\r
849                 global $blog;\r
850                 switch( $which )\r
851                 {\r
852                         case 'id':\r
853                                 echo Entity::hsc($blog->getID());\r
854                                 break;\r
855                         case 'url':\r
856                                 echo Entity::hsc($blog->getURL());\r
857                                 break;\r
858                         case 'name':\r
859                                 echo Entity::hsc($blog->getName());\r
860                                 break;\r
861                         case 'desc':\r
862                                 echo Entity::hsc($blog->getDescription());\r
863                                 break;\r
864                         case 'short':\r
865                                 echo Entity::hsc($blog->getShortName());\r
866                                 break;\r
867                 }\r
868                 return;\r
869         }\r
870         \r
871         /**\r
872          * Actions::parse_callback()\r
873          * Parse callback\r
874          * \r
875          * @param       string  $eventName      name of event\r
876          * @param       string  $type   type of skin\r
877          * @return      void\r
878          */\r
879         public function parse_callback($eventName, $type)\r
880         {\r
881                 global $manager;\r
882                 $manager->notify($eventName, array('type' => $type));\r
883                 return;\r
884         }\r
885         \r
886         /**\r
887          * Actions::parse_category()\r
888          * Parse skinvar category\r
889          * \r
890          * @param       string  $type   key of category settings\r
891          * @return      void\r
892          */\r
893         public function parse_category($type = 'name')\r
894         {\r
895                 global $catid, $blog;\r
896                 if ( !$blog->isValidCategory($catid) )\r
897                 {\r
898                         return;\r
899                 }\r
900                 \r
901                 switch ( $type )\r
902                 {\r
903                         case 'name':\r
904                                 echo $blog->getCategoryName($catid);\r
905                                 break;\r
906                         case 'desc':\r
907                                 echo $blog->getCategoryDesc($catid);\r
908                                 break;\r
909                         case 'id':\r
910                                 echo $catid;\r
911                                 break;\r
912                 }\r
913                 return;\r
914         }\r
915         \r
916         /**\r
917          * Actions::parse_categorylist()\r
918          * Parse categorylist\r
919          * \r
920          * @param       string  $template       name of template\r
921          * @param       string  $blogname       name of weblog\r
922          * @return      void\r
923          */\r
924         public function parse_categorylist($template, $blogname = '')\r
925         {\r
926                 global $blog, $manager;\r
927                 \r
928                 // when no blog found\r
929                 if ( ($blogname == '') && (!is_object($blog)) )\r
930                 {\r
931                         return 0;\r
932                 }\r
933                         \r
934                 if ( $blogname == '' )\r
935                 {\r
936                         $this->preBlogContent('categorylist',$blog);\r
937                         $blog->showCategoryList($template);\r
938                         $this->postBlogContent('categorylist',$blog);\r
939                 }\r
940                 else\r
941                 {\r
942                         $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
943                         $this->preBlogContent('categorylist',$b);\r
944                         $b->showCategoryList($template);\r
945                         $this->postBlogContent('categorylist',$b);\r
946                 }\r
947                 return;\r
948         }\r
949         \r
950         /**\r
951          * Actions::parse_charset()\r
952          * Parse skinvar charset\r
953          * \r
954          * @param       void\r
955          * @return      void\r
956          */\r
957         public function parse_charset()\r
958         {\r
959                 echo i18n::get_current_charset();\r
960                 return;\r
961         }\r
962         \r
963         /**\r
964          * Actions::parse_commentform()\r
965          * Parse skinvar commentform\r
966          * \r
967          * @param       string  $destinationurl URI for redirection\r
968          * @return      void\r
969          */\r
970         public function parse_commentform($destinationurl = '')\r
971         {\r
972                 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;\r
973                 \r
974                 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)\r
975                 if ( stristr($destinationurl, 'action.php') )\r
976                 {\r
977                         $args = func_get_args();\r
978                         $destinationurl = $args[1];\r
979                         ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);\r
980                 }\r
981                 \r
982                 $actionurl = $CONF['ActionURL'];\r
983                 \r
984                 // if item is closed, show message and do nothing\r
985                 $item =& $manager->getItem($itemid,0,0);\r
986                 if ( $item['closed'] || !$blog->commentsEnabled() )\r
987                 {\r
988                         $this->doForm('commentform-closed');\r
989                         return;\r
990                 }\r
991                 \r
992                 if ( !$blog->isPublic() && !$member->isLoggedIn() )\r
993                 {\r
994                         $this->doForm('commentform-closedtopublic');\r
995                         return;\r
996                 }\r
997                 \r
998                 if ( !$destinationurl )\r
999                 {\r
1000                         // note: createLink returns an HTML encoded URL\r
1001                         $destinationurl = Link::create_link(\r
1002                                 'item',\r
1003                                 array(\r
1004                                         'itemid' => $itemid,\r
1005                                         'title' => $item['title'],\r
1006                                         'timestamp' => $item['timestamp'],\r
1007                                         'extra' => $this->linkparams\r
1008                                 )\r
1009                         );\r
1010                 }\r
1011                 else\r
1012                 {\r
1013                         // HTML encode URL\r
1014                         $destinationurl = Entity::hsc($destinationurl);\r
1015                 }\r
1016                 \r
1017                 // values to prefill\r
1018                 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');\r
1019                 if ( !$user )\r
1020                 {\r
1021                         $user = postVar('user');\r
1022                 }\r
1023                 \r
1024                 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');\r
1025                 if ( !$userid )\r
1026                 {\r
1027                         $userid = postVar('userid');\r
1028                 }\r
1029                 \r
1030                 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');\r
1031                 if (!$email)\r
1032                 {\r
1033                         $email = postVar('email');\r
1034                 }\r
1035                 \r
1036                 $body = postVar('body');\r
1037                 \r
1038                 $this->formdata = array(\r
1039                         'destinationurl' => $destinationurl,    // url is already HTML encoded\r
1040                         'actionurl' => Entity::hsc($actionurl),\r
1041                         'itemid' => $itemid,\r
1042                         'user' => Entity::hsc($user),\r
1043                         'userid' => Entity::hsc($userid),\r
1044                         'email' => Entity::hsc($email),\r
1045                         'body' => Entity::hsc($body),\r
1046                         'membername' => $member->getDisplayName(),\r
1047                         'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''\r
1048                 );\r
1049                 \r
1050                 if ( !$member->isLoggedIn() )\r
1051                 {\r
1052                         $this->doForm('commentform-notloggedin');\r
1053                 }\r
1054                 else\r
1055                 {\r
1056                         $this->doForm('commentform-loggedin');\r
1057                 }\r
1058                 return;\r
1059         }\r
1060         \r
1061         /**\r
1062          * Actions::parse_comments()\r
1063          * Parse skinvar comments\r
1064          * include comments for one item\r
1065          * \r
1066          * @param       string  $template       name of template\r
1067          * @return      void\r
1068          */\r
1069         public function parse_comments($template)\r
1070         {\r
1071                 global $itemid, $manager, $blog, $highlight;\r
1072                 $template =& $manager->getTemplate($template);\r
1073                 \r
1074                 // create parser object & action handler\r
1075                 $actions = new ItemActions($blog);\r
1076                 $parser = new Parser($actions->getDefinedActions(),$actions);\r
1077                 $actions->setTemplate($template);\r
1078                 $actions->setParser($parser);\r
1079                 $item = Item::getitem($itemid, 0, 0);\r
1080                 $actions->setCurrentItem($item);\r
1081                 \r
1082                 $comments = new Comments($itemid);\r
1083                 $comments->setItemActions($actions);\r
1084                 // shows ALL comments\r
1085                 $comments->showComments($template, -1, 1, $highlight);\r
1086                 return;\r
1087         }\r
1088         \r
1089         /**\r
1090          * Actions::parse_errordiv()\r
1091          * Parse errordiv\r
1092          * \r
1093          * @param       void\r
1094          * @return      void\r
1095          */\r
1096         public function parse_errordiv()\r
1097         {\r
1098                 global $errormessage;\r
1099                 if ( $errormessage )\r
1100                 {\r
1101                         echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";\r
1102                 }\r
1103                 return;\r
1104         }\r
1105         \r
1106         /**\r
1107          * Actions::parse_errormessage()\r
1108          * Parse skinvar errormessage\r
1109          * \r
1110          * @param       void\r
1111          * @return      void\r
1112          */\r
1113         public function parse_errormessage()\r
1114         {\r
1115                 global $errormessage;\r
1116                 echo $errormessage;\r
1117                 return;\r
1118         }\r
1119         \r
1120         /**\r
1121          * Actions::parse_formdata()\r
1122          * Parse formdata\r
1123          * \r
1124          * @param       string  $what   key of format data\r
1125          * @return      void\r
1126          */\r
1127         public function parse_formdata($what)\r
1128         {\r
1129                 echo $this->formdata[$what];\r
1130                 return;\r
1131         }\r
1132         \r
1133         /**\r
1134          * Actions::parse_ifcat()\r
1135          * Parse ifcat\r
1136          * \r
1137          * @param       string  $text\r
1138          * @return      void\r
1139          */\r
1140         public function parse_ifcat($text = '')\r
1141         {\r
1142                 if ( $text == '' )\r
1143                 {\r
1144                         // new behaviour\r
1145                         $this->parse_if('category');\r
1146                 }\r
1147                 else\r
1148                 {\r
1149                         // old behaviour\r
1150                         global $catid, $blog;\r
1151                         if ( $blog->isValidCategory($catid) )\r
1152                         {\r
1153                                 echo $text;\r
1154                         }\r
1155                 }\r
1156                 return;\r
1157         }\r
1158         \r
1159         /**\r
1160          * Actions::parse_image()\r
1161          * Parse skinvar image\r
1162          * \r
1163          * @param       string  $what   name of tag\r
1164          * @return      void\r
1165          */\r
1166         public function parse_image($what = 'imgtag')\r
1167         {\r
1168                 global $CONF;\r
1169                 \r
1170                 $imagetext      = Entity::hsc(requestVar('imagetext'));\r
1171                 $imagepopup = requestVar('imagepopup');\r
1172                 $width          = intRequestVar('width');\r
1173                 $height         = intRequestVar('height');\r
1174                 $fullurl        = Entity::hsc($CONF['MediaURL'] . $imagepopup);\r
1175                 \r
1176                 switch ( $what )\r
1177                 {\r
1178                         case 'url':\r
1179                                 echo $fullurl;\r
1180                                 break;\r
1181                         case 'width':\r
1182                                 echo $width;\r
1183                                 break;\r
1184                         case 'height':\r
1185                                 echo $height;\r
1186                                 break;\r
1187                         case 'caption':\r
1188                         case 'text':\r
1189                                 echo $imagetext;\r
1190                                 break;\r
1191                         case 'imgtag':\r
1192                         default:\r
1193                                 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";\r
1194                                 break;\r
1195                 }\r
1196                 return;\r
1197         }\r
1198         \r
1199         /**\r
1200          * Actions::parse_imagetext()\r
1201          * Parse skinvar imagetext\r
1202          * \r
1203          * @param       void\r
1204          * @return      void\r
1205          */\r
1206         public function parse_imagetext()\r
1207         {\r
1208                 $this->parse_image('imagetext');\r
1209                 return;\r
1210         }\r
1211 \r
1212         /**\r
1213          * Actions::parse_item()\r
1214          * Parse skinvar item\r
1215          * include one item (no comments)\r
1216          * \r
1217          * @param       void\r
1218          * @return      void\r
1219          */\r
1220         public function parse_item($template)\r
1221         {\r
1222                 global $blog, $itemid, $highlight;\r
1223                 \r
1224                 // need this to select default category\r
1225                 $this->setBlogCategory($blog, '');\r
1226                 $this->preBlogContent('item',$blog);\r
1227                 $r = $blog->showOneitem($itemid, $template, $highlight);\r
1228                 if ( $r == 0 )\r
1229                 {\r
1230                         echo _ERROR_NOSUCHITEM;\r
1231                 }\r
1232                 $this->postBlogContent('item',$blog);\r
1233                 return;\r
1234         }\r
1235 \r
1236         /**\r
1237          * Actions::parse_itemid()\r
1238          * Parse skinvar itemid\r
1239          * \r
1240          * @param       void\r
1241          * @return      void\r
1242          */\r
1243         public function parse_itemid()\r
1244         {\r
1245                 global $itemid;\r
1246                 echo $itemid;\r
1247                 return;\r
1248         }\r
1249         \r
1250         /**\r
1251          * Actions::parseitemlink()\r
1252          * Parse skinvar itemlink\r
1253          * \r
1254          * @param       void\r
1255          * @return      void\r
1256          */\r
1257         public function parse_itemlink($linktext = '')\r
1258         {\r
1259                 global $itemid;\r
1260                 $this->itemlink($itemid, $linktext);\r
1261                 return;\r
1262         }\r
1263         \r
1264         /**\r
1265          * Actions::parse_itemtitle()\r
1266          * Parse itemtitle\r
1267          * \r
1268          * @param       void\r
1269          * @return      void\r
1270          */\r
1271         public function parse_itemtitle($format = '')\r
1272         {\r
1273                 global $manager, $itemid;\r
1274                 $item =& $manager->getItem($itemid,0,0);\r
1275                 \r
1276                 switch ( $format )\r
1277                 {\r
1278                         case 'xml':\r
1279                                 echo Entity::hen($item['title']);\r
1280                                 break;\r
1281                         case 'raw':\r
1282                                 echo $item['title'];\r
1283                                 break;\r
1284                         case 'attribute':\r
1285                         default:\r
1286                                 echo Entity::hsc(strip_tags($item['title']));\r
1287                                 break;\r
1288                 }\r
1289                 return;\r
1290         }\r
1291         \r
1292         /**\r
1293          * Actions::parse_loginform()\r
1294          * Parse skinvar loginform\r
1295          * \r
1296          * @param       void\r
1297          * @return      void\r
1298          */\r
1299         public function parse_loginform()\r
1300         {\r
1301                 global $member, $CONF;\r
1302                 if ( !$member->isLoggedIn() )\r
1303                 {\r
1304                         $filename = 'loginform-notloggedin';\r
1305                         $this->formdata = array();\r
1306                 }\r
1307                 else\r
1308                 {\r
1309                         $filename = 'loginform-loggedin';\r
1310                         $this->formdata = array(\r
1311                                 'membername' => $member->getDisplayName(),\r
1312                         );\r
1313                 }\r
1314                 $this->doForm($filename);\r
1315                 return;\r
1316         }\r
1317         \r
1318         /**\r
1319          * Actions::parse_member()\r
1320          * Parse skinvar member\r
1321          * (includes a member info thingie)\r
1322          * \r
1323          * @param       string  $what   which memberdata is needed\r
1324          * @return      void\r
1325          */\r
1326         public function parse_member($what)\r
1327         {\r
1328                 global $memberinfo, $member, $CONF;\r
1329                 \r
1330                 // 1. only allow the member-details-page specific variables on member pages\r
1331                 if ( $this->skintype == 'member' )\r
1332                 {\r
1333                         switch( $what )\r
1334                         {\r
1335                                 case 'name':\r
1336                                         echo Entity::hsc($memberinfo->getDisplayName());\r
1337                                         break;\r
1338                                 case 'realname':\r
1339                                         echo Entity::hsc($memberinfo->getRealName());\r
1340                                         break;\r
1341                                 case 'notes':\r
1342                                         echo Entity::hsc($memberinfo->getNotes());\r
1343                                         break;\r
1344                                 case 'url':\r
1345                                         echo Entity::hsc($memberinfo->getURL());\r
1346                                         break;\r
1347                                 case 'email':\r
1348                                         echo Entity::hsc($memberinfo->getEmail());\r
1349                                         break;\r
1350                                 case 'id':\r
1351                                         echo Entity::hsc($memberinfo->getID());\r
1352                                         break;\r
1353                         }\r
1354                 }\r
1355                 \r
1356                 // 2. the next bunch of options is available everywhere, as long as the user is logged in\r
1357                 if ( $member->isLoggedIn() )\r
1358                 {\r
1359                         switch( $what )\r
1360                         {\r
1361                                 case 'yourname':\r
1362                                         echo $member->getDisplayName();\r
1363                                         break;\r
1364                                 case 'yourrealname':\r
1365                                         echo $member->getRealName();\r
1366                                         break;\r
1367                                 case 'yournotes':\r
1368                                         echo $member->getNotes();\r
1369                                         break;\r
1370                                 case 'yoururl':\r
1371                                         echo $member->getURL();\r
1372                                         break;\r
1373                                 case 'youremail':\r
1374                                         echo $member->getEmail();\r
1375                                         break;\r
1376                                 case 'yourid':\r
1377                                         echo $member->getID();\r
1378                                         break;\r
1379                                 case 'yourprofileurl':\r
1380                                         if ($CONF['URLMode'] == 'pathinfo')\r
1381                                                 echo Link::create_member_link($member->getID());\r
1382                                         else\r
1383                                                 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());\r
1384                                         break;\r
1385                         }\r
1386                 }\r
1387                 return;\r
1388         }\r
1389         \r
1390         /**\r
1391          * Link::parse_membermailform()\r
1392          * Parse skinvar membermailform\r
1393          * \r
1394          * @param       integer $rows   the height for textarea\r
1395          * @param       integer $cols   the width for textarea\r
1396          * @param       string  $desturl        URI to redirect\r
1397          * @return      void\r
1398          */\r
1399         public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')\r
1400         {\r
1401                 global $member, $CONF, $memberid;\r
1402                 \r
1403                 if ( $desturl == '' )\r
1404                 {\r
1405                         if ( $CONF['URLMode'] == 'pathinfo' )\r
1406                         {\r
1407                                 $desturl = Link::create_member_link($memberid);\r
1408                         }\r
1409                         else\r
1410                         {\r
1411                                 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);\r
1412                         }\r
1413                 }\r
1414                 \r
1415                 $message = postVar('message');\r
1416                 $frommail = postVar('frommail');\r
1417                 \r
1418                 $this->formdata = array(\r
1419                         'url' => Entity::hsc($desturl),\r
1420                         'actionurl' => Entity::hsc($CONF['ActionURL']),\r
1421                         'memberid' => $memberid,\r
1422                         'rows' => $rows,\r
1423                         'cols' => $cols,\r
1424                         'message' => Entity::hsc($message),\r
1425                         'frommail' => Entity::hsc($frommail)\r
1426                 );\r
1427                 \r
1428                 if ( $member->isLoggedIn() )\r
1429                 {\r
1430                         $this->doForm('membermailform-loggedin');\r
1431                 }\r
1432                 else if ( $CONF['NonmemberMail'] )\r
1433                 {\r
1434                         $this->doForm('membermailform-notloggedin');\r
1435                 }\r
1436                 else\r
1437                 {\r
1438                         $this->doForm('membermailform-disallowed');\r
1439                 }\r
1440                 return;\r
1441         }\r
1442         \r
1443         /**\r
1444          * Actions::parse_nextarchive()\r
1445          * Parse skinvar nextarchive\r
1446          * \r
1447          * @param       void\r
1448          * @return      void\r
1449          */\r
1450         public function parse_nextarchive()\r
1451         {\r
1452                 global $archivenext;\r
1453                 echo $archivenext;\r
1454                 return;\r
1455         }\r
1456         \r
1457         /**\r
1458          * Parse skinvar nextitem\r
1459          * (include itemid of next item)\r
1460          * \r
1461          * @param       void\r
1462          * @return      void\r
1463          */\r
1464         public function parse_nextitem()\r
1465         {\r
1466                 global $itemidnext;\r
1467                 if ( isset($itemidnext) )\r
1468                 {\r
1469                         echo (int)$itemidnext;\r
1470                 }\r
1471                 return;\r
1472         }\r
1473         \r
1474         /**\r
1475          * Actions::parse_nextitemtitle()\r
1476          * Parse skinvar nextitemtitle\r
1477          * (include itemtitle of next item)\r
1478          * \r
1479          * @param       string  $format format of text\r
1480          * @return      void\r
1481          */\r
1482         public function parse_nextitemtitle($format = '')\r
1483         {\r
1484                 global $itemtitlenext;\r
1485                 \r
1486                 switch ( $format )\r
1487                 {\r
1488                         case 'xml':\r
1489                                 echo Entity::hen($itemtitlenext);\r
1490                                 break;\r
1491                         case 'raw':\r
1492                                 echo $itemtitlenext;\r
1493                                 break;\r
1494                         case 'attribute':\r
1495                         default:\r
1496                                 echo Entity::hsc($itemtitlenext);\r
1497                                 break;\r
1498                 }\r
1499                 return;\r
1500         }\r
1501         \r
1502         /**\r
1503          * Actions::parse_nextlink()\r
1504          * Parse skinvar nextlink\r
1505          * \r
1506          * @param       string  $linktext       text for content of anchor element\r
1507          * @param       integer $amount         the amount of items in a display\r
1508          * @param       integer $recount        increment from this value\r
1509          * @return      void\r
1510          */\r
1511         public function parse_nextlink($linktext = '', $amount = 10, $recount = '')\r
1512         {\r
1513                 global $itemidnext, $archivenext, $startpos;\r
1514                 if ( $this->skintype == 'item' )\r
1515                 {\r
1516                         $this->itemlink($itemidnext, $linktext);\r
1517                 }\r
1518                 else if ( $this->skintype == 'search' || $this->skintype == 'index' )\r
1519                 {\r
1520                         $this->searchlink($amount, $startpos, 'next', $linktext, $recount);\r
1521                 }\r
1522                 else\r
1523                 {\r
1524                         $this->archivelink($archivenext, $linktext);\r
1525                 }\r
1526                 return;\r
1527         }\r
1528 \r
1529         /**\r
1530          * Actions::parse_nucleusbutton()\r
1531          * Parse skinvar nucleusbutton\r
1532          * \r
1533          * @param       string  $imgurl URL  for image\r
1534          * @param       integer $imgwidth       width of image\r
1535          * @param       integer $imgheidht      height of image\r
1536          */\r
1537         public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')\r
1538         {\r
1539                 global $CONF;\r
1540                 if ( $imgurl == '' )\r
1541                 {\r
1542                         $imgurl = $CONF['AdminURL'] . 'nucleus.gif';\r
1543                 }\r
1544                 else if ( Parser::getProperty('IncludeMode') == 'skindir' )\r
1545                 {\r
1546                         // when skindit IncludeMode is used: start from skindir\r
1547                         $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;\r
1548                 }\r
1549                 \r
1550                 $this->formdata = array(\r
1551                         'imgurl' => $imgurl,\r
1552                         'imgwidth' => $imgwidth,\r
1553                         'imgheight' => $imgheight,\r
1554                 );\r
1555                 $this->doForm('nucleusbutton');\r
1556                 return;\r
1557         }\r
1558         \r
1559         /**\r
1560          * Actions::parse_otherarchive()\r
1561          * Parse skinvar otherarchive\r
1562          * \r
1563          * @param       string  $blogname       name of weblog\r
1564          * @param       string  $template       name of template\r
1565          * @param       string  $category       name of category\r
1566          * @return      void\r
1567          */     \r
1568         public function parse_otherarchive($blogname, $template, $category = '')\r
1569         {\r
1570                 global $archive, $manager;\r
1571                 sscanf($archive,'%d-%d-%d',$y,$m,$d);\r
1572                 $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
1573                 $this->setBlogCategory($b, $category);\r
1574                 $this->preBlogContent('otherachive',$b);\r
1575                 $b->showArchive($template, $y, $m, $d);\r
1576                 $this->postBlogContent('otherachive',$b);\r
1577                 return;\r
1578         }\r
1579         \r
1580         /**\r
1581          * Actions::parse_otherarchivedaylist()\r
1582          * Parse skinvar otherarchivedaylist\r
1583          * \r
1584          * @param       string  $blogname       name of weblog\r
1585          * @param       string  $template       name of template\r
1586          * @param       string  $category       name of category\r
1587          * @param       integer $limit          the amount of items in a display\r
1588          * @return      void\r
1589          */\r
1590         public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)\r
1591         {\r
1592                 global $manager;\r
1593                 if ( $category == 'all')\r
1594                 {\r
1595                         $category = '';\r
1596                 }\r
1597                 $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
1598                 $this->setBlogCategory($b, $category);\r
1599                 $this->preBlogContent('otherarchivelist',$b);\r
1600                 $b->showArchiveList($template, 'day', $limit);\r
1601                 $this->postBlogContent('otherarchivelist',$b);\r
1602                 return;\r
1603         }\r
1604         \r
1605         /**\r
1606          * Actions::parse_otherarchivelist()\r
1607          * Parse skinvar otherarchivelist\r
1608          * \r
1609          * @param       string  $blogname       name of weblog\r
1610          * @param       string  $template       name of template\r
1611          * @param       string  $category       name of category\r
1612          * @param       integer $limit          the amount of items in a display\r
1613          * @return      void\r
1614          */\r
1615         public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)\r
1616         {\r
1617                 global $manager;\r
1618                 if ( $category == 'all' )\r
1619                 {\r
1620                         $category = '';\r
1621                 }\r
1622                 $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
1623                 $this->setBlogCategory($b, $category);\r
1624                 $this->preBlogContent('otherarchivelist',$b);\r
1625                 $b->showArchiveList($template, 'month', $limit);\r
1626                 $this->postBlogContent('otherarchivelist',$b);\r
1627                 return;\r
1628         }\r
1629         \r
1630         /**\r
1631          * Actions::parse_otherarchiveyearlist()\r
1632          * Parse skinvar otherarchiveyearlist\r
1633          * \r
1634          * @param       string  $blogname       name of weblog\r
1635          * @param       string  $template       name of template\r
1636          * @param       string  $category       name of category\r
1637          * @limit       integer $limit          the amount of items in a display\r
1638          */\r
1639         public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)\r
1640         {\r
1641                 global $manager;\r
1642                 if ( $category == 'all' )\r
1643                 {\r
1644                         $category = '';\r
1645                 }\r
1646                 $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
1647                 $this->setBlogCategory($b, $category);\r
1648                 $this->preBlogContent('otherarchivelist',$b);\r
1649                 $b->showArchiveList($template, 'year', $limit);\r
1650                 $this->postBlogContent('otherarchivelist',$b);\r
1651                 return;\r
1652         }\r
1653         \r
1654         /**\r
1655          * Actions::parse_otherblog()\r
1656          * Parse skinvar otherblog\r
1657          * \r
1658          * @param       string  $blogname       name of weblog\r
1659          * @param       string  $template       name of template\r
1660          * @param       mixed   $amount         the amount of items, in case it includes the beginning\r
1661          * @param       string  $category       name of category\r
1662          * @return      void\r
1663          */\r
1664         public function parse_otherblog($blogname, $template, $amount = 10, $category = '')\r
1665         {\r
1666                 global $manager;\r
1667                 \r
1668                 list($limit, $offset) = sscanf($amount, '%d(%d)');\r
1669                 \r
1670                 $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
1671                 $this->setBlogCategory($b, $category);\r
1672                 $this->preBlogContent('otherblog',$b);\r
1673                 $this->amountfound = $b->readLog($template, $limit, $offset);\r
1674                 $this->postBlogContent('otherblog',$b);\r
1675                 return;\r
1676         }\r
1677         \r
1678         /**\r
1679          * Actions::parse_othersearchresults()\r
1680          * Parse skinvar othersearchresults\r
1681          * \r
1682          * @param       string  $blogname       name of weblog\r
1683          * @param       string  $template       name of template\r
1684          * @param       integer $maxresults     the amount of results\r
1685          * @return      void\r
1686          */\r
1687         public function parse_othersearchresults($blogname, $template, $maxresults = 50)\r
1688         {\r
1689                 global $query, $amount, $manager, $startpos;\r
1690                 $b =& $manager->getBlog(getBlogIDFromName($blogname));\r
1691                 // need this to select default category\r
1692                 $this->setBlogCategory($b, '');\r
1693                 $this->preBlogContent('othersearchresults',$b);\r
1694                 $b->search($query, $template, $amount, $maxresults, $startpos);\r
1695                 $this->postBlogContent('othersearchresults',$b);\r
1696                 return;\r
1697         }\r
1698         \r
1699         /**\r
1700          * Actions::parse_plugin()\r
1701          * Executes a plugin skinvar\r
1702          * extra parameters can be added\r
1703          * \r
1704          * @param       string  $pluginName     name of plugin (without the NP_)\r
1705          * @return      void\r
1706          */\r
1707         public function parse_plugin($pluginName)\r
1708         {\r
1709                 global $manager;\r
1710                 \r
1711                 $plugin =& $manager->getPlugin('NP_' . $pluginName);\r
1712                 if ( !$plugin )\r
1713                 {\r
1714                         return;\r
1715                 }\r
1716                 \r
1717                 // get arguments\r
1718                 $params = func_get_args();\r
1719                 \r
1720                 // remove plugin name\r
1721                 array_shift($params);\r
1722                 \r
1723                 // add skin type on front\r
1724                 array_unshift($params, $this->skintype);\r
1725                 \r
1726                 call_user_func_array(array(&$plugin,'doSkinVar'), $params);\r
1727                 return;\r
1728         }\r
1729         \r
1730         /**\r
1731          * Actions::parse_prevarchive()\r
1732          * Parse skinvar prevarchive\r
1733          * \r
1734          * @param       void\r
1735          * @return      void\r
1736          */\r
1737         public function parse_prevarchive()\r
1738         {\r
1739                 global $archiveprev;\r
1740                 echo $archiveprev;\r
1741         }\r
1742         \r
1743         /**\r
1744          * Actions::parse_preview()\r
1745          * Parse skinvar preview\r
1746          * \r
1747          * @param       string  $template       name of tempalte\r
1748          * @return      void\r
1749          */\r
1750         public function parse_preview($template)\r
1751         {\r
1752                 global $blog, $CONF, $manager;\r
1753                 \r
1754                 $template =& $manager->getTemplate($template);\r
1755                 \r
1756                 $row['body'] = '<span id="prevbody"></span>';\r
1757                 $row['title'] = '<span id="prevtitle"></span>';\r
1758                 $row['more'] = '<span id="prevmore"></span>';\r
1759                 $row['itemlink'] = '';\r
1760                 $row['itemid'] = 0; $row['blogid'] = $blog->getID();\r
1761                 \r
1762                 echo Template::fill($template['ITEM_HEADER'],$row);\r
1763                 echo Template::fill($template['ITEM'],$row);\r
1764                 echo Template::fill($template['ITEM_FOOTER'],$row);\r
1765                 return;\r
1766         }\r
1767         \r
1768         /**\r
1769          * Actions::parse_previtem()\r
1770          * Parse skinvar previtem\r
1771          * (include itemid of prev item)\r
1772          * \r
1773          * @param       void\r
1774          * @return      void\r
1775          */\r
1776         public function parse_previtem()\r
1777         {\r
1778                 global $itemidprev;\r
1779                 if ( isset($itemidprev) )\r
1780                 {\r
1781                         echo (integer) $itemidprev;\r
1782                 }\r
1783                 return;\r
1784         }\r
1785         \r
1786         /**\r
1787          * Actions::parse_previtemtitle()\r
1788          * Parse skinvar previtemtitle\r
1789          * (include itemtitle of prev item)\r
1790          * \r
1791          * @param       String  $format string format\r
1792          * @return      String  formatted string\r
1793          */\r
1794         public function parse_previtemtitle($format = '')\r
1795         {\r
1796                 global $itemtitleprev;\r
1797                 \r
1798                 switch ( $format )\r
1799                 {\r
1800                         case 'xml':\r
1801                                 echo Entity::hen($itemtitleprev);\r
1802                                 break;\r
1803                         case 'raw':\r
1804                                 echo $itemtitleprev;\r
1805                                 break;\r
1806                         case 'attribute':\r
1807                         default:\r
1808                                 echo Entity::hsc($itemtitleprev);\r
1809                                 break;\r
1810                 }\r
1811                 return;\r
1812         }\r
1813         \r
1814         /**\r
1815          * Actions::parse_prevlink()\r
1816          * Parse skinvar prevlink\r
1817          * \r
1818          * @param       string  $linktext       text as a content of anchor element\r
1819          * @param       integer the amount of links\r
1820          * @return      void\r
1821          */\r
1822         public function parse_prevlink($linktext = '', $amount = 10)\r
1823         {\r
1824                 global $itemidprev, $archiveprev, $startpos;\r
1825                 \r
1826                 if ( $this->skintype == 'item' )\r
1827                 {\r
1828                         $this->itemlink($itemidprev, $linktext);\r
1829                 }\r
1830                 else if ( $this->skintype == 'search' || $this->skintype == 'index' )\r
1831                 {\r
1832                         $this->searchlink($amount, $startpos, 'prev', $linktext);\r
1833                 }\r
1834                 else\r
1835                 {\r
1836                         $this->archivelink($archiveprev, $linktext);\r
1837                 }\r
1838                 return;\r
1839         }\r
1840         \r
1841         /**\r
1842          * Actions::parse_query()\r
1843          * Parse skinvar query\r
1844          * (includes the search query)   \r
1845          * \r
1846          * @param       void\r
1847          * @return      void\r
1848          */\r
1849         public function parse_query()\r
1850         {\r
1851                 global $query;\r
1852                 echo Entity::hsc($query);\r
1853                 return;\r
1854         }\r
1855         \r
1856         /**\r
1857          * Actions::parse_referer()\r
1858          * Parse skinvar referer\r
1859          * \r
1860          * @param       void\r
1861          * @return      void\r
1862          */\r
1863         public function parse_referer()\r
1864         {\r
1865                 echo Entity::hsc(serverVar('HTTP_REFERER'));\r
1866                 return;\r
1867         }\r
1868         \r
1869         /**\r
1870          * Actions::parse_searchform()\r
1871          * Parse skinvar searchform\r
1872          * \r
1873          * @param       string  $blogname       name of weblog\r
1874          * @return      void\r
1875          */\r
1876         public function parse_searchform($blogname = '')\r
1877         {\r
1878                 global $CONF, $manager, $maxresults;\r
1879                 if ( $blogname )\r
1880                 {\r
1881                         $blog =& $manager->getBlog(getBlogIDFromName($blogname));\r
1882                 }\r
1883                 else\r
1884                 {\r
1885                         global $blog;\r
1886                 }\r
1887                 // use default blog when no blog is selected\r
1888                 $this->formdata = array(\r
1889                         'id'    => $blog?$blog->getID():$CONF['DefaultBlog'],\r
1890                         'query' => Entity::hsc(getVar('query')),\r
1891                 );\r
1892                 $this->doForm('searchform');\r
1893                 return;\r
1894         }\r
1895         \r
1896         /**\r
1897          * Actions::parse_searchresults()\r
1898          * Parse skinvar searchresults\r
1899          * \r
1900          * @param       string  $template       name of tempalte\r
1901          * @param       integer $maxresults     searched items in a display\r
1902          * @return      void;\r
1903          */\r
1904         public function parse_searchresults($template, $maxresults = 50 )\r
1905         {\r
1906                 global $blog, $query, $amount, $startpos;\r
1907                 \r
1908                 $this->setBlogCategory($blog, '');      // need this to select default category\r
1909                 $this->preBlogContent('searchresults',$blog);\r
1910                 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);\r
1911                 $this->postBlogContent('searchresults',$blog);\r
1912                 return;\r
1913         }\r
1914         \r
1915         /**\r
1916          * Actions::parse_self()\r
1917          * Parse skinvar self\r
1918          * \r
1919          * @param       void\r
1920          * @return      void\r
1921          */\r
1922         public function parse_self()\r
1923         {\r
1924                 global $CONF;\r
1925                 echo $CONF['Self'];\r
1926                 return;\r
1927         }\r
1928         \r
1929         /**\r
1930          * Actions::parse_sitevar()\r
1931          * Parse skinvar sitevar\r
1932          * (include a sitevar)\r
1933          * \r
1934          * @param       string  $which\r
1935          * @return      void\r
1936          */\r
1937         public function parse_sitevar($which)\r
1938         {\r
1939                 global $CONF;\r
1940                 switch ( $which )\r
1941                 {\r
1942                         case 'url':\r
1943                                 echo $CONF['IndexURL'];\r
1944                                 break;\r
1945                         case 'name':\r
1946                                 echo $CONF['SiteName'];\r
1947                                 break;\r
1948                         case 'admin':\r
1949                                 echo $CONF['AdminEmail'];\r
1950                                 break;\r
1951                         case 'adminurl':\r
1952                                 echo $CONF['AdminURL'];\r
1953                 }\r
1954                 return;\r
1955         }\r
1956         \r
1957         /**\r
1958          * Actions::parse_skinname()\r
1959          * Parse skinname\r
1960          * \r
1961          * @param       void\r
1962          * @return      void\r
1963          */\r
1964         public function parse_skinname()\r
1965         {\r
1966                 echo $this->skin->getName();\r
1967                 return;\r
1968         }\r
1969         \r
1970         /**\r
1971          * Actions::parse_skintype()\r
1972          * Parse skintype (experimental)\r
1973          * \r
1974          * @param       void\r
1975          * @return      void\r
1976          */\r
1977         public function parse_skintype()\r
1978         {\r
1979                 echo $this->skintype;\r
1980                 return;\r
1981         }\r
1982         \r
1983         /**\r
1984          * Actions::parse_text()\r
1985          * Parse text\r
1986          * \r
1987          * @param       void\r
1988          * @return      void\r
1989          */\r
1990         public function parse_text($which)\r
1991         {\r
1992                 // constant($which) only available from 4.0.4 :(\r
1993                 if ( defined($which) )\r
1994                 {\r
1995                         eval("echo $which;");\r
1996                 }\r
1997                 return;\r
1998         }\r
1999         \r
2000         /**\r
2001          * Actions::parse_ticket()\r
2002          * Parse ticket\r
2003          * \r
2004          * @param       void\r
2005          * @return      void\r
2006          */\r
2007         public function parse_ticket()\r
2008         {\r
2009                 global $manager;\r
2010                 $manager->addTicketHidden();\r
2011                 return;\r
2012         }\r
2013 \r
2014         /**\r
2015          * Actions::parse_todaylink()\r
2016          * Parse skinvar todaylink\r
2017          * A link to the today page (depending on selected blog, etc...)\r
2018          *\r
2019          * @param       string  $linktext       text for link\r
2020          * @return      void\r
2021          */\r
2022         public function parse_todaylink($linktext = '')\r
2023         {\r
2024                 global $blog, $CONF;\r
2025                 if ( $blog )\r
2026                 {\r
2027                         echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);\r
2028                 }\r
2029                 else\r
2030                 {\r
2031                         echo $this->link($CONF['SiteUrl'], $linktext);\r
2032                 }\r
2033                 return;\r
2034         }\r
2035         \r
2036         /**\r
2037          * Parse vars\r
2038          * When commentform is not used, to include a hidden field with itemid   \r
2039          * \r
2040          * @param       void\r
2041          * @return      void\r
2042          */\r
2043         public function parse_vars()\r
2044         {\r
2045                 global $itemid;\r
2046                 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";\r
2047                 return;\r
2048         }\r
2049 \r
2050         /**\r
2051          * Actions::parse_version()\r
2052          * Parse skinvar version\r
2053          * (include nucleus versionnumber)       \r
2054          * \r
2055          * @param       void\r
2056          * @return      void\r
2057          */\r
2058         public function parse_version()\r
2059         {\r
2060                 global $nucleus;\r
2061                 echo 'Nucleus CMS ' . $nucleus['version'];\r
2062                 return;\r
2063         }\r
2064         \r
2065         /**\r
2066          * Actions::parse_sticky()\r
2067          * Parse skinvar sticky\r
2068          * \r
2069          * @param       integer $itemnumber     id of item\r
2070          * @param       string  $template       name of template\r
2071          * @return      void\r
2072          */\r
2073         public function parse_sticky($itemnumber = 0, $template = '')\r
2074         {\r
2075                 global $manager;\r
2076                 \r
2077                 $itemnumber = intval($itemnumber);\r
2078                 $itemarray = array($itemnumber);\r
2079                 \r
2080                 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));\r
2081                 $this->preBlogContent('sticky',$b);\r
2082                 $this->amountfound = $b->readLogFromList($itemarray, $template);\r
2083                 $this->postBlogContent('sticky',$b);\r
2084                 return;\r
2085         }\r
2086 }\r