4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2009 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-2009 The Nucleus Group
\r
18 * @version $Id: BODYACTIONS.php 1626 2012-01-09 15:46:54Z sakamocchi $
\r
21 class BODYACTIONS extends BaseActions {
\r
28 * Constructor of the BODYACTIONS
\r
30 function BODYACTIONS () {
\r
31 $this->BaseActions();
\r
35 * Set the current item
\r
38 * reference to the current item
\r
40 function setCurrentItem(&$item) {
\r
41 $this->currentItem =& $item;
\r
42 global $currentitemid;
\r
43 $currentitemid = $this->currentItem->itemid;
\r
47 * Set the current template
\r
50 * Template to be used
\r
52 function setTemplate($template) {
\r
53 $this->template =& $template;
\r
57 * Get the defined actions in an item
\r
59 function getDefinedActions() {
\r
60 return array('image', 'media', 'popup', 'plugin', 'if', 'else', 'endif', 'elseif', 'ifnot', 'elseifnot');
\r
64 * Parse a plugin var
\r
65 * Called if <%plugin(...)%> in an item appears
\r
67 * Calls the doItemVar function in the plugin
\r
69 function parse_plugin($pluginName) {
\r
72 // should be already tested from the parser (PARSER.php)
\r
73 // only continue when the plugin is really installed
\r
74 /*if (!$manager->pluginInstalled('NP_' . $pluginName)) {
\r
78 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
79 if (!$plugin) return;
\r
82 $params = func_get_args();
\r
84 // remove plugin name
\r
85 array_shift($params);
\r
87 // add item reference (array_unshift didn't work)
\r
88 $params = array_merge(array(&$this->currentItem),$params);
\r
90 call_user_func_array(array(&$plugin,'doItemVar'), $params);
\r
95 * Called if <%image(...)%> in an item appears
\r
97 function parse_image() {
\r
98 // image/popup calls have arguments separated by |
\r
99 $args = func_get_args();
\r
100 $args = i18n::explode('|',implode($args,', '));
\r
101 call_user_func_array(array(&$this,'createImageCode'),$args);
\r
105 * Creates the code for an image
\r
107 function createImageCode($filename, $width, $height, $text = '') {
\r
110 // select private collection when no collection given
\r
111 if (!strstr($filename,'/')) {
\r
112 $filename = $this->currentItem->authorid . '/' . $filename;
\r
115 $windowwidth = $width;
\r
116 $windowheight = $height;
\r
118 $vars['link'] = ENTITY::hsc($CONF['MediaURL']. $filename);
\r
119 $vars['text'] = ENTITY::hsc($text);
\r
120 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" title="' . $vars['text'] . '" />';
\r
121 $vars['width'] = $width;
\r
122 $vars['height'] = $height;
\r
123 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
\r
126 echo TEMPLATE::fill($this->template['IMAGE_CODE'],$vars);;
\r
132 * Called if <%media(...)%> in an item appears
\r
134 function parse_media() {
\r
135 // image/popup calls have arguments separated by |
\r
136 $args = func_get_args();
\r
137 $args = i18n::explode('|',implode($args,', '));
\r
138 call_user_func_array(array(&$this,'createMediaCode'),$args);
\r
142 * Creates the code for a media
\r
144 function createMediaCode($filename, $text = '') {
\r
147 // select private collection when no collection given
\r
148 if (!strstr($filename,'/')) {
\r
149 $filename = $this->currentItem->authorid . '/' . $filename;
\r
152 $vars['link'] = ENTITY::hsc($CONF['MediaURL'] . $filename);
\r
153 $vars['text'] = ENTITY::hsc($text);
\r
154 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
\r
156 echo TEMPLATE::fill($this->template['MEDIA_CODE'],$vars);;
\r
161 * Called if <%popup(...)%> in an item appears
\r
163 function parse_popup() {
\r
164 // image/popup calls have arguments separated by |
\r
165 $args = func_get_args();
\r
166 $args = i18n::explode('|',implode($args,', '));
\r
167 call_user_func_array(array(&$this,'createPopupCode'),$args);
\r
171 * Creates the code for a popup
\r
173 function createPopupCode($filename, $width, $height, $text = '') {
\r
176 // select private collection when no collection given
\r
177 if (!strstr($filename,'/')) {
\r
178 $filename = $this->currentItem->authorid . '/' . $filename;
\r
181 $windowwidth = $width;
\r
182 $windowheight = $height;
\r
184 $vars['rawpopuplink'] = $CONF['Self'] . "?imagepopup=" . ENTITY::hsc($filename) . "&width=$width&height=$height&imagetext=" . urlencode(ENTITY::hsc($text));
\r
185 $vars['popupcode'] = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
\r
186 $vars['popuptext'] = ENTITY::hsc($text);
\r
187 $vars['popuplink'] = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';
\r
188 $vars['width'] = $width;
\r
189 $vars['height'] = $height;
\r
190 $vars['text'] = $text;
\r
191 $vars['link'] = ENTITY::hsc($CONF['MediaURL'] . $filename);
\r
192 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['popuptext'] . '</a>';
\r
194 echo TEMPLATE::fill($this->template['POPUP_CODE'],$vars);
\r
197 // function to enable if-else-elseif-elseifnot-ifnot-endif to item template fields
\r
200 * Checks conditions for if statements
\r
202 * @param string $field type of <%if%>
\r
203 * @param string $name property of field
\r
204 * @param string $value value of property
\r
206 function checkCondition($field, $name='', $value = '') {
\r
207 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
212 $condition = ($blog && $this->_ifCategory($name,$value));
\r
214 case 'itemcategory':
\r
215 $condition = ($this->_ifItemCategory($name,$value));
\r
217 case 'blogsetting':
\r
218 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
220 case 'itemblogsetting':
\r
221 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
\r
222 $condition = ($b && ($b->getSetting($name) == $value));
\r
225 $condition = $member->isLoggedIn();
\r
228 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
\r
231 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
\r
234 $condition = ($this->_ifAuthor($name,$value));
\r
236 /* case 'nextitem':
\r
237 $condition = ($itemidnext != '');
\r
240 $condition = ($itemidprev != '');
\r
242 case 'archiveprevexists':
\r
243 $condition = ($archiveprevexists == true);
\r
245 case 'archivenextexists':
\r
246 $condition = ($archivenextexists == true);
\r
249 $condition = ($name == $this->skintype);
\r
252 $condition = $this->_ifHasPlugin($name, $value);
\r
255 $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
\r
262 * Different checks for a category
\r
264 function _ifCategory($name = '', $value='') {
\r
265 global $blog, $catid;
\r
267 // when no parameter is defined, just check if a category is selected
\r
268 if (($name != 'catname' && $name != 'catid') || ($value == ''))
\r
269 return $blog->isValidCategory($catid);
\r
271 // check category name
\r
272 if ($name == 'catname') {
\r
273 $value = $blog->getCategoryIdFromName($value);
\r
274 if ($value == $catid)
\r
275 return $blog->isValidCategory($catid);
\r
278 // check category id
\r
279 if (($name == 'catid') && ($value == $catid))
\r
280 return $blog->isValidCategory($catid);
\r
287 * Different checks for an author
\r
289 function _ifAuthor($name = '', $value='') {
\r
290 global $member, $manager;
\r
292 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
\r
294 // when no parameter is defined, just check if author is current visitor
\r
295 if (($name != 'isadmin' && $name != 'name') || ($name == 'name' && $value == '')) {
\r
296 return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem->authorid));
\r
299 // check author name
\r
300 if ($name == 'name') {
\r
301 $value = strtolower($value);
\r
302 if ($value == strtolower($this->currentItem->author))
\r
306 // check if author is admin
\r
307 if (($name == 'isadmin')) {
\r
308 $aid = intval($this->currentItem->authorid);
\r
309 $blogid = intval($b->getID());
\r
310 $amember =& $manager->getMember($aid);
\r
311 if ($amember->isAdmin())
\r
314 return $amember->isBlogAdmin($blogid);
\r
321 * Different checks for a category
\r
323 function _ifItemCategory($name = '', $value='') {
\r
324 global $catid, $manager;
\r
326 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
\r
328 // when no parameter is defined, just check if a category is selected
\r
329 if (($name != 'catname' && $name != 'catid') || ($value == ''))
\r
330 return $b->isValidCategory($catid);
\r
332 $icatid = $this->currentItem->catid;
\r
333 //$icategory = $this->currentItem->category;
\r
335 // check category name
\r
336 if ($name == 'catname') {
\r
337 $value = $b->getCategoryIdFromName($value);
\r
338 if ($value == $icatid)
\r
339 return $b->isValidCategory($icatid);
\r
342 // check category id
\r
343 if (($name == 'catid') && ($value == $icatid))
\r
344 return $b->isValidCategory($icatid);
\r
351 * Checks if a member is on the team of a blog and return his rights
\r
353 function _ifOnTeam($blogName = '') {
\r
354 global $blog, $member, $manager;
\r
356 // when no blog found
\r
357 if (($blogName == '') && (!is_object($blog)))
\r
360 // explicit blog selection
\r
361 if ($blogName != '')
\r
362 $blogid = getBlogIDFromName($blogName);
\r
364 if (($blogName == '') || !$manager->existsBlogID($blogid))
\r
365 // use current blog
\r
366 $blogid = $blog->getID();
\r
368 return $member->teamRights($blogid);
\r
372 * Checks if a member is admin of a blog
\r
374 function _ifAdmin($blogName = '') {
\r
375 global $blog, $member, $manager;
\r
377 // when no blog found
\r
378 if (($blogName == '') && (!is_object($blog)))
\r
381 // explicit blog selection
\r
382 if ($blogName != '')
\r
383 $blogid = getBlogIDFromName($blogName);
\r
385 if (($blogName == '') || !$manager->existsBlogID($blogid))
\r
386 // use current blog
\r
387 $blogid = $blog->getID();
\r
389 return $member->isBlogAdmin($blogid);
\r
394 * hasplugin,PlugName
\r
395 * -> checks if plugin exists
\r
396 * hasplugin,PlugName,OptionName
\r
397 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
398 * hasplugin,PlugName,OptionName=value
\r
399 * -> checks if the option OptionName from plugin PlugName is set to value
\r
401 function _ifHasPlugin($name, $value) {
\r
403 $condition = false;
\r
404 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
405 if ($manager->pluginInstalled('NP_'.$name)) {
\r
406 $plugin =& $manager->getPlugin('NP_' . $name);
\r
407 if ($plugin != NULL) {
\r
408 if ($value == "") {
\r
411 list($name2, $value2) = i18n::explode('=', $value, 2);
\r
412 if ($value2 == "" && $plugin->getOption($name2) != 'no') {
\r
414 } else if ($plugin->getOption($name2) == $value2) {
\r
424 * Checks if a plugin exists and call its doIf function
\r
426 function _ifPlugin($name, $key = '', $value = '') {
\r
429 $plugin =& $manager->getPlugin('NP_' . $name);
\r
430 if (!$plugin) return;
\r
432 $params = func_get_args();
\r
433 array_shift($params);
\r
435 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r