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 * The allowed tags for a type of skinpart are defined by the
\r
17 * Skin::getAllowedActionsForType($type) method
\r
19 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
20 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
21 * @version $Id: ACTIONS.php 1784 2012-04-22 04:28:30Z sakamocchi $
24 class Actions extends BaseActions
\r
26 // part of the skin currently being parsed ('index', 'item', 'archive',
\r
27 // 'archivelist', 'member', 'search', 'error', 'imagepopup')
\r
30 // contains an assoc array with parameters that need to be included when
\r
31 // generating links to items/archives/... (e.g. catid)
\r
32 private $linkparams;
\r
34 // reference to the skin object for which a part is being parsed
\r
37 // used when including templated forms from the include/ dir. The $formdata var
\r
38 // contains the values to fill out in there (assoc array name -> value)
\r
41 // filled out with the number of displayed items after calling one of the
\r
42 // (other)blog/(other)searchresults skinvars.
\r
43 private $amountfound;
\r
46 * Actions::$default_actions
\r
47 * list of whole action names with which this class can deal
\r
49 static private $default_actions = array(
\r
60 'otherarchivedaylist',
\r
62 'otherarchiveyearlist',
\r
73 // deprecated (Nucleus v2.0)
\r
74 /* TODO: remove this */
\r
79 * Actions::$skin_type_friendly_names
\r
80 * friendly name for wrapped page types
\r
82 static public $default_skin_types = array(
83 'index' => _SKIN_PART_MAIN,
\r
84 'item' => _SKIN_PART_ITEM,
\r
85 'archivelist' => _SKIN_PART_ALIST,
\r
86 'archive' => _SKIN_PART_ARCHIVE,
\r
87 'search' => _SKIN_PART_SEARCH,
\r
88 'error' => _SKIN_PART_ERROR,
\r
89 'member' => _SKIN_PART_MEMBER,
\r
90 'imagepopup' => _SKIN_PART_POPUP
\r
94 * Actions::getDefinedActions()
\r
97 * @param string $type page type
\r
98 * @return array allowed actions for the page type
\r
100 static public function getDefinedActions($type='')
\r
102 $extra_actions = array();
\r
107 $extra_actions = array(
\r
121 $extra_actions = array(
\r
138 case 'archivelist':
\r
139 $extra_actions = array(
\r
149 $extra_actions = array(
\r
156 'othersearchresults',
\r
164 $extra_actions = array(
\r
166 // deprecated (Nucleus v2.0)
\r
167 /* TODO: remove this */
\r
172 $extra_actions = array(
\r
180 $extra_actions = array(
\r
203 $extra_actions = array(
\r
209 $extra_actions = array(
\r
227 $defined_actions = array_merge(self::$default_actions, $extra_actions);
229 return array_merge($defined_actions, parent::getDefinedActions());
233 * Actions::getDefaultSkinTypes()
237 * @return array list of friendly names for page actions
\r
239 static public function getDefaultSkinTypes()
241 return self::$default_skin_types;
245 * Actions::__construct()
\r
246 * Constructor for a new Actions object
\r
248 * @param string $type
\r
251 public function __construct($type)
\r
255 // call constructor of superclass first
\r
256 parent::__construct();
258 $this->skintype = $type;
\r
262 $this->linkparams = array('catid' => $catid);
\r
268 * Actions::setSkin()
\r
270 * @param object $skin an instance of Skin class
\r
273 public function setSkin(&$skin)
\r
275 $this->skin =& $skin;
\r
280 * Actions::setParser()
\r
283 * @param object $parser an instance of Parser class
\r
286 public function setParser(&$parser)
\r
288 $this->parser =& $parser;
\r
293 * Actions::doForm()
\r
294 * Forms get parsedincluded now, using an extra <formdata> skinvar
\r
296 * @param string $filename
\r
299 public function doForm($filename)
\r
301 global $DIR_NUCLEUS;
\r
302 array_push($this->parser->actions,'formdata','text','callback','errordiv','ticket');
\r
304 $oldIncludeMode = Parser::getProperty('IncludeMode');
\r
305 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
\r
306 Parser::setProperty('IncludeMode','normal');
\r
307 Parser::setProperty('IncludePrefix','');
\r
309 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
\r
310 Parser::setProperty('IncludeMode',$oldIncludeMode);
\r
311 Parser::setProperty('IncludePrefix',$oldIncludePrefix);
\r
313 array_pop($this->parser->actions); // errordiv
\r
314 array_pop($this->parser->actions); // callback
\r
315 array_pop($this->parser->actions); // text
\r
316 array_pop($this->parser->actions); // formdata
\r
317 array_pop($this->parser->actions); // ticket
\r
322 * Actions::checkCondition()
\r
323 * Checks conditions for if statements
\r
325 * @param string $field type of <%if%>
\r
326 * @param string $name property of field
\r
327 * @param string $value value of property
\r
328 * @return boolean condition
\r
330 protected function checkCondition($field, $name='', $value = '')
\r
332 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
338 $condition = ($blog && $this->ifCategory($name,$value));
\r
340 case 'blogsetting':
\r
341 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
344 $condition = $member->isLoggedIn();
\r
347 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
\r
350 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
\r
353 $condition = ($itemidnext != '');
\r
356 $condition = ($itemidprev != '');
\r
358 case 'archiveprevexists':
\r
359 $condition = ($archiveprevexists == true);
\r
361 case 'archivenextexists':
\r
362 $condition = ($archivenextexists == true);
\r
365 $condition = (($name == $this->skintype) || ($name == requestVar('action')));
\r
368 $condition = $this->ifHasPlugin($name, $value);
\r
371 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);
\r
378 * Actions::_ifHasPlugin()
\r
379 * hasplugin,PlugName
\r
380 * -> checks if plugin exists
\r
381 * hasplugin,PlugName,OptionName
\r
382 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
383 * hasplugin,PlugName,OptionName=value
\r
384 * -> checks if the option OptionName from plugin PlugName is set to value
\r
386 * @param string $name name of plugin
\r
387 * @param string $value
\r
390 private function ifHasPlugin($name, $value)
\r
393 $condition = false;
\r
394 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
395 if ( $manager->pluginInstalled("NP_{$name}") )
\r
397 $plugin =& $manager->getPlugin("NP_{$name}");
\r
398 if ( $plugin != NULL )
\r
400 if ( $value == "" )
\r
406 list($name2, $value2) = preg_split('#=#', $value, 2);
\r
407 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
\r
411 else if ( $plugin->getOption($name2) == $value2 )
\r
422 * Actions::ifPlugin()
\r
423 * Checks if a plugin exists and call its doIf function
\r
425 * @param string $name name of plugin
\r
426 * @param string $key name of plugin option
\r
427 * @param string $value value of plugin option
\r
430 private function ifPlugin($name, $key = '', $value = '')
\r
434 $plugin =& $manager->getPlugin("NP_{$name}");
\r
440 $params = func_get_args();
\r
441 array_shift($params);
\r
443 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r
447 * Actions::ifCategory()
\r
448 * Different checks for a category
\r
450 * @param string $name
\r
451 * @param string $value
\r
454 private function ifCategory($name = '', $value='')
\r
456 global $blog, $catid;
\r
458 // when no parameter is defined, just check if a category is selected
\r
459 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )
\r
461 return $blog->isValidCategory($catid);
\r
464 // check category name
\r
465 if ( $name == 'catname' )
\r
467 $value = $blog->getCategoryIdFromName($value);
\r
468 if ( $value == $catid )
\r
470 return $blog->isValidCategory($catid);
\r
474 // check category id
\r
475 if ( ($name == 'catid') && ($value == $catid) )
\r
477 return $blog->isValidCategory($catid);
\r
483 * Actions::ifOnTeam()
\r
484 * Checks if a member is on the team of a blog and return his rights
\r
486 * @param string $blogName name of weblog
\r
489 private function ifOnTeam($blogName = '')
\r
491 global $blog, $member, $manager;
\r
493 // when no blog found
\r
494 if ( ($blogName == '') && !is_object($blog) )
\r
499 // explicit blog selection
\r
500 if ( $blogName != '' )
\r
502 $blogid = getBlogIDFromName($blogName);
\r
505 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
507 // use current blog
\r
508 $blogid = $blog->getID();
\r
511 return $member->teamRights($blogid);
\r
515 * Actions::ifAdmin()
\r
516 * Checks if a member is admin of a blog
\r
518 * @param string $blogName name of weblog
\r
521 private function ifAdmin($blogName = '')
\r
523 global $blog, $member, $manager;
\r
525 // when no blog found
\r
526 if ( ($blogName == '') && (!is_object($blog)) )
\r
531 // explicit blog selection
\r
532 if ( $blogName != '' )
\r
534 $blogid = getBlogIDFromName($blogName);
\r
537 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
539 // use current blog
\r
540 $blogid = $blog->getID();
\r
543 return $member->isBlogAdmin($blogid);
\r
549 * - a raw link (html/xml encoded) when no linktext is provided
\r
550 * - a (x)html <a href... link when a text is present (text htmlencoded)
\r
552 * @param string $url URL for href attribute of anchor element
\r
553 * @param string $linktext content of anchor element
\r
556 private function link($url, $linktext = '')
\r
558 $u = Entity::hsc($url);
\r
559 // fix URLs that already had encoded ampersands
\r
560 $u = preg_replace("#&amp;#", '&', $u);
\r
561 if ( $linktext != '' )
\r
563 $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';
\r
573 * Actions::searchlink()
\r
574 * Outputs a next/prev link
\r
576 * @param $maxresults
\r
577 * The maximum amount of items shown per page (e.g. 10)
\r
579 * Current start position (requestVar('startpos'))
\r
580 * @param $direction
\r
581 * either 'prev' or 'next'
\r
583 * When present, the output will be a full <a href...> link. When empty,
\r
584 * only a raw link will be outputted
\r
586 private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')
\r
588 global $CONF, $blog, $query, $amount;
\r
589 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
\r
590 $startpos = (integer) $startpos;
\r
591 $parsed = parse_url(serverVar('REQUEST_URI'));
\r
592 $path = $parsed['path'];
\r
593 $parsed = $parsed['query'];
\r
596 if ( $direction == 'prev' )
\r
598 if ( intval($startpos) - intval($maxresults) >= 0 )
\r
600 $startpos = intval($startpos) - intval($maxresults);
\r
602 if ( $this->skintype == 'index' )
\r
606 else if ( $this->skintype == 'search' )
\r
608 $url = $CONF['SearchURL'];
\r
610 $url .= '?' . alterQueryStr($parsed,'startpos',$startpos);
\r
613 else if ( $direction == 'next' )
\r
615 global $navigationItems;
\r
616 if ( !isset($navigationItems) )
\r
618 $navigationItems = 0;
\r
623 $iAmountOnPage = 0;
\r
627 $iAmountOnPage = $this->amountfound;
\r
630 if ( intval($navigationItems) > 0 )
\r
632 $iAmountOnPage = intval($navigationItems) - intval($startpos);
\r
634 elseif ( $iAmountOnPage == 0 )
\r
637 * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
\r
638 * try a count query
\r
640 if ( $this->skintype == 'index' )
\r
642 $sqlquery = $blog->getSqlBlog('', 'count');
\r
645 else if ( $this->skintype == 'search' )
\r
647 $unused_highlight = '';
\r
648 $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
\r
649 $url = $CONF['SearchURL'];
\r
653 $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
\r
658 if ( intval($iAmountOnPage) >= intval($maxresults) )
\r
660 $startpos = intval($startpos) + intval($maxresults);
\r
661 $url .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
\r
667 echo $this->link($url, $linktext);
\r
673 * Actions::itemlink()
\r
674 * Creates an item link and if no id is given a todaylink
\r
676 * @param integer $id id for link
\r
677 * @param string $linktext text for link
\r
680 private function itemlink($id, $linktext = '')
\r
685 echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);
\r
689 $this->parse_todaylink($linktext);
\r
695 * Actions::archivelink)
\r
696 * Creates an archive link and if no id is given a todaylink
\r
698 * @param integer $id id for link
\r
699 * @param string $linktext text for link
\r
702 private function archivelink($id, $linktext = '')
\r
704 global $CONF, $blog;
\r
707 echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
\r
711 $this->parse_todaylink($linktext);
\r
717 * Actions:setBlogCategory()
\r
718 * Helper function that sets the category that a blog will need to use
\r
720 * @param string $blog An object of the blog class, passed by reference (we want to make changes to it)
\r
721 * @param string $catname The name of the category to use
\r
724 private function setBlogCategory(&$blog, $catname)
\r
727 if ( $catname != '' )
\r
729 $blog->setSelectedCategoryByName($catname);
\r
733 $blog->setSelectedCategory($catid);
\r
739 * Actions::preBlogContent()
\r
740 * Notifies the Manager that a PreBlogContent event occurs
\r
742 * @param string $type type of skin
\r
743 * @param object $blog an instance of Blog class
\r
746 private function preBlogContent($type, &$blog)
\r
749 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
\r
754 * Actions::postBlogContent()
\r
755 * Notifies the Manager that a PostBlogContent event occurs
\r
757 * @param string $type type of skin
\r
758 * @param objecct $blog an instance of Blog class
\r
761 private function postBlogContent($type, &$blog)
\r
764 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
\r
769 * Actions::parse_additemform()
\r
770 * Parse skinvar additemform
\r
775 public function parse_additemform()
\r
777 global $blog, $CONF;
\r
778 $this->formdata = array(
\r
779 'adminurl' => Entity::hsc($CONF['AdminURL']),
\r
780 'catid' => $blog->getDefaultCategory()
\r
782 $blog->InsertJavaScriptInfo();
\r
783 $this->doForm('additemform');
\r
788 * Actions::parse_addlink()
\r
789 * Parse skinvar addlink
\r
790 * A Link that allows to open a bookmarklet to add an item
\r
792 public function parse_addlink()
\r
794 global $CONF, $member, $blog;
\r
795 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
\r
797 echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
\r
803 * Actions::parse_addpopupcode()
\r
804 * Parse skinvar addpopupcode
\r
805 * Code that opens a bookmarklet in an popup window
\r
810 public function parse_addpopupcode()
\r
812 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
817 * Parse skinvar adminurl
\r
818 * (shortcut for admin url)
\r
823 public function parse_adminurl()
\r
825 $this->parse_sitevar('adminurl');
\r
830 * Actions::parse_archive()
\r
831 * Parse skinvar archive
\r
833 * @param string $template name of template
\r
834 * @param string $category name of category
\r
837 public function parse_archive($template, $category = '')
\r
839 global $blog, $archive;
\r
840 // can be used with either yyyy-mm or yyyy-mm-dd
\r
841 sscanf($archive,'%d-%d-%d', $y, $m, $d);
\r
842 $this->setBlogCategory($blog, $category);
\r
843 $this->preBlogContent('achive',$blog);
\r
844 $blog->showArchive($template, $y, $m, $d);
\r
845 $this->postBlogContent('achive',$blog);
\r
850 * Actions::parse_archivedate()
\r
851 * %archivedate(locale,date format)%
\r
853 * @param string $locale
\r
856 public function parse_archivedate($locale = '-def-')
\r
861 * TODO: these lines are no meaning because there is no $template.
\r
862 if ( $locale == '-def-' )
\r
864 setlocale(LC_TIME, $template['LOCALE']);
\r
868 setlocale(LC_TIME, $locale);
\r
872 // get archive date
\r
873 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
876 $args = func_get_args();
\r
877 // format can be spread over multiple parameters
\r
878 if ( sizeof($args) > 1 )
\r
880 // take away locale
\r
881 array_shift($args);
\r
883 $format=implode(',',$args);
\r
885 elseif ( $d == 0 && $m !=0 )
\r
895 $format = '%d %B %Y';
\r
897 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
\r
902 * Actions::parse_archivedaylist()
\r
903 * Parse skinvar archivedaylist
\r
905 * @param string $template name of template
\r
906 * @param string $category name of category
\r
907 * @param integer $limit the number of items in a display
\r
910 public function parse_archivedaylist($template, $category = 'all', $limit = 0)
\r
913 if ( $category == 'all' )
\r
917 $this->preBlogContent('archivelist',$blog);
\r
918 $this->setBlogCategory($blog, $category);
\r
919 $blog->showArchiveList($template, 'day', $limit);
\r
920 $this->postBlogContent('archivelist',$blog);
\r
925 * Actions::parse_archivelink()
\r
926 * A link to the archives for the current blog (or for default blog)
\r
928 * @param string $linktext text for link
\r
931 public function parse_archivelink($linktext = '')
\r
933 global $blog, $CONF;
\r
936 echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
\r
940 echo $this->link(Link::create_archivelist_link(), $linktext);
\r
946 * Actions::parse_archivelist()
\r
948 * @param string $template name of template
\r
949 * @param string $category name of category
\r
950 * @param integer $limit the number of items in a display
\r
953 public function parse_archivelist($template, $category = 'all', $limit = 0)
\r
956 if ( $category == 'all' )
\r
960 $this->preBlogContent('archivelist',$blog);
\r
961 $this->setBlogCategory($blog, $category);
\r
962 $blog->showArchiveList($template, 'month', $limit);
\r
963 $this->postBlogContent('archivelist',$blog);
\r
968 * Actions::parse_archiveyearlist()
\r
970 * @param string $template name of template
\r
971 * @param string $category name of category
\r
972 * @param integer $limit the number of items in a display
\r
974 public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
\r
977 if ( $category == 'all' )
\r
981 $this->preBlogContent('archivelist',$blog);
\r
982 $this->setBlogCategory($blog, $category);
\r
983 $blog->showArchiveList($template, 'year', $limit);
\r
984 $this->postBlogContent('archivelist',$blog);
\r
989 * Actions::parse_archivetype()
\r
990 * Parse skinvar archivetype
\r
995 public function parse_archivetype()
\r
997 global $archivetype;
\r
1003 * Actions::parse_blog()
\r
1004 * Parse skinvar blog
\r
1006 * @param string $template name of template
\r
1007 * @param mixed $amount the number of items in a display, in case it includes the beginning
\r
1008 * @param string $category name of category
\r
1011 public function parse_blog($template, $amount = 10, $category = '')
\r
1013 global $blog, $startpos;
\r
1015 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1016 $this->setBlogCategory($blog, $category);
\r
1017 $this->preBlogContent('blog',$blog);
\r
1018 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
\r
1019 $this->postBlogContent('blog',$blog);
\r
1024 * Actions::parse_bloglist()
\r
1025 * Parse skinvar bloglist
\r
1026 * Shows a list of all blogs
\r
1028 * @param string $template name of template
\r
1029 * @param string $bnametype whether 'name' or 'shortname' is used for the link text
\r
1030 * @param string $orderby order criteria
\r
1031 * @param string $direction order ascending or descending
\r
1034 public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
\r
1036 Blog::showBlogList($template, $bnametype, $orderby, $direction);
\r
1041 * Actions::parse_blogsetting()
\r
1042 * Parse skinvar blogsetting
\r
1044 * @param string $which key of weblog settings
\r
1047 public function parse_blogsetting($which)
\r
1053 echo Entity::hsc($blog->getID());
\r
1056 echo Entity::hsc($blog->getURL());
\r
1059 echo Entity::hsc($blog->getName());
\r
1062 echo Entity::hsc($blog->getDescription());
\r
1065 echo Entity::hsc($blog->getShortName());
\r
1072 * Actions::parse_callback()
\r
1075 * @param string $eventName name of event
\r
1076 * @param string $type type of skin
\r
1079 public function parse_callback($eventName, $type)
\r
1082 $manager->notify($eventName, array('type' => $type));
\r
1087 * Actions::parse_category()
\r
1088 * Parse skinvar category
\r
1090 * @param string $type key of category settings
\r
1093 public function parse_category($type = 'name')
\r
1095 global $catid, $blog;
\r
1096 if ( !$blog->isValidCategory($catid) )
\r
1104 echo $blog->getCategoryName($catid);
\r
1107 echo $blog->getCategoryDesc($catid);
\r
1117 * Actions::parse_categorylist()
\r
1118 * Parse categorylist
\r
1120 * @param string $template name of template
\r
1121 * @param string $blogname name of weblog
\r
1124 public function parse_categorylist($template, $blogname = '')
\r
1126 global $blog, $manager;
\r
1128 // when no blog found
\r
1129 if ( ($blogname == '') && (!is_object($blog)) )
\r
1134 if ( $blogname == '' )
\r
1136 $this->preBlogContent('categorylist',$blog);
\r
1137 $blog->showCategoryList($template);
\r
1138 $this->postBlogContent('categorylist',$blog);
\r
1142 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1143 $this->preBlogContent('categorylist',$b);
\r
1144 $b->showCategoryList($template);
\r
1145 $this->postBlogContent('categorylist',$b);
\r
1151 * Actions::parse_charset()
\r
1152 * Parse skinvar charset
\r
1157 public function parse_charset()
\r
1159 echo i18n::get_current_charset();
\r
1164 * Actions::parse_commentform()
\r
1165 * Parse skinvar commentform
\r
1167 * @param string $destinationurl URI for redirection
\r
1170 public function parse_commentform($destinationurl = '')
\r
1172 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
\r
1174 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
\r
1175 if ( stristr($destinationurl, 'action.php') )
\r
1177 $args = func_get_args();
\r
1178 $destinationurl = $args[1];
\r
1179 ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
\r
1182 $actionurl = $CONF['ActionURL'];
\r
1184 // if item is closed, show message and do nothing
\r
1185 $item =& $manager->getItem($itemid,0,0);
\r
1186 if ( $item['closed'] || !$blog->commentsEnabled() )
\r
1188 $this->doForm('commentform-closed');
\r
1192 if ( !$blog->isPublic() && !$member->isLoggedIn() )
\r
1194 $this->doForm('commentform-closedtopublic');
\r
1198 if ( !$destinationurl )
\r
1200 // note: createLink returns an HTML encoded URL
\r
1201 $destinationurl = Link::create_link(
\r
1204 'itemid' => $itemid,
\r
1205 'title' => $item['title'],
\r
1206 'timestamp' => $item['timestamp'],
\r
1207 'extra' => $this->linkparams
\r
1213 // HTML encode URL
\r
1214 $destinationurl = Entity::hsc($destinationurl);
\r
1217 // values to prefill
\r
1218 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
\r
1221 $user = postVar('user');
\r
1224 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
\r
1227 $userid = postVar('userid');
\r
1230 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
\r
1233 $email = postVar('email');
\r
1236 $body = postVar('body');
\r
1238 $this->formdata = array(
\r
1239 'destinationurl' => $destinationurl, // url is already HTML encoded
\r
1240 'actionurl' => Entity::hsc($actionurl),
\r
1241 'itemid' => $itemid,
\r
1242 'user' => Entity::hsc($user),
\r
1243 'userid' => Entity::hsc($userid),
\r
1244 'email' => Entity::hsc($email),
\r
1245 'body' => Entity::hsc($body),
\r
1246 'membername' => $member->getDisplayName(),
\r
1247 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
\r
1250 if ( !$member->isLoggedIn() )
\r
1252 $this->doForm('commentform-notloggedin');
\r
1256 $this->doForm('commentform-loggedin');
\r
1262 * Actions::parse_comments()
\r
1263 * Parse skinvar comments
\r
1264 * include comments for one item
\r
1266 * @param string $template name of template
\r
1269 public function parse_comments($template)
\r
1271 global $itemid, $manager, $blog, $highlight;
\r
1272 $template =& $manager->getTemplate($template);
\r
1274 // create parser object & action handler
\r
1275 $actions = new ItemActions($blog);
\r
1276 $parser = new Parser($actions->getDefinedActions(),$actions);
\r
1277 $actions->setTemplate($template);
\r
1278 $actions->setParser($parser);
\r
1279 $item = Item::getitem($itemid, 0, 0);
\r
1280 $actions->setCurrentItem($item);
\r
1282 $comments = new Comments($itemid);
\r
1283 $comments->setItemActions($actions);
\r
1284 // shows ALL comments
\r
1285 $comments->showComments($template, -1, 1, $highlight);
\r
1290 * Actions::parse_errordiv()
\r
1296 public function parse_errordiv()
\r
1298 global $errormessage;
\r
1299 if ( $errormessage )
\r
1301 echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
\r
1307 * Actions::parse_errormessage()
\r
1308 * Parse skinvar errormessage
\r
1313 public function parse_errormessage()
\r
1315 global $errormessage;
\r
1316 echo $errormessage;
\r
1321 * Actions::parse_formdata()
\r
1324 * @param string $what key of format data
\r
1327 public function parse_formdata($what)
\r
1329 echo $this->formdata[$what];
\r
1334 * Actions::parse_ifcat()
\r
1337 * @param string $text
\r
1340 public function parse_ifcat($text = '')
\r
1342 if ( $text == '' )
\r
1345 $this->parse_if('category');
\r
1350 global $catid, $blog;
\r
1351 if ( $blog->isValidCategory($catid) )
\r
1360 * Actions::parse_image()
\r
1361 * Parse skinvar image
\r
1363 * @param string $what name of tag
\r
1366 public function parse_image($what = 'imgtag')
\r
1370 $imagetext = Entity::hsc(requestVar('imagetext'));
\r
1371 $imagepopup = requestVar('imagepopup');
\r
1372 $width = intRequestVar('width');
\r
1373 $height = intRequestVar('height');
\r
1374 $fullurl = Entity::hsc($CONF['MediaURL'] . $imagepopup);
\r
1393 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
\r
1400 * Actions::parse_imagetext()
\r
1401 * Parse skinvar imagetext
\r
1406 public function parse_imagetext()
\r
1408 $this->parse_image('imagetext');
\r
1413 * Actions::parse_item()
\r
1414 * Parse skinvar item
\r
1415 * include one item (no comments)
\r
1420 public function parse_item($template)
\r
1422 global $blog, $itemid, $highlight;
\r
1424 // need this to select default category
\r
1425 $this->setBlogCategory($blog, '');
\r
1426 $this->preBlogContent('item',$blog);
\r
1427 $r = $blog->showOneitem($itemid, $template, $highlight);
\r
1430 echo _ERROR_NOSUCHITEM;
\r
1432 $this->postBlogContent('item',$blog);
\r
1437 * Actions::parse_itemid()
\r
1438 * Parse skinvar itemid
\r
1443 public function parse_itemid()
\r
1451 * Actions::parseitemlink()
\r
1452 * Parse skinvar itemlink
\r
1457 public function parse_itemlink($linktext = '')
\r
1460 $this->itemlink($itemid, $linktext);
\r
1465 * Actions::parse_itemtitle()
\r
1471 public function parse_itemtitle($format = '')
\r
1473 global $manager, $itemid;
\r
1474 $item =& $manager->getItem($itemid,0,0);
\r
1476 switch ( $format )
\r
1479 echo Entity::hen($item['title']);
\r
1482 echo $item['title'];
\r
1486 echo Entity::hsc(strip_tags($item['title']));
\r
1493 * Actions::parse_loginform()
\r
1494 * Parse skinvar loginform
\r
1499 public function parse_loginform()
\r
1501 global $member, $CONF;
\r
1502 if ( !$member->isLoggedIn() )
\r
1504 $filename = 'loginform-notloggedin';
\r
1505 $this->formdata = array();
\r
1509 $filename = 'loginform-loggedin';
\r
1510 $this->formdata = array(
\r
1511 'membername' => $member->getDisplayName(),
\r
1514 $this->doForm($filename);
\r
1519 * Actions::parse_member()
\r
1520 * Parse skinvar member
\r
1521 * (includes a member info thingie)
\r
1523 * @param string $what which memberdata is needed
\r
1526 public function parse_member($what)
\r
1528 global $memberinfo, $member, $CONF;
\r
1530 // 1. only allow the member-details-page specific variables on member pages
\r
1531 if ( $this->skintype == 'member' )
\r
1536 echo Entity::hsc($memberinfo->getDisplayName());
\r
1539 echo Entity::hsc($memberinfo->getRealName());
\r
1542 echo Entity::hsc($memberinfo->getNotes());
\r
1545 echo Entity::hsc($memberinfo->getURL());
\r
1548 echo Entity::hsc($memberinfo->getEmail());
\r
1551 echo Entity::hsc($memberinfo->getID());
\r
1556 // 2. the next bunch of options is available everywhere, as long as the user is logged in
\r
1557 if ( $member->isLoggedIn() )
\r
1562 echo $member->getDisplayName();
\r
1564 case 'yourrealname':
\r
1565 echo $member->getRealName();
\r
1568 echo $member->getNotes();
\r
1571 echo $member->getURL();
\r
1574 echo $member->getEmail();
\r
1577 echo $member->getID();
\r
1579 case 'yourprofileurl':
\r
1580 if ($CONF['URLMode'] == 'pathinfo')
\r
1581 echo Link::create_member_link($member->getID());
\r
1583 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
\r
1591 * Link::parse_membermailform()
\r
1592 * Parse skinvar membermailform
\r
1594 * @param integer $rows the height for textarea
\r
1595 * @param integer $cols the width for textarea
\r
1596 * @param string $desturl URI to redirect
\r
1599 public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
\r
1601 global $member, $CONF, $memberid;
\r
1603 if ( $desturl == '' )
\r
1605 if ( $CONF['URLMode'] == 'pathinfo' )
\r
1607 $desturl = Link::create_member_link($memberid);
\r
1611 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
\r
1615 $message = postVar('message');
\r
1616 $frommail = postVar('frommail');
\r
1618 $this->formdata = array(
\r
1619 'url' => Entity::hsc($desturl),
\r
1620 'actionurl' => Entity::hsc($CONF['ActionURL']),
\r
1621 'memberid' => $memberid,
\r
1624 'message' => Entity::hsc($message),
\r
1625 'frommail' => Entity::hsc($frommail)
\r
1628 if ( $member->isLoggedIn() )
\r
1630 $this->doForm('membermailform-loggedin');
\r
1632 else if ( $CONF['NonmemberMail'] )
\r
1634 $this->doForm('membermailform-notloggedin');
\r
1638 $this->doForm('membermailform-disallowed');
\r
1644 * Actions::parse_nextarchive()
\r
1645 * Parse skinvar nextarchive
\r
1650 public function parse_nextarchive()
\r
1652 global $archivenext;
\r
1653 echo $archivenext;
\r
1658 * Parse skinvar nextitem
\r
1659 * (include itemid of next item)
\r
1664 public function parse_nextitem()
\r
1666 global $itemidnext;
\r
1667 if ( isset($itemidnext) )
\r
1669 echo (int)$itemidnext;
\r
1675 * Actions::parse_nextitemtitle()
\r
1676 * Parse skinvar nextitemtitle
\r
1677 * (include itemtitle of next item)
\r
1679 * @param string $format format of text
\r
1682 public function parse_nextitemtitle($format = '')
\r
1684 global $itemtitlenext;
\r
1686 switch ( $format )
\r
1689 echo Entity::hen($itemtitlenext);
\r
1692 echo $itemtitlenext;
\r
1696 echo Entity::hsc($itemtitlenext);
\r
1703 * Actions::parse_nextlink()
\r
1704 * Parse skinvar nextlink
\r
1706 * @param string $linktext text for content of anchor element
\r
1707 * @param integer $amount the amount of items in a display
\r
1708 * @param integer $recount increment from this value
\r
1711 public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
\r
1713 global $itemidnext, $archivenext, $startpos;
\r
1714 if ( $this->skintype == 'item' )
\r
1716 $this->itemlink($itemidnext, $linktext);
\r
1718 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
1720 $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
\r
1724 $this->archivelink($archivenext, $linktext);
\r
1730 * Actions::parse_nucleusbutton()
\r
1731 * Parse skinvar nucleusbutton
\r
1733 * @param string $imgurl URL for image
\r
1734 * @param integer $imgwidth width of image
\r
1735 * @param integer $imgheidht height of image
\r
1737 public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
\r
1740 if ( $imgurl == '' )
\r
1742 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
\r
1744 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
\r
1746 // when skindit IncludeMode is used: start from skindir
\r
1747 $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
\r
1750 $this->formdata = array(
\r
1751 'imgurl' => $imgurl,
\r
1752 'imgwidth' => $imgwidth,
\r
1753 'imgheight' => $imgheight,
\r
1755 $this->doForm('nucleusbutton');
\r
1760 * Actions::parse_otherarchive()
\r
1761 * Parse skinvar otherarchive
\r
1763 * @param string $blogname name of weblog
\r
1764 * @param string $template name of template
\r
1765 * @param string $category name of category
\r
1768 public function parse_otherarchive($blogname, $template, $category = '')
\r
1770 global $archive, $manager;
\r
1771 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
1772 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1773 $this->setBlogCategory($b, $category);
\r
1774 $this->preBlogContent('otherachive',$b);
\r
1775 $b->showArchive($template, $y, $m, $d);
\r
1776 $this->postBlogContent('otherachive',$b);
\r
1781 * Actions::parse_otherarchivedaylist()
\r
1782 * Parse skinvar otherarchivedaylist
\r
1784 * @param string $blogname name of weblog
\r
1785 * @param string $template name of template
\r
1786 * @param string $category name of category
\r
1787 * @param integer $limit the amount of items in a display
\r
1790 public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
\r
1793 if ( $category == 'all')
\r
1797 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1798 $this->setBlogCategory($b, $category);
\r
1799 $this->preBlogContent('otherarchivelist',$b);
\r
1800 $b->showArchiveList($template, 'day', $limit);
\r
1801 $this->postBlogContent('otherarchivelist',$b);
\r
1806 * Actions::parse_otherarchivelist()
\r
1807 * Parse skinvar otherarchivelist
\r
1809 * @param string $blogname name of weblog
\r
1810 * @param string $template name of template
\r
1811 * @param string $category name of category
\r
1812 * @param integer $limit the amount of items in a display
\r
1815 public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
\r
1818 if ( $category == 'all' )
\r
1822 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1823 $this->setBlogCategory($b, $category);
\r
1824 $this->preBlogContent('otherarchivelist',$b);
\r
1825 $b->showArchiveList($template, 'month', $limit);
\r
1826 $this->postBlogContent('otherarchivelist',$b);
\r
1831 * Actions::parse_otherarchiveyearlist()
\r
1832 * Parse skinvar otherarchiveyearlist
\r
1834 * @param string $blogname name of weblog
\r
1835 * @param string $template name of template
\r
1836 * @param string $category name of category
\r
1837 * @limit integer $limit the amount of items in a display
\r
1839 public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
\r
1842 if ( $category == 'all' )
\r
1846 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1847 $this->setBlogCategory($b, $category);
\r
1848 $this->preBlogContent('otherarchivelist',$b);
\r
1849 $b->showArchiveList($template, 'year', $limit);
\r
1850 $this->postBlogContent('otherarchivelist',$b);
\r
1855 * Actions::parse_otherblog()
\r
1856 * Parse skinvar otherblog
\r
1858 * @param string $blogname name of weblog
\r
1859 * @param string $template name of template
\r
1860 * @param mixed $amount the amount of items, in case it includes the beginning
\r
1861 * @param string $category name of category
\r
1864 public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
\r
1868 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1870 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1871 $this->setBlogCategory($b, $category);
\r
1872 $this->preBlogContent('otherblog',$b);
\r
1873 $this->amountfound = $b->readLog($template, $limit, $offset);
\r
1874 $this->postBlogContent('otherblog',$b);
\r
1879 * Actions::parse_othersearchresults()
\r
1880 * Parse skinvar othersearchresults
\r
1882 * @param string $blogname name of weblog
\r
1883 * @param string $template name of template
\r
1884 * @param integer $maxresults the amount of results
\r
1887 public function parse_othersearchresults($blogname, $template, $maxresults = 50)
\r
1889 global $query, $amount, $manager, $startpos;
\r
1890 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1891 // need this to select default category
\r
1892 $this->setBlogCategory($b, '');
\r
1893 $this->preBlogContent('othersearchresults',$b);
\r
1894 $b->search($query, $template, $amount, $maxresults, $startpos);
\r
1895 $this->postBlogContent('othersearchresults',$b);
\r
1900 * Actions::parse_plugin()
\r
1901 * Executes a plugin skinvar
\r
1902 * extra parameters can be added
\r
1904 * @param string $pluginName name of plugin (without the NP_)
\r
1907 public function parse_plugin($pluginName)
\r
1911 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
1918 $params = func_get_args();
\r
1920 // remove plugin name
\r
1921 array_shift($params);
\r
1923 // add skin type on front
\r
1924 array_unshift($params, $this->skintype);
\r
1926 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
\r
1931 * Actions::parse_prevarchive()
\r
1932 * Parse skinvar prevarchive
\r
1937 public function parse_prevarchive()
\r
1939 global $archiveprev;
\r
1940 echo $archiveprev;
\r
1944 * Actions::parse_preview()
\r
1945 * Parse skinvar preview
\r
1947 * @param string $template name of tempalte
\r
1950 public function parse_preview($template)
\r
1952 global $blog, $CONF, $manager;
\r
1954 $template =& $manager->getTemplate($template);
\r
1956 $row['body'] = '<span id="prevbody"></span>';
\r
1957 $row['title'] = '<span id="prevtitle"></span>';
\r
1958 $row['more'] = '<span id="prevmore"></span>';
\r
1959 $row['itemlink'] = '';
\r
1960 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
\r
1962 echo Template::fill($template['ITEM_HEADER'],$row);
\r
1963 echo Template::fill($template['ITEM'],$row);
\r
1964 echo Template::fill($template['ITEM_FOOTER'],$row);
\r
1969 * Actions::parse_previtem()
\r
1970 * Parse skinvar previtem
\r
1971 * (include itemid of prev item)
\r
1976 public function parse_previtem()
\r
1978 global $itemidprev;
\r
1979 if ( isset($itemidprev) )
\r
1981 echo (integer) $itemidprev;
\r
1987 * Actions::parse_previtemtitle()
\r
1988 * Parse skinvar previtemtitle
\r
1989 * (include itemtitle of prev item)
\r
1991 * @param String $format string format
\r
1992 * @return String formatted string
\r
1994 public function parse_previtemtitle($format = '')
\r
1996 global $itemtitleprev;
\r
1998 switch ( $format )
\r
2001 echo Entity::hen($itemtitleprev);
\r
2004 echo $itemtitleprev;
\r
2008 echo Entity::hsc($itemtitleprev);
\r
2015 * Actions::parse_prevlink()
\r
2016 * Parse skinvar prevlink
\r
2018 * @param string $linktext text as a content of anchor element
\r
2019 * @param integer the amount of links
\r
2022 public function parse_prevlink($linktext = '', $amount = 10)
\r
2024 global $itemidprev, $archiveprev, $startpos;
\r
2026 if ( $this->skintype == 'item' )
\r
2028 $this->itemlink($itemidprev, $linktext);
\r
2030 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
2032 $this->searchlink($amount, $startpos, 'prev', $linktext);
\r
2036 $this->archivelink($archiveprev, $linktext);
\r
2042 * Actions::parse_query()
\r
2043 * Parse skinvar query
\r
2044 * (includes the search query)
\r
2049 public function parse_query()
\r
2052 echo Entity::hsc($query);
\r
2057 * Actions::parse_referer()
\r
2058 * Parse skinvar referer
\r
2063 public function parse_referer()
\r
2065 echo Entity::hsc(serverVar('HTTP_REFERER'));
\r
2070 * Actions::parse_searchform()
\r
2071 * Parse skinvar searchform
\r
2073 * @param string $blogname name of weblog
\r
2076 public function parse_searchform($blogname = '')
\r
2078 global $CONF, $manager, $maxresults;
\r
2081 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
\r
2087 // use default blog when no blog is selected
\r
2088 $this->formdata = array(
\r
2089 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
\r
2090 'query' => Entity::hsc(getVar('query')),
\r
2092 $this->doForm('searchform');
\r
2097 * Actions::parse_searchresults()
\r
2098 * Parse skinvar searchresults
\r
2100 * @param string $template name of tempalte
\r
2101 * @param integer $maxresults searched items in a display
\r
2104 public function parse_searchresults($template, $maxresults = 50 )
\r
2106 global $blog, $query, $amount, $startpos;
\r
2108 $this->setBlogCategory($blog, ''); // need this to select default category
\r
2109 $this->preBlogContent('searchresults',$blog);
\r
2110 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
\r
2111 $this->postBlogContent('searchresults',$blog);
\r
2116 * Actions::parse_self()
\r
2117 * Parse skinvar self
\r
2122 public function parse_self()
\r
2125 echo $CONF['Self'];
\r
2130 * Actions::parse_sitevar()
\r
2131 * Parse skinvar sitevar
\r
2132 * (include a sitevar)
\r
2134 * @param string $which
\r
2137 public function parse_sitevar($which)
\r
2143 echo $CONF['IndexURL'];
\r
2146 echo $CONF['SiteName'];
\r
2149 echo $CONF['AdminEmail'];
\r
2152 echo $CONF['AdminURL'];
\r
2158 * Actions::parse_skinname()
\r
2164 public function parse_skinname()
\r
2166 echo $this->skin->getName();
\r
2171 * Actions::parse_skintype()
\r
2172 * Parse skintype (experimental)
\r
2177 public function parse_skintype()
\r
2179 echo $this->skintype;
\r
2184 * Actions::parse_text()
\r
2190 public function parse_text($which)
\r
2192 // constant($which) only available from 4.0.4 :(
\r
2193 if ( defined($which) )
\r
2195 eval("echo $which;");
\r
2201 * Actions::parse_ticket()
\r
2207 public function parse_ticket()
\r
2210 $manager->addTicketHidden();
\r
2215 * Actions::parse_todaylink()
\r
2216 * Parse skinvar todaylink
\r
2217 * A link to the today page (depending on selected blog, etc...)
\r
2219 * @param string $linktext text for link
\r
2222 public function parse_todaylink($linktext = '')
\r
2224 global $blog, $CONF;
\r
2227 echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
\r
2231 echo $this->link($CONF['SiteUrl'], $linktext);
\r
2238 * When commentform is not used, to include a hidden field with itemid
\r
2243 public function parse_vars()
\r
2246 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
\r
2251 * Actions::parse_version()
\r
2252 * Parse skinvar version
\r
2253 * (include nucleus versionnumber)
\r
2258 public function parse_version()
\r
2261 echo 'Nucleus CMS ' . $nucleus['version'];
\r
2266 * Actions::parse_sticky()
\r
2267 * Parse skinvar sticky
\r
2269 * @param integer $itemnumber id of item
\r
2270 * @param string $template name of template
\r
2273 public function parse_sticky($itemnumber = 0, $template = '')
\r
2277 $itemnumber = intval($itemnumber);
\r
2278 $itemarray = array($itemnumber);
\r
2280 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
\r
2281 $this->preBlogContent('sticky',$b);
\r
2282 $this->amountfound = $b->readLogFromList($itemarray, $template);
\r
2283 $this->postBlogContent('sticky',$b);
\r