<?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/view/admin/adminplugintemplatedview.class.php" );

	/**
	 * implements the main view of the feed reader plugin
	 */
	class PluginRssImportConfigView extends AdminPluginTemplatedView
	{


		function PluginRssImportConfigView( $blogInfo )
		{
			$this->AdminPluginTemplatedView( $blogInfo, "rssimport", "rssimport" );
			
		}
		
		function render()
		{
			// load some configuration settings
			$blogSettings = $this->_blogInfo->getSettings();
			$pluginEnabled = $blogSettings->getValue( "plugin_rssimport_enabled" );
			
			$feedurl = $blogSettings->getValue( "plugin_rssimport_feedurl" );

			$accessKey = $blogSettings->getValue( "plugin_rssimport_accessKey" );
			// If accessKey is not set, generate a new one
			if ( $accessKey == null || $accessKey == "" )
			{
			    $rg =& $this->_blogInfo->getBlogRequestGenerator();
			    $rg->blogLink();

			    // Generate a unique accessKey for this plugin
			    $accessKey = md5($rg->blogLink() . time());
			}

//			$accessHosts = $blogSettings->getValue( "plugin_rssimport_accessHosts" );

			// Get the title format string
			$titleFormat = $blogSettings->getValue( "plugin_rssimport_titleFormat" );
			if ( $titleFormat == null || $titleFormat == "" )
			{
			    $locale = $this->_blogInfo->getLocale();
			    $titleFormat = $locale->tr("rssimport_default_titleformat");
			}

			$categoryId = $blogSettings->getValue( "plugin_rssimport_article_category_id" );

			// fetch all the current article categories
			lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php");
			$categories = new ArticleCategories();
			$blogCategories = $categories->getBlogCategories( $this->_blogInfo->getId());

			// get the update url from rssimport plugin and pass to the plugin setting view
			$plugins = $this->_pm->getPlugins();
			$this->setValue( 'importRssUrl', $plugins['rssimport']->getImportRssUrl($accessKey) );


			// create a view and export the settings to the template
			$this->setValue( "pluginEnabled", $pluginEnabled );
			
			$this->setValue( "feedurl", $feedurl );	

			$this->setValue( "accessKey", $accessKey );	

//			$this->setValue( "accessHosts", $accessHosts );	

			$this->setValue( "titleFormat", $titleFormat );

			$this->setValue( "categoryId", $categoryId );
			$this->setValue( "categories", $blogCategories );

			parent::render();			
		}
	}
?>
