Location: PHPKode > projects > Yupi cms > yupi-cms/include/class.yc_page.php
<?php
/**
 * @author Edin.o
 * @copyright 2008
 */

/**
 * Singleton class that should provide all information about web page
 * such as title, keywords, metatags, content, css i js external links, theme and theme file,
 * header, footer, inline style and js scripts, also there is BasicSettings var
 * that reads additional settings that are common to all pages like Google track code, etc.
 */ 

class Yc_Page
{
    private static $instance;
    var $Title;
    var $Keywords;
    var $Description;
    var $Metatags;
    var $Content;  #main content of web page

    var $CssLinks;
    var $CssStyles;
    var $JsLinks;
    var $JsScripts;

    var $Theme;
    var $ThemeFile;
    
    var $Header;
    var $Footer;
    var $BasicSettings;
    var $Debug = array();


    private function __construct()
    {
        #no public create
        $this->CssLinks = array();
        $this->CssStyles = array();
        $this->JsLinks = array();
        $this->JsScripts = array();
        
        #set default theme and theme file
        $this->Theme ="default";
        $this->ThemeFile="theme.php";
        
		global $BasicSettings;
        $this->Title = $BasicSettings['title'];
        $this->Keywords = $BasicSettings['keywords'];
        $this->Description = $BasicSettings['description'];
        $this->Metatags = $BasicSettings['metatags'];
		
		#Load base page settings
		$reg = new Registry();
		$reg->OpenSection("System\Settings\General");
		$this->Settings = $reg->GetKeys();
		unset($reg);	
    }

    static function getInstance()
    {
        if (!isset(self::$instance)) {
            self::$instance = new Yc_Page();
        }
        return self::$instance;
    }

    #Include a script to page
    function IncludeScript($script)
    {
        if (!in_array($script, $this->JsScripts)) {
            $this->JsScripts[] = $script;
        }
    }
    
    #Include inline style
    function AddInlineStyle($style){
        if (!in_array($style, $this->CssStyles)) {
            $this->CssStyles[] = $style;
        }    	
	}

    #Mantains array of CSS files which will be included in the page
    function IncludeCSS($filePath)
    {
        if (!in_array($filePath, $this->CssLinks)) {
            $this->CssLinks[] = $filePath;
        }
    }

    #Mantains array of java script files which will be included in the page
    function IncludeJS($filePath)
    {
        if (!in_array($filePath, $this->JsLinks)) {
            $this->JsLinks[] = $filePath;
        }
    }
    #Build css and java links
    function GetCssAndJSLinks()
    {
        $lib =  html_file('lib');
        
        $inc = "";
        for ($i = 0; $i < sizeof($this->CssLinks); $i++) {
            $path = str_replace('{lib}', $lib, $this->CssLinks[$i]);
            $inc .= "<link rel='stylesheet' type='text/css' href='$path'/>\n";
        }

        for ($i = 0; $i < sizeof($this->JsLinks); $i++) {
            $path = str_replace('{lib}', $lib, $this->JsLinks[$i]);
            $inc .= "<script type='text/javascript' src='$path'></script>\n";
        }
        return $inc;
    }

    #returns a page script
    function GetPageScript()
    {
        return join("\n", $this->JsScripts);
    }
    
    #return inline style
    function GetInlineStyle(){
		return join("\n",$this->CssStyles);
	 }
    
    function GetHeader(){
    	
    	$links  = $this->GetCssAndJSLinks();
    	$script = $this->GetPageScript();

    	
    	$header =<<<DOC
<!--Content generated by Yupi-Cms, yupi-cms.com ligthweight cms-->
<!--begin header-->    	
<title>{$this->Title}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="keywords" content="{$this->Keywords}" />
<meta name="description" content="{$this->Description}" />
{$this->Metatags}
{$links}
{$script}
<!--end of header-->
DOC;
    	return $header;
    }
}

?>
Return current item: Yupi cms