3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2012 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
13 * This class contains the functions that get called by using
\r
14 * the special tags in the skins
\r
16 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
17 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
18 * @version $Id: ACTIONS.php 1863 2012-05-19 10:50:27Z sakamocchi $
21 class Actions extends BaseActions
\r
23 // part of the skin currently being parsed ('index', 'item', 'archive',
\r
24 // 'archivelist', 'member', 'search', 'error', 'imagepopup')
\r
27 // contains an assoc array with parameters that need to be included when
\r
28 // generating links to items/archives/... (e.g. catid)
\r
29 private $linkparams;
\r
31 // used when including templated forms from the include/ dir. The $formdata var
\r
32 // contains the values to fill out in there (assoc array name -> value)
\r
35 // filled out with the number of displayed items after calling one of the
\r
36 // (other)blog/(other)searchresults skinvars.
\r
37 private $amountfound;
\r
40 * Actions::$default_actions
\r
41 * list of whole action names with which this class can deal
\r
43 static private $default_actions = array(
\r
53 'otherarchivedaylist',
\r
55 'otherarchiveyearlist',
\r
66 // deprecated (Nucleus v2.0)
\r
67 /* TODO: remove this */
\r
72 * Actions::$skin_type_friendly_names
\r
73 * friendly name for wrapped page types
\r
75 static public $default_skin_types = array(
\r
76 'index' => _SKIN_PART_MAIN,
\r
77 'item' => _SKIN_PART_ITEM,
\r
78 'archivelist' => _SKIN_PART_ALIST,
\r
79 'archive' => _SKIN_PART_ARCHIVE,
\r
80 'search' => _SKIN_PART_SEARCH,
\r
81 'error' => _SKIN_PART_ERROR,
\r
82 'member' => _SKIN_PART_MEMBER,
\r
83 'imagepopup' => _SKIN_PART_POPUP
\r
87 * Actions::getAvailableSkinTypes()
\r
91 * @return array list of friendly names for page actions
\r
93 static public function getAvailableSkinTypes()
\r
95 return self::$default_skin_types;
\r
99 * Actions::__construct()
\r
100 * Constructor for a new Actions object
\r
102 * @param string $type
\r
105 public function __construct($type)
\r
109 // call constructor of superclass first
\r
110 parent::__construct();
\r
111 $this->skintype = $type;
\r
115 $this->linkparams = array('catid' => $catid);
\r
121 * Actions::getAvailableActions()
\r
124 * @return array allowed actions for the page type
\r
126 public function getAvailableActions()
\r
128 $extra_actions = array();
\r
130 switch ( $this->skintype )
\r
133 $extra_actions = array(
\r
147 $extra_actions = array(
\r
164 case 'archivelist':
\r
165 $extra_actions = array(
\r
175 $extra_actions = array(
\r
182 'othersearchresults',
\r
190 $extra_actions = array(
\r
192 // deprecated (Nucleus v2.0)
\r
193 /* TODO: remove this */
\r
198 $extra_actions = array(
\r
206 $extra_actions = array(
\r
229 $extra_actions = array(
\r
235 $extra_actions = array(
\r
253 $defined_actions = array_merge(self::$default_actions, $extra_actions);
\r
255 return array_merge($defined_actions, parent::getAvailableActions());
\r
259 * Actions::doForm()
\r
260 * Forms get parsedincluded now, using an extra <formdata> skinvar
\r
262 * @param string $filename
\r
265 public function doForm($filename)
\r
267 global $DIR_NUCLEUS;
\r
268 array_push($this->parser->actions,'formdata', 'callback','errordiv','ticket');
\r
270 $oldIncludeMode = Parser::getProperty('IncludeMode');
\r
271 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
\r
272 Parser::setProperty('IncludeMode','normal');
\r
273 Parser::setProperty('IncludePrefix','');
\r
275 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
\r
276 Parser::setProperty('IncludeMode',$oldIncludeMode);
\r
277 Parser::setProperty('IncludePrefix',$oldIncludePrefix);
\r
279 array_pop($this->parser->actions); // errordiv
\r
280 array_pop($this->parser->actions); // callback
\r
281 array_pop($this->parser->actions); // formdata
\r
282 array_pop($this->parser->actions); // ticket
\r
287 * Actions::checkCondition()
\r
288 * Checks conditions for if statements
\r
290 * @param string $field type of <%if%>
\r
291 * @param string $name property of field
\r
292 * @param string $value value of property
\r
293 * @return boolean condition
\r
295 protected function checkCondition($field, $name='', $value = '')
\r
297 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
303 $condition = ($blog && $this->ifCategory($name,$value));
\r
305 case 'blogsetting':
\r
306 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
309 $condition = $member->isLoggedIn();
\r
312 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
\r
315 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
\r
318 $condition = ($itemidnext != '');
\r
321 $condition = ($itemidprev != '');
\r
323 case 'archiveprevexists':
\r
324 $condition = ($archiveprevexists == true);
\r
326 case 'archivenextexists':
\r
327 $condition = ($archivenextexists == true);
\r
330 $condition = (($name == $this->skintype) || ($name == requestVar('action')));
\r
333 $condition = $this->ifHasPlugin($name, $value);
\r
336 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);
\r
343 * Actions::_ifHasPlugin()
\r
344 * hasplugin,PlugName
\r
345 * -> checks if plugin exists
\r
346 * hasplugin,PlugName,OptionName
\r
347 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
348 * hasplugin,PlugName,OptionName=value
\r
349 * -> checks if the option OptionName from plugin PlugName is set to value
\r
351 * @param string $name name of plugin
\r
352 * @param string $value
\r
355 private function ifHasPlugin($name, $value)
\r
358 $condition = false;
\r
359 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
360 if ( $manager->pluginInstalled("NP_{$name}") )
\r
362 $plugin =& $manager->getPlugin("NP_{$name}");
\r
363 if ( $plugin != NULL )
\r
365 if ( $value == "" )
\r
371 list($name2, $value2) = preg_split('#=#', $value, 2);
\r
372 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
\r
376 else if ( $plugin->getOption($name2) == $value2 )
\r
387 * Actions::ifPlugin()
\r
388 * Checks if a plugin exists and call its doIf function
\r
390 * @param string $name name of plugin
\r
391 * @param string $key name of plugin option
\r
392 * @param string $value value of plugin option
\r
395 private function ifPlugin($name, $key = '', $value = '')
\r
399 $plugin =& $manager->getPlugin("NP_{$name}");
\r
405 $params = func_get_args();
\r
406 array_shift($params);
\r
408 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r
412 * Actions::ifCategory()
\r
413 * Different checks for a category
\r
415 * @param string $name
\r
416 * @param string $value
\r
419 private function ifCategory($name = '', $value='')
\r
421 global $blog, $catid;
\r
423 // when no parameter is defined, just check if a category is selected
\r
424 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )
\r
426 return $blog->isValidCategory($catid);
\r
429 // check category name
\r
430 else if ( $name == 'catname' )
432 $value = $blog->getCategoryIdFromName($value);
\r
433 if ( $value == $catid )
\r
435 return $blog->isValidCategory($catid);
\r
439 // check category id
\r
440 else if ( ($name == 'catid') && ($value == $catid) )
442 return $blog->isValidCategory($catid);
\r
448 * Actions::ifOnTeam()
\r
449 * Checks if a member is on the team of a blog and return his rights
\r
451 * @param string $blogName name of weblog
\r
454 private function ifOnTeam($blogName = '')
\r
456 global $blog, $member, $manager;
\r
458 // when no blog found
\r
459 if ( ($blogName == '') && !is_object($blog) )
\r
464 // explicit blog selection
\r
465 if ( $blogName != '' )
\r
467 $blogid = getBlogIDFromName($blogName);
\r
470 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
472 // use current blog
\r
473 $blogid = $blog->getID();
\r
476 return $member->teamRights($blogid);
\r
480 * Actions::ifAdmin()
\r
481 * Checks if a member is admin of a blog
\r
483 * @param string $blogName name of weblog
\r
486 private function ifAdmin($blogName = '')
\r
488 global $blog, $member, $manager;
\r
490 // when no blog found
\r
491 if ( ($blogName == '') && (!is_object($blog)) )
\r
496 // explicit blog selection
\r
497 if ( $blogName != '' )
\r
499 $blogid = getBlogIDFromName($blogName);
\r
502 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
504 // use current blog
\r
505 $blogid = $blog->getID();
\r
508 return $member->isBlogAdmin($blogid);
\r
514 * - a raw link (html/xml encoded) when no linktext is provided
\r
515 * - a (x)html <a href... link when a text is present (text htmlencoded)
\r
517 * @param string $url URL for href attribute of anchor element
\r
518 * @param string $linktext content of anchor element
\r
521 private function link($url, $linktext = '')
\r
523 $u = Entity::hsc($url);
\r
524 // fix URLs that already had encoded ampersands
\r
525 $u = preg_replace("#&amp;#", '&', $u);
\r
526 if ( $linktext != '' )
\r
528 $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';
\r
538 * Actions::searchlink()
\r
539 * Outputs a next/prev link
\r
541 * @param $maxresults
\r
542 * The maximum amount of items shown per page (e.g. 10)
\r
544 * Current start position (requestVar('startpos'))
\r
545 * @param $direction
\r
546 * either 'prev' or 'next'
\r
548 * When present, the output will be a full <a href...> link. When empty,
\r
549 * only a raw link will be outputted
\r
551 private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')
\r
553 global $CONF, $blog, $query, $amount;
\r
554 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
\r
555 $startpos = (integer) $startpos;
\r
556 $parsed = parse_url(serverVar('REQUEST_URI'));
\r
557 $path = ( in_array('path', $parsed) ) ? $parsed['path'] : '';
\r
558 $parsed = ( in_array('query', $parsed) ) ? $parsed['query'] : '';
\r
561 if ( $direction == 'prev' )
\r
563 if ( intval($startpos) - intval($maxresults) >= 0 )
\r
565 $startpos = intval($startpos) - intval($maxresults);
\r
567 if ( $this->skintype == 'index' )
\r
571 else if ( $this->skintype == 'search' )
\r
573 $url = $CONF['SearchURL'];
\r
575 $url .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
\r
578 else if ( $direction == 'next' )
\r
580 global $navigationItems;
\r
581 if ( !isset($navigationItems) )
\r
583 $navigationItems = 0;
\r
588 $iAmountOnPage = 0;
\r
592 $iAmountOnPage = $this->amountfound;
\r
595 if ( intval($navigationItems) > 0 )
\r
597 $iAmountOnPage = intval($navigationItems) - intval($startpos);
\r
599 elseif ( $iAmountOnPage == 0 )
\r
602 * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
\r
603 * try a count query
\r
605 if ( $this->skintype == 'index' )
\r
607 $sqlquery = $blog->getSqlBlog('', 'count');
\r
610 else if ( $this->skintype == 'search' )
\r
612 $unused_highlight = '';
\r
613 $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
\r
614 $url = $CONF['SearchURL'];
\r
618 $iAmountOnPage = intval(DB::getValue($sqlquery)) - intval($startpos);
\r
623 if ( intval($iAmountOnPage) >= intval($maxresults) )
\r
625 $startpos = intval($startpos) + intval($maxresults);
\r
626 $url .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
\r
632 echo $this->link($url, $linktext);
\r
638 * Actions::itemlink()
\r
639 * Creates an item link and if no id is given a todaylink
\r
641 * @param integer $id id for link
\r
642 * @param string $linktext text for link
\r
645 private function itemlink($id, $linktext = '')
\r
650 echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);
\r
654 $this->parse_todaylink($linktext);
\r
660 * Actions::archivelink)
\r
661 * Creates an archive link and if no id is given a todaylink
\r
663 * @param integer $id id for link
\r
664 * @param string $linktext text for link
\r
667 private function archivelink($id, $linktext = '')
\r
669 global $CONF, $blog;
\r
672 echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
\r
676 $this->parse_todaylink($linktext);
\r
682 * Actions:setBlogCategory()
\r
683 * Helper function that sets the category that a blog will need to use
\r
685 * @param string $blog An object of the blog class, passed by reference (we want to make changes to it)
\r
686 * @param string $catname The name of the category to use
\r
689 private function setBlogCategory(&$blog, $catname)
\r
692 if ( $catname != '' )
\r
694 $blog->setSelectedCategoryByName($catname);
\r
698 $blog->setSelectedCategory($catid);
\r
704 * Actions::preBlogContent()
\r
705 * Notifies the Manager that a PreBlogContent event occurs
\r
707 * @param string $type type of skin
\r
708 * @param object $blog an instance of Blog class
\r
711 private function preBlogContent($type, &$blog)
\r
714 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
\r
719 * Actions::postBlogContent()
\r
720 * Notifies the Manager that a PostBlogContent event occurs
\r
722 * @param string $type type of skin
\r
723 * @param objecct $blog an instance of Blog class
\r
726 private function postBlogContent($type, &$blog)
\r
729 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
\r
734 * Actions::parse_additemform()
\r
735 * Parse skinvar additemform
\r
740 public function parse_additemform()
\r
742 global $blog, $CONF;
\r
743 $this->formdata = array(
\r
744 'adminurl' => Entity::hsc($CONF['AdminURL']),
\r
745 'catid' => $blog->getDefaultCategory()
\r
747 $blog->InsertJavaScriptInfo();
\r
748 $this->doForm('additemform');
\r
753 * Actions::parse_addlink()
\r
754 * Parse skinvar addlink
\r
755 * A Link that allows to open a bookmarklet to add an item
\r
757 public function parse_addlink()
\r
759 global $CONF, $member, $blog;
\r
760 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
\r
762 echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
\r
768 * Actions::parse_addpopupcode()
\r
769 * Parse skinvar addpopupcode
\r
770 * Code that opens a bookmarklet in an popup window
\r
775 public function parse_addpopupcode()
\r
777 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
782 * Parse skinvar adminurl
\r
783 * (shortcut for admin url)
\r
788 public function parse_adminurl()
\r
790 $this->parse_sitevar('adminurl');
\r
795 * Actions::parse_archive()
\r
796 * Parse skinvar archive
\r
798 * @param string $template name of template
\r
799 * @param string $category name of category
\r
802 public function parse_archive($template, $category = '')
\r
804 global $blog, $archive;
\r
805 // can be used with either yyyy-mm or yyyy-mm-dd
\r
806 sscanf($archive,'%d-%d-%d', $y, $m, $d);
\r
807 $this->setBlogCategory($blog, $category);
\r
808 $this->preBlogContent('achive',$blog);
\r
809 $blog->showArchive($template, $y, $m, $d);
\r
810 $this->postBlogContent('achive',$blog);
\r
815 * Actions::parse_archivedate()
\r
816 * %archivedate(locale,date format)%
\r
818 * @param string $locale
\r
821 public function parse_archivedate($locale = '-def-')
\r
826 * TODO: these lines are no meaning because there is no $template.
\r
827 if ( $locale == '-def-' )
\r
829 setlocale(LC_TIME, $template['LOCALE']);
\r
833 setlocale(LC_TIME, $locale);
\r
837 // get archive date
\r
838 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
841 $args = func_get_args();
\r
842 // format can be spread over multiple parameters
\r
843 if ( sizeof($args) > 1 )
\r
845 // take away locale
\r
846 array_shift($args);
\r
848 $format=implode(',',$args);
\r
850 elseif ( $d == 0 && $m !=0 )
\r
860 $format = '%d %B %Y';
\r
862 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
\r
867 * Actions::parse_archivedaylist()
\r
868 * Parse skinvar archivedaylist
\r
870 * @param string $template name of template
\r
871 * @param string $category name of category
\r
872 * @param integer $limit the number of items in a display
\r
875 public function parse_archivedaylist($template, $category = 'all', $limit = 0)
\r
878 if ( $category == 'all' )
\r
882 $this->preBlogContent('archivelist',$blog);
\r
883 $this->setBlogCategory($blog, $category);
\r
884 $blog->showArchiveList($template, 'day', $limit);
\r
885 $this->postBlogContent('archivelist',$blog);
\r
890 * Actions::parse_archivelink()
\r
891 * A link to the archives for the current blog (or for default blog)
\r
893 * @param string $linktext text for link
\r
896 public function parse_archivelink($linktext = '')
\r
898 global $blog, $CONF;
\r
901 echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
\r
905 echo $this->link(Link::create_archivelist_link(), $linktext);
\r
911 * Actions::parse_archivelist()
\r
913 * @param string $template name of template
\r
914 * @param string $category name of category
\r
915 * @param integer $limit the number of items in a display
\r
918 public function parse_archivelist($template, $category = 'all', $limit = 0)
\r
921 if ( $category == 'all' )
\r
925 $this->preBlogContent('archivelist',$blog);
\r
926 $this->setBlogCategory($blog, $category);
\r
927 $blog->showArchiveList($template, 'month', $limit);
\r
928 $this->postBlogContent('archivelist',$blog);
\r
933 * Actions::parse_archiveyearlist()
\r
935 * @param string $template name of template
\r
936 * @param string $category name of category
\r
937 * @param integer $limit the number of items in a display
\r
939 public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
\r
942 if ( $category == 'all' )
\r
946 $this->preBlogContent('archivelist',$blog);
\r
947 $this->setBlogCategory($blog, $category);
\r
948 $blog->showArchiveList($template, 'year', $limit);
\r
949 $this->postBlogContent('archivelist',$blog);
\r
954 * Actions::parse_archivetype()
\r
955 * Parse skinvar archivetype
\r
960 public function parse_archivetype()
\r
962 global $archivetype;
\r
968 * Actions::parse_blog()
\r
969 * Parse skinvar blog
\r
971 * @param string $template name of template
\r
972 * @param mixed $amount the number of items in a display, in case it includes the beginning
\r
973 * @param string $category name of category
\r
976 public function parse_blog($template, $amount = 10, $category = '')
\r
978 global $blog, $startpos;
\r
980 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
981 $this->setBlogCategory($blog, $category);
\r
982 $this->preBlogContent('blog',$blog);
\r
983 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
\r
984 $this->postBlogContent('blog',$blog);
\r
989 * Actions::parse_bloglist()
\r
990 * Parse skinvar bloglist
\r
991 * Shows a list of all blogs
\r
993 * @param string $template name of template
\r
994 * @param string $bnametype whether 'name' or 'shortname' is used for the link text
\r
995 * @param string $orderby order criteria
\r
996 * @param string $direction order ascending or descending
\r
999 public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
\r
1001 Blog::showBlogList($template, $bnametype, $orderby, $direction);
\r
1006 * Actions::parse_blogsetting()
\r
1007 * Parse skinvar blogsetting
\r
1009 * @param string $which key of weblog settings
\r
1012 public function parse_blogsetting($which)
\r
1018 echo Entity::hsc($blog->getID());
\r
1021 echo Entity::hsc($blog->getURL());
\r
1024 echo Entity::hsc($blog->getName());
\r
1027 echo Entity::hsc($blog->getDescription());
\r
1030 echo Entity::hsc($blog->getShortName());
\r
1037 * Actions::parse_callback()
\r
1040 * @param string $eventName name of event
\r
1041 * @param string $type type of skin
\r
1044 public function parse_callback($eventName, $type)
\r
1047 $manager->notify($eventName, array('type' => $type));
\r
1052 * Actions::parse_category()
\r
1053 * Parse skinvar category
\r
1055 * @param string $type key of category settings
\r
1058 public function parse_category($type = 'name')
\r
1060 global $catid, $blog;
\r
1061 if ( !$blog->isValidCategory($catid) )
\r
1069 echo $blog->getCategoryName($catid);
\r
1072 echo $blog->getCategoryDesc($catid);
\r
1082 * Actions::parse_categorylist()
\r
1083 * Parse categorylist
\r
1085 * @param string $template name of template
\r
1086 * @param string $blogname name of weblog
\r
1089 public function parse_categorylist($template, $blogname = '')
\r
1091 global $blog, $manager;
\r
1093 // when no blog found
\r
1094 if ( ($blogname == '') && (!is_object($blog)) )
\r
1099 if ( $blogname == '' )
\r
1101 $this->preBlogContent('categorylist',$blog);
\r
1102 $blog->showCategoryList($template);
\r
1103 $this->postBlogContent('categorylist',$blog);
\r
1107 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1108 $this->preBlogContent('categorylist',$b);
\r
1109 $b->showCategoryList($template);
\r
1110 $this->postBlogContent('categorylist',$b);
\r
1116 * Actions::parse_commentform()
\r
1117 * Parse skinvar commentform
\r
1119 * @param string $destinationurl URI for redirection
\r
1122 public function parse_commentform($destinationurl = '')
\r
1124 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
\r
1126 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
\r
1127 if ( stristr($destinationurl, 'action.php') )
\r
1129 $args = func_get_args();
\r
1130 $destinationurl = $args[1];
\r
1131 ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
\r
1134 $actionurl = $CONF['ActionURL'];
\r
1136 // if item is closed, show message and do nothing
\r
1137 $item =& $manager->getItem($itemid,0,0);
\r
1138 if ( $item['closed'] || !$blog->commentsEnabled() )
\r
1140 $this->doForm('commentform-closed');
\r
1144 if ( !$blog->isPublic() && !$member->isLoggedIn() )
\r
1146 $this->doForm('commentform-closedtopublic');
\r
1150 if ( !$destinationurl )
\r
1152 // note: createLink returns an HTML encoded URL
\r
1153 $destinationurl = Link::create_link(
\r
1156 'itemid' => $itemid,
\r
1157 'title' => $item['title'],
\r
1158 'timestamp' => $item['timestamp'],
\r
1159 'extra' => $this->linkparams
\r
1165 // HTML encode URL
\r
1166 $destinationurl = Entity::hsc($destinationurl);
\r
1169 // values to prefill
\r
1170 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
\r
1173 $user = postVar('user');
\r
1176 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
\r
1179 $userid = postVar('userid');
\r
1182 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
\r
1185 $email = postVar('email');
\r
1188 $body = postVar('body');
\r
1190 $this->formdata = array(
\r
1191 'destinationurl' => $destinationurl, // url is already HTML encoded
\r
1192 'actionurl' => Entity::hsc($actionurl),
\r
1193 'itemid' => $itemid,
\r
1194 'user' => Entity::hsc($user),
\r
1195 'userid' => Entity::hsc($userid),
\r
1196 'email' => Entity::hsc($email),
\r
1197 'body' => Entity::hsc($body),
\r
1198 'membername' => $member->getDisplayName(),
\r
1199 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
\r
1202 if ( !$member->isLoggedIn() )
\r
1204 $this->doForm('commentform-notloggedin');
\r
1208 $this->doForm('commentform-loggedin');
\r
1214 * Actions::parse_comments()
\r
1215 * Parse skinvar comments
\r
1216 * include comments for one item
\r
1218 * @param string $template name of template
\r
1221 public function parse_comments($template)
\r
1223 global $manager, $blog, $highlight, $itemid;
\r
1225 $template =& $manager->getTemplate($template);
\r
1226 $item =& $manager->getitem($itemid, 0, 0);
\r
1228 // create parser object & action handler
\r
1229 $handler = new ItemActions($blog);
\r
1230 $handler->setTemplate($template);
\r
1231 $handler->setCurrentItem($item);
\r
1233 $parser = new Parser($handler);
\r
1235 $comments = new Comments($itemid);
\r
1236 $comments->setItemActions($handler);
\r
1237 // shows ALL comments
\r
1238 $comments->showComments($template, -1, 1, $highlight);
\r
1243 * Actions::parse_errordiv()
\r
1249 public function parse_errordiv()
\r
1251 global $errormessage;
\r
1252 if ( $errormessage )
\r
1254 echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
\r
1260 * Actions::parse_errormessage()
\r
1261 * Parse skinvar errormessage
\r
1266 public function parse_errormessage()
\r
1268 global $errormessage;
\r
1269 echo $errormessage;
\r
1274 * Actions::parse_formdata()
\r
1277 * @param string $what key of format data
\r
1280 public function parse_formdata($what)
\r
1282 echo $this->formdata[$what];
\r
1287 * Actions::parse_ifcat()
\r
1290 * @param string $text
\r
1293 public function parse_ifcat($text = '')
\r
1295 if ( $text == '' )
\r
1298 $this->parse_if('category');
\r
1303 global $catid, $blog;
\r
1304 if ( $blog->isValidCategory($catid) )
\r
1313 * Actions::parse_image()
\r
1314 * Parse skinvar image
\r
1316 * @param string $what name of tag
\r
1319 public function parse_image($what = 'imgtag')
\r
1323 $imagetext = Entity::hsc(requestVar('imagetext'));
\r
1324 $imagepopup = requestVar('imagepopup');
\r
1325 $width = intRequestVar('width');
\r
1326 $height = intRequestVar('height');
\r
1327 $fullurl = Entity::hsc($CONF['MediaURL'] . $imagepopup);
\r
1346 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
\r
1353 * Actions::parse_imagetext()
\r
1354 * Parse skinvar imagetext
\r
1359 public function parse_imagetext()
\r
1361 $this->parse_image('imagetext');
\r
1366 * Actions::parse_item()
\r
1367 * Parse skinvar item
\r
1368 * include one item (no comments)
\r
1373 public function parse_item($template)
\r
1375 global $blog, $itemid, $highlight;
\r
1377 // need this to select default category
\r
1378 $this->setBlogCategory($blog, '');
\r
1379 $this->preBlogContent('item',$blog);
\r
1380 $r = $blog->showOneitem($itemid, $template, $highlight);
\r
1383 echo _ERROR_NOSUCHITEM;
\r
1385 $this->postBlogContent('item',$blog);
\r
1390 * Actions::parse_itemid()
\r
1391 * Parse skinvar itemid
\r
1396 public function parse_itemid()
\r
1404 * Actions::parseitemlink()
\r
1405 * Parse skinvar itemlink
\r
1410 public function parse_itemlink($linktext = '')
\r
1413 $this->itemlink($itemid, $linktext);
\r
1418 * Actions::parse_itemtitle()
\r
1424 public function parse_itemtitle($format = '')
\r
1426 global $manager, $itemid;
\r
1427 $item =& $manager->getItem($itemid,0,0);
\r
1429 switch ( $format )
\r
1432 echo Entity::hen($item['title']);
\r
1435 echo $item['title'];
\r
1439 echo Entity::hsc(strip_tags($item['title']));
\r
1446 * Actions::parse_loginform()
\r
1447 * Parse skinvar loginform
\r
1452 public function parse_loginform()
\r
1454 global $member, $CONF;
\r
1455 if ( !$member->isLoggedIn() )
\r
1457 $filename = 'loginform-notloggedin';
\r
1458 $this->formdata = array();
\r
1462 $filename = 'loginform-loggedin';
\r
1463 $this->formdata = array(
\r
1464 'membername' => $member->getDisplayName(),
\r
1467 $this->doForm($filename);
\r
1472 * Actions::parse_member()
\r
1473 * Parse skinvar member
\r
1474 * (includes a member info thingie)
\r
1476 * @param string $what which memberdata is needed
\r
1479 public function parse_member($what)
\r
1481 global $memberinfo, $member, $CONF;
\r
1483 // 1. only allow the member-details-page specific variables on member pages
\r
1484 if ( $this->skintype == 'member' )
\r
1489 echo Entity::hsc($memberinfo->getDisplayName());
\r
1492 echo Entity::hsc($memberinfo->getRealName());
\r
1495 echo Entity::hsc($memberinfo->getNotes());
\r
1498 echo Entity::hsc($memberinfo->getURL());
\r
1501 echo Entity::hsc($memberinfo->getEmail());
\r
1504 echo Entity::hsc($memberinfo->getID());
\r
1509 // 2. the next bunch of options is available everywhere, as long as the user is logged in
\r
1510 if ( $member->isLoggedIn() )
\r
1515 echo $member->getDisplayName();
\r
1517 case 'yourrealname':
\r
1518 echo $member->getRealName();
\r
1521 echo $member->getNotes();
\r
1524 echo $member->getURL();
\r
1527 echo $member->getEmail();
\r
1530 echo $member->getID();
\r
1532 case 'yourprofileurl':
\r
1533 if ($CONF['URLMode'] == 'pathinfo')
\r
1534 echo Link::create_member_link($member->getID());
\r
1536 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
\r
1544 * Link::parse_membermailform()
\r
1545 * Parse skinvar membermailform
\r
1547 * @param integer $rows the height for textarea
\r
1548 * @param integer $cols the width for textarea
\r
1549 * @param string $desturl URI to redirect
\r
1552 public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
\r
1554 global $member, $CONF, $memberid;
\r
1556 if ( $desturl == '' )
\r
1558 if ( $CONF['URLMode'] == 'pathinfo' )
\r
1560 $desturl = Link::create_member_link($memberid);
\r
1564 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
\r
1568 $message = postVar('message');
\r
1569 $frommail = postVar('frommail');
\r
1571 $this->formdata = array(
\r
1572 'url' => Entity::hsc($desturl),
\r
1573 'actionurl' => Entity::hsc($CONF['ActionURL']),
\r
1574 'memberid' => $memberid,
\r
1577 'message' => Entity::hsc($message),
\r
1578 'frommail' => Entity::hsc($frommail)
\r
1581 if ( $member->isLoggedIn() )
\r
1583 $this->doForm('membermailform-loggedin');
\r
1585 else if ( $CONF['NonmemberMail'] )
\r
1587 $this->doForm('membermailform-notloggedin');
\r
1591 $this->doForm('membermailform-disallowed');
\r
1597 * Actions::parse_nextarchive()
\r
1598 * Parse skinvar nextarchive
\r
1603 public function parse_nextarchive()
\r
1605 global $archivenext;
\r
1606 echo $archivenext;
\r
1611 * Parse skinvar nextitem
\r
1612 * (include itemid of next item)
\r
1617 public function parse_nextitem()
\r
1619 global $itemidnext;
\r
1620 if ( isset($itemidnext) )
\r
1622 echo (int)$itemidnext;
\r
1628 * Actions::parse_nextitemtitle()
\r
1629 * Parse skinvar nextitemtitle
\r
1630 * (include itemtitle of next item)
\r
1632 * @param string $format format of text
\r
1635 public function parse_nextitemtitle($format = '')
\r
1637 global $itemtitlenext;
\r
1639 switch ( $format )
\r
1642 echo Entity::hen($itemtitlenext);
\r
1645 echo $itemtitlenext;
\r
1649 echo Entity::hsc($itemtitlenext);
\r
1656 * Actions::parse_nextlink()
\r
1657 * Parse skinvar nextlink
\r
1659 * @param string $linktext text for content of anchor element
\r
1660 * @param integer $amount the amount of items in a display
\r
1661 * @param integer $recount increment from this value
\r
1664 public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
\r
1666 global $itemidnext, $archivenext, $startpos;
\r
1667 if ( $this->skintype == 'item' )
\r
1669 $this->itemlink($itemidnext, $linktext);
\r
1671 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
1673 $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
\r
1677 $this->archivelink($archivenext, $linktext);
\r
1683 * Actions::parse_nucleusbutton()
\r
1684 * Parse skinvar nucleusbutton
\r
1686 * @param string $imgurl URL for image
\r
1687 * @param integer $imgwidth width of image
\r
1688 * @param integer $imgheidht height of image
\r
1690 public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
\r
1693 if ( $imgurl == '' )
\r
1695 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
\r
1697 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
\r
1699 // when skindit IncludeMode is used: start from skindir
\r
1700 $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
\r
1703 $this->formdata = array(
\r
1704 'imgurl' => $imgurl,
\r
1705 'imgwidth' => $imgwidth,
\r
1706 'imgheight' => $imgheight,
\r
1708 $this->doForm('nucleusbutton');
\r
1713 * Actions::parse_otherarchive()
\r
1714 * Parse skinvar otherarchive
\r
1716 * @param string $blogname name of weblog
\r
1717 * @param string $template name of template
\r
1718 * @param string $category name of category
\r
1721 public function parse_otherarchive($blogname, $template, $category = '')
\r
1723 global $archive, $manager;
\r
1724 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
1725 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1726 $this->setBlogCategory($b, $category);
\r
1727 $this->preBlogContent('otherachive',$b);
\r
1728 $b->showArchive($template, $y, $m, $d);
\r
1729 $this->postBlogContent('otherachive',$b);
\r
1734 * Actions::parse_otherarchivedaylist()
\r
1735 * Parse skinvar otherarchivedaylist
\r
1737 * @param string $blogname name of weblog
\r
1738 * @param string $template name of template
\r
1739 * @param string $category name of category
\r
1740 * @param integer $limit the amount of items in a display
\r
1743 public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
\r
1746 if ( $category == 'all')
\r
1750 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1751 $this->setBlogCategory($b, $category);
\r
1752 $this->preBlogContent('otherarchivelist',$b);
\r
1753 $b->showArchiveList($template, 'day', $limit);
\r
1754 $this->postBlogContent('otherarchivelist',$b);
\r
1759 * Actions::parse_otherarchivelist()
\r
1760 * Parse skinvar otherarchivelist
\r
1762 * @param string $blogname name of weblog
\r
1763 * @param string $template name of template
\r
1764 * @param string $category name of category
\r
1765 * @param integer $limit the amount of items in a display
\r
1768 public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
\r
1771 if ( $category == 'all' )
\r
1775 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1776 $this->setBlogCategory($b, $category);
\r
1777 $this->preBlogContent('otherarchivelist',$b);
\r
1778 $b->showArchiveList($template, 'month', $limit);
\r
1779 $this->postBlogContent('otherarchivelist',$b);
\r
1784 * Actions::parse_otherarchiveyearlist()
\r
1785 * Parse skinvar otherarchiveyearlist
\r
1787 * @param string $blogname name of weblog
\r
1788 * @param string $template name of template
\r
1789 * @param string $category name of category
\r
1790 * @limit integer $limit the amount of items in a display
\r
1792 public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
\r
1795 if ( $category == 'all' )
\r
1799 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1800 $this->setBlogCategory($b, $category);
\r
1801 $this->preBlogContent('otherarchivelist',$b);
\r
1802 $b->showArchiveList($template, 'year', $limit);
\r
1803 $this->postBlogContent('otherarchivelist',$b);
\r
1808 * Actions::parse_otherblog()
\r
1809 * Parse skinvar otherblog
\r
1811 * @param string $blogname name of weblog
\r
1812 * @param string $template name of template
\r
1813 * @param mixed $amount the amount of items, in case it includes the beginning
\r
1814 * @param string $category name of category
\r
1817 public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
\r
1821 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
1823 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1824 $this->setBlogCategory($b, $category);
\r
1825 $this->preBlogContent('otherblog',$b);
\r
1826 $this->amountfound = $b->readLog($template, $limit, $offset);
\r
1827 $this->postBlogContent('otherblog',$b);
\r
1832 * Actions::parse_othersearchresults()
\r
1833 * Parse skinvar othersearchresults
\r
1835 * @param string $blogname name of weblog
\r
1836 * @param string $template name of template
\r
1837 * @param integer $maxresults the amount of results
\r
1840 public function parse_othersearchresults($blogname, $template, $maxresults = 50)
\r
1842 global $query, $amount, $manager, $startpos;
\r
1843 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1844 // need this to select default category
\r
1845 $this->setBlogCategory($b, '');
\r
1846 $this->preBlogContent('othersearchresults',$b);
\r
1847 $b->search($query, $template, $amount, $maxresults, $startpos);
\r
1848 $this->postBlogContent('othersearchresults',$b);
\r
1853 * Actions::parse_plugin()
\r
1854 * Executes a plugin skinvar
\r
1855 * extra parameters can be added
\r
1857 * @param string $pluginName name of plugin (without the NP_)
\r
1860 public function parse_plugin($pluginName)
\r
1864 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
1871 $params = func_get_args();
\r
1873 // remove plugin name
\r
1874 array_shift($params);
\r
1876 // add skin type on front
\r
1877 array_unshift($params, $this->skintype);
\r
1879 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
\r
1884 * Actions::parse_prevarchive()
\r
1885 * Parse skinvar prevarchive
\r
1890 public function parse_prevarchive()
\r
1892 global $archiveprev;
\r
1893 echo $archiveprev;
\r
1897 * Actions::parse_preview()
\r
1898 * Parse skinvar preview
\r
1900 * @param string $template name of tempalte
\r
1903 public function parse_preview($template)
\r
1905 global $blog, $CONF, $manager;
\r
1907 $template =& $manager->getTemplate($template);
\r
1909 $row['body'] = '<span id="prevbody"></span>';
\r
1910 $row['title'] = '<span id="prevtitle"></span>';
\r
1911 $row['more'] = '<span id="prevmore"></span>';
\r
1912 $row['itemlink'] = '';
\r
1913 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
\r
1915 echo Template::fill($template['ITEM_HEADER'],$row);
\r
1916 echo Template::fill($template['ITEM'],$row);
\r
1917 echo Template::fill($template['ITEM_FOOTER'],$row);
\r
1922 * Actions::parse_previtem()
\r
1923 * Parse skinvar previtem
\r
1924 * (include itemid of prev item)
\r
1929 public function parse_previtem()
\r
1931 global $itemidprev;
\r
1932 if ( isset($itemidprev) )
\r
1934 echo (integer) $itemidprev;
\r
1940 * Actions::parse_previtemtitle()
\r
1941 * Parse skinvar previtemtitle
\r
1942 * (include itemtitle of prev item)
\r
1944 * @param String $format string format
\r
1945 * @return String formatted string
\r
1947 public function parse_previtemtitle($format = '')
\r
1949 global $itemtitleprev;
\r
1951 switch ( $format )
\r
1954 echo Entity::hen($itemtitleprev);
\r
1957 echo $itemtitleprev;
\r
1961 echo Entity::hsc($itemtitleprev);
\r
1968 * Actions::parse_prevlink()
\r
1969 * Parse skinvar prevlink
\r
1971 * @param string $linktext text as a content of anchor element
\r
1972 * @param integer the amount of links
\r
1975 public function parse_prevlink($linktext = '', $amount = 10)
\r
1977 global $itemidprev, $archiveprev, $startpos;
\r
1979 if ( $this->skintype == 'item' )
\r
1981 $this->itemlink($itemidprev, $linktext);
\r
1983 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
\r
1985 $this->searchlink($amount, $startpos, 'prev', $linktext);
\r
1989 $this->archivelink($archiveprev, $linktext);
\r
1995 * Actions::parse_query()
\r
1996 * Parse skinvar query
\r
1997 * (includes the search query)
\r
2002 public function parse_query()
\r
2005 echo Entity::hsc($query);
\r
2010 * Actions::parse_referer()
\r
2011 * Parse skinvar referer
\r
2016 public function parse_referer()
\r
2018 echo Entity::hsc(serverVar('HTTP_REFERER'));
\r
2023 * Actions::parse_searchform()
\r
2024 * Parse skinvar searchform
\r
2026 * @param string $blogname name of weblog
\r
2029 public function parse_searchform($blogname = '')
\r
2031 global $CONF, $manager, $maxresults;
\r
2034 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
\r
2040 // use default blog when no blog is selected
\r
2041 $this->formdata = array(
\r
2042 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
\r
2043 'query' => Entity::hsc(getVar('query')),
\r
2045 $this->doForm('searchform');
\r
2050 * Actions::parse_searchresults()
\r
2051 * Parse skinvar searchresults
\r
2053 * @param string $template name of tempalte
\r
2054 * @param integer $maxresults searched items in a display
\r
2057 public function parse_searchresults($template, $maxresults = 50 )
\r
2059 global $blog, $query, $amount, $startpos;
\r
2061 $this->setBlogCategory($blog, ''); // need this to select default category
\r
2062 $this->preBlogContent('searchresults',$blog);
\r
2063 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
\r
2064 $this->postBlogContent('searchresults',$blog);
\r
2069 * Actions::parse_self()
\r
2070 * Parse skinvar self
\r
2075 public function parse_self()
\r
2078 echo $CONF['Self'];
\r
2083 * Actions::parse_sitevar()
\r
2084 * Parse skinvar sitevar
\r
2085 * (include a sitevar)
\r
2087 * @param string $which
\r
2090 public function parse_sitevar($which)
\r
2096 echo $CONF['IndexURL'];
\r
2099 echo $CONF['SiteName'];
\r
2102 echo $CONF['AdminEmail'];
\r
2105 echo $CONF['AdminURL'];
\r
2111 * Actions::parse_skinname()
\r
2117 public function parse_skinname()
\r
2119 echo $this->parser->skin->getName();
\r
2124 * Actions::parse_skintype()
\r
2125 * Parse skintype (experimental)
\r
2130 public function parse_skintype()
\r
2132 echo $this->skintype;
\r
2137 * Actions::parse_ticket()
\r
2143 public function parse_ticket()
\r
2146 $manager->addTicketHidden();
\r
2151 * Actions::parse_todaylink()
\r
2152 * Parse skinvar todaylink
\r
2153 * A link to the today page (depending on selected blog, etc...)
\r
2155 * @param string $linktext text for link
\r
2158 public function parse_todaylink($linktext = '')
\r
2160 global $blog, $CONF;
\r
2163 echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
\r
2167 echo $this->link($CONF['SiteUrl'], $linktext);
\r
2174 * When commentform is not used, to include a hidden field with itemid
\r
2179 public function parse_vars()
\r
2182 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
\r
2187 * Actions::parse_version()
\r
2188 * Parse skinvar version
\r
2189 * (include nucleus versionnumber)
\r
2194 public function parse_version()
\r
2197 echo 'Nucleus CMS ' . $nucleus['version'];
\r
2202 * Actions::parse_sticky()
\r
2203 * Parse skinvar sticky
\r
2205 * @param integer $itemnumber id of item
\r
2206 * @param string $template name of template
\r
2209 public function parse_sticky($itemnumber = 0, $template = '')
\r
2213 $itemnumber = intval($itemnumber);
\r
2214 $itemarray = array($itemnumber);
\r
2216 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
\r
2217 $this->preBlogContent('sticky',$b);
\r
2218 $this->amountfound = $b->readLogFromList($itemarray, $template);
\r
2219 $this->postBlogContent('sticky',$b);
\r