-<?php\r
-/*\r
- * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
- * Copyright (C) 2002-2012 The Nucleus Group\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- * (see nucleus/documentation/index.html#license for more info)\r
- */\r
-/**\r
- * This class contains parse actions that are available in all ACTION classes\r
- * e.g. include, phpinclude, parsedinclude, skinfile, ...\r
- *\r
- * It should never be used on it's own\r
- *\r
- * @license http://nucleuscms.org/license.txt GNU General Public License\r
- * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
- * @version $Id: BaseActions.php 1527 2011-06-21 10:43:44Z sakamocchi $\r
- */\r
-\r
-class BaseActions\r
-{\r
- // depth level for includes (max. level is 3)\r
- var $level;\r
-\r
- // array of evaluated conditions (true/false). The element at the end is the one for the most nested\r
- // if block.\r
- var $if_conditions;\r
-\r
- // in the "elseif" / "elseifnot" sequences, if one of the conditions become "true" remained conditions should not\r
- // be tested. this variable (actually a stack) holds this information.\r
- var $if_execute;\r
-\r
- // at all times, can be evaluated to either true if the current block needs to be displayed. This\r
- // variable is used to decide to skip skinvars in parts that will never be outputted.\r
- var $if_currentlevel;\r
-\r
- // contains a search string with keywords that need to be highlighted. These get parsed into $aHighlight\r
- var $strHighlight;\r
-\r
- // array of keywords that need to be highlighted in search results (see the highlight()\r
- // and parseHighlight() methods)\r
- var $aHighlight;\r
-\r
- // reference to the parser object that is using this object as actions-handler\r
- var $parser;\r
-\r
- /**\r
- * Constructor for a new BaseAction object\r
- */\r
- function BaseActions() {\r
- $this->level = 0;\r
-\r
- // if nesting level\r
- $this->if_conditions = array(); // array on which condition values are pushed/popped\r
- $this->if_execute = array(); // array on which condition values are pushed/popped\r
- $this->if_currentlevel = 1; // 1 = current level is displayed; 0 = current level not displayed\r
-\r
- // highlights\r
- $this->strHighlight = ''; // full highlight\r
- $this->aHighlight = array(); // parsed highlight\r
-\r
- }\r
-\r
- /**\r
- * include file (no parsing of php)\r
- * \r
- * ToDo: function returns nothing and refering to the cross reference it\r
- * isn't called from anywhere \r
- * \r
- * @param $filename\r
- */\r
- function parse_include($filename) {\r
- @readfile($this->getIncludeFileName($filename));\r
- }\r
-\r
- /**\r
- * php-include file\r
- * \r
- * @param $filename\r
- */\r
- function parse_phpinclude($filename) {\r
- includephp($this->getIncludeFileName($filename));\r
- }\r
-\r
- \r
- /**\r
- * parsed include\r
- * \r
- * @param $filename\r
- */\r
- function parse_parsedinclude($filename) {\r
- // check current level\r
- if ($this->level > 3) return; // max. depth reached (avoid endless loop)\r
- $file = $this->getIncludeFileName($filename);\r
- if (!file_exists($file)) return;\r
- $contents = file_get_contents($file);\r
- if (empty($contents)) return;\r
- \r
- $this->level = $this->level + 1;\r
- // parse file contents\r
- $this->parser->parse($contents);\r
-\r
- $this->level = $this->level - 1;\r
- }\r
-\r
- /**\r
- * Returns the correct location of the file to be included, according to\r
- * parser properties\r
- *\r
- * IF IncludeMode = 'skindir' => use skindir\r
- * \r
- * @param $filename\r
- */\r
- function getIncludeFileName($filename) {\r
- // leave absolute filenames and http urls as they are\r
- if (\r
- (i18n::substr($filename,0,1) == '/')\r
- || (i18n::substr($filename,0,7) == 'http://')\r
- || (i18n::substr($filename,0,6) == 'ftp://')\r
- )\r
- return $filename;\r
-\r
- $filename = Parser::getProperty('IncludePrefix') . $filename;\r
- if (Parser::getProperty('IncludeMode') == 'skindir') {\r
- global $DIR_SKINS;\r
- return $DIR_SKINS . $filename;\r
- } else {\r
- return $filename;\r
- }\r
- }\r
-\r
- /**\r
- * Inserts an url relative to the skindir (useful when doing import/export)\r
- *\r
- * e.g. <skinfile(default/myfile.sth)>\r
- */\r
- function parse_skinfile($filename) {\r
- global $CONF;\r
-\r
- echo $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $filename;\r
- }\r
-\r
- /**\r
- * Sets a property for the parser\r
- */\r
- function parse_set($property, $value) {\r
- Parser::setProperty($property, $value);\r
- }\r
-\r
- /**\r
- * Helper function: add if condition\r
- */\r
- function _addIfCondition($condition) {\r
-\r
- array_push($this->if_conditions,$condition);\r
-\r
- $this->_updateTopIfCondition();\r
-\r
- ob_start();\r
- }\r
-\r
- /**\r
- * Helper function: update the Top of the If Conditions Array\r
- */\r
- function _updateTopIfCondition() {\r
- if (sizeof($this->if_conditions) == 0) {\r
- $this->if_currentlevel = 1;\r
- }\r
- else {\r
- $this->if_currentlevel = $this->if_conditions[sizeof($this->if_conditions) - 1];\r
- }\r
- }\r
-\r
- /**\r
- * Helper function for elseif / elseifnot\r
- */\r
- function _addIfExecute() {\r
- array_push($this->if_execute, 0);\r
- }\r
-\r
- /**\r
- * Helper function for elseif / elseifnot\r
- * @param string condition to be fullfilled\r
- */\r
- function _updateIfExecute($condition) {\r
- $index = sizeof($this->if_execute) - 1;\r
- $this->if_execute[$index] = $this->if_execute[$index] || $condition;\r
- }\r
-\r
- /**\r
- * returns the currently top if condition\r
- */\r
- function _getTopIfCondition() {\r
- return $this->if_currentlevel;\r
- }\r
-\r
- /**\r
- * Sets the search terms to be highlighted\r
- *\r
- * @param $highlight\r
- * A series of search terms\r
- */\r
- function setHighlight($highlight) {\r
- $this->strHighlight = $highlight;\r
- if ($highlight) {\r
- $this->aHighlight = parseHighlight($highlight);\r
- }\r
- }\r
- \r
- /**\r
- * Applies the highlight to the given piece of text\r
- *\r
- * @see setHighlight\r
- * @param String $data Data that needs to be highlighted\r
- * @return String hilighted data\r
- */\r
- function highlight($data)\r
- {\r
- if ( $this->aHighlight )\r
- {\r
- $data = Entity::highlight($data, $this->aHighlight, $this->template['SEARCH_HIGHLIGHT']);\r
- }\r
- return $data;\r
- }\r
- \r
- /**\r
- * Parses <%if%> statements\r
- */\r
- function parse_if() {\r
- $this->_addIfExecute();\r
-\r
- $args = func_get_args();\r
- $condition = call_user_func_array(array(&$this,'checkCondition'), $args);\r
- $this->_addIfCondition($condition);\r
- }\r
-\r
- /**\r
- * Parses <%else%> statements\r
- */\r
- function parse_else() {\r
- if (sizeof($this->if_conditions) == 0) return;\r
- array_pop($this->if_conditions);\r
- if ($this->if_currentlevel) {\r
- ob_end_flush();\r
- $this->_updateIfExecute(1);\r
- $this->_addIfCondition(0);\r
- } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {\r
- ob_end_clean();\r
- $this->_addIfCondition(0);\r
- } else {\r
- ob_end_clean();\r
- $this->_addIfCondition(1);\r
- }\r
- }\r
-\r
- /**\r
- * Parses <%elseif%> statements\r
- */\r
- function parse_elseif() {\r
- if (sizeof($this->if_conditions) == 0) return;\r
- array_pop($this->if_conditions);\r
- if ($this->if_currentlevel) {\r
- ob_end_flush();\r
- $this->_updateIfExecute(1);\r
- $this->_addIfCondition(0);\r
- } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {\r
- ob_end_clean();\r
- $this->_addIfCondition(0);\r
- } else {\r
- ob_end_clean();\r
- $args = func_get_args();\r
- $condition = call_user_func_array(array(&$this,'checkCondition'), $args);\r
- $this->_addIfCondition($condition);\r
- }\r
- }\r
-\r
- /**\r
- * Parses <%ifnot%> statements\r
- */\r
- function parse_ifnot() {\r
- $this->_addIfExecute();\r
-\r
- $args = func_get_args();\r
- $condition = call_user_func_array(array(&$this,'checkCondition'), $args);\r
- $this->_addIfCondition(!$condition);\r
- }\r
-\r
- /**\r
- * Parses <%elseifnot%> statements\r
- */\r
- function parse_elseifnot() {\r
- if (sizeof($this->if_conditions) == 0) return;\r
- array_pop($this->if_conditions);\r
- if ($this->if_currentlevel) {\r
- ob_end_flush();\r
- $this->_updateIfExecute(1);\r
- $this->_addIfCondition(0);\r
- } elseif ($this->if_execute[sizeof($this->if_execute) - 1]) {\r
- ob_end_clean();\r
- $this->_addIfCondition(0);\r
- } else {\r
- ob_end_clean();\r
- $args = func_get_args();\r
- $condition = call_user_func_array(array(&$this,'checkCondition'), $args);\r
- $this->_addIfCondition(!$condition);\r
- }\r
- }\r
-\r
- /**\r
- * Ends a conditional if-block\r
- * see e.g. ifcat (BLOG), ifblogsetting (PAGEFACTORY)\r
- */\r
- function parse_endif() {\r
- // we can only close what has been opened\r
- if (sizeof($this->if_conditions) == 0) return;\r
-\r
- if ($this->if_currentlevel) {\r
- ob_end_flush();\r
- } else {\r
- ob_end_clean();\r
- }\r
- array_pop($this->if_conditions);\r
- array_pop($this->if_execute);\r
-\r
- $this->_updateTopIfCondition();\r
- }\r
-}\r
-?>\r
+<?php
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2012 The Nucleus Group
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * (see nucleus/documentation/index.html#license for more info)
+ */
+/**
+ * This class contains parse actions that are available in all ACTION classes
+ * e.g. include, phpinclude, parsedinclude, skinfile, ...
+ *
+ * It should never be used on it's own
+ *
+ * @license http://nucleuscms.org/license.txt GNU General Public License
+ * @copyright Copyright (C) 2002-2012 The Nucleus Group
+ * @version $Id: BaseActions.php 1729 2012-04-07 05:07:08Z sakamocchi $
+ */
+
+class BaseActions
+{
+ // depth level for includes (max. level is 3)
+ public $level;
+
+ // array of evaluated conditions (true/false). The element at the end is the one for the most nested
+ // if block.
+ public $if_conditions;
+
+ // in the "elseif" / "elseifnot" sequences, if one of the conditions become "true" remained conditions should not
+ // be tested. this variable (actually a stack) holds this information.
+ public $if_execute;
+
+ // at all times, can be evaluated to either true if the current block needs to be displayed. This
+ // variable is used to decide to skip skinvars in parts that will never be outputted.
+ public $if_currentlevel;
+
+ // contains a search string with keywords that need to be highlighted. These get parsed into $aHighlight
+ public $strHighlight;
+
+ // array of keywords that need to be highlighted in search results (see the highlight()
+ // and parseHighlight() methods)
+ public $aHighlight;
+
+ // reference to the parser object that is using this object as actions-handler
+ public $parser;
+
+ /**
+ * BaseActions::BaseActions()
+ * Constructor for a new BaseAction object
+ */
+ protected function BaseActions()
+ {
+ $this->level = 0;
+
+ // if nesting level
+ $this->if_conditions = array(); // array on which condition values are pushed/popped
+ $this->if_execute = array(); // array on which condition values are pushed/popped
+ $this->if_currentlevel = 1; // 1 = current level is displayed; 0 = current level not displayed
+
+ // highlights
+ $this->strHighlight = ''; // full highlight
+ $this->aHighlight = array(); // parsed highlight
+ return;
+ }
+
+ /**
+ * BaseActions::parse_include()
+ * include file (no parsing of php)
+ *
+ * ToDo: function returns nothing and refering to the cross reference it
+ * isn't called from anywhere
+ *
+ * @param string $filename filename to be included
+ * @return void
+ */
+ public function parse_include($filename)
+ {
+ @readfile($this->getIncludeFileName($filename));
+ return;
+ }
+
+ /**
+ * BaseActions::parse_phpinclude()
+ * php-include file
+ *
+ * @param string $filename filename to be included
+ * @return void
+ */
+ public function parse_phpinclude($filename)
+ {
+ includephp($this->getIncludeFileName($filename));
+ return;
+ }
+
+
+ /**
+ * BaseActions::parse_parsedinclude()
+ * parsed include
+ *
+ * @param string $filename filename to be included
+ * @return void
+ */
+ public function parse_parsedinclude($filename)
+ {
+ // check current level
+ if ( $this->level > 3 )
+ {
+ // max. depth reached (avoid endless loop)
+ return;
+ }
+
+ $file = $this->getIncludeFileName($filename);
+
+ if ( !file_exists($file) )
+ {
+ return;
+ }
+
+ $contents = file_get_contents($file);
+
+ if ( empty($contents) )
+ {
+ return;
+ }
+
+ $this->level = $this->level + 1;
+ // parse file contents
+ $this->parser->parse($contents);
+
+ $this->level = $this->level - 1;
+ return;
+ }
+
+ /**
+ * BaseActions::getIncludeFileName()
+ * Returns the correct location of the file to be included, according to
+ * parser properties
+ *
+ * IF IncludeMode = 'skindir' => use skindir
+ *
+ * @param string $filename name of file to be inclluded
+ * @return string name of file with relative path
+ */
+ public function getIncludeFileName($filename)
+ {
+ // leave absolute filenames and http urls as they are
+ if (
+ (i18n::substr($filename,0,1) == '/')
+ || (i18n::substr($filename,0,7) == 'http://')
+ || (i18n::substr($filename,0,6) == 'ftp://')
+ )
+ {
+ return $filename;
+ }
+
+ $filename = Parser::getProperty('IncludePrefix') . $filename;
+
+ if ( Parser::getProperty('IncludeMode') == 'skindir' )
+ {
+ global $DIR_SKINS;
+ return $DIR_SKINS . $filename;
+ }
+ return $filename;
+ }
+
+ /**
+ * BaseActions::parse_skinfile()
+ * Inserts an url relative to the skindir (useful when doing import/export)
+ *
+ * e.g. <skinfile(default/myfile.sth)>
+ *
+ * @param string $filename name of file to be inclluded
+ * @return void
+ */
+ public function parse_skinfile($filename)
+ {
+ global $CONF;
+ echo $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $filename;
+ return;
+ }
+
+ /**
+ * BaseActions::parse_set()
+ * Sets a property for the parser
+ *
+ * @param string $property name of property
+ * @param string $value value of property
+ * @return void
+ */
+ public function parse_set($property, $value)
+ {
+ Parser::setProperty($property, $value);
+ return;
+ }
+
+ /**
+ * BaseActions::_addIfCondition()
+ * Helper function: add if condition
+ *
+ * @param string $condition condition for if context
+ * @return void
+ */
+ protected function _addIfCondition($condition)
+ {
+ array_push($this->if_conditions,$condition);
+ $this->_updateTopIfCondition();
+ ob_start();
+ return;
+ }
+
+ /**
+ * BaseActions::_updateTopIfCondition()
+ * Helper function: update the Top of the If Conditions Array
+ *
+ * @param void
+ * @return void
+ */
+ protected function _updateTopIfCondition()
+ {
+ if ( sizeof($this->if_conditions) == 0 )
+ {
+ $this->if_currentlevel = 1;
+ }
+ else
+ {
+ $this->if_currentlevel = $this->if_conditions[sizeof($this->if_conditions) - 1];
+ }
+ return;
+ }
+
+ /**
+ * BaseActions::_addIfExecute()
+ * Helper function for elseif / elseifnot
+ *
+ * @param void
+ * @return void
+ */
+ protected function _addIfExecute()
+ {
+ array_push($this->if_execute, 0);
+ return;
+ }
+
+ /**
+ * BaseActions::_updateIfExecute()
+ * Helper function for elseif / elseifnot
+ *
+ * @param string $condition condition to be fullfilled
+ * @return void
+ */
+ protected function _updateIfExecute($condition)
+ {
+ $index = sizeof($this->if_execute) - 1;
+ $this->if_execute[$index] = $this->if_execute[$index] || $condition;
+ return;
+ }
+
+ /**
+ * BaseActions::_getTopIfCondition()()
+ * returns the currently top if condition
+ *
+ * @param void
+ * @return string level
+ */
+ protected function _getTopIfCondition()
+ {
+ return $this->if_currentlevel;
+ }
+
+ /**
+ * BaseActions::setHighlight(()
+ * Sets the search terms to be highlighted
+ *
+ * @param string $highlight A series of search terms
+ * @return void
+ */
+ public function setHighlight($highlight)
+ {
+ $this->strHighlight = $highlight;
+ if ( $highlight )
+ {
+ $this->aHighlight = parseHighlight($highlight);
+ }
+ return;
+ }
+
+ /**
+ * BaseActions::highlight()
+ * Applies the highlight to the given piece of text
+ *
+ * @see setHighlight
+ * @param string $data Data that needs to be highlighted
+ * @return string hilighted data
+ */
+ public function highlight($data)
+ {
+ if ( $this->aHighlight )
+ {
+ $data = Entity::highlight($data, $this->aHighlight, $this->template['SEARCH_HIGHLIGHT']);
+ }
+ return $data;
+ }
+
+ /**
+ * BaseActions::parse_if()
+ * Parses <%if%> statements
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_if()
+ {
+ $this->_addIfExecute();
+ $args = func_get_args();
+ $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
+ $this->_addIfCondition($condition);
+ return;
+ }
+
+ /**
+ * BaseActions::parse_else()
+ * Parses <%else%> statements
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_else()
+ {
+ if ( sizeof($this->if_conditions) == 0 )
+ {
+ return;
+ }
+
+ array_pop($this->if_conditions);
+
+ if ( $this->if_currentlevel )
+ {
+ ob_end_flush();
+ $this->_updateIfExecute(1);
+ $this->_addIfCondition(0);
+ }
+ elseif ( $this->if_execute[sizeof($this->if_execute) - 1] )
+ {
+ ob_end_clean();
+ $this->_addIfCondition(0);
+ }
+ else
+ {
+ ob_end_clean();
+ $this->_addIfCondition(1);
+ }
+ return;
+ }
+
+ /**
+ * BaseActions::parse_elseif()
+ * Parses <%elseif%> statements
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_elseif()
+ {
+ if ( sizeof($this->if_conditions) == 0 )
+ {
+ return;
+ }
+
+ array_pop($this->if_conditions);
+
+ if ( $this->if_currentlevel )
+ {
+ ob_end_flush();
+ $this->_updateIfExecute(1);
+ $this->_addIfCondition(0);
+ }
+ elseif ( $this->if_execute[sizeof($this->if_execute) - 1] )
+ {
+ ob_end_clean();
+ $this->_addIfCondition(0);
+ }
+ else
+ {
+ ob_end_clean();
+ $args = func_get_args();
+ $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
+ $this->_addIfCondition($condition);
+ }
+ return;
+ }
+
+ /**
+ * BaseActions::parse_ifnot()
+ * Parses <%ifnot%> statements
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_ifnot()
+ {
+ $this->_addIfExecute();
+
+ $args = func_get_args();
+ $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
+ $this->_addIfCondition(!$condition);
+ return;
+ }
+
+ /**
+ * BaseActions::parse_elseifnot()
+ * Parses <%elseifnot%> statements
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_elseifnot()
+ {
+ if ( sizeof($this->if_conditions) == 0 )
+ {
+ return;
+ }
+
+ array_pop($this->if_conditions);
+
+ if ( $this->if_currentlevel )
+ {
+ ob_end_flush();
+ $this->_updateIfExecute(1);
+ $this->_addIfCondition(0);
+ }
+ elseif ( $this->if_execute[sizeof($this->if_execute) - 1] )
+ {
+ ob_end_clean();
+ $this->_addIfCondition(0);
+ }
+ else
+ {
+ ob_end_clean();
+ $args = func_get_args();
+ $condition = call_user_func_array(array(&$this,'checkCondition'), $args);
+ $this->_addIfCondition(!$condition);
+ }
+ return;
+ }
+
+ /**
+ * BaseActions::parse_endif()
+ * Ends a conditional if-block
+ * see e.g. ifcat (BLOG), ifblogsetting (PAGEFACTORY)
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_endif()
+ {
+ // we can only close what has been opened
+ if ( sizeof($this->if_conditions) == 0 )
+ {
+ return;
+ }
+
+ if ( $this->if_currentlevel )
+ {
+ ob_end_flush();
+ }
+ else
+ {
+ ob_end_clean();
+ }
+
+ array_pop($this->if_conditions);
+ array_pop($this->if_execute);
+
+ $this->_updateTopIfCondition();
+ return;
+ }
+}