// Merge -> revision 8720

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8722 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-09-22 15:45:10 +00:00
parent 69db63f26c
commit 4f2a090e24
87 changed files with 1591 additions and 724 deletions
+34 -12
View File
@@ -44,7 +44,7 @@ class Blockrss extends Module
$this->displayName = $this->l('RSS feed block');
$this->description = $this->l('Adds a block displaying an RSS feed.');
$this->version = '1.0';
$this->version = '1.1';
$this->author = 'PrestaShop';
$this->error = false;
$this->valid = false;
@@ -65,34 +65,51 @@ class Blockrss extends Module
if (Tools::isSubmit('submitBlockRss'))
{
$errors = array();
$urlfeed = strval(Tools::getValue('urlfeed'));
$title = strval(Tools::getValue('title'));
$nbr = (int)(Tools::getValue('nbr'));
if ($urlfeed AND !Validate::isUrl($urlfeed))
$errors[] = $this->l('Invalid feed URL');
elseif (!$title OR empty($title) OR !Validate::isGenericName($title))
$errors[] = $this->l('Invalid title');
elseif (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
$errors[] = $this->l('Invalid number of feeds');
elseif (stristr($urlfeed, $_SERVER['HTTP_HOST'].__PS_BASE_URI__))
$errors[] = $this->l('You have selected a feed URL on your own website. Please choose another URL');
elseif (!($contents = @file_get_contents($urlfeed)))
$errors[] = $this->l('Feed is unreacheable, check your URL');
/* Even if the feed was reachable, We need to make sure that the feed is well formated */
else
{
if (stristr($urlfeed, $_SERVER['HTTP_HOST'].__PS_BASE_URI__))
$errors[] = $this->l('Error: You have selected a feed URL on your own website. Please choose another URL (eg. http://news.google.com/?output=rss).');
try
{
$xmlFeed = new XML_Feed_Parser($contents);
}
catch (XML_Feed_Parser_Exception $e)
{
$errors[] = $this->l('Invalid feed:').' '.$e->getMessage();
}
}
if (!sizeof($errors))
{
Configuration::updateValue('RSS_FEED_URL', $urlfeed);
Configuration::updateValue('RSS_FEED_TITLE', $title);
Configuration::updateValue('RSS_FEED_NBR', $nbr);
}
if (isset($errors) AND sizeof($errors))
$output .= $this->displayError(implode('<br />', $errors));
else
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
else
$output .= $this->displayError(implode('<br />', $errors));
}
else
{
$errors = array();
if (stristr(Configuration::get('RSS_FEED_URL'), $_SERVER['HTTP_HOST'].__PS_BASE_URI__))
$errors[] = $this->l('Error: You have selected a feed URL on your own website. Please choose another URL (eg. http://news.google.com/?output=rss).');
$errors[] = $this->l('You have selected a feed URL on your own website. Please choose another URL');
if (sizeof($errors))
$output .= $this->displayError(implode('<br />', $errors));
@@ -115,7 +132,7 @@ class Blockrss extends Module
<label>'.$this->l('Add a feed URL').'</label>
<div class="margin-form">
<input type="text" size="85" name="urlfeed" value="'.htmlentities(Tools::getValue('urlfeed', Configuration::get('RSS_FEED_URL'))).'" />
<p class="clear">'.$this->l('Add the URL of the feed you want to use').'</p>
<p class="clear">'.$this->l('Add the URL of the feed you want to use (sample: http://news.google.com/?output=rss)').'</p>
</div>
<label>'.$this->l('Number of threads displayed').'</label>
@@ -141,10 +158,17 @@ class Blockrss extends Module
// Getting data
$rss_links = array();
if ($url && ($contents = @file_get_contents($url)))
try
{
if (@$src = new XML_Feed_Parser($contents))
for ($i = 0; $i < ($nb ? $nb : 5); $i++)
if (@$item = $src->getEntryByOffset($i))
$rss_links[] = array('title' => $item->title, 'url' => $item->link);
}
catch (XML_Feed_Parser_Exception $e)
{
Tools::dieOrLog(Tools::displayError('Error: invalid RSS feed in blockrss module').' '.$e->getMessage(), false);
}
// Display smarty
$this->context->smarty->assign(array('title' => ($title ? $title : $this->l('RSS feed')), 'rss_links' => $rss_links));
@@ -161,6 +185,4 @@ class Blockrss extends Module
{
$this->context->controller->addCSS(($this->_path).'blockrss.css', 'all');
}
}
}