Location: PHPKode > scripts > XHTML Page Creator > xhtml-page-creator/XHTMLClass.php
<?php
#------------------------------------------------------------------------------------------------------
#
#	CLASS:			XHTML 1.0 Page Creator Class
#	FILE:			XHTMLClass.php
#	AUTHOR:			Gabor Magasvari [Hungary]
#	COPYRIGHT:		Gábor Magasvári (c) 2005/11/13
#	LICENCE:		Creative Commons Attribution-NonCommercial-NoDerivs 2.5 Hungary License
#					- Look at: http://creativecommons.org/licenses/by-nc-nd/2.5/
#					- If you used the class send a thanks e-mail to: magasvari[at]gmail[dot]com. 
#					Subject: "XHTML 1.0 Page Creator Class" 
#	VERSION:		2.0
#
#-------------------------------------------------------------------------------------------------------

class CreateXHTMLDocument 
	{
	var $title; // Document title (between <title> tags)
	var $charset = "charset=iso-8859-1"; // Default charset
	var $xmllang = "eng"; // Default xml:lang
	var $meta = array();
	var $metadata;
	var $meta_link = array();
	var $meta_link_data;
	var $elements;
	var $head_elements;
	var $profile;

	function GetDynamic ()
		{
		/* PHP scripts often generate dynamic content that must not be cached 
		by the client browser or any proxy caches between the server and the 
		client browser. Many proxies and clients can be forced to disable caching with: */
			// Date in the past
			$XHD = header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
			// always modified
			$XHD .= header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
			// HTTP/1.1
			$XHD .= header("Cache-Control: no-store, no-cache, must-revalidate");
			$XHD .= header("Cache-Control: post-check=0, pre-check=0", false);
			// HTTP/1.0
			$XHD .= header("Pragma: no-cache");
			return $XHD;
		} 
		
	function Header () // Main function
		{
		$Header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="'.$this->xmllang.'" xmlns="http://www.w3.org/1999/xhtml">
<head'.$this->HeadProfile ().'>
<title>'.$this->title.'</title>
<meta http-equiv="Content-Type" content="text/html; '.$this->charset.'" />'."\n"
.$this->MetaData ()."\n"
.$this->MetaLinks ()."\n"
.$this->HeadOther ().
'</head>'."\n\n";
		$Header .= "<body>\n<!-- Start the content -->\n";
		echo $Header;
		}
	
	function SetProfile ($profile)
		{
		$this->profile = $profile;
		}
		
	function SetDocumentTitle ($title)
		{
		$this->title = $title;
		}
		
	function SetCharset ($charset)
		{
		$this->charset = $charset;
		}
		
	function SetXMLLang ($xmllang)
		{
		$this->xmllang = $xmllang;
		}
	
	function SetMeta ($meta)
		{
		$this->meta = $meta;
		
		foreach ($this->meta as $meta_array)
			{
			if (is_string($meta_array)) $this->metadata .= "<!-- " . $meta_array . " -->\n"; // Comments
			else
			{
			if (is_array($meta_array[2])) $meta_array[2] = $this->KeyWords ($meta_array[2]); // Usage of the datas in array
			$this->metadata .= '<meta '.$meta_array[0].'="'.$meta_array[1].'" ';
			(strtolower($meta_array[1]) == strtolower("PICS-Label")) ? $this->metadata .= 'content=\''.$meta_array[2].'\' ' : $this->metadata .= 'content="'.$meta_array[2].'" ';
			
			if(isset($meta_array[3]) && is_array($meta_array[3])) 
				{
				foreach ($meta_array[3] as $name => $content)
					{
					$this->metadata .= $name.'="'.$content.'" ';
					}
				}
			if(isset($meta_array[4]) && is_array($meta_array[4])) 
				{
				foreach ($meta_array[4] as $name => $content)
					{
					$this->metadata .= $name.'="'.$content.'" ';
					}
				}
			$this->metadata .= '/>'."\n";
			}
			}
		}
		
	function SetMetaLinks ($meta_link)
		{
		$this->meta_link = $meta_link;
		
		foreach ($this->meta_link as $meta_link_array)
			{
			if (is_string($meta_link_array)) $this->meta_link_data .= "<!-- " . $meta_link_array . " -->\n"; // Comments
			else
			{
			$this->meta_link_data .= '<link '.$meta_link_array[0].'="'.$meta_link_array[1].'" href="'.$meta_link_array[2].'" ';
			if(isset($meta_link_array[3]) && is_array($meta_link_array[3])) 
				{
				foreach ($meta_link_array[3] as $name => $content)
					{
					$this->meta_link_data .= $name.'="'.$content.'" ';
					}
				}
			if(isset($meta_link_array[4]) && is_array($meta_link_array[4])) 
				{
				foreach ($meta_link_array[4] as $name => $content)
					{
					$this->meta_link_data .= $name.'="'.$content.'" ';
					}
				}
			$this->meta_link_data .= '/>'."\n";
			}
			}
		}
		
	function HeadProfile ()
		{
		if (strlen($this->profile))
		return (' profile="'.$this->profile.'"');
		}
	
	function MetaData ()
		{
		return $this->metadata;
		}
		
	function MetaLinks ()
		{
		return $this->meta_link_data;
		}
		
	function OtherHeadElement ($elements)
		{
		$this->head_elements = $elements;
		}
		
	function HeadOther ()
		{
		return $this->head_elements."\n";
		}
	function DocumentEnd ()
		{
		echo "\n<!-- End the content -->\n</body>\n</html>";
		}
	
	function KeyWords ($keywords_array)
		{
		$keywords = NULL;
		foreach ($keywords_array as $kv)
			{
			$keywords .= $kv .", ";
			}
		$pos = strrpos($keywords, ",");
		if ($pos === false) 
			{ // note: three equal signs
   			 // not found...
			$keywords = $keywords_array;
			}
			else
			{
			$keywords = substr($keywords, 0, $pos);
			}
		return $keywords;
		}
	
	} // Class END
?>
Return current item: XHTML Page Creator