| // +----------------------------------------------------------------------+ // // $Id: Page.php,v 1.8 2002/02/28 08:27:13 sebastian Exp $ require_once "HTML/Common.php"; /** * Base class for HTML pages * * This class handles the details for creating a properly constructed HTML page. * Page caching, stylesheets, client side script, and Meta tags can be * managed using this class. * @author Adam Daniel * @version 1.0 * @since PHP 4.0.3pl1 */ class HTML_Page extends HTML_Common { /** * Controls caching of the page * @var bool * @access private */ var $_cache = False; /** * HTML page title * @var string * @access private */ var $_title = ""; /** * Array of meta tags * @var array * @access private */ var $_metaTags = array("GENERATOR"=>"PEAR HTML_Page"); /** * Array of linked style sheets * @var array * @access private */ var $_styleSheets = array(); /** * Array of linked scripts * @var array * @access private */ var $_scripts = array(); /** * Contents of HTML <BODY> tag * @var mixed * @access public */ var $body = ""; /** * Returns the HTML page * @access public * @return string of HTML */ function toHtml() { $strName = ""; $strContent = ""; $intCounter = 0; $strHtml = ""; if ($this->_comment) { $strHtml = "\n"; } $strHtml .= "\n"; $strHtml .= "\n"; $strHtml .= " $this->_title \n"; for(reset($this->_metaTags); $strName = key($this->_metaTags); next($this->_metaTags)) { $strContent = pos($this->_metaTags); $strHtml .= "\n"; } for($intCounter=0; $intCounter_styleSheets); $intCounter++) { $strStyleSheet = $this->_styleSheets[$intCounter]; $strHtml .= "\n"; } for($intCounter=0; $intCounter_scripts); $intCounter++) { $strType = $this->_scripts[$intCounter]["type"]; $strSrc = $this->_scripts[$intCounter]["src"]; $strHtml .= "\n"; } $strHtml .= "\n"; $strAttr = $this->_getAttrString($this->_attributes); $strHtml .= "\n"; if (is_object($this->body)) { if (method_exists($this->body, "toHtml")) { $strHtml .= $this->body->toHtml(); } elseif (method_exists($contents, "toString")) { $strHtml .= $contents->toString(); } } elseif(is_array($this->body)) { foreach ($this->body as $element) { if (is_object($element)) { if (method_exists($element, "toHtml")) { $strHtml .= $element->toHtml(); } elseif (method_exists($element, "toString")) { $strHtml .= $element->toString(); } } else { $strHtml .= $element; } } } else { $strHtml .= $this->body; } $strHtml .= "\n"; $strHtml .= "\n"; return $strHtml; } // end func toHtml /** * Displays the HTML page to screen * @access public */ function display() { if(! $this->_cache) { header("Expires: Tue, 1 Jan 1980 12:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); } $strHtml = $this->toHtml(); print $strHtml; } // end func display /** * Adds a linked style sheet to the page * @param string $url URL to the linked style sheet * @access public */ function addStyleSheet($url) { $this->_styleSheets[] = $url; } // end func addStyleSheet /** * Adds a linked script to the page * @param string $url URL to the linked style sheet * @param string $type (optional) Type of script. Defaults to 'javascript' * @access public */ function addScript($url, $type="javascript") { $this->_scripts[] = array("type"=>$type, "src"=>$url); } // end func addScript /** * Adds a meta tag to the page * @param string $name META tag name * @param string $content META tag contents * @access public */ function addMetaData($name, $content) { $this->_metaTags[$name] = $content; } // end func addMetaData /** * Sets the caching of the page * @param bool $cache Set to false to turn page caching off * @access public */ function setCache($cache) { $this->_cache = $cache; } // end func setCache /** * Sets the title of the page * @param string $title * @access public */ function setTitle($title) { $this->_title = $title; } // end func setTitle /** * Return the title of the page * @access public * @returns string */ function getTitle() { return $this->_title; } // end func getTitle } // end class HTML_Page ?>