<?php
/*
* Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2012 The Nucleus Group
+ * Copyright (C) 2002-2009 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
* 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 $
+ * @copyright Copyright (C) 2002-2009 The Nucleus Group
+ * @version $Id: BaseActions.php 1882 2012-06-17 07:52:43Z sakamocchi $
*/
class BaseActions
{
+ /**
+ * BaseActions::$parser
+ * Skin class calls parser with action classes succeeded to this class
+ */
+ protected $parser;
+
+
// depth level for includes (max. level is 3)
- public $level;
+ private $level;
// array of evaluated conditions (true/false). The element at the end is the one for the most nested
// if block.
- public $if_conditions;
+ private $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;
+ private $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;
+ private $if_currentlevel;
+
// contains a search string with keywords that need to be highlighted. These get parsed into $aHighlight
- public $strHighlight;
+ protected $strHighlight;
// array of keywords that need to be highlighted in search results (see the highlight()
// and parseHighlight() methods)
- public $aHighlight;
+ private $aHighlight;
- // reference to the parser object that is using this object as actions-handler
- public $parser;
+ /* NOTE: defined actions for this base class */
+ static private $defined_actions = array(
+ 'benchmark',
+ 'charset',
+ 'else',
+ 'elseif',
+ 'elseifnot',
+ 'endif',
+ 'if',
+ 'ifnot',
+ 'include',
+ 'locale',
+ 'parsedinclude',
+ 'phpinclude',
+ 'set',
+ 'skinfile',
+ 'text'
+ );
/**
- * BaseActions::BaseActions()
+ * BaseActions::__construct()
* Constructor for a new BaseAction object
*/
- protected function BaseActions()
+ protected function __construct()
{
$this->level = 0;
// if nesting level
- $this->if_conditions = array(); // array on which condition values are pushed/popped
+ $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
+ $this->strHighlight = ''; // full highlight
+ $this->aHighlight = array(); // parsed highlight
+ return;
+ }
+
+ /**
+ * BaseActions::getAvailableActions()
+ *
+ * @param void
+ * @return void
+ */
+ public function getAvailableActions()
+ {
+ return self::$defined_actions;
+ }
+
+ /**
+ * BaseActions::setParser()
+ * Set the parser
+ *
+ * @param object $parser an instance of Parser class
+ * @return void
+ */
+ public function setParser(&$parser)
+ {
+ $this->parser =& $parser;
+ return;
+ }
+
+ /**
+ * BaseActions::parse_charset()
+ * Parse charset to appropriate character set name registered to IANA
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_charset()
+ {
+ global $member;
+
+ if ( i18n::get_forced_charset() !== '' )
+ {
+ echo i18n::get_forced_charset();
+ }
+ else
+ {
+ echo i18n::get_current_charset();
+ }
+
+ return;
+ }
+
+ /**
+ * BaseActions::parse_locale()
+ * Parse locale to language-region according to RFC 4646
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_locale()
+ {
+ echo preg_replace('#(.+)_(.+)_(.+)#', '$1-$3', i18n::get_current_locale());
return;
}
* BaseActions::parse_parsedinclude()
* parsed include
*
- * @param string $filename filename to be included
+ * @param string $name filename to be included
* @return void
*/
- public function parse_parsedinclude($filename)
+ public function parse_parsedinclude($name)
{
// check current level
if ( $this->level > 3 )
return;
}
- $file = $this->getIncludeFileName($filename);
-
- if ( !file_exists($file) )
+ $file = $this->getIncludeFileName($name);
+ if ( !file_exists($file) && $this->parser->skin != NULL)
{
- return;
+ $contents = $this->parser->skin->getContentFromDB($name);
+ }
+ else
+ {
+ $contents = file_get_contents($file);
}
-
- $contents = file_get_contents($file);
if ( empty($contents) )
{
* @param string $filename name of file to be inclluded
* @return string name of file with relative path
*/
- public function getIncludeFileName($filename)
+ private function getIncludeFileName($filename)
{
// leave absolute filenames and http urls as they are
if (
}
/**
- * BaseActions::_addIfCondition()
+ * BaseActions::parse_text()
+ * Parse text
+ *
+ * @param string $constant named constant
+ * @return void
+ */
+ public function parse_text($constant)
+ {
+ if ( !defined($constant) )
+ {
+ echo $constant;
+ }
+ else
+ {
+ echo constant($constant);
+ }
+ return;
+ }
+
+ /**
+ * BaseActions::addIfCondition()
* Helper function: add if condition
*
* @param string $condition condition for if context
* @return void
*/
- protected function _addIfCondition($condition)
+ private function addIfCondition($condition)
{
array_push($this->if_conditions,$condition);
- $this->_updateTopIfCondition();
+ $this->updateTopIfCondition();
ob_start();
return;
}
/**
- * BaseActions::_updateTopIfCondition()
+ * BaseActions::updateTopIfCondition()
* Helper function: update the Top of the If Conditions Array
*
* @param void
* @return void
*/
- protected function _updateTopIfCondition()
+ private function updateTopIfCondition()
{
if ( sizeof($this->if_conditions) == 0 )
{
}
/**
- * BaseActions::_addIfExecute()
+ * BaseActions::addIfExecute()
* Helper function for elseif / elseifnot
*
* @param void
* @return void
*/
- protected function _addIfExecute()
+ private function addIfExecute()
{
array_push($this->if_execute, 0);
return;
}
/**
- * BaseActions::_updateIfExecute()
+ * BaseActions::updateIfExecute()
* Helper function for elseif / elseifnot
*
* @param string $condition condition to be fullfilled
* @return void
*/
- protected function _updateIfExecute($condition)
+ private function updateIfExecute($condition)
{
$index = sizeof($this->if_execute) - 1;
$this->if_execute[$index] = $this->if_execute[$index] || $condition;
}
/**
- * BaseActions::_getTopIfCondition()()
+ * BaseActions::getTopIfCondition()()
* returns the currently top if condition
*
* @param void
* @return string level
*/
- protected function _getTopIfCondition()
+ public function getTopIfCondition()
{
return $this->if_currentlevel;
}
}
/**
+ * BaseActions::parse_benchmark()
+ *
+ * @param void
+ * @return void
+ */
+ public function parse_benchmark()
+ {
+ global $StartTime;
+ $loadtime = microtime(TRUE) - $StartTime;
+ printf("%.3F sec/%d queries", $loadtime, DB::getExecCount());
+ return;
+ }
+
+ /**
* BaseActions::parse_if()
* Parses <%if%> statements
*
*/
public function parse_if()
{
- $this->_addIfExecute();
+ $this->addIfExecute();
$args = func_get_args();
$condition = call_user_func_array(array(&$this,'checkCondition'), $args);
- $this->_addIfCondition($condition);
+ $this->addIfCondition($condition);
return;
}
if ( $this->if_currentlevel )
{
ob_end_flush();
- $this->_updateIfExecute(1);
- $this->_addIfCondition(0);
+ $this->updateIfExecute(1);
+ $this->addIfCondition(0);
}
elseif ( $this->if_execute[sizeof($this->if_execute) - 1] )
{
ob_end_clean();
- $this->_addIfCondition(0);
+ $this->addIfCondition(0);
}
else
{
ob_end_clean();
- $this->_addIfCondition(1);
+ $this->addIfCondition(1);
}
return;
}
if ( $this->if_currentlevel )
{
ob_end_flush();
- $this->_updateIfExecute(1);
- $this->_addIfCondition(0);
+ $this->updateIfExecute(1);
+ $this->addIfCondition(0);
}
elseif ( $this->if_execute[sizeof($this->if_execute) - 1] )
{
ob_end_clean();
- $this->_addIfCondition(0);
+ $this->addIfCondition(0);
}
else
{
ob_end_clean();
$args = func_get_args();
$condition = call_user_func_array(array(&$this,'checkCondition'), $args);
- $this->_addIfCondition($condition);
+ $this->addIfCondition($condition);
}
return;
}
*/
public function parse_ifnot()
{
- $this->_addIfExecute();
+ $this->addIfExecute();
$args = func_get_args();
$condition = call_user_func_array(array(&$this,'checkCondition'), $args);
- $this->_addIfCondition(!$condition);
+ $this->addIfCondition(!$condition);
return;
}
if ( $this->if_currentlevel )
{
ob_end_flush();
- $this->_updateIfExecute(1);
- $this->_addIfCondition(0);
+ $this->updateIfExecute(1);
+ $this->addIfCondition(0);
}
elseif ( $this->if_execute[sizeof($this->if_execute) - 1] )
{
ob_end_clean();
- $this->_addIfCondition(0);
+ $this->addIfCondition(0);
}
else
{
ob_end_clean();
$args = func_get_args();
$condition = call_user_func_array(array(&$this,'checkCondition'), $args);
- $this->_addIfCondition(!$condition);
+ $this->addIfCondition(!$condition);
}
return;
}
array_pop($this->if_conditions);
array_pop($this->if_execute);
- $this->_updateTopIfCondition();
+ $this->updateTopIfCondition();
return;
}
}