Created
November 25, 2013 21:42
-
-
Save wwwbruno/7649409 to your computer and use it in GitHub Desktop.
Helper do codeigniter com funções úteis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/* | |
| ------------------------------------------------------------------------- | |
| Site Helper | |
| ------------------------------------------------------------------------- | |
| Desenvolvido por Bruno Almeida | |
| | |
*/ | |
/** | |
* url_amigavel | |
* | |
* Retira acentos, substitui espaço por - e | |
* deixa tudo minúsculo | |
* | |
* | |
* @param string | |
* @return string | |
*/ | |
function url_amigavel($variavel){ | |
$procurar = array('à','ã','â','é','ê','í','ó','ô','õ','ú','ü','ç',); | |
$substituir = array('a','a','a','e','e','i','o','o','o','u','u','c',); | |
$variavel = strtolower($variavel); | |
$variavel = str_replace($procurar, $substituir, $variavel); | |
$variavel = htmlentities($variavel); | |
$variavel = preg_replace("/&(.)(acute|cedil|circ|ring|tilde|uml);/", "$1", $variavel); | |
$variavel = preg_replace("/([^a-z0-9]+)/", "-", html_entity_decode($variavel)); | |
return trim($variavel, "-"); | |
} | |
/** | |
* data_br | |
* | |
* Converte uma data no formato mysql para o formato brasileiro | |
* | |
* | |
* @param string | |
* @return string | |
*/ | |
function data_br($data_bd){ | |
return implode('/',array_reverse(explode('-',$data_bd))); | |
} | |
/** | |
* data_bd | |
* | |
* Converte uma data no formato brasileiro para o formato mysql | |
* | |
* | |
* @param string | |
* @return string | |
*/ | |
function data_bd($data_br){ | |
return implode('-',array_reverse(explode('/',$data_br))); | |
} | |
/** | |
* limitar_texto | |
* | |
* Remove todas as tags HTML e limita os caractéres do texto, adicionando ... se for maior que o limite | |
* | |
* | |
* @param string, int | |
* @return string | |
*/ | |
function limitar_texto($texto,$limit){ | |
$texto = strip_tags($texto); | |
if(strlen($texto) > $limit){ | |
return substr($texto,0,$limit).'...'; | |
} else { | |
return substr($texto,0,$limit); | |
} | |
} | |
/** | |
* enviar_email | |
* | |
* Faz o envio de e-mail | |
* | |
* | |
* @param string, string, string/array | |
* @return boolean | |
*/ | |
function enviar_email($destinatarios,$assunto,$corpo){ | |
$CI =& get_instance(); | |
$config = array( | |
'protocol' => 'smtp', | |
'smtp_host' => 'mail.site.com.br', | |
'smtp_port' => 465, | |
'smtp_user' => '[email protected]', | |
'smtp_pass' => 'senha' | |
); | |
$CI->load->library('email', $config); | |
$CI->email->set_newline("\r\n"); | |
$CI->email->from('[email protected]', 'Portal Urubici.com.br'); | |
$CI->email->subject($assunto); | |
$CI->email->message($corpo); | |
if(!is_array($destinatarios)){ | |
$CI->email->to($destinatarios); | |
} else { | |
foreach ($destinatarios as $destinatario) { | |
$CI->email->to($destinatario); | |
} | |
} | |
return $CI->email->send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment