--- nfo/php/libs/com.newsblob.phphtmllib/ContainerClass.inc 2003/01/30 03:29:08 1.1.1.1
+++ nfo/php/libs/com.newsblob.phphtmllib/ContainerClass.inc 2004/05/06 16:23:38 1.4
@@ -3,7 +3,7 @@
/**
* Holds the Container class.
*
- * $Id: ContainerClass.inc,v 1.1.1.1 2003/01/30 03:29:08 jonen Exp $
+ * $Id: ContainerClass.inc,v 1.4 2004/05/06 16:23:38 jonen Exp $
*
* @author Walter A. Boring IV
* @package phpHtmlLib
@@ -32,6 +32,7 @@
*
* @author Walter A. Boring IV
* @package phpHtmlLib
+ * @tutorial Container.cls
*
*/
@@ -46,7 +47,6 @@
*/
var $_content = array();
-
/**
* This keeps track of how much content
* data has been pushed into the content
@@ -57,54 +57,13 @@
*/
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
- * @var int
- * @access private
- */
- 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
+ * The flags that tell us
+ * how to render the tag
+ * its contents, and the close
+ * @access private
*/
- var $_newline_after_content_flag = TRUE;
+ var $_flags = _NEWLINEAFTERCONTENT;
/**
@@ -115,6 +74,10 @@
* added to the container. This
* works in the same manner as
* the push() method.
+ *
+ * {@source }
+ *
+ * @tutorial Container.cls#constructor
*/
function Container() {
//We do the adding to the content var
@@ -125,7 +88,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();
}
@@ -135,6 +101,8 @@
* It just walks through each of the
* class' data and renders it with the
* appropriate indentation.
+ *
+ * {@source }
*
* @param int - the indentation level for
* the container.
@@ -143,29 +111,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 {
@@ -189,6 +159,8 @@
* Same as add().
* NOTE: only exists for 1.1.x compatibility
*
+ * {@source }
+ *
* @deprecated
* @param mixed $content - either string, or tag object.
* @access public
@@ -204,6 +176,11 @@
* adds content to tag as a FIFO.
* You can have n number of parameters.
* each one will get added in succession to the content.
+ *
+ * {@source }
+ *
+ * @tutorial Container.cls#add
+ *
* @param mixed $content - either string, or tag object.
* @access public
*/
@@ -223,6 +200,7 @@
* Same as add_reference
* NOTE : only exists for compatibility with 1.1.x
*
+ * {@source }
* @deprecated
*
* @access public
@@ -257,6 +235,8 @@
/**
* destroy existing content and start with new content.
+ *
+ * {@source }
*
* @access public
* @param mixed $content can be tag object, or raw (string).
@@ -264,27 +244,66 @@
function reset_content( ) {
$this->_content = array();
$this->_data_count = 0;
+ $args = func_get_args();
+ call_user_func_array( array(&$this, "add"), $args);
}
/**
* counts the number of content objects
*
+ * {@source }
* @access public
* @return int
*/
function count_content( ) {
- return $this->_data_count;;
+ return $this->_data_count;
+ }
+
+
+ /**
+ * get the nth element from content array
+ *
+ * {@source }
+ *
+ * @param int $cell the cell to get
+ * @return mixed
+ */
+ function &get_element( $cell ) {
+ return $this->_content[$cell];
+ }
+
+
+ /**
+ * 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
+ *
+ * {@source }
+ * @access private
+ *
+ */
+ function _set_flags() {
+ $this->_flags = _NEWLINEAFTERCONTENT | _INDENT;
}
/**
* function to set the indent flag
+ *
+ * {@source }
*
* @access public
* @param boolean $flag TRUE or FALSE
*/
function set_indent_flag( $flag ) {
- $this->indent_flag = $flag;
+ if ($flag) {
+ $this->_flags |= _INDENT;
+ } else {
+ $this->_flags &= ~_INDENT;
+ }
}
@@ -292,30 +311,36 @@
* This flag gets the current value
* of the indent flag
*
- * @access public
+ * {@source }
*
* @return boolean
*/
function get_indent_flag() {
- return $this->indent_flag;
+ return $this->_flags & _INDENT;
}
/**
* This function turns on the collapse flag
*
- * @access public
+ * {@source }
+ *
+ * @tutorial Container.cls#collapse
*
* @param boolean - the collapse flag
* @param boolean - the indent flag
* 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;
}
}
@@ -324,6 +349,7 @@
/**
* returns leading indent for tag
*
+ * {@source }
* @access private
*
* @param int the indentation level for this tag.
@@ -334,11 +360,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;
}