53 |
*/ |
*/ |
54 |
var $_attributes = array(); |
var $_attributes = array(); |
55 |
|
|
|
/** |
|
|
* flag to render close tag or not. |
|
|
* set to FALSE if no close tag is needed |
|
|
* ie <img src=hotchick.png> |
|
|
* @var boolean |
|
|
* @access private |
|
|
*/ |
|
|
var $_close_tag_required = TRUE; |
|
|
|
|
|
/** |
|
|
* Flag to render content or not. |
|
|
* set to FALSE to not render content. |
|
|
* ie <img src=hotchick.png> |
|
|
* @var boolean |
|
|
* @access private |
|
|
*/ |
|
|
var $_content_required = TRUE; |
|
|
|
|
|
/** |
|
|
* Flag to place a newline after open tag. |
|
|
* some tags are nice to have a \n after |
|
|
* to make reading of html easier. |
|
|
* ie <table> |
|
|
* @var boolean |
|
|
* @access public |
|
|
*/ |
|
|
var $newline_after_opentag = TRUE; |
|
|
|
|
|
/** |
|
|
* Flag to place a newline after close tag. |
|
|
* usefull for maintaining nice output inside |
|
|
* a table |
|
|
* @var boolean |
|
|
* @access public |
|
|
*/ |
|
|
var $newline_after_closetag = TRUE; |
|
|
|
|
|
/** |
|
|
* Flag to tell the renderer to NEVER |
|
|
* to render the tag name in lower case |
|
|
* no matter what |
|
|
* @var boolean |
|
|
* @access private |
|
|
*/ |
|
|
var $_always_upper_case = FALSE; |
|
|
|
|
|
/** |
|
|
* Flag to tell the renderer to NEVER |
|
|
* to render the tag name in upper case |
|
|
* no matter what |
|
|
* @var boolean |
|
|
* @access private |
|
|
*/ |
|
|
var $_always_lower_case = FALSE; |
|
|
|
|
|
/** |
|
|
* Automatically wrap ALL content |
|
|
* inside the <![CDATA[ CONTENT ]]> |
|
|
* tag |
|
|
* |
|
|
* @var boolean |
|
|
*/ |
|
|
var $_cdata_content_wrap = FALSE; |
|
|
|
|
|
|
|
|
/** |
|
|
* holds the tag prefix |
|
|
* |
|
|
*/ |
|
|
var $_tag_prefix = "<"; |
|
|
|
|
|
/** |
|
|
* holds the tag postfix |
|
|
* |
|
|
*/ |
|
|
var $_tag_postfix = ">"; |
|
|
|
|
|
|
|
|
|
|
56 |
|
|
57 |
/** |
/** |
58 |
* The constructor |
* The constructor |
72 |
$num_args = func_num_args(); |
$num_args = func_num_args(); |
73 |
for ($i=2;$i<$num_args;$i++) { |
for ($i=2;$i<$num_args;$i++) { |
74 |
$this->add(func_get_arg($i)); |
$this->add(func_get_arg($i)); |
75 |
} |
} |
76 |
|
|
77 |
|
$this->_set_flags(); |
78 |
} |
} |
79 |
|
|
80 |
|
|
92 |
//based on the data |
//based on the data |
93 |
$this->_prepare_flags(); |
$this->_prepare_flags(); |
94 |
|
|
95 |
//build the open tag and its |
//return $xml; |
96 |
//attributes |
return $this->_render_open_tag( $indent_level ) . |
97 |
$xml = $this->_render_open_tag( $indent_level ); |
$this->_render_content( $indent_level ) . |
98 |
|
$this->_render_close_tag( $indent_level ); |
|
//build the content or PCDATA |
|
|
$xml .= $this->_render_content( $indent_level ); |
|
|
|
|
|
//build the close tag |
|
|
//if required. |
|
|
$xml .= $this->_render_close_tag( $indent_level ); |
|
|
|
|
|
return $xml; |
|
99 |
} |
} |
100 |
|
|
101 |
|
|
105 |
/* attributes and PCDATA */ |
/* attributes and PCDATA */ |
106 |
/****************************************/ |
/****************************************/ |
107 |
|
|
108 |
|
/** |
109 |
|
* This method is used to set the bitmask |
110 |
|
* flags for this tag. It tells the |
111 |
|
* class how to render the tag. |
112 |
|
* |
113 |
|
* NOTE: the child class can override this |
114 |
|
* to set the options |
115 |
|
*/ |
116 |
|
function _set_flags() { |
117 |
|
parent::_set_flags(); |
118 |
|
$this->_flags |= _NEWLINEAFTEROPENTAG | _NEWLINEAFTERCLOSETAG | |
119 |
|
_CONTENTREQUIRED | _CLOSETAGREQUIRED; |
120 |
|
} |
121 |
|
|
122 |
/** |
/** |
123 |
* This method sets the name of the tag |
* This method sets the name of the tag |
202 |
* @param boolean $flag TRUE or FALSE |
* @param boolean $flag TRUE or FALSE |
203 |
*/ |
*/ |
204 |
function set_newline_after_opentag( $flag ) { |
function set_newline_after_opentag( $flag ) { |
205 |
$this->newline_after_opentag = $flag; |
if ($flag) { |
206 |
|
$this->_flags |= _NEWLINEAFTEROPENTAG; |
207 |
|
} else{ |
208 |
|
$this->_flags &= ~_NEWLINEAFTEROPENTAG; |
209 |
|
} |
210 |
} |
} |
211 |
|
|
212 |
/** |
/** |
214 |
* @param boolean $flag TRUE or FALSE |
* @param boolean $flag TRUE or FALSE |
215 |
*/ |
*/ |
216 |
function set_newline_after_closetag( $flag ) { |
function set_newline_after_closetag( $flag ) { |
217 |
$this->newline_after_closetag = $flag; |
if ($flag) { |
218 |
|
$this->_flags |= _NEWLINEAFTERCLOSETAG; |
219 |
|
} else{ |
220 |
|
$this->_flags &= ~_NEWLINEAFTERCLOSETAG; |
221 |
|
} |
222 |
|
} |
223 |
|
|
224 |
|
/** |
225 |
|
* This method turns on the automatic wrapping |
226 |
|
* of the tag's content inside the CDATA wrapper |
227 |
|
* for XML |
228 |
|
* |
229 |
|
* @param boolean $flag TRUE or FALSE |
230 |
|
*/ |
231 |
|
function set_cdata_flag($flag) { |
232 |
|
if ($flag) { |
233 |
|
$this->_flags |= _CDATACONTENTWRAP; |
234 |
|
$this->set_collapse(TRUE); |
235 |
|
} else{ |
236 |
|
$this->_flags &= ~_CDATACONTENTWRAP; |
237 |
|
} |
238 |
} |
} |
239 |
|
|
240 |
/** |
/** |
245 |
* DEFAULT: TRUE; |
* DEFAULT: TRUE; |
246 |
*/ |
*/ |
247 |
function set_collapse($collapse=TRUE, $indent=TRUE) { |
function set_collapse($collapse=TRUE, $indent=TRUE) { |
248 |
$this->_collapse_flag = $collapse; |
if ($collapse) { |
249 |
|
$this->_flags |= _COLLAPSE; |
250 |
|
} else { |
251 |
|
$this->_flags &= ~_COLLAPSE; |
252 |
|
} |
253 |
|
|
254 |
$this->set_newline_after_opentag(FALSE); |
$this->set_newline_after_opentag(FALSE); |
255 |
$this->set_indent_flag($indent); |
$this->set_indent_flag($indent); |
257 |
$this->set_newline_after_closetag(TRUE); |
$this->set_newline_after_closetag(TRUE); |
258 |
} else { |
} else { |
259 |
$this->set_newline_after_closetag(FALSE); |
$this->set_newline_after_closetag(FALSE); |
260 |
} |
} |
261 |
} |
} |
262 |
|
|
263 |
/** |
/** |
268 |
* |
* |
269 |
*/ |
*/ |
270 |
function _prepare_flags() { |
function _prepare_flags() { |
271 |
if ($this->_content_required) { |
if ($this->_flags & _CONTENTREQUIRED) { |
272 |
if ($this->count_content() == 1 || $this->count_content() == 0) { |
if ($this->count_content() == 1) { |
273 |
if (!is_object($this->_content[0])) { |
if (!is_object($this->_content[0])) { |
274 |
//ok looks like this object has only |
//ok looks like this object has only |
275 |
//1 data for content and its a string. |
//1 data for content and its a string. |
276 |
if ( !strstr($this->_content[0], "\n") ) { |
if ( !strstr($this->_content[0], "\n") ) { |
277 |
$this->newline_after_opentag = FALSE; |
$this->_flags &= ~_NEWLINEAFTEROPENTAG; |
278 |
} |
} |
279 |
} |
} |
280 |
} |
} else if ($this->count_content() == 0) { |
281 |
|
$this->_flags &= ~(_CONTENTREQUIRED | _CLOSETAGREQUIRED); |
282 |
|
} |
283 |
} |
} |
284 |
} |
} |
285 |
|
|
298 |
* close tag and no content? |
* close tag and no content? |
299 |
*/ |
*/ |
300 |
function _render_open_tag( $indent_level, $finish_slash=TRUE ) { |
function _render_open_tag( $indent_level, $finish_slash=TRUE ) { |
|
|
|
301 |
//get the indent level |
//get the indent level |
302 |
$indent = $this->_render_indent( $indent_level ); |
$indent = $this->_render_indent( $indent_level ); |
303 |
|
|
304 |
//build the tag |
//build the tag |
305 |
$tag = $this->_tag; |
if ($this->_flags & _ALWAYS_LOWERCASE) { |
306 |
if ($this->_always_lower_case) { |
$this->_tag = strtolower($this->_tag); |
307 |
$tag = strtolower($tag); |
} else if ($this->_flags & _ALWAYS_UPPERCASE) { |
308 |
} else if ($this->_always_upper_case) { |
$this->_tag = strtoupper($this->_tag); |
|
$tag = strtoupper($tag); |
|
309 |
} |
} |
310 |
$xml = $indent . $this->_tag_prefix . $tag; |
//save on mem |
311 |
|
$xml = $indent . (@$this->_tag_prefix ? $this->_tag_prefix : _TAG_PREFIX) . $this->_tag; |
312 |
|
|
313 |
foreach( $this->_attributes as $name => $value) { |
foreach( $this->_attributes as $name => $value) { |
314 |
$xml .= $this->_build_attribute_string($name, $value); |
$xml .= $this->_build_attribute_string($name, $value); |
315 |
} |
} |
316 |
|
|
317 |
if ( !$this->_close_tag_required && !$this->_no_finish_slash_xhtml |
if ( !($this->_flags & _CLOSETAGREQUIRED) && !($this->_flags & _NOFINISHSLASHXHTML) |
318 |
&& $finish_slash ) { |
&& $finish_slash ) { |
319 |
$xml .= " /".$this->_tag_postfix; |
$xml .= " /".(@$this->_tag_postfix ? $this->_tag_postfix : _TAG_SUFFIX); |
320 |
} else { |
} else { |
321 |
$xml .= $this->_tag_postfix; |
$xml .= (@$this->_tag_postfix ? $this->_tag_postfix : _TAG_SUFFIX); |
322 |
} |
} |
323 |
|
|
324 |
if ($this->newline_after_opentag) { |
if ($this->_flags & _NEWLINEAFTEROPENTAG) { |
325 |
$xml .= "\n"; |
$xml .= "\n"; |
326 |
} |
} |
327 |
|
|
328 |
return $xml; |
return $xml; |
329 |
} |
} |
330 |
|
|
339 |
function _render_content( $indent_level, $output_debug=0 ) { |
function _render_content( $indent_level, $output_debug=0 ) { |
340 |
|
|
341 |
//walk through the content |
//walk through the content |
342 |
$xml = ''; |
$xml = ''; |
343 |
foreach ($this->_content as $item) { |
for ($x=0; $x<=$this->_data_count-1; $x++) { |
344 |
|
$item = &$this->_content[$x]; |
345 |
if (method_exists($item, "render")) { |
if (method_exists($item, "render")) { |
346 |
if ($this->_collapse_flag && method_exists($item, "set_collapse")) { |
if (($this->_flags & _COLLAPSE) && method_exists($item, "set_collapse")) { |
347 |
$item->set_collapse(TRUE, FALSE); |
$item->set_collapse(TRUE, FALSE); |
348 |
} |
} |
349 |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
353 |
} |
} |
354 |
$xml .= $item->render($indent, $output_debug); |
$xml .= $item->render($indent, $output_debug); |
355 |
} else { |
} else { |
356 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
357 |
$xml .= $item; |
$xml .= $item; |
358 |
} else { |
} else { |
359 |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
361 |
} else { |
} else { |
362 |
$indent = $indent_level + 1; |
$indent = $indent_level + 1; |
363 |
} |
} |
364 |
$indent = $this->_render_indent($indent + 1); |
$indent = $this->_render_indent($indent); |
365 |
if ($this->newline_after_opentag) { |
if ($this->_flags & _NEWLINEAFTEROPENTAG) { |
366 |
$item = str_replace("\n", "\n" . $indent, $item); |
$item = str_replace("\n", "\n" . $indent, $item); |
367 |
$xml .= $indent . $item . "\n"; |
$xml .= $indent . $item . "\n"; |
368 |
} else { |
} else { |
372 |
} |
} |
373 |
} |
} |
374 |
} |
} |
375 |
if ($this->_cdata_content_wrap) { |
if ($this->_flags & _CDATACONTENTWRAP) { |
376 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
377 |
$xml = "<![CDATA[ ".$xml." ]]>"; |
$xml = "<![CDATA[ ".$xml." ]]>"; |
378 |
} else { |
} else { |
379 |
$indent = $this->_render_indent($indent+1); |
$indent = $this->_render_indent($indent+1); |
394 |
* @param int - the indent level |
* @param int - the indent level |
395 |
*/ |
*/ |
396 |
function _render_close_tag( $indent_level ) { |
function _render_close_tag( $indent_level ) { |
397 |
if (!$this->_close_tag_required) { |
if (!($this->_flags & _CLOSETAGREQUIRED)) { |
398 |
return ''; |
return ''; |
399 |
} |
} |
400 |
|
|
401 |
$indent = ""; |
$indent = ""; |
402 |
if ($this->indent_flag && $this->newline_after_opentag) { |
if (($this->_flags & _INDENT) && ($this->_flags & _NEWLINEAFTEROPENTAG)) { |
403 |
$indent = $this->_render_indent($indent_level); |
$indent = $this->_render_indent($indent_level); |
404 |
} |
} |
405 |
$str = $indent ."</".$this->_tag.">"; |
$str = $indent ."</".$this->_tag.">"; |
406 |
|
|
407 |
if ($this->newline_after_closetag) { |
if ($this->_flags & _NEWLINEAFTERCLOSETAG) { |
408 |
$str .= "\n"; |
$str .= "\n"; |
409 |
} |
} |
410 |
|
|
422 |
* to be added to the tag. |
* to be added to the tag. |
423 |
*/ |
*/ |
424 |
function _build_attribute_string($name, $value) { |
function _build_attribute_string($name, $value) { |
425 |
if ( ((int)$name - 0) === $name) { |
return " ".$name."=\"".$value."\""; |
|
$returnval = " ".$value; |
|
|
} else if ( $value === NULL ) { |
|
|
$returnval = " ".$name; |
|
|
} else { |
|
|
$returnval= " ".$name."=\"".$value."\""; |
|
|
} |
|
|
return $returnval; |
|
426 |
} |
} |
427 |
} |
} |
428 |
?> |
?> |