<?php 

// +----------------------------------------------------------------------+
// | File name : page_context.php                                                |
// | PHP version >= 5.2                                                   |
// +----------------------------------------------------------------------+
// | Author: ARUN SADASIVAN<arun.s@armiasystems.com>              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems � 2010                                      |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+

class PageContext{
	
	 //private static $table_metadata="ei_metadata";
	 public static $metaTitle		  = null;
	 public static $metaDes		  	  = null;
	 public static $metaKey			  = null;
         public static $customTitle	          = null;
	 
	
    public static function registerMetaData() {
        //exit;
        //echo "EasyIndex_payments",;
        $table_metadata=MYSQL_TABLE_PREFIX."metadata";
        $db = new BaseModel();
        $url = $_SERVER['PATH_INFO'];
        if (!($url[strlen($url) - 1] == '/'))
            $url = $url . "/";
        if ($db->checkTableExist($table_metadata)) {

            //Initial Value

            if ($result = $db->selectResultFrom($table_metadata, "keyword,description,title", "url = '*'")) {
                PageContext::$metaKey = $result[0]->keyword;
                PageContext::$metaDes = $result[0]->description;
                PageContext::$metaTitle = $result[0]->title;
                
            }



            $count = substr_count($url, "/");
            $metaTagUrls = $db->selectResultFrom($table_metadata, url, "1=1");

            for ($i = 0; $i < $count; $i++) {
                if ($i == 0)
                    $url = $url;
                else {
                    $url = strrev($url);
                    $url = preg_replace('/\/.*?\//', "*/", $url, 1);
                    $url = strrev($url);
                    $url = str_replace("**", "*", $url);
                    $url = $url . "/";
                }


                foreach ($metaTagUrls as $metaTagUrl) {

                    //For Appending / at end
                    if (!( $metaTagUrl->url[strlen($metaTagUrl->url) - 1] == '/'))
                        $metaTagUrlref->url = $metaTagUrl->url . "/";
                    else
                        $metaTagUrlref->url = $metaTagUrl->url;

                    //For Appending / at Begining
                    if (!($metaTagUrlref->url[0] == '/'))
                        $metaTagUrlref->url = "/" . $metaTagUrlref->url;
                    else
                        $metaTagUrlref->url = $metaTagUrlref->url;

                    //echo "<br>".$metaTagUrlref->url."==".$url;
                    if ($metaTagUrlref->url == $url) {
                        $result = $db->selectResultFrom($table_metadata, "keyword,description,title", "url = '" . $metaTagUrl->url . "'");
                        PageContext::$metaKey = $result[0]->keyword;
                        PageContext::$metaDes = $result[0]->description;
                        PageContext::$metaTitle = $result[0]->title;
                        return;
                    }
                }
            }
        }
    }
	 
	 
}


?>