0) return substr($PHP_SELF, 0, strlen($PHP_SELF) - strlen($paths[count($paths) - 1]) - 1); die("PHP_SELF é inválido: " + $PHP_SELF); } function absurl($localUrl, $w_host = false, $https = false) { global $FW_FRONT_CONTROLLER; $config = $FW_FRONT_CONTROLLER->getConfig(); $contextPath = $config["contextPath"]; // ver se $$localUrl comeca com /, se sim, tratar if(strpos($localUrl, "/") != 0) { $localUrl = "/$localUrl"; } if($w_host) { $hostDoRequest = $_SERVER['HTTP_HOST']; if(isset($config["hostReplace"])) { foreach ($config["hostReplace"] as $hostFrom => $hostTo) { if($hostFrom == $hostDoRequest) $hostDoRequest = $hostTo; } } $host = "http" . ($https ? "s" : "") . "://" . $hostDoRequest; } else { $host = ''; } return is_null($localUrl) ? "$host$localUrl" : "$host$contextPath$localUrl"; } function dbNow() { return date(DB_TIMESTAMP_PATTERN); } function dbToday() { return date(DB_DATE_PATTERN); } function userNow() { return date(USER_TIMESTAMP_PATTERN); } function userToday() { return date(USER_DATE_PATTERN); } function toDbDate($slashDate) { if(empty($slashDate)) { return null; } list($dia, $mes, $ano) = split('\/', $slashDate); return "$ano-$mes-$dia"; } function toDbCurrency($userCurrency) { if (empty($userCurrency)) return null; return str_replace(',', '.', str_replace('.', '', $userCurrency)); } function toUserCurrency($dbCurrency, $casasDecimais = 2) { return number_format($dbCurrency, $casasDecimais, ',', '.'); } function toUserPercent($dbCurrency) { if ($dbCurrency - intval($dbCurrency) == 0) return number_format($dbCurrency, 0); return number_format($dbCurrency, 2, ',', '.'); } function toUserBoolean($dbBoolean) { return $dbBoolean ? "sim" : "não"; } function normalizeUserCurrency($value) { return toUserCurrency(toDbCurrency($value)); } function toDbHour($hour) { // nada a fazer? return $hour; } function toUserSexo($mOuF) { if($mOuF == 'f' || $mOuF == 'F') return "feminino"; if($mOuF == 'm' || $mOuF == 'M') return "masculino"; return "?"; } function toUserDate($dashDate, $wo_day=false) { if(empty($dashDate)) { return ""; } list($data, $hora) = explode(" ", $dashDate); list($ano, $mes, $dia) = split('-', $data); if (!$wo_day) return "$dia/$mes/$ano"; else return "$mes/$ano"; } function toUserNomeMes($numeroMes) { switch ($numeroMes) { case 1: return "Janeiro"; case 2: return "Fevereiro"; case 3: return "Março"; case 4: return "Abril"; case 5: return "Maio"; case 6: return "Junho"; case 7: return "Julho"; case 8: return "Agosto"; case 9: return "Setembro"; case 10: return "Outubro"; case 11: return "Novembro"; case 12: return "Dezembro"; } return "?"; } function toUserDateTime($mysqlDateTime) { if(empty($mysqlDateTime)) { return ""; } list($data, $hora) = split(' ', $mysqlDateTime); list($ano, $mes, $dia) = split('-', $data); if (empty($hora)) $hora = "00:00:00"; return "$dia/$mes/$ano $hora"; } function toUserDateTimeNoSec($mysqlDateTime) { if(empty($mysqlDateTime)) { return ""; } list($data, $hora) = split(' ', $mysqlDateTime); list($ano, $mes, $dia) = split('-', $data); list($h, $i, $s) = split(':', $hora); return "$dia/$mes/$ano $h:$i"; } function toDbDateTime($userDateTime) { if(empty($userDateTime)) { return NULL; } list($data, $hora) = split(' ', $userDateTime); list($dia, $mes, $ano) = split('/', $data); return "$ano-" . str_pad($mes, 2, "0", STR_PAD_LEFT) . "-" . str_pad($dia, 2, "0", STR_PAD_LEFT) . " $hora"; } function toUserNoYearDate($dashDate) { if(empty($dashDate)) { return ""; } list($ano, $mes, $dia) = split('-', $dashDate); // TODO por zeros return "$dia/$mes"; } function toUserDay($dashDate) { if(empty($dashDate)) { return ""; } list($ano, $mes, $dia) = split('-', $dashDate); // TODO por zeros return $dia; } function toUserHour($fullHour) { if(empty($fullHour)) { return ""; } list($hora, $minuto, $segundo) = split(':', $fullHour); return "$hora:$minuto"; } function toUserCpf($cpfSoNumeros) { if(empty($cpfSoNumeros)) { return ""; } $userCpf = ""; $cpfSoNumeros = "00000000000000$cpfSoNumeros"; $len = strlen($cpfSoNumeros); for ($i = $len - 1; $i >= 0 ; $i--) { if($i == $len - 3) { $userCpf = "-$userCpf"; } if($i == $len - 6 || $i == $len - 9 || $i == $len - 12) { $userCpf = ".$userCpf"; } $userCpf = "${cpfSoNumeros[$i]}$userCpf"; } return substr($userCpf, strlen($userCpf) - 14); } function toUserCnpj($cnpjSoNumeros) { if(empty($cnpjSoNumeros)) { return ""; } $userCnpj = ""; $cnpjSoNumeros = "000000000000000000$cnpjSoNumeros"; $len = strlen($cnpjSoNumeros); for ($i = $len - 1; $i >= 0 ; $i--) { if($i == $len - 3) { $userCnpj = "-$userCnpj"; } if($i == $len - 7) { $userCnpj = "/$userCnpj"; } if($i == $len - 10 || $i == $len - 13) { $userCnpj = ".$userCnpj"; } $userCnpj = "${cnpjSoNumeros[$i]}$userCnpj"; } return substr($userCnpj, strlen($userCnpj) - 18); } function toDbCpf($cpfComOuSemPontos) { if(empty($cpfComOuSemPontos)) { return ""; } return str_replace("-", "", str_replace(".", "", $cpfComOuSemPontos)); } function toDbCnpj($cnpjComOuSemPontos) { if(empty($cnpjComOuSemPontos)) { return ""; } return str_replace("-", "", str_replace(".", "", str_replace("/", "", $cnpjComOuSemPontos))); } function toDbCep($cepComOuSemIfem) { if(empty($cepComOuSemIfem)) { return ""; } return str_replace("-", "", $cepComOuSemIfem); } function toUserCep($cepSoNumeros) { if(empty($cepSoNumeros)) { return ""; } $userCep = ""; $cepSoNumeros = "000000000$cepSoNumeros"; $len = strlen($cepSoNumeros); for ($i = $len - 1; $i >= 0 ; $i--) { if($i == $len - 4) { $userCep = "-$userCep"; } $userCep = "${cepSoNumeros[$i]}$userCep"; } return substr($userCep, strlen($userCep) - 9); } function toDbPhone($phoneComOuSemMascara) { if(empty($phoneComOuSemMascara)) { return null; } $phoneComOuSemMascara = str_replace("(", "", $phoneComOuSemMascara); $phoneComOuSemMascara = str_replace(")", "", $phoneComOuSemMascara); $phoneComOuSemMascara = str_replace(" ", "", $phoneComOuSemMascara); $phoneComOuSemMascara = str_replace("-", "", $phoneComOuSemMascara); return $phoneComOuSemMascara; } function toDbAbsUrl($absurl) { return str_replace(HOST_ABS_URL_SITE, STR_CONT_ABS_URL, $absurl); } function toUserAbsUrl($absurl) { return str_replace(STR_CONT_ABS_URL, HOST_ABS_URL_SITE, $absurl); } function nvl($valor, $stringSeNulo = '') { return $valor ? $valor : $stringSeNulo; } function toUserPhone($phoneSoNumeros) { if(empty($phoneSoNumeros)) { return ""; } $userPhone = ""; $phoneSoNumeros = "00000000000000$phoneSoNumeros"; $len = strlen($phoneSoNumeros); for ($i = $len - 1; $i >= 0 ; $i--) { if($i == $len - 5) { $userPhone = "-$userPhone"; } if($i == $len - 8) { $userPhone = ") $userPhone"; } if($i == $len - 11) { $userPhone = "($userPhone"; } $userPhone = "${phoneSoNumeros[$i]}$userPhone"; } return substr($userPhone, strlen($userPhone) - 14); } function senhaAleatoria($tipo="E N N L N L N L L E") { $tipo = explode(" ", $tipo); $padrao_letras = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|X|W|Y|Z|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|x|w|y|z"; $padrao_numeros = "0|1|2|3|4|5|6|7|8|9"; $padrao_esp = "*|$|%|@|#|&|*|+|=|-"; $array_letras = explode("|", $padrao_letras); $array_numeros = explode("|", $padrao_numeros); $array_esp = explode("|", $padrao_esp); $senha = ""; for ($i=0; $iopen($arquivo)) { $zip->extractTo($dir); $zip->close(); if ($del_zip) unlink($arquivo); } } } } function urlencodeArray($arr) { if (!empty($arr) && is_array($arr)) { foreach ($arr as $key => $value) { $arr[$key] = urlencode($value); } return $arr; } return null; } // Valida de data Inicial é menor que data Final // Enviar datas no formato dd/mm/aaaa h:m:s function validateIntervaloData($dataInicial, $dataFinal) { if (!empty($dataInicial) && !empty($dataFinal)) { list($data_i,$hora_i) = explode(" ", $dataInicial); list($data_f,$hora_f) = explode(" ", $dataFinal); list($dia_i,$mes_i,$ano_i) = split("[/.-]", $data_i); if (empty($hora_i)) list($hora_i,$minuto_i,$segundo_i) = array(0,0,0); else list($hora_i,$minuto_i,$segundo_i) = split(":", $hora_i); list($dia_f,$mes_f,$ano_f) = split("[/.-]", $data_f); if (empty($hora_f)) list($hora_f,$minuto_f,$segundo_f) = array(0,0,0); else list($hora_f,$minuto_f,$segundo_f) = split(":", $hora_f); if (mktime($hora_i,$minuto_i,$segundo_i,$mes_i,$dia_i,$ano_i) > mktime($hora_f,$minuto_f,$segundo_f,$mes_f,$dia_f,$ano_f)) return false; else return true; } return true; } function he($s) { return htmlentities($s, ENT_QUOTES, CHAR_SET); } function debug($message) { // se DEBUG_ENABLED esta true no setup.php, esse debug sai no error_log do Apache if(defined("DEBUG_ENABLED") && DEBUG_ENABLED == true) error_log($message); } function toUserBytes($sizeInBytes, $casasDecimais = 0) { if($sizeInBytes > 1024 * 1024 * 1024) return number_format($sizeInBytes / (1024*1024), $casasDecimais, ",", ".") ." GB"; if($sizeInBytes > 1024 * 1024) return number_format($sizeInBytes / (1024*1024), $casasDecimais, ",", ".") ." MB"; else if($sizeInBytes > 1024) return number_format($sizeInBytes / 1024, $casasDecimais, ",", ".") . " KB"; return number_format($sizeInBytes, $casasDecimais, ",", ".") . " bytes"; } function toClearId($encodedId) { // return (base_convert($encodedId, 36, 10) - 4321) / 1234; return $encodedId; } function toEncodedId($clearId) { // return base_convert($clearId * 1234 + 4321, 10, 36); return $clearId; } function changeQueryStringParam($parName, $newParValue, $queryString = '', $parValuePattern = "[a-zA-Z0-9_]*") { if(empty($queryString)) $queryString = $_SERVER['QUERY_STRING']; // remover url rewrite das actions $queryString = ereg_replace('(ac|ns|op|lb)=[a-zA-Z\-]*(\&|$)', "", $queryString); // ter certeza que alguns parametros estao (isso é necessário para os permlinks // onde o parametro é inserido no request mas nao esta na queryString) $nomesParametrosComuns = array('c', 'q', 'id', 'p'); foreach ($nomesParametrosComuns as $nomeParComum) { if(isset($_REQUEST[$nomeParComum]) && !empty($_REQUEST[$nomeParComum])) { $queryString = replaceQueryStringParam( $nomeParComum, $_REQUEST[$nomeParComum], $queryString, $parValuePattern); } } // finalmente, botar o valor novo no parametro return replaceQueryStringParam($parName, $newParValue, $queryString, $parValuePattern); } function replaceQueryStringParam($parName, $newParValue, $queryString, $parValuePattern) { $pos = strpos($queryString, "&$parName="); if($pos === false) { $pos = strpos($queryString, "$parName="); if($pos != 0) // so vale aqui se for a primeira $pos = false; } if($pos === false) { //echo "NAOACHOU:$params|&$parName=|"; if(empty($queryString)) $queryString = "$parName=$newParValue"; else $queryString .= "&$parName=$newParValue"; } else { $patt = "(^|\&)$parName={$parValuePattern}(\&|$)"; $queryString = ereg_replace($patt, "\\1$parName=$newParValue\\2", $queryString); } return $queryString; } function strtolower_utf8($string){ $convert_to = array( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "ø", "ù", "ú", "û", "ü", "ý", "а", "б", "в", "г", "д", "е", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы", "ь", "э", "ю", "я" ); $convert_from = array( "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ъ", "Ь", "Э", "Ю", "Я" ); return str_replace($convert_from, $convert_to, $string); } function toStringParaPermLink($s) { // limpar acentos $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ'; $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr'; $s = utf8_decode($s); $s = strtr($s, utf8_decode($a), $b); $s = utf8_encode($s); // substitui tudo que nao é letra ou numero por - $ultimoFoiHifen = true; $novaS = ''; for ($i=0; $i < strlen($s);$i++){ $c = $s[$i]; if(('a' <= $c && $c <= 'z') || ('A' <= $c && $c <= 'Z') || ('0' <= $c && $c <= '9')) { $novaS .= $c; $ultimoFoiHifen = false; } else { if(!$ultimoFoiHifen) { $novaS .= '-'; $ultimoFoiHifen = true; } } } // tira os hifens das pontas e // retorna em minusculas return strtolower(trim($novaS, "-")); } function unZipDir($dir, $del_zip = true) { $path = $dir . "/*.zip"; $path = str_replace("//","/",$path); if ($objs = glob($path)) { foreach ($objs as $arquivo) { $zip = new ZipArchive; if ($zip->open($arquivo)) { $zip->extractTo($dir); $zip->close(); if ($del_zip) unlink($arquivo); } } if (glob($path) && $del_zip) unZipDir($dir, $del_zip); } } function createZipFile($path, $fileName, $pattern = "*") { $zip = new ZipArchive; if ($zip->open($path . $fileName, ZIPARCHIVE::CREATE) === true) { if ($objs = glob($path.$pattern)) { foreach ($objs as $arquivo) { $zip->addFile($arquivo, substr( $arquivo, ( strrpos( $arquivo, "/" ) +1 ) )); } } } $zip->close(); return true; } function getTinyUrl($longUrl) { $gdUrl = "http://is.gd/api.php?longurl=" . urlencode($longUrl); @$linhas = file($gdUrl); if(empty($linhas)) { $tinyUrl = $longUrl; } else { $tinyUrl = trim(join($linhas)); } return $tinyUrl; } ?>Banco de dados inacessível: exception 'ADODB_Exception' with message 'mysql error: [2000: mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file] in CONNECT(mysql.golaco.com.br, 'golac1br', '****', golac1br) ' in /var/www/vhosts/golaco.com.br/httpdocs/adodb/adodb-exceptions.inc.php:78 Stack trace: #0 /var/www/vhosts/golaco.com.br/httpdocs/adodb/adodb.inc.php(434): adodb_throw('mysql', 'CONNECT', 2000, 'mysqlnd cannot ...', 'mysql.golaco.co...', 'golac1br', Object(ADODB_mysql)) #1 /var/www/vhosts/golaco.com.br/httpdocs/adodb/adodb.inc.php(4204): ADOConnection->Connect('mysql.golaco.co...', 'golac1br', '16gola45', 'golac1br') #2 /var/www/vhosts/golaco.com.br/httpdocs/adodb/adodb.inc.php(4072): ADONewConnection('mysql://golac1b...') #3 /var/www/vhosts/golaco.com.br/httpdocs/config/setup.php(16): NewADOConnection('mysql://golac1b...') #4 /var/www/vhosts/golaco.com.br/httpdocs/index.php(3): include('/var/www/vhosts...') #5 {main}