<?php

	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
	include_once( PLOG_CLASS_PATH."plugins/textparser/class/view/adminplugintextparsersettingsview.class.php" );

	/**
	 * updates the plugin configuration
	 */
	class AdminPluginTextParserUpdateSettingsAction extends AdminAction
	{
	
		var $_pluginEnabled;
		var $_filter;
		
		function AdminPluginTextParserUpdateSettingsAction( $actionInfo, $request )
		{
			$this->AdminAction( $actionInfo, $request );
		}
		
		function validate()
		{
            $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
            $this->_pluginEnabled = ($this->_pluginEnabled != "" );			
            $this->_filter = $this->_request->getValue( "filter" );
            if( $this->_filter == "" )
                $this->_filter = PLUGIN_TEXTPARSER_FILTER_WIKI;
			
			return true;
		}

		function perform()
		{
            // and check which smiley set we should be using, or if none, then the default one
			$blogSettings = $this->_blogInfo->getSettings();
            $blogSettings->setValue( "plugin_textparser_enabled", $this->_pluginEnabled );
            $blogSettings->setValue( "plugin_textparser_filter", $this->_filter );
            $this->_blogInfo->setSettings( $blogSettings );
		
			// save the blogs settings
			$blogs = new Blogs();
            if( !$blogs->updateBlog( $this->_blogInfo )) {
                $this->_view = new AdminPluginTextParserSettingsView( $this->_blogInfo );
                $this->_view->setErrorMessage( "message", $this->_locale->tr("error_updating_settings"));
                $this->setCommonData();

                return false;
            }
			
			// if everything went ok...
            $this->_blogInfo->setSettings( $blogSettings );
            $this->_session->setValue( "blogInfo", $this->_blogInfo );
            $this->saveSession();
			
			$this->_view = new AdminPluginTextParserSettingsView( $this->_blogInfo );
			$this->_view->setSuccessMessage( $this->_locale->tr("textparser_settings_saved_ok"));
			$this->setCommonData();
			
			// clear the cache
			CacheControl::resetBlogCache( $this->_blogInfo->getId());					
            
            return true;		
		}
	}
?>