349 lines
14 KiB
PHP
349 lines
14 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 13/gen/2016
|
|
*/
|
|
|
|
class GUIHandler {
|
|
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"];
|
|
}
|
|
|
|
$author = $conf->info->author;
|
|
if (array_key_exists("author", $data)){
|
|
$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</title>\n";
|
|
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
|
|
echo "<meta name=\"description\" content=\"$description\">\n";
|
|
echo "<meta name=\"author\" content=\"$author\">\n";
|
|
echo "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge,chrome=1\">";
|
|
echo '<link rel="shortcut icon" href="'.self::getImagesUrl().'/favicon.png">'."\n";
|
|
echo '<link href="http://fonts.googleapis.com/css?family=Lato&subset=latin,latin-ext" rel="stylesheet" type="text/css">'."\n";
|
|
|
|
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 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 GUIHandler::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 GUIHandler::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;
|
|
}
|
|
|
|
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(){
|
|
$mesi = array(1=>'Gennaio', 'Febbraio', 'Marzo', 'Aprile',
|
|
'Maggio', 'Giugno', 'Luglio', 'Agosto',
|
|
'Settembre', 'Ottobre', 'Novembre','Dicembre');
|
|
$day = date("d");
|
|
|
|
?>
|
|
<div id="floating" style="display:none;"></div>
|
|
<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 class="loginReg"><a href="#">LOGIN</a> | <a id="regButton" href="javascript:openRegistrationModal();">REGISTRATI</a></div>
|
|
<div class="socialBar">
|
|
<a class="socialLink" href="https://www.facebook.com/ifattidinapoli" target="_blank"><div style="background-image:url(images/fb.png);"></div></a>
|
|
<a class="socialLink" href="https://twitter.com/fattidinapoli" target="_blank"><div style="background-image:url(images/twitter.png);"></div></a>
|
|
<a class="socialLink" href="https://plus.google.com/111810489585204500066/posts" target="_blank"><div style="background-image:url(images/google.png);"></div></a>
|
|
<a class="socialLink" href="https://www.linkedin.com/in/antonio-pianelli-5970043b" target="_blank"><div style="background-image:url(images/linkedin.png);"></div></a>
|
|
<a class="socialLink" href="https://www.youtube.com/user/tvnapoli" target="_blank"><div style="background-image:url(images/youtube.png);"></div></a>
|
|
</div>
|
|
</div>
|
|
<div class="middleBar">
|
|
<div class="leftBanner topBanner"><img src="images/ads.png" alt=""><span style="color:red;">BANNER</span></div><?php //TODO: Bannerizzare?>
|
|
<div class="logo"><img src="images/logo_uff.png"></div>
|
|
<div class="rightBanner topBanner"><img src="images/ads.png" alt=""><span style="color:red;">BANNER</span></div><?php //TODO: Bannerizzare?>
|
|
</div>
|
|
<div class="bottomBar" style="height:40px;width:1000px;"></div>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
public static function generateMenu(){
|
|
?><div class="menuContainer">
|
|
<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
|
|
}
|
|
}
|
|
?>
|
|
<div style="display:inline-block;">
|
|
<div class="menuTab" id="menuable" >
|
|
<a href="javascript:void(0);">TUTTE LE SEZIONI <img style="margin-left:5px;vertical-align:middle;"src="images/menuArrow.png" alt""></a>
|
|
</div>
|
|
<div class="hiddenMenu" style="display:none;">
|
|
<ul class="categoryList">
|
|
<?php
|
|
foreach(NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
|
if(!$data["mainMenu"] && !$data["hidden"]){
|
|
?>
|
|
<li class="categoryVoice"><a href="categorySummary.php?category=<?php echo $category;?>"><?php echo strtoupper($data["label"]);?></a></li>
|
|
<?php
|
|
}
|
|
}
|
|
?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="searchBar">
|
|
<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>
|
|
<script type="text/javascript">
|
|
$(document).ready(function(event){
|
|
$("#menuable").click(function(){
|
|
if($(".hiddenMenu").hasClass("open")){
|
|
$(".hiddenMenu").fadeOut().removeClass("open");
|
|
|
|
}
|
|
else{
|
|
$(".hiddenMenu").fadeIn().addClass("open");
|
|
}
|
|
});
|
|
|
|
$(".hiddenMenu").mouseleave(function(){
|
|
if($(".hiddenMenu").hasClass("open")){
|
|
$(".hiddenMenu").fadeOut().removeClass("open");
|
|
|
|
}
|
|
});
|
|
|
|
$("#sendFormGlass").click(function (){
|
|
$("#searchForm").submit();
|
|
});
|
|
|
|
$(".inputBar").keypress(function(e){
|
|
if(e.which == 13){
|
|
$("#sendFormGlass").click();
|
|
}
|
|
});
|
|
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
|
|
public static function generateFooter(){
|
|
?>
|
|
<div class="footer">
|
|
<div class="footerCategory">
|
|
<a href="index.php">Home</a>
|
|
<?php
|
|
foreach(NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
|
if($data["mainMenu"] && !$data["hidden"]){
|
|
?>
|
|
| <a href="categorySummary.php?category=<?php echo $category;?>"><?php echo $data["label"];?></a>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
?>
|
|
</div>
|
|
<div style="text-align:center;color:white;margin-top:25px;">TESTATA REGISTRATA PRESSO IL TRIBUNALE DI NAPOLI AUT. NR. 8 DEL 27 GENNAIO 2006</div>
|
|
<div style="text-align:center;color:white;margin-top:20px;">COPYRIGHT © 2016 <a href="www.ifattidinapoli.it" style="color:white;">www.ifattidinapoli.it</a> - Giornale della Terza Metropoli Italiana</div>
|
|
<div style="text-align:center;color:white;margin-top:20px;"><a href="redazione.php" style="color:white;">REDAZIONE</a> | <a href="archivio.php" style="color:white;">ARCHIVIO STORICO</a></div>
|
|
|
|
</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(){
|
|
$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>Guarda anche</div>
|
|
<div class="bannerContainer mediaContent"><img alt="" src="images/ads_big.png" /><span style="color:red;">BANNER</span></div> <?php //TODO: Bannerizzare?>
|
|
<div class="bannerContainer mediaContent"><img alt="" src="images/ads_big.png" /><span style="color:red;">BANNER</span></div> <?php //TODO: Bannerizzare?>
|
|
</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){
|
|
foreach($lastsNews as $last){
|
|
$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;?>
|
|
<div class="lastContainer">
|
|
<div class="lastData"><?php echo $data;?></div>
|
|
<div class="lastTitle"><?php echo $string;?></div>
|
|
<div class="lastContinua" style="text-align:right;"><a href="articolo.php?id=<?php echo $last->id;?>">Leggi</a></div>
|
|
</div>
|
|
<?php }
|
|
}?>
|
|
</div>
|
|
</div>
|
|
<div class="rotoBanner not">
|
|
<div>Guarda anche</div>
|
|
<div class="bannerContainer mediaContent"><img alt="" src="images/ads_big.png" /><span style="color:red;">BANNER</span></div> <?php //TODO: Bannerizzare?>
|
|
<div class="bannerContainer mediaContent"><img alt="" src="images/ads_big.png" /><span style="color:red;">BANNER</span></div> <?php //TODO: Bannerizzare?>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
?>
|