blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Meta   Login nu   Login
blank.gif
 ««« Se kilde koden
blank.gif
triangle.gif Basic Base  Component Db Dto Form Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util
blank.gif
blank.gif
 
arrow-headline.gif Index
 
  Tilbage

Navn : Meta.php


Sample code, tutorial

Sådan benyttes komponenten Meta klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Meta.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Meta
    ::display($param1, $param2, $param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object
    = new Meta($param1, $param2, $param3, ...);
    print
    $object->getHtml();
    ?>

Parent html

Sådan vises komponenten Meta klassen


PHP source code

Den fulde PHP kildekode for Meta klassen

<?
/**
* @package base
* @filesource
* @see HTML_BASE_PAGE_PATH.'/Meta.php'
* @copyright (c) http://Finn-Rasmussen.com
* @license http://Finn-Rasmussen.com/license/ myPHP License conditions
* @author http://Finn-Rasmussen.com
* @version 1.10
* @since 22-feb-2007
*/

/**
* 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;
        }

        
$this->robots       = META_ROBOTS;
        
$this->copyright    = TEXT_COPYRIGHT_BY.' '.META_COPYRIGHT_TEXT;
        
$this->author       = TEXT_CREATED_BY.' '.META_AUTHOR_TEXT;

        
$this->Content_Type = META_CONTENT_TYPE;
        
$this->Content_Language = $language!=''?$language:PAGE_LANGUAGE;

        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';

            
$this->resource_type = META_RESOURCE_TYPE;
            
$this->distribution  = META_DISTRIBUTION;
            
$this->revisit_after = META_REVISIT_AFTER;
            
            
// IE specific    
            
$this->Site_Enter    = META_SITE_ENTER;
            
$this->Site_Exit     = META_SITE_EXIT;
            
$this->Page_Enter    = META_PAGE_ENTER;
            
$this->Page_Exit     = META_PAGE_EXIT;
        }
    }

    
/**
     * Get html
     * Returns the meta data for the page
     * @return String the complete html
     */
    
function getHtml() {
        
$html = $this->html;
        if (
defined('HTTP_USER_AGENT') && HTTP_USER_AGENT!=HTTP_USER_AGENT_P900) {
            if (
$this->keyword!='') {
                
$html .= "<!-- ".$this->getClassName().' keyword: '.$this->keyword." -->\r\n"; // TODO what?
            
}
            
$html .= $this->getContent('title'      , META_SHOW_CONTENT_TITLE);
            
$html .= $this->getContent('description', META_SHOW_CONTENT_DESCRIPTION);
            
$html .= $this->getContent('keywords'   , META_SHOW_CONTENT_KEYWORDS);
            
$html .= $this->getContent('robots'     , META_SHOW_CONTENT_ROBOTS);
            
$html .= $this->getContent('copyright'  , META_SHOW_CONTENT_COPYRIGHT);
            
$html .= $this->getContent('author'     , META_SHOW_CONTENT_AUTHOR);
            
$html .= $this->getContent('resource_type', META_SHOW_CONTENT_RESOURCE_TYPE);
            
$html .= $this->getContent('distribution' , META_SHOW_CONTENT_DISTRIBUTION);
            
$html .= $this->getContent('revisit_after', META_SHOW_CONTENT_REVISIT_AFTER);
            
            
// IE Specific
            
$html .= $this->getHttpEquiv('Site_Enter', META_SHOW_HTTP_EQUIV_SITE_ENTER);
            
$html .= $this->getHttpEquiv('Site_Exit' , META_SHOW_HTTP_EQUIV_SITE_EXIT);
            
$html .= $this->getHttpEquiv('Page_Enter', META_SHOW_HTTP_EQUIV_PAGE_ENTER);
            
$html .= $this->getHttpEquiv('Page_Exit' , META_SHOW_HTTP_EQUIV_PAGE_EXIT);

            
$html .= $this->getHttpEquiv('keywords'  , META_SHOW_HTTP_EQUIV_KEYWORDS);
            
            
$html .= $this->getHttpEquiv('Content_Type', META_SHOW_HTTP_EQUIV_CONTENT_TYPE);
            
$html .= $this->getHttpEquiv('Content_Language', META_SHOW_HTTP_EQUIV_LANGUAGE);
            
$html .= $this->getHttpEquiv('Expires', META_SHOW_HTTP_EQUIV_EXPIRES);
            
$html .= $this->getHttpEquiv('Cache_Control', META_SHOW_HTTP_EQUIV_CACHE_CONTROL);
            
$html .= $this->getHttpEquiv('Pragma', META_SHOW_HTTP_EQUIV_PRAGMA);
            if (
defined('JAVASCRIPT_INCLUDE') && JAVASCRIPT_INCLUDE & JAVASCRIPT_INCLUDE_WIDG_EDITOR) {
                
//$html .= '<meta name="MSSmartTagsPreventParsing" content="true" />'."\r\n";
            
}
        }
        return
$html;
    }

    
/**
     * Set the Meta Content.
     * @param String $name  The name of the meta content tag
     * @param String $value The value of the content attribute
     */
    
function setContent($name,$value) {
        
$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();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Meta klassen

<?
<!-- Meta keyword: Meta -->
<
meta name="title" content="Meta @ finn-rasmussen.com" />
<
meta name="description" content="Meta" />
<
meta name="keywords" content="finn-rasmussen.com,Meta" />
<
meta name="robots" content="ALL" />
<
meta name="copyright" content="Copyright (c) http://hvepseeksperten.dk/copyright/" />
<
meta name="author" content="Designet af http://Finn-Rasmussen.com/" />
<
meta name="resource_type" content="document" />
<
meta name="distribution" content="global" />
<
meta name="revisit_after" content="2 days" />
<
meta http-equiv="keywords" content="finn-rasmussen.com,Meta" />
<
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<
meta http-equiv="Content-Language" content="da" />
<
meta http-equiv="Expires" content="-1" />
<
meta http-equiv="Cache-Control" content="no-cache" />
<
meta http-equiv="Pragma" content="no-cache" />

?>

Class methods

Her er 'klasse metoderne' for Meta klassen:

  • meta
  • gethtml
  • setcontent
  • getcontent
  • sethttpequiv
  • gethttpequiv
  • display
  • object
  • getclassname
  • getmsg
  • addhtml
  • tostring
  • getcachefilename
  • save
  • content
  • html
  • setobject
  • set
  • get
  • getattribute
  • gettag
  • add
  • getsizeof
  • getelement
  • getelements
  • gettoogle
  • getmaximize
  • getminimize
  • newtriangle
  • showsource

Object vars

Her er 'objekt variable' for Meta klassen:

  • title => Meta @ finn-rasmussen.com
  • description => Meta
  • keyword => Meta
  • keywords => finn-rasmussen.com,Meta
  • robots => ALL
  • copyright => Copyright (c) http://hvepseeksperten.dk/copyright/
  • author => Designet af http://Finn-Rasmussen.com/
  • Content_Type => text/html; charset=ISO-8859-1
  • Content_Language => da
  • Expires => -1
  • Cache_Control => no-cache
  • Pragma => no-cache
  • resource_type => document
  • distribution => global
  • revisit_after => 2 days
  • Site_Enter => blendTrans(Duration=3.0)
  • Site_Exit => blendTrans(Duration=3.0)
  • Page_Enter => blendTrans(Duration=3.0)
  • Page_Exit => blendTrans(Duration=3.0)
  • refresh =>
  • content =>
  • html =>
  • sql =>
  • elements => Array
  • sizeof => 0

 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif