Prueba de logs

parent 6cfb18c2
<?php
namespace AppBundle\Lib;
/**
* Encripta en md5
*
* @author Luis Arcos
*/
class Crypt {
public $key = NULL;
function Crypt() {
}
function AES_Encode($plain_text) {
return base64_encode(openssl_encrypt($plain_text, "aes-256-cbc", $this->key, true, str_repeat(chr(0), 16)));
}
function AES_Decode($base64_text) {
return openssl_decrypt(base64_decode($base64_text), "aes-256-cbc", $this->key, true, str_repeat(chr(0), 16));
}
}
<?php
namespace AppBundle\Lib;
/**
* Clase que contiene las definiciones de los documentos
* a generar en el sistema.
*
* @author cdiaz
*/
class Documentos {
public static function despacho(Array $orden, String $url, \AppBundle\Model\Empresa $empresa) {
$doctype = "<!DOCTYPE html> <html xmlns='http://www.w3.org/1999/xhtml'>";
$base_css = "#sidebar{position:absolute;top:0;left:0;bottom:0;width:250px;padding:0;margin:0;overflow:auto}#page-container{position:absolute;top:0;left:0;margin:0;padding:0;border:0}@media screen{#sidebar.opened+#page-container{left:250px}#page-container{bottom:0;right:0;overflow:auto}.loading-indicator{display:none}.loading-indicator.active{display:block;position:absolute;width:64px;height:64px;top:50%;left:50%;margin-top:-32px;margin-left:-32px}.loading-indicator img{position:absolute;top:0;left:0;bottom:0;right:0}}@media print{@page{margin:0}html{margin:0}body{margin:0;-webkit-print-color-adjust:exact}#sidebar{display:none}#page-container{width:auto;height:auto;overflow:visible;background-color:transparent}.d{display:none}}.pf{position:relative;background-color:white;overflow:hidden;margin:0;border:0}.pc{position:absolute;border:0;padding:0;margin:0;top:0;left:0;width:100%;height:100%;overflow:hidden;display:block;transform-origin:0 0;-ms-transform-origin:0 0;-webkit-transform-origin:0 0}.pc.opened{display:block}.bf{position:absolute;border:0;margin:0;top:0;bottom:0;width:100%;height:100%;-ms-user-select:none;-moz-user-select:none;-webkit-user-select:none;user-select:none}.bi{position:absolute;border:0;margin:0;-ms-user-select:none;-moz-user-select:none;-webkit-user-select:none;user-select:none}@media print{.pf{margin:0;box-shadow:none;page-break-after:always;page-break-inside:avoid}@-moz-document url-prefix(){.pf{overflow:visible;border:1px solid #fff}.pc{overflow:visible}}}.c{position:absolute;border:0;padding:0;margin:0;overflow:hidden;display:block}.t{position:absolute;white-space:pre;font-size:1px;transform-origin:0 100%;-ms-transform-origin:0 100%;-webkit-transform-origin:0 100%;unicode-bidi:bidi-override;-moz-font-feature-settings:'liga' 0}.t:after{content:''}.t:before{content:'';display:inline-block}.t span{position:relative;unicode-bidi:bidi-override}._{display:inline-block;color:transparent;z-index:-1}::selection{background:rgba(127,255,255,0.4)}::-moz-selection{background:rgba(127,255,255,0.4)}.pi{display:none}.d{position:absolute;transform-origin:0 100%;-ms-transform-origin:0 100%;-webkit-transform-origin:0 100%}.it{border:0;background-color:rgba(255,255,255,0.0)}.ir:hover{cursor:pointer}";
$fancy_css = "@keyframes fadein{from{opacity:0}to{opacity:1}}@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes swing{0{transform:rotate(0)}10%{transform:rotate(0)}90%{transform:rotate(720deg)}100%{transform:rotate(720deg)}}@-webkit-keyframes swing{0{-webkit-transform:rotate(0)}10%{-webkit-transform:rotate(0)}90%{-webkit-transform:rotate(720deg)}100%{-webkit-transform:rotate(720deg)}}@media screen{#sidebar{background-color:#2f3236;background-image:url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPgo8cmVjdCB3aWR0aD0iNCIgaGVpZ2h0PSI0IiBmaWxsPSIjNDAzYzNmIj48L3JlY3Q+CjxwYXRoIGQ9Ik0wIDBMNCA0Wk00IDBMMCA0WiIgc3Ryb2tlLXdpZHRoPSIxIiBzdHJva2U9IiMxZTI5MmQiPjwvcGF0aD4KPC9zdmc+')}#outline{font-family:Georgia,Times,'Times New Roman',serif;font-size:13px;margin:2em 1em}#outline ul{padding:0}#outline li{list-style-type:none;margin:1em 0}#outline li>ul{margin-left:1em}#outline a,#outline a:visited,#outline a:hover,#outline a:active{line-height:1.2;color:#e8e8e8;text-overflow:ellipsis;white-space:nowrap;text-decoration:none;display:block;overflow:hidden;outline:0}#outline a:hover{color:#0cf}#page-container{background-color:#9e9e9e;background-image:url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1IiBoZWlnaHQ9IjUiPgo8cmVjdCB3aWR0aD0iNSIgaGVpZ2h0PSI1IiBmaWxsPSIjOWU5ZTllIj48L3JlY3Q+CjxwYXRoIGQ9Ik0wIDVMNSAwWk02IDRMNCA2Wk0tMSAxTDEgLTFaIiBzdHJva2U9IiM4ODgiIHN0cm9rZS13aWR0aD0iMSI+PC9wYXRoPgo8L3N2Zz4=');-webkit-transition:left 500ms;transition:left 500ms}.pf{margin:13px auto;box-shadow:1px 1px 3px 1px #333;border-collapse:separate}.pc.opened{-webkit-animation:fadein 100ms;animation:fadein 100ms}.loading-indicator.active{-webkit-animation:swing 1.5s ease-in-out .01s infinite alternate none;animation:swing 1.5s ease-in-out .01s infinite alternate none}.checked{background:no-repeat url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3goQDSYgDiGofgAAAslJREFUOMvtlM9LFGEYx7/vvOPM6ywuuyPFihWFBUsdNnA6KLIh+QPx4KWExULdHQ/9A9EfUodYmATDYg/iRewQzklFWxcEBcGgEplDkDtI6sw4PzrIbrOuedBb9MALD7zv+3m+z4/3Bf7bZS2bzQIAcrmcMDExcTeXy10DAFVVAQDksgFUVZ1ljD3yfd+0LOuFpmnvVVW9GHhkZAQcxwkNDQ2FSCQyRMgJxnVdy7KstKZpn7nwha6urqqfTqfPBAJAuVymlNLXoigOhfd5nmeiKL5TVTV+lmIKwAOA7u5u6Lped2BsbOwjY6yf4zgQQkAIAcedaPR9H67r3uYBQFEUFItFtLe332lpaVkUBOHK3t5eRtf1DwAwODiIubk5DA8PM8bYW1EU+wEgCIJqsCAIQAiB7/u253k2BQDDMJBKpa4mEon5eDx+UxAESJL0uK2t7XosFlvSdf0QAEmlUnlRFJ9Waho2Qghc1/U9z3uWz+eX+Wr+lL6SZfleEAQIggA8z6OpqSknimIvYyybSCReMsZ6TislhCAIAti2Dc/zejVNWwCAavN8339j27YbTg0AGGM3WltbP4WhlRWq6Q/btrs1TVsYHx+vNgqKoqBUKn2NRqPFxsbGJzzP05puUlpt0ukyOI6z7zjOwNTU1OLo6CgmJyf/gA3DgKIoWF1d/cIY24/FYgOU0pp0z/Ityzo8Pj5OTk9PbwHA+vp6zWghDC+VSiuRSOQgGo32UErJ38CO42wdHR09LBQK3zKZDDY2NupmFmF4R0cHVlZWlmRZ/iVJUn9FeWWcCCE4ODjYtG27Z2Zm5juAOmgdGAB2d3cBADs7O8uSJN2SZfl+WKlpmpumaT6Yn58vn/fs6XmbhmHMNjc3tzDGFI7jYJrm5vb29sDa2trPC/9aiqJUy5pOp4f6+vqeJ5PJBAB0dnZe/t8NBajx/z37Df5OGX8d13xzAAAAAElFTkSuQmCC)}}";
$main_css = " .ff0{font-family:sans-serif;visibility:hidden;}
@font-face{font-family:ff1;src:url(f1.woff)format('woff');}.ff1{font-family:ff1;line-height:1.035645;font-style:normal;font-weight:normal;visibility:visible;}
@font-face{font-family:ff2;src:url(f2.woff)format('woff');}.ff2{font-family:ff2;line-height:1.035645;font-style:normal;font-weight:normal;visibility:visible;}
.m0{transform:matrix(0.250000,0.000000,0.000000,0.250000,0,0);-ms-transform:matrix(0.250000,0.000000,0.000000,0.250000,0,0);-webkit-transform:matrix(0.250000,0.000000,0.000000,0.250000,0,0);}
.v0{vertical-align:0.000000px;}
.ls0{letter-spacing:0.000000px;}
.sc_{text-shadow:none;}
.sc0{text-shadow:-0.015em 0 transparent,0 0.015em transparent,0.015em 0 transparent,0 -0.015em transparent;}
@media screen and (-webkit-min-device-pixel-ratio:0){
.sc_{-webkit-text-stroke:0px transparent;}
.sc0{-webkit-text-stroke:0.015em transparent;text-shadow:none;}
}
.ws0{word-spacing:0.000000px;}
._1{width:513.428000px;}
._3{width:554.092000px;}
._4{width:616.648000px;}
._6{width:679.612000px;}
._5{width:695.272000px;}
._2{width:714.496000px;}
._0{width:907.548000px;}
.fc2{color:rgb(255,255,255);}
.fc1{color:rgb(0,0,0);}
.fc0{color:rgb(85,85,85);}
.fs0{font-size:36.000000px;}
.fs1{font-size:66.000000px;}
.y4{bottom:23.404000px;}
.y12{bottom:418.036000px;}
.y0{bottom:431.000000px;}
.y11{bottom:439.006000px;}
.y10{bottom:459.976000px;}
.yf{bottom:500.446000px;}
.ye{bottom:519.916000px;}
.yd{bottom:550.636000px;}
.yc{bottom:562.606000px;}
.yb{bottom:574.576000px;}
.ya{bottom:586.546000px;}
.y9{bottom:598.516000px;}
.y8{bottom:610.486000px;}
.y7{bottom:622.456000px;}
.y6{bottom:634.426000px;}
.y5{bottom:665.940000px;}
.y3{bottom:752.601000px;}
.y2{bottom:764.571000px;}
.y1{bottom:776.541000px;}
.h2{height:28.792969px;}
.h3{height:52.787109px;}
.h1{height:355.000000px;}
.h0{height:841.890000px;}
.w1{width:475.500000px;}
.w0{width:595.280000px;}
.x0{left:60.000000px;}
.x5{left:63.750000px;}
.x6{left:301.390000px;}
.x9{left:451.376000px;}
.x8{left:467.819000px;}
.x1{left:477.377000px;}
.x2{left:485.189000px;}
.x7{left:491.201000px;}
.x3{left:495.827000px;}
.x4{left:504.461000px;}
.xa{left:516.086000px;}
@media print{
.v0{vertical-align:0.000000pt;}
.ls0{letter-spacing:0.000000pt;}
.ws0{word-spacing:0.000000pt;}
._1{width:684.570667pt;}
._3{width:738.789333pt;}
._4{width:822.197333pt;}
._6{width:906.149333pt;}
._5{width:927.029333pt;}
._2{width:952.661333pt;}
._0{width:1210.064000pt;}
.fs0{font-size:48.000000pt;}
.fs1{font-size:88.000000pt;}
.y4{bottom:31.205333pt;}
.y12{bottom:557.381333pt;}
.y0{bottom:574.666667pt;}
.y11{bottom:585.341333pt;}
.y10{bottom:613.301333pt;}
.yf{bottom:667.261333pt;}
.ye{bottom:693.221333pt;}
.yd{bottom:734.181333pt;}
.yc{bottom:750.141333pt;}
.yb{bottom:766.101333pt;}
.ya{bottom:782.061333pt;}
.y9{bottom:798.021333pt;}
.y8{bottom:813.981333pt;}
.y7{bottom:829.941333pt;}
.y6{bottom:845.901333pt;}
.y5{bottom:887.920000pt;}
.y3{bottom:1003.468000pt;}
.y2{bottom:1019.428000pt;}
.y1{bottom:1035.388000pt;}
.h2{height:38.390625pt;}
.h3{height:70.382812pt;}
.h1{height:473.333333pt;}
.h0{height:1122.520000pt;}
.w1{width:634.000000pt;}
.w0{width:793.706667pt;}
.x0{left:80.000000pt;}
.x5{left:85.000000pt;}
.x6{left:401.853333pt;}
.x9{left:601.834667pt;}
.x8{left:623.758667pt;}
.x1{left:636.502667pt;}
.x2{left:646.918667pt;}
.x7{left:654.934667pt;}
.x3{left:661.102667pt;}
.x4{left:672.614667pt;}
.xa{left:688.114667pt;}
}
";
$css = "$base_css $fancy_css $main_css";
$meta = "<meta charset='utf-8'/> <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'/>";
$head = "$doctype $meta $css";
$body = "<body>
<div id='sidebar'>
<div id='outline'>
</div>
</div>
<div id='page-container'>
<div id='pf1' class='pf w0 h0' data-page-no='1'><div class='pc pc1 w0 h0'><img class='bi x0 y0 w1 h1' alt='' src='bg1.png'/><div class='t m0 x1 h2 y1 ff1 fs0 fc0 sc0 ls0 ws0'>Balmoral 163</div><div class='t m0 x2 h2 y2 ff1 fs0 fc0 sc0 ls0 ws0'>Las Condes</div><div class='t m0 x3 h2 y3 ff1 fs0 fc0 sc0 ls0 ws0'>Santiago</div><div class='t m0 x4 h2 y4 ff1 fs0 fc0 sc0 ls0 ws0'>1 de 1</div><div class='t m0 x5 h3 y5 ff2 fs1 fc1 sc0 ls0 ws0'>Factura</div><div class='t m0 x5 h2 y6 ff1 fs0 fc0 sc0 ls0 ws0'>Factura nº: 00653-2020</div><div class='t m0 x5 h2 y7 ff1 fs0 fc0 sc0 ls0 ws0'>Fecha de la factura: 1111 [.31-] 0303 [.-] 20202020</div><div class='t m0 x5 h2 y8 ff1 fs0 fc0 sc0 ls0 ws0'>23:19:14</div><div class='t m0 x5 h2 y9 ff1 fs0 fc0 sc0 ls0 ws0'>Fecha del pedido: 1212 [.31-] 0303 [.-] 20202020</div><div class='t m0 x5 h2 ya ff1 fs0 fc0 sc0 ls0 ws0'>02:17:41</div><div class='t m0 x5 h2 yb ff1 fs0 fc0 sc0 ls0 ws0'>Pedido número: 100080265</div><div class='t m0 x5 h2 yc ff1 fs0 fc0 sc0 ls0 ws0'>Método de pago: Webpay Crédito</div><div class='t m0 x5 h2 yd ff1 fs0 fc0 sc0 ls0 ws0'>Método de envío: Precio fijo</div><div class='t m0 x6 h2 y6 ff2 fs0 fc0 sc0 ls0 ws0'>Facturar a:</div><div class='t m0 x6 h2 y7 ff1 fs0 fc0 sc0 ls0 ws0'>Viviana Hojman</div><div class='t m0 x6 h2 y8 ff1 fs0 fc0 sc0 ls0 ws0'>Domingo Bondi 990</div><div class='t m0 x6 h2 y9 ff1 fs0 fc0 sc0 ls0 ws0'>203</div><div class='t m0 x6 h2 ya ff1 fs0 fc0 sc0 ls0 ws0'>Las Condes</div><div class='t m0 x7 h2 y6 ff2 fs0 fc0 sc0 ls0 ws0'>Enviar a:</div><div class='t m0 x8 h2 y7 ff1 fs0 fc0 sc0 ls0 ws0'>Viviana Hojman</div><div class='t m0 x9 h2 y8 ff1 fs0 fc0 sc0 ls0 ws0'>Domingo Bondi 990</div><div class='t m0 xa h2 y9 ff1 fs0 fc0 sc0 ls0 ws0'>203</div><div class='t m0 x5 h2 ye ff2 fs0 fc2 sc0 ls0 ws0'>Decripción<span class='_ _0'> </span>Cantidad<span class='_ _1'> </span>Total</div><div class='t m0 x5 h2 yf ff1 fs0 fc0 sc0 ls0 ws0'>POLERA PIQUE M/C CLG - 10<span class='_ _2'> </span>4<span class='_ _3'> </span>$36400</div><div class='t m0 x6 h2 y10 ff2 fs0 fc0 sc0 ls0 ws0'>Subtotal:<span class='_ _4'> </span>$36400</div><div class='t m0 x6 h2 y11 ff2 fs0 fc0 sc0 ls0 ws0'>Envío:<span class='_ _5'> </span>$4000</div><div class='t m0 x6 h2 y12 ff2 fs0 fc0 sc0 ls0 ws0'>Total:<span class='_ _6'> </span>$40400</div></div><div class='pi' data-data='{'ctm':[1.000000,0.000000,0.000000,1.000000,0.000000,0.000000]}'></div></div>
</div>
<div class='loading-indicator'>
</div>
</body>";
$footer = "";
$html = "$head $body $footer";
return $html;
}
}
<?php
namespace AppBundle\Lib;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use AppBundle\Model\ParametroConfiguracionQuery;
use AppBundle\Model\ParametroServicioQuery;
/**
* Description of Utiles
*
* @author Luis Arcos
*/
class Utiles {
public static function setLog($type = '', $archivo = 'web') {
$logFechaNombre = $archivo . "_" . date("Ymd") . ".log";
$logPath = __DIR__ . '/../../../app/logs/' . $logFechaNombre;
$log = new Logger($type);
$handler = new StreamHandler($logPath, Logger::DEBUG);
$handler->setFormatter(new LineFormatter(null, null, true, true));
$log->pushHandler($handler);
return $log;
}
public static function isMsisdn2($msisdn) {
// if(preg_match("/^[0-9]+$/", $msisdn) && strlen($msisdn) == 11)
if (is_numeric($msisdn) && strlen($msisdn) == 9)
return true;
else
return false;
}
public static function isMsisdn($msisdn) {
// if(preg_match("/^[0-9]+$/", $msisdn) && strlen($msisdn) == 11)
if (is_numeric($msisdn) && strlen($msisdn) == 11)
return true;
else
return false;
}
/**
* Recibe un String en formato 'dd/mm/yyyy'
* o con un separador presonalizado pero en orden dd mm yyyy
* y retorna true si es una fecha valida.
*
* @param String $fecha
* @return Boolean
*/
public static function esFecha($fecha, $separador = "/") {
try {
list($dd, $mm, $aa) = explode($separador, $fecha);
} catch (\Exception $exc) {
return FALSE;
}
return checkdate($mm, $dd, $aa);
}
/**
* Retorna la ruta hasta 'entelcorproaming/www/sf2/web'
*
* @return String
*/
public static function getWebRoot() {
return $pathRoot = __DIR__ . '/../../../web';
}
/**
* Valida que msisdn solo contenga numeros y devuelve el nro en formato "internacional"
* retorna false de lo contrario
* @param type $msisdn
* @return boolean
*/
public static function formatMsisdn($msisdn) {
if (preg_match("/^[0-9]+$/", $msisdn) && strlen($msisdn) == 8) {
// if(is_numeric($msisdn) && strlen($msisdn) == 8){
return '569' . $msisdn;
}
return false;
}
public static function formatMsisdnSpecial($msisdn) {
if (preg_match("/^[0-9]+$/", $msisdn) && strlen($msisdn) == 11) {
// if(is_numeric($msisdn) && strlen($msisdn) == 8){
return $msisdn;
}
return false;
}
/**
* retorna la versión de IE de acuerdo al UserAgent pasado como parametro.
*
*
* @param type $userAgent
* @return string
*/
public static function getVersionOfIe($userAgent) {
$ub = "MSIE";
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $userAgent, $matches)) {
// we have no matching number just continue
}
// see how many we have
$i = count($matches['browser']);
if ($i != 1) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if (strripos($userAgent, "Version") < strripos($userAgent, $ub)) {
$version = $matches['version'][0];
} else {
$version = $matches['version'][1];
}
} else {
$version = $matches['version'][0];
}
// check if we have a number
if ($version == null || $version == "") {
$version = "?";
}
return $version;
}
public static function limpiarCaracteresEspeciales($string) {
$string = htmlentities($string);
//$string = preg_replace('/\&(.)[^;]*;/', '\\1', $string);
//$string = preg_replace('/[^a-zA-Z0-9\']/', '_', "There wouldn't be any");
//$stringfinal = preg_replace('/[^\p{L}\p{N}]/u', '', $string);
$stringfinal = preg_replace('/[^a-zA-Z0-9\']/', '', $string);
////$string = str_replace(' ', '', $string);
//$string = str_replace('@','',$string);
//$string = str_replace('&', '', $string);
//$string = str_replace('=','',$string);
return $stringfinal;
}
public static function getParametroConfiguracion($nombre) {
$str_valor = '';
$parametro = ParametroConfiguracionQuery::create()->findOneByPcoNombre($nombre);
if ($parametro)
$str_valor = $parametro->getPcoValor();
return $str_valor;
}
public static function getParametroServicio($nombre, $empresa) {
$str_valor = '';
$parametro = ParametroServicioQuery::create()->filterByEmpId($empresa)->findOneByPseNombre($nombre);
if ($parametro) {
$str_valor = $parametro->getPseValor();
}
return $str_valor;
}
/**
* Setea el valor del parametro de configuración 'tiempo_promedio_respuesta_asistentes'
*
* @param type $tiempo
*/
public static function setPromedioRespuesta($tiempo) {
ParametroConfiguracionQuery::create()
->filterByPcoNombre('tiempo_promedio_respuesta_asistentes')
->update(array('PcoValor' => $tiempo));
}
public static function setParametroConfiguracion($pcoNombre, $valor) {
ParametroConfiguracionQuery::create()
->filterByPcoNombre($pcoNombre)
->update(array('PcoValor' => $valor));
}
/**
* Retorna un array con los mails en BD que deben hacer seguimiento a las solicitudes emitidas por la plataforma
*
* @return array
*/
public static function getArrayMailsSeguimientoSolicitudes() {
$stringMails = self::getParametroConfiguracion('mails_seguimiento_solicitudes');
if ($stringMails != '') {
return explode(',', $stringMails);
}
return NULL;
}
/**
* Devuelve los valores de una sola columna del array de entrada
* descartando las otras keys
*
* @param array $array
* @param string $column_name
* @return array
*/
public static function array_column($array, $column_name) {
return array_map(function($element) use($column_name) {
return $element[$column_name];
}, $array);
}
/**
* cuenta el nro de digitos en un string dado
*
* @param string $str
* @return int
*/
public static function contarDigitosInString($str) {
return preg_match_all("/[0-9]/", $str);
}
/**
* Retorna una array con los MimeTypes de archivos considerados validos como CSVs
*
* @return array
*/
public static function getMimeTypesCsv() {
return array('application/vnd.ms-excel');
}
/**
* FUNCIÓN PARA VALIDAR CORREO ELECTRÓNICO, MEDIANTE USO DE EXPRESIÓN REGULAR.
* @param type $email
* @return int
*/
public static function validarCorreo($email = "") {
$expresion_regular_correo = "/^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i";
if (preg_match($expresion_regular_correo, $email)) {
return 1;
} else {
return 0;
}
}
/**
* Genera una password
* @param int $length largo de la cadena
* @return string
*/
public static function generarPassword($length = 8) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$count = mb_strlen($chars);
for ($i = 0, $result = ''; $i < $length; $i++) {
$index = rand(0, $count - 1);
$result .= mb_substr($chars, $index, 1);
}
return $result;
}
/**
* Retorna la ruta de instalación del proyecto
*
* @return String
*/
public static function getProjectRoot() {
return $pathRoot = __DIR__ . '/../../../';
}
/**
* Obtiene el dominio base de la url
* @param String $url
* @return type
*/
public static function getDomainFromUrl($url) {
$domain = "";
$parse = Utiles::parseUrlAll($url);
if (isset($parse['domain']))
$domain = $parse['domain'];
return $domain;
}
/**
* Obtiene el dominio base de la url
* @param String $url
* @return array host,domain,domainX
*/
public static function parseUrlAll($url) {
$url = substr($url, 0, 4) == 'http' ? $url : 'http://' . $url;
$d = parse_url($url);
$tmp = explode('.', $d['host']);
$n = count($tmp);
if ($n >= 2) {
if ($n == 4 || ($n == 3 && strlen($tmp[($n - 2)]) <= 3)) {
$d['domain'] = $tmp[($n - 3)] . "." . $tmp[($n - 2)] . "." . $tmp[($n - 1)];
$d['domainX'] = $tmp[($n - 3)];
} else {
$d['domain'] = $tmp[($n - 2)] . "." . $tmp[($n - 1)];
$d['domainX'] = $tmp[($n - 2)];
}
}
return $d;
}
public static function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
public static function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
/**
* Comprueba si el rut ingresado es valido
* @param string $rut RUT
* @return boolean
*/
public static function valida_rut($rut) {
if (!preg_match("/^[0-9.]+[-]?+[0-9kK]{1}/", $rut)) {
return false;
}
$rut = preg_replace('/[\.\-]/i', '', $rut);
$dv = substr($rut, -1);
$numero = substr($rut, 0, strlen($rut) - 1);
$i = 2;
$suma = 0;
foreach (array_reverse(str_split($numero)) as $v) {
if ($i == 8)
$i = 2;
$suma += $v * $i;
++$i;
}
$dvr = 11 - ($suma % 11);
if ($dvr == 11)
$dvr = 0;
if ($dvr == 10)
$dvr = 'K';
if ($dvr == strtoupper($dv))
return true;
else
return false;
}
/**
* Funcion retorna instancia de openfire
* @return OpenfireRestApi
*/
public static function getOpenfireInstance() {
$openfire = new OpenfireRestApi();
$openfire->host = self::getParametroConfiguracion('openfire_domain');
$openfire->port = self::getParametroConfiguracion('puerto_openfire');
$openfire->secret = self::getParametroConfiguracion('openfire_rest_api_secret_key');
return $openfire;
}
/* Valida si el json entrante es valido */
public static function validarJSON(String $json) {
$arrayResponse = array();
$result = json_decode($json, true);
switch (json_last_error()) {
case JSON_ERROR_NONE:
$error = ''; // JSON Válido
break;
case JSON_ERROR_DEPTH:
$error = 'Se ha superado la profundidad máxima de pila.';
break;
case JSON_ERROR_STATE_MISMATCH:
$error = 'JSON no válido o con formato incorrecto.';
break;
case JSON_ERROR_CTRL_CHAR:
$error = 'Error de carácter de control, posiblemente codificado incorrectamente';
break;
case JSON_ERROR_SYNTAX:
$error = 'Error de sintaxis, JSON mal formado.';
break;
// PHP >= 5.3.3
case JSON_ERROR_UTF8:
$error = 'Caracteres UTF-8 mal formados, posiblemente codificados incorrectamente.';
break;
// PHP >= 5.5.0
case JSON_ERROR_RECURSION:
$error = 'Una o más referencias recursivas en el valor a codificar.';
break;
// PHP >= 5.5.0
case JSON_ERROR_INF_OR_NAN:
$error = 'Uno o más valores NAN o INF en el valor a codificar.';
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$error = 'Se dio un valor de un tipo que no puede ser codificado.';
break;
default:
$error = 'Ocurrió un error JSON desconocido';
break;
}
if ($error !== '') {
array_push($arrayResponse, $error);
array_push($arrayResponse, $json);
} else {
array_push($arrayResponse, $error);
array_push($arrayResponse, $result);
}
return $arrayResponse;
}
public static function jsonFixer($json) {
$patterns = [];
/** garbage removal */
$patterns[0] = "/([\s:,\{}\[\]])\s*'([^:,\{}\[\]]*)'\s*([\s:,\{}\[\]])/"; //Find any character except colons, commas, curly and square brackets surrounded or not by spaces preceded and followed by spaces, colons, commas, curly or square brackets...
$patterns[1] = '/([^\s:,\{}\[\]]*)\{([^\s:,\{}\[\]]*)/'; //Find any left curly brackets surrounded or not by one or more of any character except spaces, colons, commas, curly and square brackets...
$patterns[2] = "/([^\s:,\{}\[\]]+)}/"; //Find any right curly brackets preceded by one or more of any character except spaces, colons, commas, curly and square brackets...
$patterns[3] = "/(}),\s*/"; //JSON.parse() doesn't allow trailing commas
/** reformatting */
$patterns[4] = '/([^\s:,\{}\[\]]+\s*)*[^\s:,\{}\[\]]+/'; //Find or not one or more of any character except spaces, colons, commas, curly and square brackets followed by one or more of any character except spaces, colons, commas, curly and square brackets...
$patterns[5] = '/["\']+([^"\':,\{}\[\]]*)["\']+/'; //Find one or more of quotation marks or/and apostrophes surrounding any character except colons, commas, curly and square brackets...
$patterns[6] = '/(")([^\s:,\{}\[\]]+)(")(\s+([^\s:,\{}\[\]]+))/'; //Find or not one or more of any character except spaces, colons, commas, curly and square brackets surrounded by quotation marks followed by one or more spaces and one or more of any character except spaces, colons, commas, curly and square brackets...
$patterns[7] = "/(')([^\s:,\{}\[\]]+)(')(\s+([^\s:,\{}\[\]]+))/"; //Find or not one or more of any character except spaces, colons, commas, curly and square brackets surrounded by apostrophes followed by one or more spaces and one or more of any character except spaces, colons, commas, curly and square brackets...
$patterns[8] = '/(})(")/'; //Find any right curly brackets followed by quotation marks...
$patterns[9] = '/,\s+(})/'; //Find any comma followed by one or more spaces and a right curly bracket...
$patterns[10] = '/\s+/'; //Find one or more spaces...
$patterns[11] = '/^\s+/'; //Find one or more spaces at start of string...
$replacements = [];
/** garbage removal */
$replacements[0] = '$1 "$2" $3'; //...and put quotation marks surrounded by spaces between them;
$replacements[1] = '$1 { $2'; //...and put spaces between them;
$replacements[2] = '$1 }'; //...and put a space between them;
$replacements[3] = '$1'; //...so, remove trailing commas of any right curly brackets;
/** reformatting */
$replacements[4] = '"$0"'; //...and put quotation marks surrounding them;
$replacements[5] = '"$1"'; //...and replace by single quotation marks;
$replacements[6] = '\\$1$2\\$3$4'; //...and add back slashes to its quotation marks;
$replacements[7] = '\\$1$2\\$3$4'; //...and add back slashes to its apostrophes;
$replacements[8] = '$1, $2'; //...and put a comma followed by a space character between them;
$replacements[9] = ' $1'; //...and replace by a space followed by a right curly bracket;
$replacements[10] = ' '; //...and replace by one space;
$replacements[11] = ''; //...and remove it.
$result = preg_replace($patterns, $replacements, $json);
return $result;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment