| 46 |
*/ |
*/ |
| 47 |
var $_content = array(); |
var $_content = array(); |
| 48 |
|
|
|
|
|
| 49 |
/** |
/** |
| 50 |
* This keeps track of how much content |
* This keeps track of how much content |
| 51 |
* data has been pushed into the content |
* data has been pushed into the content |
| 56 |
*/ |
*/ |
| 57 |
var $_data_count = 0; |
var $_data_count = 0; |
| 58 |
|
|
|
/** |
|
|
* 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 <table> |
|
|
* <tr> |
|
|
* <td><\td> |
|
|
* </tr> |
|
|
* </table> |
|
|
* @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; |
|
|
|
|
| 59 |
/** |
/** |
| 60 |
* Do we render a newline after the |
* The flags that tell us |
| 61 |
* contents has been rendered? |
* how to render the tag |
| 62 |
* |
* its contents, and the close |
|
* @var boolean |
|
| 63 |
*/ |
*/ |
| 64 |
var $_newline_after_content_flag = TRUE; |
var $_flags = _NEWLINEAFTERCONTENT; |
| 65 |
|
|
| 66 |
|
|
| 67 |
/** |
/** |
| 82 |
$arg = func_get_arg($i); |
$arg = func_get_arg($i); |
| 83 |
array_push($this->_content, $arg); |
array_push($this->_content, $arg); |
| 84 |
} |
} |
| 85 |
$this->_data_count += $num; |
$this->_data_count += $num; |
| 86 |
|
|
| 87 |
|
//set the flag bitmask |
| 88 |
|
$this->_set_flags(); |
| 89 |
} |
} |
| 90 |
|
|
| 91 |
|
|
| 103 |
* |
* |
| 104 |
* @return string the raw html output. |
* @return string the raw html output. |
| 105 |
*/ |
*/ |
| 106 |
function render($indent_level=1, $output_debug=0) { |
function render($indent_level=0, $output_debug=0) { |
| 107 |
$html = ''; |
$html = ''; |
| 108 |
foreach( $this->_content as $item) { |
|
| 109 |
|
for ($x=0; $x<=$this->_data_count-1; $x++) { |
| 110 |
|
$item = &$this->_content[$x]; |
| 111 |
if (method_exists($item, "render") ) { |
if (method_exists($item, "render") ) { |
| 112 |
if ($this->_collapse_flag && method_exists($item, "set_collapse")) { |
if (($this->_flags & _COLLAPSE) && method_exists($item, "set_collapse")) { |
| 113 |
$item->set_collapse(TRUE, FALSE); |
$item->set_collapse(TRUE, FALSE); |
| 114 |
} |
} |
| 115 |
$html .= $item->render($indent_level, $output_debug); |
$html .= $item->render($indent_level, $output_debug); |
| 116 |
} else { |
} else { |
| 117 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
| 118 |
$html .= $item; |
$html .= $item; |
| 119 |
} else { |
} else { |
| 120 |
$indent = $this->_render_indent($indent_level, $output_debug); |
$indent = $this->_render_indent($indent_level, $output_debug); |
| 121 |
$html .= $indent.$item; |
$html .= $indent.$item; |
| 122 |
if ($this->_newline_after_content_flag) { |
if ($this->_flags & _NEWLINEAFTERCONTENT) { |
| 123 |
$html .= "\n"; |
$html .= "\n"; |
| 124 |
} |
} |
| 125 |
} |
} |
| 126 |
} |
} |
| 127 |
} |
} |
| 128 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
| 129 |
$indent = $this->_render_indent($indent_level, $output_debug); |
$indent = $this->_render_indent($indent_level, $output_debug); |
| 130 |
if ($this->_newline_after_content_flag) { |
if ($this->_flags & _NEWLINEAFTERCONTENT) { |
| 131 |
if ($output_debug) { |
if ($output_debug) { |
| 132 |
$html = $indent . $html . "<br>\n"; |
$html = $indent . $html . "<br>\n"; |
| 133 |
} else { |
} else { |
| 226 |
function reset_content( ) { |
function reset_content( ) { |
| 227 |
$this->_content = array(); |
$this->_content = array(); |
| 228 |
$this->_data_count = 0; |
$this->_data_count = 0; |
| 229 |
|
$args = func_get_args(); |
| 230 |
|
call_user_func_array( array(&$this, "add"), $args); |
| 231 |
} |
} |
| 232 |
|
|
| 233 |
/** |
/** |
| 237 |
* @return int |
* @return int |
| 238 |
*/ |
*/ |
| 239 |
function count_content( ) { |
function count_content( ) { |
| 240 |
return $this->_data_count;; |
return $this->_data_count; |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
|
| 244 |
|
/** |
| 245 |
|
* This method is used to set the bitmask |
| 246 |
|
* flags for this tag. It tells the |
| 247 |
|
* class how to render the tag. |
| 248 |
|
* |
| 249 |
|
* NOTE: the child class can override this |
| 250 |
|
* to set the options |
| 251 |
|
*/ |
| 252 |
|
function _set_flags() { |
| 253 |
|
$this->_flags = _NEWLINEAFTERCONTENT | _INDENT; |
| 254 |
} |
} |
| 255 |
|
|
| 256 |
|
|
| 261 |
* @param boolean $flag TRUE or FALSE |
* @param boolean $flag TRUE or FALSE |
| 262 |
*/ |
*/ |
| 263 |
function set_indent_flag( $flag ) { |
function set_indent_flag( $flag ) { |
| 264 |
$this->indent_flag = $flag; |
if ($flag) { |
| 265 |
|
$this->_flags |= _INDENT; |
| 266 |
|
} else { |
| 267 |
|
$this->_flags &= ~_INDENT; |
| 268 |
|
} |
| 269 |
} |
} |
| 270 |
|
|
| 271 |
|
|
| 278 |
* @return boolean |
* @return boolean |
| 279 |
*/ |
*/ |
| 280 |
function get_indent_flag() { |
function get_indent_flag() { |
| 281 |
return $this->indent_flag; |
return $this->_flags & _INDENT; |
| 282 |
} |
} |
| 283 |
|
|
| 284 |
|
|
| 292 |
* DEFAULT: TRUE; |
* DEFAULT: TRUE; |
| 293 |
*/ |
*/ |
| 294 |
function set_collapse($collapse=TRUE, $indent=TRUE) { |
function set_collapse($collapse=TRUE, $indent=TRUE) { |
| 295 |
$this->_collapse_flag = $collapse; |
if ($collapse) { |
| 296 |
|
$this->_flags |= _COLLAPSE; |
| 297 |
|
} else { |
| 298 |
|
$this->_flags &= ~_COLLAPSE; |
| 299 |
|
} |
| 300 |
|
|
| 301 |
if (!$indent) { |
if (!$indent) { |
| 302 |
$this->set_indent_flag($indent); |
$this->set_indent_flag($indent); |
| 303 |
$this->_newline_after_content_flag = FALSE; |
$this->_flags &= ~_NEWLINEAFTERCONTENT; |
| 304 |
} |
} |
| 305 |
} |
} |
| 306 |
|
|
| 319 |
if ( $debug_flag && $indent_level > 0) { |
if ( $debug_flag && $indent_level > 0) { |
| 320 |
$indent_level *=2; |
$indent_level *=2; |
| 321 |
} |
} |
| 322 |
if ( $this->indent_flag && $indent_level > 0) { |
if ( ($this->_flags & _INDENT) && $indent_level > 0) { |
| 323 |
$indent = str_repeat($this->_indent_str, $indent_level); |
$indent = str_repeat(_INDENT_STR, $indent_level); |
| 324 |
} |
} |
| 325 |
if ( $debug_flag && $indent_level > 0) { |
if ( $debug_flag && $indent_level > 0) { |
| 326 |
$indent = str_replace($this->_indent_str, " ", $indent); |
$indent = str_replace(_INDENT_STR, " ", $indent); |
| 327 |
} |
} |
| 328 |
return $indent; |
return $indent; |
| 329 |
} |
} |