4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2012 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
14 * A class to parses plugin calls inside items
\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: BODYACTIONS.php 1626 2012-01-09 15:46:54Z sakamocchi $
\r
21 class BodyActions extends BaseActions
\r
29 * Constructor of the BODYACTIONS
\r
31 function __construct() {
\r
32 $this->BaseActions();
\r
36 * Set the current item
\r
39 * reference to the current item
\r
41 function setCurrentItem(&$item) {
\r
42 $this->currentItem =& $item;
\r
43 global $currentitemid;
\r
44 $currentitemid = $this->currentItem->itemid;
\r
48 * Set the current template
\r
51 * Template to be used
\r
53 function setTemplate($template) {
\r
54 $this->template =& $template;
\r
58 * Get the defined actions in an item
\r
60 function getDefinedActions() {
\r
61 return array('image', 'media', 'popup', 'plugin', 'if', 'else', 'endif', 'elseif', 'ifnot', 'elseifnot');
\r
65 * Parse a plugin var
\r
66 * Called if <%plugin(...)%> in an item appears
\r
68 * Calls the doItemVar function in the plugin
\r
70 function parse_plugin($pluginName) {
\r
73 // should be already tested from the parser (PARSER.php)
\r
74 // only continue when the plugin is really installed
\r
75 /*if (!$manager->pluginInstalled('NP_' . $pluginName)) {
\r
79 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
80 if (!$plugin) return;
\r
83 $params = func_get_args();
\r
85 // remove plugin name
\r
86 array_shift($params);
\r
88 // add item reference (array_unshift didn't work)
\r
89 $params = array_merge(array(&$this->currentItem),$params);
\r
91 call_user_func_array(array(&$plugin,'doItemVar'), $params);
\r
96 * Called if <%image(...)%> in an item appears
\r
98 function parse_image() {
\r
99 // image/popup calls have arguments separated by |
\r
100 $args = func_get_args();
\r
101 $args = i18n::explode('|',implode($args,', '));
\r
102 call_user_func_array(array(&$this,'createImageCode'),$args);
\r
106 * Creates the code for an image
\r
108 function createImageCode($filename, $width, $height, $text = '') {
\r
111 // select private collection when no collection given
\r
112 if (!strstr($filename,'/')) {
\r
113 $filename = $this->currentItem->authorid . '/' . $filename;
\r
116 $windowwidth = $width;
\r
117 $windowheight = $height;
\r
119 $vars['link'] = Entity::hsc($CONF['MediaURL']. $filename);
\r
120 $vars['text'] = Entity::hsc($text);
\r
121 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" title="' . $vars['text'] . '" />';
\r
122 $vars['width'] = $width;
\r
123 $vars['height'] = $height;
\r
124 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
\r
127 echo Template::fill($this->template['IMAGE_CODE'],$vars);;
\r
133 * Called if <%media(...)%> in an item appears
\r
135 function parse_media() {
\r
136 // image/popup calls have arguments separated by |
\r
137 $args = func_get_args();
\r
138 $args = i18n::explode('|',implode($args,', '));
\r
139 call_user_func_array(array(&$this,'createMediaCode'),$args);
\r
143 * Creates the code for a media
\r
145 function createMediaCode($filename, $text = '') {
\r
148 // select private collection when no collection given
\r
149 if (!strstr($filename,'/')) {
\r
150 $filename = $this->currentItem->authorid . '/' . $filename;
\r
153 $vars['link'] = Entity::hsc($CONF['MediaURL'] . $filename);
\r
154 $vars['text'] = Entity::hsc($text);
\r
155 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
\r
157 echo Template::fill($this->template['MEDIA_CODE'],$vars);;
\r
162 * Called if <%popup(...)%> in an item appears
\r
164 function parse_popup() {
\r
165 // image/popup calls have arguments separated by |
\r
166 $args = func_get_args();
\r
167 $args = i18n::explode('|',implode($args,', '));
\r
168 call_user_func_array(array(&$this,'createPopupCode'),$args);
\r
172 * Creates the code for a popup
\r
174 function createPopupCode($filename, $width, $height, $text = '') {
\r
177 // select private collection when no collection given
\r
178 if (!strstr($filename,'/')) {
\r
179 $filename = $this->currentItem->authorid . '/' . $filename;
\r
182 $windowwidth = $width;
\r
183 $windowheight = $height;
\r
185 $vars['rawpopuplink'] = $CONF['Self'] . "?imagepopup=" . Entity::hsc($filename) . "&width=$width&height=$height&imagetext=" . urlencode(Entity::hsc($text));
\r
186 $vars['popupcode'] = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
\r
187 $vars['popuptext'] = Entity::hsc($text);
\r
188 $vars['popuplink'] = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';
\r
189 $vars['width'] = $width;
\r
190 $vars['height'] = $height;
\r
191 $vars['text'] = $text;
\r
192 $vars['link'] = Entity::hsc($CONF['MediaURL'] . $filename);
\r
193 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['popuptext'] . '</a>';
\r
195 echo Template::fill($this->template['POPUP_CODE'],$vars);
\r
198 // function to enable if-else-elseif-elseifnot-ifnot-endif to item template fields
\r
201 * Checks conditions for if statements
\r
203 * @param string $field type of <%if%>
\r
204 * @param string $name property of field
\r
205 * @param string $value value of property
\r
207 function checkCondition($field, $name='', $value = '') {
\r
208 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
213 $condition = ($blog && $this->_ifCategory($name,$value));
\r
215 case 'itemcategory':
\r
216 $condition = ($this->_ifItemCategory($name,$value));
\r
218 case 'blogsetting':
\r
219 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
221 case 'itemblogsetting':
\r
222 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
\r
223 $condition = ($b && ($b->getSetting($name) == $value));
\r
226 $condition = $member->isLoggedIn();
\r
229 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
\r
232 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
\r
235 $condition = ($this->_ifAuthor($name,$value));
\r
237 /* case 'nextitem':
\r
238 $condition = ($itemidnext != '');
\r
241 $condition = ($itemidprev != '');
\r
243 case 'archiveprevexists':
\r
244 $condition = ($archiveprevexists == true);
\r
246 case 'archivenextexists':
\r
247 $condition = ($archivenextexists == true);
\r
250 $condition = ($name == $this->skintype);
\r
253 $condition = $this->_ifHasPlugin($name, $value);
\r
256 $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
\r
263 * Different checks for a category
\r
265 function _ifCategory($name = '', $value='') {
\r
266 global $blog, $catid;
\r
268 // when no parameter is defined, just check if a category is selected
\r
269 if (($name != 'catname' && $name != 'catid') || ($value == ''))
\r
270 return $blog->isValidCategory($catid);
\r
272 // check category name
\r
273 if ($name == 'catname') {
\r
274 $value = $blog->getCategoryIdFromName($value);
\r
275 if ($value == $catid)
\r
276 return $blog->isValidCategory($catid);
\r
279 // check category id
\r
280 if (($name == 'catid') && ($value == $catid))
\r
281 return $blog->isValidCategory($catid);
\r
288 * Different checks for an author
\r
290 function _ifAuthor($name = '', $value='') {
\r
291 global $member, $manager;
\r
293 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
\r
295 // when no parameter is defined, just check if author is current visitor
\r
296 if (($name != 'isadmin' && $name != 'name') || ($name == 'name' && $value == '')) {
\r
297 return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem->authorid));
\r
300 // check author name
\r
301 if ($name == 'name') {
\r
302 $value = strtolower($value);
\r
303 if ($value == strtolower($this->currentItem->author))
\r
307 // check if author is admin
\r
308 if (($name == 'isadmin')) {
\r
309 $aid = intval($this->currentItem->authorid);
\r
310 $blogid = intval($b->getID());
\r
311 $amember =& $manager->getMember($aid);
\r
312 if ($amember->isAdmin())
\r
315 return $amember->isBlogAdmin($blogid);
\r
322 * Different checks for a category
\r
324 function _ifItemCategory($name = '', $value='') {
\r
325 global $catid, $manager;
\r
327 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
\r
329 // when no parameter is defined, just check if a category is selected
\r
330 if (($name != 'catname' && $name != 'catid') || ($value == ''))
\r
331 return $b->isValidCategory($catid);
\r
333 $icatid = $this->currentItem->catid;
\r
334 //$icategory = $this->currentItem->category;
\r
336 // check category name
\r
337 if ($name == 'catname') {
\r
338 $value = $b->getCategoryIdFromName($value);
\r
339 if ($value == $icatid)
\r
340 return $b->isValidCategory($icatid);
\r
343 // check category id
\r
344 if (($name == 'catid') && ($value == $icatid))
\r
345 return $b->isValidCategory($icatid);
\r
352 * Checks if a member is on the team of a blog and return his rights
\r
354 function _ifOnTeam($blogName = '') {
\r
355 global $blog, $member, $manager;
\r
357 // when no blog found
\r
358 if (($blogName == '') && (!is_object($blog)))
\r
361 // explicit blog selection
\r
362 if ($blogName != '')
\r
363 $blogid = getBlogIDFromName($blogName);
\r
365 if (($blogName == '') || !$manager->existsBlogID($blogid))
\r
366 // use current blog
\r
367 $blogid = $blog->getID();
\r
369 return $member->teamRights($blogid);
\r
373 * Checks if a member is admin of a blog
\r
375 function _ifAdmin($blogName = '') {
\r
376 global $blog, $member, $manager;
\r
378 // when no blog found
\r
379 if (($blogName == '') && (!is_object($blog)))
\r
382 // explicit blog selection
\r
383 if ($blogName != '')
\r
384 $blogid = getBlogIDFromName($blogName);
\r
386 if (($blogName == '') || !$manager->existsBlogID($blogid))
\r
387 // use current blog
\r
388 $blogid = $blog->getID();
\r
390 return $member->isBlogAdmin($blogid);
\r
395 * hasplugin,PlugName
\r
396 * -> checks if plugin exists
\r
397 * hasplugin,PlugName,OptionName
\r
398 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
399 * hasplugin,PlugName,OptionName=value
\r
400 * -> checks if the option OptionName from plugin PlugName is set to value
\r
402 function _ifHasPlugin($name, $value) {
\r
404 $condition = false;
\r
405 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
406 if ($manager->pluginInstalled('NP_'.$name)) {
\r
407 $plugin =& $manager->getPlugin('NP_' . $name);
\r
408 if ($plugin != NULL) {
\r
409 if ($value == "") {
\r
412 list($name2, $value2) = i18n::explode('=', $value, 2);
\r
413 if ($value2 == "" && $plugin->getOption($name2) != 'no') {
\r
415 } else if ($plugin->getOption($name2) == $value2) {
\r
425 * Checks if a plugin exists and call its doIf function
\r
427 function _ifPlugin($name, $key = '', $value = '') {
\r
430 $plugin =& $manager->getPlugin('NP_' . $name);
\r
431 if (!$plugin) return;
\r
433 $params = func_get_args();
\r
434 array_shift($params);
\r
436 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r