<?php
	include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
	include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );

	class PlugincoComment extends PluginBase
	{
		var $pluginEnabled;
		
		function PlugincoComment()
		{
			$this->PluginBase();

			$this->id      = "cocomment";
			$this->author  = "James Huang";
			$this->desc    = "Integrate cocomment into LifeType commentform template.";

			$this->locales = Array( "en_UK" , "zh_TW" );

			$this->init();
		}

		function init()
		{
            $this->registerBlogAction( "coComment", "ShowcoCommentAction" );
            $this->registerAdminAction( "coCommentConfig", "PlugincoCommentConfigAction" );
			$this->registerAdminAction( "updatecoCommentConfig", "PlugincoCommentUpdateConfigAction" );
			
			$menu =& Menu::getMenu();
			if( !$menu->entryExists( "/menu/controlCenter/manageAppearancePlugins" ))						
				$this->addMenuEntry( "/menu/controlCenter", "manageAppearancePlugins", "", "", true, false );			
            $this->addMenuEntry( "/menu/controlCenter/manageAppearancePlugins", "coComment", "?op=coCommentConfig", "" );
		}

		function register()
		{
		    $blogSettings = $this->blogInfo->getSettings();
			$this->pluginEnabled = $blogSettings->getValue( "plugin_cocomment_enabled" );
		}

	    function isEnabled()
	    {
	        return $this->pluginEnabled;
	    }
	    
	    function show($postId)
	    {

			$str = '';
	    
            if ($this->isEnabled())
            {
            
                // articles object
                $articles = new Articles;
    
    
                $rg = $this->blogInfo->getBlogRequestGenerator();
                $post = $articles->getBlogArticle($postId);
    
                $str = '<script type="text/javascript">';
                $str .= 'var blogTool = "LifeType";';
                $str .= 'var blogURL = "'.$rg->blogLink().'";';
                $str .= 'var blogTitle = "'.$this->blogInfo->getBlog().'";';
                $str .= 'var postURL = "'.$rg->postPermalink($post).'";';
                $str .= 'var postTitle = "'.$post->getTopic().'";';
                $str .= 'var commentAuthorFieldName = "userName";';
                $str .= 'var commentAuthorLoggedIn = false;';
                $str .='var commentFormID = "NewComment";';
                $str .='var commentTextFieldName = "commentText";';
                $str .='var commentButtonName = "Add";';
    //			$str .='var cocomment_force = false;';
                $str .='</script>';
                $str .='<script id="cocomment-fetchlet" src="http://www.cocomment.com/js/enabler.js"></script>';
            }
	    	return $str;
		}
	}
?>