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 1757 2012-04-15 09:02:32Z sakamocchi $
\r
21 class BodyActions extends BaseActions
\r
23 private $currentItem;
\r
26 static private $defined_actions = array(
\r
34 * BodyActions::__construct()
\r
35 * Constructor of the BODYACTIONS
\r
40 public function __construct()
\r
42 parent::__construct();
47 * BodyActions::getAvailableActions()
\r
48 * Get the defined actions in an item
\r
51 * @return array self::$defined_actions
\r
53 public function getAvailableActions()
\r
55 return array_merge(self::$defined_actions, parent::getAvailableActions());
\r
59 * BodyActions::setCurrentItem()
\r
60 * Set the current item
\r
62 * @param object &$item reference to the current item
\r
65 public function setCurrentItem(&$item)
\r
67 global $currentitemid;
\r
68 $this->currentItem =& $item;
\r
69 $currentitemid = $this->currentItem['itemid'];
\r
74 * BodyActions::setTemplate()
\r
75 * Set the current template
\r
77 * @param string $template Template to be used
\r
80 public function setTemplate($template)
\r
82 $this->template =& $template;
\r
87 * BodyActions::parse_plugin()
\r
88 * Parse a plugin var
\r
89 * Called if <%plugin(...)%> in an item appears
\r
91 * Calls the doItemVar function in the plugin
\r
93 public function parse_plugin($pluginName)
\r
97 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
104 $params = func_get_args();
\r
106 // remove plugin name
\r
107 array_shift($params);
\r
109 // add item reference (array_unshift didn't work)
\r
110 $params = array_merge(array(&$this->currentItem), $params);
\r
112 call_user_func_array(array(&$plugin, 'doItemVar'), $params);
\r
117 * BodyActions::parse_image()
\r
119 * Called if <%image(...)%> in an item appears
\r
122 * @return parsed image tag
\r
124 public function parse_image()
\r
126 // image/popup calls have arguments separated by |
\r
127 $args = func_get_args();
\r
128 $args = preg_split('#\|#', implode($args, ', '));
\r
129 echo call_user_func_array(array(&$this, 'createImageCode'), $args);
\r
133 * BodyActions::createImageCode()
\r
134 * Creates the code for an image
\r
136 * @param string $filename name of file from tag
\r
137 * @param integer $width width of file from tag
\r
138 * @param integer $height height of file from tag
\r
139 * @return string image element with anchor element
\r
141 public function createImageCode($filename, $width, $height, $text = '')
\r
145 // select private collection when no collection given
\r
146 if ( i18n::strpos($filename, '/') === FALSE )
\r
148 $filename = $this->currentItem['authorid'] . '/' . $filename;
\r
151 $windowwidth = $width;
\r
152 $windowheight = $height;
\r
154 $vars['link'] = Entity::hsc($CONF['MediaURL']. $filename);
\r
155 $vars['text'] = Entity::hsc($text);
\r
156 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" title="' . $vars['text'] . '" />';
\r
157 $vars['width'] = $width;
\r
158 $vars['height'] = $height;
\r
159 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
\r
161 return Template::fill($this->template['IMAGE_CODE'], $vars);
165 * BodyActions::parse_media()
\r
167 * Called if <%media(...)%> in an item appears
\r
170 * @param parsed media tag
\r
172 public function parse_media()
\r
174 // image/popup calls have arguments separated by |
\r
175 $args = func_get_args();
\r
176 $args = preg_split('#\|#', implode($args, ', '));
\r
177 echo call_user_func_array(array(&$this, 'createMediaCode'), $args);
\r
181 * BodyActions::createMediaCode()
\r
182 * Creates the code for a media
\r
184 * @param string $filename name of file from tag
\r
185 * @param string $text alternative text from tag
\r
186 * @return string text element with anchor element
\r
188 public function createMediaCode($filename, $text = '')
\r
192 // select private collection when no collection given
\r
193 if ( i18n::strpos($filename, '/') === FALSE )
\r
195 $filename = $this->currentItem['authorid'] . '/' . $filename;
\r
198 $vars['link'] = Entity::hsc($CONF['MediaURL'] . $filename);
\r
199 $vars['text'] = Entity::hsc($text);
\r
200 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
\r
202 return Template::fill($this->template['MEDIA_CODE'], $vars);;
\r
206 * BodyActions::parse_popup()
\r
208 * Called if <%popup(...)%> in an item appears
\r
211 * @return string parsed popup tag
\r
213 public function parse_popup()
\r
215 // image/popup calls have arguments separated by |
\r
216 $args = func_get_args();
\r
217 $args = preg_split('#\|#', implode($args, ', '));
\r
218 echo call_user_func_array(array(&$this, 'createPopupCode'), $args);
\r
222 * BodyActions::createPopupCode()
\r
223 * Creates the code for a popup
\r
225 * @param string $filename name of file from tag
\r
226 * @param integer $width width of file from tag
\r
227 * @param integer $height height of file from tag
\r
228 * @param string $text alternative text from tag
\r
229 * @return string text element with anchor element of JavaScript window.open
\r
231 public function createPopupCode($filename, $width, $height, $text = '')
\r
235 // select private collection when no collection given
\r
236 if ( i18n::strpos($filename, '/') === FALSE )
\r
238 $filename = $this->currentItem['authorid'] . '/' . $filename;
\r
241 $windowwidth = $width;
\r
242 $windowheight = $height;
\r
244 $vars['rawpopuplink'] = $CONF['Self'] . "?imagepopup=" . Entity::hsc($filename) . "&width=$width&height=$height&imagetext=" . urlencode(Entity::hsc($text));
\r
245 $vars['popupcode'] = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
\r
246 $vars['popuptext'] = Entity::hsc($text);
\r
247 $vars['popuplink'] = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';
\r
248 $vars['width'] = $width;
\r
249 $vars['height'] = $height;
\r
250 $vars['text'] = $text;
\r
251 $vars['link'] = Entity::hsc($CONF['MediaURL'] . $filename);
\r
252 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['popuptext'] . '</a>';
\r
254 return Template::fill($this->template['POPUP_CODE'], $vars);
\r
258 * BodyActions::checkCondition()
\r
259 * Checks conditions for if statements
\r
261 * @param string $field type of <%if%>
\r
262 * @param string $name property of field
\r
263 * @param string $value value of property
\r
264 * @return condition
\r
266 protected function checkCondition($field, $name='', $value = '')
\r
268 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
\r
274 $condition = ($blog && $this->ifCategory($name,$value));
\r
276 case 'itemcategory':
\r
277 $condition = ($this->ifItemCategory($name,$value));
\r
279 case 'blogsetting':
\r
280 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
282 case 'itemblogsetting':
\r
283 $b =& $manager->getBlog($this->currentItem['blogid']);
\r
284 $condition = ($b && ($b->getSetting($name) == $value));
\r
287 $condition = $member->isLoggedIn();
\r
290 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
\r
293 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
\r
296 $condition = ($this->ifAuthor($name,$value));
\r
299 $condition = $this->ifHasPlugin($name, $value);
\r
302 $condition = $manager->pluginInstalled('NP_' . $field) && $this->ifPlugin($field, $name, $value);
\r
309 * BodyActions::ifCategory()
\r
310 * Different checks for a category
\r
312 * @param string $key key for data of category
\r
313 * @param string $value value for data of category
\r
316 private function ifCategory($key = '', $value = '')
\r
318 global $blog, $catid;
\r
320 // when no parameter is defined, just check if a category is selected
\r
321 if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
\r
323 return $blog->isValidCategory($catid);
\r
326 // check category name
\r
327 if ( $key == 'catname' )
\r
329 $value = $blog->getCategoryIdFromName($value);
\r
330 if ( $value == $catid )
\r
332 return $blog->isValidCategory($catid);
\r
336 // check category id
\r
337 if ( ($key == 'catid') && ($value == $catid) )
\r
339 return $blog->isValidCategory($catid);
\r
346 * BodyActions::ifAuthor()
\r
347 * Different checks for an author
\r
349 * @param string $key key for data of author
\r
350 * @param string $value value for data of author
\r
353 private function ifAuthor($key = '', $value = '')
\r
355 global $member, $manager;
\r
357 $b =& $manager->getBlog($this->currentItem['blogid']);
\r
359 // when no parameter is defined, just check if author is current visitor
\r
360 if ( ($key != 'isadmin' && $key != 'name') || ($key == 'name' && $value == '') )
\r
362 return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem['authorid']));
\r
365 // check author name
\r
366 if ( $key == 'name' )
\r
368 $value = strtolower($value);
\r
369 if ( $value == strtolower($this->currentItem['author']) )
\r
375 // check if author is admin
\r
376 if ( ($key == 'isadmin') )
\r
378 $aid = intval($this->currentItem['authorid']);
\r
379 $blogid = intval($b->getID());
\r
380 $amember =& $manager->getMember($aid);
\r
381 if ( $amember->isAdmin() )
\r
385 return $amember->isBlogAdmin($blogid);
\r
392 * BodyActions::ifItemCategory()
\r
393 * Different checks for a category
\r
395 * @param string $key key for data of category
\r
396 * @param string $value value for data of category
\r
399 private function ifItemCategory($key = '', $value = '')
\r
401 global $catid, $manager;
\r
403 $b =& $manager->getBlog($this->currentItem['blogid']);
\r
405 // when no parameter is defined, just check if a category is selected
\r
406 if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
\r
408 return $b->isValidCategory($catid);
\r
411 $icatid = $this->currentItem['catid'];
\r
413 // check category name
\r
414 if ( $key == 'catname' )
\r
416 $value = $b->getCategoryIdFromName($value);
\r
417 if ( $value == $icatid )
\r
419 return $b->isValidCategory($icatid);
\r
423 // check category id
\r
424 if ( ($key == 'catid') && ($value == $icatid) )
\r
426 return $b->isValidCategory($icatid);
\r
432 * BodyActions::ifOnTeam()
\r
433 * Checks if a member is on the team of a blog and return his rights
\r
435 * @param string $blogName name of weblog
\r
438 private function ifOnTeam($blogName = '')
\r
440 global $blog, $member, $manager;
\r
442 // when no blog found
\r
443 if ( ($blogName == '') && (!is_object($blog)) )
\r
448 // explicit blog selection
\r
449 if ( $blogName != '' )
\r
451 $blogid = getBlogIDFromName($blogName);
\r
454 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
456 // use current blog
\r
457 $blogid = $blog->getID();
\r
459 return $member->teamRights($blogid);
\r
463 * BodyActions::ifAdmin()
\r
464 * Checks if a member is admin of a blog
\r
466 * @param string $blogName name of weblog
\r
469 private function ifAdmin($blogName = '')
\r
471 global $blog, $member, $manager;
\r
473 // when no blog found
\r
474 if ( ($blogName == '') && (!is_object($blog)) )
\r
479 // explicit blog selection
\r
480 if ( $blogName != '' )
\r
482 $blogid = getBlogIDFromName($blogName);
\r
485 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
\r
487 // use current blog
\r
488 $blogid = $blog->getID();
\r
490 return $member->isBlogAdmin($blogid);
\r
495 * BodyActions::ifHasPlugin()
\r
496 * hasplugin,PlugName
\r
497 * -> checks if plugin exists
\r
498 * hasplugin,PlugName,OptionName
\r
499 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
500 * hasplugin,PlugName,OptionName=value
\r
501 * -> checks if the option OptionName from plugin PlugName is set to value
\r
503 * @param string $name name of plugin
\r
504 * @param string $value value for plugin argument
\r
507 private function ifHasPlugin($name, $value)
\r
510 $condition = false;
\r
512 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
513 if ( $manager->pluginInstalled("NP_{$name}") )
\r
515 $plugin =& $manager->getPlugin("NP_{$name}");
\r
516 if ( $plugin != NULL )
\r
518 if ( $value == "" )
\r
524 list($name2, $value2) = preg_split('#=#', $value, 2);
\r
525 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
\r
529 else if ( $plugin->getOption($name2) == $value2 )
\r
540 * BodyActions::ifPlugin()
\r
541 * Checks if a plugin exists and call its doIf function
\r
543 * @param string $name name of plugin
\r
544 * @param string $key ...
\r
545 * @param string $value ...
\r
546 * @return string result of plugin 'doIf'
\r
548 private function ifPlugin($name, $key = '', $value = '')
\r
552 $plugin =& $manager->getPlugin("NP_{$name}");
\r
558 $params = func_get_args();
\r
559 array_shift($params);
\r
561 return call_user_func_array(array(&$plugin, 'doIf'), $params);
\r