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 $
\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
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(
\r
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);
\r
229 return array_merge($defined_actions, parent::getDefinedActions());
\r
233 * Actions::getDefaultSkinTypes()
\r
237 * @return array list of friendly names for page actions
\r
239 static public function getDefaultSkinTypes()
\r
241 return self::$default_skin_types;
\r
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();
\r
257 $this->skintype = $type;
\r
261 $this->linkparams = array('catid' => $catid);
\r
267 * Actions::setSkin()
\r
269 * @param object $skin an instance of Skin class
\r
272 public function setSkin(&$skin)
\r
274 $this->skin =& $skin;
\r
279 * Actions::doForm()
\r
280 * Forms get parsedincluded now, using an extra <formdata> skinvar
\r
282 * @param string $filename
\r
285 public function doForm($filename)
\r
287 global $DIR_NUCLEUS;
\r
288 array_push($this->parser->actions,'formdata', 'callback','errordiv','ticket');
\r
290 $oldIncludeMode = Parser::getProperty('IncludeMode');
\r
291 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
\r
292 Parser::setProperty('IncludeMode','normal');
\r
293 Parser::setProperty('IncludePrefix','');
\r
295 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
\r
296 Parser::setProperty('IncludeMode',$oldIncludeMode);
\r
297 Parser::setProperty('IncludePrefix',$oldIncludePrefix);
\r
299 array_pop($this->parser->actions); // errordiv
\r
300 array_pop($this->parser->actions); // callback
\r
301 array_pop($this->parser->actions); // formdata
\r
302 array_pop($this->parser->actions); // ticket
\r
307 * Actions::checkCondition()
\r
308 * Checks conditions for if statements
\r
310 * @param string $field type of <%if%>
\r
311 * @param string $name property of field
\r
312 * @param string $value value of property
\r
313 * @return boolean condition
\r
315 protected function checkCondition($field, $name='', $value = '')
\r
317 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
323 $condition = ($blog && $this->ifCategory($name,$value));
\r
325 case 'blogsetting':
\r
326 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
329 $condition = $member->isLoggedIn();
\r
332 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
\r
335 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
\r
338 $condition = ($itemidnext != '');
\r
341 $condition = ($itemidprev != '');
\r
343 case 'archiveprevexists':
\r
344 $condition = ($archiveprevexists == true);
\r
346 case 'archivenextexists':
\r
347 $condition = ($archivenextexists == true);
\r
350 $condition = (($name == $this->skintype) || ($name == requestVar('action')));
\r
353 $condition = $this->ifHasPlugin($name, $value);
\r
356 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);
\r
363 * Actions::_ifHasPlugin()
\r
364 * hasplugin,PlugName
\r
365 * -> checks if plugin exists
\r
366 * hasplugin,PlugName,OptionName
\r
367 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
368 * hasplugin,PlugName,OptionName=value
\r
369 * -> checks if the option OptionName from plugin PlugName is set to value
\r
371 * @param string $name name of plugin
\r
372 * @param string $value
\r
375 private function ifHasPlugin($name, $value)
\r
378 $condition = false;
\r
379 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
380 if ( $manager->pluginInstalled("NP_{$name}") )
\r
382 $plugin =& $manager->getPlugin("NP_{$name}");
\r
383 if ( $plugin != NULL )
\r
385 if ( $value == "" )
\r
391 list($name2, $value2) = preg_split('#=#', $value, 2);
\r
392 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
\r
396 else if ( $plugin->getOption($name2) == $value2 )
\r
407 * Actions::ifPlugin()
\r
408 * Checks if a plugin exists and call its doIf function
\r
410 * @param string $name name of plugin
\r
411 * @param string $key name of plugin option
\r
412 * @param string $value value of plugin option
\r
415 private function ifPlugin($name, $key = '', $value = '')
\r
419 $plugin =& $manager->getPlugin("NP_{$name}");
\r
425 $params = func_get_args();
\r
426 array_shift($params);
\r
428 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r
432 * Actions::ifCategory()
\r
433 * Different checks for a category
\r
435 * @param string $name
\r
436 * @param string $value
\r
439 private function ifCategory($name = '', $value='')
\r
441 global $blog, $catid;
\r
443 // when no parameter is defined, just check if a category is selected
\r
444 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )
\r
446 return $blog->isValidCategory($catid);
\r
449 // check category name
\r
450 if ( $name == 'catname' )
\r
452 $value = $blog->getCategoryIdFromName($value);
\r
453 if ( $value == $catid )
\r
455 return $blog->isValidCategory($catid);
\r
459 // check category id
\r
460 if ( ($name == 'catid') && ($value == $catid) )
\r
462 return $blog->isValidCategory($catid);
\r
468 * Actions::ifOnTeam()
\r
469 * Checks if a member is on the team of a blog and return his rights
\r
471 * @param string $blogName name of weblog
\r
474 private function ifOnTeam($blogName = '')
\r
476 global $blog, $member, $manager;
\r
478 // when no blog found
\r
479 if ( ($blogName == '') && !is_object($blog) )
\r
484 // explicit blog selection
\r
485 if ( $blogName != '' )
\r
487 $blogid = getBlogIDFromName($blogName);
\r
490 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
492 // use current blog
\r
493 $blogid = $blog->getID();
\r
496 return $member->teamRights($blogid);
\r
500 * Actions::ifAdmin()
\r
501 * Checks if a member is admin of a blog
\r
503 * @param string $blogName name of weblog
\r
506 private function ifAdmin($blogName = '')
\r
508 global $blog, $member, $manager;
\r
510 // when no blog found
\r
511 if ( ($blogName == '') && (!is_object($blog)) )
\r
516 // explicit blog selection
\r
517 if ( $blogName != '' )
\r
519 $blogid = getBlogIDFromName($blogName);
\r
522 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
524 // use current blog
\r
525 $blogid = $blog->getID();
\r
528 return $member->isBlogAdmin($blogid);
\r
534 * - a raw link (html/xml encoded) when no linktext is provided
\r
535 * - a (x)html <a href... link when a text is present (text htmlencoded)
\r
537 * @param string $url URL for href attribute of anchor element
\r
538 * @param string $linktext content of anchor element
\r
541 private function link($url, $linktext = '')
\r
543 $u = Entity::hsc($url);
\r
544 // fix URLs that already had encoded ampersands
\r
545 $u = preg_replace("#&amp;#", '&', $u);
\r
546 if ( $linktext != '' )
\r
548 $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';
\r
558 * Actions::searchlink()
\r
559 * Outputs a next/prev link
\r
561 * @param $maxresults
\r
562 * The maximum amount of items shown per page (e.g. 10)
\r
564 * Current start position (requestVar('startpos'))
\r
565 * @param $direction
\r
566 * either 'prev' or 'next'
\r
568 * When present, the output will be a full <a href...> link. When empty,
\r
569 * only a raw link will be outputted
\r
571 private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')
\r
573 global $CONF, $blog, $query, $amount;
\r
574 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
\r
575 $startpos = (integer) $startpos;
\r
576 $parsed = parse_url(serverVar('REQUEST_URI'));
\r
577 $path = $parsed['path'];
\r
578 $parsed = $parsed['query'];
\r
581 if ( $direction == 'prev' )
\r
583 if ( intval($startpos) - intval($maxresults) >= 0 )
\r
585 $startpos = intval($startpos) - intval($maxresults);
\r
587 if ( $this->skintype == 'index' )
\r
591 else if ( $this->skintype == 'search' )
\r
593 $url = $CONF['SearchURL'];
\r
595 $url .= '?' . alterQueryStr($parsed,'startpos',$startpos);
\r
598 else if ( $direction == 'next' )
\r
600 global $navigationItems;
\r
601 if ( !isset($navigationItems) )
\r
603 $navigationItems = 0;
\r
608 $iAmountOnPage = 0;
\r
612 $iAmountOnPage = $this->amountfound;
\r
615 if ( intval($navigationItems) > 0 )
\r
617 $iAmountOnPage = intval($navigationItems) - intval($startpos);
\r
619 elseif ( $iAmountOnPage == 0 )
\r
622 * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
\r
623 * try a count query
\r
625 if ( $this->skintype == 'index' )
\r
627 $sqlquery = $blog->getSqlBlog('', 'count');
\r
630 else if ( $this->skintype == 'search' )
\r
632 $unused_highlight = '';
\r
633 $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
\r
634 $url = $CONF['SearchURL'];
\r
638 $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
\r
643 if ( intval($iAmountOnPage) >= intval($maxresults) )
\r
645 $startpos = intval($startpos) + intval($maxresults);
\r
646 $url .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
\r
652 echo $this->link($url, $linktext);
\r
658 * Actions::itemlink()
\r
659 * Creates an item link and if no id is given a todaylink
\r
661 * @param integer $id id for link
\r
662 * @param string $linktext text for link
\r
665 private function itemlink($id, $linktext = '')
\r
670 echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);
\r
674 $this->parse_todaylink($linktext);
\r
680 * Actions::archivelink)
\r
681 * Creates an archive 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 archivelink($id, $linktext = '')
\r
689 global $CONF, $blog;
\r
692 echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
\r
696 $this->parse_todaylink($linktext);
\r
702 * Actions:setBlogCategory()
\r
703 * Helper function that sets the category that a blog will need to use
\r
705 * @param string $blog An object of the blog class, passed by reference (we want to make changes to it)
\r
706 * @param string $catname The name of the category to use
\r
709 private function setBlogCategory(&$blog, $catname)
\r
712 if ( $catname != '' )
\r
714 $blog->setSelectedCategoryByName($catname);
\r
718 $blog->setSelectedCategory($catid);
\r
724 * Actions::preBlogContent()
\r
725 * Notifies the Manager that a PreBlogContent event occurs
\r
727 * @param string $type type of skin
\r
728 * @param object $blog an instance of Blog class
\r
731 private function preBlogContent($type, &$blog)
\r
734 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
\r
739 * Actions::postBlogContent()
\r
740 * Notifies the Manager that a PostBlogContent event occurs
\r
742 * @param string $type type of skin
\r
743 * @param objecct $blog an instance of Blog class
\r
746 private function postBlogContent($type, &$blog)
\r
749 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
\r
754 * Actions::parse_additemform()
\r
755 * Parse skinvar additemform
\r
760 public function parse_additemform()
\r
762 global $blog, $CONF;
\r
763 $this->formdata = array(
\r
764 'adminurl' => Entity::hsc($CONF['AdminURL']),
\r
765 'catid' => $blog->getDefaultCategory()
\r
767 $blog->InsertJavaScriptInfo();
\r
768 $this->doForm('additemform');
\r
773 * Actions::parse_addlink()
\r
774 * Parse skinvar addlink
\r
775 * A Link that allows to open a bookmarklet to add an item
\r
777 public function parse_addlink()
\r
779 global $CONF, $member, $blog;
\r
780 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
\r
782 echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
\r
788 * Actions::parse_addpopupcode()
\r
789 * Parse skinvar addpopupcode
\r
790 * Code that opens a bookmarklet in an popup window
\r
795 public function parse_addpopupcode()
\r
797 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
802 * Parse skinvar adminurl
\r
803 * (shortcut for admin url)
\r
808 public function parse_adminurl()
\r
810 $this->parse_sitevar('adminurl');
\r
815 * Actions::parse_archive()
\r
816 * Parse skinvar archive
\r
818 * @param string $template name of template
\r
819 * @param string $category name of category
\r
822 public function parse_archive($template, $category = '')
\r
824 global $blog, $archive;
\r
825 // can be used with either yyyy-mm or yyyy-mm-dd
\r
826 sscanf($archive,'%d-%d-%d', $y, $m, $d);
\r
827 $this->setBlogCategory($blog, $category);
\r
828 $this->preBlogContent('achive',$blog);
\r
829 $blog->showArchive($template, $y, $m, $d);
\r
830 $this->postBlogContent('achive',$blog);
\r
835 * Actions::parse_archivedate()
\r
836 * %archivedate(locale,date format)%
\r
838 * @param string $locale
\r
841 public function parse_archivedate($locale = '-def-')
\r
846 * TODO: these lines are no meaning because there is no $template.
\r
847 if ( $locale == '-def-' )
\r
849 setlocale(LC_TIME, $template['LOCALE']);
\r
853 setlocale(LC_TIME, $locale);
\r
857 // get archive date
\r
858 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
861 $args = func_get_args();
\r
862 // format can be spread over multiple parameters
\r
863 if ( sizeof($args) > 1 )
\r
865 // take away locale
\r
866 array_shift($args);
\r
868 $format=implode(',',$args);
\r
870 elseif ( $d == 0 && $m !=0 )
\r
880 $format = '%d %B %Y';
\r
882 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
\r
887 * Actions::parse_archivedaylist()
\r
888 * Parse skinvar archivedaylist
\r
890 * @param string $template name of template
\r
891 * @param string $category name of category
\r
892 * @param integer $limit the number of items in a display
\r
895 public function parse_archivedaylist($template, $category = 'all', $limit = 0)
\r
898 if ( $category == 'all' )
\r
902 $this->preBlogContent('archivelist',$blog);
\r
903 $this->setBlogCategory($blog, $category);
\r
904 $blog->showArchiveList($template, 'day', $limit);
\r
905 $this->postBlogContent('archivelist',$blog);
\r
910 * Actions::parse_archivelink()
\r
911 * A link to the archives for the current blog (or for default blog)
\r
913 * @param string $linktext text for link
\r
916 public function parse_archivelink($linktext = '')
\r
918 global $blog, $CONF;
\r
921 echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
\r
925 echo $this->link(Link::create_archivelist_link(), $linktext);
\r
931 * Actions::parse_archivelist()
\r
933 * @param string $template name of template
\r
934 * @param string $category name of category
\r
935 * @param integer $limit the number of items in a display
\r
938 public function parse_archivelist($template, $category = 'all', $limit = 0)
\r
941 if ( $category == 'all' )
\r
945 $this->preBlogContent('archivelist',$blog);
\r
946 $this->setBlogCategory($blog, $category);
\r
947 $blog->showArchiveList($template, 'month', $limit);
\r
948 $this->postBlogContent('archivelist',$blog);
\r
953 * Actions::parse_archiveyearlist()
\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
959 public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
\r
962 if ( $category == 'all' )
\r
966 $this->preBlogContent('archivelist',$blog);
\r
967 $this->setBlogCategory($blog, $category);
\r
968 $blog->showArchiveList($template, 'year', $limit);
\r
969 $this->postBlogContent('archivelist',$blog);
\r
974 * Actions::parse_archivetype()
\r
975 * Parse skinvar archivetype
\r
980 public function parse_archivetype()
\r
982 global $archivetype;
\r
988 * Actions::parse_blog()
\r
989 * Parse skinvar blog
\r
991 * @param string $template name of template
\r
992 * @param mixed $amount the number of items in a display, in case it includes the beginning
\r
993 * @param string $category name of category
\r
996 public function parse_blog($template, $amount = 10, $category = '')
\r
998 global $blog, $startpos;
\r
1000 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1001 $this->setBlogCategory($blog, $category);
\r
1002 $this->preBlogContent('blog',$blog);
\r
1003 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
\r
1004 $this->postBlogContent('blog',$blog);
\r
1009 * Actions::parse_bloglist()
\r
1010 * Parse skinvar bloglist
\r
1011 * Shows a list of all blogs
\r
1013 * @param string $template name of template
\r
1014 * @param string $bnametype whether 'name' or 'shortname' is used for the link text
\r
1015 * @param string $orderby order criteria
\r
1016 * @param string $direction order ascending or descending
\r
1019 public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
\r
1021 Blog::showBlogList($template, $bnametype, $orderby, $direction);
\r
1026 * Actions::parse_blogsetting()
\r
1027 * Parse skinvar blogsetting
\r
1029 * @param string $which key of weblog settings
\r
1032 public function parse_blogsetting($which)
\r
1038 echo Entity::hsc($blog->getID());
\r
1041 echo Entity::hsc($blog->getURL());
\r
1044 echo Entity::hsc($blog->getName());
\r
1047 echo Entity::hsc($blog->getDescription());
\r
1050 echo Entity::hsc($blog->getShortName());
\r
1057 * Actions::parse_callback()
\r
1060 * @param string $eventName name of event
\r
1061 * @param string $type type of skin
\r
1064 public function parse_callback($eventName, $type)
\r
1067 $manager->notify($eventName, array('type' => $type));
\r
1072 * Actions::parse_category()
\r
1073 * Parse skinvar category
\r
1075 * @param string $type key of category settings
\r
1078 public function parse_category($type = 'name')
\r
1080 global $catid, $blog;
\r
1081 if ( !$blog->isValidCategory($catid) )
\r
1089 echo $blog->getCategoryName($catid);
\r
1092 echo $blog->getCategoryDesc($catid);
\r
1102 * Actions::parse_categorylist()
\r
1103 * Parse categorylist
\r
1105 * @param string $template name of template
\r
1106 * @param string $blogname name of weblog
\r
1109 public function parse_categorylist($template, $blogname = '')
\r
1111 global $blog, $manager;
\r
1113 // when no blog found
\r
1114 if ( ($blogname == '') && (!is_object($blog)) )
\r
1119 if ( $blogname == '' )
\r
1121 $this->preBlogContent('categorylist',$blog);
\r
1122 $blog->showCategoryList($template);
\r
1123 $this->postBlogContent('categorylist',$blog);
\r
1127 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1128 $this->preBlogContent('categorylist',$b);
\r
1129 $b->showCategoryList($template);
\r
1130 $this->postBlogContent('categorylist',$b);
\r
1136 * Actions::parse_charset()
\r
1137 * Parse skinvar charset
\r
1142 public function parse_charset()
\r
1144 echo i18n::get_current_charset();
\r
1149 * Actions::parse_commentform()
\r
1150 * Parse skinvar commentform
\r
1152 * @param string $destinationurl URI for redirection
\r
1155 public function parse_commentform($destinationurl = '')
\r
1157 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
\r
1159 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
\r
1160 if ( stristr($destinationurl, 'action.php') )
\r
1162 $args = func_get_args();
\r
1163 $destinationurl = $args[1];
\r
1164 ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
\r
1167 $actionurl = $CONF['ActionURL'];
\r
1169 // if item is closed, show message and do nothing
\r
1170 $item =& $manager->getItem($itemid,0,0);
\r
1171 if ( $item['closed'] || !$blog->commentsEnabled() )
\r
1173 $this->doForm('commentform-closed');
\r
1177 if ( !$blog->isPublic() && !$member->isLoggedIn() )
\r
1179 $this->doForm('commentform-closedtopublic');
\r
1183 if ( !$destinationurl )
\r
1185 // note: createLink returns an HTML encoded URL
\r
1186 $destinationurl = Link::create_link(
\r
1189 'itemid' => $itemid,
\r
1190 'title' => $item['title'],
\r
1191 'timestamp' => $item['timestamp'],
\r
1192 'extra' => $this->linkparams
\r
1198 // HTML encode URL
\r
1199 $destinationurl = Entity::hsc($destinationurl);
\r
1202 // values to prefill
\r
1203 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
\r
1206 $user = postVar('user');
\r
1209 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
\r
1212 $userid = postVar('userid');
\r
1215 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
\r
1218 $email = postVar('email');
\r
1221 $body = postVar('body');
\r
1223 $this->formdata = array(
\r
1224 'destinationurl' => $destinationurl, // url is already HTML encoded
\r
1225 'actionurl' => Entity::hsc($actionurl),
\r
1226 'itemid' => $itemid,
\r
1227 'user' => Entity::hsc($user),
\r
1228 'userid' => Entity::hsc($userid),
\r
1229 'email' => Entity::hsc($email),
\r
1230 'body' => Entity::hsc($body),
\r
1231 'membername' => $member->getDisplayName(),
\r
1232 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
\r
1235 if ( !$member->isLoggedIn() )
\r
1237 $this->doForm('commentform-notloggedin');
\r
1241 $this->doForm('commentform-loggedin');
\r
1247 * Actions::parse_comments()
\r
1248 * Parse skinvar comments
\r
1249 * include comments for one item
\r
1251 * @param string $template name of template
\r
1254 public function parse_comments($template)
\r
1256 global $itemid, $manager, $blog, $highlight;
\r
1257 $template =& $manager->getTemplate($template);
\r
1259 // create parser object & action handler
\r
1260 $handler = new ItemActions($blog);
\r
1261 $parser = new Parser($handler->getDefinedActions(),$handler);
\r
1262 $handler->setTemplate($template);
\r
1263 $handler->setParser($parser);
\r
1264 $item = Item::getitem($itemid, 0, 0);
\r
1265 $handler->setCurrentItem($item);
\r
1267 $comments = new Comments($itemid);
\r
1268 $comments->setItemActions($handler);
\r
1269 // shows ALL comments
\r
1270 $comments->showComments($template, -1, 1, $highlight);
\r
1275 * Actions::parse_errordiv()
\r
1281 public function parse_errordiv()
\r
1283 global $errormessage;
\r
1284 if ( $errormessage )
\r
1286 echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
\r
1292 * Actions::parse_errormessage()
\r
1293 * Parse skinvar errormessage
\r
1298 public function parse_errormessage()
\r
1300 global $errormessage;
\r
1301 echo $errormessage;
\r
1306 * Actions::parse_formdata()
\r
1309 * @param string $what key of format data
\r
1312 public function parse_formdata($what)
\r
1314 echo $this->formdata[$what];
\r
1319 * Actions::parse_ifcat()
\r
1322 * @param string $text
\r
1325 public function parse_ifcat($text = '')
\r
1327 if ( $text == '' )
\r
1330 $this->parse_if('category');
\r
1335 global $catid, $blog;
\r
1336 if ( $blog->isValidCategory($catid) )
\r
1345 * Actions::parse_image()
\r
1346 * Parse skinvar image
\r
1348 * @param string $what name of tag
\r
1351 public function parse_image($what = 'imgtag')
\r
1355 $imagetext = Entity::hsc(requestVar('imagetext'));
\r
1356 $imagepopup = requestVar('imagepopup');
\r
1357 $width = intRequestVar('width');
\r
1358 $height = intRequestVar('height');
\r
1359 $fullurl = Entity::hsc($CONF['MediaURL'] . $imagepopup);
\r
1378 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
\r
1385 * Actions::parse_imagetext()
\r
1386 * Parse skinvar imagetext
\r
1391 public function parse_imagetext()
\r
1393 $this->parse_image('imagetext');
\r
1398 * Actions::parse_item()
\r
1399 * Parse skinvar item
\r
1400 * include one item (no comments)
\r
1405 public function parse_item($template)
\r
1407 global $blog, $itemid, $highlight;
\r
1409 // need this to select default category
\r
1410 $this->setBlogCategory($blog, '');
\r
1411 $this->preBlogContent('item',$blog);
\r
1412 $r = $blog->showOneitem($itemid, $template, $highlight);
\r
1415 echo _ERROR_NOSUCHITEM;
\r
1417 $this->postBlogContent('item',$blog);
\r
1422 * Actions::parse_itemid()
\r
1423 * Parse skinvar itemid
\r
1428 public function parse_itemid()
\r
1436 * Actions::parseitemlink()
\r
1437 * Parse skinvar itemlink
\r
1442 public function parse_itemlink($linktext = '')
\r
1445 $this->itemlink($itemid, $linktext);
\r
1450 * Actions::parse_itemtitle()
\r
1456 public function parse_itemtitle($format = '')
\r
1458 global $manager, $itemid;
\r
1459 $item =& $manager->getItem($itemid,0,0);
\r
1461 switch ( $format )
\r
1464 echo Entity::hen($item['title']);
\r
1467 echo $item['title'];
\r
1471 echo Entity::hsc(strip_tags($item['title']));
\r
1478 * Actions::parse_loginform()
\r
1479 * Parse skinvar loginform
\r
1484 public function parse_loginform()
\r
1486 global $member, $CONF;
\r
1487 if ( !$member->isLoggedIn() )
\r
1489 $filename = 'loginform-notloggedin';
\r
1490 $this->formdata = array();
\r
1494 $filename = 'loginform-loggedin';
\r
1495 $this->formdata = array(
\r
1496 'membername' => $member->getDisplayName(),
\r
1499 $this->doForm($filename);
\r
1504 * Actions::parse_member()
\r
1505 * Parse skinvar member
\r
1506 * (includes a member info thingie)
\r
1508 * @param string $what which memberdata is needed
\r
1511 public function parse_member($what)
\r
1513 global $memberinfo, $member, $CONF;
\r
1515 // 1. only allow the member-details-page specific variables on member pages
\r
1516 if ( $this->skintype == 'member' )
\r
1521 echo Entity::hsc($memberinfo->getDisplayName());
\r
1524 echo Entity::hsc($memberinfo->getRealName());
\r
1527 echo Entity::hsc($memberinfo->getNotes());
\r
1530 echo Entity::hsc($memberinfo->getURL());
\r
1533 echo Entity::hsc($memberinfo->getEmail());
\r
1536 echo Entity::hsc($memberinfo->getID());
\r
1541 // 2. the next bunch of options is available everywhere, as long as the user is logged in
\r
1542 if ( $member->isLoggedIn() )
\r
1547 echo $member->getDisplayName();
\r
1549 case 'yourrealname':
\r
1550 echo $member->getRealName();
\r
1553 echo $member->getNotes();
\r
1556 echo $member->getURL();
\r
1559 echo $member->getEmail();
\r
1562 echo $member->getID();
\r
1564 case 'yourprofileurl':
\r
1565 if ($CONF['URLMode'] == 'pathinfo')
\r
1566 echo Link::create_member_link($member->getID());
\r
1568 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
\r
1576 * Link::parse_membermailform()
\r
1577 * Parse skinvar membermailform
\r
1579 * @param integer $rows the height for textarea
\r
1580 * @param integer $cols the width for textarea
\r
1581 * @param string $desturl URI to redirect
\r
1584 public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
\r
1586 global $member, $CONF, $memberid;
\r
1588 if ( $desturl == '' )
\r
1590 if ( $CONF['URLMode'] == 'pathinfo' )
\r
1592 $desturl = Link::create_member_link($memberid);
\r
1596 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
\r
1600 $message = postVar('message');
\r
1601 $frommail = postVar('frommail');
\r
1603 $this->formdata = array(
\r
1604 'url' => Entity::hsc($desturl),
\r
1605 'actionurl' => Entity::hsc($CONF['ActionURL']),
\r
1606 'memberid' => $memberid,
\r
1609 'message' => Entity::hsc($message),
\r
1610 'frommail' => Entity::hsc($frommail)
\r
1613 if ( $member->isLoggedIn() )
\r
1615 $this->doForm('membermailform-loggedin');
\r
1617 else if ( $CONF['NonmemberMail'] )
\r
1619 $this->doForm('membermailform-notloggedin');
\r
1623 $this->doForm('membermailform-disallowed');
\r
1629 * Actions::parse_nextarchive()
\r
1630 * Parse skinvar nextarchive
\r
1635 public function parse_nextarchive()
\r
1637 global $archivenext;
\r
1638 echo $archivenext;
\r
1643 * Parse skinvar nextitem
\r
1644 * (include itemid of next item)
\r
1649 public function parse_nextitem()
\r
1651 global $itemidnext;
\r
1652 if ( isset($itemidnext) )
\r
1654 echo (int)$itemidnext;
\r
1660 * Actions::parse_nextitemtitle()
\r
1661 * Parse skinvar nextitemtitle
\r
1662 * (include itemtitle of next item)
\r
1664 * @param string $format format of text
\r
1667 public function parse_nextitemtitle($format = '')
\r
1669 global $itemtitlenext;
\r
1671 switch ( $format )
\r
1674 echo Entity::hen($itemtitlenext);
\r
1677 echo $itemtitlenext;
\r
1681 echo Entity::hsc($itemtitlenext);
\r
1688 * Actions::parse_nextlink()
\r
1689 * Parse skinvar nextlink
\r
1691 * @param string $linktext text for content of anchor element
\r
1692 * @param integer $amount the amount of items in a display
\r
1693 * @param integer $recount increment from this value
\r
1696 public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
\r
1698 global $itemidnext, $archivenext, $startpos;
\r
1699 if ( $this->skintype == 'item' )
\r
1701 $this->itemlink($itemidnext, $linktext);
\r
1703 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
1705 $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
\r
1709 $this->archivelink($archivenext, $linktext);
\r
1715 * Actions::parse_nucleusbutton()
\r
1716 * Parse skinvar nucleusbutton
\r
1718 * @param string $imgurl URL for image
\r
1719 * @param integer $imgwidth width of image
\r
1720 * @param integer $imgheidht height of image
\r
1722 public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
\r
1725 if ( $imgurl == '' )
\r
1727 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
\r
1729 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
\r
1731 // when skindit IncludeMode is used: start from skindir
\r
1732 $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
\r
1735 $this->formdata = array(
\r
1736 'imgurl' => $imgurl,
\r
1737 'imgwidth' => $imgwidth,
\r
1738 'imgheight' => $imgheight,
\r
1740 $this->doForm('nucleusbutton');
\r
1745 * Actions::parse_otherarchive()
\r
1746 * Parse skinvar otherarchive
\r
1748 * @param string $blogname name of weblog
\r
1749 * @param string $template name of template
\r
1750 * @param string $category name of category
\r
1753 public function parse_otherarchive($blogname, $template, $category = '')
\r
1755 global $archive, $manager;
\r
1756 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
1757 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1758 $this->setBlogCategory($b, $category);
\r
1759 $this->preBlogContent('otherachive',$b);
\r
1760 $b->showArchive($template, $y, $m, $d);
\r
1761 $this->postBlogContent('otherachive',$b);
\r
1766 * Actions::parse_otherarchivedaylist()
\r
1767 * Parse skinvar otherarchivedaylist
\r
1769 * @param string $blogname name of weblog
\r
1770 * @param string $template name of template
\r
1771 * @param string $category name of category
\r
1772 * @param integer $limit the amount of items in a display
\r
1775 public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
\r
1778 if ( $category == 'all')
\r
1782 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1783 $this->setBlogCategory($b, $category);
\r
1784 $this->preBlogContent('otherarchivelist',$b);
\r
1785 $b->showArchiveList($template, 'day', $limit);
\r
1786 $this->postBlogContent('otherarchivelist',$b);
\r
1791 * Actions::parse_otherarchivelist()
\r
1792 * Parse skinvar otherarchivelist
\r
1794 * @param string $blogname name of weblog
\r
1795 * @param string $template name of template
\r
1796 * @param string $category name of category
\r
1797 * @param integer $limit the amount of items in a display
\r
1800 public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
\r
1803 if ( $category == 'all' )
\r
1807 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1808 $this->setBlogCategory($b, $category);
\r
1809 $this->preBlogContent('otherarchivelist',$b);
\r
1810 $b->showArchiveList($template, 'month', $limit);
\r
1811 $this->postBlogContent('otherarchivelist',$b);
\r
1816 * Actions::parse_otherarchiveyearlist()
\r
1817 * Parse skinvar otherarchiveyearlist
\r
1819 * @param string $blogname name of weblog
\r
1820 * @param string $template name of template
\r
1821 * @param string $category name of category
\r
1822 * @limit integer $limit the amount of items in a display
\r
1824 public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
\r
1827 if ( $category == 'all' )
\r
1831 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1832 $this->setBlogCategory($b, $category);
\r
1833 $this->preBlogContent('otherarchivelist',$b);
\r
1834 $b->showArchiveList($template, 'year', $limit);
\r
1835 $this->postBlogContent('otherarchivelist',$b);
\r
1840 * Actions::parse_otherblog()
\r
1841 * Parse skinvar otherblog
\r
1843 * @param string $blogname name of weblog
\r
1844 * @param string $template name of template
\r
1845 * @param mixed $amount the amount of items, in case it includes the beginning
\r
1846 * @param string $category name of category
\r
1849 public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
\r
1853 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1855 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1856 $this->setBlogCategory($b, $category);
\r
1857 $this->preBlogContent('otherblog',$b);
\r
1858 $this->amountfound = $b->readLog($template, $limit, $offset);
\r
1859 $this->postBlogContent('otherblog',$b);
\r
1864 * Actions::parse_othersearchresults()
\r
1865 * Parse skinvar othersearchresults
\r
1867 * @param string $blogname name of weblog
\r
1868 * @param string $template name of template
\r
1869 * @param integer $maxresults the amount of results
\r
1872 public function parse_othersearchresults($blogname, $template, $maxresults = 50)
\r
1874 global $query, $amount, $manager, $startpos;
\r
1875 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1876 // need this to select default category
\r
1877 $this->setBlogCategory($b, '');
\r
1878 $this->preBlogContent('othersearchresults',$b);
\r
1879 $b->search($query, $template, $amount, $maxresults, $startpos);
\r
1880 $this->postBlogContent('othersearchresults',$b);
\r
1885 * Actions::parse_plugin()
\r
1886 * Executes a plugin skinvar
\r
1887 * extra parameters can be added
\r
1889 * @param string $pluginName name of plugin (without the NP_)
\r
1892 public function parse_plugin($pluginName)
\r
1896 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
1903 $params = func_get_args();
\r
1905 // remove plugin name
\r
1906 array_shift($params);
\r
1908 // add skin type on front
\r
1909 array_unshift($params, $this->skintype);
\r
1911 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
\r
1916 * Actions::parse_prevarchive()
\r
1917 * Parse skinvar prevarchive
\r
1922 public function parse_prevarchive()
\r
1924 global $archiveprev;
\r
1925 echo $archiveprev;
\r
1929 * Actions::parse_preview()
\r
1930 * Parse skinvar preview
\r
1932 * @param string $template name of tempalte
\r
1935 public function parse_preview($template)
\r
1937 global $blog, $CONF, $manager;
\r
1939 $template =& $manager->getTemplate($template);
\r
1941 $row['body'] = '<span id="prevbody"></span>';
\r
1942 $row['title'] = '<span id="prevtitle"></span>';
\r
1943 $row['more'] = '<span id="prevmore"></span>';
\r
1944 $row['itemlink'] = '';
\r
1945 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
\r
1947 echo Template::fill($template['ITEM_HEADER'],$row);
\r
1948 echo Template::fill($template['ITEM'],$row);
\r
1949 echo Template::fill($template['ITEM_FOOTER'],$row);
\r
1954 * Actions::parse_previtem()
\r
1955 * Parse skinvar previtem
\r
1956 * (include itemid of prev item)
\r
1961 public function parse_previtem()
\r
1963 global $itemidprev;
\r
1964 if ( isset($itemidprev) )
\r
1966 echo (integer) $itemidprev;
\r
1972 * Actions::parse_previtemtitle()
\r
1973 * Parse skinvar previtemtitle
\r
1974 * (include itemtitle of prev item)
\r
1976 * @param String $format string format
\r
1977 * @return String formatted string
\r
1979 public function parse_previtemtitle($format = '')
\r
1981 global $itemtitleprev;
\r
1983 switch ( $format )
\r
1986 echo Entity::hen($itemtitleprev);
\r
1989 echo $itemtitleprev;
\r
1993 echo Entity::hsc($itemtitleprev);
\r
2000 * Actions::parse_prevlink()
\r
2001 * Parse skinvar prevlink
\r
2003 * @param string $linktext text as a content of anchor element
\r
2004 * @param integer the amount of links
\r
2007 public function parse_prevlink($linktext = '', $amount = 10)
\r
2009 global $itemidprev, $archiveprev, $startpos;
\r
2011 if ( $this->skintype == 'item' )
\r
2013 $this->itemlink($itemidprev, $linktext);
\r
2015 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
2017 $this->searchlink($amount, $startpos, 'prev', $linktext);
\r
2021 $this->archivelink($archiveprev, $linktext);
\r
2027 * Actions::parse_query()
\r
2028 * Parse skinvar query
\r
2029 * (includes the search query)
\r
2034 public function parse_query()
\r
2037 echo Entity::hsc($query);
\r
2042 * Actions::parse_referer()
\r
2043 * Parse skinvar referer
\r
2048 public function parse_referer()
\r
2050 echo Entity::hsc(serverVar('HTTP_REFERER'));
\r
2055 * Actions::parse_searchform()
\r
2056 * Parse skinvar searchform
\r
2058 * @param string $blogname name of weblog
\r
2061 public function parse_searchform($blogname = '')
\r
2063 global $CONF, $manager, $maxresults;
\r
2066 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
\r
2072 // use default blog when no blog is selected
\r
2073 $this->formdata = array(
\r
2074 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
\r
2075 'query' => Entity::hsc(getVar('query')),
\r
2077 $this->doForm('searchform');
\r
2082 * Actions::parse_searchresults()
\r
2083 * Parse skinvar searchresults
\r
2085 * @param string $template name of tempalte
\r
2086 * @param integer $maxresults searched items in a display
\r
2089 public function parse_searchresults($template, $maxresults = 50 )
\r
2091 global $blog, $query, $amount, $startpos;
\r
2093 $this->setBlogCategory($blog, ''); // need this to select default category
\r
2094 $this->preBlogContent('searchresults',$blog);
\r
2095 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
\r
2096 $this->postBlogContent('searchresults',$blog);
\r
2101 * Actions::parse_self()
\r
2102 * Parse skinvar self
\r
2107 public function parse_self()
\r
2110 echo $CONF['Self'];
\r
2115 * Actions::parse_sitevar()
\r
2116 * Parse skinvar sitevar
\r
2117 * (include a sitevar)
\r
2119 * @param string $which
\r
2122 public function parse_sitevar($which)
\r
2128 echo $CONF['IndexURL'];
\r
2131 echo $CONF['SiteName'];
\r
2134 echo $CONF['AdminEmail'];
\r
2137 echo $CONF['AdminURL'];
\r
2143 * Actions::parse_skinname()
\r
2149 public function parse_skinname()
\r
2151 echo $this->skin->getName();
\r
2156 * Actions::parse_skintype()
\r
2157 * Parse skintype (experimental)
\r
2162 public function parse_skintype()
\r
2164 echo $this->skintype;
\r
2169 * Actions::parse_ticket()
\r
2175 public function parse_ticket()
\r
2178 $manager->addTicketHidden();
\r
2183 * Actions::parse_todaylink()
\r
2184 * Parse skinvar todaylink
\r
2185 * A link to the today page (depending on selected blog, etc...)
\r
2187 * @param string $linktext text for link
\r
2190 public function parse_todaylink($linktext = '')
\r
2192 global $blog, $CONF;
\r
2195 echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
\r
2199 echo $this->link($CONF['SiteUrl'], $linktext);
\r
2206 * When commentform is not used, to include a hidden field with itemid
\r
2211 public function parse_vars()
\r
2214 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
\r
2219 * Actions::parse_version()
\r
2220 * Parse skinvar version
\r
2221 * (include nucleus versionnumber)
\r
2226 public function parse_version()
\r
2229 echo 'Nucleus CMS ' . $nucleus['version'];
\r
2234 * Actions::parse_sticky()
\r
2235 * Parse skinvar sticky
\r
2237 * @param integer $itemnumber id of item
\r
2238 * @param string $template name of template
\r
2241 public function parse_sticky($itemnumber = 0, $template = '')
\r
2245 $itemnumber = intval($itemnumber);
\r
2246 $itemarray = array($itemnumber);
\r
2248 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
\r
2249 $this->preBlogContent('sticky',$b);
\r
2250 $this->amountfound = $b->readLogFromList($itemarray, $template);
\r
2251 $this->postBlogContent('sticky',$b);
\r