/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Html.php');
require_once(HTML_BASIC_UTIL_PATH.'/Message.php');
/**
* The Meta Object is used to define the html meta tags for a page
* NOTE: The header() function is called inside the file
* @see Cache.php if no cache is defined
* <code>
* Usage:
* $meta = new Meta($title,$description,$keyword,$keywords,$language);
* print $meta->getHtml();
* Or
* print $meta->getHttpEquiv($name);
* Or
* print $meta->getContent($name);
* Or
* $meta = new Meta();
* $meta->setHttpEquiv($name,$value);
* I.e.
* $meta->setHttpEquiv("refresh","1;URL=http://finn-rasmussen.com/");
* print $meta->getHttpEquiv("refresh");
* Or
* Meta::display($title,$description,$keyword,$keywords,$language);
* </code>
* @package base
*/
class Meta extends Html {
var $title = '';
var $description = '';
var $keyword = ''; // Internal usage, not part of the meta tags
var $keywords = '';
var $robots = '';
var $copyright = '';
var $author = '';
var $Content_Type = '';
var $Content_Language = '';
var $Expires = '';
var $Cache_Control = '';
var $Pragma = '';
var $resource_type = '';
var $distribution = '';
var $revisit_after = '';
// IE specific
var $Site_Enter = '';
var $Site_Exit = '';
var $Page_Enter = '';
var $Page_Exit = '';
/**
* @var String $refresh The meta refresh url to redirect to content="time;url""
*/
var $refresh = '';
/**
* @var String $content The meta content
*/
var $content = '';
/**
* Constructor
* @param String $title The title of the page
* @param String $description The description of the page
* @param String $keyword The unique keyword for this page (internal usage)
* @param String $keywords The keywords for the page
* @param String $language The language for the page
*/
function Meta($title='',$description='',$keyword='',$keywords='',$language='') {
$this->Html();
$this->keyword = $keyword!=''?$keyword:PAGE_KEYWORD; // Unique keyword for this page (internal usage)
$this->title = $title!=''?$title:PAGE_TITLE;
if ($this->keyword != '' && strpos($this->title, $this->keyword) === false) {
$this->title = $keyword.' - '.$this->title;
}
if (strpos($this->title, DOMAIN_NAME) === false) {
$this->title .= ' @ '.DOMAIN_NAME;
}
$this->description = $description!=''?$description:PAGE_DESCRIPTION;
$this->keywords = $keywords!=''?$keywords:PAGE_KEYWORDS;
if ($this->keyword != '' && strpos($this->keywords, $this->keyword) === false) {
$this->keywords = $this->keyword.','.$this->keywords;
}
if (strpos($this->keywords, DOMAIN_NAME) === false) {
$this->keywords = DOMAIN_NAME.','.$this->keywords;
}
if (defined('CACHE_BROWSER') && CACHE_BROWSER) {
// Normal
} else {
$filename = '';
$lineno = '';
if (headers_sent($filename, $lineno)) {
// TODO move to another class and add to head.php
//$msg = "Headers are alredy sent see $filename, $lineno";
//Message::add($msg,__FILE__,__LINE__);
} else {
if (defined('CACHE_BROWSER') && CACHE_BROWSER) {
// Do nothing
} else {
header("Expires: mon, 11 mar 1953 18:55:00"); // Date in the past
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); // Always modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP 1.1
// Or use this, if you are using a form and using back button
// header("Cache-control: private");
// Regarding SSL/IE bug/Sessions,
// also make sure you DO NOT SET THE HEADER 'Pragma: no-cache'
// if you are sending an inline document (e.g., PDF document).
// TODO if (! 'SSL') { }
header("Pragma: no-cache"); // HTTP 1.0
}
}
$this->Expires = '-1';
$this->Cache_Control = 'no-cache';
$this->Pragma = 'no-cache';
/**
* Set the Meta Content.
* @param String $name The name of the meta content tag
* @param String $value The value of the content attribute
* @param String $show Show the Meta tag or not the meta tag
*/
function setContent($name, $value, $show) {
if (defined('META_SHOW_CONTENT') && META_SHOW_CONTENT & $show) {
$this->$name = $value;
}
}
/**
* Get Meta name Content.
* Returns the html for the meta name/content
* @param String $name The name of the meta tag
* @param String $show Show the Meta tag or not the meta tag
* @return String the complete html
*/
function getContent($name, $show) {
$html = '';
if (defined('META_SHOW_CONTENT') && META_SHOW_CONTENT & $show) {
if (isset($this->$name) && $this->$name!='') {
$html .= '<meta name="'.$name.'" content="'.$this->$name.'" />'."\r\n";
}
}
return $html;
}
/**
* Set the Meta http-equiv Content.
* @param String $name The name of the meta setHttpEquiv tag
* @param String $value The value of the content attribute
* @param String $show Set the Meta tag or not
*/
function setHttpEquiv($name,$value, $show) {
if (defined('META_SHOW_HTTP_EQUIV') && META_SHOW_HTTP_EQUIV & $show) {
$this->$name = $value;
}
}
/**
* Get Meta http-equiv Content.
* Get the html for the meta http-equiv/content
* Any '_' in the $name, are automatically replaced with '-'
* @param String $name The name of the meta tag
* @param String $show Show the Meta tag or not the meta tag
* @return String The complete html
*/
function getHttpEquiv($name, $show) {
$html = '';
if (defined('META_SHOW_HTTP_EQUIV') && META_SHOW_HTTP_EQUIV & $show) {
if (isset($this->$name) && $this->$name != '') {
$html .= '<meta http-equiv="'.str_replace('_','-',$name).'" content="'.$this->$name.'" />'."\r\n";
}
}
return $html;
}
/**
* Display html
* <code>
* Usage:
* Meta::display($title,$description,$keyword,$keywords,$language);
* </code>
* @static
* @param String $title The title of the page
* @param String $description The description of the page
* @param String $keyword The unique keyword for this page
* @param String $keywords The keywords for the page
* @param String $language The language for the page
*/
function display($title='',$description='',$keyword='',$keywords='',$language='') {
$html = new Meta($title,$description,$keyword,$keywords,$language);
$html->addHtml();
}
}
?>