/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/HTMLTagClass.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/HTMLTagClass.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by jonen, Thu Jan 30 03:29:08 2003 UTC revision 1.4 by jonen, Thu May 6 16:23:38 2004 UTC
# Line 26  require_once( $phphtmllib."/XMLTagClass. Line 26  require_once( $phphtmllib."/XMLTagClass.
26   *   *
27   * @author      Walter A. Boring IV <waboring@buildabetterweb.com>   * @author      Walter A. Boring IV <waboring@buildabetterweb.com>
28   * @link http://phphtmllib.sourceforge.net   * @link http://phphtmllib.sourceforge.net
29     * @package phpHtmlLib
30   */   */
31  class HTMLTagClass extends XMLTagClass {  class HTMLTagClass extends XMLTagClass {
32    
   
         /**  
          * Flag to tell the renderer not to  
          * place the /> if we are in xhtml  
          * compliant mode.  
          */  
         var $_no_finish_slash_xhtml = FALSE;  
   
   
         /**  
          * Flag to let us know to render XHTML 1.0  
          * compliant output. defaulted to FALSE  
          * @var boolean  
          * @access private  
          */  
         var $_xhtml_compliant = FALSE;  
   
         /**  
          * Flag to denote that this tag is  
          * depricated by the HTML standard.  
          *  
          */  
         var $_depricated = FALSE;  
   
33          /**          /**
34           * the list of tag attributes that we           * the list of tag attributes that we
35           * should create a clickable link for           * should create a clickable link for
36           * when in debug mode.           * when in debug mode.
37         *
38         * We comment this declaration out
39         * to save memory, since only a small
40         * number of tags use it
41         *
42           * @var  array           * @var  array
43           * @access private           * @access private
44           */           */
45          var $_debug_link_attributes = array("background");          //var $_debug_link_attributes = array("background");
46    
47          /**          /**
48           * The list of attributes not to render           * The list of attributes not to render
49           * if HTML_RENDER_TYPE is "XHTML STRICT"           * if $GLOBALS["HTML_RENDER_TYPE"] is "XHTML STRICT"
50           *           *
51         * We comment this declaration out
52         * to save memory, since only a small
53         * number of tags use it
54         *
55           */           */
56          var $_xhtml_strict_attributes = array();          //var $_xhtml_strict_attributes = array();
57    
58    
59          /**          /**
# Line 75  class HTMLTagClass extends XMLTagClass { Line 61  class HTMLTagClass extends XMLTagClass {
61           * htmlentities() on if we are in XHTML_STRICT           * htmlentities() on if we are in XHTML_STRICT
62           * mode.  Otherwise the validator complains about           * mode.  Otherwise the validator complains about
63           * html characters such as &.           * html characters such as &.
64         *
65         * We comment this declaration out
66         * to save memory, since only a small
67         * number of tags use it
68         *
69           * @var array.           * @var array.
70           * @access private           * @access private
71           */           */
72          var $_htmlentities_attributes = array();          //var $_htmlentities_attributes = array();
73    
74    
75          /**          /**
76           * Class Constructor           * Class Constructor
77         *
78         * {@source }
79         *
80           * @param   array - Associative array of           * @param   array - Associative array of
81           *                  name="value" pairs of           *                  name="value" pairs of
82           *                  tag atributes.           *                  tag atributes.
# Line 92  class HTMLTagClass extends XMLTagClass { Line 86  class HTMLTagClass extends XMLTagClass {
86           *                  of parameters that will           *                  of parameters that will
87           *                  be added to the content           *                  be added to the content
88           *                  of the tag automatically.           *                  of the tag automatically.
          *  
          * @access   public  
89           */           */
90          function HTMLTagClass( $attributes=NULL ) {          function HTMLTagClass( $attributes=NULL ) {
91                  if ( $attributes ) {                  if ( $attributes ) {
92                          $this->set_tag_attributes( $attributes );                          $this->set_tag_attributes( $attributes );
93                  }                  }
94    
95            //set the default tag options
96            $this->_set_flags();
97    
98                  //add the content if any.                  //add the content if any.
99                  $num_args = func_num_args();                  $num_args = func_num_args();
100                  for ($i = 1; $i < $num_args; $i++) {                  for ($i = 1; $i < $num_args; $i++) {
# Line 111  class HTMLTagClass extends XMLTagClass { Line 106  class HTMLTagClass extends XMLTagClass {
106                  //this is a magic test.  It assumes that                  //this is a magic test.  It assumes that
107                  //someone has created the define for                  //someone has created the define for
108                  //HTML_RENDER_TYPE                  //HTML_RENDER_TYPE
109                  if ( HTML_RENDER_TYPE == XHTML ||                  if ( $GLOBALS["HTML_RENDER_TYPE"] == XHTML ||
110                           HTML_RENDER_TYPE == XHTML_STRICT ) {                           $GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT ) {
111                          $this->_xhtml_compliant = TRUE;                          $this->_flags |= _XHTMLCOMPLIANT;
112    
113                  }                  }
114    
115                  //if the tag is depricated                  //if the tag is depricated
116                  //we raise an alert.                  //we raise an alert.
117                  if ( $this->_depricated ) {                  if ( $this->_flags & _DEPRICATED ) {
118                          trigger_error(htmlspecialchars($this->_tag) . " has been depricated in HTML 4.0", E_USER_NOTICE);                          trigger_error(htmlspecialchars($this->_tag) . " has been depricated in HTML 4.0", E_USER_NOTICE);
119                  }                  }
120          }          }
# Line 127  class HTMLTagClass extends XMLTagClass { Line 122  class HTMLTagClass extends XMLTagClass {
122    
123          /**          /**
124           * Renders the tag, attributes, content and close tag.           * Renders the tag, attributes, content and close tag.
125         *
126         * {@source }
127         *
128           * @param   int    $indent_level    the indentation level for this tag.           * @param   int    $indent_level    the indentation level for this tag.
129         * @param  boolean output in html viewable mode
130           * @return  string           * @return  string
          * @access  public  
131           */           */
132          function render($indent_level=NULL, $output_debug=0) {          function render($indent_level=NULL, $output_debug=0) {
133    
# Line 138  class HTMLTagClass extends XMLTagClass { Line 136  class HTMLTagClass extends XMLTagClass {
136                  $this->_prepare_flags();                  $this->_prepare_flags();
137    
138                  if ( $indent_level==NULL ) {                  if ( $indent_level==NULL ) {
139                          $indent_level = $this->_indent_level;                          $indent_level = 0;
140                  }                  }
141    
142                  $html  = $this->_render_tag($indent_level, $output_debug);                  $html = $this->_render_tag($indent_level, $output_debug);
143    
144                  if ( $this->_content_required ) {                  if ( $this->_flags & _CONTENTREQUIRED) {
145                          $html .= $this->_render_content($indent_level, $output_debug);                          $html .= $this->_render_content($indent_level, $output_debug);
146                  }                  }
147                  if ( $this->_close_tag_required ) {                  if ( $this->_flags & _CLOSETAGREQUIRED ) {
148                          $html .= $this->_render_close_tag($indent_level, $output_debug);                          $html .= $this->_render_close_tag($indent_level, $output_debug);
149                  }                  }
150    
# Line 161  class HTMLTagClass extends XMLTagClass { Line 159  class HTMLTagClass extends XMLTagClass {
159       * This function is a shorthand helper       * This function is a shorthand helper
160       * to setting the style attribute on a       * to setting the style attribute on a
161       * tag.       * tag.
162         *
163         * {@source }
164       *       *
165       * @param string - the style value.       * @param string - the style value.
166         * @return none
167       */       */
168      function set_style( $value ) {      function set_style( $value ) {
169          $this->set_tag_attribute("style", $value);          $this->set_tag_attribute("style", $value);
# Line 172  class HTMLTagClass extends XMLTagClass { Line 173  class HTMLTagClass extends XMLTagClass {
173       * This function is a shorthand helper       * This function is a shorthand helper
174       * to setting the class attribute on a       * to setting the class attribute on a
175       * tag.       * tag.
176         *
177         * {@source }
178       *       *
179       * @param string - the class value.       * @param string - the class value.
180         * @return none
181       */       */
182      function set_class( $value ) {      function set_class( $value ) {
183          $this->set_tag_attribute("class", $value);          $this->set_tag_attribute("class", $value);
# Line 183  class HTMLTagClass extends XMLTagClass { Line 187  class HTMLTagClass extends XMLTagClass {
187       * This function is a shorthand helper       * This function is a shorthand helper
188       * to setting the id attribute on a       * to setting the id attribute on a
189       * tag.       * tag.
190         *
191         * {@source }
192       *       *
193       * @param string - the class value.       * @param string - the class value.
194         * @return none
195       */       */
196      function set_id( $value ) {      function set_id( $value ) {
197          $this->set_tag_attribute("id", $value);          $this->set_tag_attribute("id", $value);
# Line 197  class HTMLTagClass extends XMLTagClass { Line 204  class HTMLTagClass extends XMLTagClass {
204    
205          /**          /**
206           * renders the open tag. is <TABLE>           * renders the open tag. is <TABLE>
207           * @param   int    $indent_level    the indentation level for this tag.       *
208           * @return  string       * {@source }
209           * @access  private       * @access  private
210         *
211             * @param int the indentation level for this tag.
212             * @return string
213           */           */
214          function _render_tag($indent_level, $output_debug=0) {          function _render_tag($indent_level, $output_debug=0) {
215                  if ( $output_debug ) {                  if ( $output_debug ) {
216                          //lets call the special render tag debug function                          //lets call the special render tag debug function
217                          return $this->_render_tag_debug( $indent_level );                                      return $this->_render_tag_debug( $indent_level );            
218                  } else {                  } else {
219              return XMLTag::_render_open_tag($indent_level, $this->_xhtml_compliant);              return XMLTag::_render_open_tag($indent_level, $this->_flags & _XHTMLCOMPLIANT);
220                  }                  }
221          }          }
222    
223          /**          /**
224           * Renders all of the content.           * Renders all of the content.
225           * Content can be raw strings, or tag objects.           * Content can be raw strings, or tag objects.
226           * @param   int    $indent_level    the indentation level for this tag.       *
227         * {@source }
228         * @access private
229         *
230             * @param int the indentation level for this tag.
231           * @return  string           * @return  string
          * @access  private  
232           */           */
233          function _render_content($indent_level, $output_debug=0) {          function _render_content($indent_level, $output_debug=0) {
234                  if ( $output_debug ) {                  if ( $output_debug ) {
# Line 227  class HTMLTagClass extends XMLTagClass { Line 240  class HTMLTagClass extends XMLTagClass {
240    
241          /**          /**
242           * Renders the close tag (if needed)           * Renders the close tag (if needed)
243           * @param   int    $indent_level    the indentation level for this tag.       *
244           * @return  string       * {@source }
245           * @access  private       * @access private
246         *
247             * @param int the indentation level for this tag.
248             * @return string
249           */           */
250          function _render_close_tag($indent_level, $output_debug=0) {          function _render_close_tag($indent_level, $output_debug=0) {
251                  if ( $output_debug ) {                  if ( $output_debug ) {
# Line 246  class HTMLTagClass extends XMLTagClass { Line 262  class HTMLTagClass extends XMLTagClass {
262           * so we can override this by the child           * so we can override this by the child
263           * tag, so it can add a link on content or           * tag, so it can add a link on content or
264           * one of the attributes.             * one of the attributes.  
265         *
266         * {@source }
267         * @access private
268         *
269         * @param int the indentation level
270         * @return string
271           */           */
272          function _render_tag_debug($indent_level) {          function _render_tag_debug($indent_level) {
273    
274                  $indent = $this->_render_indent($indent_level, TRUE);                  $indent = $this->_render_indent($indent_level, TRUE);
275    
276                  $tag_prefix = htmlspecialchars( $this->_tag_prefix );                  $tag_prefix = htmlspecialchars( (@$this->_tag_prefix ? $this->_tag_prefix : _TAG_PREFIX));
277                  $tab_postfix = htmlspecialchars( $this->_tag_postfix );                  $tab_postfix = htmlspecialchars( (@$this->_tag_postfix ? $this->_tag_postfix : _TAG_SUFFIX));
278                  $str = $indent . $tag_prefix. "<span class=\"purple\" style=\"white-space:nowrap;\">";                  $str = $indent . $tag_prefix. "<span class=\"purple\" style=\"white-space:nowrap;\">";
279                  $str .= $this->_tag . "</span>";                  $str .= $this->_tag . "</span>";
280    
281                  if ( $this->_xhtml_compliant && !$this->_always_upper_case ) {                  if ( ($this->_flags & _XHTMLCOMPLIANT) && !($this->_flags & _ALWAYS_UPPERCASE) ) {
282                          //we have to have the tag name be lower case.                          //we have to have the tag name be lower case.
283                          $str = strtolower( $str );                          $str = strtolower( $str );
284                  }                  }
# Line 267  class HTMLTagClass extends XMLTagClass { Line 289  class HTMLTagClass extends XMLTagClass {
289    
290                  //if we want to output xhtml compliant code, we have to                  //if we want to output xhtml compliant code, we have to
291                  //render a special tag closing.                  //render a special tag closing.
292                  if ( $this->_xhtml_compliant ) {                  if ( $this->_flags & _XHTMLCOMPLIANT ) {
293                          //we have to render a special close for the                          //we have to render a special close for the
294                          //open tag, if the tag doesn't require a close                          //open tag, if the tag doesn't require a close
295                          //tag or content.                          //tag or content.
296                          if ( !$this->_close_tag_required && !$this->_no_finish_slash_xhtml ) {                          if ( !($this->_flags & _CLOSETAGREQUIRED) && !($this->_flags & _NOFINISHSLASHXHTML) ) {
297                                  $html = $str . "&nbsp;/&gt;";                                  $html = $str . "&nbsp;/&gt;";
298                          } else {                          } else {
299                                  $html = $str."&gt;";                                  $html = $str."&gt;";
# Line 280  class HTMLTagClass extends XMLTagClass { Line 302  class HTMLTagClass extends XMLTagClass {
302                          $html = $str."&gt;";                          $html = $str."&gt;";
303                  }                  }
304    
305                  if ( $this->newline_after_opentag ) {                  if ( $this->_flags & _NEWLINEAFTEROPENTAG ) {
306                          $html .= "<br>\n";                          $html .= "<br>\n";
307                  }                  }
308                  return $html;                  return $html;
# Line 292  class HTMLTagClass extends XMLTagClass { Line 314  class HTMLTagClass extends XMLTagClass {
314           * so it acts like view source.           * so it acts like view source.
315           *           *
316           * Content can be raw strings, or tag objects.           * Content can be raw strings, or tag objects.
317           * @param   int    $indent_level    the indentation level for this tag.       *
318           * @return  string       * {@source }
319           * @access  private       * @access private
320         *
321             * @param int the indentation level for this tag.
322             * @return string
323           */           */
324          function _render_content_debug($indent_level) {          function _render_content_debug($indent_level) {
325    
326                  $html = '';                  $html = '';
327                  //walk through the content                  //walk through the content
328                  foreach ($this->_content as $item) {                  for ($x=0; $x<=$this->_data_count; $x++) {
329                $item = &$this->_content[$x];
330                          if (method_exists($item, "render")) {                          if (method_exists($item, "render")) {
331                                  if ($this->_collapse_flag && method_exists($item, "set_collapse")) {                                  if (($this->_flags & _COLLAPSE) && method_exists($item, "set_collapse")) {
332                                                  $item->set_collapse(TRUE, FALSE);                                                  $item->set_collapse(TRUE, FALSE);
333                                  }                                  }
334                                  if ($indent_level == INDENT_LEFT_JUSTIFY) {                                  if ($indent_level == INDENT_LEFT_JUSTIFY) {
# Line 312  class HTMLTagClass extends XMLTagClass { Line 338  class HTMLTagClass extends XMLTagClass {
338                                  }                                  }
339                                  $html .= $item->render($indent, TRUE);                                  $html .= $item->render($indent, TRUE);
340                          } else {                          } else {
341                                  if ($this->_collapse_flag) {                                  if ($this->_flags & _COLLAPSE) {
342                      $html .= htmlspecialchars($item);                      $html .= htmlspecialchars($item);
343                                  } else {                                  } else {
344                                          if ($indent_level == INDENT_LEFT_JUSTIFY) {                                          if ($indent_level == INDENT_LEFT_JUSTIFY) {
# Line 321  class HTMLTagClass extends XMLTagClass { Line 347  class HTMLTagClass extends XMLTagClass {
347                                                  $indent = $indent_level + 1;                                                  $indent = $indent_level + 1;
348                                          }                                          }
349                                          $indent = $this->_render_indent($indent, TRUE);                                          $indent = $this->_render_indent($indent, TRUE);
350                                          if ( $this->newline_after_opentag ) {                                          if ( $this->_flags & _NEWLINEAFTEROPENTAG ) {
351                                                  $item = htmlspecialchars($item);                                                  $item = htmlspecialchars($item);
352                                                  $item = str_replace("\n", "<br>\n" . $indent, $item);                                                  $item = str_replace("\n", "<br>\n" . $indent, $item);
353                                                  $html .= $indent . "<span style=\"white-space:nowrap\">" .$item . "</span><br>\n";                                                  $html .= $indent . "<span style=\"white-space:nowrap\">" .$item . "</span><br>\n";
# Line 339  class HTMLTagClass extends XMLTagClass { Line 365  class HTMLTagClass extends XMLTagClass {
365    
366          /**          /**
367           * this renders the close tag in debugging mode.           * this renders the close tag in debugging mode.
368           * @param   int    $indent_level    the indentation level for this tag.       *
369           * @return  string       * {@source }
370           * @access  private       * @access private
371         *
372             * @param int the indentation level for this tag.
373             * @return string
374           */           */
375          function _render_close_tag_debug( $indent_level ) {          function _render_close_tag_debug( $indent_level ) {
376    
377                  $indent ="";                  $indent ="";
378                  if ( $this->indent_flag && $this->newline_after_opentag ) {                  if ( ($this->_flags & _INDENT) && ($this->_flags & _NEWLINEAFTEROPENTAG) ) {
379                          $indent = $this->_render_indent($indent_level, TRUE);                          $indent = $this->_render_indent($indent_level, TRUE);
380                  }                  }
381                  $str = $indent . "&lt;/" . "<span class=\"purple\">";                  $str = $indent . "&lt;/" . "<span class=\"purple\">";
382                  $str .= $this->_tag . "</span>&gt;";                  $str .= $this->_tag . "</span>&gt;";
383    
384                  if ( $this->_xhtml_compliant ) {                  if ( $this->_flags & _XHTMLCOMPLIANT ) {
385                          $str = strtolower( $str );                          $str = strtolower( $str );
386                  }                  }
387    
388                  if ( $this->newline_after_closetag ) {                  if ( $this->_flags & _NEWLINEAFTERCLOSETAG ) {
389                          $str .= "<br>\n";                          $str .= "<br>\n";
390                  }                  }
391    
# Line 375  class HTMLTagClass extends XMLTagClass { Line 404  class HTMLTagClass extends XMLTagClass {
404           * that shouldn't be rendered if they           * that shouldn't be rendered if they
405           * are in the $this->_xhtml_strict_attributes           * are in the $this->_xhtml_strict_attributes
406           * array and HTML_RENDER_TYPE = XHTML STRICT           * array and HTML_RENDER_TYPE = XHTML STRICT
407         *
408         * {@source }
409         * @access private
410           *           *
411           * @param   string - $name attribute name           * @param   string - $name attribute name
412           * @param   mixed - $value attribute value           * @param   mixed - $value attribute value
# Line 391  class HTMLTagClass extends XMLTagClass { Line 423  class HTMLTagClass extends XMLTagClass {
423                          } else if ( $value === NULL ) {                          } else if ( $value === NULL ) {
424                                  $returnval = " <span class=\"black\">$name</span>";                                  $returnval = " <span class=\"black\">$name</span>";
425                          } else {                          } else {
426                                  if ( in_array($name, $this->_debug_link_attributes) ) {                                  if ( @in_array($name, $this->_debug_link_attributes) ) {
427                                          //lets create a clickable link for the value                                          //lets create a clickable link for the value
428                                          //of this attribute                                          //of this attribute
429                                          $value = "<a href=\"$value\">$value</a>";                                          $value = "<a href=\"$value\">$value</a>";
# Line 401  class HTMLTagClass extends XMLTagClass { Line 433  class HTMLTagClass extends XMLTagClass {
433                                  }                                  }
434                          }                          }
435    
436                          if ( HTML_RENDER_TYPE == XHTML_STRICT &&                          if ( $GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT &&
437                                   in_array($name, $this->_xhtml_strict_attributes) ) {                                   @in_array($name, $this->_xhtml_strict_attributes) ) {
438                                  $returnval = NULL;                                  $returnval = NULL;
439                          }                          }
440                  } else {                  } else {
441                          //hack to make non name-value pair work.                          //hack to make non name-value pair work.
442                          //ie <option name=foo value=bar CHECKED>                          //ie <option name=foo value=bar CHECKED>
443                          if ( HTML_RENDER_TYPE == XHTML_STRICT && !is_int($name) ) {                          if ( $GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT && !is_int($name) ) {
444                                  //We do this because XHTML STRICT complains about                                  //We do this because XHTML STRICT complains about
445                                  //html characters such as &.  So we mask them.                                  //html characters such as &.  So we mask them.
446                                  $value = htmlentities($value);                                  $value = htmlspecialchars($value);
447                          }                          }
448    
449                          if ( HTML_RENDER_TYPE == XHTML_STRICT &&                          if ( $GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT &&
450                                   in_array($name, $this->_xhtml_strict_attributes) ) {                                   @in_array($name, $this->_xhtml_strict_attributes) ) {
451                                  $returnval = NULL;                                  $returnval = NULL;
452                          } else {                          } else {
453                                  $returnval = XMLTagClass::_build_attribute_string($name, $value);                  if ( ((int)$name - 0) === $name) {
454                        $returnval = " ".$value;
455                    } else if ( $value === NULL ) {
456                        $returnval = " ".$name;
457                    } else {
458                        $returnval= " ".$name."=\"".$value."\"";
459                    }
460                          }                          }
461                  }                  }
462                  return $returnval;                  return $returnval;
# Line 428  class HTMLTagClass extends XMLTagClass { Line 466  class HTMLTagClass extends XMLTagClass {
466          // Misc functions          // Misc functions
467          //****************************************************************          //****************************************************************
468    
469    
470        /**
471         * This function checks to see if
472         * there is only 1 content data, and
473         * its not an object, then it auto
474         * sets some of the indentation flags
475         *
476         * {@source }
477         * @access private
478         * @return none
479         */
480        function _prepare_flags() {
481                    if ($this->_flags & _CONTENTREQUIRED) {
482                            if ($this->count_content() == 1) {
483                                    if (!is_object($this->_content[0])) {
484                                            //ok looks like this object has only
485                                            //1 data for content and its a string.          
486                                            if ( !strstr($this->_content[0], "\n") ) {
487                                                    $this->_flags &= ~_NEWLINEAFTEROPENTAG;
488                                            }
489                                    }
490                            } else if ($this->count_content() == 0) {
491                    $this->_flags &= ~_NEWLINEAFTEROPENTAG;
492                }
493                    }
494        }
495    
496  }  }
497  ?>  ?>

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed