3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2009 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
13 * This class contains parse actions that are available in all ACTION classes
\r
14 * e.g. include, phpinclude, parsedinclude, skinfile, ...
\r
16 * It should never be used on it's own
\r
18 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
19 * @copyright Copyright (C) 2002-2009 The Nucleus Group
\r
20 * @version $Id: BaseActions.php 1527 2011-06-21 10:43:44Z sakamocchi $
\r
25 // depth level for includes (max. level is 3)
\r
28 // array of evaluated conditions (true/false). The element at the end is the one for the most nested
\r
32 // in the "elseif" / "elseifnot" sequences, if one of the conditions become "true" remained conditions should not
\r
33 // be tested. this variable (actually a stack) holds this information.
\r
36 // at all times, can be evaluated to either true if the current block needs to be displayed. This
\r
37 // variable is used to decide to skip skinvars in parts that will never be outputted.
\r
38 var $if_currentlevel;
\r
40 // contains a search string with keywords that need to be highlighted. These get parsed into $aHighlight
\r
43 // array of keywords that need to be highlighted in search results (see the highlight()
\r
44 // and parseHighlight() methods)
\r
47 // reference to the parser object that is using this object as actions-handler
\r
51 * Constructor for a new BaseAction object
\r
53 function BaseActions() {
\r
57 $this->if_conditions = array(); // array on which condition values are pushed/popped
\r
58 $this->if_execute = array(); // array on which condition values are pushed/popped
\r
59 $this->if_currentlevel = 1; // 1 = current level is displayed; 0 = current level not displayed
\r
62 $this->strHighlight = ''; // full highlight
\r
63 $this->aHighlight = array(); // parsed highlight
\r
68 * include file (no parsing of php)
\r
70 * ToDo: function returns nothing and refering to the cross reference it
\r
71 * isn't called from anywhere
\r
75 function parse_include($filename) {
\r
76 @readfile($this->getIncludeFileName($filename));
\r
84 function parse_phpinclude($filename) {
\r
85 includephp($this->getIncludeFileName($filename));
\r
94 function parse_parsedinclude($filename) {
\r
95 // check current level
\r
96 if ($this->level > 3) return; // max. depth reached (avoid endless loop)
\r
97 $file = $this->getIncludeFileName($filename);
\r
98 if (!file_exists($file)) return;
\r
99 $contents = file_get_contents($file);
\r
100 if (empty($contents)) return;
\r
102 $this->level = $this->level + 1;
\r
103 // parse file contents
\r
104 $this->parser->parse($contents);
\r
106 $this->level = $this->level - 1;
\r
110 * Returns the correct location of the file to be included, according to
\r
111 * parser properties
\r
113 * IF IncludeMode = 'skindir' => use skindir
\r
117 function getIncludeFileName($filename) {
\r
118 // leave absolute filenames and http urls as they are
\r
120 (i18n::substr($filename,0,1) == '/')
\r
121 || (i18n::substr($filename,0,7) == 'http://')
\r
122 || (i18n::substr($filename,0,6) == 'ftp://')
\r
126 $filename = Parser::getProperty('IncludePrefix') . $filename;
\r
127 if (Parser::getProperty('IncludeMode') == 'skindir') {
\r
129 return $DIR_SKINS . $filename;
\r
136 * Inserts an url relative to the skindir (useful when doing import/export)
\r
138 * e.g. <skinfile(default/myfile.sth)>
\r
140 function parse_skinfile($filename) {
\r
143 echo $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $filename;
\r
147 * Sets a property for the parser
\r
149 function parse_set($property, $value) {
\r
150 Parser::setProperty($property, $value);
\r
154 * Helper function: add if condition
\r
156 function _addIfCondition($condition) {
\r
158 array_push($this->if_conditions,$condition);
\r
160 $this->_updateTopIfCondition();
\r
166 * Helper function: update the Top of the If Conditions Array
\r
168 function _updateTopIfCondition() {
\r
169 if (sizeof($this->if_conditions) == 0) {
\r
170 $this->if_currentlevel = 1;
\r
173 $this->if_currentlevel = $this->if_conditions[sizeof($this->if_conditions) - 1];
\r
178 * Helper function for elseif / elseifnot
\r
180 function _addIfExecute() {
\r
181 array_push($this->if_execute, 0);
\r
185 * Helper function for elseif / elseifnot
\r
186 * @param string condition to be fullfilled
\r
188 function _updateIfExecute($condition) {
\r
189 $index = sizeof($this->if_execute) - 1;
\r
190 $this->if_execute[$index] = $this->if_execute[$index] || $condition;
\r
194 * returns the currently top if condition
\r
196 function _getTopIfCondition() {
\r
197 return $this->if_currentlevel;
\r
201 * Sets the search terms to be highlighted
\r
203 * @param $highlight
\r
204 * A series of search terms
\r
206 function setHighlight($highlight) {
\r
207 $this->strHighlight = $highlight;
\r
209 $this->aHighlight = parseHighlight($highlight);
\r
214 * Applies the highlight to the given piece of text
\r
216 * @see setHighlight
\r
217 * @param String $data Data that needs to be highlighted
\r
218 * @return String hilighted data
\r
220 function highlight($data)
\r
222 if ( $this->aHighlight )
\r
224 $data = Entity::highlight($data, $this->aHighlight, $this->template['SEARCH_HIGHLIGHT']);
\r
230 * Parses <%if%> statements
\r
232 function parse_if() {
\r
233 $this->_addIfExecute();
\r
235 $args = func_get_args();
\r
236 $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
\r
237 $this->_addIfCondition($condition);
\r
241 * Parses <%else%> statements
\r
243 function parse_else() {
\r
244 if (sizeof($this->if_conditions) == 0) return;
\r
245 array_pop($this->if_conditions);
\r
246 if ($this->if_currentlevel) {
\r
248 $this->_updateIfExecute(1);
\r
249 $this->_addIfCondition(0);
\r
250 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {
\r
252 $this->_addIfCondition(0);
\r
255 $this->_addIfCondition(1);
\r
260 * Parses <%elseif%> statements
\r
262 function parse_elseif() {
\r
263 if (sizeof($this->if_conditions) == 0) return;
\r
264 array_pop($this->if_conditions);
\r
265 if ($this->if_currentlevel) {
\r
267 $this->_updateIfExecute(1);
\r
268 $this->_addIfCondition(0);
\r
269 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {
\r
271 $this->_addIfCondition(0);
\r
274 $args = func_get_args();
\r
275 $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
\r
276 $this->_addIfCondition($condition);
\r
281 * Parses <%ifnot%> statements
\r
283 function parse_ifnot() {
\r
284 $this->_addIfExecute();
\r
286 $args = func_get_args();
\r
287 $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
\r
288 $this->_addIfCondition(!$condition);
\r
292 * Parses <%elseifnot%> statements
\r
294 function parse_elseifnot() {
\r
295 if (sizeof($this->if_conditions) == 0) return;
\r
296 array_pop($this->if_conditions);
\r
297 if ($this->if_currentlevel) {
\r
299 $this->_updateIfExecute(1);
\r
300 $this->_addIfCondition(0);
\r
301 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {
\r
303 $this->_addIfCondition(0);
\r
306 $args = func_get_args();
\r
307 $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
\r
308 $this->_addIfCondition(!$condition);
\r
313 * Ends a conditional if-block
\r
314 * see e.g. ifcat (BLOG), ifblogsetting (PAGEFACTORY)
\r
316 function parse_endif() {
\r
317 // we can only close what has been opened
\r
318 if (sizeof($this->if_conditions) == 0) return;
\r
320 if ($this->if_currentlevel) {
\r
325 array_pop($this->if_conditions);
\r
326 array_pop($this->if_execute);
\r
328 $this->_updateTopIfCondition();
\r