BaseActions.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
00004  * Copyright (C) 2002-2007 The Nucleus Group
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * (see nucleus/documentation/index.html#license for more info)
00011  */
00024 class BaseActions {
00025 
00026         // depth level for includes (max. level is 3)
00027         var $level;
00028 
00029         // array of evaluated conditions (true/false). The element at the end is the one for the most nested
00030         // if block.
00031         var $if_conditions;
00032 
00033         // in the "elseif" / "elseifnot" sequences, if one of the conditions become "true" remained conditions should not
00034         // be tested. this variable (actually a stack) holds this information.
00035         var $if_execute;
00036 
00037         // at all times, can be evaluated to either true if the current block needs to be displayed. This
00038         // variable is used to decide to skip skinvars in parts that will never be outputted.
00039         var $if_currentlevel;
00040 
00041         // contains a search string with keywords that need to be highlighted. These get parsed into $aHighlight
00042         var $strHighlight;
00043 
00044         // array of keywords that need to be highlighted in search results (see the highlight()
00045         // and parseHighlight() methods)
00046         var $aHighlight;
00047 
00048         // reference to the parser object that is using this object as actions-handler
00049         var $parser;
00050 
00051         function BaseActions() {
00052                 $this->level = 0;
00053 
00054                 // if nesting level
00055                 $this->if_conditions = array(); // array on which condition values are pushed/popped
00056                 $this->if_execute = array();    // array on which condition values are pushed/popped
00057                 $this->if_currentlevel = 1;             // 1 = current level is displayed; 0 = current level not displayed
00058 
00059                 // highlights
00060                 $this->strHighlight = '';                       // full highlight
00061                 $this->aHighlight = array();            // parsed highlight
00062 
00063         }
00064 
00065         // include file (no parsing of php)
00066         function parse_include($filename) {
00067                 @readfile($this->getIncludeFileName($filename));
00068         }
00069 
00070         // php-include file
00071         function parse_phpinclude($filename) {
00072                 includephp($this->getIncludeFileName($filename));
00073         }
00074 
00075         // parsed include
00076         function parse_parsedinclude($filename) {
00077                 // check current level
00078                 if ($this->level > 3) return;   // max. depth reached (avoid endless loop)
00079                 $filename = $this->getIncludeFileName($filename);
00080                 if (!file_exists($filename)) return '';
00081 
00082                 $fsize = filesize($filename);
00083 
00084                 // nothing to include
00085                 if ($fsize <= 0)
00086                         return;
00087 
00088                 $this->level = $this->level + 1;
00089 
00090                 // read file
00091                 $fd = fopen ($filename, 'r');
00092                 $contents = fread ($fd, $fsize);
00093                 fclose ($fd);
00094 
00095                 // parse file contents
00096                 $this->parser->parse($contents);
00097 
00098                 $this->level = $this->level - 1;
00099         }
00100 
00107         function getIncludeFileName($filename) {
00108                 // leave absolute filenames and http urls as they are
00109                 if (
00110                                 (substr($filename,0,1) == '/')
00111                         ||      (substr($filename,0,7) == 'http://')
00112                         ||      (substr($filename,0,6) == 'ftp://')
00113                         )
00114                         return $filename;
00115 
00116                 $filename = PARSER::getProperty('IncludePrefix') . $filename;
00117                 if (PARSER::getProperty('IncludeMode') == 'skindir') {
00118                         global $DIR_SKINS;
00119                         return $DIR_SKINS . $filename;
00120                 } else {
00121                         return $filename;
00122                 }
00123         }
00124 
00130         function parse_skinfile($filename) {
00131                 global $CONF;
00132 
00133                 echo $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $filename;
00134         }
00135 
00139         function parse_set($property, $value) {
00140                 PARSER::setProperty($property, $value);
00141         }
00142 
00146         function _addIfCondition($condition) {
00147 
00148                 array_push($this->if_conditions,$condition);
00149 
00150                 $this->_updateTopIfCondition();
00151 
00152                 ob_start();
00153         }
00154 
00155         function _updateTopIfCondition() {
00156                 if (sizeof($this->if_conditions) == 0)
00157                         $this->if_currentlevel = 1;
00158                 else
00159                         $this->if_currentlevel = $this->if_conditions[sizeof($this->if_conditions) - 1];
00160         }
00161 
00165         function _addIfExecute() {
00166                 array_push($this->if_execute, 0);
00167         }
00168 
00173         function _updateIfExecute($condition) {
00174                 $index = sizeof($this->if_execute) - 1;
00175                 $this->if_execute[$index] = $this->if_execute[$index] || $condition;
00176         }
00177 
00181         function _getTopIfCondition() {
00182                 return $this->if_currentlevel;
00183         }
00184 
00191         function setHighlight($highlight) {
00192                 $this->strHighlight = $highlight;
00193                 if ($highlight) {
00194                         $this->aHighlight = parseHighlight($highlight);
00195                 }
00196         }
00197 
00205         function highlight(&$data) {
00206                 if ($this->aHighlight)
00207                         return highlight($data,$this->aHighlight,$this->template['SEARCH_HIGHLIGHT']);
00208                 else
00209                         return $data;
00210         }
00211 
00215         function parse_if() {
00216                 $this->_addIfExecute();
00217 
00218                 $args = func_get_args();
00219                 $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
00220                 $this->_addIfCondition($condition);
00221         }
00222 
00226         function parse_else() {
00227                 if (sizeof($this->if_conditions) == 0) return;
00228                 array_pop($this->if_conditions);
00229                 if ($this->if_currentlevel) {
00230                         ob_end_flush();
00231                         $this->_updateIfExecute(1);
00232                         $this->_addIfCondition(0);
00233                 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {
00234                         ob_end_clean();
00235                         $this->_addIfCondition(0);
00236                 } else {
00237                         ob_end_clean();
00238                         $this->_addIfCondition(1);
00239                 }
00240         }
00241 
00245         function parse_elseif() {
00246                 if (sizeof($this->if_conditions) == 0) return;
00247                 array_pop($this->if_conditions);
00248                 if ($this->if_currentlevel) {
00249                         ob_end_flush();
00250                         $this->_updateIfExecute(1);
00251                         $this->_addIfCondition(0);
00252                 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {
00253                         ob_end_clean();
00254                         $this->_addIfCondition(0);
00255                 } else {
00256                         ob_end_clean();
00257                         $args = func_get_args();
00258                         $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
00259                         $this->_addIfCondition($condition);
00260                 }
00261         }
00262 
00266         function parse_ifnot() {
00267                 $this->_addIfExecute();
00268 
00269                 $args = func_get_args();
00270                 $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
00271                 $this->_addIfCondition(!$condition);
00272         }
00273 
00277         function parse_elseifnot() {
00278                 if (sizeof($this->if_conditions) == 0) return;
00279                 array_pop($this->if_conditions);
00280                 if ($this->if_currentlevel) {
00281                         ob_end_flush();
00282                         $this->_updateIfExecute(1);
00283                         $this->_addIfCondition(0);
00284                 } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {
00285                         ob_end_clean();
00286                         $this->_addIfCondition(0);
00287                 } else {
00288                         ob_end_clean();
00289                         $args = func_get_args();
00290                         $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
00291                         $this->_addIfCondition(!$condition);
00292                 }
00293         }
00294 
00299         function parse_endif() {
00300                 // we can only close what has been opened
00301                 if (sizeof($this->if_conditions) == 0) return;
00302 
00303                 if ($this->if_currentlevel) {
00304                         ob_end_flush();
00305                 } else {
00306                         ob_end_clean();
00307                 }
00308                 array_pop($this->if_conditions);
00309                 array_pop($this->if_execute);
00310 
00311                 $this->_updateTopIfCondition();
00312         }
00313 }
00314 ?>



Generated on Wed Jun 25 17:25:57 2008 by  doxygen 1.5.5