Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Mysql {
- var $host;
- var $user;
- var $pass;
- var $base;
- var $connect_id = 0;
- var $result_id;
- var $error;
- var $query;
- // privado: constructor //
- function Mysql($Host='', $User='', $Pass='', $Base='') {
- $this->host=$Host;
- $this->user=$User;
- $this->pass=$Pass;
- $this->base=$Base;
- }
- // Remuevo barras y las agrego //
- function arreglar($valor) {
- // Retiro barras
- if (get_magic_quotes_gpc()) {
- $valor = stripslashes($valor);
- }
- // Colocar comillas si no es entero
- if (!is_numeric($valor)) {
- $valor=mysql_real_escape_string($valor);
- }
- return "'$valor'";
- }
- // Para ejecutar querys a la base de datos ( se recomienda solo aplicar en parametros ) //
- function mysql_real_escape_array($t){
- return is_array($t) ? array_map('mysql_real_escape_array', $t) : trim($this->arreglar($t));
- }
- function separacionCampos($camposMostrar) {
- $campos="";
- for($i=0; $i < count($camposMostrar);$i++) {
- $nombre_campo=$camposMostrar[$i];
- if ( strlen($campos) == 0 ) { $campos=$nombre_campo; }
- else { $campos=$campos.",".$nombre_campo; }
- }
- return $campos;
- }
- function crearConsulta($tipo,$camposMostrar,$tabla,$camposDatos,$datosCampos) {
- $sql="";
- $campos1=$this->separacionCampos($camposMostrar);
- $campos2=$this->separacionCampos($camposDatos);
- // Updates or where //
- $camposWhere="";
- $camposUpdate="";
- $camposInsert="";
- for($i=0; $i < count($camposDatos);$i++) {
- $nombreCampo=$camposDatos[$i];
- $valorCampo='$datosCampos[$i]';
- $equivalencia=$nombreCampo."=".$valorCampo;
- if ( strlen($camposWhere) == 0 ) { $camposWhere=$equivalencia; }
- else { $camposWhere=$camposWhere." and ".$equivalencia; }
- if ( strlen($camposUpdate) == 0 ) { $camposUpdate=$equivalencia; }
- else { $camposUpdate=$Update.",".$equivalencia; }
- if ( strlen($camposInsert) == 0 ) { $camposInsert=$valorCampo; }
- else { $camposInsert=$camposInsert.",".$valorCampo; }
- }
- if ( $tipo == "delete" ) { $sql="DELETE FROM $tabla WHERE $camposWhere"; }
- if ( $tipo == "select" ) { $sql="SELECT $campos1 FROM $tabla WHERE $camposWhere"; }
- if ( $tipo == "insert" ) { $sql="INSERT INTO $tabla ($campos2) VALUES($camposInsert)"; }
- if ( $tipo == "update" ) { $sql="UPDATE $tabla SET $camposUpdate WHERE $camposWhere"; }
- return $sql;
- }
- // Arregla cadenas de texto para mostrar en pantalla ( remueve barras ) //
- function stripslashes_array($array) {
- return is_array($array) ? array_map('stripslashes_array', $array) : trim(stripslashes($array));
- }
- // devuelve error //
- function error($res) {
- return @mysql_error();
- }
- //libera resultado de memoria
- function libera_resultado($res) {
- return @mysql_free_result($res);
- }
- // cierra la conexion
- function cerrar_conexion() {
- $this->libera_resultado($this->connect_id);
- return @mysql_close($this->connect_id) ;
- }
- // conexion a la base //
- function conexion($Host, $User, $Pass, $Base) {
- $this->connect_id = @mysql_connect($Host, $User, $Pass);
- @mysql_query("SET NAMES 'utf8'",$this->connect_id);
- if( @mysql_select_db($Base, $this->connect_id)){ return $this->connect_id; };
- return FALSE;
- }
- // ejecutar query
- function consulta($query) {
- $this->query = trim($query);
- if ( !$this->connect_id ) { $this->conexion($this->host,$this->user,$this->pass,$this->base); }
- if ( $this->result_id = @mysql_query($this->query, $this->connect_id) ) {
- return $this->result_id;
- }
- return FALSE;
- }
- // Obtengo cantidad de registros obtenidos segun la ultima consulta //
- function cantidadRegistros($res,$query) {
- $data=0;
- if ( isset($res) ) {
- if ( preg_match('`^select`i',$query) ) { $data=@mysql_num_rows($res); }
- if ( preg_match('`^(insert|update|delete)`i',$query) ) { $data=@mysql_affected_rows($res); }
- }
- return $data;
- }
- function getArray($resQuery) {
- $got=array();
- if ( $this->cantidadRegistros($resQuery,$this->query) > 0 ) {
- $i=0;
- $claves=array_keys(mysql_fetch_array($resQuery,MYSQL_ASSOC));
- mysql_data_seek($resQuery, 0);
- while ($row = mysql_fetch_array($resQuery,MYSQL_ASSOC)) {
- foreach ($claves as $claveEspecifica) {
- $got[$i][$claveEspecifica]=$this->stripslashes_array($row[$claveEspecifica]);
- }
- $i++;
- }
- $this->libera_resultado($resQuery);
- }
- return $got;
- }
- function getArray1Dimension($resQuery,$idioma) {
- $got=array();
- if ( $this->cantidadRegistros($resQuery,$this->query) > 0 ) {
- mysql_data_seek($resQuery, 0);
- while ($row = mysql_fetch_array($resQuery,MYSQL_ASSOC)) {
- $campoNombre=$this->stripslashes_array($row['campo']);
- $contenido=$this->stripslashes_array($this->desencriptar($row[$idioma]));
- $got[$campoNombre]=$contenido;
- }
- $this->libera_resultado($resQuery);
- }
- return $got;
- }
- function desencriptar($text) {
- // $modificadores="iusS";
- $modificadores="iS";
- $modificadores="iS";
- global $dirTrabajo;
- $patrones = array(
- "&class=([A-Za-z]+)&".$modificadores,
- "&colspan=([0-9]+)&".$modificadores,
- "&\[url\]\[cl\](.+)\[/cl\]\[tex\](.+)\[/tex\](.+)\[/url\]&".$modificadores,
- "&\[url_popup\]\[cl\](.+)\[/cl\]\[tex\](.+)\[/tex\](.+)\[/url_popup\]&".$modificadores,
- "&\[url_transp\]\[cl\](.+)\[/cl\]\[med\](.+)\[/med\]\[tex\](.+)\[/tex\](.+)\[/url_transp\]&".$modificadores,
- "&\[bot\]\[nom\](.+)\[/nom\]\[val\](.+)\[/val\]\[size\](.+)\[/size\](.+)\[/bot\]&".$modificadores,
- "&\[img\](.+)\[/img\]&".$modificadores,
- "&\<b\>(.+)\</b\>&".$modificadores,
- //"&\<b\>([.|/s])*\</b\>&".$modificadores,
- //"@\[li\](.+?)\[/li\]@".$modificadores,
- "@\[li\](.+?)\[/li\]@".$modificadores,
- "&\[combo\](.+)\[/combo\]&".$modificadores
- );
- $reemplazos = array(
- 'class="$1"',
- 'colspan="$1"',
- "<a class='$1' href=".chr(34).crearLink('$3').chr(34)." >$2</a>
- ",
- "<a class='$1' href='javascript:;' onmouseover=".chr(34)."showTitle(event,this,'$3')".chr(34)."
- onmouseout='hideTitle(event, this);' >$2</a>
- ",
- "<a class='$1' href=".chr(34).crearLink('$4').chr(34)." title='info' rel='$2'>$3</a>",
- '<input
- type="button" value="$2" name="$1" id="$1" class="bton1" size="$3" onclick="$4" />',
- "<img src=".chr(34).crearLink('$1').chr(34).">",
- "<span class='bold'>$1</span>",
- "<li>$1</li>",
- "$1:"
- );
- if ( preg_match_all($patrones[3],$text,$salida,PREG_PATTERN_ORDER) ) {
- $parte3=$salida[3][0];
- $text=str_replace($parte3,rawurlencode($parte3),$text);
- }
- $newText = preg_replace($patrones,$reemplazos, $text);
- return $this->reemplazar($newText);
- }
- function reemplazar($texto) {
- global $datosPagina,$tiempoExpiracionMinutos,$tiempoExpiracionHoras;
- $texto= str_replace(chr(13),"",$texto);
- $texto=str_replace(chr(10),"",$texto);
- // $texto=str_replace("<br>","<br><br>",$texto);
- $texto=str_replace("#nom_pag#",$datosPagina['pag'],$texto);
- $texto=str_replace("#ref_pag#",$datosPagina['pag_ref'],$texto);
- $texto=str_replace("#nom_emp#",'<span class="titulos">'.$datosPagina['pag_nom'].'</span>',$texto);
- $texto=str_replace("#nom_emp_notit#",$datosPagina['pag_nom'],$texto);
- $texto=str_replace("#nom_emp_2#",'<span class="titulos">'.$datosPagina['pag_nom_2'].'</span>',$texto);
- $texto=str_replace("#nom_emp_largo#",'<span class="titulos">'.$datosPagina['pag_nom_largo'].'</span>',$texto);
- $texto=str_replace("#nom_emp_largo_g#",'<span class="titulos_grande">'.$datosPagina['pag_nom_largo'].'</span>',$texto);
- $mail=mailicono($datosPagina['pag_mail_contacto']);
- $texto=str_replace("#mail_contacto#",$mail,$texto);
- $mail=mailicono($datosPagina['pag_mail_busquedas']);
- $texto=str_replace("#mail_busquedas#",$mail,$texto);
- $texto=str_replace("#pin_expiracion_login#",$tiempoExpiracionMinutos,$texto);
- $texto=str_replace("#pin_expiracion_horas#",$tiempoExpiracionHoras,$texto);
- $texto=str_replace('<br>','<br/>',$texto);
- // $texto=str_replace('&','&',$texto);
- // $texto=mb_convert_encoding($texto, "ISO-8859-15");
- //$texto=mb_convert_encoding($texto, "UTF-8");
- // return utf8_encode(htmlentities($texto));
- // return utf8_encode($texto);
- // return htmlspecialchars($texto,ENT_QUOTES);
- return $texto;
- // return iconv($this->tipo_encode($texto), "ISO-8859-1", $texto);
- }
- function tipo_encode($texto) {
- return mb_detect_encoding($str, "auto");
- }
- /*
- function classLink($text,$seccionSite) {
- $modificadores="iS";
- $patrones = array(
- "&\[url_seccion\](.+)\[/url_seccion\]&".$modificadores,
- );
- // Traigo lss urls
- if ( preg_match_all($patrones[0],$text,$salida,PREG_PATTERN_ORDER) ) {
- $arrayUrls=$salida[1];
- }
- if ( count($arrayUrls) > 0 ) {
- // Recorro cada una de las urls
- foreach ($arrayUrls as $valor) {
- $paginaTemporal=$valor
- // Pregunto por la seccion de la url
- $patrones2 = array(
- "&\[seccion\](.+)\[/seccion\]&".$modificadores,
- );
- if ( preg_match($patrones2[0],$paginaTemporal,$salida2,PREG_PATTERN_ORDER) ) {
- $seccion=$salida2[1];
- if ( $seccion == $seccionSite ) {
- }
- }
- }
- $newText = preg_replace($patrones,$reemplazos, $text);
- return $this->$newText;
- }
- */
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement