| 32 |
* |
* |
| 33 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
| 34 |
* @package phpHtmlLib |
* @package phpHtmlLib |
| 35 |
|
* @tutorial Container.cls |
| 36 |
* |
* |
| 37 |
*/ |
*/ |
| 38 |
|
|
| 47 |
*/ |
*/ |
| 48 |
var $_content = array(); |
var $_content = array(); |
| 49 |
|
|
|
|
|
| 50 |
/** |
/** |
| 51 |
* This keeps track of how much content |
* This keeps track of how much content |
| 52 |
* data has been pushed into the content |
* data has been pushed into the content |
| 57 |
*/ |
*/ |
| 58 |
var $_data_count = 0; |
var $_data_count = 0; |
| 59 |
|
|
|
/** |
|
|
* 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; |
|
|
|
|
| 60 |
/** |
/** |
| 61 |
* The indent level for data. |
* The flags that tell us |
| 62 |
* used for pretty formatting of output |
* how to render the tag |
| 63 |
* ie <table> |
* its contents, and the close |
| 64 |
* <tr> |
* @access private |
|
* <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; |
|
|
|
|
|
/** |
|
|
* Do we render a newline after the |
|
|
* contents has been rendered? |
|
|
* |
|
|
* @var boolean |
|
| 65 |
*/ |
*/ |
| 66 |
var $_newline_after_content_flag = TRUE; |
var $_flags = _NEWLINEAFTERCONTENT; |
| 67 |
|
|
| 68 |
|
|
| 69 |
/** |
/** |
| 74 |
* added to the container. This |
* added to the container. This |
| 75 |
* works in the same manner as |
* works in the same manner as |
| 76 |
* the push() method. |
* the push() method. |
| 77 |
|
* |
| 78 |
|
* {@source } |
| 79 |
|
* |
| 80 |
|
* @tutorial Container.cls#constructor |
| 81 |
*/ |
*/ |
| 82 |
function Container() { |
function Container() { |
| 83 |
//We do the adding to the content var |
//We do the adding to the content var |
| 88 |
$arg = func_get_arg($i); |
$arg = func_get_arg($i); |
| 89 |
array_push($this->_content, $arg); |
array_push($this->_content, $arg); |
| 90 |
} |
} |
| 91 |
$this->_data_count += $num; |
$this->_data_count += $num; |
| 92 |
|
|
| 93 |
|
//set the flag bitmask |
| 94 |
|
$this->_set_flags(); |
| 95 |
} |
} |
| 96 |
|
|
| 97 |
|
|
| 101 |
* It just walks through each of the |
* It just walks through each of the |
| 102 |
* class' data and renders it with the |
* class' data and renders it with the |
| 103 |
* appropriate indentation. |
* appropriate indentation. |
| 104 |
|
* |
| 105 |
|
* {@source } |
| 106 |
* |
* |
| 107 |
* @param int - the indentation level for |
* @param int - the indentation level for |
| 108 |
* the container. |
* the container. |
| 111 |
* |
* |
| 112 |
* @return string the raw html output. |
* @return string the raw html output. |
| 113 |
*/ |
*/ |
| 114 |
function render($indent_level=1, $output_debug=0) { |
function render($indent_level=0, $output_debug=0) { |
| 115 |
$html = ''; |
$html = ''; |
| 116 |
foreach( $this->_content as $item) { |
|
| 117 |
|
for ($x=0; $x<=$this->_data_count-1; $x++) { |
| 118 |
|
$item = &$this->_content[$x]; |
| 119 |
if (method_exists($item, "render") ) { |
if (method_exists($item, "render") ) { |
| 120 |
if ($this->_collapse_flag && method_exists($item, "set_collapse")) { |
if (($this->_flags & _COLLAPSE) && method_exists($item, "set_collapse")) { |
| 121 |
$item->set_collapse(TRUE, FALSE); |
$item->set_collapse(TRUE, FALSE); |
| 122 |
} |
} |
| 123 |
$html .= $item->render($indent_level, $output_debug); |
$html .= $item->render($indent_level, $output_debug); |
| 124 |
} else { |
} else { |
| 125 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
| 126 |
$html .= $item; |
$html .= $item; |
| 127 |
} else { |
} else { |
| 128 |
$indent = $this->_render_indent($indent_level, $output_debug); |
$indent = $this->_render_indent($indent_level, $output_debug); |
| 129 |
$html .= $indent.$item; |
$html .= $indent.$item; |
| 130 |
if ($this->_newline_after_content_flag) { |
if ($this->_flags & _NEWLINEAFTERCONTENT) { |
| 131 |
$html .= "\n"; |
$html .= "\n"; |
| 132 |
} |
} |
| 133 |
} |
} |
| 134 |
} |
} |
| 135 |
} |
} |
| 136 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
| 137 |
$indent = $this->_render_indent($indent_level, $output_debug); |
$indent = $this->_render_indent($indent_level, $output_debug); |
| 138 |
if ($this->_newline_after_content_flag) { |
if ($this->_flags & _NEWLINEAFTERCONTENT) { |
| 139 |
if ($output_debug) { |
if ($output_debug) { |
| 140 |
$html = $indent . $html . "<br>\n"; |
$html = $indent . $html . "<br>\n"; |
| 141 |
} else { |
} else { |
| 159 |
* Same as add(). |
* Same as add(). |
| 160 |
* NOTE: only exists for 1.1.x compatibility |
* NOTE: only exists for 1.1.x compatibility |
| 161 |
* |
* |
| 162 |
|
* {@source } |
| 163 |
|
* |
| 164 |
* @deprecated |
* @deprecated |
| 165 |
* @param mixed $content - either string, or tag object. |
* @param mixed $content - either string, or tag object. |
| 166 |
* @access public |
* @access public |
| 176 |
* adds content to tag as a FIFO. |
* adds content to tag as a FIFO. |
| 177 |
* You can have n number of parameters. |
* You can have n number of parameters. |
| 178 |
* each one will get added in succession to the content. |
* each one will get added in succession to the content. |
| 179 |
|
* |
| 180 |
|
* {@source } |
| 181 |
|
* |
| 182 |
|
* @tutorial Container.cls#add |
| 183 |
|
* |
| 184 |
* @param mixed $content - either string, or tag object. |
* @param mixed $content - either string, or tag object. |
| 185 |
* @access public |
* @access public |
| 186 |
*/ |
*/ |
| 200 |
* Same as add_reference |
* Same as add_reference |
| 201 |
* NOTE : only exists for compatibility with 1.1.x |
* NOTE : only exists for compatibility with 1.1.x |
| 202 |
* |
* |
| 203 |
|
* {@source } |
| 204 |
* @deprecated |
* @deprecated |
| 205 |
* |
* |
| 206 |
* @access public |
* @access public |
| 235 |
|
|
| 236 |
/** |
/** |
| 237 |
* destroy existing content and start with new content. |
* destroy existing content and start with new content. |
| 238 |
|
* |
| 239 |
|
* {@source } |
| 240 |
* |
* |
| 241 |
* @access public |
* @access public |
| 242 |
* @param mixed $content can be tag object, or raw (string). |
* @param mixed $content can be tag object, or raw (string). |
| 244 |
function reset_content( ) { |
function reset_content( ) { |
| 245 |
$this->_content = array(); |
$this->_content = array(); |
| 246 |
$this->_data_count = 0; |
$this->_data_count = 0; |
| 247 |
|
$args = func_get_args(); |
| 248 |
|
call_user_func_array( array(&$this, "add"), $args); |
| 249 |
} |
} |
| 250 |
|
|
| 251 |
/** |
/** |
| 252 |
* counts the number of content objects |
* counts the number of content objects |
| 253 |
* |
* |
| 254 |
|
* {@source } |
| 255 |
* @access public |
* @access public |
| 256 |
* @return int |
* @return int |
| 257 |
*/ |
*/ |
| 258 |
function count_content( ) { |
function count_content( ) { |
| 259 |
return $this->_data_count;; |
return $this->_data_count; |
| 260 |
|
} |
| 261 |
|
|
| 262 |
|
|
| 263 |
|
/** |
| 264 |
|
* get the nth element from content array |
| 265 |
|
* |
| 266 |
|
* {@source } |
| 267 |
|
* |
| 268 |
|
* @param int $cell the cell to get |
| 269 |
|
* @return mixed |
| 270 |
|
*/ |
| 271 |
|
function &get_element( $cell ) { |
| 272 |
|
return $this->_content[$cell]; |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
|
| 276 |
|
/** |
| 277 |
|
* This method is used to set the bitmask |
| 278 |
|
* flags for this tag. It tells the |
| 279 |
|
* class how to render the tag. |
| 280 |
|
* |
| 281 |
|
* NOTE: the child class can override this |
| 282 |
|
* to set the options |
| 283 |
|
* |
| 284 |
|
* {@source } |
| 285 |
|
* @access private |
| 286 |
|
* |
| 287 |
|
*/ |
| 288 |
|
function _set_flags() { |
| 289 |
|
$this->_flags = _NEWLINEAFTERCONTENT | _INDENT; |
| 290 |
} |
} |
| 291 |
|
|
| 292 |
|
|
| 293 |
/** |
/** |
| 294 |
* function to set the indent flag |
* function to set the indent flag |
| 295 |
|
* |
| 296 |
|
* {@source } |
| 297 |
* |
* |
| 298 |
* @access public |
* @access public |
| 299 |
* @param boolean $flag TRUE or FALSE |
* @param boolean $flag TRUE or FALSE |
| 300 |
*/ |
*/ |
| 301 |
function set_indent_flag( $flag ) { |
function set_indent_flag( $flag ) { |
| 302 |
$this->indent_flag = $flag; |
if ($flag) { |
| 303 |
|
$this->_flags |= _INDENT; |
| 304 |
|
} else { |
| 305 |
|
$this->_flags &= ~_INDENT; |
| 306 |
|
} |
| 307 |
} |
} |
| 308 |
|
|
| 309 |
|
|
| 311 |
* This flag gets the current value |
* This flag gets the current value |
| 312 |
* of the indent flag |
* of the indent flag |
| 313 |
* |
* |
| 314 |
* @access public |
* {@source } |
| 315 |
* |
* |
| 316 |
* @return boolean |
* @return boolean |
| 317 |
*/ |
*/ |
| 318 |
function get_indent_flag() { |
function get_indent_flag() { |
| 319 |
return $this->indent_flag; |
return $this->_flags & _INDENT; |
| 320 |
} |
} |
| 321 |
|
|
| 322 |
|
|
| 323 |
/** |
/** |
| 324 |
* This function turns on the collapse flag |
* This function turns on the collapse flag |
| 325 |
* |
* |
| 326 |
* @access public |
* {@source } |
| 327 |
|
* |
| 328 |
|
* @tutorial Container.cls#collapse |
| 329 |
* |
* |
| 330 |
* @param boolean - the collapse flag |
* @param boolean - the collapse flag |
| 331 |
* @param boolean - the indent flag |
* @param boolean - the indent flag |
| 332 |
* DEFAULT: TRUE; |
* DEFAULT: TRUE; |
| 333 |
*/ |
*/ |
| 334 |
function set_collapse($collapse=TRUE, $indent=TRUE) { |
function set_collapse($collapse=TRUE, $indent=TRUE) { |
| 335 |
$this->_collapse_flag = $collapse; |
if ($collapse) { |
| 336 |
|
$this->_flags |= _COLLAPSE; |
| 337 |
|
} else { |
| 338 |
|
$this->_flags &= ~_COLLAPSE; |
| 339 |
|
} |
| 340 |
|
|
| 341 |
if (!$indent) { |
if (!$indent) { |
| 342 |
$this->set_indent_flag($indent); |
$this->set_indent_flag($indent); |
| 343 |
$this->_newline_after_content_flag = FALSE; |
$this->_flags &= ~_NEWLINEAFTERCONTENT; |
| 344 |
} |
} |
| 345 |
} |
} |
| 346 |
|
|
| 349 |
/** |
/** |
| 350 |
* returns leading indent for tag |
* returns leading indent for tag |
| 351 |
* |
* |
| 352 |
|
* {@source } |
| 353 |
* @access private |
* @access private |
| 354 |
* |
* |
| 355 |
* @param int the indentation level for this tag. |
* @param int the indentation level for this tag. |
| 360 |
if ( $debug_flag && $indent_level > 0) { |
if ( $debug_flag && $indent_level > 0) { |
| 361 |
$indent_level *=2; |
$indent_level *=2; |
| 362 |
} |
} |
| 363 |
if ( $this->indent_flag && $indent_level > 0) { |
if ( ($this->_flags & _INDENT) && $indent_level > 0) { |
| 364 |
$indent = str_repeat($this->_indent_str, $indent_level); |
$indent = str_repeat(_INDENT_STR, $indent_level); |
| 365 |
} |
} |
| 366 |
if ( $debug_flag && $indent_level > 0) { |
if ( $debug_flag && $indent_level > 0) { |
| 367 |
$indent = str_replace($this->_indent_str, " ", $indent); |
$indent = str_replace(_INDENT_STR, " ", $indent); |
| 368 |
} |
} |
| 369 |
return $indent; |
return $indent; |
| 370 |
} |
} |