public function readAction() { $this->disableLayout(); $this->disableView(); $ressource_dir = dirname(dirname(__FILE__)) . '/ressources'; /* var_dump($this->_request); exit;*/ $feed = $this->_request->getParam('feed'); $catID = $this->_request->getParam('catID'); $feed = str_replace('.xml', "-{$catID}.xml", $feed); $rssLimit = Cible_FunctionsCategories::getRssItemsLimitPerCategory($catID); $langId = Cible_FunctionsGeneral::getLanguageID($this->_request->getParam('lang')); Zend_Registry::set('languageID', $langId); $lang = $this->_request->getParam('lang'); $feed_url = Zend_Registry::get('absolute_web_root') . "/{$this->_request->getParam('lang')}/{$this->_request->getParam('feed')}"; if (file_exists("{$ressource_dir}/{$lang}/{$feed}")) { $lastUpdate = new Zend_Date(filemtime("{$ressource_dir}/{$lang}/{$feed}")); $now = new Zend_Date(); } if (file_exists("{$ressource_dir}/{$lang}/{$feed}") && !$now->isLater($lastUpdate->addMinute($this->_config->rss->refresh->delay))) { $xml = file_get_contents("{$ressource_dir}/{$lang}/{$feed}"); } else { $file = fopen("{$ressource_dir}/{$lang}/{$feed}", "w"); $select = $this->_db->select(); $select->from('NewsData')->joinLeft('NewsIndex', 'NewsData.ND_ID = NewsIndex.NI_NewsDataID')->joinleft('CategoriesIndex', 'CategoriesIndex.CI_CategoryID = NewsData.ND_CategoryID')->joinleft('Categories', 'Categories.C_ID = NewsData.ND_CategoryID')->where('CategoriesIndex.CI_LanguageID = ?', $langId)->where('NewsIndex.NI_LanguageID = ?', $langId)->where('Categories.C_ID = ?', $catID)->where('Categories.C_ShowInRss = ?', 1)->order('ND_Date DESC')->limit($rssLimit); //die($select); $news = $this->_db->fetchAll($select); $feedPubDate = date("r", strtotime('now')); $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; $xml .= "<rss version=\"2.0\">"; $xml .= "<channel>"; $xml .= "<title>" . $this->_config->site->title . "</title>"; $xml .= "<description>"; $xml .= str_replace('##SITE_NAME##', $this->_config->site->title, $this->view->getCibleText('rss_read_description_field_label')); $xml .= "</description>"; $xml .= "<lastBuildDate>{$feedPubDate}</lastBuildDate>"; $xml .= "<link>{$feed_url}</link>"; foreach ($news as $details) { if ($details['NI_Status'] == 1) { // Titres des nouvelles (FR) $title = str_replace("'", "'", $details['NI_Title']); $title = str_replace("<br>", "<br />", $title); $title = str_replace("&", "&", $title); // Textes des nouvelles (FR) $description = str_replace("'", "'", $this->KeepTextOnly($details["NI_Brief"])); $description = htmlspecialchars($description); $description = str_replace("<br>", "<br />", $description); $pubDate = date("r", strtotime($details["ND_ReleaseDate"])); $news_url = Zend_Registry::get('absolute_web_root') . '/' . Cible_FunctionsCategories::getPagePerCategoryView($details["ND_CategoryID"], 'details') . "/ID/{$details['ND_ID']}"; $xml .= "<item>"; $xml .= "<title>{$title}</title>"; $xml .= "<description>{$description}</description>"; $xml .= "<pubDate>{$pubDate}</pubDate>"; $xml .= "<guid>{$news_url}</guid>"; $xml .= "<link>{$news_url}</link>"; $xml .= "</item>"; } } $xml .= "</channel>"; $xml .= "</rss>"; fwrite($file, $xml); fclose($file); } $this->_response->setHeader('Content-Type', 'application/rss+xml'); echo $xml; }