3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
13 * This class contains the functions that get called by using
14 * the special tags in the skins
16 * @license http://nucleuscms.org/license.txt GNU General Public License
17 * @copyright Copyright (C) 2002-2012 The Nucleus Group
18 * @version $Id: ACTIONS.php 1863 2012-05-19 10:50:27Z sakamocchi $
21 class Actions extends BaseActions
23 // part of the skin currently being parsed ('index', 'item', 'archive',
24 // 'archivelist', 'member', 'search', 'error', 'imagepopup')
27 // contains an assoc array with parameters that need to be included when
28 // generating links to items/archives/... (e.g. catid)
31 // used when including templated forms from the include/ dir. The $formdata var
32 // contains the values to fill out in there (assoc array name -> value)
35 // filled out with the number of displayed items after calling one of the
36 // (other)blog/(other)searchresults skinvars.
40 * Actions::$default_actions
41 * list of whole action names with which this class can deal
43 static private $default_actions = array(
53 'otherarchivedaylist',
55 'otherarchiveyearlist',
66 // deprecated (Nucleus v2.0)
67 /* TODO: remove this */
72 * Actions::$skin_type_friendly_names
73 * friendly name for wrapped page types
75 static public $default_skin_types = array(
76 'index' => _SKIN_PART_MAIN,
77 'item' => _SKIN_PART_ITEM,
78 'archivelist' => _SKIN_PART_ALIST,
79 'archive' => _SKIN_PART_ARCHIVE,
80 'search' => _SKIN_PART_SEARCH,
81 'error' => _SKIN_PART_ERROR,
82 'member' => _SKIN_PART_MEMBER,
83 'imagepopup' => _SKIN_PART_POPUP
87 * Actions::getAvailableSkinTypes()
91 * @return array list of friendly names for page actions
93 static public function getAvailableSkinTypes()
95 return self::$default_skin_types;
99 * Actions::__construct()
100 * Constructor for a new Actions object
102 * @param string $type
105 public function __construct($type)
109 // call constructor of superclass first
110 parent::__construct();
111 $this->skintype = $type;
115 $this->linkparams = array('catid' => $catid);
121 * Actions::getAvailableActions()
124 * @return array allowed actions for the page type
126 public function getAvailableActions()
128 $extra_actions = array();
130 switch ( $this->skintype )
133 $extra_actions = array(
147 $extra_actions = array(
165 $extra_actions = array(
175 $extra_actions = array(
182 'othersearchresults',
190 $extra_actions = array(
192 // deprecated (Nucleus v2.0)
193 /* TODO: remove this */
198 $extra_actions = array(
206 $extra_actions = array(
229 $extra_actions = array(
235 $extra_actions = array(
253 $defined_actions = array_merge(self::$default_actions, $extra_actions);
255 return array_merge($defined_actions, parent::getAvailableActions());
260 * Forms get parsedincluded now, using an extra <formdata> skinvar
262 * @param string $filename
265 public function doForm($filename)
268 array_push($this->parser->actions,'formdata', 'callback','errordiv','ticket');
270 $oldIncludeMode = Parser::getProperty('IncludeMode');
271 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
272 Parser::setProperty('IncludeMode','normal');
273 Parser::setProperty('IncludePrefix','');
275 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
276 Parser::setProperty('IncludeMode',$oldIncludeMode);
277 Parser::setProperty('IncludePrefix',$oldIncludePrefix);
279 array_pop($this->parser->actions); // errordiv
280 array_pop($this->parser->actions); // callback
281 array_pop($this->parser->actions); // formdata
282 array_pop($this->parser->actions); // ticket
287 * Actions::checkCondition()
288 * Checks conditions for if statements
290 * @param string $field type of <%if%>
291 * @param string $name property of field
292 * @param string $value value of property
293 * @return boolean condition
295 protected function checkCondition($field, $name='', $value = '')
297 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
303 $condition = ($blog && $this->ifCategory($name,$value));
306 $condition = ($blog && ($blog->getSetting($name) == $value));
309 $condition = $member->isLoggedIn();
312 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
315 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
318 $condition = ($itemidnext != '');
321 $condition = ($itemidprev != '');
323 case 'archiveprevexists':
324 $condition = ($archiveprevexists == true);
326 case 'archivenextexists':
327 $condition = ($archivenextexists == true);
330 $condition = (($name == $this->skintype) || ($name == requestVar('action')));
333 $condition = $this->ifHasPlugin($name, $value);
336 $condition = $manager->pluginInstalled("NP_{$field}") && $this->ifPlugin($field, $name, $value);
343 * Actions::_ifHasPlugin()
345 * -> checks if plugin exists
346 * hasplugin,PlugName,OptionName
347 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
348 * hasplugin,PlugName,OptionName=value
349 * -> checks if the option OptionName from plugin PlugName is set to value
351 * @param string $name name of plugin
352 * @param string $value
355 private function ifHasPlugin($name, $value)
359 // (pluginInstalled method won't write a message in the actionlog on failure)
360 if ( $manager->pluginInstalled("NP_{$name}") )
362 $plugin =& $manager->getPlugin("NP_{$name}");
363 if ( $plugin != NULL )
371 list($name2, $value2) = preg_split('#=#', $value, 2);
372 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
376 else if ( $plugin->getOption($name2) == $value2 )
387 * Actions::ifPlugin()
388 * Checks if a plugin exists and call its doIf function
390 * @param string $name name of plugin
391 * @param string $key name of plugin option
392 * @param string $value value of plugin option
395 private function ifPlugin($name, $key = '', $value = '')
399 $plugin =& $manager->getPlugin("NP_{$name}");
405 $params = func_get_args();
406 array_shift($params);
408 return call_user_func_array(array(&$plugin, 'doIf'), $params);
412 * Actions::ifCategory()
413 * Different checks for a category
415 * @param string $name
416 * @param string $value
419 private function ifCategory($name = '', $value='')
421 global $blog, $catid;
423 // when no parameter is defined, just check if a category is selected
424 if ( ($name != 'catname' && $name != 'catid') || ($value == '') )
426 return $blog->isValidCategory($catid);
428 // check category name
429 else if ( $name == 'catname' )
431 $value = $blog->getCategoryIdFromName($value);
432 if ( $value == $catid )
434 return $blog->isValidCategory($catid);
438 else if ( ($name == 'catid') && ($value == $catid) )
440 return $blog->isValidCategory($catid);
446 * Actions::ifOnTeam()
447 * Checks if a member is on the team of a blog and return his rights
449 * @param string $blogName name of weblog
452 private function ifOnTeam($blogName = '')
454 global $blog, $member, $manager;
456 // when no blog found
457 if ( ($blogName == '') && !is_object($blog) )
462 // explicit blog selection
463 if ( $blogName != '' )
465 $blogid = getBlogIDFromName($blogName);
468 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
471 $blogid = $blog->getID();
474 return $member->teamRights($blogid);
479 * Checks if a member is admin of a blog
481 * @param string $blogName name of weblog
484 private function ifAdmin($blogName = '')
486 global $blog, $member, $manager;
488 // when no blog found
489 if ( ($blogName == '') && (!is_object($blog)) )
494 // explicit blog selection
495 if ( $blogName != '' )
497 $blogid = getBlogIDFromName($blogName);
500 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
503 $blogid = $blog->getID();
506 return $member->isBlogAdmin($blogid);
512 * - a raw link (html/xml encoded) when no linktext is provided
513 * - a (x)html <a href... link when a text is present (text htmlencoded)
515 * @param string $url URL for href attribute of anchor element
516 * @param string $linktext content of anchor element
519 private function link($url, $linktext = '')
521 $u = Entity::hsc($url);
522 // fix URLs that already had encoded ampersands
523 $u = preg_replace("#&amp;#", '&', $u);
524 if ( $linktext != '' )
526 $l = '<a href="' . $u .'">' . Entity::hsc($linktext) . '</a>';
536 * Actions::searchlink()
537 * Outputs a next/prev link
540 * The maximum amount of items shown per page (e.g. 10)
542 * Current start position (requestVar('startpos'))
544 * either 'prev' or 'next'
546 * When present, the output will be a full <a href...> link. When empty,
547 * only a raw link will be outputted
549 private function searchlink($maxresults, $startpos, $direction, $linktext = '', $recount = '')
551 global $CONF, $blog, $query, $amount;
552 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
553 $startpos = (integer) $startpos;
554 $parsed = parse_url(serverVar('REQUEST_URI'));
555 $path = $parsed['path'];
556 $parsed = $parsed['query'];
559 if ( $direction == 'prev' )
561 if ( intval($startpos) - intval($maxresults) >= 0 )
563 $startpos = intval($startpos) - intval($maxresults);
565 if ( $this->skintype == 'index' )
569 else if ( $this->skintype == 'search' )
571 $url = $CONF['SearchURL'];
573 $url .= '?' . alterQueryStr($parsed,'startpos',$startpos);
576 else if ( $direction == 'next' )
578 global $navigationItems;
579 if ( !isset($navigationItems) )
581 $navigationItems = 0;
590 $iAmountOnPage = $this->amountfound;
593 if ( intval($navigationItems) > 0 )
595 $iAmountOnPage = intval($navigationItems) - intval($startpos);
597 elseif ( $iAmountOnPage == 0 )
600 * [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
603 if ( $this->skintype == 'index' )
605 $sqlquery = $blog->getSqlBlog('', 'count');
608 else if ( $this->skintype == 'search' )
610 $unused_highlight = '';
611 $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
612 $url = $CONF['SearchURL'];
616 $iAmountOnPage = intval(DB::getValue($sqlquery)) - intval($startpos);
621 if ( intval($iAmountOnPage) >= intval($maxresults) )
623 $startpos = intval($startpos) + intval($maxresults);
624 $url .= '?' . alterQueryStr($parsed, 'startpos', $startpos);
630 echo $this->link($url, $linktext);
636 * Actions::itemlink()
637 * Creates an item link and if no id is given a todaylink
639 * @param integer $id id for link
640 * @param string $linktext text for link
643 private function itemlink($id, $linktext = '')
648 echo $this->link(Link::create_item_link($id, $this->linkparams), $linktext);
652 $this->parse_todaylink($linktext);
658 * Actions::archivelink)
659 * Creates an archive link and if no id is given a todaylink
661 * @param integer $id id for link
662 * @param string $linktext text for link
665 private function archivelink($id, $linktext = '')
670 echo $this->link(Link::create_archive_link($blog->getID(), $id, $this->linkparams), $linktext);
674 $this->parse_todaylink($linktext);
680 * Actions:setBlogCategory()
681 * Helper function that sets the category that a blog will need to use
683 * @param string $blog An object of the blog class, passed by reference (we want to make changes to it)
684 * @param string $catname The name of the category to use
687 private function setBlogCategory(&$blog, $catname)
690 if ( $catname != '' )
692 $blog->setSelectedCategoryByName($catname);
696 $blog->setSelectedCategory($catid);
702 * Actions::preBlogContent()
703 * Notifies the Manager that a PreBlogContent event occurs
705 * @param string $type type of skin
706 * @param object $blog an instance of Blog class
709 private function preBlogContent($type, &$blog)
712 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
717 * Actions::postBlogContent()
718 * Notifies the Manager that a PostBlogContent event occurs
720 * @param string $type type of skin
721 * @param objecct $blog an instance of Blog class
724 private function postBlogContent($type, &$blog)
727 $manager->notify('PostBlogContent', array('blog' => &$blog, 'type' => $type));
732 * Actions::parse_additemform()
733 * Parse skinvar additemform
738 public function parse_additemform()
741 $this->formdata = array(
742 'adminurl' => Entity::hsc($CONF['AdminURL']),
743 'catid' => $blog->getDefaultCategory()
745 $blog->InsertJavaScriptInfo();
746 $this->doForm('additemform');
751 * Actions::parse_addlink()
752 * Parse skinvar addlink
753 * A Link that allows to open a bookmarklet to add an item
755 public function parse_addlink()
757 global $CONF, $member, $blog;
758 if ( $member->isLoggedIn() && $member->isTeamMember($blog->blogid) )
760 echo $CONF['AdminURL'].'bookmarklet.php?blogid='.$blog->blogid;
766 * Actions::parse_addpopupcode()
767 * Parse skinvar addpopupcode
768 * Code that opens a bookmarklet in an popup window
773 public function parse_addpopupcode()
775 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;";
780 * Parse skinvar adminurl
781 * (shortcut for admin url)
786 public function parse_adminurl()
788 $this->parse_sitevar('adminurl');
793 * Actions::parse_archive()
794 * Parse skinvar archive
796 * @param string $template name of template
797 * @param string $category name of category
800 public function parse_archive($template, $category = '')
802 global $blog, $archive;
803 // can be used with either yyyy-mm or yyyy-mm-dd
804 sscanf($archive,'%d-%d-%d', $y, $m, $d);
805 $this->setBlogCategory($blog, $category);
806 $this->preBlogContent('achive',$blog);
807 $blog->showArchive($template, $y, $m, $d);
808 $this->postBlogContent('achive',$blog);
813 * Actions::parse_archivedate()
814 * %archivedate(locale,date format)%
816 * @param string $locale
819 public function parse_archivedate($locale = '-def-')
824 * TODO: these lines are no meaning because there is no $template.
825 if ( $locale == '-def-' )
827 setlocale(LC_TIME, $template['LOCALE']);
831 setlocale(LC_TIME, $locale);
836 sscanf($archive,'%d-%d-%d',$y,$m,$d);
839 $args = func_get_args();
840 // format can be spread over multiple parameters
841 if ( sizeof($args) > 1 )
846 $format=implode(',',$args);
848 elseif ( $d == 0 && $m !=0 )
858 $format = '%d %B %Y';
860 echo i18n::formatted_datetime($format, mktime(0,0,0,$m?$m:1,$d?$d:1,$y));
865 * Actions::parse_archivedaylist()
866 * Parse skinvar archivedaylist
868 * @param string $template name of template
869 * @param string $category name of category
870 * @param integer $limit the number of items in a display
873 public function parse_archivedaylist($template, $category = 'all', $limit = 0)
876 if ( $category == 'all' )
880 $this->preBlogContent('archivelist',$blog);
881 $this->setBlogCategory($blog, $category);
882 $blog->showArchiveList($template, 'day', $limit);
883 $this->postBlogContent('archivelist',$blog);
888 * Actions::parse_archivelink()
889 * A link to the archives for the current blog (or for default blog)
891 * @param string $linktext text for link
894 public function parse_archivelink($linktext = '')
899 echo $this->link(Link::create_archivelist_link($blog->getID(), $this->linkparams), $linktext);
903 echo $this->link(Link::create_archivelist_link(), $linktext);
909 * Actions::parse_archivelist()
911 * @param string $template name of template
912 * @param string $category name of category
913 * @param integer $limit the number of items in a display
916 public function parse_archivelist($template, $category = 'all', $limit = 0)
919 if ( $category == 'all' )
923 $this->preBlogContent('archivelist',$blog);
924 $this->setBlogCategory($blog, $category);
925 $blog->showArchiveList($template, 'month', $limit);
926 $this->postBlogContent('archivelist',$blog);
931 * Actions::parse_archiveyearlist()
933 * @param string $template name of template
934 * @param string $category name of category
935 * @param integer $limit the number of items in a display
937 public function parse_archiveyearlist($template, $category = 'all', $limit = 0)
940 if ( $category == 'all' )
944 $this->preBlogContent('archivelist',$blog);
945 $this->setBlogCategory($blog, $category);
946 $blog->showArchiveList($template, 'year', $limit);
947 $this->postBlogContent('archivelist',$blog);
952 * Actions::parse_archivetype()
953 * Parse skinvar archivetype
958 public function parse_archivetype()
966 * Actions::parse_blog()
969 * @param string $template name of template
970 * @param mixed $amount the number of items in a display, in case it includes the beginning
971 * @param string $category name of category
974 public function parse_blog($template, $amount = 10, $category = '')
976 global $blog, $startpos;
978 list($limit, $offset) = sscanf($amount, '%d(%d)');
979 $this->setBlogCategory($blog, $category);
980 $this->preBlogContent('blog',$blog);
981 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
982 $this->postBlogContent('blog',$blog);
987 * Actions::parse_bloglist()
988 * Parse skinvar bloglist
989 * Shows a list of all blogs
991 * @param string $template name of template
992 * @param string $bnametype whether 'name' or 'shortname' is used for the link text
993 * @param string $orderby order criteria
994 * @param string $direction order ascending or descending
997 public function parse_bloglist($template, $bnametype = '', $orderby='number', $direction='asc')
999 Blog::showBlogList($template, $bnametype, $orderby, $direction);
1004 * Actions::parse_blogsetting()
1005 * Parse skinvar blogsetting
1007 * @param string $which key of weblog settings
1010 public function parse_blogsetting($which)
1016 echo Entity::hsc($blog->getID());
1019 echo Entity::hsc($blog->getURL());
1022 echo Entity::hsc($blog->getName());
1025 echo Entity::hsc($blog->getDescription());
1028 echo Entity::hsc($blog->getShortName());
1035 * Actions::parse_callback()
1038 * @param string $eventName name of event
1039 * @param string $type type of skin
1042 public function parse_callback($eventName, $type)
1045 $manager->notify($eventName, array('type' => $type));
1050 * Actions::parse_category()
1051 * Parse skinvar category
1053 * @param string $type key of category settings
1056 public function parse_category($type = 'name')
1058 global $catid, $blog;
1059 if ( !$blog->isValidCategory($catid) )
1067 echo $blog->getCategoryName($catid);
1070 echo $blog->getCategoryDesc($catid);
1080 * Actions::parse_categorylist()
1081 * Parse categorylist
1083 * @param string $template name of template
1084 * @param string $blogname name of weblog
1087 public function parse_categorylist($template, $blogname = '')
1089 global $blog, $manager;
1091 // when no blog found
1092 if ( ($blogname == '') && (!is_object($blog)) )
1097 if ( $blogname == '' )
1099 $this->preBlogContent('categorylist',$blog);
1100 $blog->showCategoryList($template);
1101 $this->postBlogContent('categorylist',$blog);
1105 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1106 $this->preBlogContent('categorylist',$b);
1107 $b->showCategoryList($template);
1108 $this->postBlogContent('categorylist',$b);
1114 * Actions::parse_commentform()
1115 * Parse skinvar commentform
1117 * @param string $destinationurl URI for redirection
1120 public function parse_commentform($destinationurl = '')
1122 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
1124 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
1125 if ( stristr($destinationurl, 'action.php') )
1127 $args = func_get_args();
1128 $destinationurl = $args[1];
1129 ActionLog::add(WARNING,_ACTIONURL_NOTLONGER_PARAMATER);
1132 $actionurl = $CONF['ActionURL'];
1134 // if item is closed, show message and do nothing
1135 $item =& $manager->getItem($itemid,0,0);
1136 if ( $item['closed'] || !$blog->commentsEnabled() )
1138 $this->doForm('commentform-closed');
1142 if ( !$blog->isPublic() && !$member->isLoggedIn() )
1144 $this->doForm('commentform-closedtopublic');
1148 if ( !$destinationurl )
1150 // note: createLink returns an HTML encoded URL
1151 $destinationurl = Link::create_link(
1154 'itemid' => $itemid,
1155 'title' => $item['title'],
1156 'timestamp' => $item['timestamp'],
1157 'extra' => $this->linkparams
1164 $destinationurl = Entity::hsc($destinationurl);
1167 // values to prefill
1168 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
1171 $user = postVar('user');
1174 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
1177 $userid = postVar('userid');
1180 $email = cookieVar($CONF['CookiePrefix'] .'comment_email');
1183 $email = postVar('email');
1186 $body = postVar('body');
1188 $this->formdata = array(
1189 'destinationurl' => $destinationurl, // url is already HTML encoded
1190 'actionurl' => Entity::hsc($actionurl),
1191 'itemid' => $itemid,
1192 'user' => Entity::hsc($user),
1193 'userid' => Entity::hsc($userid),
1194 'email' => Entity::hsc($email),
1195 'body' => Entity::hsc($body),
1196 'membername' => $member->getDisplayName(),
1197 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
1200 if ( !$member->isLoggedIn() )
1202 $this->doForm('commentform-notloggedin');
1206 $this->doForm('commentform-loggedin');
1212 * Actions::parse_comments()
1213 * Parse skinvar comments
1214 * include comments for one item
1216 * @param string $template name of template
1219 public function parse_comments($template)
1221 global $manager, $blog, $highlight, $itemid;
1223 $template =& $manager->getTemplate($template);
1224 $item =& $manager->getItem($itemid, 0, 0);
1226 // create parser object & action handler
1227 $handler = new ItemActions($blog);
1228 $handler->setTemplate($template);
1229 $handler->setCurrentItem($item);
1231 $parser = new Parser($handler);
1233 $comments = new Comments($itemid);
1234 $comments->setItemActions($handler);
1235 // shows ALL comments
1236 $comments->showComments($template, -1, 1, $highlight);
1241 * Actions::parse_errordiv()
1247 public function parse_errordiv()
1249 global $errormessage;
1250 if ( $errormessage )
1252 echo '<div class="error">' . Entity::hsc($errormessage) . "</div>\n";
1258 * Actions::parse_errormessage()
1259 * Parse skinvar errormessage
1264 public function parse_errormessage()
1266 global $errormessage;
1272 * Actions::parse_formdata()
1275 * @param string $what key of format data
1278 public function parse_formdata($what)
1280 echo $this->formdata[$what];
1285 * Actions::parse_ifcat()
1288 * @param string $text
1291 public function parse_ifcat($text = '')
1296 $this->parse_if('category');
1301 global $catid, $blog;
1302 if ( $blog->isValidCategory($catid) )
1311 * Actions::parse_image()
1312 * Parse skinvar image
1314 * @param string $what name of tag
1317 public function parse_image($what = 'imgtag')
1321 $imagetext = Entity::hsc(requestVar('imagetext'));
1322 $imagepopup = requestVar('imagepopup');
1323 $width = intRequestVar('width');
1324 $height = intRequestVar('height');
1325 $fullurl = Entity::hsc($CONF['MediaURL'] . $imagepopup);
1344 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
1351 * Actions::parse_imagetext()
1352 * Parse skinvar imagetext
1357 public function parse_imagetext()
1359 $this->parse_image('imagetext');
1364 * Actions::parse_item()
1365 * Parse skinvar item
1366 * include one item (no comments)
1371 public function parse_item($template)
1373 global $blog, $itemid, $highlight;
1375 // need this to select default category
1376 $this->setBlogCategory($blog, '');
1377 $this->preBlogContent('item',$blog);
1378 $r = $blog->showOneitem($itemid, $template, $highlight);
1381 echo _ERROR_NOSUCHITEM;
1383 $this->postBlogContent('item',$blog);
1388 * Actions::parse_itemid()
1389 * Parse skinvar itemid
1394 public function parse_itemid()
1402 * Actions::parseitemlink()
1403 * Parse skinvar itemlink
1408 public function parse_itemlink($linktext = '')
1411 $this->itemlink($itemid, $linktext);
1416 * Actions::parse_itemtitle()
1422 public function parse_itemtitle($format = '')
1424 global $manager, $itemid;
1425 $item =& $manager->getItem($itemid,0,0);
1430 echo Entity::hen($item['title']);
1433 echo $item['title'];
1437 echo Entity::hsc(strip_tags($item['title']));
1444 * Actions::parse_loginform()
1445 * Parse skinvar loginform
1450 public function parse_loginform()
1452 global $member, $CONF;
1453 if ( !$member->isLoggedIn() )
1455 $filename = 'loginform-notloggedin';
1456 $this->formdata = array();
1460 $filename = 'loginform-loggedin';
1461 $this->formdata = array(
1462 'membername' => $member->getDisplayName(),
1465 $this->doForm($filename);
1470 * Actions::parse_member()
1471 * Parse skinvar member
1472 * (includes a member info thingie)
1474 * @param string $what which memberdata is needed
1477 public function parse_member($what)
1479 global $memberinfo, $member, $CONF;
1481 // 1. only allow the member-details-page specific variables on member pages
1482 if ( $this->skintype == 'member' )
1487 echo Entity::hsc($memberinfo->getDisplayName());
1490 echo Entity::hsc($memberinfo->getRealName());
1493 echo Entity::hsc($memberinfo->getNotes());
1496 echo Entity::hsc($memberinfo->getURL());
1499 echo Entity::hsc($memberinfo->getEmail());
1502 echo Entity::hsc($memberinfo->getID());
1507 // 2. the next bunch of options is available everywhere, as long as the user is logged in
1508 if ( $member->isLoggedIn() )
1513 echo $member->getDisplayName();
1515 case 'yourrealname':
1516 echo $member->getRealName();
1519 echo $member->getNotes();
1522 echo $member->getURL();
1525 echo $member->getEmail();
1528 echo $member->getID();
1530 case 'yourprofileurl':
1531 if ($CONF['URLMode'] == 'pathinfo')
1532 echo Link::create_member_link($member->getID());
1534 echo $CONF['IndexURL'] . Link::create_member_link($member->getID());
1542 * Link::parse_membermailform()
1543 * Parse skinvar membermailform
1545 * @param integer $rows the height for textarea
1546 * @param integer $cols the width for textarea
1547 * @param string $desturl URI to redirect
1550 public function parse_membermailform($rows = 10, $cols = 40, $desturl = '')
1552 global $member, $CONF, $memberid;
1554 if ( $desturl == '' )
1556 if ( $CONF['URLMode'] == 'pathinfo' )
1558 $desturl = Link::create_member_link($memberid);
1562 $desturl = $CONF['IndexURL'] . Link::create_member_link($memberid);
1566 $message = postVar('message');
1567 $frommail = postVar('frommail');
1569 $this->formdata = array(
1570 'url' => Entity::hsc($desturl),
1571 'actionurl' => Entity::hsc($CONF['ActionURL']),
1572 'memberid' => $memberid,
1575 'message' => Entity::hsc($message),
1576 'frommail' => Entity::hsc($frommail)
1579 if ( $member->isLoggedIn() )
1581 $this->doForm('membermailform-loggedin');
1583 else if ( $CONF['NonmemberMail'] )
1585 $this->doForm('membermailform-notloggedin');
1589 $this->doForm('membermailform-disallowed');
1595 * Actions::parse_nextarchive()
1596 * Parse skinvar nextarchive
1601 public function parse_nextarchive()
1603 global $archivenext;
1609 * Parse skinvar nextitem
1610 * (include itemid of next item)
1615 public function parse_nextitem()
1618 if ( isset($itemidnext) )
1620 echo (int)$itemidnext;
1626 * Actions::parse_nextitemtitle()
1627 * Parse skinvar nextitemtitle
1628 * (include itemtitle of next item)
1630 * @param string $format format of text
1633 public function parse_nextitemtitle($format = '')
1635 global $itemtitlenext;
1640 echo Entity::hen($itemtitlenext);
1643 echo $itemtitlenext;
1647 echo Entity::hsc($itemtitlenext);
1654 * Actions::parse_nextlink()
1655 * Parse skinvar nextlink
1657 * @param string $linktext text for content of anchor element
1658 * @param integer $amount the amount of items in a display
1659 * @param integer $recount increment from this value
1662 public function parse_nextlink($linktext = '', $amount = 10, $recount = '')
1664 global $itemidnext, $archivenext, $startpos;
1665 if ( $this->skintype == 'item' )
1667 $this->itemlink($itemidnext, $linktext);
1669 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
1671 $this->searchlink($amount, $startpos, 'next', $linktext, $recount);
1675 $this->archivelink($archivenext, $linktext);
1681 * Actions::parse_nucleusbutton()
1682 * Parse skinvar nucleusbutton
1684 * @param string $imgurl URL for image
1685 * @param integer $imgwidth width of image
1686 * @param integer $imgheidht height of image
1688 public function parse_nucleusbutton($imgurl = '', $imgwidth = '85', $imgheight = '31')
1691 if ( $imgurl == '' )
1693 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
1695 else if ( Parser::getProperty('IncludeMode') == 'skindir' )
1697 // when skindit IncludeMode is used: start from skindir
1698 $imgurl = $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $imgurl;
1701 $this->formdata = array(
1702 'imgurl' => $imgurl,
1703 'imgwidth' => $imgwidth,
1704 'imgheight' => $imgheight,
1706 $this->doForm('nucleusbutton');
1711 * Actions::parse_otherarchive()
1712 * Parse skinvar otherarchive
1714 * @param string $blogname name of weblog
1715 * @param string $template name of template
1716 * @param string $category name of category
1719 public function parse_otherarchive($blogname, $template, $category = '')
1721 global $archive, $manager;
1722 sscanf($archive,'%d-%d-%d',$y,$m,$d);
1723 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1724 $this->setBlogCategory($b, $category);
1725 $this->preBlogContent('otherachive',$b);
1726 $b->showArchive($template, $y, $m, $d);
1727 $this->postBlogContent('otherachive',$b);
1732 * Actions::parse_otherarchivedaylist()
1733 * Parse skinvar otherarchivedaylist
1735 * @param string $blogname name of weblog
1736 * @param string $template name of template
1737 * @param string $category name of category
1738 * @param integer $limit the amount of items in a display
1741 public function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0)
1744 if ( $category == 'all')
1748 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1749 $this->setBlogCategory($b, $category);
1750 $this->preBlogContent('otherarchivelist',$b);
1751 $b->showArchiveList($template, 'day', $limit);
1752 $this->postBlogContent('otherarchivelist',$b);
1757 * Actions::parse_otherarchivelist()
1758 * Parse skinvar otherarchivelist
1760 * @param string $blogname name of weblog
1761 * @param string $template name of template
1762 * @param string $category name of category
1763 * @param integer $limit the amount of items in a display
1766 public function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0)
1769 if ( $category == 'all' )
1773 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1774 $this->setBlogCategory($b, $category);
1775 $this->preBlogContent('otherarchivelist',$b);
1776 $b->showArchiveList($template, 'month', $limit);
1777 $this->postBlogContent('otherarchivelist',$b);
1782 * Actions::parse_otherarchiveyearlist()
1783 * Parse skinvar otherarchiveyearlist
1785 * @param string $blogname name of weblog
1786 * @param string $template name of template
1787 * @param string $category name of category
1788 * @limit integer $limit the amount of items in a display
1790 public function parse_otherarchiveyearlist($blogname, $template, $category = 'all', $limit = 0)
1793 if ( $category == 'all' )
1797 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1798 $this->setBlogCategory($b, $category);
1799 $this->preBlogContent('otherarchivelist',$b);
1800 $b->showArchiveList($template, 'year', $limit);
1801 $this->postBlogContent('otherarchivelist',$b);
1806 * Actions::parse_otherblog()
1807 * Parse skinvar otherblog
1809 * @param string $blogname name of weblog
1810 * @param string $template name of template
1811 * @param mixed $amount the amount of items, in case it includes the beginning
1812 * @param string $category name of category
1815 public function parse_otherblog($blogname, $template, $amount = 10, $category = '')
1819 list($limit, $offset) = sscanf($amount, '%d(%d)');
1821 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1822 $this->setBlogCategory($b, $category);
1823 $this->preBlogContent('otherblog',$b);
1824 $this->amountfound = $b->readLog($template, $limit, $offset);
1825 $this->postBlogContent('otherblog',$b);
1830 * Actions::parse_othersearchresults()
1831 * Parse skinvar othersearchresults
1833 * @param string $blogname name of weblog
1834 * @param string $template name of template
1835 * @param integer $maxresults the amount of results
1838 public function parse_othersearchresults($blogname, $template, $maxresults = 50)
1840 global $query, $amount, $manager, $startpos;
1841 $b =& $manager->getBlog(getBlogIDFromName($blogname));
1842 // need this to select default category
1843 $this->setBlogCategory($b, '');
1844 $this->preBlogContent('othersearchresults',$b);
1845 $b->search($query, $template, $amount, $maxresults, $startpos);
1846 $this->postBlogContent('othersearchresults',$b);
1851 * Actions::parse_plugin()
1852 * Executes a plugin skinvar
1853 * extra parameters can be added
1855 * @param string $pluginName name of plugin (without the NP_)
1858 public function parse_plugin($pluginName)
1862 $plugin =& $manager->getPlugin('NP_' . $pluginName);
1869 $params = func_get_args();
1871 // remove plugin name
1872 array_shift($params);
1874 // add skin type on front
1875 array_unshift($params, $this->skintype);
1877 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
1882 * Actions::parse_prevarchive()
1883 * Parse skinvar prevarchive
1888 public function parse_prevarchive()
1890 global $archiveprev;
1895 * Actions::parse_preview()
1896 * Parse skinvar preview
1898 * @param string $template name of tempalte
1901 public function parse_preview($template)
1903 global $blog, $CONF, $manager;
1905 $template =& $manager->getTemplate($template);
1907 $row['body'] = '<span id="prevbody"></span>';
1908 $row['title'] = '<span id="prevtitle"></span>';
1909 $row['more'] = '<span id="prevmore"></span>';
1910 $row['itemlink'] = '';
1911 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
1913 echo Template::fill($template['ITEM_HEADER'],$row);
1914 echo Template::fill($template['ITEM'],$row);
1915 echo Template::fill($template['ITEM_FOOTER'],$row);
1920 * Actions::parse_previtem()
1921 * Parse skinvar previtem
1922 * (include itemid of prev item)
1927 public function parse_previtem()
1930 if ( isset($itemidprev) )
1932 echo (integer) $itemidprev;
1938 * Actions::parse_previtemtitle()
1939 * Parse skinvar previtemtitle
1940 * (include itemtitle of prev item)
1942 * @param String $format string format
1943 * @return String formatted string
1945 public function parse_previtemtitle($format = '')
1947 global $itemtitleprev;
1952 echo Entity::hen($itemtitleprev);
1955 echo $itemtitleprev;
1959 echo Entity::hsc($itemtitleprev);
1966 * Actions::parse_prevlink()
1967 * Parse skinvar prevlink
1969 * @param string $linktext text as a content of anchor element
1970 * @param integer the amount of links
1973 public function parse_prevlink($linktext = '', $amount = 10)
1975 global $itemidprev, $archiveprev, $startpos;
1977 if ( $this->skintype == 'item' )
1979 $this->itemlink($itemidprev, $linktext);
1981 else if ( $this->skintype == 'search' || $this->skintype == 'index' )
1983 $this->searchlink($amount, $startpos, 'prev', $linktext);
1987 $this->archivelink($archiveprev, $linktext);
1993 * Actions::parse_query()
1994 * Parse skinvar query
1995 * (includes the search query)
2000 public function parse_query()
2003 echo Entity::hsc($query);
2008 * Actions::parse_referer()
2009 * Parse skinvar referer
2014 public function parse_referer()
2016 echo Entity::hsc(serverVar('HTTP_REFERER'));
2021 * Actions::parse_searchform()
2022 * Parse skinvar searchform
2024 * @param string $blogname name of weblog
2027 public function parse_searchform($blogname = '')
2029 global $CONF, $manager, $maxresults;
2032 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
2038 // use default blog when no blog is selected
2039 $this->formdata = array(
2040 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
2041 'query' => Entity::hsc(getVar('query')),
2043 $this->doForm('searchform');
2048 * Actions::parse_searchresults()
2049 * Parse skinvar searchresults
2051 * @param string $template name of tempalte
2052 * @param integer $maxresults searched items in a display
2055 public function parse_searchresults($template, $maxresults = 50 )
2057 global $blog, $query, $amount, $startpos;
2059 $this->setBlogCategory($blog, ''); // need this to select default category
2060 $this->preBlogContent('searchresults',$blog);
2061 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
2062 $this->postBlogContent('searchresults',$blog);
2067 * Actions::parse_self()
2068 * Parse skinvar self
2073 public function parse_self()
2081 * Actions::parse_sitevar()
2082 * Parse skinvar sitevar
2083 * (include a sitevar)
2085 * @param string $which
2088 public function parse_sitevar($which)
2094 echo $CONF['IndexURL'];
2097 echo $CONF['SiteName'];
2100 echo $CONF['AdminEmail'];
2103 echo $CONF['AdminURL'];
2109 * Actions::parse_skinname()
2115 public function parse_skinname()
2117 echo $this->parser->skin->getName();
2122 * Actions::parse_skintype()
2123 * Parse skintype (experimental)
2128 public function parse_skintype()
2130 echo $this->skintype;
2135 * Actions::parse_ticket()
2141 public function parse_ticket()
2144 $manager->addTicketHidden();
2149 * Actions::parse_todaylink()
2150 * Parse skinvar todaylink
2151 * A link to the today page (depending on selected blog, etc...)
2153 * @param string $linktext text for link
2156 public function parse_todaylink($linktext = '')
2158 global $blog, $CONF;
2161 echo $this->link(Link::create_blogid_link($blog->getID(),$this->linkparams), $linktext);
2165 echo $this->link($CONF['SiteUrl'], $linktext);
2172 * When commentform is not used, to include a hidden field with itemid
2177 public function parse_vars()
2180 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />' . "\n";
2185 * Actions::parse_version()
2186 * Parse skinvar version
2187 * (include nucleus versionnumber)
2192 public function parse_version()
2195 echo 'Nucleus CMS ' . $nucleus['version'];
2200 * Actions::parse_sticky()
2201 * Parse skinvar sticky
2203 * @param integer $itemnumber id of item
2204 * @param string $template name of template
2207 public function parse_sticky($itemnumber = 0, $template = '')
2211 $itemnumber = intval($itemnumber);
2212 $itemarray = array($itemnumber);
2214 $b =& $manager->getBlog(getBlogIDFromItemID($itemnumber));
2215 $this->preBlogContent('sticky',$b);
2216 $this->amountfound = $b->readLogFromList($itemarray, $template);
2217 $this->postBlogContent('sticky',$b);