From: sakamocchi Date: Sat, 7 Apr 2012 05:11:34 +0000 (+0900) Subject: MERGE: リビジョン1729のマージ。BaseActionsクラスのコード整理。 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=285632c994afd3d238057cc6082755b88637192e;p=nucleus-jp%2Fnucleus-next.git MERGE: リビジョン1729のマージ。BaseActionsクラスのコード整理。 Revision 1729: code clean-up for BaseActions class Adding access modifier and comments http://nucleuscms.svn.sourceforge.net/viewvc/nucleuscms?view=revision&revision=1729 --- diff --git a/nucleus/libs/BaseActions.php b/nucleus/libs/BaseActions.php index 8183375..7a06e22 100644 --- a/nucleus/libs/BaseActions.php +++ b/nucleus/libs/BaseActions.php @@ -1,331 +1,480 @@ -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 - - } - - /** - * include file (no parsing of php) - * - * ToDo: function returns nothing and refering to the cross reference it - * isn't called from anywhere - * - * @param $filename - */ - function parse_include($filename) { - @readfile($this->getIncludeFileName($filename)); - } - - /** - * php-include file - * - * @param $filename - */ - function parse_phpinclude($filename) { - includephp($this->getIncludeFileName($filename)); - } - - - /** - * parsed include - * - * @param $filename - */ - function parse_parsedinclude($filename) { - // check current level - if ($this->level > 3) return; // max. depth reached (avoid endless loop) - $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; - } - - /** - * Returns the correct location of the file to be included, according to - * parser properties - * - * IF IncludeMode = 'skindir' => use skindir - * - * @param $filename - */ - 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; - } else { - return $filename; - } - } - - /** - * Inserts an url relative to the skindir (useful when doing import/export) - * - * e.g. - */ - function parse_skinfile($filename) { - global $CONF; - - echo $CONF['SkinsURL'] . Parser::getProperty('IncludePrefix') . $filename; - } - - /** - * Sets a property for the parser - */ - function parse_set($property, $value) { - Parser::setProperty($property, $value); - } - - /** - * Helper function: add if condition - */ - function _addIfCondition($condition) { - - array_push($this->if_conditions,$condition); - - $this->_updateTopIfCondition(); - - ob_start(); - } - - /** - * Helper function: update the Top of the If Conditions Array - */ - function _updateTopIfCondition() { - if (sizeof($this->if_conditions) == 0) { - $this->if_currentlevel = 1; - } - else { - $this->if_currentlevel = $this->if_conditions[sizeof($this->if_conditions) - 1]; - } - } - - /** - * Helper function for elseif / elseifnot - */ - function _addIfExecute() { - array_push($this->if_execute, 0); - } - - /** - * Helper function for elseif / elseifnot - * @param string condition to be fullfilled - */ - function _updateIfExecute($condition) { - $index = sizeof($this->if_execute) - 1; - $this->if_execute[$index] = $this->if_execute[$index] || $condition; - } - - /** - * returns the currently top if condition - */ - function _getTopIfCondition() { - return $this->if_currentlevel; - } - - /** - * Sets the search terms to be highlighted - * - * @param $highlight - * A series of search terms - */ - function setHighlight($highlight) { - $this->strHighlight = $highlight; - if ($highlight) { - $this->aHighlight = parseHighlight($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 - */ - function highlight($data) - { - if ( $this->aHighlight ) - { - $data = Entity::highlight($data, $this->aHighlight, $this->template['SEARCH_HIGHLIGHT']); - } - return $data; - } - - /** - * Parses <%if%> statements - */ - function parse_if() { - $this->_addIfExecute(); - - $args = func_get_args(); - $condition = call_user_func_array(array(&$this,'checkCondition'), $args); - $this->_addIfCondition($condition); - } - - /** - * Parses <%else%> statements - */ - 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); - } - } - - /** - * Parses <%elseif%> statements - */ - 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); - } - } - - /** - * Parses <%ifnot%> statements - */ - function parse_ifnot() { - $this->_addIfExecute(); - - $args = func_get_args(); - $condition = call_user_func_array(array(&$this,'checkCondition'), $args); - $this->_addIfCondition(!$condition); - } - - /** - * Parses <%elseifnot%> statements - */ - 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); - } - } - - /** - * Ends a conditional if-block - * see e.g. ifcat (BLOG), ifblogsetting (PAGEFACTORY) - */ - 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(); - } -} -?> +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. + * + * @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; + } +}