--- nfo/php/libs/com.newsblob.phphtmllib/XMLTagClass.inc 2003/01/30 03:29:08 1.1
+++ nfo/php/libs/com.newsblob.phphtmllib/XMLTagClass.inc 2003/02/22 20:55:24 1.2
@@ -3,7 +3,7 @@
/**
* Holds the XMLTagClass
*
- * $Id: XMLTagClass.inc,v 1.1 2003/01/30 03:29:08 jonen Exp $
+ * $Id: XMLTagClass.inc,v 1.2 2003/02/22 20:55:24 jonen Exp $
*
* @author Walter A. Boring IV
* @package phpHtmlLib
@@ -53,85 +53,6 @@
*/
var $_attributes = array();
- /**
- * flag to render close tag or not.
- * set to FALSE if no close tag is needed
- * ie
- * @var boolean
- * @access private
- */
- var $_close_tag_required = TRUE;
-
- /**
- * Flag to render content or not.
- * set to FALSE to not render content.
- * ie
- * @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
- * @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
- * tag
- *
- * @var boolean
- */
- var $_cdata_content_wrap = FALSE;
-
-
- /**
- * holds the tag prefix
- *
- */
- var $_tag_prefix = "<";
-
- /**
- * holds the tag postfix
- *
- */
- var $_tag_postfix = ">";
-
-
-
/**
* The constructor
@@ -151,7 +72,9 @@
$num_args = func_num_args();
for ($i=2;$i<$num_args;$i++) {
$this->add(func_get_arg($i));
- }
+ }
+
+ $this->_set_flags();
}
@@ -169,18 +92,10 @@
//based on the data
$this->_prepare_flags();
- //build the open tag and its
- //attributes
- $xml = $this->_render_open_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;
+ //return $xml;
+ return $this->_render_open_tag( $indent_level ) .
+ $this->_render_content( $indent_level ) .
+ $this->_render_close_tag( $indent_level );
}
@@ -190,6 +105,19 @@
/* attributes and PCDATA */
/****************************************/
+ /**
+ * 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
+ */
+ function _set_flags() {
+ parent::_set_flags();
+ $this->_flags |= _NEWLINEAFTEROPENTAG | _NEWLINEAFTERCLOSETAG |
+ _CONTENTREQUIRED | _CLOSETAGREQUIRED;
+ }
/**
* This method sets the name of the tag
@@ -274,7 +202,11 @@
* @param boolean $flag TRUE or FALSE
*/
function set_newline_after_opentag( $flag ) {
- $this->newline_after_opentag = $flag;
+ if ($flag) {
+ $this->_flags |= _NEWLINEAFTEROPENTAG;
+ } else{
+ $this->_flags &= ~_NEWLINEAFTEROPENTAG;
+ }
}
/**
@@ -282,7 +214,11 @@
* @param boolean $flag TRUE or FALSE
*/
function set_newline_after_closetag( $flag ) {
- $this->newline_after_closetag = $flag;
+ if ($flag) {
+ $this->_flags |= _NEWLINEAFTERCLOSETAG;
+ } else{
+ $this->_flags &= ~_NEWLINEAFTERCLOSETAG;
+ }
}
/**
@@ -293,7 +229,11 @@
* DEFAULT: TRUE;
*/
function set_collapse($collapse=TRUE, $indent=TRUE) {
- $this->_collapse_flag = $collapse;
+ if ($collapse) {
+ $this->_flags |= _COLLAPSE;
+ } else {
+ $this->_flags &= ~_COLLAPSE;
+ }
$this->set_newline_after_opentag(FALSE);
$this->set_indent_flag($indent);
@@ -301,7 +241,7 @@
$this->set_newline_after_closetag(TRUE);
} else {
$this->set_newline_after_closetag(FALSE);
- }
+ }
}
/**
@@ -312,13 +252,13 @@
*
*/
function _prepare_flags() {
- if ($this->_content_required) {
- if ($this->count_content() == 1 || $this->count_content() == 0) {
+ if ($this->_flags & _CONTENTREQUIRED) {
+ if ($this->count_content() == 1) {
if (!is_object($this->_content[0])) {
//ok looks like this object has only
//1 data for content and its a string.
if ( !strstr($this->_content[0], "\n") ) {
- $this->newline_after_opentag = FALSE;
+ $this->_flags &= ~_NEWLINEAFTEROPENTAG;
}
}
}
@@ -340,34 +280,33 @@
* close tag and no content?
*/
function _render_open_tag( $indent_level, $finish_slash=TRUE ) {
-
//get the indent level
$indent = $this->_render_indent( $indent_level );
//build the tag
- $tag = $this->_tag;
- if ($this->_always_lower_case) {
- $tag = strtolower($tag);
- } else if ($this->_always_upper_case) {
- $tag = strtoupper($tag);
+ if ($this->_flags & _ALWAYS_LOWERCASE) {
+ $this->_tag = strtolower($this->_tag);
+ } else if ($this->_flags & _ALWAYS_UPPERCASE) {
+ $this->_tag = strtoupper($this->_tag);
}
- $xml = $indent . $this->_tag_prefix . $tag;
+ //save on mem
+ $xml = $indent . ($this->_tag_prefix ? $this->_tag_prefix : _TAG_PREFIX) . $this->_tag;
foreach( $this->_attributes as $name => $value) {
$xml .= $this->_build_attribute_string($name, $value);
}
- if ( !$this->_close_tag_required && !$this->_no_finish_slash_xhtml
+ if ( !($this->_flags & _CLOSETAGREQUIRED) && !($this->_flags & _NOFINISHSLASHXHTML)
&& $finish_slash ) {
- $xml .= " /".$this->_tag_postfix;
+ $xml .= " /".($this->_tag_postfix ? $this->_tag_postfix : _TAG_SUFFIX);
} else {
- $xml .= $this->_tag_postfix;
+ $xml .= ($this->_tag_postfix ? $this->_tag_postfix : _TAG_SUFFIX);
}
- if ($this->newline_after_opentag) {
+ if ($this->_flags & _NEWLINEAFTEROPENTAG) {
$xml .= "\n";
}
-
+
return $xml;
}
@@ -382,10 +321,11 @@
function _render_content( $indent_level, $output_debug=0 ) {
//walk through the content
- $xml = '';
- foreach ($this->_content as $item) {
+ $xml = '';
+ 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);
}
if ($indent_level == INDENT_LEFT_JUSTIFY) {
@@ -395,7 +335,7 @@
}
$xml .= $item->render($indent, $output_debug);
} else {
- if ($this->_collapse_flag) {
+ if ($this->_flags & _COLLAPSE) {
$xml .= $item;
} else {
if ($indent_level == INDENT_LEFT_JUSTIFY) {
@@ -404,7 +344,7 @@
$indent = $indent_level + 1;
}
$indent = $this->_render_indent($indent + 1);
- if ($this->newline_after_opentag) {
+ if ($this->_flags & _NEWLINEAFTEROPENTAG) {
$item = str_replace("\n", "\n" . $indent, $item);
$xml .= $indent . $item . "\n";
} else {
@@ -414,8 +354,8 @@
}
}
}
- if ($this->_cdata_content_wrap) {
- if ($this->_collapse_flag) {
+ if ($this->_flags & _CDATACONTENTWRAP) {
+ if ($this->_flags & _COLLAPSE) {
$xml = "";
} else {
$indent = $this->_render_indent($indent+1);
@@ -436,17 +376,17 @@
* @param int - the indent level
*/
function _render_close_tag( $indent_level ) {
- if (!$this->_close_tag_required) {
+ if (!($this->_flags & _CLOSETAGREQUIRED)) {
return '';
}
$indent = "";
- if ($this->indent_flag && $this->newline_after_opentag) {
+ if (($this->_flags & _INDENT) && ($this->_flags & _NEWLINEAFTEROPENTAG)) {
$indent = $this->_render_indent($indent_level);
}
$str = $indent ."".$this->_tag.">";
- if ($this->newline_after_closetag) {
+ if ($this->_flags & _NEWLINEAFTERCLOSETAG) {
$str .= "\n";
}