%PDF- %PDF-
Direktori : /home1/dimen328/libertysa.com.br/includes/ |
Current File : //home1/dimen328/libertysa.com.br/includes/functions.php |
<?php function getConn(){ if($_SERVER['HTTP_HOST'] == 'superteia.com.br'){ $pdo = new PDO('mysql:dbname=superteia48;host=mysql.superteia.com.br','superteia48','bds5t4'); } else if($_SERVER['HTTP_HOST'] == 'libertysa.com.br' || $_SERVER['HTTP_HOST'] == 'www.libertysa.com.br'){ $pdo = new PDO('mysql:dbname=dimen328_bdlibertysa;host=localhost:3306','dimen328_ti','DimServ@2013'); } else{ $pdo = new PDO('mysql:dbname=dimen328_bdlibertysa;host=localhost:3306','dimen328_ti','DimServ@2013'); } $pdo->exec("set names utf8"); return $pdo; } function base_url($url=''){ if($_SERVER['HTTP_HOST'] == 'superteia.com.br'){ $base = 'http://superteia.com.br/liberty/'; } else if($_SERVER['HTTP_HOST'] == 'libertysa.com.br' || $_SERVER['HTTP_HOST'] == 'www.libertysa.com.br'){ $base = 'http://libertysa.com.br/'; } else{ //$base = 'http://libertysa1.hospedagemdesites.ws/'; $base = 'http://localhost/LibertyGrupo/'; } return $base.$url; } $GLOBALS['con'] = getConn(); function getMenus(){ $pdo = $GLOBALS['con']; $menuSPANews = ''; //busca os menus $sql = "SELECT * FROM cms_menus WHERE status = :status AND local = :local AND restrito = :restrito AND tipo = :tipo order by ordem asc;"; $vars = array(":status"=>1, ":local"=>2, ":restrito"=>1, ':tipo'=>1); $stmt = $pdo->prepare($sql); $paginas_handler = array(); if($stmt->execute($vars)) { $rows = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($rows as $r){ //busca os filhos $sql = "SELECT * FROM cms_menus WHERE status = :status AND local = :local AND restrito = :restrito AND tipo = :tipo AND categoria = :categoria order by ordem asc;"; $vars = array(":status"=>1, ":local"=>2, ":restrito"=>1, ':tipo'=>2, ':categoria' => $r->id); $stmt = $pdo->prepare($sql); $filhas = array(); if($stmt->execute($vars)) { $count = $stmt->rowCount(); $rows2 = $stmt->fetchAll(PDO::FETCH_OBJ); if($count > 0){ foreach($rows2 as $r2){ $filhas[] = (Object) array( "tipo" => $r2->tipo, "nome" => $r2->descricao, "subtitulo" => '', "texto" => '', "referencia" => $r2->link ); } } } #Seta o link de noticias para fazer o SPA de noticias if($r->link == '?p=noticias'){ $menuSPANews = '#noticias'; } else { $menuSPANews = $r->link; } $paginas_handler[] = (Object) array( "tipo" => $r->tipo, "nome" => $r->descricao, "subtitulo" => '', "texto" => '', "referencia" => $menuSPANews, "filhas" => $filhas ); } } $pdo = null; return $paginas_handler; //fim da busca de menus } function linksRodape(){ $pdo = $GLOBALS['con']; //busca os menus $sql = "SELECT * FROM cms_menus WHERE status = :status AND local = :local AND restrito = :restrito AND tipo = :tipo order by ordem asc;"; $vars = array(":status"=>1, ":local"=>2, ":restrito"=>1, ':tipo'=>3); $stmt = $pdo->prepare($sql); $saida = array(); if($stmt->execute($vars)){ $rows = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($rows as $r){ $saida[] = (Object) array( "tipo" => $r->tipo, "nome" => $r->descricao, "subtitulo" => '', "texto" => '', "referencia" => $r->link, ); } } return $saida; } function linksSidebar(){ $pdo = $GLOBALS['con']; //busca os menus $sql = "SELECT * FROM cms_menus WHERE status = :status AND local = :local AND restrito = :restrito AND tipo = :tipo order by ordem asc;"; $vars = array(":status"=>1, ":local"=>2, ":restrito"=>1, ':tipo'=>4); $stmt = $pdo->prepare($sql); $saida = array(); if($stmt->execute($vars)){ $rows = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($rows as $r){ $saida[] = (Object) array( "tipo" => $r->tipo, "nome" => $r->descricao, "subtitulo" => '', "texto" => '', "referencia" => $r->link, ); } } return $saida; } function getBanners(){ $pdo = $GLOBALS['con']; $sql = "SELECT * FROM cms_banners WHERE status = :status order by posicao asc;"; $vars = array (":status"=>1); $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ return $stmt->fetchAll(PDO::FETCH_OBJ); } else{ return false; } $pdo = null; } function getDadosEmpresa(){ $pdo = $GLOBALS['con']; $sql = "SELECT * FROM cms_empresa WHERE status = :status"; $vars = array (":status"=>1); $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ return $stmt->fetch(PDO::FETCH_OBJ); } else{ return false; } $pdo = null; } function getMetaDadosEmpresa($tipoDoDado){ $pdo = $GLOBALS['con']; $sql = "SELECT * FROM cms_dados_empresa WHERE status = :status AND id_tipo_dados_empresa = :tipo"; $vars = array (":status"=>1, ":tipo" => $tipoDoDado); $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ $rows = $stmt->fetchAll(PDO::FETCH_OBJ); $saida = array(); foreach($rows as $r){ $saida[] = $r->descricao; } return $saida; } else{ return false; } $pdo = null; } function getSessao($id){ $pdo = $GLOBALS['con']; if(is_array($id)){ $vars = array(); $cond = 'id IN('; $n = 1; $primeiro = true; foreach($id as $i){ if($primeiro){ $cond .= ":".$n; $primeiro = false; } else{ $cond .= ", :".$n; } $vars[':'.$n] = $i; $n++; } $cond .= ')'; } else{ $cond = 'id = :id'; $vars = array(':id' => $id); } $sql = 'SELECT * FROM cms_corpo_destaque WHERE status = 1 AND '.$cond.' ORDER BY id ASC'; $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ if(is_array($id)){ return $stmt->fetchAll(PDO::FETCH_OBJ); } else{ return $stmt->fetch(PDO::FETCH_OBJ); } } else{ return false; } } function midiasSociais(){ $pdo = $GLOBALS['con']; $sql = "SELECT * FROM cms_redesocial WHERE status = :status order by id asc;"; $vars = array (":status"=>1); $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ return $stmt->fetchAll(PDO::FETCH_OBJ); } else{ return false; } $pdo = null; } function noticias($limite=null){ //Pegando os dados do Feed RSS $rss = simplexml_load_file("http://www.secovi.com.br/noticias/feed"); return $rss; } function contarNoticiasData($dataInicio, $dataFim){ $pdo = $GLOBALS['con']; $sql = 'SELECT count(id) as num FROM cms_noticias WHERE status = 1 AND id_categoria = 3 AND datainicio >= :inicio AND datainicio <= :fim'; $vars = array( ':inicio' => $dataInicio, ':fim' => $dataFim ); $stmt= $pdo->prepare($sql); if($stmt->execute($vars)){ $rows = $stmt->fetch(PDO::FETCH_OBJ); return $rows->num; } else{ return false; } } function proximaNoticia($noticiaAtual){ $pdo = $GLOBALS['con']; $sql = 'SELECT id, titulo FROM cms_noticias WHERE status = 1 AND id_categoria = 3 AND id > :noticiaAtual ORDER BY datahoraemissao ASC LIMIT 1'; $vars = array( ':noticiaAtual' => $noticiaAtual ); $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ return $stmt->fetch(PDO::FETCH_OBJ); } else{ return false; } } function noticiaAnterior($noticiaAtual){ $pdo = $GLOBALS['con']; $sql = 'SELECT id, titulo FROM cms_noticias WHERE status = 1 AND id_categoria = 3 AND id < :noticiaAtual ORDER BY datahoraemissao DESC LIMIT 1'; $vars = array( ':noticiaAtual' => $noticiaAtual ); $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ return $stmt->fetch(PDO::FETCH_OBJ); } else{ return false; } } function buscarNoticia($id){ $pdo = $GLOBALS['con']; $sql = 'SELECT cms_noticias.*, u.nome AS nomeusuario, sub.descricao AS nomesubcategoria FROM cms_noticias INNER JOIN cms_usuarios AS u ON cms_noticias.id_usuario = u.id INNER JOIN cms_subcategoria_noticias AS sub ON cms_noticias.subcategoria = sub.id WHERE cms_noticias.status = 1 AND cms_noticias.id_categoria = 3 AND cms_noticias.id = :id'; $vars = array(':id' => $id); $stmt= $pdo->prepare($sql); if($stmt->execute($vars)){ $rows = $stmt->fetch(PDO::FETCH_OBJ); return $rows; } else{ return false; } } function mesString($mes){ $meses = array( '01' => 'Janeiro', '02' => 'Fevereiro', '03' => 'Abril', '04' => 'Março', '05' => 'Maio', '06' => 'Junho', '07' => 'Julho', '08' => 'Agosto', '09' => 'Setembro', '10' => 'Outubro', '11' => 'Novembro', '12' => 'Dezembro', ); return $meses[$mes]; } function dataParaString($date){ $meses = array( '01' => 'Janeiro', '02' => 'Fevereiro', '03' => 'Abril', '04' => 'Março', '05' => 'Maio', '06' => 'Junho', '07' => 'Julho', '08' => 'Agosto', '09' => 'Setembro', '10' => 'Outubro', '11' => 'Novembro', '12' => 'Dezembro', ); $dataExplode = explode("-",$date); return $meses[$dataExplode[1]]." ".$dataExplode[2].", ".$dataExplode[0]; } function timestampParaString($time){ $time = explode(" ", $time); $hora = explode(":", $time[1]); return dataParaString($time[0]).' às '.$hora[0].":".$hora[1]; } function pegarServico($servico){ $pdo = $GLOBALS['con']; $sql = "SELECT * FROM cms_noticias WHERE id_categoria = 2 AND status = 1 AND link = :link"; $vars = array(':link' => $servico); $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ $row = $stmt->fetch(PDO::FETCH_OBJ); if($row){ return $row; } else{ return false; } } else{ return false; } } function categoriasNoticias(){ $pdo = $GLOBALS['con']; $sql = "SELECT * FROM cms_subcategoria_noticias WHERE status = 1 ORDER BY ordem ASC"; $stmt = $pdo->prepare($sql); if($stmt->execute()){ return $stmt->fetchAll(PDO::FETCH_OBJ); } else{ return false; } } function paginas(){ $pdo = $GLOBALS['con']; $sql = 'SELECT * FROM `cms_menus` WHERE local = 2 AND tipo in(1,2)'; $stmt = $pdo->prepare($sql); if($stmt->execute()){ return $stmt->fetchAll(PDO::FETCH_OBJ); } else{ return false; } } function listarComentarios($noticia){ $pdo = $GLOBALS['con']; $sql = 'SELECT * FROM cms_comentarios WHERE status = 1 AND noticia = :noticia'; $vars = array(':noticia' => $noticia); $stmt = $pdo->prepare($sql); if($stmt->execute($vars)){ return $stmt->fetchAll(PDO::FETCH_OBJ); } else { return array('0'); } } function getPopup(){ $pdo = $GLOBALS['con']; $sql = "SELECT * FROM popup WHERE id = 1 AND status = 1"; $stmt = $pdo->prepare($sql); if($stmt->execute()){ return $stmt->fetch(PDO::FETCH_OBJ); } else{ return false; } } function tirarAcentos($string){ return preg_replace(array("/(á|à|ã|â|ä)/","/(Á|À|Ã|Â|Ä)/","/(é|è|ê|ë)/","/(É|È|Ê|Ë)/","/(í|ì|î|ï)/","/(Í|Ì|Î|Ï)/","/(ó|ò|õ|ô|ö)/","/(Ó|Ò|Õ|Ô|Ö)/","/(ú|ù|û|ü)/","/(Ú|Ù|Û|Ü)/","/(ñ)/","/(Ñ)/"),explode(" ","a A e E i I o O u U n N"),$string); } ?>