| [ Index ] |
PHP Cross Reference of Nucleus CMS 3.32 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 4 * Copyright (C) 2002-2007 The Nucleus Group 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * (see nucleus/documentation/index.html#license for more info) 11 */ 12 /** 13 * This class contains parse actions that are available in all ACTION classes 14 * e.g. include, phpinclude, parsedinclude, skinfile, ... 15 * 16 * It should never be used on it's own 17 * 18 * @license http://nucleuscms.org/license.txt GNU General Public License 19 * @copyright Copyright (C) 2002-2007 The Nucleus Group 20 * @version $Id: BaseActions.php 1116 2007-02-03 08:24:29Z kimitake $ 21 */ 22 23 class BaseActions { 24 25 // depth level for includes (max. level is 3) 26 var $level; 27 28 // array of evaluated conditions (true/false). The element at the end is the one for the most nested 29 // if block. 30 var $if_conditions; 31 32 // in the "elseif" / "elseifnot" sequences, if one of the conditions become "true" remained conditions should not 33 // be tested. this variable (actually a stack) holds this information. 34 var $if_execute; 35 36 // at all times, can be evaluated to either true if the current block needs to be displayed. This 37 // variable is used to decide to skip skinvars in parts that will never be outputted. 38 var $if_currentlevel; 39 40 // contains a search string with keywords that need to be highlighted. These get parsed into $aHighlight 41 var $strHighlight; 42 43 // array of keywords that need to be highlighted in search results (see the highlight() 44 // and parseHighlight() methods) 45 var $aHighlight; 46 47 // reference to the parser object that is using this object as actions-handler 48 var $parser; 49 50 function BaseActions() { 51 $this->level = 0; 52 53 // if nesting level 54 $this->if_conditions = array(); // array on which condition values are pushed/popped 55 $this->if_execute = array(); // array on which condition values are pushed/popped 56 $this->if_currentlevel = 1; // 1 = current level is displayed; 0 = current level not displayed 57 58 // highlights 59 $this->strHighlight = ''; // full highlight 60 $this->aHighlight = array(); // parsed highlight 61 62 } 63 64 // include file (no parsing of php) 65 function parse_include($filename) { 66 @readfile($this->getIncludeFileName($filename)); 67 } 68 69 // php-include file 70 function parse_phpinclude($filename) { 71 includephp($this->getIncludeFileName($filename)); 72 } 73 74 // parsed include 75 function parse_parsedinclude($filename) { 76 // check current level 77 if ($this->level > 3) return; // max. depth reached (avoid endless loop) 78 $filename = $this->getIncludeFileName($filename); 79 if (!file_exists($filename)) return ''; 80 81 $fsize = filesize($filename); 82 83 // nothing to include 84 if ($fsize <= 0) 85 return; 86 87 $this->level = $this->level + 1; 88 89 // read file 90 $fd = fopen ($filename, 'r'); 91 $contents = fread ($fd, $fsize); 92 fclose ($fd); 93 94 // parse file contents 95 $this->parser->parse($contents); 96 97 $this->level = $this->level - 1; 98 } 99 100 /** 101 * Returns the correct location of the file to be included, according to 102 * parser properties 103 * 104 * IF IncludeMode = 'skindir' => use skindir 105 */ 106 function getIncludeFileName($filename) { 107 // leave absolute filenames and http urls as they are 108 if ( 109 (substr($filename,0,1) == '/') 110 || (substr($filename,0,7) == 'http://') 111 || (substr($filename,0,6) == 'ftp://') 112 ) 113 return $filename; 114 115 $filename = PARSER::getProperty('IncludePrefix') . $filename; 116 if (PARSER::getProperty('IncludeMode') == 'skindir') { 117 global $DIR_SKINS; 118 return $DIR_SKINS . $filename; 119 } else { 120 return $filename; 121 } 122 } 123 124 /** 125 * Inserts an url relative to the skindir (useful when doing import/export) 126 * 127 * e.g. <skinfile(default/myfile.sth)> 128 */ 129 function parse_skinfile($filename) { 130 global $CONF; 131 132 echo $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $filename; 133 } 134 135 /** 136 * Sets a property for the parser 137 */ 138 function parse_set($property, $value) { 139 PARSER::setProperty($property, $value); 140 } 141 142 /** 143 * Helper function: add if condition 144 */ 145 function _addIfCondition($condition) { 146 147 array_push($this->if_conditions,$condition); 148 149 $this->_updateTopIfCondition(); 150 151 ob_start(); 152 } 153 154 function _updateTopIfCondition() { 155 if (sizeof($this->if_conditions) == 0) 156 $this->if_currentlevel = 1; 157 else 158 $this->if_currentlevel = $this->if_conditions[sizeof($this->if_conditions) - 1]; 159 } 160 161 /** 162 * Helper function for elseif / elseifnot 163 */ 164 function _addIfExecute() { 165 array_push($this->if_execute, 0); 166 } 167 168 /** 169 * Helper function for elseif / elseifnot 170 * @param string condition to be fullfilled 171 */ 172 function _updateIfExecute($condition) { 173 $index = sizeof($this->if_execute) - 1; 174 $this->if_execute[$index] = $this->if_execute[$index] || $condition; 175 } 176 177 /** 178 * returns the currently top if condition 179 */ 180 function _getTopIfCondition() { 181 return $this->if_currentlevel; 182 } 183 184 /** 185 * Sets the search terms to be highlighted 186 * 187 * @param $highlight 188 * A series of search terms 189 */ 190 function setHighlight($highlight) { 191 $this->strHighlight = $highlight; 192 if ($highlight) { 193 $this->aHighlight = parseHighlight($highlight); 194 } 195 } 196 197 /** 198 * Applies the highlight to the given piece of text 199 * 200 * @param &$data 201 * Data that needs to be highlighted 202 * @see setHighlight 203 */ 204 function highlight(&$data) { 205 if ($this->aHighlight) 206 return highlight($data,$this->aHighlight,$this->template['SEARCH_HIGHLIGHT']); 207 else 208 return $data; 209 } 210 211 /** 212 * Parses <%if%> statements 213 */ 214 function parse_if() { 215 $this->_addIfExecute(); 216 217 $args = func_get_args(); 218 $condition = call_user_func_array(array(&$this,'checkCondition'), $args); 219 $this->_addIfCondition($condition); 220 } 221 222 /** 223 * Parses <%else%> statements 224 */ 225 function parse_else() { 226 if (sizeof($this->if_conditions) == 0) return; 227 array_pop($this->if_conditions); 228 if ($this->if_currentlevel) { 229 ob_end_flush(); 230 $this->_updateIfExecute(1); 231 $this->_addIfCondition(0); 232 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) { 233 ob_end_clean(); 234 $this->_addIfCondition(0); 235 } else { 236 ob_end_clean(); 237 $this->_addIfCondition(1); 238 } 239 } 240 241 /** 242 * Parses <%elseif%> statements 243 */ 244 function parse_elseif() { 245 if (sizeof($this->if_conditions) == 0) return; 246 array_pop($this->if_conditions); 247 if ($this->if_currentlevel) { 248 ob_end_flush(); 249 $this->_updateIfExecute(1); 250 $this->_addIfCondition(0); 251 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) { 252 ob_end_clean(); 253 $this->_addIfCondition(0); 254 } else { 255 ob_end_clean(); 256 $args = func_get_args(); 257 $condition = call_user_func_array(array(&$this,'checkCondition'), $args); 258 $this->_addIfCondition($condition); 259 } 260 } 261 262 /** 263 * Parses <%ifnot%> statements 264 */ 265 function parse_ifnot() { 266 $this->_addIfExecute(); 267 268 $args = func_get_args(); 269 $condition = call_user_func_array(array(&$this,'checkCondition'), $args); 270 $this->_addIfCondition(!$condition); 271 } 272 273 /** 274 * Parses <%elseifnot%> statements 275 */ 276 function parse_elseifnot() { 277 if (sizeof($this->if_conditions) == 0) return; 278 array_pop($this->if_conditions); 279 if ($this->if_currentlevel) { 280 ob_end_flush(); 281 $this->_updateIfExecute(1); 282 $this->_addIfCondition(0); 283 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) { 284 ob_end_clean(); 285 $this->_addIfCondition(0); 286 } else { 287 ob_end_clean(); 288 $args = func_get_args(); 289 $condition = call_user_func_array(array(&$this,'checkCondition'), $args); 290 $this->_addIfCondition(!$condition); 291 } 292 } 293 294 /** 295 * Ends a conditional if-block 296 * see e.g. ifcat (BLOG), ifblogsetting (PAGEFACTORY) 297 */ 298 function parse_endif() { 299 // we can only close what has been opened 300 if (sizeof($this->if_conditions) == 0) return; 301 302 if ($this->if_currentlevel) { 303 ob_end_flush(); 304 } else { 305 ob_end_clean(); 306 } 307 array_pop($this->if_conditions); 308 array_pop($this->if_execute); 309 310 $this->_updateTopIfCondition(); 311 } 312 } 313 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Feb 12 15:34:36 2008 | Cross-referenced by PHPXref 0.7 |