<?php

    include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
    include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
	include_once( PLOG_CLASS_PATH."plugins/hiddeninput/class/security/hiddeninputfilter.class.php" );
    
    /**
     * Plugin that offers hidden fields to comment form to prevent spammer post from spam robot
     */
    class PluginHiddenInput extends PluginBase
    {
        var $prefix;
        var $pluginEnabled;
        var $hiddenFields;
           
        function PluginHiddenInput()
        {
            $this->PluginBase();
  
            $this->id = "hiddeninput";
            $this->author = "Mark Wu";
            $this->desc = "This plugin offers hidden fields to comment form to prevent spammer post from spam robot.";
  
            $this->prefix = Db::getPrefix();
            
            $this->locales = Array( "en_UK" , "zh_TW" );
            
            $this->init();            
        }

		function init()
		{
			// register the filter
			$this->registerFilter( "HiddenInputFilter" );

            $this->registerAdminAction( "hiddeninput", "PluginHiddenInputConfigAction" );
			$this->registerAdminAction( "updateHiddenInputConfig", "PluginHiddenInputUpdateConfigAction" );
			
			$menu =& Menu::getMenu();
			if( !$menu->entryExists( "/menu/controlCenter/manageAntiSpamPlugins" ))						
				$this->addMenuEntry( "/menu/controlCenter", "manageAntiSpamPlugins", "", "", true, false );			
            $this->addMenuEntry( "/menu/controlCenter/manageAntiSpamPlugins", "HiddenInput", "?op=hiddeninput", "" );            
		}

		function register()
		{
		    $blogSettings = $this->blogInfo->getSettings();
		    $this->pluginEnabled = $blogSettings->getValue( "plugin_hiddeninput_enabled" );
	        $this->hiddenFields = $blogSettings->getValue( "plugin_hiddeninput_hiddenfields" );
	    }
	    
	    function isEnabled()
	    {
	        return $this->pluginEnabled;
	    }
	    
	    function getHiddenFields()
	    {
		    $hiddenFieldsList = explode(",", $this->hiddenFields);            
            
            $commentHiddenFields = Array();
            foreach( $hiddenFieldsList as $hiddenField ) {
            	array_push($commentHiddenFields, trim($hiddenField));
            }
            return $commentHiddenFields;
        }
    }
?>