| [ Index ] |
PHP Cross Reference of Nucleus CMS 3.64 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 4 * Copyright (C) 2002-2009 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-2009 The Nucleus Group 20 * @version $Id: BaseActions.php 1498 2011-02-04 16:35:39Z ftruscot $ 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 $file = $this->getIncludeFileName($filename); 79 if (!file_exists($file)) return; 80 $contents = file_get_contents($file); 81 if (empty($contents)) return; 82 83 $this->level = $this->level + 1; 84 // parse file contents 85 $this->parser->parse($contents); 86 87 $this->level = $this->level - 1; 88 } 89 90 /** 91 * Returns the correct location of the file to be included, according to 92 * parser properties 93 * 94 * IF IncludeMode = 'skindir' => use skindir 95 */ 96 function getIncludeFileName($filename) { 97 // leave absolute filenames and http urls as they are 98 if ( 99 (substr($filename,0,1) == '/') 100 || (substr($filename,0,7) == 'http://') 101 || (substr($filename,0,6) == 'ftp://') 102 ) 103 return $filename; 104 105 $filename = PARSER::getProperty('IncludePrefix') . $filename; 106 if (PARSER::getProperty('IncludeMode') == 'skindir') { 107 global $DIR_SKINS; 108 return $DIR_SKINS . $filename; 109 } else { 110 return $filename; 111 } 112 } 113 114 /** 115 * Inserts an url relative to the skindir (useful when doing import/export) 116 * 117 * e.g. <skinfile(default/myfile.sth)> 118 */ 119 function parse_skinfile($filename) { 120 global $CONF; 121 122 echo $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $filename; 123 } 124 125 /** 126 * Sets a property for the parser 127 */ 128 function parse_set($property, $value) { 129 PARSER::setProperty($property, $value); 130 } 131 132 /** 133 * Helper function: add if condition 134 */ 135 function _addIfCondition($condition) { 136 137 array_push($this->if_conditions,$condition); 138 139 $this->_updateTopIfCondition(); 140 141 ob_start(); 142 } 143 144 function _updateTopIfCondition() { 145 if (sizeof($this->if_conditions) == 0) 146 $this->if_currentlevel = 1; 147 else 148 $this->if_currentlevel = $this->if_conditions[sizeof($this->if_conditions) - 1]; 149 } 150 151 /** 152 * Helper function for elseif / elseifnot 153 */ 154 function _addIfExecute() { 155 array_push($this->if_execute, 0); 156 } 157 158 /** 159 * Helper function for elseif / elseifnot 160 * @param string condition to be fullfilled 161 */ 162 function _updateIfExecute($condition) { 163 $index = sizeof($this->if_execute) - 1; 164 $this->if_execute[$index] = $this->if_execute[$index] || $condition; 165 } 166 167 /** 168 * returns the currently top if condition 169 */ 170 function _getTopIfCondition() { 171 return $this->if_currentlevel; 172 } 173 174 /** 175 * Sets the search terms to be highlighted 176 * 177 * @param $highlight 178 * A series of search terms 179 */ 180 function setHighlight($highlight) { 181 $this->strHighlight = $highlight; 182 if ($highlight) { 183 $this->aHighlight = parseHighlight($highlight); 184 } 185 } 186 187 /** 188 * Applies the highlight to the given piece of text 189 * 190 * @param &$data 191 * Data that needs to be highlighted 192 * @see setHighlight 193 */ 194 function highlight(&$data) { 195 if ($this->aHighlight) 196 return highlight($data,$this->aHighlight,$this->template['SEARCH_HIGHLIGHT']); 197 else 198 return $data; 199 } 200 201 /** 202 * Parses <%if%> statements 203 */ 204 function parse_if() { 205 $this->_addIfExecute(); 206 207 $args = func_get_args(); 208 $condition = call_user_func_array(array(&$this,'checkCondition'), $args); 209 $this->_addIfCondition($condition); 210 } 211 212 /** 213 * Parses <%else%> statements 214 */ 215 function parse_else() { 216 if (sizeof($this->if_conditions) == 0) return; 217 array_pop($this->if_conditions); 218 if ($this->if_currentlevel) { 219 ob_end_flush(); 220 $this->_updateIfExecute(1); 221 $this->_addIfCondition(0); 222 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) { 223 ob_end_clean(); 224 $this->_addIfCondition(0); 225 } else { 226 ob_end_clean(); 227 $this->_addIfCondition(1); 228 } 229 } 230 231 /** 232 * Parses <%elseif%> statements 233 */ 234 function parse_elseif() { 235 if (sizeof($this->if_conditions) == 0) return; 236 array_pop($this->if_conditions); 237 if ($this->if_currentlevel) { 238 ob_end_flush(); 239 $this->_updateIfExecute(1); 240 $this->_addIfCondition(0); 241 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) { 242 ob_end_clean(); 243 $this->_addIfCondition(0); 244 } else { 245 ob_end_clean(); 246 $args = func_get_args(); 247 $condition = call_user_func_array(array(&$this,'checkCondition'), $args); 248 $this->_addIfCondition($condition); 249 } 250 } 251 252 /** 253 * Parses <%ifnot%> statements 254 */ 255 function parse_ifnot() { 256 $this->_addIfExecute(); 257 258 $args = func_get_args(); 259 $condition = call_user_func_array(array(&$this,'checkCondition'), $args); 260 $this->_addIfCondition(!$condition); 261 } 262 263 /** 264 * Parses <%elseifnot%> statements 265 */ 266 function parse_elseifnot() { 267 if (sizeof($this->if_conditions) == 0) return; 268 array_pop($this->if_conditions); 269 if ($this->if_currentlevel) { 270 ob_end_flush(); 271 $this->_updateIfExecute(1); 272 $this->_addIfCondition(0); 273 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) { 274 ob_end_clean(); 275 $this->_addIfCondition(0); 276 } else { 277 ob_end_clean(); 278 $args = func_get_args(); 279 $condition = call_user_func_array(array(&$this,'checkCondition'), $args); 280 $this->_addIfCondition(!$condition); 281 } 282 } 283 284 /** 285 * Ends a conditional if-block 286 * see e.g. ifcat (BLOG), ifblogsetting (PAGEFACTORY) 287 */ 288 function parse_endif() { 289 // we can only close what has been opened 290 if (sizeof($this->if_conditions) == 0) return; 291 292 if ($this->if_currentlevel) { 293 ob_end_flush(); 294 } else { 295 ob_end_clean(); 296 } 297 array_pop($this->if_conditions); 298 array_pop($this->if_execute); 299 300 $this->_updateTopIfCondition(); 301 } 302 } 303 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon May 2 16:14:08 2011 | Cross-referenced by PHPXref 0.7.1 |