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 |
/** |
/** |
229 |
* DEFAULT: TRUE; |
* DEFAULT: TRUE; |
230 |
*/ |
*/ |
231 |
function set_collapse($collapse=TRUE, $indent=TRUE) { |
function set_collapse($collapse=TRUE, $indent=TRUE) { |
232 |
$this->_collapse_flag = $collapse; |
if ($collapse) { |
233 |
|
$this->_flags |= _COLLAPSE; |
234 |
|
} else { |
235 |
|
$this->_flags &= ~_COLLAPSE; |
236 |
|
} |
237 |
|
|
238 |
$this->set_newline_after_opentag(FALSE); |
$this->set_newline_after_opentag(FALSE); |
239 |
$this->set_indent_flag($indent); |
$this->set_indent_flag($indent); |
241 |
$this->set_newline_after_closetag(TRUE); |
$this->set_newline_after_closetag(TRUE); |
242 |
} else { |
} else { |
243 |
$this->set_newline_after_closetag(FALSE); |
$this->set_newline_after_closetag(FALSE); |
244 |
} |
} |
245 |
} |
} |
246 |
|
|
247 |
/** |
/** |
252 |
* |
* |
253 |
*/ |
*/ |
254 |
function _prepare_flags() { |
function _prepare_flags() { |
255 |
if ($this->_content_required) { |
if ($this->_flags & _CONTENTREQUIRED) { |
256 |
if ($this->count_content() == 1 || $this->count_content() == 0) { |
if ($this->count_content() == 1) { |
257 |
if (!is_object($this->_content[0])) { |
if (!is_object($this->_content[0])) { |
258 |
//ok looks like this object has only |
//ok looks like this object has only |
259 |
//1 data for content and its a string. |
//1 data for content and its a string. |
260 |
if ( !strstr($this->_content[0], "\n") ) { |
if ( !strstr($this->_content[0], "\n") ) { |
261 |
$this->newline_after_opentag = FALSE; |
$this->_flags &= ~_NEWLINEAFTEROPENTAG; |
262 |
} |
} |
263 |
} |
} |
264 |
} |
} |
280 |
* close tag and no content? |
* close tag and no content? |
281 |
*/ |
*/ |
282 |
function _render_open_tag( $indent_level, $finish_slash=TRUE ) { |
function _render_open_tag( $indent_level, $finish_slash=TRUE ) { |
|
|
|
283 |
//get the indent level |
//get the indent level |
284 |
$indent = $this->_render_indent( $indent_level ); |
$indent = $this->_render_indent( $indent_level ); |
285 |
|
|
286 |
//build the tag |
//build the tag |
287 |
$tag = $this->_tag; |
if ($this->_flags & _ALWAYS_LOWERCASE) { |
288 |
if ($this->_always_lower_case) { |
$this->_tag = strtolower($this->_tag); |
289 |
$tag = strtolower($tag); |
} else if ($this->_flags & _ALWAYS_UPPERCASE) { |
290 |
} else if ($this->_always_upper_case) { |
$this->_tag = strtoupper($this->_tag); |
|
$tag = strtoupper($tag); |
|
291 |
} |
} |
292 |
$xml = $indent . $this->_tag_prefix . $tag; |
//save on mem |
293 |
|
$xml = $indent . ($this->_tag_prefix ? $this->_tag_prefix : _TAG_PREFIX) . $this->_tag; |
294 |
|
|
295 |
foreach( $this->_attributes as $name => $value) { |
foreach( $this->_attributes as $name => $value) { |
296 |
$xml .= $this->_build_attribute_string($name, $value); |
$xml .= $this->_build_attribute_string($name, $value); |
297 |
} |
} |
298 |
|
|
299 |
if ( !$this->_close_tag_required && !$this->_no_finish_slash_xhtml |
if ( !($this->_flags & _CLOSETAGREQUIRED) && !($this->_flags & _NOFINISHSLASHXHTML) |
300 |
&& $finish_slash ) { |
&& $finish_slash ) { |
301 |
$xml .= " /".$this->_tag_postfix; |
$xml .= " /".($this->_tag_postfix ? $this->_tag_postfix : _TAG_SUFFIX); |
302 |
} else { |
} else { |
303 |
$xml .= $this->_tag_postfix; |
$xml .= ($this->_tag_postfix ? $this->_tag_postfix : _TAG_SUFFIX); |
304 |
} |
} |
305 |
|
|
306 |
if ($this->newline_after_opentag) { |
if ($this->_flags & _NEWLINEAFTEROPENTAG) { |
307 |
$xml .= "\n"; |
$xml .= "\n"; |
308 |
} |
} |
309 |
|
|
310 |
return $xml; |
return $xml; |
311 |
} |
} |
312 |
|
|
321 |
function _render_content( $indent_level, $output_debug=0 ) { |
function _render_content( $indent_level, $output_debug=0 ) { |
322 |
|
|
323 |
//walk through the content |
//walk through the content |
324 |
$xml = ''; |
$xml = ''; |
325 |
foreach ($this->_content as $item) { |
for ($x=0; $x<=$this->_data_count-1; $x++) { |
326 |
|
$item = &$this->_content[$x]; |
327 |
if (method_exists($item, "render")) { |
if (method_exists($item, "render")) { |
328 |
if ($this->_collapse_flag && method_exists($item, "set_collapse")) { |
if (($this->_flags & _COLLAPSE) && method_exists($item, "set_collapse")) { |
329 |
$item->set_collapse(TRUE, FALSE); |
$item->set_collapse(TRUE, FALSE); |
330 |
} |
} |
331 |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
335 |
} |
} |
336 |
$xml .= $item->render($indent, $output_debug); |
$xml .= $item->render($indent, $output_debug); |
337 |
} else { |
} else { |
338 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
339 |
$xml .= $item; |
$xml .= $item; |
340 |
} else { |
} else { |
341 |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
344 |
$indent = $indent_level + 1; |
$indent = $indent_level + 1; |
345 |
} |
} |
346 |
$indent = $this->_render_indent($indent + 1); |
$indent = $this->_render_indent($indent + 1); |
347 |
if ($this->newline_after_opentag) { |
if ($this->_flags & _NEWLINEAFTEROPENTAG) { |
348 |
$item = str_replace("\n", "\n" . $indent, $item); |
$item = str_replace("\n", "\n" . $indent, $item); |
349 |
$xml .= $indent . $item . "\n"; |
$xml .= $indent . $item . "\n"; |
350 |
} else { |
} else { |
354 |
} |
} |
355 |
} |
} |
356 |
} |
} |
357 |
if ($this->_cdata_content_wrap) { |
if ($this->_flags & _CDATACONTENTWRAP) { |
358 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
359 |
$xml = "<![CDATA[ ".$xml." ]]>"; |
$xml = "<![CDATA[ ".$xml." ]]>"; |
360 |
} else { |
} else { |
361 |
$indent = $this->_render_indent($indent+1); |
$indent = $this->_render_indent($indent+1); |
376 |
* @param int - the indent level |
* @param int - the indent level |
377 |
*/ |
*/ |
378 |
function _render_close_tag( $indent_level ) { |
function _render_close_tag( $indent_level ) { |
379 |
if (!$this->_close_tag_required) { |
if (!($this->_flags & _CLOSETAGREQUIRED)) { |
380 |
return ''; |
return ''; |
381 |
} |
} |
382 |
|
|
383 |
$indent = ""; |
$indent = ""; |
384 |
if ($this->indent_flag && $this->newline_after_opentag) { |
if (($this->_flags & _INDENT) && ($this->_flags & _NEWLINEAFTEROPENTAG)) { |
385 |
$indent = $this->_render_indent($indent_level); |
$indent = $this->_render_indent($indent_level); |
386 |
} |
} |
387 |
$str = $indent ."</".$this->_tag.">"; |
$str = $indent ."</".$this->_tag.">"; |
388 |
|
|
389 |
if ($this->newline_after_closetag) { |
if ($this->_flags & _NEWLINEAFTERCLOSETAG) { |
390 |
$str .= "\n"; |
$str .= "\n"; |
391 |
} |
} |
392 |
|
|