<?php

    lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
    
    /**
	* offers features to inset google analytics javascript codes in tempalte header.
	*/
    class PluginGoogleAnalytics extends PluginBase
    {
        var $pluginEnabled;
		var $uacct;
        
        function PluginGoogleAnalytics( $source = "" )
        {
			$this->PluginBase($source);
			
            $this->id = "googleanalytics";
            $this->author = "lss";
            $this->desc = "This plugin offers features to inset google analytics javascript codes in tempalte header";
            $this->version = "20081119";
  
            $this->locales = Array( "en_UK" , "zh_TW" , "zh_CN", "es_ES", "fr_FR" );
            
			if( $source == "admin" )
				$this->initAdmin();
        }

		function initAdmin()
		{
			$this->registerAdminAction( "googleanalytics", "PluginGoogleAnalyticsConfigAction" );
			$this->registerAdminAction( "updategoogleanalytics", "PluginGoogleAnalyticsUpdateConfigAction" );
			
			$menu =& Menu::getMenu();
            $this->addMenuEntry( "/menu/controlCenter/manageSettings", "GoogleAnalytics", "?op=googleanalytics");
		}

		function register()
		{
		    $blogSettings = $this->blogInfo->getSettings();
		    $this->pluginEnabled = $blogSettings->getValue( "plugin_googleanalytics_enabled" );
	        $this->uacct = $blogSettings->getValue( "plugin_googleanalytics_uacct" );
	    }
	    
	    function isEnabled()
	    {
	        return $this->pluginEnabled;
	    }
        
    /**
		* Returns google analytics javascript Ga.js
		*/
        function getJavascriptCode(){
            $jsCode = "";
            if( $this->isEnabled() ){
                $jsCode ="<script type=\"text/javascript\">\n"
                ."var gaJsHost = ((\"https:\" == "
                ."document.location.protocol) ? \"https://ssl.\" "
                .": \"http://www.\");\n"
                ."document.write(unescape(\"%3Cscript src='\" "
                ." + gaJsHost + \"google-analytics.com/ga.js' "
                ."type='text/javascript'%3E%3C/script%3E\"));\n"
                ."</script>\n"
                ."<script type=\"text/javascript\">\n"
                ."var pageTracker = _gat._getTracker(\"".$this->uacct."\");\n"
                ."pageTracker._initData();\n"
                ."pageTracker._trackPageview();\n"
                ."</script>\n";
            }
			return $jsCode;
        }
        
    }
?>
