0); // métido 1 via cep if($metodo == 'all' or $metodo == 1){ $dadosvia = json_decode(file_get_contents('http://viacep.com.br/ws/'.$cep.'/json/'), true); if($dadosvia['localidade'] != ''){ $dados = array( 'resultado'=> 1, 'uf'=> ($dadosvia['uf']), 'cidade'=> ($dadosvia['localidade']), 'bairro'=> ($dadosvia['bairro']), 'logradouro'=> ($dadosvia['logradouro']), 'cep'=> $cep, 'metodo'=> 1 ); }else{ $dados = array('resultado'=> 0, 'metodo'=> 2); } if($testing == 1){ print_r($dados); }elseif($dados['resultado'] == 1){ return $dados; die(); } } // métido 2 html correios if($dado['resultado'] == 0 AND ($metodo == 'all' or $metodo == 2)){ include('phpQuery-onefile.php'); function simple_curl($url,$post=array(),$get=array()){ $url = explode('?',$url,2); if(count($url)===2){ $temp_get = array(); parse_str($url[1],$temp_get); $get = array_merge($get,$temp_get); } $ch = curl_init($url[0]."?".http_build_query($get)); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($post)); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); return curl_exec ($ch); } $html = simple_curl('http://m.correios.com.br/movel/buscaCepConfirma.do',array( 'cepEntrada'=>$cep, 'tipoCep'=>'', 'cepTemp'=>'', 'metodo'=>'buscarCep' )); phpQuery::newDocumentHTML($html, $charset = 'UTF-8'); $errCEP= array('erro'=> trim(pq('.erro:eq(0)')->html())); if(empty($errCEP["erro"])){ // multiplos locais $logradouro = trim(pq('.caixacampobranco .resposta:contains("Logradouro: ") + .respostadestaque:eq(0)')->html()); if($logradouro != ''){ $logradouro = explode(' - ', $logradouro); $logradouro = trim($logradouro[0]); }else{ $logradouro = trim(pq('.caixacampobranco .resposta:contains("Ender") + .respostadestaque:eq(0)')->html()); $logradouro = explode(',', $logradouro); $logradouro = trim($logradouro[0]); } $cidadeuf = trim(pq('.caixacampobranco .resposta:contains("Localidade / UF: ") + .respostadestaque:eq(0)')->html()); if($cidadeuf == ''){ $cidadeuf = trim(pq('.caixacampobranco .resposta:contains("Localidade/UF: ") + .respostadestaque:eq(0)')->html()); } $dados = array( 'resultado'=> 1, 'uf'=> '', 'cidade'=> '', 'bairro'=> trim(pq('.caixacampobranco .resposta:contains("Bairro: ") + .respostadestaque:eq(0)')->html()), 'logradouro'=> $logradouro, 'cidade/uf'=> $cidadeuf, 'cep'=> trim(pq('.caixacampobranco .resposta:contains("CEP: ") + .respostadestaque:eq(0)')->html()), 'metodo'=> 2 ); $dados['cidade/uf'] = explode('/',$dados['cidade/uf']); $dados['cidade'] = trim($dados['cidade/uf'][0]); $dados['uf'] = trim($dados['cidade/uf'][1]); unset($dados['cidade/uf']); }else{ $dados = array('resultado'=> 0, 'metodo'=> 2); } if($testing == 1){ print_r($dados); }elseif($dados['resultado'] == 1){ return $dados; die(); } } // metodo 3 - republica virtal if($dado['resultado'] == 0 AND ($metodo == 'all' or $metodo == 3)){ $dados = json_decode(file_get_contents('http://republicavirtual.com.br/web_cep.php?cep='.($cep).'&formato=JSON'), true); $dados['logradouro'] = $dados['tipo_logradouro'].' '.$dados['logradouro']; unset($dados['tipo_logradouro'], $dados['resultado_txt']); $dados['cep'] = $cep; $dados['metodo'] = 3; if($testing == 1){ print_r($dados); }else{ return $dados; die(); } } return $dados; } function clienteLogado() { $ID = $_SESSION["cliente"]["id"]; $email = $_SESSION["cliente"]["email"]; $sql = mysql_query("SELECT * FROM site_clientes WHERE ID = '$ID' AND email = '$email'"); $result = mysql_num_rows($sql); if($result == true) { return true; } else { return false; } } function getCliente($campo) { return mysql_fetch_object(mysql_query("SELECT * FROM site_clientes WHERE ID = '".$_SESSION["cliente"]["id"]."'"))->$campo; } function tinyCompress($foto) { $sql = mysql_fetch_object(mysql_query("SELECT * FROM sys_tiny WHERE utilizado <= limite AND ID ORDER BY RAND() LIMIT 1")); $utilizado = $sql->utilizado; if($sql == true) { $api = new TinyPNG($sql->secretKey); $api->shrink($dir.$foto); $result = $api->getResult(); $resultJson = $api->getResultJson(); $result = $resultJson->output->url; if($result == true) { @unlink($foto); @copy($result, $foto); update( array( "utilizado" ), array( $utilizado+1 ), "sys_tiny", "WHERE ID = '".$sql->ID."'" ); return true; } else { return false; } } else { return false; } /* stdClass Object ( [input] => stdClass Object ( [size] => 120483 [type] => image/jpeg ) [output] => stdClass Object ( [size] => 62948 [type] => image/jpeg [width] => 1920 [height] => 1080 [ratio] => 0.5225 [url] => https://api.tinypng.com/output/kjfj0biii8fk8di3.jpg ) ) */ } function nivel($pagina, $internas = true) { $sql = mysql_query("SELECT * FROM sys_admin_niveis WHERE adminID = '".$_SESSION["adminID"]."' AND pagina = '$pagina'"); $result = mysql_num_rows($sql); if($result > 0) { return true; } else { if($internas == true) // Internas "true" é para travar a página e exibir mensagem de acesso bloqueado { echo '

