Files
fdn2/private/lib/RSSHelper.php
T
Riccardo Di Dato 4bdf59535c Creata pagina feed RSS della home
Creata classe RSSHelper 
Creata pagina rss contenente le notizie di index

Signed-off-by: Riccardo Di Dato <r.didato@asdynamics.it>
2017-07-17 12:30:08 +02:00

71 lines
2.3 KiB
PHP

<?php
/*
* RSSHelper.php
* Author: Riccardo Di Dato
* Creation Date: 17 lug 2017
*/
class RSSHelper {
public static function generateByNotiziaList(array $notizie){
header('Content-Type: application/xml');
echo '<?xml version="1.0"?>',PHP_EOL;
echo '<rss version="2.0">',PHP_EOL;
echo '<channel>',PHP_EOL;
self::generateChannelInfo();
if (sizeof($notizie)>0){
foreach ($notizie as $notizia){
self::generateNotiziaInfo($notizia);
}
}
echo '</channel>',PHP_EOL;
echo '</rss>',PHP_EOL;
}
private static function generateChannelInfo(){
$conf = GlobalVariables::get("config");
echo '<title>'.$conf->info->projectName.'</title>',PHP_EOL;
echo '<link>'.GUIHandler::getBaseUrl().'</link>',PHP_EOL;
echo '<description>'.$conf->info->projectDescription.'</description>',PHP_EOL;
echo '<language>it-IT</language>',PHP_EOL;
echo '<webMaster>webmaster@ifattidinapoli.it</webMaster>',PHP_EOL;
echo '<image>',PHP_EOL;
echo '<title>'.$conf->info->projectName.'</title>',PHP_EOL;
echo '<link>'.GUIHandler::getBaseUrl().'</link>',PHP_EOL;
echo '<url>'.GUIHandler::getBaseUrl().'/images/logo_uff.png</url>',PHP_EOL;
echo '<width>48</width>',PHP_EOL;
echo '<height>48</height>',PHP_EOL;
echo '</image>',PHP_EOL;
}
private static function generateNotiziaInfo(NotiziaModel $notizia){
$conf = GlobalVariables::get("config");
echo '<item>',PHP_EOL;
echo '<title>'.htmlentities($notizia->titolo).'</title>',PHP_EOL;
echo '<description>'.htmlentities($notizia->testo).'</description>',PHP_EOL;
echo '<link>'.GUIHandler::getBaseUrl().'/articolo_'.$notizia->id.'</link>',PHP_EOL;
$mainMedia = DaoMediaHandler::getMainMediaFromModel($notizia);
if (!is_null($mainMedia) && $mainMedia->hasProperty("mediaType") && $mainMedia->mediaType == MediaModel::TYPE_IMAGE){
$renderer = $mainMedia->getRenderer();
if ($renderer instanceof MediaImage){
$link = $renderer->getImageLink(MediaRendererInterface::SIZE_MEDIUM);
echo '<enclosure url="'.$renderer->getImageLink(MediaRendererInterface::SIZE_MEDIUM).'" length="'.filesize($renderer->getPath()).'" type="image/png" />',PHP_EOL;
}
}
echo '<pubDate>'.date(DATE_RFC2822,$notizia->about->data->sec).'</pubDate>',PHP_EOL;
echo '<guid>'.GUIHandler::getBaseUrl().'/articolo_'.$notizia->id.'</guid>',PHP_EOL;
echo '</item>',PHP_EOL;
}
}
?>