| 1 |
jonen |
1.1 |
<?php |
| 2 |
|
|
|
| 3 |
|
|
/** |
| 4 |
|
|
* This contains the HTMLPageClass widget |
| 5 |
|
|
* |
| 6 |
jonen |
1.4 |
* $Id: HTMLPageClass.inc,v 1.29 2003/09/30 00:41:40 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 |
jonen |
1.4 |
/** |
| 178 |
|
|
* keeps track of the html |
| 179 |
|
|
* render type. |
| 180 |
|
|
* |
| 181 |
|
|
* @var string |
| 182 |
|
|
*/ |
| 183 |
|
|
var $_html_render_type = HTML; |
| 184 |
|
|
|
| 185 |
|
|
/** |
| 186 |
|
|
* The favicon params |
| 187 |
|
|
* @var array |
| 188 |
|
|
*/ |
| 189 |
|
|
var $_favicon = array("href" => "/favicon.ico", |
| 190 |
|
|
"type" => "images/x-ico", |
| 191 |
|
|
"enabled" => FALSE); |
| 192 |
|
|
|
| 193 |
jonen |
1.1 |
|
| 194 |
|
|
|
| 195 |
|
|
/** |
| 196 |
|
|
* Class Constructor |
| 197 |
|
|
* @param mixed - $title Title string or TITLEtag object for the page. |
| 198 |
|
|
* @param string - one of 3 types of html to render. Setting this will |
| 199 |
|
|
* make the object declare the gobal define which tells |
| 200 |
|
|
* all of the tag objects what type of html tags to render. |
| 201 |
|
|
* some tags support special features. such as the <IMG> |
| 202 |
|
|
* tag. If xhtml is selected, the the IMGtag object and all |
| 203 |
|
|
* utility functions will not render "border=0" as a default |
| 204 |
|
|
* attribute, since this is not proper xhtml. |
| 205 |
|
|
* "html" - HTML 4.0 (default) |
| 206 |
|
|
* "xhtml_transitional" - render xhtml instead of html |
| 207 |
|
|
* - doctype is XHTML transitional. |
| 208 |
|
|
* "xhtml_strict" - render xhtml instead of html 4.0. |
| 209 |
|
|
* - doctype is XHTML strict. |
| 210 |
|
|
* @param int - one of 2 types. INDENT_NICE or INDENT_LEFT_JUSTIFY |
| 211 |
|
|
* This tells the page how to render the indenting of the |
| 212 |
|
|
* output. By default it is set to INDENT_NICE, which nicely |
| 213 |
|
|
* indents each nested tag. You can have all tags rendered |
| 214 |
|
|
* left justified (smaller size in output) by using |
| 215 |
|
|
* INDENT_LEFT_JUSTIFY |
| 216 |
|
|
* |
| 217 |
|
|
* @access public |
| 218 |
|
|
*/ |
| 219 |
|
|
function HTMLPageClass($title=NULL, $html_type=HTML, $indent_style=INDENT_NICE) { |
| 220 |
|
|
|
| 221 |
|
|
switch ($html_type) { |
| 222 |
|
|
case HTML: |
| 223 |
|
|
default: |
| 224 |
jonen |
1.4 |
$this->build_doctype("-//W3C//DTD HTML 4.01 Transitional//EN", |
| 225 |
|
|
"http://www.w3.org/TR/html4/loose.dtd"); |
| 226 |
|
|
$this->_html_render_type = $GLOBALS["HTML_RENDER_TYPE"] = HTML; |
| 227 |
jonen |
1.1 |
break; |
| 228 |
|
|
|
| 229 |
|
|
case XHTML_STRICT: |
| 230 |
|
|
$this->build_doctype("-//W3C//DTD XHTML 1.0 Strict//EN", |
| 231 |
jonen |
1.3 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); |
| 232 |
jonen |
1.4 |
$this->_html_render_type = $GLOBALS["HTML_RENDER_TYPE"] = XHTML_STRICT; |
| 233 |
jonen |
1.1 |
$this->set_html_attributes( array( "xmlns" => "http://www.w3.org/1999/xhtml", |
| 234 |
|
|
"xml:lang" => "en", |
| 235 |
|
|
"lang" => "en") ); |
| 236 |
|
|
break; |
| 237 |
|
|
|
| 238 |
|
|
case XHTML: |
| 239 |
|
|
case XHTML_TRANSITIONAL: |
| 240 |
|
|
$this->build_doctype("-//W3C//DTD XHTML 1.0 Transitional//EN", |
| 241 |
jonen |
1.3 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"); |
| 242 |
jonen |
1.4 |
$this->_html_render_type = $GLOBALS["HTML_RENDER_TYPE"] = XHTML; |
| 243 |
jonen |
1.1 |
$this->set_html_attributes( array( "xmlns" => "http://www.w3.org/1999/xhtml", |
| 244 |
|
|
"xml:lang" => "en", |
| 245 |
|
|
"lang" => "en") ); |
| 246 |
|
|
break; |
| 247 |
|
|
|
| 248 |
|
|
//What else needs to be done to properly support |
| 249 |
|
|
//XHTML frameset? TODO LIST for 1.1 |
| 250 |
|
|
case XHTML_FRAMESET: |
| 251 |
|
|
$this->build_doctype("-//W3C//DTD XHTML 1.0 Frameset//EN", |
| 252 |
jonen |
1.3 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"); |
| 253 |
jonen |
1.4 |
$this->_html_render_type = $GLOBALS["HTML_RENDER_TYPE"] = XHTML_FRAMESET; |
| 254 |
jonen |
1.1 |
break; |
| 255 |
|
|
} |
| 256 |
|
|
|
| 257 |
|
|
$this->_head = new HEADtag; |
| 258 |
|
|
$this->_head_js = html_script(); |
| 259 |
|
|
$this->_head_style = html_style(); |
| 260 |
|
|
$this->_create_body(); |
| 261 |
|
|
if ($title != NULL) { |
| 262 |
|
|
$this->set_title( $title ); |
| 263 |
|
|
} |
| 264 |
|
|
|
| 265 |
|
|
$this->_indent_style = $indent_style; |
| 266 |
|
|
} |
| 267 |
|
|
|
| 268 |
|
|
//************************************************** |
| 269 |
|
|
//* HEAD tag related functions |
| 270 |
|
|
//************************************************** |
| 271 |
|
|
|
| 272 |
|
|
|
| 273 |
|
|
/** |
| 274 |
|
|
* this adds content to the head tag |
| 275 |
|
|
* of the page |
| 276 |
|
|
* |
| 277 |
|
|
* @param mixed - any content to add |
| 278 |
|
|
*/ |
| 279 |
|
|
function add_head_content( ) { |
| 280 |
|
|
$num_args = func_num_args(); |
| 281 |
|
|
for ($i=0;$i<$num_args;$i++) { |
| 282 |
|
|
$this->_head->add(func_get_arg($i)); |
| 283 |
|
|
} |
| 284 |
|
|
} |
| 285 |
|
|
|
| 286 |
|
|
/** |
| 287 |
|
|
* Same ass add_head_content() |
| 288 |
|
|
* |
| 289 |
|
|
* @deprecated - use add_head_content(); |
| 290 |
|
|
*/ |
| 291 |
|
|
function push_head_content( ) { |
| 292 |
|
|
$args = func_get_args(); |
| 293 |
|
|
call_user_func_array( array(&$this, "add_head_content"), $args); |
| 294 |
|
|
} |
| 295 |
|
|
|
| 296 |
|
|
|
| 297 |
|
|
/** |
| 298 |
|
|
* adds raw javascript to the head which |
| 299 |
|
|
* will automatically get wrapped in a |
| 300 |
|
|
* <script language="JavaScript"> tag. |
| 301 |
|
|
* @param mixed $content - raw javascript code to add to the head |
| 302 |
|
|
*/ |
| 303 |
|
|
function add_head_js( $content ) { |
| 304 |
|
|
$this->_head_js->push( $content ); |
| 305 |
|
|
} |
| 306 |
|
|
|
| 307 |
|
|
/** |
| 308 |
|
|
* Same ass add_head_js() |
| 309 |
|
|
* |
| 310 |
|
|
* @deprecated - use add_head_js(); |
| 311 |
|
|
*/ |
| 312 |
|
|
function push_head_js( $content ) { |
| 313 |
|
|
$this->add_head_js( $content ); |
| 314 |
|
|
} |
| 315 |
|
|
|
| 316 |
|
|
/** |
| 317 |
|
|
* this function adds raw css to the |
| 318 |
|
|
* <head> tag. It will automatically |
| 319 |
|
|
* be wrapped in a <style type="text/css"> |
| 320 |
|
|
* |
| 321 |
|
|
* @param string - the raw css |
| 322 |
|
|
*/ |
| 323 |
|
|
function add_head_css( $css ) { |
| 324 |
|
|
$this->_head_style->push( $css ); |
| 325 |
|
|
} |
| 326 |
|
|
|
| 327 |
|
|
/** |
| 328 |
|
|
* set the title of the page output. |
| 329 |
|
|
* @param mixed $title - the title of the html page |
| 330 |
|
|
* can be TITLEtag object. |
| 331 |
|
|
* |
| 332 |
|
|
*/ |
| 333 |
|
|
function set_title( $title ) { |
| 334 |
|
|
if (is_object($title)) { |
| 335 |
|
|
if ($title->_tag == "title") { |
| 336 |
|
|
$this->_title = $title; |
| 337 |
|
|
} else { |
| 338 |
|
|
//they did something funky here. |
| 339 |
|
|
return -1; |
| 340 |
|
|
} |
| 341 |
|
|
} else { |
| 342 |
|
|
$this->_title = html_title( $title ); |
| 343 |
|
|
} |
| 344 |
|
|
} |
| 345 |
|
|
|
| 346 |
|
|
/** |
| 347 |
|
|
* pushes a css external reference to the head area |
| 348 |
|
|
* @param mixed $link - link tag object or $url for a css. |
| 349 |
|
|
*/ |
| 350 |
|
|
function add_css_link( $link ) { |
| 351 |
|
|
if (is_object($link)) { |
| 352 |
|
|
$css = $link; |
| 353 |
|
|
} else { |
| 354 |
|
|
$css = html_link($link, "stylesheet", "text/css"); |
| 355 |
|
|
} |
| 356 |
|
|
$this->_head_css_link_arr[] = $css; |
| 357 |
|
|
} |
| 358 |
|
|
|
| 359 |
|
|
/** |
| 360 |
|
|
* Same ass add_css_link() |
| 361 |
|
|
* |
| 362 |
|
|
* @deprecated - use add_css_link(); |
| 363 |
|
|
*/ |
| 364 |
|
|
function push_css_link( $link ) { |
| 365 |
|
|
$this->add_css_link( $link ); |
| 366 |
|
|
|
| 367 |
|
|
} |
| 368 |
|
|
|
| 369 |
|
|
/** |
| 370 |
jonen |
1.3 |
* This adds a link to an external Javascript |
| 371 |
|
|
* file, which will get rendered in the head. |
| 372 |
jonen |
1.1 |
* |
| 373 |
jonen |
1.3 |
* @param mixed $link - script tag object or $url of .js file. |
| 374 |
jonen |
1.1 |
*/ |
| 375 |
jonen |
1.3 |
function add_js_link( $link ) { |
| 376 |
jonen |
1.1 |
if (is_object($link)) { |
| 377 |
|
|
$js = $link; |
| 378 |
|
|
} else { |
| 379 |
|
|
$js = html_script($link); |
| 380 |
|
|
} |
| 381 |
|
|
$this->_head_js_link_arr[] = $js; |
| 382 |
|
|
} |
| 383 |
|
|
|
| 384 |
|
|
/** |
| 385 |
jonen |
1.3 |
* same as add_js_link() |
| 386 |
|
|
* |
| 387 |
|
|
* @deprecated |
| 388 |
|
|
*/ |
| 389 |
|
|
function push_js_link( $link ) { |
| 390 |
|
|
$this->add_js_link( $link ); |
| 391 |
|
|
} |
| 392 |
|
|
|
| 393 |
|
|
/** |
| 394 |
jonen |
1.1 |
* Automatically set a page meta tag refresh |
| 395 |
|
|
* @param int $time - time in seconds to refresh |
| 396 |
|
|
* @param string $url - the url to go to. |
| 397 |
|
|
*/ |
| 398 |
|
|
function set_refresh( $time, $url=NULL ) { |
| 399 |
|
|
if ($url) { |
| 400 |
|
|
$time .= ";url=$url"; |
| 401 |
|
|
} |
| 402 |
|
|
$this->push_head_content( html_meta($time, "refresh") ); |
| 403 |
|
|
} |
| 404 |
|
|
|
| 405 |
|
|
/** |
| 406 |
|
|
* set the character set |
| 407 |
|
|
* @param string $charset - the charset for the meta tag |
| 408 |
|
|
* |
| 409 |
|
|
*/ |
| 410 |
|
|
function set_charset( $charset ) { |
| 411 |
|
|
$this->_charset = $charset; |
| 412 |
|
|
} |
| 413 |
|
|
|
| 414 |
|
|
/** |
| 415 |
jonen |
1.3 |
* This sets the encoding type for |
| 416 |
|
|
* XHTML documents |
| 417 |
|
|
* |
| 418 |
|
|
* @param string - the encoding parameter |
| 419 |
|
|
*/ |
| 420 |
|
|
function set_encoding( $encoding ) { |
| 421 |
|
|
$this->_xml_encoding = $encoding; |
| 422 |
|
|
} |
| 423 |
|
|
|
| 424 |
|
|
/** |
| 425 |
|
|
* This method sets the lang, and xml:lang |
| 426 |
|
|
* setting in the HTML tag. |
| 427 |
|
|
* |
| 428 |
|
|
* @param string - the language |
| 429 |
|
|
*/ |
| 430 |
|
|
function set_language( $language ) { |
| 431 |
|
|
$this->_html_attributes["xml:lang"] = $language; |
| 432 |
|
|
$this->_html_attributes["lang"] = $language; |
| 433 |
|
|
} |
| 434 |
|
|
|
| 435 |
|
|
/** |
| 436 |
jonen |
1.1 |
* This function is used to set the FRAMSETtag |
| 437 |
|
|
* object for this page. This automatically |
| 438 |
|
|
* sets the output for this page object to |
| 439 |
|
|
* be a frameset. |
| 440 |
|
|
* |
| 441 |
|
|
* @param FRAMESETtag object - $frameset |
| 442 |
|
|
*/ |
| 443 |
|
|
function set_frameset( $frameset ) { |
| 444 |
|
|
if (is_object($frameset)) { |
| 445 |
|
|
if ($frameset->get_tag() == "frameset") { |
| 446 |
|
|
$this->_frameset = $frameset; |
| 447 |
|
|
} |
| 448 |
|
|
} |
| 449 |
|
|
} |
| 450 |
|
|
|
| 451 |
|
|
|
| 452 |
|
|
/** |
| 453 |
|
|
* This function returns the |
| 454 |
|
|
* attributes to be used for the |
| 455 |
|
|
* <html> tag. |
| 456 |
|
|
* |
| 457 |
|
|
* @return array(); |
| 458 |
|
|
*/ |
| 459 |
|
|
function get_html_attributes() { |
| 460 |
|
|
return $this->_html_attributes; |
| 461 |
|
|
} |
| 462 |
|
|
|
| 463 |
|
|
/** |
| 464 |
|
|
* This function sets the attributes |
| 465 |
|
|
* for the <html> tag |
| 466 |
|
|
* |
| 467 |
|
|
* @param array - the name=>value |
| 468 |
|
|
* pair for the |
| 469 |
|
|
* attributes |
| 470 |
|
|
*/ |
| 471 |
|
|
function set_html_attributes( $attributes ) { |
| 472 |
|
|
$this->_html_attributes = $attributes; |
| 473 |
jonen |
1.3 |
} |
| 474 |
jonen |
1.1 |
|
| 475 |
|
|
|
| 476 |
|
|
/** |
| 477 |
|
|
* this builds the content type meta tag. |
| 478 |
|
|
* |
| 479 |
|
|
*/ |
| 480 |
|
|
function _build_content_type_tag() { |
| 481 |
|
|
$content_type = "text/html; charset=" . $this->_charset; |
| 482 |
|
|
return html_meta($content_type, "Content-Type"); |
| 483 |
|
|
} |
| 484 |
|
|
|
| 485 |
jonen |
1.4 |
/** |
| 486 |
|
|
* This is used to enable the ability to add the |
| 487 |
|
|
* favicon link in the head of the document. |
| 488 |
|
|
* By default it is off. |
| 489 |
|
|
* |
| 490 |
|
|
* @param boolean TRUE = enable |
| 491 |
|
|
*/ |
| 492 |
|
|
function set_favicon_flag($flag=TRUE) { |
| 493 |
|
|
$this->_favicon["enabled"] = $flag; |
| 494 |
|
|
} |
| 495 |
|
|
|
| 496 |
|
|
/** |
| 497 |
|
|
* This allows you to change the default url/path |
| 498 |
|
|
* for where the favicon.ico lives. |
| 499 |
|
|
* NOTE: calling this method automatically enables the |
| 500 |
|
|
* link in the head to be created. |
| 501 |
|
|
* |
| 502 |
|
|
* @param string the url to the favicon.ico file |
| 503 |
|
|
* @param string the type of the image. |
| 504 |
|
|
* NOTE: Default is image/x-ico |
| 505 |
|
|
*/ |
| 506 |
|
|
function set_favicon($path, $type="image/x-ico") { |
| 507 |
|
|
$this->_favicon["href"] = $path; |
| 508 |
|
|
$this->_favicon["type"] = $type; |
| 509 |
|
|
$this->set_favicon_flag( TRUE ); |
| 510 |
|
|
} |
| 511 |
|
|
|
| 512 |
jonen |
1.1 |
//************************************************** |
| 513 |
|
|
//* BODY tag related functions |
| 514 |
|
|
//************************************************** |
| 515 |
|
|
|
| 516 |
|
|
|
| 517 |
|
|
/** |
| 518 |
|
|
* This function adds content to the <body> |
| 519 |
|
|
* area of the page. |
| 520 |
|
|
* |
| 521 |
|
|
* @param mixed - any # of parameters |
| 522 |
|
|
*/ |
| 523 |
|
|
function add() { |
| 524 |
|
|
$num_args = func_num_args(); |
| 525 |
|
|
for ($i=0;$i<$num_args;$i++) { |
| 526 |
|
|
$arg = func_get_arg($i); |
| 527 |
|
|
//see if the arg is an object |
| 528 |
|
|
//and a child of BaseWidget. |
| 529 |
|
|
if (is_object($arg) && is_subclass_of( $arg, "basewidget")) { |
| 530 |
|
|
//see if they have an js they need to include |
| 531 |
|
|
$js = ""; |
| 532 |
|
|
$js = $arg->get_javascript(); |
| 533 |
|
|
$class_name = get_class($arg); |
| 534 |
jonen |
1.4 |
if ($js != "" && !isset($this->_widget_js_auto[$class_name])) { |
| 535 |
jonen |
1.1 |
$this->add_head_js( str_replace(chr(9),'', $js) ); |
| 536 |
|
|
$this->_widget_js_auto[$class_name] = TRUE; |
| 537 |
|
|
} |
| 538 |
|
|
} |
| 539 |
|
|
$this->_body->add(func_get_arg($i)); |
| 540 |
|
|
} |
| 541 |
|
|
} |
| 542 |
|
|
|
| 543 |
|
|
/** |
| 544 |
|
|
* Same as add() |
| 545 |
|
|
* |
| 546 |
|
|
* @deprecated - use add() |
| 547 |
|
|
* |
| 548 |
|
|
*/ |
| 549 |
|
|
function push( ) { |
| 550 |
|
|
$args = func_get_args(); |
| 551 |
|
|
call_user_func_array( array(&$this, "add"), $args); |
| 552 |
|
|
} |
| 553 |
|
|
|
| 554 |
|
|
/** |
| 555 |
|
|
* Adds the content reference to the <body> |
| 556 |
|
|
* tag for later use. |
| 557 |
|
|
* |
| 558 |
|
|
* @param mixed $content - content to add |
| 559 |
|
|
*/ |
| 560 |
|
|
function add_reference( &$content ) { |
| 561 |
|
|
$this->_body->push_reference( $content ); |
| 562 |
|
|
} |
| 563 |
|
|
|
| 564 |
|
|
/** |
| 565 |
|
|
* Same as add() |
| 566 |
|
|
* |
| 567 |
|
|
* @deprecated - use add() |
| 568 |
|
|
* |
| 569 |
|
|
*/ |
| 570 |
|
|
function push_reference( &$content ) { |
| 571 |
|
|
$this->add_reference( $content ); |
| 572 |
|
|
} |
| 573 |
|
|
|
| 574 |
|
|
/** |
| 575 |
|
|
* This is responsible for creating the |
| 576 |
|
|
* BODYtag object. We only will |
| 577 |
|
|
* create a new $this->_body if it doesn't |
| 578 |
|
|
* already exist. |
| 579 |
|
|
* |
| 580 |
|
|
*/ |
| 581 |
|
|
function _create_body() { |
| 582 |
|
|
if ($this->_body == NULL) { |
| 583 |
|
|
$this->_body = new BODYtag; |
| 584 |
jonen |
1.3 |
//$this->_body->add( " " ); |
| 585 |
jonen |
1.1 |
} |
| 586 |
|
|
} |
| 587 |
|
|
|
| 588 |
|
|
/** |
| 589 |
|
|
* set attributes of body tag |
| 590 |
|
|
* @param array $attributes the name=>value pairs |
| 591 |
|
|
* |
| 592 |
|
|
*/ |
| 593 |
|
|
function set_body_attributes( $attributes ) { |
| 594 |
|
|
if (!is_object( $this->_body )) { |
| 595 |
|
|
$this->_create_body(); |
| 596 |
|
|
} |
| 597 |
|
|
$this->_body->set_tag_attributes( $attributes ); |
| 598 |
|
|
} |
| 599 |
|
|
|
| 600 |
|
|
/** |
| 601 |
|
|
* This function is used to build the DOCTYPE |
| 602 |
|
|
* tag for the page. It will automatically |
| 603 |
|
|
* create a DOCTYPE with a document_element of "html" |
| 604 |
|
|
* and a source of "PUBLIC" |
| 605 |
|
|
* |
| 606 |
|
|
* @param string - link1 |
| 607 |
|
|
* @param string - link2 |
| 608 |
|
|
*/ |
| 609 |
|
|
function build_doctype($link1, $link2=NULL) { |
| 610 |
|
|
$this->_doctype = xml_doctype("html", "PUBLIC", $link1, $link2); |
| 611 |
|
|
} |
| 612 |
|
|
|
| 613 |
|
|
//************************************************** |
| 614 |
|
|
//* General functions |
| 615 |
|
|
//************************************************** |
| 616 |
|
|
|
| 617 |
|
|
/** |
| 618 |
|
|
* set the $_text_debug flag |
| 619 |
|
|
* @param $flag - boolean. |
| 620 |
|
|
*/ |
| 621 |
|
|
function set_text_debug( $flag ) { |
| 622 |
|
|
$this->_text_debug = $flag; |
| 623 |
|
|
} |
| 624 |
|
|
|
| 625 |
|
|
|
| 626 |
|
|
//************************************************** |
| 627 |
|
|
//* RENDERING of content related functions |
| 628 |
|
|
//************************************************** |
| 629 |
|
|
|
| 630 |
|
|
/** |
| 631 |
|
|
* builds the head object and its content. |
| 632 |
|
|
* |
| 633 |
|
|
*/ |
| 634 |
|
|
function _build_head() { |
| 635 |
|
|
|
| 636 |
|
|
$this->_head->add( $this->_build_content_type_tag() ); |
| 637 |
|
|
|
| 638 |
jonen |
1.3 |
if ($this->_title) { |
| 639 |
|
|
$this->_head->add( $this->_title ); |
| 640 |
|
|
} |
| 641 |
jonen |
1.4 |
|
| 642 |
|
|
if ($this->_favicon["enabled"]) { |
| 643 |
|
|
$this->_head->add( html_link($this->_favicon["href"], |
| 644 |
|
|
"shortcut icon", |
| 645 |
|
|
$this->_favicon["type"])); |
| 646 |
|
|
} |
| 647 |
jonen |
1.3 |
|
| 648 |
jonen |
1.1 |
if ( $this->_head_style->count_content() ) { |
| 649 |
|
|
$this->_head->add( $this->_head_style ); |
| 650 |
|
|
} |
| 651 |
|
|
if ( $this->_head_js->count_content() ) { |
| 652 |
|
|
$this->_head->add( $this->_head_js ); |
| 653 |
|
|
} |
| 654 |
|
|
|
| 655 |
|
|
if (count($this->_head_css_link_arr)) { |
| 656 |
|
|
foreach( $this->_head_css_link_arr as $css) { |
| 657 |
|
|
$this->_head->add( $css ); |
| 658 |
|
|
} |
| 659 |
|
|
} |
| 660 |
|
|
|
| 661 |
|
|
if (count($this->_head_js_link_arr)) { |
| 662 |
|
|
foreach( $this->_head_js_link_arr as $js) { |
| 663 |
|
|
$this->_head->add( $js ); |
| 664 |
|
|
} |
| 665 |
|
|
} |
| 666 |
|
|
} |
| 667 |
|
|
|
| 668 |
|
|
/** |
| 669 |
|
|
* This builds a frameset body tag |
| 670 |
|
|
* wrapped in a <noframes> tag. |
| 671 |
|
|
* |
| 672 |
|
|
* @return NOFRAMEStag object. |
| 673 |
|
|
*/ |
| 674 |
|
|
function _frameset_wrap_body() { |
| 675 |
|
|
$noframes = new NOFRAMEStag; |
| 676 |
|
|
$body = new BODYtag; |
| 677 |
|
|
$body->add( $this->_noframes_text ); |
| 678 |
|
|
$noframes->add( $body ); |
| 679 |
|
|
return $noframes; |
| 680 |
|
|
} |
| 681 |
|
|
|
| 682 |
|
|
/** |
| 683 |
|
|
* render the page. |
| 684 |
|
|
* |
| 685 |
|
|
* |
| 686 |
|
|
* @return string the raw html output. |
| 687 |
|
|
*/ |
| 688 |
|
|
function render() { |
| 689 |
jonen |
1.4 |
|
| 690 |
|
|
//make sure the render type is correctly |
| 691 |
|
|
//set |
| 692 |
|
|
$GLOBALS["HTML_RENDER_TYPE"] = $this->_html_render_type; |
| 693 |
jonen |
1.1 |
|
| 694 |
|
|
//lets use ourself to render the debug page! |
| 695 |
|
|
if ($this->_text_debug) { |
| 696 |
|
|
$page = new HTMLPageClass; |
| 697 |
|
|
$page->add_css_link("/phphtmllib/css/HTMLPageClass.css"); |
| 698 |
|
|
} |
| 699 |
|
|
|
| 700 |
jonen |
1.3 |
$newline = " "; |
| 701 |
jonen |
1.1 |
$attributes = $this->get_html_attributes(); |
| 702 |
|
|
$html = new HTMLtag( $attributes ); |
| 703 |
|
|
$html->add( $newline ); |
| 704 |
|
|
$this->_build_head(); |
| 705 |
|
|
$html->add( $this->_head ); |
| 706 |
|
|
|
| 707 |
|
|
//Check to see if we are rendering |
| 708 |
|
|
//a frameset page. |
| 709 |
|
|
if ($this->_frameset != NULL) { |
| 710 |
|
|
//Looks like they have set the frameset |
| 711 |
|
|
//member, so we are rendering a frameset |
| 712 |
|
|
//we will automatically wrap the <body> |
| 713 |
|
|
$html->add( $newline ); |
| 714 |
|
|
$html->add( $this->_frameset ); |
| 715 |
|
|
$html->add( $newline ); |
| 716 |
|
|
$html->add( $this->_frameset_wrap_body() ); |
| 717 |
|
|
} else { |
| 718 |
|
|
$html->add( $newline ); |
| 719 |
jonen |
1.3 |
//$this->_body->add( $newline ); |
| 720 |
jonen |
1.1 |
$html->add( $this->_body ); |
| 721 |
|
|
} |
| 722 |
|
|
|
| 723 |
|
|
$html-> add( $newline ); |
| 724 |
|
|
|
| 725 |
|
|
if ($this->_text_debug) { |
| 726 |
jonen |
1.3 |
if ($GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT) { |
| 727 |
jonen |
1.1 |
$xml = new XMLtag(array("version" => "1.0", |
| 728 |
jonen |
1.3 |
"encoding"=>$this->_xml_encoding)); |
| 729 |
jonen |
1.1 |
$page->add( $xml->render(0,1) ); |
| 730 |
|
|
} |
| 731 |
|
|
$page->add( $this->_doctype->render(0,1) ); |
| 732 |
|
|
$page->add( $html->render($this->_indent_style,1) ); |
| 733 |
|
|
return $page->render(); |
| 734 |
|
|
} else { |
| 735 |
|
|
$output = ''; |
| 736 |
jonen |
1.3 |
if ($GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT) { |
| 737 |
jonen |
1.1 |
$xml = new XMLtag(array("version" => "1.0", |
| 738 |
jonen |
1.3 |
"encoding"=>$this->_xml_encoding)); |
| 739 |
jonen |
1.1 |
$output = $xml->render(0); |
| 740 |
|
|
} |
| 741 |
|
|
$output .= $this->_doctype->render(); |
| 742 |
|
|
$output .= $html->render($this->_indent_style); |
| 743 |
|
|
return $output; |
| 744 |
|
|
} |
| 745 |
|
|
} |
| 746 |
|
|
} |
| 747 |
|
|
|
| 748 |
|
|
|
| 749 |
|
|
?> |