From d663326da958f76de3f5ceedffb965a09abb95b8 Mon Sep 17 00:00:00 2001 From: Riccardo Di Dato Date: Mon, 31 Jul 2017 15:17:09 +0200 Subject: [PATCH] Inserita funzione helper per tagli testi articolo Signed-off-by: Riccardo Di Dato --- private/lib/dao/models/NotiziaModel.php | 12 +++- public/index.php | 96 +++++++++++++++++-------- public/mobile/index.php | 56 +++++++++++++-- 3 files changed, 126 insertions(+), 38 deletions(-) diff --git a/private/lib/dao/models/NotiziaModel.php b/private/lib/dao/models/NotiziaModel.php index a86c3ff..748455b 100644 --- a/private/lib/dao/models/NotiziaModel.php +++ b/private/lib/dao/models/NotiziaModel.php @@ -54,7 +54,7 @@ class NotiziaModel extends HasMediaModel{ self::CATEGORY_GOSSIP=>array("label"=>"Gossip","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"gossip.php"),"color"=>"#3e3e3e","isSubmenu"=>null), self::CATEGORY_ANIMALI=>array("label"=>"Mondo Animale","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"animali.php"),"color"=>"#3e3e3e","isSubmenu"=>null), self::CATEGORY_VIAGGI=>array("label"=>"Viaggi","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"viaggi.php"),"color"=>"#3e3e3e","isSubmenu"=>null), - self::CATEGORY_RISTORANTI=>array("label"=>"Food&Drink","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"ristoranti.php"),"color"=>"#3e3e3e","isSubmenu"=>null), + self::CATEGORY_RISTORANTI=>array("label"=>"Food&Drink","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"ristoranti.php"),"color"=>"#502f8f","isSubmenu"=>null), self::CATEGORY_MESTIERI=>array("label"=>"Professioni e Mestieri","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"mestieri.php"),"color"=>"#3e3e3e","isSubmenu"=>null), self::CATEGORY_CASA=>array("label"=>"Casa","mainMenu"=>false, "hidden"=>true,"pages"=>array("list"=>"casa.php"),"color"=>"#3e3e3e","isSubmenu"=>null), self::CATEGORY_SALUTE=>array("label"=>"Salute","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"salute.php"),"color"=>"#3e3e3e","isSubmenu"=>null), @@ -103,6 +103,16 @@ class NotiziaModel extends HasMediaModel{ return GUIHandlerMobile::getBaseUrl().$link; } + + public function cutTextHtmlSafe($attrName, $size){ + $rval = strval( $this->$attrName ); + if (strlen($rval) > ($size + 3) ){ + $rval = html_entity_decode( $rval ); + $rval = substr($rval, 0, $size); + $rval = htmlentities($rval) . "..."; + } + return $rval; + } } ?> diff --git a/public/index.php b/public/index.php index 666d1b9..e82d185 100644 --- a/public/index.php +++ b/public/index.php @@ -171,24 +171,34 @@ catch (Exception $ex){ GUIHandler::generateMenu();?>
- titolo) > 103) ? htmlentities( substr( html_entity_decode( $ansa->titolo ) ,0,100) ).'...' : $ansa->titolo; - $stringSottotitolo = (strlen($ansa->sottotitolo) > 73) ? htmlentities( substr( html_entity_decode( $ansa->sottotitolo ) ,0,70) ).'...' : $ansa->sottotitolo; - $stringTesto = (strlen($ansa->testo) > 33) ? htmlentities( substr( html_entity_decode( $ansa->testo ),0,30) ).'...' : $ansa->testo;?> -
-
- renderMedia();?> + titolo) > 103) ? htmlentities( substr( html_entity_decode( $ansa->titolo ) ,0,100) ).'...' : $ansa->titolo; +// $stringSottotitolo = (strlen($ansa->sottotitolo) > 73) ? htmlentities( substr( html_entity_decode( $ansa->sottotitolo ) ,0,70) ).'...' : $ansa->sottotitolo; +// $stringTesto = (strlen($ansa->testo) > 33) ? htmlentities( substr( html_entity_decode( $ansa->testo ),0,30) ).'...' : $ansa->testo; + $stringTitolo = $ansa->cutTextHtmlSafe("titolo",100); + $stringSottotitolo = $ansa->cutTextHtmlSafe("sottotitolo",70); + $stringTesto = $ansa->cutTextHtmlSafe("testo",30); + ?> +
+ +
+ renderMedia();?> +
+ + +
+
+
+
- - -
-
-
-
-
@@ -207,8 +217,11 @@ catch (Exception $ex){ $i=0; foreach ($politicaNews as $politica){ $i++; - $stringTitolo = (strlen($politica->titolo) > 53) ? htmlentities( substr( html_entity_decode( $politica->titolo ) ,0,50) ).'...' : $politica->titolo; - $string = (strlen($politica->sottotitolo) > 33) ? htmlentities( substr( html_entity_decode( $politica->sottotitolo ) ,0,30) ).'...' : $politica->sottotitolo;?> +// $stringTitolo = (strlen($politica->titolo) > 53) ? htmlentities( substr( html_entity_decode( $politica->titolo ) ,0,50) ).'...' : $politica->titolo; +// $string = (strlen($politica->sottotitolo) > 33) ? htmlentities( substr( html_entity_decode( $politica->sottotitolo ) ,0,30) ).'...' : $politica->sottotitolo; + $stringTitolo = $politica->cutTextHtmlSafe("titolo",50); + $string = $politica->cutTextHtmlSafe("sottotitolo",30); + ?>
titolo) > 53) ? htmlentities( substr( html_entity_decode( $cronaca->titolo ) ,0, 50) ).'...' : $cronaca->titolo; - $string = (strlen($cronaca->sottotitolo) > 33) ? htmlentities( substr( html_entity_decode($cronaca->sottotitolo ) ,0,30) ).'...' : $cronaca->sottotitolo;?> +// $stringTitolo = (strlen($cronaca->titolo) > 53) ? htmlentities( substr( html_entity_decode( $cronaca->titolo ) ,0, 50) ).'...' : $cronaca->titolo; +// $string = (strlen($cronaca->sottotitolo) > 33) ? htmlentities( substr( html_entity_decode($cronaca->sottotitolo ) ,0,30) ).'...' : $cronaca->sottotitolo; + $stringTitolo = $cronaca->cutTextHtmlSafe("titolo",50); + $string = $cronaca->cutTextHtmlSafe("sottotitolo",30); + ?>
titolo) > 53) ? htmlentities( substr( html_entity_decode( $sport->titolo ) ,0,50) ).'...' : $sport->titolo; - $string = (strlen($sport->sottotitolo) > 33) ? htmlentities( substr( html_entity_decode( $sport->sottotitolo ) ,0,30) ).'...' : $sport->sottotitolo;?> +// $stringTitolo = (strlen($sport->titolo) > 53) ? htmlentities( substr( html_entity_decode( $sport->titolo ) ,0,50) ).'...' : $sport->titolo; +// $string = (strlen($sport->sottotitolo) > 33) ? htmlentities( substr( html_entity_decode( $sport->sottotitolo ) ,0,30) ).'...' : $sport->sottotitolo; + $stringTitolo = $sport->cutTextHtmlSafe("titolo",50); + $string = $sport->cutTextHtmlSafe("sottotitolo",30); + ?> titolo) > 53) ? htmlentities( substr( html_entity_decode( $saluteNews->titolo ) ,0,50) ) .'...' : $saluteNews->titolo;?> +// $stringTitle = (strlen($saluteNews->titolo) > 53) ? htmlentities( substr( html_entity_decode( $saluteNews->titolo ) ,0,50) ) .'...' : $saluteNews->titolo; + $stringTitle = $saluteNews->cutTextHtmlSafe("titolo",50); + ?> @@ -369,8 +394,11 @@ catch (Exception $ex){ $i = 0; foreach($gossipNews as $gossip){ $i++; - $stringTitle = (strlen($gossip->titolo) > 53) ? htmlentities( substr( html_entity_decode( $gossip->titolo ) ,0,50) ) .'...' : $gossip->titolo; - $stringSubTitle = (strlen($last->sottotitolo) > 23) ? htmlentities( substr( html_entity_decode( $last->sottotitolo ) ,0,20) ) .'...' : $last->sottotitolo;?> +// $stringTitle = (strlen($gossip->titolo) > 53) ? htmlentities( substr( html_entity_decode( $gossip->titolo ) ,0,50) ) .'...' : $gossip->titolo; +// $stringSubTitle = (strlen($last->sottotitolo) > 23) ? htmlentities( substr( html_entity_decode( $last->sottotitolo ) ,0,20) ) .'...' : $last->sottotitolo; + $stringTitle = $gossip->cutTextHtmlSafe("titolo",50); + $stringSubTitle = $gossip->cutTextHtmlSafe("sottotitolo",20); + ?> @@ -391,7 +419,9 @@ catch (Exception $ex){
titolo) > 53) ? htmlentities( substr( html_entity_decode( $elezioni->titolo ) ,0,50) ) .'...' : $elezioni->titolo;?> + $stringTitle = (strlen($elezioni->titolo) > 53) ? htmlentities( substr( html_entity_decode( $elezioni->titolo ) ,0,50) ) .'...' : $elezioni->titolo; + $stringTitle = $elezioni->cutTextHtmlSafe("titolo",50); + ?> @@ -411,7 +441,9 @@ catch (Exception $ex){
titolo) > 53) ? htmlentities( substr( html_entity_decode( $lastViaggi->titolo ) ,0,50) ) .'...' : $lastViaggi->titolo;?> +// $stringTitle = (strlen($lastViaggi->titolo) > 53) ? htmlentities( substr( html_entity_decode( $lastViaggi->titolo ) ,0,50) ) .'...' : $lastViaggi->titolo; + $stringTitle = $lastViaggi->cutTextHtmlSafe("titolo",50); + ?> @@ -430,7 +462,9 @@ catch (Exception $ex){
titolo) > 53) ? htmlentities( substr( html_entity_decode( $animalNews->titolo ) ,0,50) ) .'...' : $animalNews->titolo;?> +// $stringTitle = (strlen($animalNews->titolo) > 53) ? htmlentities( substr( html_entity_decode( $animalNews->titolo ) ,0,50) ) .'...' : $animalNews->titolo; + $stringTitle = $animalNews->cutTextHtmlSafe("titolo",50); + ?> diff --git a/public/mobile/index.php b/public/mobile/index.php index 4fe1c62..cb851c1 100644 --- a/public/mobile/index.php +++ b/public/mobile/index.php @@ -28,7 +28,7 @@ try { $ansaNews = 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"=>3)); + array("sort"=>array("about.data"=>-1),"limit"=>4)); $ansaIds = array(); if (sizeof($ansaNews)>0){ @@ -75,6 +75,14 @@ try { $culturaNews = array_map(function($ele){$ele->testo = strip_tags($ele->testo);$ele->sottotitolo = strip_tags($ele->sottotitolo); return $ele; }, $culturaNews); } + $foodNews = 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"=>4) + ); + if (sizeof($foodNews)>0){ + $foodNews = array_map(function($ele){$ele->testo = strip_tags($ele->testo);$ele->sottotitolo = strip_tags($ele->sottotitolo); return $ele; }, $foodNews); + } } catch (Exception $ex){ echo $ex->getMessage(); @@ -92,7 +100,7 @@ catch (Exception $ex){
titolo) > 103) ? substr($ansa->titolo,0,100).'...' : $ansa->titolo; + $stringTitolo = (strlen($ansa->titolo) > 103) ? htmlentities ( substr( html_entity_decode( $ansa->titolo ),0,100) ) .'...' : $ansa->titolo; // $stringSottotitolo = (strlen($ansa->sottotitolo) > 73) ? substr($ansa->sottotitolo,0,70).'...' : $ansa->sottotitolo; // $stringTesto = (strlen($ansa->testo) > 33) ? substr($ansa->testo,0,30).'...' : $ansa->testo;?>
@@ -117,7 +125,7 @@ catch (Exception $ex){ $i=0; foreach ($politicaNews as $articolo){ - $stringTitolo = (strlen($articolo->titolo) > 53) ? substr($articolo->titolo,0,50).'...' : $articolo->titolo; + $stringTitolo = (strlen($articolo->titolo) > 53) ? htmlentities ( substr( html_entity_decode( $articolo->titolo ) ,0,50) ) .'...' : $articolo->titolo; // $string = (strlen($politica->sottotitolo) > 33) ? substr($politica->sottotitolo,0,30).'...' : $politica->sottotitolo;?> @@ -157,7 +165,7 @@ catch (Exception $ex){ $i=0; foreach ($cronacaNews as $articolo){ - $stringTitolo = (strlen($articolo->titolo) > 53) ? substr($articolo->titolo,0,50).'...' : $articolo->titolo; + $stringTitolo = (strlen($articolo->titolo) > 53) ? htmlentities ( substr( html_entity_decode( $articolo->titolo ) ,0,50) ) .'...' : $articolo->titolo; // $string = (strlen($politica->sottotitolo) > 33) ? substr($politica->sottotitolo,0,30).'...' : $politica->sottotitolo;?> @@ -193,7 +201,43 @@ catch (Exception $ex){ $i=0; foreach ($sportNews as $articolo){ - $stringTitolo = (strlen($articolo->titolo) > 53) ? substr($articolo->titolo,0,50).'...' : $articolo->titolo; + $stringTitolo = (strlen($articolo->titolo) > 53) ? htmlentities ( substr( html_entity_decode( $articolo->titolo ) ,0,50) ) .'...' : $articolo->titolo; +// $string = (strlen($politica->sottotitolo) > 33) ? substr($politica->sottotitolo,0,30).'...' : $politica->sottotitolo;?> + + +
+
"> + SPORT +
+ 0){ + $i=0; + foreach ($foodNews as $articolo){ + + $stringTitolo = (strlen($articolo->titolo) > 53) ? htmlentities ( substr( html_entity_decode( $articolo->titolo ) ,0,50) ) .'...' : $articolo->titolo; // $string = (strlen($politica->sottotitolo) > 33) ? substr($politica->sottotitolo,0,30).'...' : $politica->sottotitolo;?> @@ -234,7 +278,7 @@ catch (Exception $ex){ $i=0; foreach ($culturaNews as $articolo){ - $stringTitolo = (strlen($articolo->titolo) > 53) ? substr($articolo->titolo,0,50).'...' : $articolo->titolo; + $stringTitolo = (strlen($articolo->titolo) > 53) ? htmlentities ( substr( html_entity_decode( $articolo->titolo ) ,0,50) ) .'...' : $articolo->titolo; // $string = (strlen($politica->sottotitolo) > 33) ? substr($politica->sottotitolo,0,30).'...' : $politica->sottotitolo;?>