Your IP : 216.73.216.240
<?php
/**
* @package My RSS Reader
* @copyright Copyright (C) 2010 FalsinSoft. All rights reserved.
* @license GNU/GPL
* @website http://falsinsoft-joomla.blogspot.com
* @email falsinsoft@gmail.com
*
*/
defined('_JEXEC') or die('Restricted access');
class MyRSSReaderController extends JController
{
function __construct($config = array())
{
parent::__construct($config);
$this->registerTask('rss_add', 'display');
$this->registerTask('rss_edit', 'display');
$this->registerTask('category_add', 'display');
$this->registerTask('category_edit', 'display');
$this->registerTask('advertisement_add', 'display');
$this->registerTask('advertisement_edit', 'display');
}
function display($cachable = false)
{
switch($this->getTask())
{
default:
JRequest::setVar('view', 'rsslist');
break;
case 'rss_add':
JRequest::setVar('view', 'rss');
JRequest::setVar('edit', false);
break;
case 'rss_edit':
JRequest::setVar('view', 'rss');
JRequest::setVar('edit', true);
break;
case 'category':
JRequest::setVar('view', 'categorylist');
break;
case 'category_add':
JRequest::setVar('view', 'category');
JRequest::setVar('edit', false);
break;
case 'category_edit':
JRequest::setVar('view', 'category');
JRequest::setVar('edit', true);
break;
case 'advertisement':
JRequest::setVar('view', 'advertisementlist');
break;
case 'advertisement_add':
JRequest::setVar('view', 'advertisement');
JRequest::setVar('edit', false);
break;
case 'advertisement_edit':
JRequest::setVar('view', 'advertisement');
JRequest::setVar('edit', true);
break;
case 'statistics':
JRequest::setVar('view', 'statistics');
break;
case 'settings':
JRequest::setVar('view', 'settings');
break;
case 'about':
JRequest::setVar('view', 'about');
break;
}
parent::display($cachable);
}
function rss_publish()
{
JRequest::checkToken() or die('Invalid Token');
$this->_publish(true, 'RSS');
}
function rss_unpublish()
{
JRequest::checkToken() or die('Invalid Token');
$this->_publish(false, 'RSS');
}
function settings_save()
{
JRequest::checkToken() or die('Invalid Token');
$post = JRequest::get('post');
$error_msg_array = array();
if(is_numeric($post['max_feeds_per_rss']) == false
|| intval($post['max_feeds_per_rss']) <= 0) $error_msg_array[] = JText::_('Max feeds per RSS');
if(is_numeric($post['max_feeds_per_page']) == false
|| intval($post['max_feeds_per_page']) <= 0) $error_msg_array[] = JText::_('Max feeds per page');
if(is_numeric($post['max_error_retry']) == false
|| intval($post['max_error_retry']) < 0) $error_msg_array[] = JText::_('Max retries in case of feeds load errors');
if(is_numeric($post['rss_check_time']) == false
|| intval($post['rss_check_time']) <= 0) $error_msg_array[] = JText::_('Check for new feeds every (in hours)');
if(is_numeric($post['distributed_check_delay']) == false
|| intval($post['distributed_check_delay']) < 0) $error_msg_array[] = JText::_('Delay (in minutes) between distributed checks');
if(is_numeric($post['max_rss_distributed_check']) == false
|| intval($post['max_rss_distributed_check']) <= 0) $error_msg_array[] = JText::_('Max RSS to check each time in distributed mode');
if(is_numeric($post['feed_title_size']) == false
|| intval($post['feed_title_size']) <= 0) $error_msg_array[] = JText::_('Feed title size');
if(intval($post['direct_check_link']) == 1
&& preg_match('/^[a-zA-Z0-9]+$/i', $post['direct_check_link_security_code']) == 0) $error_msg_array[] = JText::_('Security Code');
if(is_numeric($post['direct_check_link_time_limit']) == false
|| intval($post['direct_check_link_time_limit']) <= 0) $error_msg_array[] = JText::_('RSS check time limit');
if(trim($post['max_feed_body_characters_show']) != ''
&& is_numeric($post['max_feed_body_characters_show']) == false) $error_msg_array[] = JText::_('Show only max number of feed body characters');
if(count($error_msg_array) > 0)
{
$error_msg = JText::_('Settings not saved! The following values are incorrect').':<br /><br />';
$error_msg .= implode('<br />', $error_msg_array);
$this->setRedirect('index.php?option=com_myrssreader&task=settings', $error_msg, 'error');
return false;
}
$post['label_checking_for_new_post'] = addslashes(trim($post['label_checking_for_new_post']));
$post['label_checking_finished'] = addslashes(trim($post['label_checking_finished']));
$post['label_source'] = addslashes(trim($post['label_source']));
$post['max_feed_body_characters_show'] = trim($post['max_feed_body_characters_show']);
$table =& JTable::getInstance('extension');
$table->load(array('element'=>'com_myrssreader'));
$registry = new JRegistry();
unset($post['option']);
unset($post['task']);
unset($post[JUtility::getToken()]);
$registry->loadArray($post);
$post['option'] = 'com_myrssreader';
$post['params'] = $registry->toString();
$table->bind($post);
if(!$table->check())
{
JError::raiseWarning(500, $table->getError());
return false;
}
if(!$table->store())
{
JError::raiseWarning(500, $table->getError());
return false;
}
$this->setRedirect('index.php?option=com_myrssreader&task=settings', 'Operation successfull');
}
function rss_save()
{
JRequest::checkToken() or die('Invalid Token');
$post = JRequest::get('post');
$post['title'] = trim($post['title']);
$post['web_url'] = trim($post['web_url']);
$post['rss_url'] = trim($post['rss_url']);
if(strlen($post['title']) == 0) JError::raiseError(500, JText::_('Please, insert a name'));
if(strlen($post['web_url']) == 0) JError::raiseError(500, JText::_('Please, insert the web URL'));
if(strlen($post['rss_url']) == 0) JError::raiseError(500, JText::_('Please, insert the RSS URL'));
$table =& JTable::getInstance('RSS', 'Table');
if(isset($post['id']))
{
if($table->checkIfTitleExist($post['title'], $post['id'])) JError::raiseError(500, 'Title already registered by antoher RSS item');
if($table->checkIfWebUrlExist($post['web_url'], $post['id'])) JError::raiseError(500, 'Web URL already registered by antoher RSS item');
if($table->checkIfRSSUrlExist($post['rss_url'], $post['id'])) JError::raiseError(500, 'RSS URL already registered by antoher RSS item');
if($table->checkIfRSSURLChanged($post['id'], $post['rss_url']))
{
$table->deleteCachedFeeds($post['id']);
$post['last_check'] = '0000-00-00 00:00:00';
$post['start_check'] = '0000-00-00 00:00:00';
$post['check_errors'] = 0;
}
}
else
{
if($table->checkIfTitleExist($post['title'], null)) JError::raiseError(500, JText::_('Title already registered by antoher RSS item'));
if($table->checkIfWebUrlExist($post['web_url'], null)) JError::raiseError(500, JText::_('Web URL already registered by antoher RSS item'));
if($table->checkIfRSSUrlExist($post['rss_url'], null)) JError::raiseError(500, JText::_('RSS URL already registered by antoher RSS item'));
}
if(!$table->bind($post))
{
JError::raiseError(500, $table->getError() );
}
if(!$table->store($post['category_id_list']))
{
JError::raiseError(500, $table->getError() );
}
$this->setRedirect('index.php?option=com_myrssreader' , JText::_('Operation successfull'));
}
function rss_delete()
{
JRequest::checkToken() or die('Invalid Token');
$cid = JRequest::getVar('cid', array(), 'post', 'array');
JArrayHelper::toInteger($cid);
$table =& JTable::getInstance('RSS', 'Table');
if(!$table->deleteRSS($cid))
{
JError::raiseError(500, $table->getError());
}
$this->setRedirect('index.php?option=com_myrssreader');
}
function category_delete()
{
JRequest::checkToken() or die('Invalid Token');
$cid = JRequest::getVar('cid', array(), 'post', 'array');
JArrayHelper::toInteger($cid);
$table =& JTable::getInstance('Category', 'Table');
if(!$table->deteleCategory($cid))
{
JError::raiseError(500, $table->getError() );
}
$this->setRedirect('index.php?option=com_myrssreader&task=category');
}
function category_save()
{
JRequest::checkToken() or die('Invalid Token');
$post = JRequest::get('post');
$post['title'] = trim($post['title']);
$post['description'] = trim($post['description']);
if(strlen($post['title']) == 0) JError::raiseError(500, JText::_('Please, insert a category name'));
$table =& JTable::getInstance('Category', 'Table');
if(!$table->bind($post))
{
JError::raiseError(500, $table->getError());
}
if(!$table->store())
{
JError::raiseError(500, $table->getError());
}
$this->setRedirect('index.php?option=com_myrssreader&task=category' , JText::_('Operation successfull'));
}
function category_cancel()
{
JRequest::checkToken() or die('Invalid Token');
$this->setRedirect('index.php?option=com_myrssreader&task=category');
}
function advertisement_delete()
{
JRequest::checkToken() or die('Invalid Token');
$cid = JRequest::getVar('cid', array(), 'post', 'array');
JArrayHelper::toInteger($cid);
$table =& JTable::getInstance('Advertisement', 'Table');
if(!$table->deteleAdvertisement($cid))
{
JError::raiseError(500, $table->getError() );
}
$this->setRedirect('index.php?option=com_myrssreader&task=advertisement');
}
function advertisement_save()
{
JRequest::checkToken() or die('Invalid Token');
$post = JRequest::get('post');
$post['title'] = trim($post['title']);
$post['html_code'] = trim(JRequest::getString('html_code', '', 'post', 2));
if(strlen($post['title']) == 0) JError::raiseError(500, JText::_('Please, insert an advertisement name'));
if(strlen($post['html_code']) == 0) JError::raiseError(500, JText::_('Please, insert an advertisement html code'));
$table =& JTable::getInstance('Advertisement', 'Table');
if(!$table->bind($post))
{
JError::raiseError(500, $table->getError());
}
if(!$table->store($post['category_id_list']))
{
JError::raiseError(500, $table->getError());
}
$this->setRedirect('index.php?option=com_myrssreader&task=advertisement' , JText::_('Operation successfull'));
}
function advertisement_cancel()
{
JRequest::checkToken() or die('Invalid Token');
$this->setRedirect('index.php?option=com_myrssreader&task=advertisement');
}
function advertisement_publish()
{
JRequest::checkToken() or die('Invalid Token');
$this->_publish(true, 'Advertisement', '&task=advertisement');
}
function advertisement_unpublish()
{
JRequest::checkToken() or die('Invalid Token');
$this->_publish(false, 'Advertisement', '&task=advertisement');
}
function _publish($publish, $table_name, $url_section = '')
{
$cid = JRequest::getVar('cid', array(), 'post', 'array');
JArrayHelper::toInteger($cid);
if(count($cid) < 1)
{
JError::raiseError(500, JText::_('Select one or more item to publish'));
}
$table =& JTable::getInstance($table_name, 'Table');
if(!$table->publish($cid, ($publish == true) ? 1 : 0))
{
echo "<script> alert('".$table->getError(true)."'); window.history.go(-1); </script>\n";
}
$this->setRedirect('index.php?option=com_myrssreader'.$url_section);
}
}
?>