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

Annotation of /nfo/php/libs/com.newsblob.phphtmllib/widgets/HTMLPageClass.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Fri Nov 14 21:31:40 2003 UTC (20 years, 8 months ago) by jonen
Branch: MAIN
Changes since 1.2: +61 -21 lines
+ updated whole phphtmllib to v2.3.0

1 jonen 1.1 <?php
2    
3     /**
4     * This contains the HTMLPageClass widget
5     *
6 jonen 1.3 * $Id: HTMLPageClass.inc,v 1.25 2003/07/23 21:05:38 hemna Exp $
7 jonen 1.1 *
8     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
9     * @package phpHtmlLib
10     *
11     */
12    
13     /**
14     * Get all the required files for this class
15     */
16     require_once($phphtmllib."/HTMLTagClass.inc");
17    
18    
19     /**
20     * class the constructs and renders an entire
21     * HTML/XHTML document.
22     *
23     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
24     * @package phpHtmlLib
25     */
26     class HTMLPageClass {
27    
28     /**
29     * HEADtag object that holds all content
30     * for the head.
31     * @var object
32     * @access private
33     */
34     var $_head = NULL;
35    
36     /**
37     * TITLEtag object that holds the title
38     * of the page.
39     * @var object
40     * @access private
41     */
42     var $_title = NULL;
43    
44     /**
45     * SCRIPTtag object that holds javascript
46     * code for the head tag.
47     * @var object
48     * @access private
49     */
50     var $_head_js = NULL;
51    
52     /**
53     * STYLEtag object that holds css code
54     * for the head.
55     * @var object
56     * @access private
57     */
58     var $_head_style = NULL;
59    
60     /**
61     * holds an array of LINKtag objects
62     * in the head tag that reference an
63     * external stylesheet file.
64     * @var array.
65     * @access private
66     */
67     var $_head_css_link_arr = array();
68    
69     /**
70     * holds an array of SCRIPTtag objects
71     * in the head tag that reference an
72     * an extern javascript file.
73     * @var array
74     * @access private
75     */
76     var $_head_js_link_arr = array();
77    
78     /**
79     * character set to be used in this
80     * page. This gets automatically
81     * placed in the Content-Type
82     * META tag.
83     * @var string
84     * @access private
85     */
86     var $_charset = "iso-8859-1";
87    
88 jonen 1.3
89     /**
90     * The encoding of the XHTML
91     * XML tag
92     */
93     var $_xml_encoding = "UTF-8";
94    
95 jonen 1.1 /**
96     * BODYtag object that holds all content
97     * for the body tag.
98     * @var object
99     * @access private
100     */
101     var $_body = NULL;
102    
103     /**
104     * DOCTYPEag object that sets the document
105     * type. This gets rendered prior to <html>
106     * @var object
107     * @access private
108     */
109     var $_doctype = NULL;
110    
111     /**
112     * flag to tell the class to try and
113     * change the http headers to output
114     * document of type text, instead of
115     * html. This is helpfull for debugging.
116     * @var boolean
117     * @access private
118     */
119     var $_text_debug = FALSE;
120    
121     /**
122     * This holds a FRAMESETtag object.
123     * This is used if the person is trying
124     * to render a frameset page.
125     *
126     * @var FRAMESETtag object.
127     * @access private
128     */
129     var $_frameset = NULL;
130    
131    
132     /**
133     * This holds the text used to display
134     * a body content when a browser doesn't
135     * support framesets
136     *
137     * @var string
138     * @access private
139     */
140     var $_noframes_text = "Sorry, your browser does not support frames";
141    
142    
143     /**
144     * This holds the attributes for the
145     * <html> tag.
146     *
147     * @var array
148     */
149     var $_html_attributes = array();
150    
151     /**
152     * keeps track of which widgets we have
153     * automatically pulled in css for
154     *
155     * @var array
156     */
157     var $_widget_css_auto = array();
158    
159     /**
160     * keeps track of which widgets we have
161     * automatically pulled in js for
162     *
163     * @var array
164     */
165     var $_widget_js_auto = array();
166    
167    
168     /**
169     * Holds the value of the indent
170     * style the user wants to render
171     * the page w/
172     *
173     * @var int
174     */
175     var $_indent_style = 0;
176    
177    
178    
179     /**
180     * Class Constructor
181     * @param mixed - $title Title string or TITLEtag object for the page.
182     * @param string - one of 3 types of html to render. Setting this will
183     * make the object declare the gobal define which tells
184     * all of the tag objects what type of html tags to render.
185     * some tags support special features. such as the <IMG>
186     * tag. If xhtml is selected, the the IMGtag object and all
187     * utility functions will not render "border=0" as a default
188     * attribute, since this is not proper xhtml.
189     * "html" - HTML 4.0 (default)
190     * "xhtml_transitional" - render xhtml instead of html
191     * - doctype is XHTML transitional.
192     * "xhtml_strict" - render xhtml instead of html 4.0.
193     * - doctype is XHTML strict.
194     * @param int - one of 2 types. INDENT_NICE or INDENT_LEFT_JUSTIFY
195     * This tells the page how to render the indenting of the
196     * output. By default it is set to INDENT_NICE, which nicely
197     * indents each nested tag. You can have all tags rendered
198     * left justified (smaller size in output) by using
199     * INDENT_LEFT_JUSTIFY
200     *
201     * @access public
202     */
203     function HTMLPageClass($title=NULL, $html_type=HTML, $indent_style=INDENT_NICE) {
204    
205     switch ($html_type) {
206     case HTML:
207     default:
208     $this->build_doctype("-//W3C//DTD HTML 4.01 Transitional//EN");
209 jonen 1.3 $GLOBALS["HTML_RENDER_TYPE"] = HTML;
210 jonen 1.1 break;
211    
212     case XHTML_STRICT:
213     $this->build_doctype("-//W3C//DTD XHTML 1.0 Strict//EN",
214 jonen 1.3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
215     $GLOBALS["HTML_RENDER_TYPE"] = XHTML_STRICT;
216 jonen 1.1 $this->set_html_attributes( array( "xmlns" => "http://www.w3.org/1999/xhtml",
217     "xml:lang" => "en",
218     "lang" => "en") );
219     break;
220    
221     case XHTML:
222     case XHTML_TRANSITIONAL:
223     $this->build_doctype("-//W3C//DTD XHTML 1.0 Transitional//EN",
224 jonen 1.3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
225     $GLOBALS["HTML_RENDER_TYPE"] = XHTML;
226 jonen 1.1 $this->set_html_attributes( array( "xmlns" => "http://www.w3.org/1999/xhtml",
227     "xml:lang" => "en",
228     "lang" => "en") );
229     break;
230    
231     //What else needs to be done to properly support
232     //XHTML frameset? TODO LIST for 1.1
233     case XHTML_FRAMESET:
234     $this->build_doctype("-//W3C//DTD XHTML 1.0 Frameset//EN",
235 jonen 1.3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd");
236     $GLOBALS["HTML_RENDER_TYPE"] = XHTML_FRAMESET;
237 jonen 1.1 break;
238     }
239    
240     $this->_head = new HEADtag;
241     $this->_head_js = html_script();
242     $this->_head_style = html_style();
243     $this->_create_body();
244     if ($title != NULL) {
245     $this->set_title( $title );
246     }
247    
248     $this->_indent_style = $indent_style;
249     }
250    
251     //**************************************************
252     //* HEAD tag related functions
253     //**************************************************
254    
255    
256     /**
257     * this adds content to the head tag
258     * of the page
259     *
260     * @param mixed - any content to add
261     */
262     function add_head_content( ) {
263     $num_args = func_num_args();
264     for ($i=0;$i<$num_args;$i++) {
265     $this->_head->add(func_get_arg($i));
266     }
267     }
268    
269     /**
270     * Same ass add_head_content()
271     *
272     * @deprecated - use add_head_content();
273     */
274     function push_head_content( ) {
275     $args = func_get_args();
276     call_user_func_array( array(&$this, "add_head_content"), $args);
277     }
278    
279    
280     /**
281     * adds raw javascript to the head which
282     * will automatically get wrapped in a
283     * <script language="JavaScript"> tag.
284     * @param mixed $content - raw javascript code to add to the head
285     */
286     function add_head_js( $content ) {
287     $this->_head_js->push( $content );
288     }
289    
290     /**
291     * Same ass add_head_js()
292     *
293     * @deprecated - use add_head_js();
294     */
295     function push_head_js( $content ) {
296     $this->add_head_js( $content );
297     }
298    
299     /**
300     * this function adds raw css to the
301     * <head> tag. It will automatically
302     * be wrapped in a <style type="text/css">
303     *
304     * @param string - the raw css
305     */
306     function add_head_css( $css ) {
307     $this->_head_style->push( $css );
308     }
309    
310     /**
311     * set the title of the page output.
312     * @param mixed $title - the title of the html page
313     * can be TITLEtag object.
314     *
315     */
316     function set_title( $title ) {
317     if (is_object($title)) {
318     if ($title->_tag == "title") {
319     $this->_title = $title;
320     } else {
321     //they did something funky here.
322     return -1;
323     }
324     } else {
325     $this->_title = html_title( $title );
326     }
327     }
328    
329     /**
330     * pushes a css external reference to the head area
331     * @param mixed $link - link tag object or $url for a css.
332     */
333     function add_css_link( $link ) {
334     if (is_object($link)) {
335     $css = $link;
336     } else {
337     $css = html_link($link, "stylesheet", "text/css");
338     }
339     $this->_head_css_link_arr[] = $css;
340     }
341    
342     /**
343     * Same ass add_css_link()
344     *
345     * @deprecated - use add_css_link();
346     */
347     function push_css_link( $link ) {
348     $this->add_css_link( $link );
349    
350     }
351    
352     /**
353 jonen 1.3 * This adds a link to an external Javascript
354     * file, which will get rendered in the head.
355 jonen 1.1 *
356 jonen 1.3 * @param mixed $link - script tag object or $url of .js file.
357 jonen 1.1 */
358 jonen 1.3 function add_js_link( $link ) {
359 jonen 1.1 if (is_object($link)) {
360     $js = $link;
361     } else {
362     $js = html_script($link);
363     }
364     $this->_head_js_link_arr[] = $js;
365     }
366    
367     /**
368 jonen 1.3 * same as add_js_link()
369     *
370     * @deprecated
371     */
372     function push_js_link( $link ) {
373     $this->add_js_link( $link );
374     }
375    
376     /**
377 jonen 1.1 * Automatically set a page meta tag refresh
378     * @param int $time - time in seconds to refresh
379     * @param string $url - the url to go to.
380     */
381     function set_refresh( $time, $url=NULL ) {
382     if ($url) {
383     $time .= ";url=$url";
384     }
385     $this->push_head_content( html_meta($time, "refresh") );
386     }
387    
388     /**
389     * set the character set
390     * @param string $charset - the charset for the meta tag
391     *
392     */
393     function set_charset( $charset ) {
394     $this->_charset = $charset;
395     }
396    
397     /**
398 jonen 1.3 * This sets the encoding type for
399     * XHTML documents
400     *
401     * @param string - the encoding parameter
402     */
403     function set_encoding( $encoding ) {
404     $this->_xml_encoding = $encoding;
405     }
406    
407     /**
408     * This method sets the lang, and xml:lang
409     * setting in the HTML tag.
410     *
411     * @param string - the language
412     */
413     function set_language( $language ) {
414     $this->_html_attributes["xml:lang"] = $language;
415     $this->_html_attributes["lang"] = $language;
416     }
417    
418     /**
419 jonen 1.1 * This function is used to set the FRAMSETtag
420     * object for this page. This automatically
421     * sets the output for this page object to
422     * be a frameset.
423     *
424     * @param FRAMESETtag object - $frameset
425     */
426     function set_frameset( $frameset ) {
427     if (is_object($frameset)) {
428     if ($frameset->get_tag() == "frameset") {
429     $this->_frameset = $frameset;
430     }
431     }
432     }
433    
434    
435     /**
436     * This function returns the
437     * attributes to be used for the
438     * <html> tag.
439     *
440     * @return array();
441     */
442     function get_html_attributes() {
443     return $this->_html_attributes;
444     }
445    
446     /**
447     * This function sets the attributes
448     * for the <html> tag
449     *
450     * @param array - the name=>value
451     * pair for the
452     * attributes
453     */
454     function set_html_attributes( $attributes ) {
455     $this->_html_attributes = $attributes;
456 jonen 1.3 }
457 jonen 1.1
458    
459     /**
460     * this builds the content type meta tag.
461     *
462     */
463     function _build_content_type_tag() {
464     $content_type = "text/html; charset=" . $this->_charset;
465     return html_meta($content_type, "Content-Type");
466     }
467    
468     //**************************************************
469     //* BODY tag related functions
470     //**************************************************
471    
472    
473     /**
474     * This function adds content to the <body>
475     * area of the page.
476     *
477     * @param mixed - any # of parameters
478     */
479     function add() {
480     $num_args = func_num_args();
481     for ($i=0;$i<$num_args;$i++) {
482     $arg = func_get_arg($i);
483     //see if the arg is an object
484     //and a child of BaseWidget.
485     if (is_object($arg) && is_subclass_of( $arg, "basewidget")) {
486     //see if they have an js they need to include
487     $js = "";
488     $js = $arg->get_javascript();
489     $class_name = get_class($arg);
490     if ($js != "" && !$this->_widget_js_auto[$class_name]) {
491     $this->add_head_js( str_replace(chr(9),'', $js) );
492     $this->_widget_js_auto[$class_name] = TRUE;
493     }
494     }
495     $this->_body->add(func_get_arg($i));
496     }
497     }
498    
499     /**
500     * Same as add()
501     *
502     * @deprecated - use add()
503     *
504     */
505     function push( ) {
506     $args = func_get_args();
507     call_user_func_array( array(&$this, "add"), $args);
508     }
509    
510     /**
511     * Adds the content reference to the <body>
512     * tag for later use.
513     *
514     * @param mixed $content - content to add
515     */
516     function add_reference( &$content ) {
517     $this->_body->push_reference( $content );
518     }
519    
520     /**
521     * Same as add()
522     *
523     * @deprecated - use add()
524     *
525     */
526     function push_reference( &$content ) {
527     $this->add_reference( $content );
528     }
529    
530     /**
531     * This is responsible for creating the
532     * BODYtag object. We only will
533     * create a new $this->_body if it doesn't
534     * already exist.
535     *
536     */
537     function _create_body() {
538     if ($this->_body == NULL) {
539     $this->_body = new BODYtag;
540 jonen 1.3 //$this->_body->add( " " );
541 jonen 1.1 }
542     }
543    
544     /**
545     * set attributes of body tag
546     * @param array $attributes the name=>value pairs
547     *
548     */
549     function set_body_attributes( $attributes ) {
550     if (!is_object( $this->_body )) {
551     $this->_create_body();
552     }
553     $this->_body->set_tag_attributes( $attributes );
554     }
555    
556     /**
557     * This function is used to build the DOCTYPE
558     * tag for the page. It will automatically
559     * create a DOCTYPE with a document_element of "html"
560     * and a source of "PUBLIC"
561     *
562     * @param string - link1
563     * @param string - link2
564     */
565     function build_doctype($link1, $link2=NULL) {
566     $this->_doctype = xml_doctype("html", "PUBLIC", $link1, $link2);
567     }
568    
569     //**************************************************
570     //* General functions
571     //**************************************************
572    
573     /**
574     * set the $_text_debug flag
575     * @param $flag - boolean.
576     */
577     function set_text_debug( $flag ) {
578     $this->_text_debug = $flag;
579     }
580    
581    
582     //**************************************************
583     //* RENDERING of content related functions
584     //**************************************************
585    
586     /**
587     * builds the head object and its content.
588     *
589     */
590     function _build_head() {
591    
592     $this->_head->add( $this->_build_content_type_tag() );
593    
594 jonen 1.3 if ($this->_title) {
595     $this->_head->add( $this->_title );
596     }
597    
598 jonen 1.1 if ( $this->_head_style->count_content() ) {
599     $this->_head->add( $this->_head_style );
600     }
601     if ( $this->_head_js->count_content() ) {
602     $this->_head->add( $this->_head_js );
603     }
604    
605     if (count($this->_head_css_link_arr)) {
606     foreach( $this->_head_css_link_arr as $css) {
607     $this->_head->add( $css );
608     }
609     }
610    
611     if (count($this->_head_js_link_arr)) {
612     foreach( $this->_head_js_link_arr as $js) {
613     $this->_head->add( $js );
614     }
615     }
616     }
617    
618     /**
619     * This builds a frameset body tag
620     * wrapped in a <noframes> tag.
621     *
622     * @return NOFRAMEStag object.
623     */
624     function _frameset_wrap_body() {
625     $noframes = new NOFRAMEStag;
626     $body = new BODYtag;
627     $body->add( $this->_noframes_text );
628     $noframes->add( $body );
629     return $noframes;
630     }
631    
632     /**
633     * render the page.
634     *
635     *
636     * @return string the raw html output.
637     */
638     function render() {
639    
640     //lets use ourself to render the debug page!
641     if ($this->_text_debug) {
642     $page = new HTMLPageClass;
643     $page->add_css_link("/phphtmllib/css/HTMLPageClass.css");
644     }
645    
646 jonen 1.3 $newline = " ";
647 jonen 1.1 $attributes = $this->get_html_attributes();
648     $html = new HTMLtag( $attributes );
649     $html->add( $newline );
650     $this->_build_head();
651     $html->add( $this->_head );
652    
653     //Check to see if we are rendering
654     //a frameset page.
655     if ($this->_frameset != NULL) {
656     //Looks like they have set the frameset
657     //member, so we are rendering a frameset
658     //we will automatically wrap the <body>
659     $html->add( $newline );
660     $html->add( $this->_frameset );
661     $html->add( $newline );
662     $html->add( $this->_frameset_wrap_body() );
663     } else {
664     $html->add( $newline );
665 jonen 1.3 //$this->_body->add( $newline );
666 jonen 1.1 $html->add( $this->_body );
667     }
668    
669     $html-> add( $newline );
670    
671     if ($this->_text_debug) {
672 jonen 1.3 if ($GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT) {
673 jonen 1.1 $xml = new XMLtag(array("version" => "1.0",
674 jonen 1.3 "encoding"=>$this->_xml_encoding));
675 jonen 1.1 $page->add( $xml->render(0,1) );
676     }
677     $page->add( $this->_doctype->render(0,1) );
678     $page->add( $html->render($this->_indent_style,1) );
679     return $page->render();
680     } else {
681     $output = '';
682 jonen 1.3 if ($GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT) {
683 jonen 1.1 $xml = new XMLtag(array("version" => "1.0",
684 jonen 1.3 "encoding"=>$this->_xml_encoding));
685 jonen 1.1 $output = $xml->render(0);
686     }
687     $output .= $this->_doctype->render();
688     $output .= $html->render($this->_indent_style);
689     return $output;
690     }
691     }
692     }
693    
694    
695     ?>

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