$width){ $h_point = (($height - $height_new) / 2); imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new); }else{ $w_point = (($width - $width_new) / 2); imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height); } $image($dst_img, $dst_dir, $quality); if($dst_img)imagedestroy($dst_img); if($src_img)imagedestroy($src_img); } function envia_email($emailpara,$assunto,$mensagem){ if (validaEMAIL($emailpara)){ $emailde = 'naoresponder@abraco.digital'; $cabecalho = " Abraço Digital
".$nome."
"; $rodape = "

Equipe Abraço Digital
Abraço Digital
"; $mensagem = $cabecalho . $mensagem . $rodape; $headers = "MIME-Version: 1.1\n"; $headers .= "Content-type: text/html; charset=utf-8\n"; $headers .= "From: ".$emailde."\n"; // remetente $headers .= "Return-Path: ".$emailde."\n"; // return-path $quebra_linha = "\n"; if(!mail($emailpara, $assunto, $mensagem, $headers ,"-r".$emailde)){ // Se for Postfix $headers .= "Return-Path: " . $emailde . $quebra_linha; // Se "não for Postfix" $envio = mail($emailpara, $assunto, $mensagem, $headers ); } if($envio){ return 0; }else{ return 1; } } } function cria_url($string){ $string = iconv( "UTF-8" , "ASCII//TRANSLIT//IGNORE" , $string ); $string = preg_replace( array( '/[ ]/' , '/[^A-Za-z0-9\-]/' ) , array( '' , '' ) , $string ); $cont = 0; $achou = false; $stringo = $string; while (!$achou){ if (checa_url($string)) { $achou = true; }else{ $cont++; $string = $stringo . $cont; } } return $string; } function checa_url($url){ $strsql = "select id_abraco from tbl_abracos where url='".$url."'"; $res = mysqli_query($GLOBALS['bd_con'],$strsql); if (mysqli_num_rows($res)){ if($row = mysqli_fetch_array($res)) { $id_abraco = $row['id_abraco']; } } if ($id_abraco){ return false; }else{ return true; } } function conv_data($d){ $data_hora_array = explode(" ",$d); $data_hora_array1 = explode("-",$data_hora_array[0]); $dataX = trim($data_hora_array1[2]."/".$data_hora_array1[1]."/".$data_hora_array1[0]." ".$data_hora_array[1]); return $dataX; } function pega_mes($mes){ switch ($mes){ case 1: $m='JAN'; break; case 2: $m='FEV'; break; case 3: $m='MAR'; break; case 4: $m='ABR'; break; case 5: $m='MAI'; break; case 6: $m='JUN'; break; case 7: $m='JUL'; break; case 8: $m='AGO'; break; case 9: $m='SET'; break; case 10: $m='OUT'; break; case 11: $m='NOV'; break; case 12: $m='DEZ'; break; } return $m; } function pega_mes_ext($mes){ switch ($mes){ case 1: $m='Janeiro'; break; case 2: $m='Fevereiro'; break; case 3: $m='Março'; break; case 4: $m='Abril'; break; case 5: $m='Maio'; break; case 6: $m='Junho'; break; case 7: $m='Julho'; break; case 8: $m='Agosto'; break; case 9: $m='Setembro'; break; case 10: $m='Outubro'; break; case 11: $m='Novembro'; break; case 12: $m='Dezembro'; break; } return $m; } function geraTimestamp($data) { // Datas em formato AAAA-MM-DD $partes = explode('-', $data); return mktime(0, 0, 0, $partes[1], $partes[2], $partes[0]); } function pega_diferenca($data_inicial,$data_final){ // Usa a função criada e pega o timestamp das duas datas: $time_inicial = geraTimestamp($data_inicial); $time_final = geraTimestamp($data_final); // Calcula a diferença de segundos entre as duas datas: $diferenca = $time_final - $time_inicial; // 19522800 segundos // Calcula a diferença de dias $dias = (int)floor( $diferenca / (60 * 60 * 24)); // 225 dias return $dias; } function pega_foto($id){ $sql = "select foto from tbl_usuarios where id_usuario=" .$id; $resPL = mysqli_query($GLOBALS['bd_con'],$sql); if ($rowPL = mysqli_fetch_array($resPL)) { $foto = $rowPL['foto']; } $foto = foto_perfil($foto); return $foto; } function traduz_semana($dia){ switch ($dia){ case 'Sunday': $t = 'Domingo'; break; case 'Monday': $t = 'Segunda-feira'; break; case 'Tuesday': $t = 'Terça-feira'; break; case 'Wednesday': $t = 'Quarta-feira'; break; case 'Thursday': $t = 'Quinta-feira'; break; case 'Friday': $t = 'Sexta-feira'; break; case 'Saturday': $t = 'Sábado'; break; } return $t; } function validaEMAIL($email){ $mail_correcto = 0; //verifico umas coisas if ((strlen($email) >= 6) && (substr_count($email,"@") == 1) && (substr($email,0,1) != "@") && (substr($email,strlen($email)-1,1) != "@")){ if ((!strstr($email,"'")) && (!strstr($email,"\"")) && (!strstr($email,"\\")) && (!strstr($email,"\$")) && (!strstr($email," "))) { //vejo se tem caracter . (ponto) if (substr_count($email,".")>= 1){ //obtenho a terminação do dominio $term_dom = substr(strrchr ($email, '.'),1); //verifico que a terminação do dominio seja correcta if (strlen($term_dom)>1 && (!strstr($term_dom,"@")) ){ //verifico que o de antes do dominio seja correcto $antes_dom = substr($email,0,strlen($email) - strlen($term_dom) - 1); $caracter_ult = substr($antes_dom,strlen($antes_dom)-1,1); if ($caracter_ult != "@" && $caracter_ult != "."){ $mail_correcto = 1; } } } } } if ($mail_correcto) return true; else return false; } function pega_Var($sqlN){ $resN = mysqli_query($GLOBALS['bd_con'],$sqlN); if($resN){ //Exibe as linhas encontradas na consulta if ($rowN = mysqli_fetch_array($resN)) { $var = $rowN[0]; return $var; } } } function pega_VarArray($sqlN){ $resN = mysqli_query($GLOBALS['bd_con'],$sqlN); $var = array(); if($resN){ //Exibe as linhas encontradas na consulta while ($rowN = mysqli_fetch_array($resN)) { $var[] = $rowN[0]; } } return $var; } function pega_NomeEquipe($id,$mostra){ $sqlN = "SELECT titulo FROM tbl_equipes where id_equipe=".$id; $resN = mysqli_query($GLOBALS['bd_con'],$sqlN); if($resN){ //Exibe as linhas encontradas na consulta if ($rowN = mysqli_fetch_array($resN)) { $var = $rowN['titulo']; return $var; } } } // Função para limpar perfil function limpa_perfil($str) { $str = trim(str_replace("http://","",$str)); $str = trim(str_replace("https://","",$str)); $str = trim(str_replace("www.","",$str)); $str = trim(str_replace("facebook.com/","",$str)); $str = trim(str_replace("instagram.com/","",$str)); $str = trim(str_replace("twitter.com/","",$str)); $str = trim(str_replace("facebook.com.br/","",$str)); $str = trim(str_replace("instagram.com.br/","",$str)); $str = trim(str_replace("twitter.com.br/","",$str)); $x = explode("?",$str); $str = $x[0]; $str = trim(str_replace("/","",$str)); $str = trim(str_replace("@","",$str)); return $str; } // Deixa apenas números function valida_n($str) { return preg_replace("/[^0-9]/", "", $str); } // Função para Checkbox e Radio function valida_txt($str) { $str = trim(str_replace("'","",$str)); return $str; } // Função para Checkbox e Radio function valida_a($str) { if (!$str) { return 0; }else{ return $str; } } // Função para Valor function valida_m($str) { if (!$str){ return 0; }else{ $xvalor = $str; $xvalor = str_replace(".","",$xvalor); $xvalor = str_replace(",",".",$xvalor); return $xvalor; } } function mysql_hora($h){ $hor = explode(":","$h"); // fatia a string $dat em pedados, usando / como referência $hora = $hor[0]; $minuto = $hor[1]; $segundo = $hoa[2]; return $hora . ":" . $minuto; } // Função para validar Data antes de gravar function valida_d($dat){ $data = explode("/","$dat"); // fatia a string $dat em pedados, usando / como referência $d = $data[0]; $m = $data[1]; $y = $data[2]; if (is_numeric($d) && is_numeric($m) && is_numeric($y)) { // verifica se a data é válida! // 1 = true (válida) // 0 = false (inválida) $res = checkdate($m,$d,$y); if ($res == 1){ $dat = implode("-", array_reverse(explode("/", $dat))); return $dat; } else { return ''; } }else{ return ''; } } // Função para mostrar data do mysql function data_mysql($str,$comHora){ if ($str <> '0000-00-00 00:00:00'){ $datetime = strtotime($str); if ($comHora){ $xdata = date("d/m/Y H:i:s", $datetime); }else{ $xdata = date("d/m/Y", $datetime); } return $xdata; } } function valor_mysql($str,$decimal){ $xvalor = number_format($str,$decimal); $xvalor = str_replace(",","",$xvalor); $xvalor = str_replace(".",",",$xvalor); return $xvalor; } function ativo_mysql($str){ if ($str){ return "Sim"; }else{ return "Não"; } } function square_thumbnail_with_proportion($src_file,$destination_file,$square_dimensions,$jpeg_quality=100) { // Step one: Rezise with proportion the src_file *** I found this in many places. $src_img=imagecreatefromjpeg($src_file); $old_x=imageSX($src_img); $old_y=imageSY($src_img); $ratio1=$old_x/$square_dimensions; $ratio2=$old_y/$square_dimensions; if($ratio1>$ratio2) { $thumb_w=$square_dimensions; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$square_dimensions; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions $smaller_image_with_proportions=ImageCreateTrueColor($thumb_w,$thumb_h); // resize the big image to the new created one imagecopyresampled($smaller_image_with_proportions,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // *** End of Step one *** // Step Two (this is new): "Copy and Paste" the $smaller_image_with_proportions in the center of a white image of the desired square dimensions // Create image of $square_dimensions x $square_dimensions in white color (white background) $final_image = imagecreatetruecolor($square_dimensions, $square_dimensions); $bg = imagecolorallocate ( $final_image, 255, 255, 255 ); imagefilledrectangle($final_image,0,0,$square_dimensions,$square_dimensions,$bg); // need to center the small image in the squared new white image if($thumb_w>$thumb_h) { // more width than height we have to center height $dst_x=0; $dst_y=($square_dimensions-$thumb_h)/2; } elseif($thumb_h>$thumb_w) { // more height than width we have to center width $dst_x=($square_dimensions-$thumb_w)/2; $dst_y=0; } else { $dst_x=0; $dst_y=0; } $src_x=0; // we copy the src image complete $src_y=0; // we copy the src image complete $src_w=$thumb_w; // we copy the src image complete $src_h=$thumb_h; // we copy the src image complete $pct=100; // 100% over the white color ... here you can use transparency. 100 is no transparency. imagecopymerge($final_image,$smaller_image_with_proportions,$dst_x,$dst_y,$src_x,$src_y,$src_w,$src_h,$pct); imagejpeg($final_image,$destination_file,$jpeg_quality); // destroy aux images (free memory) imagedestroy($src_img); imagedestroy($smaller_image_with_proportions); imagedestroy($final_image); } function abre_con(){ ///************************* INICIO DA CONEXÃO COM BANCO DE DADOS //Este arquivo conecta um banco de dados MySQL – Servidor $host = "localhost"; // Host do banco de dados $dbname="abraco_wp"; // Indique o nome do banco de dados que será aberto $usuario="abraco_user"; // Indique o nome do usuário que tem acesso $password="2105@STcruz@3003*"; // Indique a senha do usuário if(!($GLOBALS['bd_con'] = mysqli_connect($host,$usuario,$password,$dbname))) { echo "Não foi possível estabelecer uma conexão com o gerenciador MySQL. Favor Contactar o Administrador."; exit; } ///************************* FIM DA CONEXÃO COM BANCO DE DADOS // Para processar emoji mysqli_query($GLOBALS['bd_con'], 'SET NAMES "utf8mb4" COLLATE "utf8mb4_general_ci"' ); return $GLOBALS['bd_con']; } function fecha_con(){ mysqli_close($GLOBALS['bd_con']); } ?>