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(quickQuery($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_charset()
\r
1133 * Parse skinvar charset
\r
1138 public function parse_charset()
\r
1140 echo i18n::get_current_charset();
\r
1145 * Actions::parse_commentform()
\r
1146 * Parse skinvar commentform
\r
1148 * @param string $destinationurl URI for redirection
\r
1151 public function parse_commentform($destinationurl = '')
\r
1153 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
\r
1155 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
\r
1156 if ( stristr($destinationurl, 'action.php') )
\r
1158 $args = func_get_args();
\r
1159 $destinationurl = $args[1];
\r
1160 ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
\r
1163 $actionurl = $CONF['ActionURL'];
\r
1165 // if item is closed, show message and do nothing
\r
1166 $item =& $manager->getItem($itemid,0,0);
\r
1167 if ( $item['closed'] || !$blog->commentsEnabled() )
\r
1169 $this->doForm('commentform-closed');
\r
1173 if ( !$blog->isPublic() && !$member->isLoggedIn() )
\r
1175 $this->doForm('commentform-closedtopublic');
\r
1179 if ( !$destinationurl )
\r
1181 // note: createLink returns an HTML encoded URL
\r
1182 $destinationurl = Link::create_link(
\r
1185 'itemid' => $itemid,
\r
1186 'title' => $item['title'],
\r
1187 'timestamp' => $item['timestamp'],
\r
1188 'extra' => $this->linkparams
\r
1194 // HTML encode URL
\r
1195 $destinationurl = Entity::hsc($destinationurl);
\r
1198 // values to prefill
\r
1199 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
\r
1202 $user = postVar('user');
\r
1205 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
\r
1208 $userid = postVar('userid');
\r
1211 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
\r
1214 $email = postVar('email');
\r
1217 $body = postVar('body');
\r
1219 $this->formdata = array(
\r
1220 'destinationurl' => $destinationurl, // url is already HTML encoded
\r
1221 'actionurl' => Entity::hsc($actionurl),
\r
1222 'itemid' => $itemid,
\r
1223 'user' => Entity::hsc($user),
\r
1224 'userid' => Entity::hsc($userid),
\r
1225 'email' => Entity::hsc($email),
\r
1226 'body' => Entity::hsc($body),
\r
1227 'membername' => $member->getDisplayName(),
\r
1228 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
\r
1231 if ( !$member->isLoggedIn() )
\r
1233 $this->doForm('commentform-notloggedin');
\r
1237 $this->doForm('commentform-loggedin');
\r
1243 * Actions::parse_comments()
\r
1244 * Parse skinvar comments
\r
1245 * include comments for one item
\r
1247 * @param string $template name of template
\r
1250 public function parse_comments($template)
\r
1252 global $itemid, $manager, $blog, $highlight;
\r
1254 $template =& $manager->getTemplate($template);
\r
1255 $item = Item::getitem($itemid, 0, 0);
\r
1257 // create parser object & action handler
\r
1258 $handler = new ItemActions($blog);
\r
1259 $handler->setTemplate($template);
\r
1260 $handler->setCurrentItem($item);
\r
1262 $parser = new Parser($handler);
\r
1264 $comments = new Comments($itemid);
\r
1265 $comments->setItemActions($handler);
\r
1266 // shows ALL comments
\r
1267 $comments->showComments($template, -1, 1, $highlight);
\r
1272 * Actions::parse_errordiv()
\r
1278 public function parse_errordiv()
\r
1280 global $errormessage;
\r
1281 if ( $errormessage )
\r
1283 echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
\r
1289 * Actions::parse_errormessage()
\r
1290 * Parse skinvar errormessage
\r
1295 public function parse_errormessage()
\r
1297 global $errormessage;
\r
1298 echo $errormessage;
\r
1303 * Actions::parse_formdata()
\r
1306 * @param string $what key of format data
\r
1309 public function parse_formdata($what)
\r
1311 echo $this->formdata[$what];
\r
1316 * Actions::parse_ifcat()
\r
1319 * @param string $text
\r
1322 public function parse_ifcat($text = '')
\r
1324 if ( $text == '' )
\r
1327 $this->parse_if('category');
\r
1332 global $catid, $blog;
\r
1333 if ( $blog->isValidCategory($catid) )
\r
1342 * Actions::parse_image()
\r
1343 * Parse skinvar image
\r
1345 * @param string $what name of tag
\r
1348 public function parse_image($what = 'imgtag')
\r
1352 $imagetext = Entity::hsc(requestVar('imagetext'));
\r
1353 $imagepopup = requestVar('imagepopup');
\r
1354 $width = intRequestVar('width');
\r
1355 $height = intRequestVar('height');
\r
1356 $fullurl = Entity::hsc($CONF['MediaURL'] . $imagepopup);
\r
1375 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
\r
1382 * Actions::parse_imagetext()
\r
1383 * Parse skinvar imagetext
\r
1388 public function parse_imagetext()
\r
1390 $this->parse_image('imagetext');
\r
1395 * Actions::parse_item()
\r
1396 * Parse skinvar item
\r
1397 * include one item (no comments)
\r
1402 public function parse_item($template)
\r
1404 global $blog, $itemid, $highlight;
\r
1406 // need this to select default category
\r
1407 $this->setBlogCategory($blog, '');
\r
1408 $this->preBlogContent('item',$blog);
\r
1409 $r = $blog->showOneitem($itemid, $template, $highlight);
\r
1412 echo _ERROR_NOSUCHITEM;
\r
1414 $this->postBlogContent('item',$blog);
\r
1419 * Actions::parse_itemid()
\r
1420 * Parse skinvar itemid
\r
1425 public function parse_itemid()
\r
1433 * Actions::parseitemlink()
\r
1434 * Parse skinvar itemlink
\r
1439 public function parse_itemlink($linktext = '')
\r
1442 $this->itemlink($itemid, $linktext);
\r
1447 * Actions::parse_itemtitle()
\r
1453 public function parse_itemtitle($format = '')
\r
1455 global $manager, $itemid;
\r
1456 $item =& $manager->getItem($itemid,0,0);
\r
1458 switch ( $format )
\r
1461 echo Entity::hen($item['title']);
\r
1464 echo $item['title'];
\r
1468 echo Entity::hsc(strip_tags($item['title']));
\r
1475 * Actions::parse_loginform()
\r
1476 * Parse skinvar loginform
\r
1481 public function parse_loginform()
\r
1483 global $member, $CONF;
\r
1484 if ( !$member->isLoggedIn() )
\r
1486 $filename = 'loginform-notloggedin';
\r
1487 $this->formdata = array();
\r
1491 $filename = 'loginform-loggedin';
\r
1492 $this->formdata = array(
\r
1493 'membername' => $member->getDisplayName(),
\r
1496 $this->doForm($filename);
\r
1501 * Actions::parse_member()
\r
1502 * Parse skinvar member
\r
1503 * (includes a member info thingie)
\r
1505 * @param string $what which memberdata is needed
\r
1508 public function parse_member($what)
\r
1510 global $memberinfo, $member, $CONF;
\r
1512 // 1. only allow the member-details-page specific variables on member pages
\r
1513 if ( $this->skintype == 'member' )
\r
1518 echo Entity::hsc($memberinfo->getDisplayName());
\r
1521 echo Entity::hsc($memberinfo->getRealName());
\r
1524 echo Entity::hsc($memberinfo->getNotes());
\r
1527 echo Entity::hsc($memberinfo->getURL());
\r
1530 echo Entity::hsc($memberinfo->getEmail());
\r
1533 echo Entity::hsc($memberinfo->getID());
\r
1538 // 2. the next bunch of options is available everywhere, as long as the user is logged in
\r
1539 if ( $member->isLoggedIn() )
\r
1544 echo $member->getDisplayName();
\r
1546 case 'yourrealname':
\r
1547 echo $member->getRealName();
\r
1550 echo $member->getNotes();
\r
1553 echo $member->getURL();
\r
1556 echo $member->getEmail();
\r
1559 echo $member->getID();
\r
1561 case 'yourprofileurl':
\r
1562 if ($CONF['URLMode'] == 'pathinfo')
\r
1563 echo Link::create_member_link($member->getID());
\r
1565 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
\r
1573 * Link::parse_membermailform()
\r
1574 * Parse skinvar membermailform
\r
1576 * @param integer $rows the height for textarea
\r
1577 * @param integer $cols the width for textarea
\r
1578 * @param string $desturl URI to redirect
\r
1581 public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
\r
1583 global $member, $CONF, $memberid;
\r
1585 if ( $desturl == '' )
\r
1587 if ( $CONF['URLMode'] == 'pathinfo' )
\r
1589 $desturl = Link::create_member_link($memberid);
\r
1593 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
\r
1597 $message = postVar('message');
\r
1598 $frommail = postVar('frommail');
\r
1600 $this->formdata = array(
\r
1601 'url' => Entity::hsc($desturl),
\r
1602 'actionurl' => Entity::hsc($CONF['ActionURL']),
\r
1603 'memberid' => $memberid,
\r
1606 'message' => Entity::hsc($message),
\r
1607 'frommail' => Entity::hsc($frommail)
\r
1610 if ( $member->isLoggedIn() )
\r
1612 $this->doForm('membermailform-loggedin');
\r
1614 else if ( $CONF['NonmemberMail'] )
\r
1616 $this->doForm('membermailform-notloggedin');
\r
1620 $this->doForm('membermailform-disallowed');
\r
1626 * Actions::parse_nextarchive()
\r
1627 * Parse skinvar nextarchive
\r
1632 public function parse_nextarchive()
\r
1634 global $archivenext;
\r
1635 echo $archivenext;
\r
1640 * Parse skinvar nextitem
\r
1641 * (include itemid of next item)
\r
1646 public function parse_nextitem()
\r
1648 global $itemidnext;
\r
1649 if ( isset($itemidnext) )
\r
1651 echo (int)$itemidnext;
\r
1657 * Actions::parse_nextitemtitle()
\r
1658 * Parse skinvar nextitemtitle
\r
1659 * (include itemtitle of next item)
\r
1661 * @param string $format format of text
\r
1664 public function parse_nextitemtitle($format = '')
\r
1666 global $itemtitlenext;
\r
1668 switch ( $format )
\r
1671 echo Entity::hen($itemtitlenext);
\r
1674 echo $itemtitlenext;
\r
1678 echo Entity::hsc($itemtitlenext);
\r
1685 * Actions::parse_nextlink()
\r
1686 * Parse skinvar nextlink
\r
1688 * @param string $linktext text for content of anchor element
\r
1689 * @param integer $amount the amount of items in a display
\r
1690 * @param integer $recount increment from this value
\r
1693 public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
\r
1695 global $itemidnext, $archivenext, $startpos;
\r
1696 if ( $this->skintype == 'item' )
\r
1698 $this->itemlink($itemidnext, $linktext);
\r
1700 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
1702 $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
\r
1706 $this->archivelink($archivenext, $linktext);
\r
1712 * Actions::parse_nucleusbutton()
\r
1713 * Parse skinvar nucleusbutton
\r
1715 * @param string $imgurl URL for image
\r
1716 * @param integer $imgwidth width of image
\r
1717 * @param integer $imgheidht height of image
\r
1719 public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
\r
1722 if ( $imgurl == '' )
\r
1724 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
\r
1726 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
\r
1728 // when skindit IncludeMode is used: start from skindir
\r
1729 $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
\r
1732 $this->formdata = array(
\r
1733 'imgurl' => $imgurl,
\r
1734 'imgwidth' => $imgwidth,
\r
1735 'imgheight' => $imgheight,
\r
1737 $this->doForm('nucleusbutton');
\r
1742 * Actions::parse_otherarchive()
\r
1743 * Parse skinvar otherarchive
\r
1745 * @param string $blogname name of weblog
\r
1746 * @param string $template name of template
\r
1747 * @param string $category name of category
\r
1750 public function parse_otherarchive($blogname, $template, $category = '')
\r
1752 global $archive, $manager;
\r
1753 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
1754 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1755 $this->setBlogCategory($b, $category);
\r
1756 $this->preBlogContent('otherachive',$b);
\r
1757 $b->showArchive($template, $y, $m, $d);
\r
1758 $this->postBlogContent('otherachive',$b);
\r
1763 * Actions::parse_otherarchivedaylist()
\r
1764 * Parse skinvar otherarchivedaylist
\r
1766 * @param string $blogname name of weblog
\r
1767 * @param string $template name of template
\r
1768 * @param string $category name of category
\r
1769 * @param integer $limit the amount of items in a display
\r
1772 public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
\r
1775 if ( $category == 'all')
\r
1779 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1780 $this->setBlogCategory($b, $category);
\r
1781 $this->preBlogContent('otherarchivelist',$b);
\r
1782 $b->showArchiveList($template, 'day', $limit);
\r
1783 $this->postBlogContent('otherarchivelist',$b);
\r
1788 * Actions::parse_otherarchivelist()
\r
1789 * Parse skinvar otherarchivelist
\r
1791 * @param string $blogname name of weblog
\r
1792 * @param string $template name of template
\r
1793 * @param string $category name of category
\r
1794 * @param integer $limit the amount of items in a display
\r
1797 public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
\r
1800 if ( $category == 'all' )
\r
1804 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1805 $this->setBlogCategory($b, $category);
\r
1806 $this->preBlogContent('otherarchivelist',$b);
\r
1807 $b->showArchiveList($template, 'month', $limit);
\r
1808 $this->postBlogContent('otherarchivelist',$b);
\r
1813 * Actions::parse_otherarchiveyearlist()
\r
1814 * Parse skinvar otherarchiveyearlist
\r
1816 * @param string $blogname name of weblog
\r
1817 * @param string $template name of template
\r
1818 * @param string $category name of category
\r
1819 * @limit integer $limit the amount of items in a display
\r
1821 public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
\r
1824 if ( $category == 'all' )
\r
1828 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1829 $this->setBlogCategory($b, $category);
\r
1830 $this->preBlogContent('otherarchivelist',$b);
\r
1831 $b->showArchiveList($template, 'year', $limit);
\r
1832 $this->postBlogContent('otherarchivelist',$b);
\r
1837 * Actions::parse_otherblog()
\r
1838 * Parse skinvar otherblog
\r
1840 * @param string $blogname name of weblog
\r
1841 * @param string $template name of template
\r
1842 * @param mixed $amount the amount of items, in case it includes the beginning
\r
1843 * @param string $category name of category
\r
1846 public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
\r
1850 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1852 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1853 $this->setBlogCategory($b, $category);
\r
1854 $this->preBlogContent('otherblog',$b);
\r
1855 $this->amountfound = $b->readLog($template, $limit, $offset);
\r
1856 $this->postBlogContent('otherblog',$b);
\r
1861 * Actions::parse_othersearchresults()
\r
1862 * Parse skinvar othersearchresults
\r
1864 * @param string $blogname name of weblog
\r
1865 * @param string $template name of template
\r
1866 * @param integer $maxresults the amount of results
\r
1869 public function parse_othersearchresults($blogname, $template, $maxresults = 50)
\r
1871 global $query, $amount, $manager, $startpos;
\r
1872 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1873 // need this to select default category
\r
1874 $this->setBlogCategory($b, '');
\r
1875 $this->preBlogContent('othersearchresults',$b);
\r
1876 $b->search($query, $template, $amount, $maxresults, $startpos);
\r
1877 $this->postBlogContent('othersearchresults',$b);
\r
1882 * Actions::parse_plugin()
\r
1883 * Executes a plugin skinvar
\r
1884 * extra parameters can be added
\r
1886 * @param string $pluginName name of plugin (without the NP_)
\r
1889 public function parse_plugin($pluginName)
\r
1893 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
1900 $params = func_get_args();
\r
1902 // remove plugin name
\r
1903 array_shift($params);
\r
1905 // add skin type on front
\r
1906 array_unshift($params, $this->skintype);
\r
1908 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
\r
1913 * Actions::parse_prevarchive()
\r
1914 * Parse skinvar prevarchive
\r
1919 public function parse_prevarchive()
\r
1921 global $archiveprev;
\r
1922 echo $archiveprev;
\r
1926 * Actions::parse_preview()
\r
1927 * Parse skinvar preview
\r
1929 * @param string $template name of tempalte
\r
1932 public function parse_preview($template)
\r
1934 global $blog, $CONF, $manager;
\r
1936 $template =& $manager->getTemplate($template);
\r
1938 $row['body'] = '<span id="prevbody"></span>';
\r
1939 $row['title'] = '<span id="prevtitle"></span>';
\r
1940 $row['more'] = '<span id="prevmore"></span>';
\r
1941 $row['itemlink'] = '';
\r
1942 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
\r
1944 echo Template::fill($template['ITEM_HEADER'],$row);
\r
1945 echo Template::fill($template['ITEM'],$row);
\r
1946 echo Template::fill($template['ITEM_FOOTER'],$row);
\r
1951 * Actions::parse_previtem()
\r
1952 * Parse skinvar previtem
\r
1953 * (include itemid of prev item)
\r
1958 public function parse_previtem()
\r
1960 global $itemidprev;
\r
1961 if ( isset($itemidprev) )
\r
1963 echo (integer) $itemidprev;
\r
1969 * Actions::parse_previtemtitle()
\r
1970 * Parse skinvar previtemtitle
\r
1971 * (include itemtitle of prev item)
\r
1973 * @param String $format string format
\r
1974 * @return String formatted string
\r
1976 public function parse_previtemtitle($format = '')
\r
1978 global $itemtitleprev;
\r
1980 switch ( $format )
\r
1983 echo Entity::hen($itemtitleprev);
\r
1986 echo $itemtitleprev;
\r
1990 echo Entity::hsc($itemtitleprev);
\r
1997 * Actions::parse_prevlink()
\r
1998 * Parse skinvar prevlink
\r
2000 * @param string $linktext text as a content of anchor element
\r
2001 * @param integer the amount of links
\r
2004 public function parse_prevlink($linktext = '', $amount = 10)
\r
2006 global $itemidprev, $archiveprev, $startpos;
\r
2008 if ( $this->skintype == 'item' )
\r
2010 $this->itemlink($itemidprev, $linktext);
\r
2012 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
2014 $this->searchlink($amount, $startpos, 'prev', $linktext);
\r
2018 $this->archivelink($archiveprev, $linktext);
\r
2024 * Actions::parse_query()
\r
2025 * Parse skinvar query
\r
2026 * (includes the search query)
\r
2031 public function parse_query()
\r
2034 echo Entity::hsc($query);
\r
2039 * Actions::parse_referer()
\r
2040 * Parse skinvar referer
\r
2045 public function parse_referer()
\r
2047 echo Entity::hsc(serverVar('HTTP_REFERER'));
\r
2052 * Actions::parse_searchform()
\r
2053 * Parse skinvar searchform
\r
2055 * @param string $blogname name of weblog
\r
2058 public function parse_searchform($blogname = '')
\r
2060 global $CONF, $manager, $maxresults;
\r
2063 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
\r
2069 // use default blog when no blog is selected
\r
2070 $this->formdata = array(
\r
2071 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
\r
2072 'query' => Entity::hsc(getVar('query')),
\r
2074 $this->doForm('searchform');
\r
2079 * Actions::parse_searchresults()
\r
2080 * Parse skinvar searchresults
\r
2082 * @param string $template name of tempalte
\r
2083 * @param integer $maxresults searched items in a display
\r
2086 public function parse_searchresults($template, $maxresults = 50 )
\r
2088 global $blog, $query, $amount, $startpos;
\r
2090 $this->setBlogCategory($blog, ''); // need this to select default category
\r
2091 $this->preBlogContent('searchresults',$blog);
\r
2092 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
\r
2093 $this->postBlogContent('searchresults',$blog);
\r
2098 * Actions::parse_self()
\r
2099 * Parse skinvar self
\r
2104 public function parse_self()
\r
2107 echo $CONF['Self'];
\r
2112 * Actions::parse_sitevar()
\r
2113 * Parse skinvar sitevar
\r
2114 * (include a sitevar)
\r
2116 * @param string $which
\r
2119 public function parse_sitevar($which)
\r
2125 echo $CONF['IndexURL'];
\r
2128 echo $CONF['SiteName'];
\r
2131 echo $CONF['AdminEmail'];
\r
2134 echo $CONF['AdminURL'];
\r
2140 * Actions::parse_skinname()
\r
2146 public function parse_skinname()
\r
2148 echo $this->skin->getName();
\r
2153 * Actions::parse_skintype()
\r
2154 * Parse skintype (experimental)
\r
2159 public function parse_skintype()
\r
2161 echo $this->skintype;
\r
2166 * Actions::parse_ticket()
\r
2172 public function parse_ticket()
\r
2175 $manager->addTicketHidden();
\r
2180 * Actions::parse_todaylink()
\r
2181 * Parse skinvar todaylink
\r
2182 * A link to the today page (depending on selected blog, etc...)
\r
2184 * @param string $linktext text for link
\r
2187 public function parse_todaylink($linktext = '')
\r
2189 global $blog, $CONF;
\r
2192 echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
\r
2196 echo $this->link($CONF['SiteUrl'], $linktext);
\r
2203 * When commentform is not used, to include a hidden field with itemid
\r
2208 public function parse_vars()
\r
2211 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
\r
2216 * Actions::parse_version()
\r
2217 * Parse skinvar version
\r
2218 * (include nucleus versionnumber)
\r
2223 public function parse_version()
\r
2226 echo 'Nucleus CMS ' . $nucleus['version'];
\r
2231 * Actions::parse_sticky()
\r
2232 * Parse skinvar sticky
\r
2234 * @param integer $itemnumber id of item
\r
2235 * @param string $template name of template
\r
2238 public function parse_sticky($itemnumber = 0, $template = '')
\r
2242 $itemnumber = intval($itemnumber);
\r
2243 $itemarray = array($itemnumber);
\r
2245 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
\r
2246 $this->preBlogContent('sticky',$b);
\r
2247 $this->amountfound = $b->readLogFromList($itemarray, $template);
\r
2248 $this->postBlogContent('sticky',$b);
\r