4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2010 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-2010 The Nucleus Group
19 * @version $NucleusJP: BODYACTIONS.php,v 1.6.2.1 2007/08/08 05:27:14 kimitake Exp $
22 class BODYACTIONS extends BaseActions {
28 function BODYACTIONS () {
32 function setCurrentItem(&$item) {
33 $this->currentItem =& $item;
34 global $currentitemid;
35 $currentitemid = $this->currentItem->itemid;
38 function setTemplate($template) {
39 $this->template =& $template;
42 function getDefinedActions() {
43 return array('image', 'media', 'popup', 'plugin', 'if', 'else', 'endif', 'elseif', 'ifnot', 'elseifnot');
46 function parse_plugin($pluginName) {
49 // should be already tested from the parser (PARSER.php)
\r
50 // only continue when the plugin is really installed
\r
51 /*if (!$manager->pluginInstalled('NP_' . $pluginName)) {
\r
55 $plugin =& $manager->getPlugin('NP_' . $pluginName);
59 $params = func_get_args();
64 // add item reference (array_unshift didn't work)
65 $params = array_merge(array(&$this->currentItem),$params);
67 call_user_func_array(array(&$plugin,'doItemVar'), $params);
70 function parse_image() {
71 // image/popup calls have arguments separated by |
72 $args = func_get_args();
73 $args = explode('|',implode($args,', '));
74 call_user_func_array(array(&$this,'createImageCode'),$args);
77 function createImageCode($filename, $width, $height, $text = '') {
80 // select private collection when no collection given
81 if (!strstr($filename,'/')) {
82 $filename = $this->currentItem->authorid . '/' . $filename;
85 $windowwidth = $width;
86 $windowheight = $height;
88 $vars['link'] = htmlspecialchars($CONF['MediaURL']. $filename ,ENT_QUOTES);
89 $vars['text'] = htmlspecialchars($text ,ENT_QUOTES);
90 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" title="' . $vars['text'] . '" />';
91 $vars['width'] = $width;
92 $vars['height'] = $height;
93 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
96 echo TEMPLATE::fill($this->template['IMAGE_CODE'],$vars);;
100 function parse_media() {
101 // image/popup calls have arguments separated by |
102 $args = func_get_args();
103 $args = explode('|',implode($args,', '));
104 call_user_func_array(array(&$this,'createMediaCode'),$args);
107 function createMediaCode($filename, $text = '') {
110 // select private collection when no collection given
111 if (!strstr($filename,'/')) {
112 $filename = $this->currentItem->authorid . '/' . $filename;
115 $vars['link'] = htmlspecialchars($CONF['MediaURL'] . $filename ,ENT_QUOTES);
116 $vars['text'] = htmlspecialchars($text ,ENT_QUOTES);
117 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
119 echo TEMPLATE::fill($this->template['MEDIA_CODE'],$vars);;
123 function parse_popup() {
124 // image/popup calls have arguments separated by |
125 $args = func_get_args();
126 $args = explode('|',implode($args,', '));
127 call_user_func_array(array(&$this,'createPopupCode'),$args);
130 function createPopupCode($filename, $width, $height, $text = '') {
133 // select private collection when no collection given
134 if (!strstr($filename,'/')) {
135 $filename = $this->currentItem->authorid . '/' . $filename;
138 $windowwidth = $width;
139 $windowheight = $height;
141 $vars['rawpopuplink'] = $CONF['Self'] . "?imagepopup=" . htmlspecialchars($filename,ENT_QUOTES) . "&width=$width&height=$height&imagetext=" . urlencode(htmlspecialchars($text));
142 $vars['popupcode'] = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
143 $vars['popuptext'] = htmlspecialchars($text,ENT_QUOTES);
144 $vars['popuplink'] = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';
145 $vars['width'] = $width;
146 $vars['height'] = $height;
147 $vars['text'] = $text;
148 $vars['link'] = htmlspecialchars($CONF['MediaURL'] . $filename ,ENT_QUOTES);
149 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['popuptext'] . '</a>';
151 echo TEMPLATE::fill($this->template['POPUP_CODE'],$vars);
155 // function to enable if-else-elseif-elseifnot-ifnot-endif to item template fields
158 * Checks conditions for if statements
160 * @param string $field type of <%if%>
161 * @param string $name property of field
162 * @param string $value value of property
164 function checkCondition($field, $name='', $value = '') {
165 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
170 $condition = ($blog && $this->_ifCategory($name,$value));
173 $condition = ($this->_ifItemCategory($name,$value));
176 $condition = ($blog && ($blog->getSetting($name) == $value));
178 case 'itemblogsetting':
179 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
180 $condition = ($b && ($b->getSetting($name) == $value));
183 $condition = $member->isLoggedIn();
186 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
189 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
192 $condition = ($this->_ifAuthor($name,$value));
195 $condition = ($itemidnext != '');
198 $condition = ($itemidprev != '');
200 case 'archiveprevexists':
201 $condition = ($archiveprevexists == true);
203 case 'archivenextexists':
204 $condition = ($archivenextexists == true);
207 $condition = ($name == $this->skintype);
210 $condition = $this->_ifHasPlugin($name, $value);
213 $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
220 * Different checks for a category
222 function _ifCategory($name = '', $value='') {
223 global $blog, $catid;
225 // when no parameter is defined, just check if a category is selected
226 if (($name != 'catname' && $name != 'catid') || ($value == ''))
227 return $blog->isValidCategory($catid);
229 // check category name
230 if ($name == 'catname') {
231 $value = $blog->getCategoryIdFromName($value);
232 if ($value == $catid)
233 return $blog->isValidCategory($catid);
237 if (($name == 'catid') && ($value == $catid))
238 return $blog->isValidCategory($catid);
245 * Different checks for an author
247 function _ifAuthor($name = '', $value='') {
248 global $member, $manager;
250 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
252 // when no parameter is defined, just check if author is current visitor
253 if (($name != 'isadmin' && $name != 'name') || ($name == 'name' && $value == '')) {
254 return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem->authorid));
258 if ($name == 'name') {
259 $value = strtolower($value);
260 if ($value == strtolower($this->currentItem->author))
264 // check if author is admin
265 if (($name == 'isadmin')) {
266 $aid = intval($this->currentItem->authorid);
267 $blogid = intval($b->getID());
268 $amember =& $manager->getMember($aid);
269 if ($amember->isAdmin())
272 return $amember->isBlogAdmin($blogid);
279 * Different checks for a category
281 function _ifItemCategory($name = '', $value='') {
282 global $catid, $manager;
284 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
286 // when no parameter is defined, just check if a category is selected
287 if (($name != 'catname' && $name != 'catid') || ($value == ''))
288 return $b->isValidCategory($catid);
290 $icatid = $this->currentItem->catid;
291 //$icategory = $this->currentItem->category;
293 // check category name
294 if ($name == 'catname') {
295 $value = $b->getCategoryIdFromName($value);
296 if ($value == $icatid)
297 return $b->isValidCategory($icatid);
301 if (($name == 'catid') && ($value == $icatid))
302 return $b->isValidCategory($icatid);
309 * Checks if a member is on the team of a blog and return his rights
311 function _ifOnTeam($blogName = '') {
312 global $blog, $member, $manager;
314 // when no blog found
315 if (($blogName == '') && (!is_object($blog)))
318 // explicit blog selection
320 $blogid = getBlogIDFromName($blogName);
322 if (($blogName == '') || !$manager->existsBlogID($blogid))
324 $blogid = $blog->getID();
326 return $member->teamRights($blogid);
330 * Checks if a member is admin of a blog
332 function _ifAdmin($blogName = '') {
333 global $blog, $member, $manager;
335 // when no blog found
336 if (($blogName == '') && (!is_object($blog)))
339 // explicit blog selection
341 $blogid = getBlogIDFromName($blogName);
343 if (($blogName == '') || !$manager->existsBlogID($blogid))
345 $blogid = $blog->getID();
347 return $member->isBlogAdmin($blogid);
353 * -> checks if plugin exists
354 * hasplugin,PlugName,OptionName
355 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
356 * hasplugin,PlugName,OptionName=value
357 * -> checks if the option OptionName from plugin PlugName is set to value
359 function _ifHasPlugin($name, $value) {
362 // (pluginInstalled method won't write a message in the actionlog on failure)
363 if ($manager->pluginInstalled('NP_'.$name)) {
364 $plugin =& $manager->getPlugin('NP_' . $name);
365 if ($plugin != NULL) {
369 list($name2, $value2) = explode('=', $value, 2);
370 if ($value2 == "" && $plugin->getOption($name2) != 'no') {
372 } else if ($plugin->getOption($name2) == $value2) {
382 * Checks if a plugin exists and call its doIf function
384 function _ifPlugin($name, $key = '', $value = '') {
387 $plugin =& $manager->getPlugin('NP_' . $name);
388 if (!$plugin) return;
390 $params = func_get_args();
391 array_shift($params);
393 return call_user_func_array(array(&$plugin, 'doIf'), $params);