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
57 'otherarchivedaylist',
\r
59 'otherarchiveyearlist',
\r
70 // deprecated (Nucleus v2.0)
\r
71 /* TODO: remove this */
\r
76 * Actions::$skin_type_friendly_names
\r
77 * friendly name for wrapped page types
\r
79 static public $default_skin_types = array(
\r
80 'index' => _SKIN_PART_MAIN,
\r
81 'item' => _SKIN_PART_ITEM,
\r
82 'archivelist' => _SKIN_PART_ALIST,
\r
83 'archive' => _SKIN_PART_ARCHIVE,
\r
84 'search' => _SKIN_PART_SEARCH,
\r
85 'error' => _SKIN_PART_ERROR,
\r
86 'member' => _SKIN_PART_MEMBER,
\r
87 'imagepopup' => _SKIN_PART_POPUP
\r
91 * Actions::getAvailableSkinTypes()
\r
95 * @return array list of friendly names for page actions
\r
97 static public function getAvailableSkinTypes()
\r
99 return self::$default_skin_types;
\r
103 * Actions::__construct()
\r
104 * Constructor for a new Actions object
\r
106 * @param string $type
\r
109 public function __construct($type)
\r
113 // call constructor of superclass first
\r
114 parent::__construct();
\r
115 $this->skintype = $type;
\r
119 $this->linkparams = array('catid' => $catid);
\r
125 * Actions::getAvailableActions()
\r
128 * @return array allowed actions for the page type
\r
130 public function getAvailableActions()
\r
132 $extra_actions = array();
\r
134 switch ( $this->skintype )
\r
137 $extra_actions = array(
\r
151 $extra_actions = array(
\r
168 case 'archivelist':
\r
169 $extra_actions = array(
\r
179 $extra_actions = array(
\r
186 'othersearchresults',
\r
194 $extra_actions = array(
\r
196 // deprecated (Nucleus v2.0)
\r
197 /* TODO: remove this */
\r
202 $extra_actions = array(
\r
210 $extra_actions = array(
\r
233 $extra_actions = array(
\r
239 $extra_actions = array(
\r
257 $defined_actions = array_merge(self::$default_actions, $extra_actions);
\r
259 return array_merge($defined_actions, parent::getAvailableActions());
\r
263 * Actions::setSkin()
\r
265 * @param object $skin an instance of Skin class
\r
268 public function setSkin(&$skin)
\r
270 $this->skin =& $skin;
\r
275 * Actions::doForm()
\r
276 * Forms get parsedincluded now, using an extra <formdata> skinvar
\r
278 * @param string $filename
\r
281 public function doForm($filename)
\r
283 global $DIR_NUCLEUS;
\r
284 array_push($this->parser->actions,'formdata', 'callback','errordiv','ticket');
\r
286 $oldIncludeMode = Parser::getProperty('IncludeMode');
\r
287 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
\r
288 Parser::setProperty('IncludeMode','normal');
\r
289 Parser::setProperty('IncludePrefix','');
\r
291 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
\r
292 Parser::setProperty('IncludeMode',$oldIncludeMode);
\r
293 Parser::setProperty('IncludePrefix',$oldIncludePrefix);
\r
295 array_pop($this->parser->actions); // errordiv
\r
296 array_pop($this->parser->actions); // callback
\r
297 array_pop($this->parser->actions); // formdata
\r
298 array_pop($this->parser->actions); // ticket
\r
303 * Actions::checkCondition()
\r
304 * Checks conditions for if statements
\r
306 * @param string $field type of <%if%>
\r
307 * @param string $name property of field
\r
308 * @param string $value value of property
\r
309 * @return boolean condition
\r
311 protected function checkCondition($field, $name='', $value = '')
\r
313 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
319 $condition = ($blog && $this->ifCategory($name,$value));
\r
321 case 'blogsetting':
\r
322 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
325 $condition = $member->isLoggedIn();
\r
328 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
\r
331 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
\r
334 $condition = ($itemidnext != '');
\r
337 $condition = ($itemidprev != '');
\r
339 case 'archiveprevexists':
\r
340 $condition = ($archiveprevexists == true);
\r
342 case 'archivenextexists':
\r
343 $condition = ($archivenextexists == true);
\r
346 $condition = (($name == $this->skintype) || ($name == requestVar('action')));
\r
349 $condition = $this->ifHasPlugin($name, $value);
\r
352 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);
\r
359 * Actions::_ifHasPlugin()
\r
360 * hasplugin,PlugName
\r
361 * -> checks if plugin exists
\r
362 * hasplugin,PlugName,OptionName
\r
363 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
364 * hasplugin,PlugName,OptionName=value
\r
365 * -> checks if the option OptionName from plugin PlugName is set to value
\r
367 * @param string $name name of plugin
\r
368 * @param string $value
\r
371 private function ifHasPlugin($name, $value)
\r
374 $condition = false;
\r
375 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
376 if ( $manager->pluginInstalled("NP_{$name}") )
\r
378 $plugin =& $manager->getPlugin("NP_{$name}");
\r
379 if ( $plugin != NULL )
\r
381 if ( $value == "" )
\r
387 list($name2, $value2) = preg_split('#=#', $value, 2);
\r
388 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
\r
392 else if ( $plugin->getOption($name2) == $value2 )
\r
403 * Actions::ifPlugin()
\r
404 * Checks if a plugin exists and call its doIf function
\r
406 * @param string $name name of plugin
\r
407 * @param string $key name of plugin option
\r
408 * @param string $value value of plugin option
\r
411 private function ifPlugin($name, $key = '', $value = '')
\r
415 $plugin =& $manager->getPlugin("NP_{$name}");
\r
421 $params = func_get_args();
\r
422 array_shift($params);
\r
424 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r
428 * Actions::ifCategory()
\r
429 * Different checks for a category
\r
431 * @param string $name
\r
432 * @param string $value
\r
435 private function ifCategory($name = '', $value='')
\r
437 global $blog, $catid;
\r
439 // when no parameter is defined, just check if a category is selected
\r
440 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )
\r
442 return $blog->isValidCategory($catid);
\r
445 // check category name
\r
446 if ( $name == 'catname' )
\r
448 $value = $blog->getCategoryIdFromName($value);
\r
449 if ( $value == $catid )
\r
451 return $blog->isValidCategory($catid);
\r
455 // check category id
\r
456 if ( ($name == 'catid') && ($value == $catid) )
\r
458 return $blog->isValidCategory($catid);
\r
464 * Actions::ifOnTeam()
\r
465 * Checks if a member is on the team of a blog and return his rights
\r
467 * @param string $blogName name of weblog
\r
470 private function ifOnTeam($blogName = '')
\r
472 global $blog, $member, $manager;
\r
474 // when no blog found
\r
475 if ( ($blogName == '') && !is_object($blog) )
\r
480 // explicit blog selection
\r
481 if ( $blogName != '' )
\r
483 $blogid = getBlogIDFromName($blogName);
\r
486 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
488 // use current blog
\r
489 $blogid = $blog->getID();
\r
492 return $member->teamRights($blogid);
\r
496 * Actions::ifAdmin()
\r
497 * Checks if a member is admin of a blog
\r
499 * @param string $blogName name of weblog
\r
502 private function ifAdmin($blogName = '')
\r
504 global $blog, $member, $manager;
\r
506 // when no blog found
\r
507 if ( ($blogName == '') && (!is_object($blog)) )
\r
512 // explicit blog selection
\r
513 if ( $blogName != '' )
\r
515 $blogid = getBlogIDFromName($blogName);
\r
518 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
520 // use current blog
\r
521 $blogid = $blog->getID();
\r
524 return $member->isBlogAdmin($blogid);
\r
530 * - a raw link (html/xml encoded) when no linktext is provided
\r
531 * - a (x)html <a href... link when a text is present (text htmlencoded)
\r
533 * @param string $url URL for href attribute of anchor element
\r
534 * @param string $linktext content of anchor element
\r
537 private function link($url, $linktext = '')
\r
539 $u = Entity::hsc($url);
\r
540 // fix URLs that already had encoded ampersands
\r
541 $u = preg_replace("#&amp;#", '&', $u);
\r
542 if ( $linktext != '' )
\r
544 $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';
\r
554 * Actions::searchlink()
\r
555 * Outputs a next/prev link
\r
557 * @param $maxresults
\r
558 * The maximum amount of items shown per page (e.g. 10)
\r
560 * Current start position (requestVar('startpos'))
\r
561 * @param $direction
\r
562 * either 'prev' or 'next'
\r
564 * When present, the output will be a full <a href...> link. When empty,
\r
565 * only a raw link will be outputted
\r
567 private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')
\r
569 global $CONF, $blog, $query, $amount;
\r
570 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
\r
571 $startpos = (integer) $startpos;
\r
572 $parsed = parse_url(serverVar('REQUEST_URI'));
\r
573 $path = $parsed['path'];
\r
574 $parsed = $parsed['query'];
\r
577 if ( $direction == 'prev' )
\r
579 if ( intval($startpos) - intval($maxresults) >= 0 )
\r
581 $startpos = intval($startpos) - intval($maxresults);
\r
583 if ( $this->skintype == 'index' )
\r
587 else if ( $this->skintype == 'search' )
\r
589 $url = $CONF['SearchURL'];
\r
591 $url .= '?' . alterQueryStr($parsed,'startpos',$startpos);
\r
594 else if ( $direction == 'next' )
\r
596 global $navigationItems;
\r
597 if ( !isset($navigationItems) )
\r
599 $navigationItems = 0;
\r
604 $iAmountOnPage = 0;
\r
608 $iAmountOnPage = $this->amountfound;
\r
611 if ( intval($navigationItems) > 0 )
\r
613 $iAmountOnPage = intval($navigationItems) - intval($startpos);
\r
615 elseif ( $iAmountOnPage == 0 )
\r
618 * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
\r
619 * try a count query
\r
621 if ( $this->skintype == 'index' )
\r
623 $sqlquery = $blog->getSqlBlog('', 'count');
\r
626 else if ( $this->skintype == 'search' )
\r
628 $unused_highlight = '';
\r
629 $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
\r
630 $url = $CONF['SearchURL'];
\r
634 $iAmountOnPage = intval(DB::getValue($sqlquery)) - intval($startpos);
\r
639 if ( intval($iAmountOnPage) >= intval($maxresults) )
\r
641 $startpos = intval($startpos) + intval($maxresults);
\r
642 $url .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
\r
648 echo $this->link($url, $linktext);
\r
654 * Actions::itemlink()
\r
655 * Creates an item link and if no id is given a todaylink
\r
657 * @param integer $id id for link
\r
658 * @param string $linktext text for link
\r
661 private function itemlink($id, $linktext = '')
\r
666 echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);
\r
670 $this->parse_todaylink($linktext);
\r
676 * Actions::archivelink)
\r
677 * Creates an archive link and if no id is given a todaylink
\r
679 * @param integer $id id for link
\r
680 * @param string $linktext text for link
\r
683 private function archivelink($id, $linktext = '')
\r
685 global $CONF, $blog;
\r
688 echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
\r
692 $this->parse_todaylink($linktext);
\r
698 * Actions:setBlogCategory()
\r
699 * Helper function that sets the category that a blog will need to use
\r
701 * @param string $blog An object of the blog class, passed by reference (we want to make changes to it)
\r
702 * @param string $catname The name of the category to use
\r
705 private function setBlogCategory(&$blog, $catname)
\r
708 if ( $catname != '' )
\r
710 $blog->setSelectedCategoryByName($catname);
\r
714 $blog->setSelectedCategory($catid);
\r
720 * Actions::preBlogContent()
\r
721 * Notifies the Manager that a PreBlogContent event occurs
\r
723 * @param string $type type of skin
\r
724 * @param object $blog an instance of Blog class
\r
727 private function preBlogContent($type, &$blog)
\r
730 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
\r
735 * Actions::postBlogContent()
\r
736 * Notifies the Manager that a PostBlogContent event occurs
\r
738 * @param string $type type of skin
\r
739 * @param objecct $blog an instance of Blog class
\r
742 private function postBlogContent($type, &$blog)
\r
745 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
\r
750 * Actions::parse_additemform()
\r
751 * Parse skinvar additemform
\r
756 public function parse_additemform()
\r
758 global $blog, $CONF;
\r
759 $this->formdata = array(
\r
760 'adminurl' => Entity::hsc($CONF['AdminURL']),
\r
761 'catid' => $blog->getDefaultCategory()
\r
763 $blog->InsertJavaScriptInfo();
\r
764 $this->doForm('additemform');
\r
769 * Actions::parse_addlink()
\r
770 * Parse skinvar addlink
\r
771 * A Link that allows to open a bookmarklet to add an item
\r
773 public function parse_addlink()
\r
775 global $CONF, $member, $blog;
\r
776 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
\r
778 echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
\r
784 * Actions::parse_addpopupcode()
\r
785 * Parse skinvar addpopupcode
\r
786 * Code that opens a bookmarklet in an popup window
\r
791 public function parse_addpopupcode()
\r
793 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
798 * Parse skinvar adminurl
\r
799 * (shortcut for admin url)
\r
804 public function parse_adminurl()
\r
806 $this->parse_sitevar('adminurl');
\r
811 * Actions::parse_archive()
\r
812 * Parse skinvar archive
\r
814 * @param string $template name of template
\r
815 * @param string $category name of category
\r
818 public function parse_archive($template, $category = '')
\r
820 global $blog, $archive;
\r
821 // can be used with either yyyy-mm or yyyy-mm-dd
\r
822 sscanf($archive,'%d-%d-%d', $y, $m, $d);
\r
823 $this->setBlogCategory($blog, $category);
\r
824 $this->preBlogContent('achive',$blog);
\r
825 $blog->showArchive($template, $y, $m, $d);
\r
826 $this->postBlogContent('achive',$blog);
\r
831 * Actions::parse_archivedate()
\r
832 * %archivedate(locale,date format)%
\r
834 * @param string $locale
\r
837 public function parse_archivedate($locale = '-def-')
\r
842 * TODO: these lines are no meaning because there is no $template.
\r
843 if ( $locale == '-def-' )
\r
845 setlocale(LC_TIME, $template['LOCALE']);
\r
849 setlocale(LC_TIME, $locale);
\r
853 // get archive date
\r
854 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
857 $args = func_get_args();
\r
858 // format can be spread over multiple parameters
\r
859 if ( sizeof($args) > 1 )
\r
861 // take away locale
\r
862 array_shift($args);
\r
864 $format=implode(',',$args);
\r
866 elseif ( $d == 0 && $m !=0 )
\r
876 $format = '%d %B %Y';
\r
878 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
\r
883 * Actions::parse_archivedaylist()
\r
884 * Parse skinvar archivedaylist
\r
886 * @param string $template name of template
\r
887 * @param string $category name of category
\r
888 * @param integer $limit the number of items in a display
\r
891 public function parse_archivedaylist($template, $category = 'all', $limit = 0)
\r
894 if ( $category == 'all' )
\r
898 $this->preBlogContent('archivelist',$blog);
\r
899 $this->setBlogCategory($blog, $category);
\r
900 $blog->showArchiveList($template, 'day', $limit);
\r
901 $this->postBlogContent('archivelist',$blog);
\r
906 * Actions::parse_archivelink()
\r
907 * A link to the archives for the current blog (or for default blog)
\r
909 * @param string $linktext text for link
\r
912 public function parse_archivelink($linktext = '')
\r
914 global $blog, $CONF;
\r
917 echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
\r
921 echo $this->link(Link::create_archivelist_link(), $linktext);
\r
927 * Actions::parse_archivelist()
\r
929 * @param string $template name of template
\r
930 * @param string $category name of category
\r
931 * @param integer $limit the number of items in a display
\r
934 public function parse_archivelist($template, $category = 'all', $limit = 0)
\r
937 if ( $category == 'all' )
\r
941 $this->preBlogContent('archivelist',$blog);
\r
942 $this->setBlogCategory($blog, $category);
\r
943 $blog->showArchiveList($template, 'month', $limit);
\r
944 $this->postBlogContent('archivelist',$blog);
\r
949 * Actions::parse_archiveyearlist()
\r
951 * @param string $template name of template
\r
952 * @param string $category name of category
\r
953 * @param integer $limit the number of items in a display
\r
955 public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
\r
958 if ( $category == 'all' )
\r
962 $this->preBlogContent('archivelist',$blog);
\r
963 $this->setBlogCategory($blog, $category);
\r
964 $blog->showArchiveList($template, 'year', $limit);
\r
965 $this->postBlogContent('archivelist',$blog);
\r
970 * Actions::parse_archivetype()
\r
971 * Parse skinvar archivetype
\r
976 public function parse_archivetype()
\r
978 global $archivetype;
\r
984 * Actions::parse_blog()
\r
985 * Parse skinvar blog
\r
987 * @param string $template name of template
\r
988 * @param mixed $amount the number of items in a display, in case it includes the beginning
\r
989 * @param string $category name of category
\r
992 public function parse_blog($template, $amount = 10, $category = '')
\r
994 global $blog, $startpos;
\r
996 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
997 $this->setBlogCategory($blog, $category);
\r
998 $this->preBlogContent('blog',$blog);
\r
999 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
\r
1000 $this->postBlogContent('blog',$blog);
\r
1005 * Actions::parse_bloglist()
\r
1006 * Parse skinvar bloglist
\r
1007 * Shows a list of all blogs
\r
1009 * @param string $template name of template
\r
1010 * @param string $bnametype whether 'name' or 'shortname' is used for the link text
\r
1011 * @param string $orderby order criteria
\r
1012 * @param string $direction order ascending or descending
\r
1015 public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
\r
1017 Blog::showBlogList($template, $bnametype, $orderby, $direction);
\r
1022 * Actions::parse_blogsetting()
\r
1023 * Parse skinvar blogsetting
\r
1025 * @param string $which key of weblog settings
\r
1028 public function parse_blogsetting($which)
\r
1034 echo Entity::hsc($blog->getID());
\r
1037 echo Entity::hsc($blog->getURL());
\r
1040 echo Entity::hsc($blog->getName());
\r
1043 echo Entity::hsc($blog->getDescription());
\r
1046 echo Entity::hsc($blog->getShortName());
\r
1053 * Actions::parse_callback()
\r
1056 * @param string $eventName name of event
\r
1057 * @param string $type type of skin
\r
1060 public function parse_callback($eventName, $type)
\r
1063 $manager->notify($eventName, array('type' => $type));
\r
1068 * Actions::parse_category()
\r
1069 * Parse skinvar category
\r
1071 * @param string $type key of category settings
\r
1074 public function parse_category($type = 'name')
\r
1076 global $catid, $blog;
\r
1077 if ( !$blog->isValidCategory($catid) )
\r
1085 echo $blog->getCategoryName($catid);
\r
1088 echo $blog->getCategoryDesc($catid);
\r
1098 * Actions::parse_categorylist()
\r
1099 * Parse categorylist
\r
1101 * @param string $template name of template
\r
1102 * @param string $blogname name of weblog
\r
1105 public function parse_categorylist($template, $blogname = '')
\r
1107 global $blog, $manager;
\r
1109 // when no blog found
\r
1110 if ( ($blogname == '') && (!is_object($blog)) )
\r
1115 if ( $blogname == '' )
\r
1117 $this->preBlogContent('categorylist',$blog);
\r
1118 $blog->showCategoryList($template);
\r
1119 $this->postBlogContent('categorylist',$blog);
\r
1123 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1124 $this->preBlogContent('categorylist',$b);
\r
1125 $b->showCategoryList($template);
\r
1126 $this->postBlogContent('categorylist',$b);
\r
1132 * Actions::parse_commentform()
\r
1133 * Parse skinvar commentform
\r
1135 * @param string $destinationurl URI for redirection
\r
1138 public function parse_commentform($destinationurl = '')
\r
1140 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
\r
1142 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
\r
1143 if ( stristr($destinationurl, 'action.php') )
\r
1145 $args = func_get_args();
\r
1146 $destinationurl = $args[1];
\r
1147 ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
\r
1150 $actionurl = $CONF['ActionURL'];
\r
1152 // if item is closed, show message and do nothing
\r
1153 $item =& $manager->getItem($itemid,0,0);
\r
1154 if ( $item['closed'] || !$blog->commentsEnabled() )
\r
1156 $this->doForm('commentform-closed');
\r
1160 if ( !$blog->isPublic() && !$member->isLoggedIn() )
\r
1162 $this->doForm('commentform-closedtopublic');
\r
1166 if ( !$destinationurl )
\r
1168 // note: createLink returns an HTML encoded URL
\r
1169 $destinationurl = Link::create_link(
\r
1172 'itemid' => $itemid,
\r
1173 'title' => $item['title'],
\r
1174 'timestamp' => $item['timestamp'],
\r
1175 'extra' => $this->linkparams
\r
1181 // HTML encode URL
\r
1182 $destinationurl = Entity::hsc($destinationurl);
\r
1185 // values to prefill
\r
1186 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
\r
1189 $user = postVar('user');
\r
1192 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
\r
1195 $userid = postVar('userid');
\r
1198 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
\r
1201 $email = postVar('email');
\r
1204 $body = postVar('body');
\r
1206 $this->formdata = array(
\r
1207 'destinationurl' => $destinationurl, // url is already HTML encoded
\r
1208 'actionurl' => Entity::hsc($actionurl),
\r
1209 'itemid' => $itemid,
\r
1210 'user' => Entity::hsc($user),
\r
1211 'userid' => Entity::hsc($userid),
\r
1212 'email' => Entity::hsc($email),
\r
1213 'body' => Entity::hsc($body),
\r
1214 'membername' => $member->getDisplayName(),
\r
1215 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
\r
1218 if ( !$member->isLoggedIn() )
\r
1220 $this->doForm('commentform-notloggedin');
\r
1224 $this->doForm('commentform-loggedin');
\r
1230 * Actions::parse_comments()
\r
1231 * Parse skinvar comments
\r
1232 * include comments for one item
\r
1234 * @param string $template name of template
\r
1237 public function parse_comments($template)
\r
1239 global $itemid, $manager, $blog, $highlight;
\r
1241 $template =& $manager->getTemplate($template);
\r
1242 $item = Item::getitem($itemid, 0, 0);
\r
1244 // create parser object & action handler
\r
1245 $handler = new ItemActions($blog);
\r
1246 $handler->setTemplate($template);
\r
1247 $handler->setCurrentItem($item);
\r
1249 $parser = new Parser($handler);
\r
1251 $comments = new Comments($itemid);
\r
1252 $comments->setItemActions($handler);
\r
1253 // shows ALL comments
\r
1254 $comments->showComments($template, -1, 1, $highlight);
\r
1259 * Actions::parse_errordiv()
\r
1265 public function parse_errordiv()
\r
1267 global $errormessage;
\r
1268 if ( $errormessage )
\r
1270 echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
\r
1276 * Actions::parse_errormessage()
\r
1277 * Parse skinvar errormessage
\r
1282 public function parse_errormessage()
\r
1284 global $errormessage;
\r
1285 echo $errormessage;
\r
1290 * Actions::parse_formdata()
\r
1293 * @param string $what key of format data
\r
1296 public function parse_formdata($what)
\r
1298 echo $this->formdata[$what];
\r
1303 * Actions::parse_ifcat()
\r
1306 * @param string $text
\r
1309 public function parse_ifcat($text = '')
\r
1311 if ( $text == '' )
\r
1314 $this->parse_if('category');
\r
1319 global $catid, $blog;
\r
1320 if ( $blog->isValidCategory($catid) )
\r
1329 * Actions::parse_image()
\r
1330 * Parse skinvar image
\r
1332 * @param string $what name of tag
\r
1335 public function parse_image($what = 'imgtag')
\r
1339 $imagetext = Entity::hsc(requestVar('imagetext'));
\r
1340 $imagepopup = requestVar('imagepopup');
\r
1341 $width = intRequestVar('width');
\r
1342 $height = intRequestVar('height');
\r
1343 $fullurl = Entity::hsc($CONF['MediaURL'] . $imagepopup);
\r
1362 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
\r
1369 * Actions::parse_imagetext()
\r
1370 * Parse skinvar imagetext
\r
1375 public function parse_imagetext()
\r
1377 $this->parse_image('imagetext');
\r
1382 * Actions::parse_item()
\r
1383 * Parse skinvar item
\r
1384 * include one item (no comments)
\r
1389 public function parse_item($template)
\r
1391 global $blog, $itemid, $highlight;
\r
1393 // need this to select default category
\r
1394 $this->setBlogCategory($blog, '');
\r
1395 $this->preBlogContent('item',$blog);
\r
1396 $r = $blog->showOneitem($itemid, $template, $highlight);
\r
1399 echo _ERROR_NOSUCHITEM;
\r
1401 $this->postBlogContent('item',$blog);
\r
1406 * Actions::parse_itemid()
\r
1407 * Parse skinvar itemid
\r
1412 public function parse_itemid()
\r
1420 * Actions::parseitemlink()
\r
1421 * Parse skinvar itemlink
\r
1426 public function parse_itemlink($linktext = '')
\r
1429 $this->itemlink($itemid, $linktext);
\r
1434 * Actions::parse_itemtitle()
\r
1440 public function parse_itemtitle($format = '')
\r
1442 global $manager, $itemid;
\r
1443 $item =& $manager->getItem($itemid,0,0);
\r
1445 switch ( $format )
\r
1448 echo Entity::hen($item['title']);
\r
1451 echo $item['title'];
\r
1455 echo Entity::hsc(strip_tags($item['title']));
\r
1462 * Actions::parse_loginform()
\r
1463 * Parse skinvar loginform
\r
1468 public function parse_loginform()
\r
1470 global $member, $CONF;
\r
1471 if ( !$member->isLoggedIn() )
\r
1473 $filename = 'loginform-notloggedin';
\r
1474 $this->formdata = array();
\r
1478 $filename = 'loginform-loggedin';
\r
1479 $this->formdata = array(
\r
1480 'membername' => $member->getDisplayName(),
\r
1483 $this->doForm($filename);
\r
1488 * Actions::parse_member()
\r
1489 * Parse skinvar member
\r
1490 * (includes a member info thingie)
\r
1492 * @param string $what which memberdata is needed
\r
1495 public function parse_member($what)
\r
1497 global $memberinfo, $member, $CONF;
\r
1499 // 1. only allow the member-details-page specific variables on member pages
\r
1500 if ( $this->skintype == 'member' )
\r
1505 echo Entity::hsc($memberinfo->getDisplayName());
\r
1508 echo Entity::hsc($memberinfo->getRealName());
\r
1511 echo Entity::hsc($memberinfo->getNotes());
\r
1514 echo Entity::hsc($memberinfo->getURL());
\r
1517 echo Entity::hsc($memberinfo->getEmail());
\r
1520 echo Entity::hsc($memberinfo->getID());
\r
1525 // 2. the next bunch of options is available everywhere, as long as the user is logged in
\r
1526 if ( $member->isLoggedIn() )
\r
1531 echo $member->getDisplayName();
\r
1533 case 'yourrealname':
\r
1534 echo $member->getRealName();
\r
1537 echo $member->getNotes();
\r
1540 echo $member->getURL();
\r
1543 echo $member->getEmail();
\r
1546 echo $member->getID();
\r
1548 case 'yourprofileurl':
\r
1549 if ($CONF['URLMode'] == 'pathinfo')
\r
1550 echo Link::create_member_link($member->getID());
\r
1552 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
\r
1560 * Link::parse_membermailform()
\r
1561 * Parse skinvar membermailform
\r
1563 * @param integer $rows the height for textarea
\r
1564 * @param integer $cols the width for textarea
\r
1565 * @param string $desturl URI to redirect
\r
1568 public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
\r
1570 global $member, $CONF, $memberid;
\r
1572 if ( $desturl == '' )
\r
1574 if ( $CONF['URLMode'] == 'pathinfo' )
\r
1576 $desturl = Link::create_member_link($memberid);
\r
1580 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
\r
1584 $message = postVar('message');
\r
1585 $frommail = postVar('frommail');
\r
1587 $this->formdata = array(
\r
1588 'url' => Entity::hsc($desturl),
\r
1589 'actionurl' => Entity::hsc($CONF['ActionURL']),
\r
1590 'memberid' => $memberid,
\r
1593 'message' => Entity::hsc($message),
\r
1594 'frommail' => Entity::hsc($frommail)
\r
1597 if ( $member->isLoggedIn() )
\r
1599 $this->doForm('membermailform-loggedin');
\r
1601 else if ( $CONF['NonmemberMail'] )
\r
1603 $this->doForm('membermailform-notloggedin');
\r
1607 $this->doForm('membermailform-disallowed');
\r
1613 * Actions::parse_nextarchive()
\r
1614 * Parse skinvar nextarchive
\r
1619 public function parse_nextarchive()
\r
1621 global $archivenext;
\r
1622 echo $archivenext;
\r
1627 * Parse skinvar nextitem
\r
1628 * (include itemid of next item)
\r
1633 public function parse_nextitem()
\r
1635 global $itemidnext;
\r
1636 if ( isset($itemidnext) )
\r
1638 echo (int)$itemidnext;
\r
1644 * Actions::parse_nextitemtitle()
\r
1645 * Parse skinvar nextitemtitle
\r
1646 * (include itemtitle of next item)
\r
1648 * @param string $format format of text
\r
1651 public function parse_nextitemtitle($format = '')
\r
1653 global $itemtitlenext;
\r
1655 switch ( $format )
\r
1658 echo Entity::hen($itemtitlenext);
\r
1661 echo $itemtitlenext;
\r
1665 echo Entity::hsc($itemtitlenext);
\r
1672 * Actions::parse_nextlink()
\r
1673 * Parse skinvar nextlink
\r
1675 * @param string $linktext text for content of anchor element
\r
1676 * @param integer $amount the amount of items in a display
\r
1677 * @param integer $recount increment from this value
\r
1680 public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
\r
1682 global $itemidnext, $archivenext, $startpos;
\r
1683 if ( $this->skintype == 'item' )
\r
1685 $this->itemlink($itemidnext, $linktext);
\r
1687 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
1689 $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
\r
1693 $this->archivelink($archivenext, $linktext);
\r
1699 * Actions::parse_nucleusbutton()
\r
1700 * Parse skinvar nucleusbutton
\r
1702 * @param string $imgurl URL for image
\r
1703 * @param integer $imgwidth width of image
\r
1704 * @param integer $imgheidht height of image
\r
1706 public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
\r
1709 if ( $imgurl == '' )
\r
1711 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
\r
1713 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
\r
1715 // when skindit IncludeMode is used: start from skindir
\r
1716 $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
\r
1719 $this->formdata = array(
\r
1720 'imgurl' => $imgurl,
\r
1721 'imgwidth' => $imgwidth,
\r
1722 'imgheight' => $imgheight,
\r
1724 $this->doForm('nucleusbutton');
\r
1729 * Actions::parse_otherarchive()
\r
1730 * Parse skinvar otherarchive
\r
1732 * @param string $blogname name of weblog
\r
1733 * @param string $template name of template
\r
1734 * @param string $category name of category
\r
1737 public function parse_otherarchive($blogname, $template, $category = '')
\r
1739 global $archive, $manager;
\r
1740 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
1741 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1742 $this->setBlogCategory($b, $category);
\r
1743 $this->preBlogContent('otherachive',$b);
\r
1744 $b->showArchive($template, $y, $m, $d);
\r
1745 $this->postBlogContent('otherachive',$b);
\r
1750 * Actions::parse_otherarchivedaylist()
\r
1751 * Parse skinvar otherarchivedaylist
\r
1753 * @param string $blogname name of weblog
\r
1754 * @param string $template name of template
\r
1755 * @param string $category name of category
\r
1756 * @param integer $limit the amount of items in a display
\r
1759 public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
\r
1762 if ( $category == 'all')
\r
1766 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1767 $this->setBlogCategory($b, $category);
\r
1768 $this->preBlogContent('otherarchivelist',$b);
\r
1769 $b->showArchiveList($template, 'day', $limit);
\r
1770 $this->postBlogContent('otherarchivelist',$b);
\r
1775 * Actions::parse_otherarchivelist()
\r
1776 * Parse skinvar otherarchivelist
\r
1778 * @param string $blogname name of weblog
\r
1779 * @param string $template name of template
\r
1780 * @param string $category name of category
\r
1781 * @param integer $limit the amount of items in a display
\r
1784 public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
\r
1787 if ( $category == 'all' )
\r
1791 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1792 $this->setBlogCategory($b, $category);
\r
1793 $this->preBlogContent('otherarchivelist',$b);
\r
1794 $b->showArchiveList($template, 'month', $limit);
\r
1795 $this->postBlogContent('otherarchivelist',$b);
\r
1800 * Actions::parse_otherarchiveyearlist()
\r
1801 * Parse skinvar otherarchiveyearlist
\r
1803 * @param string $blogname name of weblog
\r
1804 * @param string $template name of template
\r
1805 * @param string $category name of category
\r
1806 * @limit integer $limit the amount of items in a display
\r
1808 public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
\r
1811 if ( $category == 'all' )
\r
1815 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1816 $this->setBlogCategory($b, $category);
\r
1817 $this->preBlogContent('otherarchivelist',$b);
\r
1818 $b->showArchiveList($template, 'year', $limit);
\r
1819 $this->postBlogContent('otherarchivelist',$b);
\r
1824 * Actions::parse_otherblog()
\r
1825 * Parse skinvar otherblog
\r
1827 * @param string $blogname name of weblog
\r
1828 * @param string $template name of template
\r
1829 * @param mixed $amount the amount of items, in case it includes the beginning
\r
1830 * @param string $category name of category
\r
1833 public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
\r
1837 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1839 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1840 $this->setBlogCategory($b, $category);
\r
1841 $this->preBlogContent('otherblog',$b);
\r
1842 $this->amountfound = $b->readLog($template, $limit, $offset);
\r
1843 $this->postBlogContent('otherblog',$b);
\r
1848 * Actions::parse_othersearchresults()
\r
1849 * Parse skinvar othersearchresults
\r
1851 * @param string $blogname name of weblog
\r
1852 * @param string $template name of template
\r
1853 * @param integer $maxresults the amount of results
\r
1856 public function parse_othersearchresults($blogname, $template, $maxresults = 50)
\r
1858 global $query, $amount, $manager, $startpos;
\r
1859 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1860 // need this to select default category
\r
1861 $this->setBlogCategory($b, '');
\r
1862 $this->preBlogContent('othersearchresults',$b);
\r
1863 $b->search($query, $template, $amount, $maxresults, $startpos);
\r
1864 $this->postBlogContent('othersearchresults',$b);
\r
1869 * Actions::parse_plugin()
\r
1870 * Executes a plugin skinvar
\r
1871 * extra parameters can be added
\r
1873 * @param string $pluginName name of plugin (without the NP_)
\r
1876 public function parse_plugin($pluginName)
\r
1880 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
1887 $params = func_get_args();
\r
1889 // remove plugin name
\r
1890 array_shift($params);
\r
1892 // add skin type on front
\r
1893 array_unshift($params, $this->skintype);
\r
1895 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
\r
1900 * Actions::parse_prevarchive()
\r
1901 * Parse skinvar prevarchive
\r
1906 public function parse_prevarchive()
\r
1908 global $archiveprev;
\r
1909 echo $archiveprev;
\r
1913 * Actions::parse_preview()
\r
1914 * Parse skinvar preview
\r
1916 * @param string $template name of tempalte
\r
1919 public function parse_preview($template)
\r
1921 global $blog, $CONF, $manager;
\r
1923 $template =& $manager->getTemplate($template);
\r
1925 $row['body'] = '<span id="prevbody"></span>';
\r
1926 $row['title'] = '<span id="prevtitle"></span>';
\r
1927 $row['more'] = '<span id="prevmore"></span>';
\r
1928 $row['itemlink'] = '';
\r
1929 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
\r
1931 echo Template::fill($template['ITEM_HEADER'],$row);
\r
1932 echo Template::fill($template['ITEM'],$row);
\r
1933 echo Template::fill($template['ITEM_FOOTER'],$row);
\r
1938 * Actions::parse_previtem()
\r
1939 * Parse skinvar previtem
\r
1940 * (include itemid of prev item)
\r
1945 public function parse_previtem()
\r
1947 global $itemidprev;
\r
1948 if ( isset($itemidprev) )
\r
1950 echo (integer) $itemidprev;
\r
1956 * Actions::parse_previtemtitle()
\r
1957 * Parse skinvar previtemtitle
\r
1958 * (include itemtitle of prev item)
\r
1960 * @param String $format string format
\r
1961 * @return String formatted string
\r
1963 public function parse_previtemtitle($format = '')
\r
1965 global $itemtitleprev;
\r
1967 switch ( $format )
\r
1970 echo Entity::hen($itemtitleprev);
\r
1973 echo $itemtitleprev;
\r
1977 echo Entity::hsc($itemtitleprev);
\r
1984 * Actions::parse_prevlink()
\r
1985 * Parse skinvar prevlink
\r
1987 * @param string $linktext text as a content of anchor element
\r
1988 * @param integer the amount of links
\r
1991 public function parse_prevlink($linktext = '', $amount = 10)
\r
1993 global $itemidprev, $archiveprev, $startpos;
\r
1995 if ( $this->skintype == 'item' )
\r
1997 $this->itemlink($itemidprev, $linktext);
\r
1999 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
2001 $this->searchlink($amount, $startpos, 'prev', $linktext);
\r
2005 $this->archivelink($archiveprev, $linktext);
\r
2011 * Actions::parse_query()
\r
2012 * Parse skinvar query
\r
2013 * (includes the search query)
\r
2018 public function parse_query()
\r
2021 echo Entity::hsc($query);
\r
2026 * Actions::parse_referer()
\r
2027 * Parse skinvar referer
\r
2032 public function parse_referer()
\r
2034 echo Entity::hsc(serverVar('HTTP_REFERER'));
\r
2039 * Actions::parse_searchform()
\r
2040 * Parse skinvar searchform
\r
2042 * @param string $blogname name of weblog
\r
2045 public function parse_searchform($blogname = '')
\r
2047 global $CONF, $manager, $maxresults;
\r
2050 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
\r
2056 // use default blog when no blog is selected
\r
2057 $this->formdata = array(
\r
2058 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
\r
2059 'query' => Entity::hsc(getVar('query')),
\r
2061 $this->doForm('searchform');
\r
2066 * Actions::parse_searchresults()
\r
2067 * Parse skinvar searchresults
\r
2069 * @param string $template name of tempalte
\r
2070 * @param integer $maxresults searched items in a display
\r
2073 public function parse_searchresults($template, $maxresults = 50 )
\r
2075 global $blog, $query, $amount, $startpos;
\r
2077 $this->setBlogCategory($blog, ''); // need this to select default category
\r
2078 $this->preBlogContent('searchresults',$blog);
\r
2079 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
\r
2080 $this->postBlogContent('searchresults',$blog);
\r
2085 * Actions::parse_self()
\r
2086 * Parse skinvar self
\r
2091 public function parse_self()
\r
2094 echo $CONF['Self'];
\r
2099 * Actions::parse_sitevar()
\r
2100 * Parse skinvar sitevar
\r
2101 * (include a sitevar)
\r
2103 * @param string $which
\r
2106 public function parse_sitevar($which)
\r
2112 echo $CONF['IndexURL'];
\r
2115 echo $CONF['SiteName'];
\r
2118 echo $CONF['AdminEmail'];
\r
2121 echo $CONF['AdminURL'];
\r
2127 * Actions::parse_skinname()
\r
2133 public function parse_skinname()
\r
2135 echo $this->skin->getName();
\r
2140 * Actions::parse_skintype()
\r
2141 * Parse skintype (experimental)
\r
2146 public function parse_skintype()
\r
2148 echo $this->skintype;
\r
2153 * Actions::parse_ticket()
\r
2159 public function parse_ticket()
\r
2162 $manager->addTicketHidden();
\r
2167 * Actions::parse_todaylink()
\r
2168 * Parse skinvar todaylink
\r
2169 * A link to the today page (depending on selected blog, etc...)
\r
2171 * @param string $linktext text for link
\r
2174 public function parse_todaylink($linktext = '')
\r
2176 global $blog, $CONF;
\r
2179 echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
\r
2183 echo $this->link($CONF['SiteUrl'], $linktext);
\r
2190 * When commentform is not used, to include a hidden field with itemid
\r
2195 public function parse_vars()
\r
2198 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
\r
2203 * Actions::parse_version()
\r
2204 * Parse skinvar version
\r
2205 * (include nucleus versionnumber)
\r
2210 public function parse_version()
\r
2213 echo 'Nucleus CMS ' . $nucleus['version'];
\r
2218 * Actions::parse_sticky()
\r
2219 * Parse skinvar sticky
\r
2221 * @param integer $itemnumber id of item
\r
2222 * @param string $template name of template
\r
2225 public function parse_sticky($itemnumber = 0, $template = '')
\r
2229 $itemnumber = intval($itemnumber);
\r
2230 $itemarray = array($itemnumber);
\r
2232 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
\r
2233 $this->preBlogContent('sticky',$b);
\r
2234 $this->amountfound = $b->readLogFromList($itemarray, $template);
\r
2235 $this->postBlogContent('sticky',$b);
\r