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 1755 2012-04-14 10:05:49Z sakamocchi $
\r
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
67 'otherarchivedaylist',
\r
69 'otherarchiveyearlist',
\r
84 // deprecated (Nucleus v2.0)
\r
85 /* TODO: remove this */
\r
90 * Actions::$skin_type_friendly_names
\r
91 * friendly name for wrapped page types
\r
93 static public $skin_type_friendly_names = array(
\r
94 'index' => _SKIN_PART_MAIN,
\r
95 'item' => _SKIN_PART_ITEM,
\r
96 'archivelist' => _SKIN_PART_ALIST,
\r
97 'archive' => _SKIN_PART_ARCHIVE,
\r
98 'search' => _SKIN_PART_SEARCH,
\r
99 'error' => _SKIN_PART_ERROR,
\r
100 'member' => _SKIN_PART_MEMBER,
\r
101 'imagepopup' => _SKIN_PART_POPUP
\r
105 * Actions::getDefinedActions()
\r
108 * @param string $type page type
\r
109 * @return array allowed actions for the page type
\r
111 static public function getDefinedActions($type='')
\r
113 $extra_actions = array();
\r
118 $extra_actions = array(
\r
132 $extra_actions = array(
\r
149 case 'archivelist':
\r
150 $extra_actions = array(
\r
160 $extra_actions = array(
\r
167 'othersearchresults',
\r
175 $extra_actions = array(
\r
177 // deprecated (Nucleus v2.0)
\r
178 /* TODO: remove this */
\r
183 $extra_actions = array(
\r
191 $extra_actions = array(
\r
214 $extra_actions = array(
\r
220 $extra_actions = array(
\r
237 return array_merge(self::$default_actions, $extra_actions);
\r
241 * Actions::getSkinTypeFriendlyNames()
\r
245 * @return array list of friendly names for page actions
\r
247 static public function getSkinTypeFriendlyNames()
\r
249 return self::$skin_type_friendly_names;
\r
253 * Actions::__construct()
\r
254 * Constructor for a new Actions object
\r
256 * @param string $type
\r
259 public function __construct($type)
\r
263 // call constructor of superclass first
\r
264 $this->BaseActions();
\r
265 $this->skintype = $type;
\r
269 $this->linkparams = array('catid' => $catid);
\r
275 * Actions::setSkin()
\r
277 * @param object $skin an instance of Skin class
\r
280 public function setSkin(&$skin)
\r
282 $this->skin =& $skin;
\r
287 * Actions::setParser()
\r
290 * @param object $parser an instance of Parser class
\r
293 public function setParser(&$parser)
\r
295 $this->parser =& $parser;
\r
300 * Actions::doForm()
\r
301 * Forms get parsedincluded now, using an extra <formdata> skinvar
\r
303 * @param string $filename
\r
306 public function doForm($filename)
\r
308 global $DIR_NUCLEUS;
\r
309 array_push($this->parser->actions,'formdata','text','callback','errordiv','ticket');
\r
311 $oldIncludeMode = Parser::getProperty('IncludeMode');
\r
312 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
\r
313 Parser::setProperty('IncludeMode','normal');
\r
314 Parser::setProperty('IncludePrefix','');
\r
316 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
\r
317 Parser::setProperty('IncludeMode',$oldIncludeMode);
\r
318 Parser::setProperty('IncludePrefix',$oldIncludePrefix);
\r
320 array_pop($this->parser->actions); // errordiv
\r
321 array_pop($this->parser->actions); // callback
\r
322 array_pop($this->parser->actions); // text
\r
323 array_pop($this->parser->actions); // formdata
\r
324 array_pop($this->parser->actions); // ticket
\r
329 * Actions::checkCondition()
\r
330 * Checks conditions for if statements
\r
332 * @param string $field type of <%if%>
\r
333 * @param string $name property of field
\r
334 * @param string $value value of property
\r
335 * @return boolean condition
\r
337 public function checkCondition($field, $name='', $value = '')
\r
339 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
345 $condition = ($blog && $this->ifCategory($name,$value));
\r
347 case 'blogsetting':
\r
348 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
351 $condition = $member->isLoggedIn();
\r
354 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
\r
357 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
\r
360 $condition = ($itemidnext != '');
\r
363 $condition = ($itemidprev != '');
\r
365 case 'archiveprevexists':
\r
366 $condition = ($archiveprevexists == true);
\r
368 case 'archivenextexists':
\r
369 $condition = ($archivenextexists == true);
\r
372 $condition = (($name == $this->skintype) || ($name == requestVar('action')));
\r
375 $condition = $this->ifHasPlugin($name, $value);
\r
378 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);
\r
385 * Actions::_ifHasPlugin()
\r
386 * hasplugin,PlugName
\r
387 * -> checks if plugin exists
\r
388 * hasplugin,PlugName,OptionName
\r
389 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
390 * hasplugin,PlugName,OptionName=value
\r
391 * -> checks if the option OptionName from plugin PlugName is set to value
\r
393 * @param string $name name of plugin
\r
394 * @param string $value
\r
397 private function ifHasPlugin($name, $value)
\r
400 $condition = false;
\r
401 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
402 if ( $manager->pluginInstalled("NP_{$name}") )
\r
404 $plugin =& $manager->getPlugin("NP_{$name}");
\r
405 if ( $plugin != NULL )
\r
407 if ( $value == "" )
\r
413 list($name2, $value2) = preg_split('#=#', $value, 2);
\r
414 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
\r
418 else if ( $plugin->getOption($name2) == $value2 )
\r
429 * Actions::ifPlugin()
\r
430 * Checks if a plugin exists and call its doIf function
\r
432 * @param string $name name of plugin
\r
433 * @param string $key name of plugin option
\r
434 * @param string $value value of plugin option
\r
437 private function ifPlugin($name, $key = '', $value = '')
\r
441 $plugin =& $manager->getPlugin("NP_{$name}");
\r
447 $params = func_get_args();
\r
448 array_shift($params);
\r
450 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r
454 * Actions::ifCategory()
\r
455 * Different checks for a category
\r
457 * @param string $name
\r
458 * @param string $value
\r
461 private function ifCategory($name = '', $value='')
\r
463 global $blog, $catid;
\r
465 // when no parameter is defined, just check if a category is selected
\r
466 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )
\r
468 return $blog->isValidCategory($catid);
\r
471 // check category name
\r
472 if ( $name == 'catname' )
\r
474 $value = $blog->getCategoryIdFromName($value);
\r
475 if ( $value == $catid )
\r
477 return $blog->isValidCategory($catid);
\r
481 // check category id
\r
482 if ( ($name == 'catid') && ($value == $catid) )
\r
484 return $blog->isValidCategory($catid);
\r
490 * Actions::ifOnTeam()
\r
491 * Checks if a member is on the team of a blog and return his rights
\r
493 * @param string $blogName name of weblog
\r
496 private function ifOnTeam($blogName = '')
\r
498 global $blog, $member, $manager;
\r
500 // when no blog found
\r
501 if ( ($blogName == '') && !is_object($blog) )
\r
506 // explicit blog selection
\r
507 if ( $blogName != '' )
\r
509 $blogid = getBlogIDFromName($blogName);
\r
512 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
514 // use current blog
\r
515 $blogid = $blog->getID();
\r
518 return $member->teamRights($blogid);
\r
522 * Actions::ifAdmin()
\r
523 * Checks if a member is admin of a blog
\r
525 * @param string $blogName name of weblog
\r
528 private function ifAdmin($blogName = '')
\r
530 global $blog, $member, $manager;
\r
532 // when no blog found
\r
533 if ( ($blogName == '') && (!is_object($blog)) )
\r
538 // explicit blog selection
\r
539 if ( $blogName != '' )
\r
541 $blogid = getBlogIDFromName($blogName);
\r
544 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
546 // use current blog
\r
547 $blogid = $blog->getID();
\r
550 return $member->isBlogAdmin($blogid);
\r
556 * - a raw link (html/xml encoded) when no linktext is provided
\r
557 * - a (x)html <a href... link when a text is present (text htmlencoded)
\r
559 * @param string $url URL for href attribute of anchor element
\r
560 * @param string $linktext content of anchor element
\r
563 private function link($url, $linktext = '')
\r
565 $u = Entity::hsc($url);
\r
566 // fix URLs that already had encoded ampersands
\r
567 $u = preg_replace("#&amp;#", '&', $u);
\r
568 if ( $linktext != '' )
\r
570 $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';
\r
580 * Actions::searchlink()
\r
581 * Outputs a next/prev link
\r
583 * @param $maxresults
\r
584 * The maximum amount of items shown per page (e.g. 10)
\r
586 * Current start position (requestVar('startpos'))
\r
587 * @param $direction
\r
588 * either 'prev' or 'next'
\r
590 * When present, the output will be a full <a href...> link. When empty,
\r
591 * only a raw link will be outputted
\r
593 private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')
\r
595 global $CONF, $blog, $query, $amount;
\r
596 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
\r
597 $startpos = (integer) $startpos;
\r
598 $parsed = parse_url(serverVar('REQUEST_URI'));
\r
599 $path = $parsed['path'];
\r
600 $parsed = $parsed['query'];
\r
603 if ( $direction == 'prev' )
\r
605 if ( intval($startpos) - intval($maxresults) >= 0 )
\r
607 $startpos = intval($startpos) - intval($maxresults);
\r
609 if ( $this->skintype == 'index' )
\r
613 else if ( $this->skintype == 'search' )
\r
615 $url = $CONF['SearchURL'];
\r
617 $url .= '?' . alterQueryStr($parsed,'startpos',$startpos);
\r
620 else if ( $direction == 'next' )
\r
622 global $navigationItems;
\r
623 if ( !isset($navigationItems) )
\r
625 $navigationItems = 0;
\r
630 $iAmountOnPage = 0;
\r
634 $iAmountOnPage = $this->amountfound;
\r
637 if ( intval($navigationItems) > 0 )
\r
639 $iAmountOnPage = intval($navigationItems) - intval($startpos);
\r
641 elseif ( $iAmountOnPage == 0 )
\r
644 * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
\r
645 * try a count query
\r
647 if ( $this->skintype == 'index' )
\r
649 $sqlquery = $blog->getSqlBlog('', 'count');
\r
652 else if ( $this->skintype == 'search' )
\r
654 $unused_highlight = '';
\r
655 $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
\r
656 $url = $CONF['SearchURL'];
\r
660 $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
\r
665 if ( intval($iAmountOnPage) >= intval($maxresults) )
\r
667 $startpos = intval($startpos) + intval($maxresults);
\r
668 $url .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
\r
674 echo $this->link($url, $linktext);
\r
680 * Actions::itemlink()
\r
681 * Creates an item link and if no id is given a todaylink
\r
683 * @param integer $id id for link
\r
684 * @param string $linktext text for link
\r
687 private function itemlink($id, $linktext = '')
\r
692 echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);
\r
696 $this->parse_todaylink($linktext);
\r
702 * Actions::archivelink)
\r
703 * Creates an archive link and if no id is given a todaylink
\r
705 * @param integer $id id for link
\r
706 * @param string $linktext text for link
\r
709 private function archivelink($id, $linktext = '')
\r
711 global $CONF, $blog;
\r
714 echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
\r
718 $this->parse_todaylink($linktext);
\r
724 * Actions:setBlogCategory()
\r
725 * Helper function that sets the category that a blog will need to use
\r
727 * @param string $blog An object of the blog class, passed by reference (we want to make changes to it)
\r
728 * @param string $catname The name of the category to use
\r
731 private function setBlogCategory(&$blog, $catname)
\r
734 if ( $catname != '' )
\r
736 $blog->setSelectedCategoryByName($catname);
\r
740 $blog->setSelectedCategory($catid);
\r
746 * Actions::preBlogContent()
\r
747 * Notifies the Manager that a PreBlogContent event occurs
\r
749 * @param string $type type of skin
\r
750 * @param object $blog an instance of Blog class
\r
753 private function preBlogContent($type, &$blog)
\r
756 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
\r
761 * Actions::postBlogContent()
\r
762 * Notifies the Manager that a PostBlogContent event occurs
\r
764 * @param string $type type of skin
\r
765 * @param objecct $blog an instance of Blog class
\r
768 private function postBlogContent($type, &$blog)
\r
771 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
\r
776 * Actions::parse_additemform()
\r
777 * Parse skinvar additemform
\r
782 public function parse_additemform()
\r
784 global $blog, $CONF;
\r
785 $this->formdata = array(
\r
786 'adminurl' => Entity::hsc($CONF['AdminURL']),
\r
787 'catid' => $blog->getDefaultCategory()
\r
789 $blog->InsertJavaScriptInfo();
\r
790 $this->doForm('additemform');
\r
795 * Actions::parse_addlink()
\r
796 * Parse skinvar addlink
\r
797 * A Link that allows to open a bookmarklet to add an item
\r
799 public function parse_addlink()
\r
801 global $CONF, $member, $blog;
\r
802 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
\r
804 echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
\r
810 * Actions::parse_addpopupcode()
\r
811 * Parse skinvar addpopupcode
\r
812 * Code that opens a bookmarklet in an popup window
\r
817 public function parse_addpopupcode()
\r
819 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
824 * Parse skinvar adminurl
\r
825 * (shortcut for admin url)
\r
830 public function parse_adminurl()
\r
832 $this->parse_sitevar('adminurl');
\r
837 * Actions::parse_archive()
\r
838 * Parse skinvar archive
\r
840 * @param string $template name of template
\r
841 * @param string $category name of category
\r
844 public function parse_archive($template, $category = '')
\r
846 global $blog, $archive;
\r
847 // can be used with either yyyy-mm or yyyy-mm-dd
\r
848 sscanf($archive,'%d-%d-%d', $y, $m, $d);
\r
849 $this->setBlogCategory($blog, $category);
\r
850 $this->preBlogContent('achive',$blog);
\r
851 $blog->showArchive($template, $y, $m, $d);
\r
852 $this->postBlogContent('achive',$blog);
\r
857 * Actions::parse_archivedate()
\r
858 * %archivedate(locale,date format)%
\r
860 * @param string $locale
\r
863 public function parse_archivedate($locale = '-def-')
\r
868 * TODO: these lines are no meaning because there is no $template.
\r
869 if ( $locale == '-def-' )
\r
871 setlocale(LC_TIME, $template['LOCALE']);
\r
875 setlocale(LC_TIME, $locale);
\r
879 // get archive date
\r
880 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
883 $args = func_get_args();
\r
884 // format can be spread over multiple parameters
\r
885 if ( sizeof($args) > 1 )
\r
887 // take away locale
\r
888 array_shift($args);
\r
890 $format=implode(',',$args);
\r
892 elseif ( $d == 0 && $m !=0 )
\r
902 $format = '%d %B %Y';
\r
904 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
\r
909 * Actions::parse_archivedaylist()
\r
910 * Parse skinvar archivedaylist
\r
912 * @param string $template name of template
\r
913 * @param string $category name of category
\r
914 * @param integer $limit the number of items in a display
\r
917 public function parse_archivedaylist($template, $category = 'all', $limit = 0)
\r
920 if ( $category == 'all' )
\r
924 $this->preBlogContent('archivelist',$blog);
\r
925 $this->setBlogCategory($blog, $category);
\r
926 $blog->showArchiveList($template, 'day', $limit);
\r
927 $this->postBlogContent('archivelist',$blog);
\r
932 * Actions::parse_archivelink()
\r
933 * A link to the archives for the current blog (or for default blog)
\r
935 * @param string $linktext text for link
\r
938 public function parse_archivelink($linktext = '')
\r
940 global $blog, $CONF;
\r
943 echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
\r
947 echo $this->link(Link::create_archivelist_link(), $linktext);
\r
953 * Actions::parse_archivelist()
\r
955 * @param string $template name of template
\r
956 * @param string $category name of category
\r
957 * @param integer $limit the number of items in a display
\r
960 public function parse_archivelist($template, $category = 'all', $limit = 0)
\r
963 if ( $category == 'all' )
\r
967 $this->preBlogContent('archivelist',$blog);
\r
968 $this->setBlogCategory($blog, $category);
\r
969 $blog->showArchiveList($template, 'month', $limit);
\r
970 $this->postBlogContent('archivelist',$blog);
\r
975 * Actions::parse_archiveyearlist()
\r
977 * @param string $template name of template
\r
978 * @param string $category name of category
\r
979 * @param integer $limit the number of items in a display
\r
981 public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
\r
984 if ( $category == 'all' )
\r
988 $this->preBlogContent('archivelist',$blog);
\r
989 $this->setBlogCategory($blog, $category);
\r
990 $blog->showArchiveList($template, 'year', $limit);
\r
991 $this->postBlogContent('archivelist',$blog);
\r
996 * Actions::parse_archivetype()
\r
997 * Parse skinvar archivetype
\r
1002 public function parse_archivetype()
\r
1004 global $archivetype;
\r
1005 echo $archivetype;
\r
1010 * Actions::parse_blog()
\r
1011 * Parse skinvar blog
\r
1013 * @param string $template name of template
\r
1014 * @param mixed $amount the number of items in a display, in case it includes the beginning
\r
1015 * @param string $category name of category
\r
1018 public function parse_blog($template, $amount = 10, $category = '')
\r
1020 global $blog, $startpos;
\r
1022 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1023 $this->setBlogCategory($blog, $category);
\r
1024 $this->preBlogContent('blog',$blog);
\r
1025 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
\r
1026 $this->postBlogContent('blog',$blog);
\r
1031 * Actions::parse_bloglist()
\r
1032 * Parse skinvar bloglist
\r
1033 * Shows a list of all blogs
\r
1035 * @param string $template name of template
\r
1036 * @param string $bnametype whether 'name' or 'shortname' is used for the link text
\r
1037 * @param string $orderby order criteria
\r
1038 * @param string $direction order ascending or descending
\r
1041 public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
\r
1043 Blog::showBlogList($template, $bnametype, $orderby, $direction);
\r
1048 * Actions::parse_blogsetting()
\r
1049 * Parse skinvar blogsetting
\r
1051 * @param string $which key of weblog settings
\r
1054 public function parse_blogsetting($which)
\r
1060 echo Entity::hsc($blog->getID());
\r
1063 echo Entity::hsc($blog->getURL());
\r
1066 echo Entity::hsc($blog->getName());
\r
1069 echo Entity::hsc($blog->getDescription());
\r
1072 echo Entity::hsc($blog->getShortName());
\r
1079 * Actions::parse_callback()
\r
1082 * @param string $eventName name of event
\r
1083 * @param string $type type of skin
\r
1086 public function parse_callback($eventName, $type)
\r
1089 $manager->notify($eventName, array('type' => $type));
\r
1094 * Actions::parse_category()
\r
1095 * Parse skinvar category
\r
1097 * @param string $type key of category settings
\r
1100 public function parse_category($type = 'name')
\r
1102 global $catid, $blog;
\r
1103 if ( !$blog->isValidCategory($catid) )
\r
1111 echo $blog->getCategoryName($catid);
\r
1114 echo $blog->getCategoryDesc($catid);
\r
1124 * Actions::parse_categorylist()
\r
1125 * Parse categorylist
\r
1127 * @param string $template name of template
\r
1128 * @param string $blogname name of weblog
\r
1131 public function parse_categorylist($template, $blogname = '')
\r
1133 global $blog, $manager;
\r
1135 // when no blog found
\r
1136 if ( ($blogname == '') && (!is_object($blog)) )
\r
1141 if ( $blogname == '' )
\r
1143 $this->preBlogContent('categorylist',$blog);
\r
1144 $blog->showCategoryList($template);
\r
1145 $this->postBlogContent('categorylist',$blog);
\r
1149 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1150 $this->preBlogContent('categorylist',$b);
\r
1151 $b->showCategoryList($template);
\r
1152 $this->postBlogContent('categorylist',$b);
\r
1158 * Actions::parse_charset()
\r
1159 * Parse skinvar charset
\r
1164 public function parse_charset()
\r
1166 echo i18n::get_current_charset();
\r
1171 * Actions::parse_commentform()
\r
1172 * Parse skinvar commentform
\r
1174 * @param string $destinationurl URI for redirection
\r
1177 public function parse_commentform($destinationurl = '')
\r
1179 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
\r
1181 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
\r
1182 if ( stristr($destinationurl, 'action.php') )
\r
1184 $args = func_get_args();
\r
1185 $destinationurl = $args[1];
\r
1186 ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
\r
1189 $actionurl = $CONF['ActionURL'];
\r
1191 // if item is closed, show message and do nothing
\r
1192 $item =& $manager->getItem($itemid,0,0);
\r
1193 if ( $item['closed'] || !$blog->commentsEnabled() )
\r
1195 $this->doForm('commentform-closed');
\r
1199 if ( !$blog->isPublic() && !$member->isLoggedIn() )
\r
1201 $this->doForm('commentform-closedtopublic');
\r
1205 if ( !$destinationurl )
\r
1207 // note: createLink returns an HTML encoded URL
\r
1208 $destinationurl = Link::create_link(
\r
1211 'itemid' => $itemid,
\r
1212 'title' => $item['title'],
\r
1213 'timestamp' => $item['timestamp'],
\r
1214 'extra' => $this->linkparams
\r
1220 // HTML encode URL
\r
1221 $destinationurl = Entity::hsc($destinationurl);
\r
1224 // values to prefill
\r
1225 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
\r
1228 $user = postVar('user');
\r
1231 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
\r
1234 $userid = postVar('userid');
\r
1237 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
\r
1240 $email = postVar('email');
\r
1243 $body = postVar('body');
\r
1245 $this->formdata = array(
\r
1246 'destinationurl' => $destinationurl, // url is already HTML encoded
\r
1247 'actionurl' => Entity::hsc($actionurl),
\r
1248 'itemid' => $itemid,
\r
1249 'user' => Entity::hsc($user),
\r
1250 'userid' => Entity::hsc($userid),
\r
1251 'email' => Entity::hsc($email),
\r
1252 'body' => Entity::hsc($body),
\r
1253 'membername' => $member->getDisplayName(),
\r
1254 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
\r
1257 if ( !$member->isLoggedIn() )
\r
1259 $this->doForm('commentform-notloggedin');
\r
1263 $this->doForm('commentform-loggedin');
\r
1269 * Actions::parse_comments()
\r
1270 * Parse skinvar comments
\r
1271 * include comments for one item
\r
1273 * @param string $template name of template
\r
1276 public function parse_comments($template)
\r
1278 global $itemid, $manager, $blog, $highlight;
\r
1279 $template =& $manager->getTemplate($template);
\r
1281 // create parser object & action handler
\r
1282 $actions = new ItemActions($blog);
\r
1283 $parser = new Parser($actions->getDefinedActions(),$actions);
\r
1284 $actions->setTemplate($template);
\r
1285 $actions->setParser($parser);
\r
1286 $item = Item::getitem($itemid, 0, 0);
\r
1287 $actions->setCurrentItem($item);
\r
1289 $comments = new Comments($itemid);
\r
1290 $comments->setItemActions($actions);
\r
1291 // shows ALL comments
\r
1292 $comments->showComments($template, -1, 1, $highlight);
\r
1297 * Actions::parse_errordiv()
\r
1303 public function parse_errordiv()
\r
1305 global $errormessage;
\r
1306 if ( $errormessage )
\r
1308 echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
\r
1314 * Actions::parse_errormessage()
\r
1315 * Parse skinvar errormessage
\r
1320 public function parse_errormessage()
\r
1322 global $errormessage;
\r
1323 echo $errormessage;
\r
1328 * Actions::parse_formdata()
\r
1331 * @param string $what key of format data
\r
1334 public function parse_formdata($what)
\r
1336 echo $this->formdata[$what];
\r
1341 * Actions::parse_ifcat()
\r
1344 * @param string $text
\r
1347 public function parse_ifcat($text = '')
\r
1349 if ( $text == '' )
\r
1352 $this->parse_if('category');
\r
1357 global $catid, $blog;
\r
1358 if ( $blog->isValidCategory($catid) )
\r
1367 * Actions::parse_image()
\r
1368 * Parse skinvar image
\r
1370 * @param string $what name of tag
\r
1373 public function parse_image($what = 'imgtag')
\r
1377 $imagetext = Entity::hsc(requestVar('imagetext'));
\r
1378 $imagepopup = requestVar('imagepopup');
\r
1379 $width = intRequestVar('width');
\r
1380 $height = intRequestVar('height');
\r
1381 $fullurl = Entity::hsc($CONF['MediaURL'] . $imagepopup);
\r
1400 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
\r
1407 * Actions::parse_imagetext()
\r
1408 * Parse skinvar imagetext
\r
1413 public function parse_imagetext()
\r
1415 $this->parse_image('imagetext');
\r
1420 * Actions::parse_item()
\r
1421 * Parse skinvar item
\r
1422 * include one item (no comments)
\r
1427 public function parse_item($template)
\r
1429 global $blog, $itemid, $highlight;
\r
1431 // need this to select default category
\r
1432 $this->setBlogCategory($blog, '');
\r
1433 $this->preBlogContent('item',$blog);
\r
1434 $r = $blog->showOneitem($itemid, $template, $highlight);
\r
1437 echo _ERROR_NOSUCHITEM;
\r
1439 $this->postBlogContent('item',$blog);
\r
1444 * Actions::parse_itemid()
\r
1445 * Parse skinvar itemid
\r
1450 public function parse_itemid()
\r
1458 * Actions::parseitemlink()
\r
1459 * Parse skinvar itemlink
\r
1464 public function parse_itemlink($linktext = '')
\r
1467 $this->itemlink($itemid, $linktext);
\r
1472 * Actions::parse_itemtitle()
\r
1478 public function parse_itemtitle($format = '')
\r
1480 global $manager, $itemid;
\r
1481 $item =& $manager->getItem($itemid,0,0);
\r
1483 switch ( $format )
\r
1486 echo Entity::hen($item['title']);
\r
1489 echo $item['title'];
\r
1493 echo Entity::hsc(strip_tags($item['title']));
\r
1500 * Actions::parse_loginform()
\r
1501 * Parse skinvar loginform
\r
1506 public function parse_loginform()
\r
1508 global $member, $CONF;
\r
1509 if ( !$member->isLoggedIn() )
\r
1511 $filename = 'loginform-notloggedin';
\r
1512 $this->formdata = array();
\r
1516 $filename = 'loginform-loggedin';
\r
1517 $this->formdata = array(
\r
1518 'membername' => $member->getDisplayName(),
\r
1521 $this->doForm($filename);
\r
1526 * Actions::parse_member()
\r
1527 * Parse skinvar member
\r
1528 * (includes a member info thingie)
\r
1530 * @param string $what which memberdata is needed
\r
1533 public function parse_member($what)
\r
1535 global $memberinfo, $member, $CONF;
\r
1537 // 1. only allow the member-details-page specific variables on member pages
\r
1538 if ( $this->skintype == 'member' )
\r
1543 echo Entity::hsc($memberinfo->getDisplayName());
\r
1546 echo Entity::hsc($memberinfo->getRealName());
\r
1549 echo Entity::hsc($memberinfo->getNotes());
\r
1552 echo Entity::hsc($memberinfo->getURL());
\r
1555 echo Entity::hsc($memberinfo->getEmail());
\r
1558 echo Entity::hsc($memberinfo->getID());
\r
1563 // 2. the next bunch of options is available everywhere, as long as the user is logged in
\r
1564 if ( $member->isLoggedIn() )
\r
1569 echo $member->getDisplayName();
\r
1571 case 'yourrealname':
\r
1572 echo $member->getRealName();
\r
1575 echo $member->getNotes();
\r
1578 echo $member->getURL();
\r
1581 echo $member->getEmail();
\r
1584 echo $member->getID();
\r
1586 case 'yourprofileurl':
\r
1587 if ($CONF['URLMode'] == 'pathinfo')
\r
1588 echo Link::create_member_link($member->getID());
\r
1590 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
\r
1598 * Link::parse_membermailform()
\r
1599 * Parse skinvar membermailform
\r
1601 * @param integer $rows the height for textarea
\r
1602 * @param integer $cols the width for textarea
\r
1603 * @param string $desturl URI to redirect
\r
1606 public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
\r
1608 global $member, $CONF, $memberid;
\r
1610 if ( $desturl == '' )
\r
1612 if ( $CONF['URLMode'] == 'pathinfo' )
\r
1614 $desturl = Link::create_member_link($memberid);
\r
1618 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
\r
1622 $message = postVar('message');
\r
1623 $frommail = postVar('frommail');
\r
1625 $this->formdata = array(
\r
1626 'url' => Entity::hsc($desturl),
\r
1627 'actionurl' => Entity::hsc($CONF['ActionURL']),
\r
1628 'memberid' => $memberid,
\r
1631 'message' => Entity::hsc($message),
\r
1632 'frommail' => Entity::hsc($frommail)
\r
1635 if ( $member->isLoggedIn() )
\r
1637 $this->doForm('membermailform-loggedin');
\r
1639 else if ( $CONF['NonmemberMail'] )
\r
1641 $this->doForm('membermailform-notloggedin');
\r
1645 $this->doForm('membermailform-disallowed');
\r
1651 * Actions::parse_nextarchive()
\r
1652 * Parse skinvar nextarchive
\r
1657 public function parse_nextarchive()
\r
1659 global $archivenext;
\r
1660 echo $archivenext;
\r
1665 * Parse skinvar nextitem
\r
1666 * (include itemid of next item)
\r
1671 public function parse_nextitem()
\r
1673 global $itemidnext;
\r
1674 if ( isset($itemidnext) )
\r
1676 echo (int)$itemidnext;
\r
1682 * Actions::parse_nextitemtitle()
\r
1683 * Parse skinvar nextitemtitle
\r
1684 * (include itemtitle of next item)
\r
1686 * @param string $format format of text
\r
1689 public function parse_nextitemtitle($format = '')
\r
1691 global $itemtitlenext;
\r
1693 switch ( $format )
\r
1696 echo Entity::hen($itemtitlenext);
\r
1699 echo $itemtitlenext;
\r
1703 echo Entity::hsc($itemtitlenext);
\r
1710 * Actions::parse_nextlink()
\r
1711 * Parse skinvar nextlink
\r
1713 * @param string $linktext text for content of anchor element
\r
1714 * @param integer $amount the amount of items in a display
\r
1715 * @param integer $recount increment from this value
\r
1718 public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
\r
1720 global $itemidnext, $archivenext, $startpos;
\r
1721 if ( $this->skintype == 'item' )
\r
1723 $this->itemlink($itemidnext, $linktext);
\r
1725 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
1727 $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
\r
1731 $this->archivelink($archivenext, $linktext);
\r
1737 * Actions::parse_nucleusbutton()
\r
1738 * Parse skinvar nucleusbutton
\r
1740 * @param string $imgurl URL for image
\r
1741 * @param integer $imgwidth width of image
\r
1742 * @param integer $imgheidht height of image
\r
1744 public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
\r
1747 if ( $imgurl == '' )
\r
1749 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
\r
1751 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
\r
1753 // when skindit IncludeMode is used: start from skindir
\r
1754 $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
\r
1757 $this->formdata = array(
\r
1758 'imgurl' => $imgurl,
\r
1759 'imgwidth' => $imgwidth,
\r
1760 'imgheight' => $imgheight,
\r
1762 $this->doForm('nucleusbutton');
\r
1767 * Actions::parse_otherarchive()
\r
1768 * Parse skinvar otherarchive
\r
1770 * @param string $blogname name of weblog
\r
1771 * @param string $template name of template
\r
1772 * @param string $category name of category
\r
1775 public function parse_otherarchive($blogname, $template, $category = '')
\r
1777 global $archive, $manager;
\r
1778 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
1779 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1780 $this->setBlogCategory($b, $category);
\r
1781 $this->preBlogContent('otherachive',$b);
\r
1782 $b->showArchive($template, $y, $m, $d);
\r
1783 $this->postBlogContent('otherachive',$b);
\r
1788 * Actions::parse_otherarchivedaylist()
\r
1789 * Parse skinvar otherarchivedaylist
\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_otherarchivedaylist($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, 'day', $limit);
\r
1808 $this->postBlogContent('otherarchivelist',$b);
\r
1813 * Actions::parse_otherarchivelist()
\r
1814 * Parse skinvar otherarchivelist
\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 * @param integer $limit the amount of items in a display
\r
1822 public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
\r
1825 if ( $category == 'all' )
\r
1829 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1830 $this->setBlogCategory($b, $category);
\r
1831 $this->preBlogContent('otherarchivelist',$b);
\r
1832 $b->showArchiveList($template, 'month', $limit);
\r
1833 $this->postBlogContent('otherarchivelist',$b);
\r
1838 * Actions::parse_otherarchiveyearlist()
\r
1839 * Parse skinvar otherarchiveyearlist
\r
1841 * @param string $blogname name of weblog
\r
1842 * @param string $template name of template
\r
1843 * @param string $category name of category
\r
1844 * @limit integer $limit the amount of items in a display
\r
1846 public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
\r
1849 if ( $category == 'all' )
\r
1853 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1854 $this->setBlogCategory($b, $category);
\r
1855 $this->preBlogContent('otherarchivelist',$b);
\r
1856 $b->showArchiveList($template, 'year', $limit);
\r
1857 $this->postBlogContent('otherarchivelist',$b);
\r
1862 * Actions::parse_otherblog()
\r
1863 * Parse skinvar otherblog
\r
1865 * @param string $blogname name of weblog
\r
1866 * @param string $template name of template
\r
1867 * @param mixed $amount the amount of items, in case it includes the beginning
\r
1868 * @param string $category name of category
\r
1871 public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
\r
1875 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1877 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1878 $this->setBlogCategory($b, $category);
\r
1879 $this->preBlogContent('otherblog',$b);
\r
1880 $this->amountfound = $b->readLog($template, $limit, $offset);
\r
1881 $this->postBlogContent('otherblog',$b);
\r
1886 * Actions::parse_othersearchresults()
\r
1887 * Parse skinvar othersearchresults
\r
1889 * @param string $blogname name of weblog
\r
1890 * @param string $template name of template
\r
1891 * @param integer $maxresults the amount of results
\r
1894 public function parse_othersearchresults($blogname, $template, $maxresults = 50)
\r
1896 global $query, $amount, $manager, $startpos;
\r
1897 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1898 // need this to select default category
\r
1899 $this->setBlogCategory($b, '');
\r
1900 $this->preBlogContent('othersearchresults',$b);
\r
1901 $b->search($query, $template, $amount, $maxresults, $startpos);
\r
1902 $this->postBlogContent('othersearchresults',$b);
\r
1907 * Actions::parse_plugin()
\r
1908 * Executes a plugin skinvar
\r
1909 * extra parameters can be added
\r
1911 * @param string $pluginName name of plugin (without the NP_)
\r
1914 public function parse_plugin($pluginName)
\r
1918 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
1925 $params = func_get_args();
\r
1927 // remove plugin name
\r
1928 array_shift($params);
\r
1930 // add skin type on front
\r
1931 array_unshift($params, $this->skintype);
\r
1933 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
\r
1938 * Actions::parse_prevarchive()
\r
1939 * Parse skinvar prevarchive
\r
1944 public function parse_prevarchive()
\r
1946 global $archiveprev;
\r
1947 echo $archiveprev;
\r
1951 * Actions::parse_preview()
\r
1952 * Parse skinvar preview
\r
1954 * @param string $template name of tempalte
\r
1957 public function parse_preview($template)
\r
1959 global $blog, $CONF, $manager;
\r
1961 $template =& $manager->getTemplate($template);
\r
1963 $row['body'] = '<span id="prevbody"></span>';
\r
1964 $row['title'] = '<span id="prevtitle"></span>';
\r
1965 $row['more'] = '<span id="prevmore"></span>';
\r
1966 $row['itemlink'] = '';
\r
1967 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
\r
1969 echo Template::fill($template['ITEM_HEADER'],$row);
\r
1970 echo Template::fill($template['ITEM'],$row);
\r
1971 echo Template::fill($template['ITEM_FOOTER'],$row);
\r
1976 * Actions::parse_previtem()
\r
1977 * Parse skinvar previtem
\r
1978 * (include itemid of prev item)
\r
1983 public function parse_previtem()
\r
1985 global $itemidprev;
\r
1986 if ( isset($itemidprev) )
\r
1988 echo (integer) $itemidprev;
\r
1994 * Actions::parse_previtemtitle()
\r
1995 * Parse skinvar previtemtitle
\r
1996 * (include itemtitle of prev item)
\r
1998 * @param String $format string format
\r
1999 * @return String formatted string
\r
2001 public function parse_previtemtitle($format = '')
\r
2003 global $itemtitleprev;
\r
2005 switch ( $format )
\r
2008 echo Entity::hen($itemtitleprev);
\r
2011 echo $itemtitleprev;
\r
2015 echo Entity::hsc($itemtitleprev);
\r
2022 * Actions::parse_prevlink()
\r
2023 * Parse skinvar prevlink
\r
2025 * @param string $linktext text as a content of anchor element
\r
2026 * @param integer the amount of links
\r
2029 public function parse_prevlink($linktext = '', $amount = 10)
\r
2031 global $itemidprev, $archiveprev, $startpos;
\r
2033 if ( $this->skintype == 'item' )
\r
2035 $this->itemlink($itemidprev, $linktext);
\r
2037 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
2039 $this->searchlink($amount, $startpos, 'prev', $linktext);
\r
2043 $this->archivelink($archiveprev, $linktext);
\r
2049 * Actions::parse_query()
\r
2050 * Parse skinvar query
\r
2051 * (includes the search query)
\r
2056 public function parse_query()
\r
2059 echo Entity::hsc($query);
\r
2064 * Actions::parse_referer()
\r
2065 * Parse skinvar referer
\r
2070 public function parse_referer()
\r
2072 echo Entity::hsc(serverVar('HTTP_REFERER'));
\r
2077 * Actions::parse_searchform()
\r
2078 * Parse skinvar searchform
\r
2080 * @param string $blogname name of weblog
\r
2083 public function parse_searchform($blogname = '')
\r
2085 global $CONF, $manager, $maxresults;
\r
2088 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
\r
2094 // use default blog when no blog is selected
\r
2095 $this->formdata = array(
\r
2096 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
\r
2097 'query' => Entity::hsc(getVar('query')),
\r
2099 $this->doForm('searchform');
\r
2104 * Actions::parse_searchresults()
\r
2105 * Parse skinvar searchresults
\r
2107 * @param string $template name of tempalte
\r
2108 * @param integer $maxresults searched items in a display
\r
2111 public function parse_searchresults($template, $maxresults = 50 )
\r
2113 global $blog, $query, $amount, $startpos;
\r
2115 $this->setBlogCategory($blog, ''); // need this to select default category
\r
2116 $this->preBlogContent('searchresults',$blog);
\r
2117 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
\r
2118 $this->postBlogContent('searchresults',$blog);
\r
2123 * Actions::parse_self()
\r
2124 * Parse skinvar self
\r
2129 public function parse_self()
\r
2132 echo $CONF['Self'];
\r
2137 * Actions::parse_sitevar()
\r
2138 * Parse skinvar sitevar
\r
2139 * (include a sitevar)
\r
2141 * @param string $which
\r
2144 public function parse_sitevar($which)
\r
2150 echo $CONF['IndexURL'];
\r
2153 echo $CONF['SiteName'];
\r
2156 echo $CONF['AdminEmail'];
\r
2159 echo $CONF['AdminURL'];
\r
2165 * Actions::parse_skinname()
\r
2171 public function parse_skinname()
\r
2173 echo $this->skin->getName();
\r
2178 * Actions::parse_skintype()
\r
2179 * Parse skintype (experimental)
\r
2184 public function parse_skintype()
\r
2186 echo $this->skintype;
\r
2191 * Actions::parse_text()
\r
2197 public function parse_text($which)
\r
2199 // constant($which) only available from 4.0.4 :(
\r
2200 if ( defined($which) )
\r
2202 eval("echo $which;");
\r
2208 * Actions::parse_ticket()
\r
2214 public function parse_ticket()
\r
2217 $manager->addTicketHidden();
\r
2222 * Actions::parse_todaylink()
\r
2223 * Parse skinvar todaylink
\r
2224 * A link to the today page (depending on selected blog, etc...)
\r
2226 * @param string $linktext text for link
\r
2229 public function parse_todaylink($linktext = '')
\r
2231 global $blog, $CONF;
\r
2234 echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
\r
2238 echo $this->link($CONF['SiteUrl'], $linktext);
\r
2245 * When commentform is not used, to include a hidden field with itemid
\r
2250 public function parse_vars()
\r
2253 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
\r
2258 * Actions::parse_version()
\r
2259 * Parse skinvar version
\r
2260 * (include nucleus versionnumber)
\r
2265 public function parse_version()
\r
2268 echo 'Nucleus CMS ' . $nucleus['version'];
\r
2273 * Actions::parse_sticky()
\r
2274 * Parse skinvar sticky
\r
2276 * @param integer $itemnumber id of item
\r
2277 * @param string $template name of template
\r
2280 public function parse_sticky($itemnumber = 0, $template = '')
\r
2284 $itemnumber = intval($itemnumber);
\r
2285 $itemarray = array($itemnumber);
\r
2287 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
\r
2288 $this->preBlogContent('sticky',$b);
\r
2289 $this->amountfound = $b->readLogFromList($itemarray, $template);
\r
2290 $this->postBlogContent('sticky',$b);
\r