3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2012 The Nucleus Group
\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
13 * This class contains the functions that get called by using
\r
14 * the special tags in the skins
\r
16 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
17 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
18 * @version $Id: ACTIONS.php 1784 2012-04-22 04:28:30Z sakamocchi $
\r
21 class Actions extends BaseActions
\r
23 // part of the skin currently being parsed ('index', 'item', 'archive',
\r
24 // 'archivelist', 'member', 'search', 'error', 'imagepopup')
\r
27 // contains an assoc array with parameters that need to be included when
\r
28 // generating links to items/archives/... (e.g. catid)
\r
29 private $linkparams;
\r
31 // reference to the skin object for which a part is being parsed
\r
34 // used when including templated forms from the include/ dir. The $formdata var
\r
35 // contains the values to fill out in there (assoc array name -> value)
\r
38 // filled out with the number of displayed items after calling one of the
\r
39 // (other)blog/(other)searchresults skinvars.
\r
40 private $amountfound;
\r
43 * Actions::$default_actions
\r
44 * list of whole action names with which this class can deal
\r
46 static private $default_actions = array(
\r
56 'otherarchivedaylist',
\r
58 'otherarchiveyearlist',
\r
69 // deprecated (Nucleus v2.0)
\r
70 /* TODO: remove this */
\r
75 * Actions::$skin_type_friendly_names
\r
76 * friendly name for wrapped page types
\r
78 static public $default_skin_types = array(
\r
79 'index' => _SKIN_PART_MAIN,
\r
80 'item' => _SKIN_PART_ITEM,
\r
81 'archivelist' => _SKIN_PART_ALIST,
\r
82 'archive' => _SKIN_PART_ARCHIVE,
\r
83 'search' => _SKIN_PART_SEARCH,
\r
84 'error' => _SKIN_PART_ERROR,
\r
85 'member' => _SKIN_PART_MEMBER,
\r
86 'imagepopup' => _SKIN_PART_POPUP
\r
90 * Actions::getAvailableSkinTypes()
\r
94 * @return array list of friendly names for page actions
\r
96 static public function getAvailableSkinTypes()
\r
98 return self::$default_skin_types;
\r
102 * Actions::__construct()
\r
103 * Constructor for a new Actions object
\r
105 * @param string $type
\r
108 public function __construct($type)
\r
112 // call constructor of superclass first
\r
113 parent::__construct();
\r
114 $this->skintype = $type;
\r
118 $this->linkparams = array('catid' => $catid);
\r
124 * Actions::getAvailableActions()
\r
127 * @return array allowed actions for the page type
\r
129 public function getAvailableActions()
\r
131 $extra_actions = array();
\r
133 switch ( $this->skintype )
\r
136 $extra_actions = array(
\r
150 $extra_actions = array(
\r
167 case 'archivelist':
\r
168 $extra_actions = array(
\r
178 $extra_actions = array(
\r
185 'othersearchresults',
\r
193 $extra_actions = array(
\r
195 // deprecated (Nucleus v2.0)
\r
196 /* TODO: remove this */
\r
201 $extra_actions = array(
\r
209 $extra_actions = array(
\r
232 $extra_actions = array(
\r
238 $extra_actions = array(
\r
256 $defined_actions = array_merge(self::$default_actions, $extra_actions);
\r
258 return array_merge($defined_actions, parent::getAvailableActions());
\r
262 * Actions::setSkin()
\r
264 * @param object $skin an instance of Skin class
\r
267 public function setSkin(&$skin)
\r
269 $this->skin =& $skin;
\r
274 * Actions::doForm()
\r
275 * Forms get parsedincluded now, using an extra <formdata> skinvar
\r
277 * @param string $filename
\r
280 public function doForm($filename)
\r
282 global $DIR_NUCLEUS;
\r
283 array_push($this->parser->actions,'formdata', 'callback','errordiv','ticket');
\r
285 $oldIncludeMode = Parser::getProperty('IncludeMode');
\r
286 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
\r
287 Parser::setProperty('IncludeMode','normal');
\r
288 Parser::setProperty('IncludePrefix','');
\r
290 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
\r
291 Parser::setProperty('IncludeMode',$oldIncludeMode);
\r
292 Parser::setProperty('IncludePrefix',$oldIncludePrefix);
\r
294 array_pop($this->parser->actions); // errordiv
\r
295 array_pop($this->parser->actions); // callback
\r
296 array_pop($this->parser->actions); // formdata
\r
297 array_pop($this->parser->actions); // ticket
\r
302 * Actions::checkCondition()
\r
303 * Checks conditions for if statements
\r
305 * @param string $field type of <%if%>
\r
306 * @param string $name property of field
\r
307 * @param string $value value of property
\r
308 * @return boolean condition
\r
310 protected function checkCondition($field, $name='', $value = '')
\r
312 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
318 $condition = ($blog && $this->ifCategory($name,$value));
\r
320 case 'blogsetting':
\r
321 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
324 $condition = $member->isLoggedIn();
\r
327 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
\r
330 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
\r
333 $condition = ($itemidnext != '');
\r
336 $condition = ($itemidprev != '');
\r
338 case 'archiveprevexists':
\r
339 $condition = ($archiveprevexists == true);
\r
341 case 'archivenextexists':
\r
342 $condition = ($archivenextexists == true);
\r
345 $condition = (($name == $this->skintype) || ($name == requestVar('action')));
\r
348 $condition = $this->ifHasPlugin($name, $value);
\r
351 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);
\r
358 * Actions::_ifHasPlugin()
\r
359 * hasplugin,PlugName
\r
360 * -> checks if plugin exists
\r
361 * hasplugin,PlugName,OptionName
\r
362 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
363 * hasplugin,PlugName,OptionName=value
\r
364 * -> checks if the option OptionName from plugin PlugName is set to value
\r
366 * @param string $name name of plugin
\r
367 * @param string $value
\r
370 private function ifHasPlugin($name, $value)
\r
373 $condition = false;
\r
374 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
375 if ( $manager->pluginInstalled("NP_{$name}") )
\r
377 $plugin =& $manager->getPlugin("NP_{$name}");
\r
378 if ( $plugin != NULL )
\r
380 if ( $value == "" )
\r
386 list($name2, $value2) = preg_split('#=#', $value, 2);
\r
387 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
\r
391 else if ( $plugin->getOption($name2) == $value2 )
\r
402 * Actions::ifPlugin()
\r
403 * Checks if a plugin exists and call its doIf function
\r
405 * @param string $name name of plugin
\r
406 * @param string $key name of plugin option
\r
407 * @param string $value value of plugin option
\r
410 private function ifPlugin($name, $key = '', $value = '')
\r
414 $plugin =& $manager->getPlugin("NP_{$name}");
\r
420 $params = func_get_args();
\r
421 array_shift($params);
\r
423 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r
427 * Actions::ifCategory()
\r
428 * Different checks for a category
\r
430 * @param string $name
\r
431 * @param string $value
\r
434 private function ifCategory($name = '', $value='')
\r
436 global $blog, $catid;
\r
438 // when no parameter is defined, just check if a category is selected
\r
439 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )
\r
441 return $blog->isValidCategory($catid);
\r
444 // check category name
\r
445 if ( $name == 'catname' )
\r
447 $value = $blog->getCategoryIdFromName($value);
\r
448 if ( $value == $catid )
\r
450 return $blog->isValidCategory($catid);
\r
454 // check category id
\r
455 if ( ($name == 'catid') && ($value == $catid) )
\r
457 return $blog->isValidCategory($catid);
\r
463 * Actions::ifOnTeam()
\r
464 * Checks if a member is on the team of a blog and return his rights
\r
466 * @param string $blogName name of weblog
\r
469 private function ifOnTeam($blogName = '')
\r
471 global $blog, $member, $manager;
\r
473 // when no blog found
\r
474 if ( ($blogName == '') && !is_object($blog) )
\r
479 // explicit blog selection
\r
480 if ( $blogName != '' )
\r
482 $blogid = getBlogIDFromName($blogName);
\r
485 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
487 // use current blog
\r
488 $blogid = $blog->getID();
\r
491 return $member->teamRights($blogid);
\r
495 * Actions::ifAdmin()
\r
496 * Checks if a member is admin of a blog
\r
498 * @param string $blogName name of weblog
\r
501 private function ifAdmin($blogName = '')
\r
503 global $blog, $member, $manager;
\r
505 // when no blog found
\r
506 if ( ($blogName == '') && (!is_object($blog)) )
\r
511 // explicit blog selection
\r
512 if ( $blogName != '' )
\r
514 $blogid = getBlogIDFromName($blogName);
\r
517 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
519 // use current blog
\r
520 $blogid = $blog->getID();
\r
523 return $member->isBlogAdmin($blogid);
\r
529 * - a raw link (html/xml encoded) when no linktext is provided
\r
530 * - a (x)html <a href... link when a text is present (text htmlencoded)
\r
532 * @param string $url URL for href attribute of anchor element
\r
533 * @param string $linktext content of anchor element
\r
536 private function link($url, $linktext = '')
\r
538 $u = Entity::hsc($url);
\r
539 // fix URLs that already had encoded ampersands
\r
540 $u = preg_replace("#&amp;#", '&', $u);
\r
541 if ( $linktext != '' )
\r
543 $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';
\r
553 * Actions::searchlink()
\r
554 * Outputs a next/prev link
\r
556 * @param $maxresults
\r
557 * The maximum amount of items shown per page (e.g. 10)
\r
559 * Current start position (requestVar('startpos'))
\r
560 * @param $direction
\r
561 * either 'prev' or 'next'
\r
563 * When present, the output will be a full <a href...> link. When empty,
\r
564 * only a raw link will be outputted
\r
566 private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')
\r
568 global $CONF, $blog, $query, $amount;
\r
569 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
\r
570 $startpos = (integer) $startpos;
\r
571 $parsed = parse_url(serverVar('REQUEST_URI'));
\r
572 $path = $parsed['path'];
\r
573 $parsed = $parsed['query'];
\r
576 if ( $direction == 'prev' )
\r
578 if ( intval($startpos) - intval($maxresults) >= 0 )
\r
580 $startpos = intval($startpos) - intval($maxresults);
\r
582 if ( $this->skintype == 'index' )
\r
586 else if ( $this->skintype == 'search' )
\r
588 $url = $CONF['SearchURL'];
\r
590 $url .= '?' . alterQueryStr($parsed,'startpos',$startpos);
\r
593 else if ( $direction == 'next' )
\r
595 global $navigationItems;
\r
596 if ( !isset($navigationItems) )
\r
598 $navigationItems = 0;
\r
603 $iAmountOnPage = 0;
\r
607 $iAmountOnPage = $this->amountfound;
\r
610 if ( intval($navigationItems) > 0 )
\r
612 $iAmountOnPage = intval($navigationItems) - intval($startpos);
\r
614 elseif ( $iAmountOnPage == 0 )
\r
617 * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
\r
618 * try a count query
\r
620 if ( $this->skintype == 'index' )
\r
622 $sqlquery = $blog->getSqlBlog('', 'count');
\r
625 else if ( $this->skintype == 'search' )
\r
627 $unused_highlight = '';
\r
628 $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
\r
629 $url = $CONF['SearchURL'];
\r
633 $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
\r
638 if ( intval($iAmountOnPage) >= intval($maxresults) )
\r
640 $startpos = intval($startpos) + intval($maxresults);
\r
641 $url .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
\r
647 echo $this->link($url, $linktext);
\r
653 * Actions::itemlink()
\r
654 * Creates an item link and if no id is given a todaylink
\r
656 * @param integer $id id for link
\r
657 * @param string $linktext text for link
\r
660 private function itemlink($id, $linktext = '')
\r
665 echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);
\r
669 $this->parse_todaylink($linktext);
\r
675 * Actions::archivelink)
\r
676 * Creates an archive link and if no id is given a todaylink
\r
678 * @param integer $id id for link
\r
679 * @param string $linktext text for link
\r
682 private function archivelink($id, $linktext = '')
\r
684 global $CONF, $blog;
\r
687 echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
\r
691 $this->parse_todaylink($linktext);
\r
697 * Actions:setBlogCategory()
\r
698 * Helper function that sets the category that a blog will need to use
\r
700 * @param string $blog An object of the blog class, passed by reference (we want to make changes to it)
\r
701 * @param string $catname The name of the category to use
\r
704 private function setBlogCategory(&$blog, $catname)
\r
707 if ( $catname != '' )
\r
709 $blog->setSelectedCategoryByName($catname);
\r
713 $blog->setSelectedCategory($catid);
\r
719 * Actions::preBlogContent()
\r
720 * Notifies the Manager that a PreBlogContent event occurs
\r
722 * @param string $type type of skin
\r
723 * @param object $blog an instance of Blog class
\r
726 private function preBlogContent($type, &$blog)
\r
729 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
\r
734 * Actions::postBlogContent()
\r
735 * Notifies the Manager that a PostBlogContent event occurs
\r
737 * @param string $type type of skin
\r
738 * @param objecct $blog an instance of Blog class
\r
741 private function postBlogContent($type, &$blog)
\r
744 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
\r
749 * Actions::parse_additemform()
\r
750 * Parse skinvar additemform
\r
755 public function parse_additemform()
\r
757 global $blog, $CONF;
\r
758 $this->formdata = array(
\r
759 'adminurl' => Entity::hsc($CONF['AdminURL']),
\r
760 'catid' => $blog->getDefaultCategory()
\r
762 $blog->InsertJavaScriptInfo();
\r
763 $this->doForm('additemform');
\r
768 * Actions::parse_addlink()
\r
769 * Parse skinvar addlink
\r
770 * A Link that allows to open a bookmarklet to add an item
\r
772 public function parse_addlink()
\r
774 global $CONF, $member, $blog;
\r
775 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
\r
777 echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
\r
783 * Actions::parse_addpopupcode()
\r
784 * Parse skinvar addpopupcode
\r
785 * Code that opens a bookmarklet in an popup window
\r
790 public function parse_addpopupcode()
\r
792 echo "if (event && 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
797 * Parse skinvar adminurl
\r
798 * (shortcut for admin url)
\r
803 public function parse_adminurl()
\r
805 $this->parse_sitevar('adminurl');
\r
810 * Actions::parse_archive()
\r
811 * Parse skinvar archive
\r
813 * @param string $template name of template
\r
814 * @param string $category name of category
\r
817 public function parse_archive($template, $category = '')
\r
819 global $blog, $archive;
\r
820 // can be used with either yyyy-mm or yyyy-mm-dd
\r
821 sscanf($archive,'%d-%d-%d', $y, $m, $d);
\r
822 $this->setBlogCategory($blog, $category);
\r
823 $this->preBlogContent('achive',$blog);
\r
824 $blog->showArchive($template, $y, $m, $d);
\r
825 $this->postBlogContent('achive',$blog);
\r
830 * Actions::parse_archivedate()
\r
831 * %archivedate(locale,date format)%
\r
833 * @param string $locale
\r
836 public function parse_archivedate($locale = '-def-')
\r
841 * TODO: these lines are no meaning because there is no $template.
\r
842 if ( $locale == '-def-' )
\r
844 setlocale(LC_TIME, $template['LOCALE']);
\r
848 setlocale(LC_TIME, $locale);
\r
852 // get archive date
\r
853 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
856 $args = func_get_args();
\r
857 // format can be spread over multiple parameters
\r
858 if ( sizeof($args) > 1 )
\r
860 // take away locale
\r
861 array_shift($args);
\r
863 $format=implode(',',$args);
\r
865 elseif ( $d == 0 && $m !=0 )
\r
875 $format = '%d %B %Y';
\r
877 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
\r
882 * Actions::parse_archivedaylist()
\r
883 * Parse skinvar archivedaylist
\r
885 * @param string $template name of template
\r
886 * @param string $category name of category
\r
887 * @param integer $limit the number of items in a display
\r
890 public function parse_archivedaylist($template, $category = 'all', $limit = 0)
\r
893 if ( $category == 'all' )
\r
897 $this->preBlogContent('archivelist',$blog);
\r
898 $this->setBlogCategory($blog, $category);
\r
899 $blog->showArchiveList($template, 'day', $limit);
\r
900 $this->postBlogContent('archivelist',$blog);
\r
905 * Actions::parse_archivelink()
\r
906 * A link to the archives for the current blog (or for default blog)
\r
908 * @param string $linktext text for link
\r
911 public function parse_archivelink($linktext = '')
\r
913 global $blog, $CONF;
\r
916 echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
\r
920 echo $this->link(Link::create_archivelist_link(), $linktext);
\r
926 * Actions::parse_archivelist()
\r
928 * @param string $template name of template
\r
929 * @param string $category name of category
\r
930 * @param integer $limit the number of items in a display
\r
933 public function parse_archivelist($template, $category = 'all', $limit = 0)
\r
936 if ( $category == 'all' )
\r
940 $this->preBlogContent('archivelist',$blog);
\r
941 $this->setBlogCategory($blog, $category);
\r
942 $blog->showArchiveList($template, 'month', $limit);
\r
943 $this->postBlogContent('archivelist',$blog);
\r
948 * Actions::parse_archiveyearlist()
\r
950 * @param string $template name of template
\r
951 * @param string $category name of category
\r
952 * @param integer $limit the number of items in a display
\r
954 public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
\r
957 if ( $category == 'all' )
\r
961 $this->preBlogContent('archivelist',$blog);
\r
962 $this->setBlogCategory($blog, $category);
\r
963 $blog->showArchiveList($template, 'year', $limit);
\r
964 $this->postBlogContent('archivelist',$blog);
\r
969 * Actions::parse_archivetype()
\r
970 * Parse skinvar archivetype
\r
975 public function parse_archivetype()
\r
977 global $archivetype;
\r
983 * Actions::parse_blog()
\r
984 * Parse skinvar blog
\r
986 * @param string $template name of template
\r
987 * @param mixed $amount the number of items in a display, in case it includes the beginning
\r
988 * @param string $category name of category
\r
991 public function parse_blog($template, $amount = 10, $category = '')
\r
993 global $blog, $startpos;
\r
995 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
996 $this->setBlogCategory($blog, $category);
\r
997 $this->preBlogContent('blog',$blog);
\r
998 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
\r
999 $this->postBlogContent('blog',$blog);
\r
1004 * Actions::parse_bloglist()
\r
1005 * Parse skinvar bloglist
\r
1006 * Shows a list of all blogs
\r
1008 * @param string $template name of template
\r
1009 * @param string $bnametype whether 'name' or 'shortname' is used for the link text
\r
1010 * @param string $orderby order criteria
\r
1011 * @param string $direction order ascending or descending
\r
1014 public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
\r
1016 Blog::showBlogList($template, $bnametype, $orderby, $direction);
\r
1021 * Actions::parse_blogsetting()
\r
1022 * Parse skinvar blogsetting
\r
1024 * @param string $which key of weblog settings
\r
1027 public function parse_blogsetting($which)
\r
1033 echo Entity::hsc($blog->getID());
\r
1036 echo Entity::hsc($blog->getURL());
\r
1039 echo Entity::hsc($blog->getName());
\r
1042 echo Entity::hsc($blog->getDescription());
\r
1045 echo Entity::hsc($blog->getShortName());
\r
1052 * Actions::parse_callback()
\r
1055 * @param string $eventName name of event
\r
1056 * @param string $type type of skin
\r
1059 public function parse_callback($eventName, $type)
\r
1062 $manager->notify($eventName, array('type' => $type));
\r
1067 * Actions::parse_category()
\r
1068 * Parse skinvar category
\r
1070 * @param string $type key of category settings
\r
1073 public function parse_category($type = 'name')
\r
1075 global $catid, $blog;
\r
1076 if ( !$blog->isValidCategory($catid) )
\r
1084 echo $blog->getCategoryName($catid);
\r
1087 echo $blog->getCategoryDesc($catid);
\r
1097 * Actions::parse_categorylist()
\r
1098 * Parse categorylist
\r
1100 * @param string $template name of template
\r
1101 * @param string $blogname name of weblog
\r
1104 public function parse_categorylist($template, $blogname = '')
\r
1106 global $blog, $manager;
\r
1108 // when no blog found
\r
1109 if ( ($blogname == '') && (!is_object($blog)) )
\r
1114 if ( $blogname == '' )
\r
1116 $this->preBlogContent('categorylist',$blog);
\r
1117 $blog->showCategoryList($template);
\r
1118 $this->postBlogContent('categorylist',$blog);
\r
1122 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1123 $this->preBlogContent('categorylist',$b);
\r
1124 $b->showCategoryList($template);
\r
1125 $this->postBlogContent('categorylist',$b);
\r
1131 * Actions::parse_commentform()
\r
1132 * Parse skinvar commentform
\r
1134 * @param string $destinationurl URI for redirection
\r
1137 public function parse_commentform($destinationurl = '')
\r
1139 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
\r
1141 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
\r
1142 if ( stristr($destinationurl, 'action.php') )
\r
1144 $args = func_get_args();
\r
1145 $destinationurl = $args[1];
\r
1146 ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
\r
1149 $actionurl = $CONF['ActionURL'];
\r
1151 // if item is closed, show message and do nothing
\r
1152 $item =& $manager->getItem($itemid,0,0);
\r
1153 if ( $item['closed'] || !$blog->commentsEnabled() )
\r
1155 $this->doForm('commentform-closed');
\r
1159 if ( !$blog->isPublic() && !$member->isLoggedIn() )
\r
1161 $this->doForm('commentform-closedtopublic');
\r
1165 if ( !$destinationurl )
\r
1167 // note: createLink returns an HTML encoded URL
\r
1168 $destinationurl = Link::create_link(
\r
1171 'itemid' => $itemid,
\r
1172 'title' => $item['title'],
\r
1173 'timestamp' => $item['timestamp'],
\r
1174 'extra' => $this->linkparams
\r
1180 // HTML encode URL
\r
1181 $destinationurl = Entity::hsc($destinationurl);
\r
1184 // values to prefill
\r
1185 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
\r
1188 $user = postVar('user');
\r
1191 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
\r
1194 $userid = postVar('userid');
\r
1197 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
\r
1200 $email = postVar('email');
\r
1203 $body = postVar('body');
\r
1205 $this->formdata = array(
\r
1206 'destinationurl' => $destinationurl, // url is already HTML encoded
\r
1207 'actionurl' => Entity::hsc($actionurl),
\r
1208 'itemid' => $itemid,
\r
1209 'user' => Entity::hsc($user),
\r
1210 'userid' => Entity::hsc($userid),
\r
1211 'email' => Entity::hsc($email),
\r
1212 'body' => Entity::hsc($body),
\r
1213 'membername' => $member->getDisplayName(),
\r
1214 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
\r
1217 if ( !$member->isLoggedIn() )
\r
1219 $this->doForm('commentform-notloggedin');
\r
1223 $this->doForm('commentform-loggedin');
\r
1229 * Actions::parse_comments()
\r
1230 * Parse skinvar comments
\r
1231 * include comments for one item
\r
1233 * @param string $template name of template
\r
1236 public function parse_comments($template)
\r
1238 global $itemid, $manager, $blog, $highlight;
\r
1240 $template =& $manager->getTemplate($template);
\r
1241 $item = Item::getitem($itemid, 0, 0);
\r
1243 // create parser object & action handler
\r
1244 $handler = new ItemActions($blog);
\r
1245 $handler->setTemplate($template);
\r
1246 $handler->setCurrentItem($item);
\r
1248 $parser = new Parser($handler);
\r
1250 $comments = new Comments($itemid);
\r
1251 $comments->setItemActions($handler);
\r
1252 // shows ALL comments
\r
1253 $comments->showComments($template, -1, 1, $highlight);
\r
1258 * Actions::parse_errordiv()
\r
1264 public function parse_errordiv()
\r
1266 global $errormessage;
\r
1267 if ( $errormessage )
\r
1269 echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
\r
1275 * Actions::parse_errormessage()
\r
1276 * Parse skinvar errormessage
\r
1281 public function parse_errormessage()
\r
1283 global $errormessage;
\r
1284 echo $errormessage;
\r
1289 * Actions::parse_formdata()
\r
1292 * @param string $what key of format data
\r
1295 public function parse_formdata($what)
\r
1297 echo $this->formdata[$what];
\r
1302 * Actions::parse_ifcat()
\r
1305 * @param string $text
\r
1308 public function parse_ifcat($text = '')
\r
1310 if ( $text == '' )
\r
1313 $this->parse_if('category');
\r
1318 global $catid, $blog;
\r
1319 if ( $blog->isValidCategory($catid) )
\r
1328 * Actions::parse_image()
\r
1329 * Parse skinvar image
\r
1331 * @param string $what name of tag
\r
1334 public function parse_image($what = 'imgtag')
\r
1338 $imagetext = Entity::hsc(requestVar('imagetext'));
\r
1339 $imagepopup = requestVar('imagepopup');
\r
1340 $width = intRequestVar('width');
\r
1341 $height = intRequestVar('height');
\r
1342 $fullurl = Entity::hsc($CONF['MediaURL'] . $imagepopup);
\r
1361 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
\r
1368 * Actions::parse_imagetext()
\r
1369 * Parse skinvar imagetext
\r
1374 public function parse_imagetext()
\r
1376 $this->parse_image('imagetext');
\r
1381 * Actions::parse_item()
\r
1382 * Parse skinvar item
\r
1383 * include one item (no comments)
\r
1388 public function parse_item($template)
\r
1390 global $blog, $itemid, $highlight;
\r
1392 // need this to select default category
\r
1393 $this->setBlogCategory($blog, '');
\r
1394 $this->preBlogContent('item',$blog);
\r
1395 $r = $blog->showOneitem($itemid, $template, $highlight);
\r
1398 echo _ERROR_NOSUCHITEM;
\r
1400 $this->postBlogContent('item',$blog);
\r
1405 * Actions::parse_itemid()
\r
1406 * Parse skinvar itemid
\r
1411 public function parse_itemid()
\r
1419 * Actions::parseitemlink()
\r
1420 * Parse skinvar itemlink
\r
1425 public function parse_itemlink($linktext = '')
\r
1428 $this->itemlink($itemid, $linktext);
\r
1433 * Actions::parse_itemtitle()
\r
1439 public function parse_itemtitle($format = '')
\r
1441 global $manager, $itemid;
\r
1442 $item =& $manager->getItem($itemid,0,0);
\r
1444 switch ( $format )
\r
1447 echo Entity::hen($item['title']);
\r
1450 echo $item['title'];
\r
1454 echo Entity::hsc(strip_tags($item['title']));
\r
1461 * Actions::parse_loginform()
\r
1462 * Parse skinvar loginform
\r
1467 public function parse_loginform()
\r
1469 global $member, $CONF;
\r
1470 if ( !$member->isLoggedIn() )
\r
1472 $filename = 'loginform-notloggedin';
\r
1473 $this->formdata = array();
\r
1477 $filename = 'loginform-loggedin';
\r
1478 $this->formdata = array(
\r
1479 'membername' => $member->getDisplayName(),
\r
1482 $this->doForm($filename);
\r
1487 * Actions::parse_member()
\r
1488 * Parse skinvar member
\r
1489 * (includes a member info thingie)
\r
1491 * @param string $what which memberdata is needed
\r
1494 public function parse_member($what)
\r
1496 global $memberinfo, $member, $CONF;
\r
1498 // 1. only allow the member-details-page specific variables on member pages
\r
1499 if ( $this->skintype == 'member' )
\r
1504 echo Entity::hsc($memberinfo->getDisplayName());
\r
1507 echo Entity::hsc($memberinfo->getRealName());
\r
1510 echo Entity::hsc($memberinfo->getNotes());
\r
1513 echo Entity::hsc($memberinfo->getURL());
\r
1516 echo Entity::hsc($memberinfo->getEmail());
\r
1519 echo Entity::hsc($memberinfo->getID());
\r
1524 // 2. the next bunch of options is available everywhere, as long as the user is logged in
\r
1525 if ( $member->isLoggedIn() )
\r
1530 echo $member->getDisplayName();
\r
1532 case 'yourrealname':
\r
1533 echo $member->getRealName();
\r
1536 echo $member->getNotes();
\r
1539 echo $member->getURL();
\r
1542 echo $member->getEmail();
\r
1545 echo $member->getID();
\r
1547 case 'yourprofileurl':
\r
1548 if ($CONF['URLMode'] == 'pathinfo')
\r
1549 echo Link::create_member_link($member->getID());
\r
1551 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
\r
1559 * Link::parse_membermailform()
\r
1560 * Parse skinvar membermailform
\r
1562 * @param integer $rows the height for textarea
\r
1563 * @param integer $cols the width for textarea
\r
1564 * @param string $desturl URI to redirect
\r
1567 public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
\r
1569 global $member, $CONF, $memberid;
\r
1571 if ( $desturl == '' )
\r
1573 if ( $CONF['URLMode'] == 'pathinfo' )
\r
1575 $desturl = Link::create_member_link($memberid);
\r
1579 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
\r
1583 $message = postVar('message');
\r
1584 $frommail = postVar('frommail');
\r
1586 $this->formdata = array(
\r
1587 'url' => Entity::hsc($desturl),
\r
1588 'actionurl' => Entity::hsc($CONF['ActionURL']),
\r
1589 'memberid' => $memberid,
\r
1592 'message' => Entity::hsc($message),
\r
1593 'frommail' => Entity::hsc($frommail)
\r
1596 if ( $member->isLoggedIn() )
\r
1598 $this->doForm('membermailform-loggedin');
\r
1600 else if ( $CONF['NonmemberMail'] )
\r
1602 $this->doForm('membermailform-notloggedin');
\r
1606 $this->doForm('membermailform-disallowed');
\r
1612 * Actions::parse_nextarchive()
\r
1613 * Parse skinvar nextarchive
\r
1618 public function parse_nextarchive()
\r
1620 global $archivenext;
\r
1621 echo $archivenext;
\r
1626 * Parse skinvar nextitem
\r
1627 * (include itemid of next item)
\r
1632 public function parse_nextitem()
\r
1634 global $itemidnext;
\r
1635 if ( isset($itemidnext) )
\r
1637 echo (int)$itemidnext;
\r
1643 * Actions::parse_nextitemtitle()
\r
1644 * Parse skinvar nextitemtitle
\r
1645 * (include itemtitle of next item)
\r
1647 * @param string $format format of text
\r
1650 public function parse_nextitemtitle($format = '')
\r
1652 global $itemtitlenext;
\r
1654 switch ( $format )
\r
1657 echo Entity::hen($itemtitlenext);
\r
1660 echo $itemtitlenext;
\r
1664 echo Entity::hsc($itemtitlenext);
\r
1671 * Actions::parse_nextlink()
\r
1672 * Parse skinvar nextlink
\r
1674 * @param string $linktext text for content of anchor element
\r
1675 * @param integer $amount the amount of items in a display
\r
1676 * @param integer $recount increment from this value
\r
1679 public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
\r
1681 global $itemidnext, $archivenext, $startpos;
\r
1682 if ( $this->skintype == 'item' )
\r
1684 $this->itemlink($itemidnext, $linktext);
\r
1686 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
1688 $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
\r
1692 $this->archivelink($archivenext, $linktext);
\r
1698 * Actions::parse_nucleusbutton()
\r
1699 * Parse skinvar nucleusbutton
\r
1701 * @param string $imgurl URL for image
\r
1702 * @param integer $imgwidth width of image
\r
1703 * @param integer $imgheidht height of image
\r
1705 public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
\r
1708 if ( $imgurl == '' )
\r
1710 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
\r
1712 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
\r
1714 // when skindit IncludeMode is used: start from skindir
\r
1715 $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
\r
1718 $this->formdata = array(
\r
1719 'imgurl' => $imgurl,
\r
1720 'imgwidth' => $imgwidth,
\r
1721 'imgheight' => $imgheight,
\r
1723 $this->doForm('nucleusbutton');
\r
1728 * Actions::parse_otherarchive()
\r
1729 * Parse skinvar otherarchive
\r
1731 * @param string $blogname name of weblog
\r
1732 * @param string $template name of template
\r
1733 * @param string $category name of category
\r
1736 public function parse_otherarchive($blogname, $template, $category = '')
\r
1738 global $archive, $manager;
\r
1739 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
1740 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1741 $this->setBlogCategory($b, $category);
\r
1742 $this->preBlogContent('otherachive',$b);
\r
1743 $b->showArchive($template, $y, $m, $d);
\r
1744 $this->postBlogContent('otherachive',$b);
\r
1749 * Actions::parse_otherarchivedaylist()
\r
1750 * Parse skinvar otherarchivedaylist
\r
1752 * @param string $blogname name of weblog
\r
1753 * @param string $template name of template
\r
1754 * @param string $category name of category
\r
1755 * @param integer $limit the amount of items in a display
\r
1758 public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
\r
1761 if ( $category == 'all')
\r
1765 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1766 $this->setBlogCategory($b, $category);
\r
1767 $this->preBlogContent('otherarchivelist',$b);
\r
1768 $b->showArchiveList($template, 'day', $limit);
\r
1769 $this->postBlogContent('otherarchivelist',$b);
\r
1774 * Actions::parse_otherarchivelist()
\r
1775 * Parse skinvar otherarchivelist
\r
1777 * @param string $blogname name of weblog
\r
1778 * @param string $template name of template
\r
1779 * @param string $category name of category
\r
1780 * @param integer $limit the amount of items in a display
\r
1783 public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
\r
1786 if ( $category == 'all' )
\r
1790 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1791 $this->setBlogCategory($b, $category);
\r
1792 $this->preBlogContent('otherarchivelist',$b);
\r
1793 $b->showArchiveList($template, 'month', $limit);
\r
1794 $this->postBlogContent('otherarchivelist',$b);
\r
1799 * Actions::parse_otherarchiveyearlist()
\r
1800 * Parse skinvar otherarchiveyearlist
\r
1802 * @param string $blogname name of weblog
\r
1803 * @param string $template name of template
\r
1804 * @param string $category name of category
\r
1805 * @limit integer $limit the amount of items in a display
\r
1807 public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
\r
1810 if ( $category == 'all' )
\r
1814 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1815 $this->setBlogCategory($b, $category);
\r
1816 $this->preBlogContent('otherarchivelist',$b);
\r
1817 $b->showArchiveList($template, 'year', $limit);
\r
1818 $this->postBlogContent('otherarchivelist',$b);
\r
1823 * Actions::parse_otherblog()
\r
1824 * Parse skinvar otherblog
\r
1826 * @param string $blogname name of weblog
\r
1827 * @param string $template name of template
\r
1828 * @param mixed $amount the amount of items, in case it includes the beginning
\r
1829 * @param string $category name of category
\r
1832 public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
\r
1836 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1838 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1839 $this->setBlogCategory($b, $category);
\r
1840 $this->preBlogContent('otherblog',$b);
\r
1841 $this->amountfound = $b->readLog($template, $limit, $offset);
\r
1842 $this->postBlogContent('otherblog',$b);
\r
1847 * Actions::parse_othersearchresults()
\r
1848 * Parse skinvar othersearchresults
\r
1850 * @param string $blogname name of weblog
\r
1851 * @param string $template name of template
\r
1852 * @param integer $maxresults the amount of results
\r
1855 public function parse_othersearchresults($blogname, $template, $maxresults = 50)
\r
1857 global $query, $amount, $manager, $startpos;
\r
1858 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1859 // need this to select default category
\r
1860 $this->setBlogCategory($b, '');
\r
1861 $this->preBlogContent('othersearchresults',$b);
\r
1862 $b->search($query, $template, $amount, $maxresults, $startpos);
\r
1863 $this->postBlogContent('othersearchresults',$b);
\r
1868 * Actions::parse_plugin()
\r
1869 * Executes a plugin skinvar
\r
1870 * extra parameters can be added
\r
1872 * @param string $pluginName name of plugin (without the NP_)
\r
1875 public function parse_plugin($pluginName)
\r
1879 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
1886 $params = func_get_args();
\r
1888 // remove plugin name
\r
1889 array_shift($params);
\r
1891 // add skin type on front
\r
1892 array_unshift($params, $this->skintype);
\r
1894 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
\r
1899 * Actions::parse_prevarchive()
\r
1900 * Parse skinvar prevarchive
\r
1905 public function parse_prevarchive()
\r
1907 global $archiveprev;
\r
1908 echo $archiveprev;
\r
1912 * Actions::parse_preview()
\r
1913 * Parse skinvar preview
\r
1915 * @param string $template name of tempalte
\r
1918 public function parse_preview($template)
\r
1920 global $blog, $CONF, $manager;
\r
1922 $template =& $manager->getTemplate($template);
\r
1924 $row['body'] = '<span id="prevbody"></span>';
\r
1925 $row['title'] = '<span id="prevtitle"></span>';
\r
1926 $row['more'] = '<span id="prevmore"></span>';
\r
1927 $row['itemlink'] = '';
\r
1928 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
\r
1930 echo Template::fill($template['ITEM_HEADER'],$row);
\r
1931 echo Template::fill($template['ITEM'],$row);
\r
1932 echo Template::fill($template['ITEM_FOOTER'],$row);
\r
1937 * Actions::parse_previtem()
\r
1938 * Parse skinvar previtem
\r
1939 * (include itemid of prev item)
\r
1944 public function parse_previtem()
\r
1946 global $itemidprev;
\r
1947 if ( isset($itemidprev) )
\r
1949 echo (integer) $itemidprev;
\r
1955 * Actions::parse_previtemtitle()
\r
1956 * Parse skinvar previtemtitle
\r
1957 * (include itemtitle of prev item)
\r
1959 * @param String $format string format
\r
1960 * @return String formatted string
\r
1962 public function parse_previtemtitle($format = '')
\r
1964 global $itemtitleprev;
\r
1966 switch ( $format )
\r
1969 echo Entity::hen($itemtitleprev);
\r
1972 echo $itemtitleprev;
\r
1976 echo Entity::hsc($itemtitleprev);
\r
1983 * Actions::parse_prevlink()
\r
1984 * Parse skinvar prevlink
\r
1986 * @param string $linktext text as a content of anchor element
\r
1987 * @param integer the amount of links
\r
1990 public function parse_prevlink($linktext = '', $amount = 10)
\r
1992 global $itemidprev, $archiveprev, $startpos;
\r
1994 if ( $this->skintype == 'item' )
\r
1996 $this->itemlink($itemidprev, $linktext);
\r
1998 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
2000 $this->searchlink($amount, $startpos, 'prev', $linktext);
\r
2004 $this->archivelink($archiveprev, $linktext);
\r
2010 * Actions::parse_query()
\r
2011 * Parse skinvar query
\r
2012 * (includes the search query)
\r
2017 public function parse_query()
\r
2020 echo Entity::hsc($query);
\r
2025 * Actions::parse_referer()
\r
2026 * Parse skinvar referer
\r
2031 public function parse_referer()
\r
2033 echo Entity::hsc(serverVar('HTTP_REFERER'));
\r
2038 * Actions::parse_searchform()
\r
2039 * Parse skinvar searchform
\r
2041 * @param string $blogname name of weblog
\r
2044 public function parse_searchform($blogname = '')
\r
2046 global $CONF, $manager, $maxresults;
\r
2049 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
\r
2055 // use default blog when no blog is selected
\r
2056 $this->formdata = array(
\r
2057 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
\r
2058 'query' => Entity::hsc(getVar('query')),
\r
2060 $this->doForm('searchform');
\r
2065 * Actions::parse_searchresults()
\r
2066 * Parse skinvar searchresults
\r
2068 * @param string $template name of tempalte
\r
2069 * @param integer $maxresults searched items in a display
\r
2072 public function parse_searchresults($template, $maxresults = 50 )
\r
2074 global $blog, $query, $amount, $startpos;
\r
2076 $this->setBlogCategory($blog, ''); // need this to select default category
\r
2077 $this->preBlogContent('searchresults',$blog);
\r
2078 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
\r
2079 $this->postBlogContent('searchresults',$blog);
\r
2084 * Actions::parse_self()
\r
2085 * Parse skinvar self
\r
2090 public function parse_self()
\r
2093 echo $CONF['Self'];
\r
2098 * Actions::parse_sitevar()
\r
2099 * Parse skinvar sitevar
\r
2100 * (include a sitevar)
\r
2102 * @param string $which
\r
2105 public function parse_sitevar($which)
\r
2111 echo $CONF['IndexURL'];
\r
2114 echo $CONF['SiteName'];
\r
2117 echo $CONF['AdminEmail'];
\r
2120 echo $CONF['AdminURL'];
\r
2126 * Actions::parse_skinname()
\r
2132 public function parse_skinname()
\r
2134 echo $this->skin->getName();
\r
2139 * Actions::parse_skintype()
\r
2140 * Parse skintype (experimental)
\r
2145 public function parse_skintype()
\r
2147 echo $this->skintype;
\r
2152 * Actions::parse_ticket()
\r
2158 public function parse_ticket()
\r
2161 $manager->addTicketHidden();
\r
2166 * Actions::parse_todaylink()
\r
2167 * Parse skinvar todaylink
\r
2168 * A link to the today page (depending on selected blog, etc...)
\r
2170 * @param string $linktext text for link
\r
2173 public function parse_todaylink($linktext = '')
\r
2175 global $blog, $CONF;
\r
2178 echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
\r
2182 echo $this->link($CONF['SiteUrl'], $linktext);
\r
2189 * When commentform is not used, to include a hidden field with itemid
\r
2194 public function parse_vars()
\r
2197 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
\r
2202 * Actions::parse_version()
\r
2203 * Parse skinvar version
\r
2204 * (include nucleus versionnumber)
\r
2209 public function parse_version()
\r
2212 echo 'Nucleus CMS ' . $nucleus['version'];
\r
2217 * Actions::parse_sticky()
\r
2218 * Parse skinvar sticky
\r
2220 * @param integer $itemnumber id of item
\r
2221 * @param string $template name of template
\r
2224 public function parse_sticky($itemnumber = 0, $template = '')
\r
2228 $itemnumber = intval($itemnumber);
\r
2229 $itemarray = array($itemnumber);
\r
2231 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
\r
2232 $this->preBlogContent('sticky',$b);
\r
2233 $this->amountfound = $b->readLogFromList($itemarray, $template);
\r
2234 $this->postBlogContent('sticky',$b);
\r