/config/funcoes.php
PHP | 273 lines | 162 code | 50 blank | 61 comment | 28 complexity | 079f0653cc5e2908e7b4d007b8e99eda MD5 | raw file
Possible License(s): BSD-2-Clause, Apache-2.0, MIT, GPL-3.0
- <?php
- function crip($msg){
- $date="08:36:21";
- $chave="X1C3fh50";
-
- $iv = md5( md5(($date)) );
- return base64_encode(utf8_encode( mcrypt_encrypt(
- MCRYPT_RIJNDAEL_256, md5( $chave ),
- $msg, MCRYPT_MODE_CBC, $iv
- )));
- }
- function descrip($msg){
- $date="08:36:21";
- $chave="X1C3fh50";
- return rtrim(
- mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5($chave), utf8_decode(base64_decode($msg)), MCRYPT_MODE_CBC, md5( md5($date))),
- "\x00..\x1F"
- );
- }
- function notificacao($titulo,$mensagem,$tipo){
- echo "<script>";
- echo "new PNotify({";
- echo "title: '".$titulo."',";
- echo "text: '".$mensagem."',";
- echo " type: '".$tipo."',";
- echo " styling: 'bootstrap3'";
- echo "});";
- echo "</script>";
- }
- //funcao de envio do email
- function enviarEmail( $para, $assunto, $corpo ) {
- //importa o phpmailer
- require '../classes/PHPMailerAutoload.php';
- //define o usuario e senha do gmail
- define( 'GUSER', "cristianhassfretes@gmail.com" ); // <-- Insira aqui o seu GMail
- define( 'GPWD', "euquerocafe" ); // <-- Insira aqui a senha do seu GMail
- global $error;
- $mail = new PHPMailer();
- $mail->IsSMTP(); // Ativar SMTP
- $mail->SMTPDebug = 0; // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
- $mail->SMTPAuth = true; // Autenticação ativada
- $mail->SMTPSecure = 'tls'; // SSL REQUERIDO pelo GMail
- $mail->Host = 'smtp.gmail.com'; // SMTP utilizado
- $mail->Port = 587; // A porta 587 deverá estar aberta em seu servidor
- $mail->Username = GUSER;
- $mail->Password = GPWD;
- $mail->SetFrom(GUSER, "Sistema Escolar");
- $mail->Subject = $assunto;
- $mail->Body = $corpo;
- $mail->AddAddress( $para );
- $mail->CharSet = 'utf-8';
- if ( !$mail->Send() ) {
- $error = 'Mail error: ' . $mail->ErrorInfo;
- return false;
- } else {
- return true;
- }
- }
- function validaEmail($email){
- //verifica se e-mail esta no formato correto de escrita
- if (!preg_match('/^([a-zA-Z0-9.-_])*([@])([a-z0-9]).([a-z]{2,3})/',$email)){
- return false;
- }
- else{
- //Valida o dominio
- $dominio=explode('@',$email);
- if(!checkdnsrr($dominio[1],'MX')){
- return false;
- }
- else{return true;} // Retorno true para indicar que o e-mail é valido
- }
- }
- function remover_caracter($string) {
- // matriz de entrada
- $what = array( 'ä','ã','à','á','â','ê','ë','è','é','ï','ì','í','ö','õ','ò','ó','ô','ü','ù','ú','û','À','Á','É','Í','Ó','Ú','ñ','Ñ','ç','Ç',' ','-','(',')',',',';',':','|','!','"','#','$','%','&','/','=','?','~','^','>','<','ª','º','.' );
- // matriz de saída
- $by = array( 'a','a','a','a','a','e','e','e','e','i','i','i','o','o','o','o','o','u','u','u','u','A','A','E','I','O','U','n','n','c','C','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','','-','-','-','-','-','-','-' );
- // devolver a string
- return str_replace($what, $by, $string);
-
- }
- function textoLink($txt){
- $saida=remover_caracter($txt);
- $saida=explode('--',$saida);
- $saida=implode('-',$saida);
- $saida=strtolower($saida);
- return $saida;
- }
- function texto ($texto,$maximo){
- $texto = strip_tags($texto);
- $conta = strlen($texto);
-
- if($conta <= $maximo){
- return $texto;
- }
- else{
- $limita =substr($texto, 0,$maximo);
-
- return $limita.'...';
-
-
-
- }}
-
- function ProcurarImagensNoHTML( $html) {
- $pattern='/<img.*src="(.*?)".*\/?>/';
- $result=preg_match_all($pattern,$html,$matches);
- if(!$result){
- return false;
- }
- $matches=$matches[0];
-
- return $matches;
- }
- function limpaTexto ($texto){
- return mysql_real_escape_string(strip_tags(trim(stripslashes($texto))));
-
-
- }
- /**
- * @author Luís Fred
- * @mail fred.alphax@gmail.com
- */
- /*Esta é a função que se encarregará de criar as imagens menores, ela contem
- *5 variáveis como parâmetros, que são:
- * $filetype: o tipo de arquivo envolvido, se gif, jpeg ou png;
- * $origfile: E o arquivo de imagem original, que você indicou para upload e que dará
- * origem à uma imagem menor(thumb);
- * $thumbfile: Este parâmetro irá conter o caminho/nome da imagem que será a nossa imegem
- * de tamanho reduzido(thumb);
- * $new_w: Esta variável irá conter o valor de configuração para a largura da imagem menor;
- * $new_h: Está variável irá conter o valor de configuração para a altura da imagem menor;
- */
- function createthumbnail($filetype, $origfile, $thumbfile, $new_w, $new_h, $compress) {
- /*Nas três linhas que seguem, são feitas algumas verificações acerca do tipo de arquivo de imagem.
- *Para cada verificação bem sucedida, é criado um novo arquivo de imagem apartir da imagem original.
- *a função imagecreatefrom*() retorna um identificador de imagem representando a imagem obtida através do nome de *arquivo dado.
- **/
- if ($filetype == 1) { $origimage = imagecreatefromgif($origfile); }
- elseif ($filetype == 2) { $origimage = imagecreatefromjpeg($origfile); }
- elseif ($filetype == 3) { $origimage = imagecreatefrompng($origfile); }
- /*Nestas duas linhas que seguem, note que são obtidas largura e altura da imagem com as funções
- *imagesx() e imagesy() respectivamente. para mais informações sobre as funções utilizadas neste
- *script, acesse www.php.net
- */
- $old_x = imagesx($origimage);
- $old_y = imagesy($origimage);
- /*verifica se a largura e altura obtidas anteriormente são maiores
- *que a largura e a altura estabelecidas estabelecidas para as imagens menores
- *que serão criadas.
- *Em seguida, estabelece as novas dimensões para a imagem original. veja o uso
- *da funcção round() na terceira linha do laço if():
- *$thumb_w = round(($old_x * $new_h) / $old_y).
- *multiplica-se o valor da largura que foi obtida da imagem, usando imagesx() pelo
- *valor da altura estabelecido para a imagem menor. em seguida divide-se o valor obtido
- *pela altura da imagem original, a função roud() arredonda o valor do resultado nesta
- *operação. Este resultado é então armazenado na variável $thumb_w, que será a largura
- *da imagem pequena.
- *a operação $thumb_h = round(($old_y * $new_w) / $old_x); segue o mesmo raciocínio.
- */
- if ($old_x > $new_w || $old_y > $new_h) {
- if ($old_x < $old_y) {
- $thumb_w = round(($old_x * $new_h) / $old_y);
- $thumb_h = $new_h;
- } elseif ($old_x > $old_y) {
- $thumb_w = $new_w;
- $thumb_h = round(($old_y * $new_w) / $old_x);
- } else {
- $thumb_w = $new_w;
- $thumb_h = $new_h;
- }
- } else {
- $thumb_w = $old_x;
- $thumb_h = $old_y;
- }
- /*apartir daqui, temos a criação propriamente dita, das imagens pequenas.
- *Repare nas funções imagecreate() e imagecreatetruecolor(). Esta ultima requer
- *versão GD 2.0.1 ou maiores. se não for possível usar gd1, então será usada gd2 para
- *diminuir a imagem original.
- *a função imagecopyresized() redimensiona e copia a imagem.
- *imagecreatetruecolor() tem um efeito similar a imagecreate().
- *Para mais informações a respeito de imagecreatetruecolor(), imagecreate() e imagecopyresampled(),
- *acesse www.php.net.
- */
- if ($compress == "gd1") {
- $thumbimage = imagecreate($thumb_w,$thumb_h);
- $result = imagecopyresized($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
- } else {
- $thumbimage = imagecreatetruecolor($thumb_w,$thumb_h);
- $result = imagecopyresampled($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
- }
- /*Muda o tempo de acesso e modificação do arquivo de imagem fornecido como terceiro parâmetro da função *createthumbnail() para o tempo atual.
- */
- touch($thumbfile);
- /*a função imagegif() cria uma imagem gif em $thumbfile apartir de $thumbimage
- *que guarda a imagem que foi criada com novas dimensões.
- *imagejpeg() e imagepng() tem efeitos similares a função imagegif().
- */
- if ($filetype == 1) { imagegif($thumbimage, $thumbfile); }
- elseif ($filetype == 2) { imagejpeg($thumbimage, $thumbfile); }
- elseif ($filetype == 3) { imagepng($thumbimage, $thumbfile); }
- }
- /*Esta função checa se uma imagem existe em um determinado diretório.
- *se a imagem procurada existir, então será criado um nome diferente para ela
- */
- function image_exists($dir, $image) {
- $i = 1;
- $image_name = substr($image, 0, strrpos($image, "."));
- $image_ext = strrchr($image,".");
- while (file_exists($dir.$image)) {
- $image = $image_name."_".$i.$image_ext;
- $i++;
- }
- return $image;
- }
- function data($d1, $d2, $type='', $sep='-')
- {
- $d1 = explode($sep, $d1);
- $d2 = explode($sep, $d2);
- $segundos= ( ( ( mktime($d2[3], $d2[4], $d2[5], $d2[0], $d2[1], $d2[2]) - mktime($d1[3], $d1[4], $d1[5], $d1[0], $d1[1], $d1[2]) ) ));
- if($segundos>=86400){
- return intval($segundos/86400)." dia (s)";
- }
- else if($segundos>=3600){
- return intval($segundos/3600)." hora (s)";
- }
- else if($segundos>=60){
- return intval($segundos/60)." min (s)";
- }
- else{
- return "agora";
- }
- }
- ?>