4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2012 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)
13 * A class to parses plugin calls inside items
16 class BODYACTIONS extends BaseActions {
22 function BODYACTIONS () {
26 function setCurrentItem(&$item) {
27 $this->currentItem =& $item;
28 global $currentitemid;
29 $currentitemid = $this->currentItem->itemid;
32 function setTemplate($template) {
33 $this->template =& $template;
36 function getDefinedActions() {
37 return array('image', 'media', 'popup', 'plugin', 'if', 'else', 'endif', 'elseif', 'ifnot', 'elseifnot');
40 function parse_plugin($pluginName) {
43 // should be already tested from the parser (PARSER.php)
\r
44 // only continue when the plugin is really installed
\r
45 /*if (!$manager->pluginInstalled('NP_' . $pluginName)) {
\r
49 $plugin =& $manager->getPlugin('NP_' . $pluginName);
53 $params = func_get_args();
58 // add item reference (array_unshift didn't work)
59 $params = array_merge(array(&$this->currentItem),$params);
61 call_user_func_array(array($plugin,'doItemVar'), $params);
64 function parse_image() {
65 // image/popup calls have arguments separated by |
66 $args = func_get_args();
67 $args = explode('|',implode($args,', '));
68 call_user_func_array(array($this,'createImageCode'), $args);
71 function createImageCode($filename, $width, $height, $text = '') {
74 // select private collection when no collection given
75 if (!strstr($filename,'/')) {
76 $filename = $this->currentItem->authorid . '/' . $filename;
79 $windowwidth = $width;
80 $windowheight = $height;
82 $vars['link'] = htmlspecialchars($CONF['MediaURL']. $filename ,ENT_QUOTES);
83 $vars['text'] = htmlspecialchars($text ,ENT_QUOTES);
84 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" title="' . $vars['text'] . '" />';
85 $vars['width'] = $width;
86 $vars['height'] = $height;
87 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
90 echo TEMPLATE::fill($this->template['IMAGE_CODE'],$vars);;
94 function parse_media() {
95 // image/popup calls have arguments separated by |
96 $args = func_get_args();
97 $args = explode('|',implode($args,', '));
98 call_user_func_array(array($this,'createMediaCode'), $args);
101 function createMediaCode($filename, $text = '') {
104 // select private collection when no collection given
105 if (!strstr($filename,'/')) {
106 $filename = $this->currentItem->authorid . '/' . $filename;
109 $vars['link'] = htmlspecialchars($CONF['MediaURL'] . $filename ,ENT_QUOTES);
110 $vars['text'] = htmlspecialchars($text ,ENT_QUOTES);
111 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';
113 echo TEMPLATE::fill($this->template['MEDIA_CODE'],$vars);;
117 function parse_popup() {
118 // image/popup calls have arguments separated by |
119 $args = func_get_args();
120 $args = explode('|',implode($args,', '));
121 call_user_func_array(array($this,'createPopupCode'), $args);
124 function createPopupCode($filename, $width, $height, $text = '') {
127 // select private collection when no collection given
128 if (!strstr($filename,'/')) {
129 $filename = $this->currentItem->authorid . '/' . $filename;
132 $windowwidth = $width;
133 $windowheight = $height;
135 $vars['rawpopuplink'] = $CONF['Self'] . "?imagepopup=" . htmlspecialchars($filename,ENT_QUOTES) . "&width=$width&height=$height&imagetext=" . urlencode(htmlspecialchars($text));
136 $vars['popupcode'] = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
137 $vars['popuptext'] = htmlspecialchars($text,ENT_QUOTES);
138 $vars['popuplink'] = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';
139 $vars['width'] = $width;
140 $vars['height'] = $height;
141 $vars['text'] = $text;
142 $vars['link'] = htmlspecialchars($CONF['MediaURL'] . $filename ,ENT_QUOTES);
143 $vars['media'] = '<a href="' . $vars['link'] . '">' . $vars['popuptext'] . '</a>';
145 echo TEMPLATE::fill($this->template['POPUP_CODE'],$vars);
149 // function to enable if-else-elseif-elseifnot-ifnot-endif to item template fields
152 * Checks conditions for if statements
154 * @param string $field type of <%if%>
155 * @param string $name property of field
156 * @param string $value value of property
158 function checkCondition($field, $name='', $value = '') {
159 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager, $archiveprevexists, $archivenextexists;
164 $condition = ($blog && $this->_ifCategory($name,$value));
167 $condition = ($this->_ifItemCategory($name,$value));
170 $condition = ($blog && ($blog->getSetting($name) == $value));
172 case 'itemblogsetting':
173 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
174 $condition = ($b && ($b->getSetting($name) == $value));
177 $condition = $member->isLoggedIn();
180 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
183 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
186 $condition = ($this->_ifAuthor($name,$value));
189 $condition = ($itemidnext != '');
192 $condition = ($itemidprev != '');
194 case 'archiveprevexists':
195 $condition = ($archiveprevexists == true);
197 case 'archivenextexists':
198 $condition = ($archivenextexists == true);
201 $condition = ($name == $this->skintype);
204 $condition = $this->_ifHasPlugin($name, $value);
207 $condition = $manager->pluginInstalled('NP_' . $field) && $this->_ifPlugin($field, $name, $value);
214 * Different checks for a category
216 function _ifCategory($name = '', $value='') {
217 global $blog, $catid;
219 // when no parameter is defined, just check if a category is selected
220 if (($name != 'catname' && $name != 'catid') || ($value == ''))
221 return $blog->isValidCategory($catid);
223 // check category name
224 if ($name == 'catname') {
225 $value = $blog->getCategoryIdFromName($value);
226 if ($value == $catid)
227 return $blog->isValidCategory($catid);
231 if (($name == 'catid') && ($value == $catid))
232 return $blog->isValidCategory($catid);
239 * Different checks for an author
241 function _ifAuthor($name = '', $value='') {
242 global $member, $manager;
244 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
246 // when no parameter is defined, just check if author is current visitor
247 if (($name != 'isadmin' && $name != 'name') || ($name == 'name' && $value == '')) {
248 return (intval($member->getID()) > 0 && intval($member->getID()) == intval($this->currentItem->authorid));
252 if ($name == 'name') {
253 $value = strtolower($value);
254 if ($value == strtolower($this->currentItem->author))
258 // check if author is admin
259 if (($name == 'isadmin')) {
260 $aid = intval($this->currentItem->authorid);
261 $blogid = intval($b->getID());
262 $amember =& $manager->getMember($aid);
263 if ($amember->isAdmin())
266 return $amember->isBlogAdmin($blogid);
273 * Different checks for a category
275 function _ifItemCategory($name = '', $value='') {
276 global $catid, $manager;
278 $b =& $manager->getBlog(getBlogIDFromItemID($this->currentItem->itemid));
280 // when no parameter is defined, just check if a category is selected
281 if (($name != 'catname' && $name != 'catid') || ($value == ''))
282 return $b->isValidCategory($catid);
284 $icatid = $this->currentItem->catid;
285 //$icategory = $this->currentItem->category;
287 // check category name
288 if ($name == 'catname') {
289 $value = $b->getCategoryIdFromName($value);
290 if ($value == $icatid)
291 return $b->isValidCategory($icatid);
295 if (($name == 'catid') && ($value == $icatid))
296 return $b->isValidCategory($icatid);
303 * Checks if a member is on the team of a blog and return his rights
305 function _ifOnTeam($blogName = '') {
306 global $blog, $member, $manager;
308 // when no blog found
309 if (($blogName == '') && (!is_object($blog)))
312 // explicit blog selection
314 $blogid = getBlogIDFromName($blogName);
316 if (($blogName == '') || !$manager->existsBlogID($blogid))
318 $blogid = $blog->getID();
320 return $member->teamRights($blogid);
324 * Checks if a member is admin of a blog
326 function _ifAdmin($blogName = '') {
327 global $blog, $member, $manager;
329 // when no blog found
330 if (($blogName == '') && (!is_object($blog)))
333 // explicit blog selection
335 $blogid = getBlogIDFromName($blogName);
337 if (($blogName == '') || !$manager->existsBlogID($blogid))
339 $blogid = $blog->getID();
341 return $member->isBlogAdmin($blogid);
347 * -> checks if plugin exists
348 * hasplugin,PlugName,OptionName
349 * -> checks if the option OptionName from plugin PlugName is not set to 'no'
350 * hasplugin,PlugName,OptionName=value
351 * -> checks if the option OptionName from plugin PlugName is set to value
353 function _ifHasPlugin($name, $value) {
356 // (pluginInstalled method won't write a message in the actionlog on failure)
357 if ($manager->pluginInstalled('NP_'.$name)) {
358 $plugin =& $manager->getPlugin('NP_' . $name);
359 if ($plugin != NULL) {
363 list($name2, $value2) = explode('=', $value, 2);
364 if ($value2 == "" && $plugin->getOption($name2) != 'no') {
366 } else if ($plugin->getOption($name2) == $value2) {
376 * Checks if a plugin exists and call its doIf function
378 function _ifPlugin($name, $key = '', $value = '') {
381 $plugin =& $manager->getPlugin('NP_' . $name);
382 if (!$plugin) return;
384 $params = func_get_args();
385 array_shift($params);
387 return call_user_func_array(array($plugin, 'doIf'), $params);