ok
Direktori : /home/institutonamaste/www/class/ |
Current File : /home/institutonamaste/www/class/class-blog.php |
<?php class Blog{ private $li = 'blog/'; private $licons = 'icons/'; private $tb = "blog"; private $tbi = "blog_idioma"; private $tbc = "categoria"; private $tbbc = "blog_categoria"; private $padrao = "banner-site-irm-blog-dicas.jpg"; public function __construct($page) { if($page == 'home') echo $this->Home(); elseif($page == 'interno') if($_GET['url']) echo $this->Interno(); else echo $this->Blocos(); } public function Home() { $i = 0; $sql = DBRead($this->tb, "WHERE status = '1' AND id_blog_master = '0' ORDER BY data+0 DESC LIMIT 3", "titulo, img, texto, autor, data, video, url"); while($row = mysqli_fetch_object($sql)) { $img = (!empty($row->img)) ? IMG.$this->li.$row->img : ((!empty($row->video)) ? 'https://i1.ytimg.com/vi/'.$row->video.'/mqdefault.jpg' : IMG.$this->li.$this->padrao); $title = Resumo($row->titulo, 120); $link = BLOG.'/'.$row->url; $text = Resumo($row->texto, 180); $box[$i] = $this->HomeBox($img, $title, $text, $link); $i++; } $blog = ' <div class="row"> <div class="col-md-6 col-12"> <div class="box plus"> '.$box[0].' </div><!-- box --> </div><!-- cols --> <div class="col-md-6 col-12"> <div class="box"> '.$box[1].' </div><!-- box --> <div class="box"> '.$box[2].' </div><!-- box --> </div><!-- cols --> </div><!-- row --> <a href="'.URL.'/blog" class="more">VER MAIS CONTEÚDO</a>'; echo $blog; } private function HomeBox($img, $title, $text, $lk) { $box = ' <img src="'.$img.'"/> <div class="text"> <h3>'.$title.'</h3> <p>'.$text.'</p> <a href="'.$lk.'" class="read"><i class="fa fa-plus-square" aria-hidden="true"></i> Ler mais</a> </div><!-- text -->'; return $box; } public function Blocos() { $p = (isset($_GET["p"])) ? $_GET["p"] : 1; $qnt = 5; $ini = ($p*$qnt) - $qnt; $max = NULL; if(!empty($_GET['ano']) && !empty($_GET['mes'])){ $ano = DBEscape($_GET['ano']); $mes = DBEscape($_GET['mes']); $where = " WHERE status = '1' AND YEAR(data) = '".$ano."' AND MONTH(data) = '".$mes."'"; }elseif(!empty($_GET['idioma'])){ $sigla = DBEscape($_GET['idioma']); $sig = $this->ReadIdiomas($sigla); $where = " WHERE status = '1' AND idioma = '".$sig->id."'"; }elseif(!empty($_GET['busca'])){ $where = $this->Search($_GET['busca']); }else{ $where = " WHERE status = '1' AND id_blog_master = '0'"; } if(!empty($_GET['categoria'])) { $cat = DBEscape($_GET['categoria']); $sql = DBExecute(" SELECT b.id id, b.titulo titulo, b.texto texto, b.img img, b.url url, b.video video, DATE_FORMAT(b.data, '%d') dia, DATE_FORMAT(b.data, '%m') mes, DATE_FORMAT(b.data, '%Y') ano, DATE_FORMAT(b.data, '%d/%m/%y') datas FROM ".TBP.$this->tb." b INNER JOIN ".TBP.$this->tbbc." bc ON b.id = bc.id_blog INNER JOIN ".TBP.$this->tbc." c ON c.id = bc.id_categoria WHERE c.url = '$cat' AND b.status = '1'"); $max = (mysqli_num_rows($sql) > 0) ? mysqli_num_rows($sql) : 1; } else { $sql = DBRead($this->tb, $where." ORDER BY data+0 DESC LIMIT $ini, $qnt", "id, titulo, texto, img, url, video, DATE_FORMAT(data, '%d') dia, DATE_FORMAT(data, '%m') mes, DATE_FORMAT(data, '%Y') ano, DATE_FORMAT(data, '%d/%m/%y') datas"); } $blog = ' <section class="blog"> <div class="banner pages-banner"> <div class="container"> <h1>BLOG NAMASTÊ</h1> <h2>Acompanhe as últimas novidades.</h2> </div><!-- container --> </div><!-- banner --> <div class="container"> <div class="row"> <div class="col-md-8 col-sm-8 col-12">'; if(mysqli_num_rows($sql) > 0) { while($row = mysqli_fetch_object($sql)) { $img = (!empty($row->img)) ? IMG.$this->li.$row->img : ((!empty($row->video)) ? 'https://i1.ytimg.com/vi/'.$row->video.'/mqdefault.jpg' : IMG.$this->li.$this->padrao); $ti = Resumo($row->titulo, 160); $lk = BLOG.'/'.$row->url; $res = Resumo($row->texto, 800); $blog .= ' <div class="box"> <div class="datas"> <i class="fa fa-calendar" aria-hidden="true"></i> '.$row->datas.' '.$this->ReadCategoria($row->id).' </div><!-- --> <div class="image"> <a href="'.$lk.'"><img src="'.$img.'" /></a> </div><!-- image --> <div class="resume"> <a href="'.$lk.'"><h3>'.$ti.'</h3></a> <p>'.$res.'</p> <a href="'.$lk.'" class="more"><i class="fa fa-plus-square" aria-hidden="true"></i> Ler mais</a> </div><!-- resume --> </div><!-- box -->'; } }else{ $blog .= ' <div class="box"> <h1>Não encontramos nenhum artigo publicado nesse link.</h1> </div><!-- box -->'; } $url = $this->UrlPages(); $blog .= Paginacao($qnt, $p, $url, $where, $this->tb, $max).' </div>'. $this->SideRecentes($url).' </div><!-- row -->'; $blog .= ' </div><!-- container --> </section>'; return $blog; } private function Search($busca) { $busca = DBEscape($busca); list($dia, $mes, $ano) = explode("/", $busca); if(!empty($dia) && !empty($mes) && !empty($ano) && strlen(trim($ano)) == 4) { $data = $ano.'-'.$mes.'-'.$dia; $where = " WHERE status = '1' AND data = '".$data."'"; } else { $where = " WHERE status = '1' AND titulo LIKE '%".$busca."%'"; } return $where; } public function Interno() { $url = DBEscape($_GET['url']); $sql = DBRead($this->tb, "WHERE url = '$url'", "titulo, img, texto, autor, status, data, video, meta_keywords, meta_description, url"); if(mysqli_num_rows($sql) < 1) LinkAlert(BLOG, ""); $row = mysqli_fetch_object($sql); $img = (!empty($row->img)) ? '<div class="img"><img src="'.IMG.$this->li.$row->img.'" /></div>' : ''; $you = (!empty($row->video))? Youtube($row->video, $row->titulo) : ''; $box .= ' <div class="container blog-interno blog"> <div class="row"> <div class="col-md-8 col-sm-8 col-xs-12"> <h1>'.$row->titulo.'</h1> '.$img.' '.$you.' <div class="text"> '.$row->texto.' </div><!-- text --> <div class="col-xs-12 social">'. AddThis(). AddFacebookComents(BLOG.'/'.$url).' </div> <div class="col-xs-12 voltar"> <a href="'.BLOG.'">Voltar</a> </div> </div>'; $box .= $this->SideRecentes($url); $box .= ' </div> </div>'; return $box; } private function SideRecentes($url) { $box = ' <div class="col-sm-4 col-xs-12 side"> '.$this->Idioma().' '.$this->Buscar().' '.$this->Recentes($url).' '.$this->Arquivos().' '.$this->Categorias().' </div><!-- col-sm-4 col-xs-12 -->'; return $box; } private function ReadDias($mes, $ano) { $sql = DBRead($this->tb, "WHERE YEAR(data) = '$ano' AND MONTH(data) = '$mes' AND status = '1'", "COUNT(*) dias"); $row = mysqli_fetch_object($sql); $mes = '<span>»</span> '.MesName($mes).' <span>('.$row->dias.')</span>'; return $mes; } private function ReadIdiomas($sigla) { $sql = DBRead($this->tbi, "WHERE sigla = '".$sigla."'", "idioma, sigla, id, img"); $row = mysqli_fetch_object($sql); return $row; } private function ReadCategoria($id) { $sql = DBRead($this->tbbc, "WHERE id_blog = '".$id."'", "id_categoria"); while($row = mysqli_fetch_object($sql)) { $sql2 = DBRead($this->tbc, "WHERE id = '".$row->id_categoria."'", "categoria"); $row2 = mysqli_fetch_object($sql2); $box .= '<i class="fa fa-bookmark-o" aria-hidden="true"></i>'.$row2->categoria; } return $box; } private function UrlPages() { if($_GET['ano'] && $_GET['mes']) return BLOG."?ano=".$_GET['ano']."&mes=".$_GET['mes']."&"; elseif($_GET['categoria']) return URL."/tag/".$_GET['categoria']."?"; elseif($_GET['idioma']) return URL."/language/".$_GET['idioma']."?"; else return BLOG."?"; } private function Idioma() { $box = ' <div class="idiomas"> <h3>IDIOMA</h3>'; $sql = DBRead($this->tbi, "WHERE img <> '' ORDER BY sigla ASC", "id, idioma, sigla, img"); while($row = mysqli_fetch_object($sql)){ $box .= '<a href="'.URL."/language/".$row->sigla.'" title="'.$row->idioma.'" alt="'.$row->idioma.'"><img src="'.IMG.$this->licons.$row->img.'" /><span>'.$row->sigla.'</span></a>'; } $box .= ' </div><!-- idiomas -->'; return $box; } private function Buscar() { $box = ' <div class="search"> <h3>BUSCAR</h3> <form action="'.BLOG.'" method="GET"> <input name="busca" type="text" placeholder="Buscar informações" value="'.$_GET['busca'].'" required/> <button type="submit"><i class="fa fa-search" aria-hidden="true"></i></button> </form> </div><!-- search -->'; return $box; } private function Recentes($url) { $box = ' <div class="recentes"> <h3>PUBLICAÇÕES RECENTES</h3>'; $select = DBRead($this->tb, "WHERE url <> '$url' AND status = '1' ORDER BY data+0 DESC LIMIT 5", "titulo, DATE_FORMAT(data, '%d/%m/%y') data, url"); while($line = mysqli_fetch_object($select)){ $lk = BLOG.'/'.$line->url; $titulo = Resumo($line->titulo, 70); $box .= '<a href="'.$lk.'" title="'.$line->titulo.'" alt="'.$line->titulo.'"><span>'.$line->data.'</span> '.$titulo.'</a><hr>'; } $box .= ' </div><!-- recentes -->'; return $box; } private function Arquivos() { $box = ' <div class="arquivos" id="accordion"> <h3>ARQUIVO</h3>'; $fa = 1; $show = 1; $sql = DBRead($this->tb, "WHERE status = '1' ORDER BY YEAR(data) DESC", "DISTINCT YEAR(data) ano"); while($row = mysqli_fetch_object($sql)) { $fa = ($fa == '1') ? 'fa-minus' : 'fa-plus'; $show = ($show == '1') ? ' show' : ''; $box .= ' <button class="header" data-toggle="collapse" data-target="#d'.$row->ano.'" aria-expanded="true" aria-controls="d'.$row->ano.'"> '.$row->ano.' <span>[ <i class="fa '.$fa.'"></i> ]</span> </button> <div id="d'.$row->ano.'" class="collapse'.$show.'" aria-labelledby="headingOne" data-parent="#accordion">'; for($i = 1; $i<13; $i++){ $box .= '<a href="'.BLOG.'?ano='.$row->ano.'&mes='.$i.'">'.$this->ReadDias($i, $row->ano).'</a>'; } $box .= ' </div>'; } $box .= ' </div><!-- arquivos -->'; return $box; } private function Categorias() { $box = ' <div class="categorias" > <h3>CATEGORIAS</h3>'; $sql = DBExecute(" SELECT DISTINCT(c.categoria) categoria, c.url url FROM ".TBP.$this->tb." b INNER JOIN ".TBP.$this->tbbc." bc ON b.id = bc.id_blog INNER JOIN ".TBP.$this->tbc." c ON c.id = bc.id_categoria WHERE b.status = '1' ORDER BY RAND()"); //$sql = DBRead($this->tbc, "ORDER BY RAND()", "categoria, url"); while($row = mysqli_fetch_object($sql)) { $box .= '<a href="'.URL.'/tag/'.$row->url.'">'.$row->categoria.'</a>'; } $box .= ' </div><!-- categorias -->'; return $box; } } ?>