505 lines
18 KiB
PHP
505 lines
18 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 13/gen/2016
|
|
*/
|
|
|
|
class GUIHandlerMobile {
|
|
const STYLESHEET_GENERAL = 0;
|
|
const STYLESHEET_USER = 1;
|
|
const STYLESHEET_ADMIN = 2;
|
|
|
|
const JAVASCRIPT_GENERAL = 0;
|
|
const JAVASCRIPT_USER = 1;
|
|
const JAVASCRIPT_ADMIN = 2;
|
|
|
|
private static $STYLESHEETS = array(self::STYLESHEET_GENERAL=>array(),self::STYLESHEET_USER=>array(),self::STYLESHEET_ADMIN=>array());
|
|
private static $JAVASCRIPTS = array(self::JAVASCRIPT_GENERAL=>array(),self::JAVASCRIPT_USER=>array(),self::JAVASCRIPT_ADMIN=>array());
|
|
|
|
private static $onLoadEvents = array();
|
|
|
|
public static function generateHtmlHeaders(array $data = array(), $admin = false){
|
|
$conf = GlobalVariables::get("config");
|
|
|
|
$title = $conf->info->projectName;
|
|
if (array_key_exists("title", $data)){
|
|
$title = $data["title"];
|
|
}
|
|
|
|
$description = $conf->info->projectDescription;
|
|
if (array_key_exists("description", $data)){
|
|
$description = $data["description"];
|
|
}
|
|
|
|
$useAuthor = true;
|
|
$author = $conf->info->author;
|
|
if (array_key_exists("author", $data)){
|
|
if ($data["author"] === false){
|
|
$useAuthor = false;
|
|
$author = "";
|
|
}
|
|
else {
|
|
$author = $data["author"];
|
|
}
|
|
}
|
|
|
|
header("Content-type: text/html; charset=utf-8");
|
|
|
|
echo "<!DOCTYPE html>\n";
|
|
echo "<html class=\"sidebar_default no-js\" lang=\"en\">\n<head>\n";
|
|
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
|
|
echo "<title>$title - versione mobile</title>\n";
|
|
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
|
|
echo "<meta name=\"description\" content=\"$description\">\n";
|
|
if ($useAuthor){
|
|
echo "<meta name=\"author\" content=\"$author\">\n";
|
|
}
|
|
echo "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge,chrome=1\">\n";
|
|
echo '<link rel="shortcut icon" href="images/favicon.ico">'."\n";
|
|
echo '<link href="http://fonts.googleapis.com/css?family=Lato&subset=latin,latin-ext" rel="stylesheet" type="text/css">'."\n";
|
|
echo '<META http-equiv="Cache-Control" content="no-cache,no-store" />'."\n";
|
|
echo '<META http-equiv="Pragma" content="no-cache" />'."\n";
|
|
if (array_key_exists("additionalMetadata", $data) && is_array($data["additionalMetadata"]) && sizeof($data["additionalMetadata"])>0){
|
|
echo implode("\n", $data["additionalMetadata"]);
|
|
}
|
|
|
|
if ($admin){
|
|
|
|
}
|
|
|
|
foreach (self::$STYLESHEETS[self::STYLESHEET_GENERAL] as $file){
|
|
echo '<link type="text/css" rel="stylesheet" href="'.self::getStylesheetsUrl().$file.'"';
|
|
}
|
|
|
|
$othStyle = $admin?self::STYLESHEET_ADMIN:self::STYLESHEET_USER;
|
|
foreach (self::$STYLESHEETS[$othStyle] as $file){
|
|
echo '<link type="text/css" rel="stylesheet" href="'.self::getStylesheetsUrl().$file.'">'."\n";
|
|
}
|
|
|
|
foreach (self::$JAVASCRIPTS[self::JAVASCRIPT_GENERAL] as $file){
|
|
echo '<script type="text/javascript" src="'.self::getJavascriptsUrl().$file.'"></script>'."\n";
|
|
}
|
|
|
|
$othJs = $admin?self::JAVASCRIPT_ADMIN:self::JAVASCRIPT_USER;
|
|
foreach (self::$JAVASCRIPTS[$othJs] as $file){
|
|
echo '<script type="text/javascript" src="'.self::getJavascriptsUrl().$file.'"></script>'."\n";
|
|
}
|
|
|
|
if (sizeof(self::$onLoadEvents)>0){
|
|
echo '<script type="text/javascript">'."\n";
|
|
echo '$(document).ready(function(){'."\n";
|
|
foreach (self::$onLoadEvents as $evt){
|
|
echo $evt;
|
|
}
|
|
echo '});'."\n";
|
|
echo '</script>'."\n";
|
|
}
|
|
|
|
if (array_key_exists("additionalHeaders", $data) && is_array($data["additionalHeaders"]) && sizeof($data["additionalHeaders"])>0){
|
|
echo implode("\n", $data["additionalHeaders"]);
|
|
}
|
|
echo '</head>';
|
|
}
|
|
|
|
public static function redirect($url){
|
|
// $tmp = new JavaScriptElement("var index = window.location.href.indexOf('#');window.location.href='".$url."'+(index == -1 ? '' : window.location.href.substr(index));");
|
|
// $tmp->render();
|
|
echo '<script type="text/javascript">window.location.href="'.self::getBaseUrl().$url.'";</script>';
|
|
die();
|
|
}
|
|
|
|
public static function pageReload(){
|
|
// $tmp = new JavaScriptElement("var index = window.location.href.indexOf('#');window.location.href='".$url."'+(index == -1 ? '' : window.location.href.substr(index));");
|
|
// $tmp->render();
|
|
echo '<script type="text/javascript">location.reload();</script>';
|
|
die();
|
|
}
|
|
|
|
public static function redirectPost($url,array $vals = array()){
|
|
// $tmp = new JavaScriptElement("var index = window.location.href.indexOf('#');window.location.href='".$url."'+(index == -1 ? '' : window.location.href.substr(index));");
|
|
// $tmp->render();
|
|
$valArr = array();
|
|
|
|
if (sizeof($vals)>0){
|
|
foreach ($vals as $key=>$val){
|
|
$valArr[] = '{"name":"'.$key.'","value":"'.$val.'"}';
|
|
}
|
|
}
|
|
$valString = '['.implode(",", $valArr).']';
|
|
echo '<script type="text/javascript">$(document).ready(function(){openPagePost("'.self::getBaseUrl().$url.'",'.$valString.');});</script>';
|
|
die();
|
|
}
|
|
|
|
public static function addStylesheet($group, $file){
|
|
if (array_key_exists($group, self::$STYLESHEETS)){
|
|
self::$STYLESHEETS[$group][] = $file;
|
|
}
|
|
else {
|
|
throw new CoreException("Invalid stylesheet group ($group) passed to GUIHandlerMobile::addStylesheet() for file '$file'");
|
|
}
|
|
}
|
|
|
|
public static function addJavascriptLib($group, $file){
|
|
if (array_key_exists($group, self::$JAVASCRIPTS)){
|
|
self::$JAVASCRIPTS[$group][] = $file;
|
|
}
|
|
else {
|
|
throw new CoreException("Invalid stylesheet group ($group) passed to GUIHandlerMobile::addJavascriptLib() for file '$file'");
|
|
}
|
|
}
|
|
// public static function generateLoadingOverlay(){
|
|
// echo '<div id="loading" class="no-print"><div>Caricamento....<br/>Attendere prego<br/><br/><img src="'.self::getImagesUrl().'/ajax-loader.gif"></div></div>';
|
|
// }
|
|
|
|
public static function getBaseUrl(){
|
|
$conf = GlobalVariables::get("config");
|
|
return $conf->pages->remoteLocationPath."mobile/";
|
|
}
|
|
|
|
public static function getImagesUrl(){
|
|
return self::getBaseUrl()."images/";
|
|
}
|
|
|
|
public static function getStylesheetsUrl(){
|
|
return self::getBaseUrl()."style/";
|
|
}
|
|
|
|
public static function getJavascriptsUrl(){
|
|
return self::getBaseUrl()."js/";
|
|
}
|
|
|
|
public static function addOnLoadJsEvent($script){
|
|
self::$onLoadEvents[] = $script;
|
|
}
|
|
|
|
public static function generateHeadPublic($bannerCategory = BannerModel::GENERAL_CATEGORY){
|
|
$mesi = array(1=>'Gennaio', 'Febbraio', 'Marzo', 'Aprile',
|
|
'Maggio', 'Giugno', 'Luglio', 'Agosto',
|
|
'Settembre', 'Ottobre', 'Novembre','Dicembre');
|
|
$day = date("d");
|
|
|
|
ASDSessionHandler::setSessionValue("bannerActive",array());
|
|
?>
|
|
<script>
|
|
window.fbAsyncInit = function() {
|
|
FB.init({
|
|
appId : '1707001356211512',
|
|
xfbml : true,
|
|
version : 'v2.6'
|
|
});
|
|
};
|
|
|
|
(function(d, s, id){
|
|
var js, fjs = d.getElementsByTagName(s)[0];
|
|
if (d.getElementById(id)) {return;}
|
|
js = d.createElement(s); js.id = id;
|
|
js.src = "//connect.facebook.net/en_US/sdk.js";
|
|
fjs.parentNode.insertBefore(js, fjs);
|
|
}(document, 'script', 'facebook-jssdk'));
|
|
</script>
|
|
<div class="headContainer">
|
|
<div class="upperBar">
|
|
<div class="dateBar"><?php echo $day." ".$mesi[date("n")]." ".date("Y"); ?> - Aggiornato alle <span style="color:#f68235;"><?php echo date("H:i");?></span></div>
|
|
</div>
|
|
<div class="logo"><a href="http://ifattidinapoli.com/mobile/index.php"><img src="images/logo_uff.png" /></a></div>
|
|
<div class="bottomBar">
|
|
<img id="menuMobile" alt="" src="images/menuIcon.png">
|
|
<?php
|
|
if(!UserLoginManager::isLogged()){
|
|
?>
|
|
<img id="loginMobile" alt="" src="images/loginIcon.png">
|
|
<?php
|
|
}
|
|
else{
|
|
echo "<span style=\"display:inline-block;vertical-align:top;padding:5px 10px;\">".UserLoginManager::getLogged()->nome." ".UserLoginManager::getLogged()->cognome." (<a href=\"javascript:logout();\">logout</a>)</span>";
|
|
}
|
|
?>
|
|
</div>
|
|
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
public static function generateMenu(){
|
|
?><div class="menuContainer">
|
|
<div class="menuHead">
|
|
<img id="closeMenu" alt="" src="images/closeMenuIcon.png"/>
|
|
<div class="searchBar">
|
|
<div>
|
|
<form id="searchForm" method="POST" action="searchResults.php">
|
|
<input class="inputBar" name="search" placeholder="cerca nel sito" />
|
|
</form>
|
|
<img id="sendFormGlass" alt="" src="images/magnifyingGlass.png"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="menuBar">
|
|
<div class="menuTab">
|
|
<a href="index.php">HOME</a>
|
|
</div>
|
|
<?php
|
|
foreach (NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
|
if(($data["mainMenu"]) && !$data["hidden"]){
|
|
?>
|
|
<div class="menuTab"><a href="categorySummary.php?category=<?php echo $category;?>"><?php echo strtoupper($data["label"]);?></a></div>
|
|
<?php
|
|
}
|
|
}
|
|
foreach(NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
|
if(!$data["mainMenu"] && !$data["hidden"] && is_null($data["isSubmenu"])){
|
|
if(strcasecmp($data["label"],NotiziaModel::$NOTIZIE_CATEGORY[NotiziaModel::CATEGORY_ANIMALI]["label"])==0){?>
|
|
<div class="menuTab"><a href="categorySummary.php?category=<?php echo $category;?>"><?php echo strtoupper($data["label"]);?></a></div>
|
|
<div class="menuTab subVoice"><a href="categorySummary.php?category=<?php echo NotiziaModel::CATEGORY_SMARRITI;?>"><span>></span><?php echo strtoupper(NotiziaModel::$NOTIZIE_CATEGORY[NotiziaModel::CATEGORY_SMARRITI]["label"]);?></a></div>
|
|
<div class="menuTab subVoice"><a href="categorySummary.php?category=<?php echo NotiziaModel::CATEGORY_RITROVATI;?>"><span>></span><?php echo strtoupper(NotiziaModel::$NOTIZIE_CATEGORY[NotiziaModel::CATEGORY_RITROVATI]["label"]);?></a></div>
|
|
<?php }else {?>
|
|
<div class="menuTab"><a href="categorySummary.php?category=<?php echo $category;?>"><?php echo strtoupper($data["label"]);?></a></div>
|
|
<?php }
|
|
}
|
|
}
|
|
?>
|
|
<!-- </ul> -->
|
|
</div>
|
|
</div>
|
|
<div class="loginContainer">
|
|
<div class="menuHead">
|
|
<img id="closeLogin" alt="" src="images/closeMenuIcon.png"/>
|
|
</div>
|
|
<div class="loginReg">
|
|
<div class="loginData">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
$(document).ready(function(event){
|
|
$("#sendFormGlass").click(function (){
|
|
$("#searchForm").submit();
|
|
});
|
|
|
|
$(".inputBar").keypress(function(e){
|
|
if(e.which == 13){
|
|
$("#sendFormGlass").click();
|
|
}
|
|
});
|
|
|
|
$(".menuContainer").bind("open",function(){
|
|
if(!$(this).hasClass("open")){
|
|
|
|
$(this).animate({
|
|
"margin-left":"0vw"
|
|
},700).addClass("open");
|
|
$("body").css({"position":"fixed"});
|
|
}
|
|
}).bind("close",function (){
|
|
if($(this).hasClass("open")){
|
|
$(this).animate({
|
|
"margin-left":"-100vw"
|
|
},700).removeClass("open");
|
|
$("body").css({"position":"static"})
|
|
}
|
|
});
|
|
|
|
$("#menuMobile").click(function (){
|
|
$(".menuContainer").trigger("open");
|
|
});
|
|
|
|
$("#closeMenu").click(function (){
|
|
$(".menuContainer").trigger("close");
|
|
});
|
|
|
|
|
|
/*LOGIN MENU*/
|
|
$(".loginContainer").bind("open",function(){
|
|
if(!$(this).hasClass("open")){
|
|
|
|
$(this).animate({
|
|
"margin-left":"0vw"
|
|
},700).addClass("open");
|
|
$("body").css({"position":"fixed"});
|
|
}
|
|
}).bind("close",function (){
|
|
if($(this).hasClass("open")){
|
|
$(this).animate({
|
|
"margin-left":"100vw"
|
|
},700).removeClass("open");
|
|
$("body").css({"position":"static"})
|
|
}
|
|
});
|
|
|
|
$("#loginMobile").click(function (){
|
|
openLogin();
|
|
$(".loginContainer").trigger("open");
|
|
});
|
|
|
|
$("#closeLogin").click(function (){
|
|
$(".loginContainer").trigger("close");
|
|
});
|
|
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
|
|
public static function generateFooter(){
|
|
if (!self::hasSeenCookieMessage()){
|
|
?>
|
|
<!-- <div class="cookieAdvice"> -->
|
|
<!-- <div>Questo sito utilizza cookie tecnici per offrirti una migliore esperienza di navigazione sul sito.</div> -->
|
|
<!-- <div>Navigando su questo sito accetti l'utilizzo dei cookie.</div><br/> -->
|
|
<!-- <a class="closeAdvice">Chiudi</a> -->
|
|
<!-- <br/><br/> -->
|
|
<!-- </div> -->
|
|
<script type="text/javascript">
|
|
$(document).ready(function(){
|
|
$('.closeAdvice').click(function(){
|
|
$('.cookieAdvice').hide();
|
|
});
|
|
$('.cookieAdvice').click(function(){
|
|
$('.cookieAdvice').hide();
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
self::setCookieSeen();
|
|
}
|
|
?>
|
|
<div class="footer">
|
|
<div class="footerButton" style="text-align:center;">
|
|
<a href="#">
|
|
<img alt="" src="images/goTopButton.png">
|
|
<div>TORNA SU</div>
|
|
</a>
|
|
</div>
|
|
|
|
<p>TESTATA REGISTRATA PRESSO IL TRIBUNALE DI NAPOLI AUT. NR. 8 DEL 27 GENNAIO 2006</p>
|
|
<p>COPYRIGHT © 2016 <a href="http://www.ifattidinapoli.it" style="color:white;">www.ifattidinapoli.it</a> - Giornale della Terza Metropoli Italiana</p>
|
|
<p><a href="redazione.php" style="color:white;">REDAZIONE</a> | <a href="archivio.php" style="color:white;">ARCHIVIO STORICO</a></p>
|
|
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
public static function getFacebookShareFunction(NotiziaModel $notizia){
|
|
$url = self::getBaseUrl()."fbMetadata.php?id=".$notizia->id;
|
|
return 'window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent("'.$url.'"))';
|
|
}
|
|
|
|
public static function getTwitterShareFunction(NotiziaModel $notizia){
|
|
$url = self::getBaseUrl()."articolo.php?id=".$notizia->id;
|
|
return 'window.open("http://twitter.com/home?source=ifdn&status="+encodeURIComponent("'.$url.'"))';
|
|
}
|
|
|
|
public static function getGooglePlusShareFunction(NotiziaModel $notizia){
|
|
$url = self::getBaseUrl()."fbMetadata.php?id=".$notizia->id;
|
|
return 'window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent("'.$url.'"))';
|
|
}
|
|
|
|
public static function getLinkedinShareFunction(NotiziaModel $notizia){
|
|
$url = self::getBaseUrl()."fbMetadata.php?id=".$notizia->id;
|
|
return 'window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent("'.$url.'"))';
|
|
}
|
|
|
|
|
|
public static function generateRightBannerBlock($category = BannerModel::GENERAL_CATEGORY){
|
|
$stats = GlobalVariables::get("dao")->aggregate("StatisticModel",PipelineHelper::getMostViewedOfLastDays(strtotime("-7 days"),5));
|
|
$idArray = array_map(function ($ele){ return new MongoId($ele["_id"]["notizia"]);}, $stats);
|
|
|
|
$lastsNews = GlobalVariables::get("dao")->query("NotiziaModel",
|
|
array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$in'=>$idArray)),
|
|
array("sort"=>array("about.data"=>-1))
|
|
);
|
|
|
|
if (sizeof($lastsNews)<5){
|
|
$missing = 5-sizeof($lastsNews);
|
|
$add = GlobalVariables::get("dao")->query("NotiziaModel",
|
|
array("status"=>NotiziaModel::STATUS_ACCEPTED,"_id"=>array('$nin'=>$idArray)),
|
|
array("sort"=>array("about.data"=>-1),"limit"=>$missing)
|
|
);
|
|
$lastsNews = array_merge($lastsNews,$add);
|
|
}
|
|
|
|
// $lastsNews = GlobalVariables::get("dao")->query("NotiziaModel",
|
|
// array("status"=>NotiziaModel::STATUS_ACCEPTED),
|
|
// array("sort"=>array("about.data"=>-1),"limit"=>5)
|
|
// );
|
|
if (sizeof($lastsNews)>0){
|
|
$lastsNews = array_map(function($ele){$ele->testo = strip_tags($ele->testo);$ele->sottotitolo = strip_tags($ele->sottotitolo); return $ele; }, $lastsNews);
|
|
}
|
|
|
|
$mesi = array(1=>'Gennaio', 'Febbraio', 'Marzo', 'Aprile',
|
|
'Maggio', 'Giugno', 'Luglio', 'Agosto',
|
|
'Settembre', 'Ottobre', 'Novembre','Dicembre');
|
|
|
|
?>
|
|
<div id="rightBarContainer" class="">
|
|
<div class="rotoBanner">
|
|
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY,$category);?></div>
|
|
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY,$category);?></div>
|
|
</div>
|
|
<div class="reader">
|
|
<div class="lastNews">
|
|
<div class="categoryBar" style="text-align:left;">
|
|
<div class="categoryTag"><span>Più Letti</span></div>
|
|
<div class="categoryLine"></div>
|
|
</div>
|
|
<?php if(sizeof($lastsNews)>0){
|
|
$i=0;
|
|
foreach($lastsNews as $last){
|
|
$i++;
|
|
$data = $mesi[date("n",$last->about->data->sec)]." ".date("Y",$last->about->data->sec);
|
|
$string = (strlen($last->titolo) > 103) ? substr($last->titolo,0,100).'...' : $last->titolo;?>
|
|
<a href="articolo.php?id=<?php echo $last->id;?>" id="last_<?php echo $i;?>" class="lastContainer">
|
|
<div class="lastData"><?php echo $data;?></div>
|
|
<div class="lastTitle"><?php echo $string;?></div>
|
|
</a>
|
|
<?php }
|
|
}?>
|
|
</div>
|
|
</div>
|
|
<div class="rotoBanner not">
|
|
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY,$category);?></div>
|
|
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY,$category);?></div>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
public static function generateGoogleAnalyticsScripts(){
|
|
?>
|
|
<script>
|
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
|
|
ga('create', 'UA-75287906-1', 'auto');
|
|
ga('send', 'pageview');
|
|
|
|
ga('create', 'UA-6137905-1', 'auto');
|
|
ga('send', 'pageview');
|
|
|
|
</script>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* ritorna true se bisogna mostrare il messaggio dei cookie
|
|
* Il messaggio è basato su SESSIONE
|
|
* @return bool
|
|
*/
|
|
public static function hasSeenCookieMessage(){
|
|
return ASDSessionHandler::sessionValueExists("cookieShown") && ASDSessionHandler::getSessionValue("cookieShown")===true;
|
|
}
|
|
|
|
/**
|
|
* Chiamare quando viene mostrato il messaggio dei cookies
|
|
*/
|
|
public static function setCookieSeen(){
|
|
ASDSessionHandler::setSessionValue("cookieShown",true);
|
|
}
|
|
|
|
}
|
|
?>
|