From 806a5297e7e99d455b97a4f0acaba2f40f470584 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 26 Jul 2007 13:02:24 +0000 Subject: renamed files for autoloader --- it_html_page.class | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 it_html_page.class (limited to 'it_html_page.class') diff --git a/it_html_page.class b/it_html_page.class new file mode 100644 index 0000000..1121017 --- /dev/null +++ b/it_html_page.class @@ -0,0 +1,215 @@ + of this page */ + var $doctype; /* Document type, will be reasonably initialized */ + var $encoding; /* If set, generate Content-Type HTTP/meta headers */ + + var $url; /* Site-relative URL of this page, without GET args */ + var $remote_host; /* IP address of caller (can deal with most proxies) */ + + /* Private */ + var $headers; /* Header lines to output in context */ + var $meta_headers = array(); /* tags in context */ + var $body_tags = array(); /* array of tags in */ + var $body_end = ""; /* Output immediately before */ + var $head_sent = 0; /* 1 if area already sent to client */ + var $in_body = 0; /* false=in header, true=in body */ + var $in_input_tr = 0; /* For input_text() */ + + + +/** + * Constructor + * @param $tags optional array of key => value pairs: title, doctype, encoding + */ +function it_html_page($tags='') +{ + /* Set defaults */ + $this->doctype = ''; + + /* Determine the relative URL of this page for self-reference */ + if (isset($_SERVER['SCRIPT_URL'])) + $this->url = $_SERVER['SCRIPT_URL']; + else + { + list($this->url) = explode("?", $_SERVER['REQUEST_URI']); + $this->url = substr(strrchr($this->url, "/"), 1); /* $$$ what's this?? */ + } + + /* This is needed for POST requests to oneself */ + if ($this->url == "") + $this->url = "./"; + + /* Determine IP address of caller */ + if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && ereg('^([0-9.]{7,15})', $_SERVER['HTTP_X_FORWARDED_FOR'], $regs)) + $this->remote_host = trim($regs[1]); + else + $this->remote_host = $_SERVER['REMOTE_ADDR']; + + /* Is this a good idea? */ + $this->add_meta_header('generator', '$Id$'); + + /* Override defaults with user tags */ + if (is_array($tags)) + foreach($tags as $key => $value) + $this->$key = $value; + + if (isset($this->encoding)) + { + $ct = 'text/html; charset='.$this->encoding; + header('Content-Type: '.$ct); + $this->add_header(''); + } +} + + +/** + * Set the title of the page + */ +function set_title($title) +{ + $this->title = $title; +} + + +/** + * Add a line to the header area and trim it + */ +function add_header($header) +{ + $this->headers .= trim($header)."\n"; +} + + +/** + * Add a meta header. + * If a header with the same name exists, overwrite it. + */ +function add_meta_header($name, $value) +{ + $this->meta_headers[strtolower($name)] = $value; +} + + +/** + * Add a tag=value pair in body_tags[strtolower($name)] = $value; +} + + +/** + * Add a line to the body area after other lines that were added + */ +function add_body_start($html) +{ + $this->body_start .= $html; +} + + +/** + * Add a line to the body end area before other lines that were added + */ +function add_body_end($html) +{ + $this->body_end = $html . $this->body_end; +} + + +/** + * Write out HTML section, if not already done. + */ +function head() +{ + /* This function can be called multiple times, no harm is done. */ + if (!$this->head_sent) + { + $lang = $this->language ? " lang='$this->language'" : ""; + + if (!$GLOBALS['SENT_PREAMBLE']) /* RELOAD_MAGIC already sent */ + echo $this->doctype, "\n\n\n"; + + # Generate title tag. If empty string, output (html-required) + if (isset($this->title)) + echo ''.$this->title."\n"; + + echo $this->headers; + + while (list($name, $content) = each($this->meta_headers)) + echo "\n"; + + echo "\n"; + $this->head_sent = 1; + } +} + + +/** + * Write out HTML section and body start, if not already done. + * @param ... If parameters are present, output them and call end() + */ +function body() +{ + /* Write out header part */ + $this->head(); + + /* This function can be called multiple times, no harm is done. */ + if (!$this->in_body) + { + echo 'body_tags)) + echo " $tag=\"$value\""; + + echo ">\n".$this->body_start; + $this->in_body = 1; + + if ($args = func_get_args()) + { + foreach($args as $arg) + echo $arg; + $this->end(); + } + } +} + + +/** + * End a HTML page. + */ +function end() +{ + $this->head(); + + if ($this->in_body) + { + echo $this->body_end."\n"; + $this->in_body = 0; + } + + echo "\n"; +} + + +} /* End class it_html_page */ +?> -- cgit v1.2.3