--- nfo/php/libs/com.newsblob.phphtmllib/ContainerClass.inc 2003/01/30 03:29:08 1.1 +++ nfo/php/libs/com.newsblob.phphtmllib/ContainerClass.inc 2003/02/22 20:55:22 1.2 @@ -3,7 +3,7 @@ /** * Holds the Container class. * - * $Id: ContainerClass.inc,v 1.1 2003/01/30 03:29:08 jonen Exp $ + * $Id: ContainerClass.inc,v 1.2 2003/02/22 20:55:22 jonen Exp $ * * @author Walter A. Boring IV * @package phpHtmlLib @@ -46,7 +46,6 @@ */ var $_content = array(); - /** * This keeps track of how much content * data has been pushed into the content @@ -57,54 +56,12 @@ */ var $_data_count = 0; - /** - * String to use as indent string. - * can be any char. defaulted to 1 space - * @var string - * @access private - */ - var $_indent_str = " "; - - /** - * Flag for pretty (indented) output - * @var boolean - * @access public - */ - var $indent_flag = TRUE; - /** - * The indent level for data. - * used for pretty formatting of output - * ie - * - * - *
<\td> - *
- * @var int - * @access private + * The flags that tell us + * how to render the tag + * its contents, and the close */ - var $_indent_level = 0; - - - /** - * This flag tells us to collapse all - * the content for a tag on to 1 line. - * Don't do a new line after open tag, - * Don't do indenting in the content, - * Don't do a newline after the close tag. - * - * @var boolean - * @access private - */ - var $_collapse_flag = FALSE; - - /** - * Do we render a newline after the - * contents has been rendered? - * - * @var boolean - */ - var $_newline_after_content_flag = TRUE; + var $_flags = _NEWLINEAFTERCONTENT; /** @@ -125,7 +82,10 @@ $arg = func_get_arg($i); array_push($this->_content, $arg); } - $this->_data_count += $num; + $this->_data_count += $num; + + //set the flag bitmask + $this->_set_flags(); } @@ -143,29 +103,31 @@ * * @return string the raw html output. */ - function render($indent_level=1, $output_debug=0) { + function render($indent_level=0, $output_debug=0) { $html = ''; - foreach( $this->_content as $item) { + + for ($x=0; $x<=$this->_data_count-1; $x++) { + $item = &$this->_content[$x]; if (method_exists($item, "render") ) { - if ($this->_collapse_flag && method_exists($item, "set_collapse")) { + if (($this->_flags & _COLLAPSE) && method_exists($item, "set_collapse")) { $item->set_collapse(TRUE, FALSE); } $html .= $item->render($indent_level, $output_debug); } else { - if ($this->_collapse_flag) { + if ($this->_flags & _COLLAPSE) { $html .= $item; } else { $indent = $this->_render_indent($indent_level, $output_debug); $html .= $indent.$item; - if ($this->_newline_after_content_flag) { + if ($this->_flags & _NEWLINEAFTERCONTENT) { $html .= "\n"; } } } } - if ($this->_collapse_flag) { + if ($this->_flags & _COLLAPSE) { $indent = $this->_render_indent($indent_level, $output_debug); - if ($this->_newline_after_content_flag) { + if ($this->_flags & _NEWLINEAFTERCONTENT) { if ($output_debug) { $html = $indent . $html . "
\n"; } else { @@ -264,6 +226,8 @@ function reset_content( ) { $this->_content = array(); $this->_data_count = 0; + $args = func_get_args(); + call_user_func_array( array(&$this, "add"), $args); } /** @@ -273,7 +237,20 @@ * @return int */ function count_content( ) { - return $this->_data_count;; + return $this->_data_count; + } + + + /** + * This method is used to set the bitmask + * flags for this tag. It tells the + * class how to render the tag. + * + * NOTE: the child class can override this + * to set the options + */ + function _set_flags() { + $this->_flags = _NEWLINEAFTERCONTENT | _INDENT; } @@ -284,7 +261,11 @@ * @param boolean $flag TRUE or FALSE */ function set_indent_flag( $flag ) { - $this->indent_flag = $flag; + if ($flag) { + $this->_flags |= _INDENT; + } else { + $this->_flags &= ~_INDENT; + } } @@ -297,7 +278,7 @@ * @return boolean */ function get_indent_flag() { - return $this->indent_flag; + return $this->_flags & _INDENT; } @@ -311,11 +292,15 @@ * DEFAULT: TRUE; */ function set_collapse($collapse=TRUE, $indent=TRUE) { - $this->_collapse_flag = $collapse; + if ($collapse) { + $this->_flags |= _COLLAPSE; + } else { + $this->_flags &= ~_COLLAPSE; + } if (!$indent) { $this->set_indent_flag($indent); - $this->_newline_after_content_flag = FALSE; + $this->_flags &= ~_NEWLINEAFTERCONTENT; } } @@ -334,11 +319,11 @@ if ( $debug_flag && $indent_level > 0) { $indent_level *=2; } - if ( $this->indent_flag && $indent_level > 0) { - $indent = str_repeat($this->_indent_str, $indent_level); + if ( ($this->_flags & _INDENT) && $indent_level > 0) { + $indent = str_repeat(_INDENT_STR, $indent_level); } if ( $debug_flag && $indent_level > 0) { - $indent = str_replace($this->_indent_str, " ", $indent); + $indent = str_replace(_INDENT_STR, " ", $indent); } return $indent; }