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>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -46,5 +46,7 @@ require_once(dirname(__FILE__)."/PipelineHelper.php");
|
||||
|
||||
require_once(dirname(__FILE__)."/BannerHelper.php");
|
||||
|
||||
require_once(dirname(__FILE__)."/RSSHelper.php");
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/*
|
||||
* index.php
|
||||
* Author: Riccardo Di Dato
|
||||
* Creation Date: 17 lug 2017
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__)."/../load.php");
|
||||
|
||||
try {
|
||||
|
||||
|
||||
$notizie = GlobalVariables::get("dao")->query("NotiziaModel",
|
||||
array("isAnsa"=>true,"status"=>NotiziaModel::STATUS_ACCEPTED,"about.data"=>array('$lte'=>new MongoDate())),
|
||||
array("sort"=>array("about.data"=>-1),"limit"=>5));
|
||||
|
||||
$ansaIds = array();
|
||||
if (sizeof($notizie)>0){
|
||||
$ansaIds = array_map(function($ele){return new MongoId($ele->id);}, $notizie);
|
||||
}
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->query("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_POLITICA,
|
||||
'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1),"limit"=>3)
|
||||
);
|
||||
|
||||
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->query("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_CRONACA,'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1),"limit"=>3)
|
||||
);
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->query("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_SPORT,
|
||||
'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1),"limit"=>2)
|
||||
);
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->query("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_CULTURA,'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1),"limit"=>4)
|
||||
);
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->query("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_RISTORANTI,
|
||||
'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1),"limit"=>3)
|
||||
);
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->query("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_GOSSIP,
|
||||
'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1),"limit"=>2)
|
||||
);
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->getFirst("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_VIAGGI,
|
||||
'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1))
|
||||
);
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->getFirst("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_ANIMALI,
|
||||
'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1))
|
||||
);
|
||||
|
||||
$notizie += GlobalVariables::get("dao")->getFirst("NotiziaModel",
|
||||
array(
|
||||
"status"=>NotiziaModel::STATUS_ACCEPTED,
|
||||
"category"=>NotiziaModel::CATEGORY_SALUTE,
|
||||
'_id'=>array('$nin'=>$ansaIds),
|
||||
"about.data"=>array('$lte'=>new MongoDate())
|
||||
),
|
||||
array("sort"=>array("about.data"=>-1))
|
||||
);
|
||||
|
||||
RSSHelper::generateByNotiziaList($notizie);
|
||||
|
||||
}
|
||||
catch (Exception $ex){
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user