<?php
    /*
    Copyright 2006, 2008 Paul Westbrook (paul@westbrooks.org)
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */



	lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
	lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );


	class PluginRssImport extends PluginBase
	{
		var $pluginEnabled;
		
		function PluginRssImport( $source = "" )
		{
			$this->PluginBase($source);

			$this->id      = "rssimport";
			$this->author  = "Paul Westbrook";
			$this->desc    = "The Rss Import plugin imports an rss feed and creates an article with the contentss";
			$this->version = "20080715";

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

			if( $source == "admin" )
				$this->initAdmin();
			else
				$this->init();
		}
		
		function init()
		{
			$this->registerBlogAction( "importFeed", "ImportRssFeedAction" );
		}


		function initAdmin()
		{
		        $this->registerAdminAction( "rssImportConfig", "PluginRssImportConfigAction" );
			$this->registerAdminAction( "updateRssImportConfig", "PluginRssImportUpdateConfigAction" );
			
			$menu =& Menu::getMenu();
			if( !$menu->entryExists( "/menu/controlCenter/manageIntegrationPlugins" ))						
				$this->addMenuEntry( "/menu/controlCenter", "manageIntegrationPlugins", "", "", true, false );			
			
			$this->addMenuEntry( "/menu/controlCenter/manageIntegrationPlugins", "rssimport", "?op=rssImportConfig", "" );
		}

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

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

		function getImportRssUrl($accessKey)
		{
			lt_include( PLOG_CLASS_PATH."class/net/rawrequestgenerator.class.php" );
		
 			$rg = new RawRequestGenerator($this->blogInfo);
            
	            	$rg->addParameter( "op", "importFeed" );
            		$rg->addParameter( "accessKey", $accessKey);

            		$importRssUrl = $rg->getIndexUrl().$rg->getRequest();

			return $importRssUrl;
		}
	    
	}
?>
