name = 'blockrss'; $this->tab = 'Blocks'; parent::__construct(); $this->displayName = $this->l('RSS feed block'); $this->description = $this->l('Adds a block displaying an RSS feed'); $this->version = '1.0'; $this->error = false; $this->valid = false; } function install() { Configuration::updateValue('RSS_FEED_TITLE', $this->l('RSS feed')); Configuration::updateValue('RSS_FEED_NBR', 5); if (parent::install() == false OR $this->registerHook('leftColumn') == false) return false; return true; } public function getContent() { $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitBlockRss')) { $urlfeed = strval(Tools::getValue('urlfeed')); $title = strval(Tools::getValue('title')); $nbr = intval(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 cannot select your own RSS feed'); else { 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('
', $errors)); else $output .= $this->displayConfirmation($this->l('Settings updated')); } return $output.$this->displayForm(); } public function displayForm() { $output = '
'.$this->l('Settings').'

'.$this->l('Create a title for the block (default: \'RSS feed\')').'

'.$this->l('Add the url of the feed you wan\'t to use').'

'.$this->l('The number of threads displayed by the block (default value: 5)').'

'; return $output; } function hookLeftColumn($params) { global $smarty; // Conf $title = strval(Configuration::get('RSS_FEED_TITLE')); $url = strval(Configuration::get('RSS_FEED_URL')); $nb = intval(Configuration::get('RSS_FEED_NBR')); // Getting data $rss_links = array(); if ($url && ($contents = @file_get_contents($url))) 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); // Display smarty $smarty->assign(array( 'title' => ($title ? $title : $this->l('RSS feed')), 'rss_links' => $rss_links )); return $this->display(__FILE__, 'blockrss.tpl'); } function hookRightColumn($params) { return $this->hookLeftColumn($params); } } ?>