diff --git a/oth/docs/install.memo b/oth/docs/install.memo index 2f0ba01..e0adca4 100644 --- a/oth/docs/install.memo +++ b/oth/docs/install.memo @@ -8,3 +8,11 @@ db.runCommand({ textSearchEnabled: 1 }); + +INDEX DA CREARE +db.notizia.ensureIndex({"about.author":"text",titolo:"text",sottotitolo:"text",testo:"text"},{default_language: "italian"}) +db.administrators.ensureIndex({nome:"text",cognome:"text",email:"text"},{default_language: "italian"}) +db.mail.ensureIndex({recipient:"text",subject:"text",body:"text"},{default_language: "italian"}) +db.users.ensureIndex({nome:"text",cognome:"text",email:"text"},{default_language: "italian"}) +db.banner.ensureIndex({customer:"text",link:"text"},{default_language: "italian"}) +db.commenti.ensureIndex({titolo:"text",testo:"text"},{default_language: "italian"}) diff --git a/private/lib/AnalyticsHelper.php b/private/lib/AnalyticsHelper.php index 4728eae..09e8ba9 100644 --- a/private/lib/AnalyticsHelper.php +++ b/private/lib/AnalyticsHelper.php @@ -190,9 +190,13 @@ class AnalyticsHelper { if (array_key_exists("HTTP_REFERER",$_SERVER)){ $source = $_SERVER['HTTP_REFERER']; } - + $function = '$.ajax({url: "stats/bannerImpression.php", method: "POST", data: { "ip": "'.$ip.'", "banner": "'.$id.'", "source": "'.$source.'" }, dataType: "html" });'; - GUIHandler::addOnLoadJsEvent($function); + echo ''; + + // OLD VERSION +// $function = '$.ajax({url: "stats/bannerImpression.php", method: "POST", data: { "ip": "'.$ip.'", "banner": "'.$id.'", "source": "'.$source.'" }, dataType: "html" });'; +// GUIHandler::addOnLoadJsEvent($function); } /** @@ -285,17 +289,18 @@ class AnalyticsHelper { $rval = null; if (ASDSessionHandler::sessionValueExists("bannerActive")){ $shown = ASDSessionHandler::getSessionValue("bannerActive"); - + if (!is_null($replaced) && in_array($replaced, $shown)){ - $key = array_search($needle, $shown); + $key = array_search($replaced, $shown); unset($shown[$key]); + ASDSessionHandler::setSessionValue("bannerActive",$shown); } } // idlist contiene gli id dei banner in ordine di visualizzazione crescente (esclusi quelli non visualizzati) $pipeline = PipelineHelper::getTodaysBannerVisualizationPipeline($position); $stats = GlobalVariables::get("dao")->aggregate("StatisticModel",$pipeline); - var_dump($stats); +// var_dump($stats); $idList = array(); if (sizeof($stats)>0){ foreach ($stats as $stat){ @@ -316,7 +321,7 @@ class AnalyticsHelper { } if (is_null($rval)){ - $todayLessShown = array_diff($idList, $shown); + $todayLessShown = array_values(array_diff($idList, $shown)); if (sizeof($todayLessShown)>0){ $i = 0; while (is_null($rval) && $i +
+ \ No newline at end of file diff --git a/private/lib/PipelineHelper.php b/private/lib/PipelineHelper.php index c3436b9..29e4172 100644 --- a/private/lib/PipelineHelper.php +++ b/private/lib/PipelineHelper.php @@ -161,6 +161,7 @@ class PipelineHelper { return $rval; } + } ?> \ No newline at end of file diff --git a/private/lib/dao/GenericDao.php b/private/lib/dao/GenericDao.php index 3578357..fe31bef 100644 --- a/private/lib/dao/GenericDao.php +++ b/private/lib/dao/GenericDao.php @@ -246,6 +246,69 @@ class GenericDao{ // var_dump($resultArray); return $rval; } + + + /** + * Ritorna la lista dei notizia model ordinati per pertinenza + * @param string $modelClass + * @param string $searchWord + * @param array $filter + * @param array $options + * @throws CoreException + * @return DaoSaveable[] + */ + public function search($modelClass, $searchWord, array $filter = array(), array $options = array()){ + if (!is_null($modelClass)){ + if (!is_subclass_of($modelClass, "DaoSaveable", true)){ + throw new CoreException("Invalid return class passed to GenericDao::query ($modelClass)"); + } + } + + $collectionName = $modelClass::getCollectionName(); + $collection = $this->database->$collectionName; + + $useFilter = $filter; + $useFilter['$text'] = array('$search'=>$searchWord); + + if (!array_key_exists("deleted",$useFilter)){ + $useFilter["deleted"] = false; + } + + if (array_key_exists("id",$useFilter)){ + $useFilter["_id"] = $useFilter["id"]; + unset($useFilter["id"]); + } + + if (array_key_exists("_id",$useFilter) && is_string($useFilter["_id"])){ + $useFilter["_id"] = new MongoId($useFilter["_id"]); + } + + $cursor = $collection->find($useFilter,array('score' => array('$meta' => 'textScore'))); + + $sortArray = array(); + if (array_key_exists("sort",$options)){ + $sortArray = $options["sort"]; + } + $sortArray = array_merge($sortArray,array('score' => array('$meta' => 'textScore')) ); + + $cursor->sort($sortArray); + if (array_key_exists("skip",$options)){ + $cursor->skip($options["skip"]); + } + if (array_key_exists("limit",$options)){ + $cursor->limit($options["limit"]); + } + + $rval = array(); + foreach ($cursor as $element){ + unset($element->score); + $rval[] = $modelClass::buildFromSaveableObj($element); + } + + return $rval; + + + } } ?> \ No newline at end of file diff --git a/private/lib/dao/models/UserModel.php b/private/lib/dao/models/UserModel.php index d6747cc..3af6f95 100644 --- a/private/lib/dao/models/UserModel.php +++ b/private/lib/dao/models/UserModel.php @@ -24,6 +24,14 @@ class UserModel extends Model{ if(!$this->hasProperty("password")){ new CoreException("Impossible to create a user without a password"); } + + if(!$this->hasProperty("active")){ + $this->active = false; + } + + if(!$this->hasProperty("activationSent")){ + $this->activationSent = false; + } } public static function getCollectionName(){ diff --git a/private/lib/gui/DatatablesHelper.php b/private/lib/gui/DatatablesHelper.php index 545b026..7802ba1 100644 --- a/private/lib/gui/DatatablesHelper.php +++ b/private/lib/gui/DatatablesHelper.php @@ -27,8 +27,16 @@ class DatatablesHelper { $options["sort"][$key] = strcasecmp($details["dir"], "asc")==0?1:-1; } } + + $models = array(); + if (array_key_exists("search", $_POST) && array_key_exists("value", $_POST["search"]) && strcmp(trim($_POST["search"]["value"]),"")!=0 ){ + $models = $dao->search($useModel, trim($_POST["search"]["value"]), $filter, $options); + } + else { + $models = $dao->query($useModel, $filter, $options); + } - $models = $dao->query($useModel, $filter, $options); + if (sizeof($models)>0){ foreach ($models as $model){ @@ -138,7 +146,8 @@ class DatatablesHelper { "columnDefs": [ {"className":"lastVisible","targets":[]}, {"className":"hidden","targets":[]} - ] + ], + "searchDelay":600, }); $('# tbody').on( 'click', 'tr', function () { if ( $(this).hasClass('selected') ) { diff --git a/private/lib/gui/GUIHandler.php b/private/lib/gui/GUIHandler.php index e414b87..d9afe98 100644 --- a/private/lib/gui/GUIHandler.php +++ b/private/lib/gui/GUIHandler.php @@ -153,12 +153,13 @@ class GUIHandler { 'Settembre', 'Ottobre', 'Novembre','Dicembre'); $day = date("d"); + ASDSessionHandler::setSessionValue("bannerActive",array()); ?>
- Aggiornato alle
- +
nome." ".UserLoginManager::getLogged()->cognome:'LOGIN';?> | REGISTRATI
@@ -168,9 +169,14 @@ class GUIHandler {
-
BANNER
+
+ + +
-
BANNER
+
+ +
@@ -314,8 +320,8 @@ class GUIHandler {
Guarda anche
-
BANNER
-
BANNER
+
+
@@ -338,8 +344,8 @@ class GUIHandler {
Guarda anche
-
BANNER
-
BANNER
+
+
\ No newline at end of file diff --git a/private/lib/media/mediaRenderers/MediaHtml5.php b/private/lib/media/mediaRenderers/MediaHtml5.php index c0f324d..d449158 100644 --- a/private/lib/media/mediaRenderers/MediaHtml5.php +++ b/private/lib/media/mediaRenderers/MediaHtml5.php @@ -17,7 +17,8 @@ class MediaHtml5 extends MediaRenderer{ $height = 'width:'.self::$SIZES[$size]["height"].'px;'; } - return '
'.$this->code.'
'; + return $this->code; +// return '
'.$this->code.'
'; } public function render(array $opt = array()){ diff --git a/private/lib/media/mediaRenderers/MediaYoutube.php b/private/lib/media/mediaRenderers/MediaYoutube.php index c6159c9..af851c5 100644 --- a/private/lib/media/mediaRenderers/MediaYoutube.php +++ b/private/lib/media/mediaRenderers/MediaYoutube.php @@ -9,8 +9,7 @@ class MediaYoutube extends MediaRenderer{ public function asText(array $opt = array()){ // return $this->link; - return ''; + return ''; // return ''; } diff --git a/public/archivio.php b/public/archivio.php index c644065..1fed61c 100644 --- a/public/archivio.php +++ b/public/archivio.php @@ -4,7 +4,6 @@ require_once(dirname(__FILE__)."/load.php"); try { - AnalyticsHelper::logNotiziaImpression($articolo->id); AnalyticsHelper::logPageImpression(); GUIHandler::generateHtmlHeaders(); diff --git a/public/getBanner.php b/public/getBanner.php index ccfb8cc..6884df2 100644 --- a/public/getBanner.php +++ b/public/getBanner.php @@ -5,21 +5,43 @@ Creation Date: 02/mar/2016 */ -require_once(dirname(__FILE__)."/load.php"); + require_once(dirname(__FILE__)."/load.php"); -// if (array_key_exists("id",$_GET)) { + $replaced = null; + if (array_key_exists("replaced",$_GET)) { + $replaced = $_GET["replaced"]; + } + + $position = BannerModel::POSITION_HEAD; + if (array_key_exists("pos",$_GET)) { + $intPost = intval($_GET["pos"]); + if (array_key_exists($intPost,BannerModel::$BANNER_POSITIONS)){ + $position = $intPost; + } + } + // $banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$_GET['id'])); - ASDSessionHandler::setSessionValue("bannerActive",array()); - $banner = AnalyticsHelper::getBannerToShow(BannerModel::POSITION_HEAD); + +// ASDSessionHandler::setSessionValue("bannerActive",array()); + $banner = AnalyticsHelper::getBannerToShow($position,$replaced); +// var_dump($replaced); if (!is_null($banner)){ $media = DaoMediaHandler::getMainMediaFromModel($banner); - echo ''; + echo ''; $media->renderMedia(); echo ''; AnalyticsHelper::logBannerImpression($banner->id); + + ?> + + \ No newline at end of file +// GUIHandler::generateHtmlHeaders(array(),true); +?> diff --git a/public/index.php b/public/index.php index f1fbd96..4127050 100644 --- a/public/index.php +++ b/public/index.php @@ -242,7 +242,7 @@ catch (Exception $ex){ -
+
RISTORANTI
@@ -267,7 +267,7 @@ catch (Exception $ex){
-
+
Più Letti
@@ -285,7 +285,7 @@ catch (Exception $ex){
-
+
GOSSIP
diff --git a/public/js/functions.js b/public/js/functions.js index f21e087..8caf811 100644 --- a/public/js/functions.js +++ b/public/js/functions.js @@ -27,18 +27,28 @@ function openRegistrationModal(){ }); } -function sendRegistration(){ +function openLoginModal(){ $.ajax({ - method:'POST', - url:'sendRegistrationBackend.php', + method:"POST", + url:'login.php', dataType:'html', - data:$('#regForm').serialize(), success: function(data){ -// $("#regForm").remove(); - $(".modalResponse").html(data); - /* Verificare se si possa eliminare la form in caso di registrazione avvenuta con successo assegnando un parametro - * allo span di avvenuta registrazione*/ -// $(".modalError").html(""); + $("#floating").html(data); + var off = $("#regButton").offset(); + var right = $(document).width()-off.left - $("#regButton").outerWidth(); + $("#floating").css("position","absolute").css("right",right).css("top",off.top+25); + $("#floating").show(); } }); -} \ No newline at end of file +} + +function bannerRoll(prev,pos){ + $.ajax({ + method:"POST", + url:'getBanner.php?replaced='+prev+'&pos='+pos, + dataType:'html', + success: function(data){ + $('#'+prev).parent().html(data); + } + }); +} \ No newline at end of file diff --git a/public/login.php b/public/login.php new file mode 100644 index 0000000..80e0a70 --- /dev/null +++ b/public/login.php @@ -0,0 +1,67 @@ +getMessage(); + $err = true; +}catch (Exception $exec){ + $msg = LogModel::fromException($exec); + GlobalVariables::get("dao")->save($msg); +} +if ($saved){ + echo "Registrazione avvenuta con successo"; +} +else { + ?> + +
+
+
+ +
Username:
+
Password:
+ +
+
+ + \ No newline at end of file diff --git a/public/redazione.php b/public/redazione.php index 982c128..ceebf67 100644 --- a/public/redazione.php +++ b/public/redazione.php @@ -4,7 +4,6 @@ require_once(dirname(__FILE__)."/load.php"); try { - AnalyticsHelper::logNotiziaImpression($articolo->id); AnalyticsHelper::logPageImpression(); GUIHandler::generateHtmlHeaders(); diff --git a/public/registration.php b/public/registration.php index b0c46c1..83b41e4 100644 --- a/public/registration.php +++ b/public/registration.php @@ -3,24 +3,100 @@ require_once(dirname(__FILE__)."/load.php"); try { - ?> - -
-
-
-
Email:
-
Username:
-
Password:
-
Conferma password:
-
Vuoi iscriverti alla newsletter?
- -
-
+ $msg = ""; + $saved = false; - nome = PostHandler::get("nome"); + $obj->cognome = PostHandler::get("cognome"); + + $email = trim(PostHandler::get("email")); + if (is_null($email) || !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/",$email)){ + throw new GUIException("L'email inserita non è in un formato valido ($email)"); + } + if (GlobalVariables::get("dao")->count("AdminModel",array("email",$email)) > 0 ){ + throw new GUIException("L'email inserita è già in uso ($email)"); + } + $obj->email = $email; + + $username = trim(PostHandler::get("username")); + + // Validate Username + if (is_null($username) || strcmp($username,"")==0){ + throw new GUIException("Inserire un nome utente valido"); + } + if (GlobalVariables::get("dao")->count("UserModel",array("username"=>$username ) ) > 0 ){ + throw new GUIException("Il nome utente '".$username."' è già in uso"); + } + + $obj->username = $username; + + $pass = trim(PostHandler::get("password")); + $passConf = trim(PostHandler::get("password_confirm")); + if (is_null($pass) || strcmp($pass,"")==0){ + throw new GUIException("Inserire una password"); + } + if (strcmp($pass,$passConf)!=0){ + throw new GUIException("Le password inserite non coincidono"); + } + $obj->password = sha1($pass); + + $obj->newsletter = false; + $news = PostHandler::get("newsletter"); + if (!is_null($news) && strcasecmp("true", $news)){ + $obj->newsletter = true; + } + $user = new UserModel($obj); + GlobalVariables::get("dao")->save($user); + $saved = true; + } + +}catch(GUIException $ex){ + $msg = $ex->getMessage(); + $err = true; }catch (Exception $exec){ $msg = LogModel::fromException($exec); GlobalVariables::get("dao")->save($msg); } -// echo "zzzzzzzzzzzzzzzzzzzzzz"; +if ($saved){ + echo "Registrazione avvenuta con successo"; +} +else { +?> + +
+
+
+ +
Nome:
+
Cognome:
+
Email:
+
Username:
+
Password:
+
Conferma password:
+
Vuoi iscriverti alla newsletter?
+ +
+
+ + \ No newline at end of file diff --git a/public/searchResults.php b/public/searchResults.php index 5b59def..ee2610d 100644 --- a/public/searchResults.php +++ b/public/searchResults.php @@ -25,9 +25,8 @@ try { } $skip =($page - 1) * $limit; - $notizieAll = GlobalVariables::get("dao")->query("NotiziaModel", - array("status"=>NotiziaModel::STATUS_ACCEPTED), - array("sort"=>array("about.data"=>-1)) + $notizieAll = GlobalVariables::get("dao")->search("NotiziaModel",$searchParameters, + array("status"=>NotiziaModel::STATUS_ACCEPTED) ); if(sizeof($notizieAll)>0){ @@ -38,9 +37,14 @@ try { $found = false; } - $notizie = GlobalVariables::get("dao")->query("NotiziaModel", +// $notizie = GlobalVariables::get("dao")->query("NotiziaModel", +// array("status"=>NotiziaModel::STATUS_ACCEPTED), +// array("sort"=>array("about.data"=>-1),"skip"=>$skip,"limit"=>$limit) +// ); + + $notizie = GlobalVariables::get("dao")->search("NotiziaModel",$searchParameters, array("status"=>NotiziaModel::STATUS_ACCEPTED), - array("sort"=>array("about.data"=>-1),"skip"=>$skip,"limit"=>$limit) + array("skip"=>$skip,"limit"=>$limit) ); if (sizeof($notizie)>0){ @@ -50,7 +54,8 @@ try { } else{ - GUIHandler::redirect("index.php"); +// GUIHandler::redirect("index.php"); + echo "Errore"; } diff --git a/public/style/admin.css b/public/style/admin.css index 6210b41..48ec083 100644 --- a/public/style/admin.css +++ b/public/style/admin.css @@ -68,7 +68,7 @@ form > div{margin:5px 0;} .notiziaMenu ul {list-style:none; display:inline-block; padding:0 20px;} .notiziaMenu ul li{margin: 10px 0px;display: block; clear:both;} -div.notiziaAcceptance{text-align: center; background-color: #ffd677; padding: 20px; border: 1px solid grey; border-radius: 10px;} +div.notiziaAcceptance{text-align: center; background-color: #ffd677; padding: 20px; border: 1px solid grey; border-radius: 10px;margin-bottom:10px;} div.notiziaAcceptance > .buttons a{text-decoration:none; color:rgb(51, 102, 255); font-weight:bold; margin-right:5px; padding:5px; display:inline-block;} div.notiziaAcceptance > .buttons a.green:hover{background-color:#7EFF83;} div.notiziaAcceptance > .buttons a.red:hover{background-color:#FF8DA6;} diff --git a/public/style/public.css b/public/style/public.css index e4b4a9d..b8a8c27 100644 --- a/public/style/public.css +++ b/public/style/public.css @@ -78,6 +78,7 @@ body{font-family:lato, arial;} -moz-box-shadow: 0px 0px 10px -3px; padding: 10px 5px 5px; margin-left: 1px; + margin-bottom: 25px; } @@ -136,7 +137,9 @@ body{font-family:lato, arial;} .ansa{border:solid #d6d6d6 1px;border-left:0px;border-right:0px;border-top:0px;height:180px;} .ansa> div {display:inline-block;vertical-align:top;} -.mediaContent > *{max-height:100%;max-width:100%;} +.mediaContent{overflow:hidden;} +.mediaContent *{max-height:100%;max-width:100%;} +.mediaContent > a{height:100%; width:100%;display:inline-block;} .ansaImage{display:inline-block;margin:15px 7px;width:150px; height:113px; overflow:hidden;text-align:center;} .ansaNews{margin-top:2px;width:330px;cursor:pointer;} @@ -224,7 +227,7 @@ body{font-family:lato, arial;} .ristorantiTitle, .culturaTitle{font-weight: bold;text-align: left;font-size: 12px;} .ristorantiBlock .ristorantiLink > a, .culturaNews .culturaLink > a{color:#3498d4;font-size:13px;} -.middleBanner{max-height:165px;} +.middleBanner{height:165px;} .middleBanner > img{max-height:100px;max-width:220px;} .ristorantiTitle{margin-top:10px;} @@ -232,7 +235,7 @@ body{font-family:lato, arial;} .rightBarNews{display:inline-block;width:230px;height:1380px;vertical-align:top;margin-top:20px;} .meteo{max-height:165px;max-width:220px;} .meteo > img{max-width:220px;max-height:165px;} -.middleRightBanner{width:220px;overflow:hidden;} +.middleRightBanner{width: 220px;overflow: hidden;height: 165px;margin: 5px 0;} .middleRightBanner > img{max-width:220px; max-heigth:200px;} .reader > .lastContainer, .lastContainer{max-height:120px;margin-top:5px;margin-bottom:5px;border-bottom:dotted #C1B4B4 1px;}