Você não tem permissão para acessar essa página.
Entre em contato com administrador do site
'; include_once("footer.php"); exit; } else // Internas "false" exibe apenas retorno "true" ou "false" { return false; } } } // Apenas para as páginas do Admin function separador($text){ return '

'.$text.'


'; } function dadosAdmin($campo) { $sql = mysql_query("SELECT $campo FROM sys_admin"); $ln = mysql_fetch_object($sql); if($ln->$campo == true) { return $ln->$campo; } else { return "Campo $campo nao encontrado."; } } function sweetAlert($title, $msg, $type, $btnText = 'Fechar') { if($type == "error") { $btnColor = "#F27474"; } elseif($type == "success") { $btnColor = "#A5DC86"; } elseif($type == "warning") { $btnColor = "#F8C086"; } elseif($type == "info") { $btnColor = "#C9DAE1"; } return ' '; } function sweetDoisBotao($title, $msg, $type, $btnText1, $btnText2, $url1, $url2) { if($type == "error") { $btnColor = "#F27474"; } elseif($type == "success") { $btnColor = "#A5DC86"; } elseif($type == "warning") { $btnColor = "#F8C086"; } elseif($type == "info") { $btnColor = "#C9DAE1"; } return ' '; } function jsScript($content) { return ' '; } function sweetRedir($title, $msg, $type, $url, $btnText = 'Continuar') { if($type == "error") { $btnColor = "#F27474"; } elseif($type == "success") { $btnColor = "#A5DC86"; } elseif($type == "warning") { $btnColor = "#F8BF86"; } elseif($type == "info") { $btnColor = "#C9DAE1"; } else { $btnColor = "#888888"; } return ' '; } function sweetAutoRedir($title, $msg, $type, $url) { return ' '; } function sweetFunc($title, $msg, $type, $btnText = 'Continuar', $funcao) { if($type == "error") { $btnColor = "#F27474"; } elseif($type == "success") { $btnColor = "#A5DC86"; } elseif($type == "warning") { $btnColor = "#F8BF86"; } elseif($type == "info") { $btnColor = "#C9DAE1"; } else { $btnColor = "#888888"; } return ' '; } function jsRedir($url) { echo ''; } function redirPHP($url) { ob_start(); header("Location: $url"); } function noInject($campo, $adicionaBarras = false) { $campo = preg_replace("/(from|alter table|select|insert|delete|update|where|drop table|show tables|#|\*|--|\\\\)/i","",$campo); $campo = trim($campo); $campo = strip_tags($campo); if($adicionaBarras || !get_magic_quotes_gpc()) $campo = addslashes($campo); return $campo; } /* LIMITAR PALAVRAS */ function limitarPalavras($str, $limit = 25) { $str = preg_replace( "/\r|\n/", " ", html_entity_decode (strip_tags($str) )); $str = str_replace(''', "'", $str); $exp = explode(' ', $str); $return = ''; for($n=0; $n<$limit; $n++){ if(trim($exp[$n]) != ''){ $return .= trim($exp[$n]).' '; } } if(count($exp) > $limit){ $return .= '...'; } return $return; } function limitarParagrafos($str, $limit = 1, $limpaTags = false) { $textoChamada = explode('

', str_replace(array("
", "
", "
", "
", "

"), "", $str)); $parafs = array(); for($i=1; $i<=$limit*2; $i++){ $s = $textoChamada[$i-1]; if($limpaTags){$s = strip_tags($s); } $s = trim($s); if($s != ''){ $parafs[] = $s; } } $parafsFinais = array(); for($i=0; $i<=$limit; $i++){ $parafsFinais[] = $parafs[$i]; } return implode('
', $parafsFinais); } function upper($p){ $p = strtr($p, "áàãâéêíóôõúüç; ", "ÁÀÃÂÉÊÍÓÔÕÚÜÇ"); $p = strtoupper($p); return $p; } /* LOWERCASE RÁPIDO*/ function lower($p){ $p = strtr($p, "ÁÀÃÂÉÊÍÓÔÕÚÜÇ", "áàãâéêíóôõúüç; "); $p = strtolower($p); return $p; } function youtubeID($url) { $pattern = '#^(?:https?://|//)?(?:www\.|m\.)?(?:youtu\.be/|youtube\.com/(?:embed/|v/|watch\?v=|watch\?.+&v=))([\w-]{11})(?![\w-])#'; preg_match($pattern, $url, $matches); return (isset($matches[1])) ? $matches[1] : false; } function youtubeDownImg($videoID, $dir) { $sizes = array("default", "hqdefault", "mqdefault", "sddefault", "maxresdefault"); foreach($sizes as $key) { copy("http://img.youtube.com/vi/$videoID/$key.jpg", $dir."yt_".$key."_".$videoID.".jpg"); } } function vimeoID($url, $option) { $content = file_get_contents("http://vimeo.com/api/oembed.json?url=$url"); $json = json_decode($content); if($json->$option == true) { return $json->$option; } else { return false; } /* { "type": "video", "version": "1.0", "provider_name": "Vimeo", "provider_url": "http://vimeo.com/", "title": "Danny MacAskill - \"Way Back Home\"", "author_name": "Dave Sowerby", "author_url": "http://vimeo.com/tdave", "is_plus": "1", "html": "