4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2009 The Nucleus Group
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * (see nucleus/documentation/index.html#license for more info)
14 * A class to parses plugin calls inside items
16 * @license http://nucleuscms.org/license.txt GNU General Public License
17 * @copyright Copyright (C) 2002-2009 The Nucleus Group
19 * @version $Id: BODYACTIONS.php 1757 2012-04-15 09:02:32Z sakamocchi $
21 * @version $Id: BODYACTIONS.php 1886 2012-06-17 08:27:27Z sakamocchi $
22 >>>>>>> skinnable-master
25 class BodyActions extends BaseActions
30 static private $defined_actions = array(
38 * BodyActions::__construct()
39 * Constructor of the BODYACTIONS
44 public function __construct()
47 parent::__construct();
49 parent::__construct();
50 >>>>>>> skinnable-master
55 * BodyActions::getAvailableActions()
56 * Get the defined actions in an item
59 * @return array self::$defined_actions
61 public function getAvailableActions()
63 return array_merge(self::$defined_actions, parent::getAvailableActions());
67 * BodyActions::setCurrentItem()
68 * Set the current item
70 * @param object &$item reference to the current item
73 public function setCurrentItem(&$item)
75 global $currentitemid;
76 $this->currentItem =& $item;
77 $currentitemid = $this->currentItem['itemid'];
82 * BodyActions::setTemplate()
83 * Set the current template
85 * @param string $template Template to be used
88 public function setTemplate($template)
90 $this->template =& $template;
95 * BodyActions::parse_plugin()
97 * Called if <%plugin(...)%> in an item appears
99 * Calls the doItemVar function in the plugin
101 public function parse_plugin($pluginName)
105 $plugin =& $manager->getPlugin('NP_' . $pluginName);
112 $params = func_get_args();
114 // remove plugin name
115 array_shift($params);
117 // add item reference (array_unshift didn't work)
119 $params = array_merge(array(&$this->currentItem), $params);
121 call_user_func_array(array(&$plugin, 'doItemVar'), $params);
123 $target = array(&$this->currentItem);
124 $params = array_merge($target, $params);
126 call_user_func_array(array($plugin, 'doItemVar'), $params);
127 >>>>>>> skinnable-master
132 * BodyActions::parse_image()
134 * Called if <%image(...)%> in an item appears
137 * @return parsed image tag
139 public function parse_image()
141 // image/popup calls have arguments separated by |
142 $args = func_get_args();
143 $args = preg_split('#\|#', implode($args, ', '));
145 echo call_user_func_array(array(&$this, 'createImageCode'), $args);
147 echo call_user_func_array(array($this, 'createImageCode'), $args);
148 >>>>>>> skinnable-master
152 * BodyActions::createImageCode()
153 * Creates the code for an image
155 * @param string $filename name of file from tag
156 * @param integer $width width of file from tag
157 * @param integer $height height of file from tag
158 * @return string image element with anchor element
160 public function createImageCode($filename, $width, $height, $text = '')
164 // select private collection when no collection given
165 if ( i18n::strpos($filename, '/') === FALSE )
167 $filename = $this->currentItem['authorid'] . '/' . $filename;
170 $windowwidth = $width;
171 $windowheight = $height;
173 $vars['link'] = Entity::hsc($CONF['MediaURL']. $filename);
174 $vars['text'] = Entity::hsc($text);
175 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" title="' . $vars['text'] . '" />';
176 $vars['width'] = $width;
177 $vars['height'] = $height;
178 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
180 return Template::fill($this->template['IMAGE_CODE'], $vars);
184 * BodyActions::parse_media()
186 * Called if <%media(...)%> in an item appears
189 * @param parsed media tag
191 public function parse_media()
193 // image/popup calls have arguments separated by |
194 $args = func_get_args();
195 $args = preg_split('#\|#', implode($args, ', '));
197 echo call_user_func_array(array(&$this, 'createMediaCode'), $args);
199 echo call_user_func_array(array($this, 'createMediaCode'), $args);
200 >>>>>>> skinnable-master
204 * BodyActions::createMediaCode()
205 * Creates the code for a media
207 * @param string $filename name of file from tag
208 * @param string $text alternative text from tag
209 * @return string text element with anchor element
211 public function createMediaCode($filename, $text = '')
215 // select private collection when no collection given
216 if ( i18n::strpos($filename, '/') === FALSE )
218 $filename = $this->currentItem['authorid'] . '/' . $filename;
221 $vars['link'] = Entity::hsc($CONF['MediaURL'] . $filename);
222 $vars['text'] = Entity::hsc($text);
223 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
225 return Template::fill($this->template['MEDIA_CODE'], $vars);;
229 * BodyActions::parse_popup()
231 * Called if <%popup(...)%> in an item appears
234 * @return string parsed popup tag
236 public function parse_popup()
238 // image/popup calls have arguments separated by |
239 $args = func_get_args();
240 $args = preg_split('#\|#', implode($args, ', '));
242 echo call_user_func_array(array(&$this, 'createPopupCode'), $args);
244 echo call_user_func_array(array($this, 'createPopupCode'), $args);
245 >>>>>>> skinnable-master
249 * BodyActions::createPopupCode()
250 * Creates the code for a popup
252 * @param string $filename name of file from tag
253 * @param integer $width width of file from tag
254 * @param integer $height height of file from tag
255 * @param string $text alternative text from tag
256 * @return string text element with anchor element of JavaScript window.open
258 public function createPopupCode($filename, $width, $height, $text = '')
262 // select private collection when no collection given
263 if ( i18n::strpos($filename, '/') === FALSE )
265 $filename = $this->currentItem['authorid'] . '/' . $filename;
268 $windowwidth = $width;
269 $windowheight = $height;
271 $vars['rawpopuplink'] = $CONF['Self'] . "?imagepopup=" . Entity::hsc($filename) . "&width=$width&height=$height&imagetext=" . urlencode(Entity::hsc($text));
272 $vars['popupcode'] = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
273 $vars['popuptext'] = Entity::hsc($text);
274 $vars['popuplink'] = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';
275 $vars['width'] = $width;
276 $vars['height'] = $height;
277 $vars['text'] = $text;
278 $vars['link'] = Entity::hsc($CONF['MediaURL'] . $filename);
279 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['popuptext'] . '</a>';
281 return Template::fill($this->template['POPUP_CODE'], $vars);
285 * BodyActions::checkCondition()
286 * Checks conditions for if statements
288 * @param string $field type of <%if%>
289 * @param string $name property of field
290 * @param string $value value of property
293 protected function checkCondition($field, $name='', $value = '')
295 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
301 $condition = ($blog && $this->ifCategory($name,$value));
304 $condition = ($this->ifItemCategory($name,$value));
307 $condition = ($blog && ($blog->getSetting($name) == $value));
309 case 'itemblogsetting':
311 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid']));
313 $b =& $manager->getBlog($this->currentItem['blogid']);
314 >>>>>>> skinnable-master
315 $condition = ($b && ($b->getSetting($name) == $value));
318 $condition = $member->isLoggedIn();
321 $condition = $member->isLoggedIn() && $this->ifOnTeam($name);
324 $condition = $member->isLoggedIn() && $this->ifAdmin($name);
327 $condition = ($this->ifAuthor($name,$value));
330 $condition = $this->ifHasPlugin($name, $value);
333 $condition = $manager->pluginInstalled('NP_' . $field) && $this->ifPlugin($field, $name, $value);
340 * BodyActions::ifCategory()
341 * Different checks for a category
343 * @param string $key key for data of category
344 * @param string $value value for data of category
347 private function ifCategory($key = '', $value = '')
349 global $blog, $catid;
351 // when no parameter is defined, just check if a category is selected
352 if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
354 return $blog->isValidCategory($catid);
357 // check category name
358 if ( $key == 'catname' )
360 $value = $blog->getCategoryIdFromName($value);
361 if ( $value == $catid )
363 return $blog->isValidCategory($catid);
368 if ( ($key == 'catid') && ($value == $catid) )
370 return $blog->isValidCategory($catid);
377 * BodyActions::ifAuthor()
378 * Different checks for an author
380 * @param string $key key for data of author
381 * @param string $value value for data of author
384 private function ifAuthor($key = '', $value = '')
386 global $member, $manager;
389 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid']));
391 $b =& $manager->getBlog($this->currentItem['blogid']);
392 >>>>>>> skinnable-master
394 // when no parameter is defined, just check if author is current visitor
395 if ( ($key != 'isadmin' && $key != 'name') || ($key == 'name' && $value == '') )
397 return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem['authorid']));
401 if ( $key == 'name' )
403 $value = strtolower($value);
404 if ( $value == strtolower($this->currentItem['author']) )
410 // check if author is admin
411 if ( ($key == 'isadmin') )
413 $aid = intval($this->currentItem['authorid']);
414 $blogid = intval($b->getID());
415 $amember =& $manager->getMember($aid);
416 if ( $amember->isAdmin() )
420 return $amember->isBlogAdmin($blogid);
427 * BodyActions::ifItemCategory()
428 * Different checks for a category
430 * @param string $key key for data of category
431 * @param string $value value for data of category
434 private function ifItemCategory($key = '', $value = '')
436 global $catid, $manager;
439 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem['itemid']));
441 $b =& $manager->getBlog($this->currentItem['blogid']);
442 >>>>>>> skinnable-master
444 // when no parameter is defined, just check if a category is selected
445 if ( ($key != 'catname' && $key != 'catid') || ($value == '') )
447 return $b->isValidCategory($catid);
450 $icatid = $this->currentItem['catid'];
452 // check category name
453 if ( $key == 'catname' )
455 $value = $b->getCategoryIdFromName($value);
456 if ( $value == $icatid )
458 return $b->isValidCategory($icatid);
463 if ( ($key == 'catid') && ($value == $icatid) )
465 return $b->isValidCategory($icatid);
471 * BodyActions::ifOnTeam()
472 * Checks if a member is on the team of a blog and return his rights
474 * @param string $blogName name of weblog
477 private function ifOnTeam($blogName = '')
479 global $blog, $member, $manager;
481 // when no blog found
482 if ( ($blogName == '') && (!is_object($blog)) )
487 // explicit blog selection
488 if ( $blogName != '' )
490 $blogid = getBlogIDFromName($blogName);
493 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
496 $blogid = $blog->getID();
498 return $member->teamRights($blogid);
502 * BodyActions::ifAdmin()
503 * Checks if a member is admin of a blog
505 * @param string $blogName name of weblog
508 private function ifAdmin($blogName = '')
510 global $blog, $member, $manager;
512 // when no blog found
513 if ( ($blogName == '') && (!is_object($blog)) )
518 // explicit blog selection
519 if ( $blogName != '' )
521 $blogid = getBlogIDFromName($blogName);
524 if ( ($blogName == '') || !$manager->existsBlogID($blogid) )
527 $blogid = $blog->getID();
529 return $member->isBlogAdmin($blogid);
534 * BodyActions::ifHasPlugin()
536 * -> checks if plugin exists
537 * hasplugin,PlugName,OptionName
538 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
539 * hasplugin,PlugName,OptionName=value
540 * -> checks if the option OptionName from plugin PlugName is set to value
542 * @param string $name name of plugin
543 * @param string $value value for plugin argument
546 private function ifHasPlugin($name, $value)
551 // (pluginInstalled method won't write a message in the actionlog on failure)
552 if ( $manager->pluginInstalled("NP_{$name}") )
554 $plugin =& $manager->getPlugin("NP_{$name}");
555 if ( $plugin != NULL )
563 list($name2, $value2) = preg_split('#=#', $value, 2);
564 if ( $value2 == "" && $plugin->getOption($name2) != 'no' )
568 else if ( $plugin->getOption($name2) == $value2 )
579 * BodyActions::ifPlugin()
580 * Checks if a plugin exists and call its doIf function
582 * @param string $name name of plugin
583 * @param string $key ...
584 * @param string $value ...
585 * @return string result of plugin 'doIf'
587 private function ifPlugin($name, $key = '', $value = '')
591 $plugin =& $manager->getPlugin("NP_{$name}");
597 $params = func_get_args();
598 array_shift($params);
601 return call_user_func_array(array(&$plugin, 'doIf'), $params);
603 return call_user_func_array(array($plugin, 'doIf'), $params);
604 >>>>>>> skinnable-master