Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.64 KB | None | 0 0
  1. <?php
  2. class Mysql {
  3. var $host;
  4. var $user;
  5. var $pass;
  6. var $base;
  7. var $connect_id = 0;
  8. var $result_id;
  9.  
  10. var $error;
  11. var $query;
  12.  
  13.  
  14. // privado: constructor //
  15. function Mysql($Host='', $User='', $Pass='', $Base='') {
  16. $this->host=$Host;
  17. $this->user=$User;
  18. $this->pass=$Pass;
  19. $this->base=$Base;
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26. // Remuevo barras y las agrego //
  27. function arreglar($valor) {
  28. // Retiro barras
  29. if (get_magic_quotes_gpc()) {
  30. $valor = stripslashes($valor);
  31. }
  32. // Colocar comillas si no es entero
  33. if (!is_numeric($valor)) {
  34. $valor=mysql_real_escape_string($valor);
  35. }
  36. return "'$valor'";
  37. }
  38.  
  39.  
  40. // Para ejecutar querys a la base de datos ( se recomienda solo aplicar en parametros ) //
  41. function mysql_real_escape_array($t){
  42. return is_array($t) ? array_map('mysql_real_escape_array', $t) : trim($this->arreglar($t));
  43. }
  44.  
  45.  
  46. function separacionCampos($camposMostrar) {
  47. $campos="";
  48. for($i=0; $i < count($camposMostrar);$i++) {
  49. $nombre_campo=$camposMostrar[$i];
  50. if ( strlen($campos) == 0 ) { $campos=$nombre_campo; }
  51. else { $campos=$campos.",".$nombre_campo; }
  52. }
  53. return $campos;
  54. }
  55.  
  56.  
  57. function crearConsulta($tipo,$camposMostrar,$tabla,$camposDatos,$datosCampos) {
  58. $sql="";
  59. $campos1=$this->separacionCampos($camposMostrar);
  60. $campos2=$this->separacionCampos($camposDatos);
  61.  
  62. // Updates or where //
  63. $camposWhere="";
  64. $camposUpdate="";
  65. $camposInsert="";
  66. for($i=0; $i < count($camposDatos);$i++) {
  67. $nombreCampo=$camposDatos[$i];
  68. $valorCampo='$datosCampos[$i]';
  69. $equivalencia=$nombreCampo."=".$valorCampo;
  70.  
  71. if ( strlen($camposWhere) == 0 ) { $camposWhere=$equivalencia; }
  72. else { $camposWhere=$camposWhere." and ".$equivalencia; }
  73.  
  74. if ( strlen($camposUpdate) == 0 ) { $camposUpdate=$equivalencia; }
  75. else { $camposUpdate=$Update.",".$equivalencia; }
  76.  
  77. if ( strlen($camposInsert) == 0 ) { $camposInsert=$valorCampo; }
  78. else { $camposInsert=$camposInsert.",".$valorCampo; }
  79.  
  80. }
  81.  
  82. if ( $tipo == "delete" ) { $sql="DELETE FROM $tabla WHERE $camposWhere"; }
  83. if ( $tipo == "select" ) { $sql="SELECT $campos1 FROM $tabla WHERE $camposWhere"; }
  84. if ( $tipo == "insert" ) { $sql="INSERT INTO $tabla ($campos2) VALUES($camposInsert)"; }
  85. if ( $tipo == "update" ) { $sql="UPDATE $tabla SET $camposUpdate WHERE $camposWhere"; }
  86.  
  87. return $sql;
  88. }
  89.  
  90.  
  91.  
  92.  
  93. // Arregla cadenas de texto para mostrar en pantalla ( remueve barras ) //
  94. function stripslashes_array($array) {
  95. return is_array($array) ? array_map('stripslashes_array', $array) : trim(stripslashes($array));
  96. }
  97.  
  98.  
  99.  
  100.  
  101. // devuelve error //
  102. function error($res) {
  103. return @mysql_error();
  104. }
  105.  
  106. //libera resultado de memoria
  107. function libera_resultado($res) {
  108. return @mysql_free_result($res);
  109. }
  110.  
  111.  
  112. // cierra la conexion
  113. function cerrar_conexion() {
  114. $this->libera_resultado($this->connect_id);
  115. return @mysql_close($this->connect_id) ;
  116. }
  117.  
  118. // conexion a la base //
  119. function conexion($Host, $User, $Pass, $Base) {
  120. $this->connect_id = @mysql_connect($Host, $User, $Pass);
  121.  
  122. @mysql_query("SET NAMES 'utf8'",$this->connect_id);
  123.  
  124. if( @mysql_select_db($Base, $this->connect_id)){ return $this->connect_id; };
  125. return FALSE;
  126.  
  127. }
  128.  
  129. // ejecutar query
  130. function consulta($query) {
  131. $this->query = trim($query);
  132. if ( !$this->connect_id ) { $this->conexion($this->host,$this->user,$this->pass,$this->base); }
  133. if ( $this->result_id = @mysql_query($this->query, $this->connect_id) ) {
  134. return $this->result_id;
  135. }
  136.  
  137. return FALSE;
  138. }
  139.  
  140.  
  141.  
  142. // Obtengo cantidad de registros obtenidos segun la ultima consulta //
  143. function cantidadRegistros($res,$query) {
  144. $data=0;
  145. if ( isset($res) ) {
  146. if ( preg_match('`^select`i',$query) ) { $data=@mysql_num_rows($res); }
  147. if ( preg_match('`^(insert|update|delete)`i',$query) ) { $data=@mysql_affected_rows($res); }
  148. }
  149. return $data;
  150. }
  151.  
  152.  
  153. function getArray($resQuery) {
  154. $got=array();
  155. if ( $this->cantidadRegistros($resQuery,$this->query) > 0 ) {
  156. $i=0;
  157. $claves=array_keys(mysql_fetch_array($resQuery,MYSQL_ASSOC));
  158. mysql_data_seek($resQuery, 0);
  159. while ($row = mysql_fetch_array($resQuery,MYSQL_ASSOC)) {
  160. foreach ($claves as $claveEspecifica) {
  161. $got[$i][$claveEspecifica]=$this->stripslashes_array($row[$claveEspecifica]);
  162. }
  163. $i++;
  164. }
  165. $this->libera_resultado($resQuery);
  166. }
  167. return $got;
  168.  
  169. }
  170.  
  171.  
  172. function getArray1Dimension($resQuery,$idioma) {
  173. $got=array();
  174. if ( $this->cantidadRegistros($resQuery,$this->query) > 0 ) {
  175. mysql_data_seek($resQuery, 0);
  176. while ($row = mysql_fetch_array($resQuery,MYSQL_ASSOC)) {
  177. $campoNombre=$this->stripslashes_array($row['campo']);
  178.  
  179. $contenido=$this->stripslashes_array($this->desencriptar($row[$idioma]));
  180. $got[$campoNombre]=$contenido;
  181.  
  182. }
  183. $this->libera_resultado($resQuery);
  184. }
  185. return $got;
  186.  
  187. }
  188.  
  189.  
  190.  
  191.  
  192.  
  193. function desencriptar($text) {
  194. // $modificadores="iusS";
  195. $modificadores="iS";
  196.  
  197. $modificadores="iS";
  198. global $dirTrabajo;
  199.  
  200. $patrones = array(
  201.  
  202.  
  203.  
  204.  
  205. "&class=([A-Za-z]+)&".$modificadores,
  206. "&colspan=([0-9]+)&".$modificadores,
  207.  
  208. "&\[url\]\[cl\](.+)\[/cl\]\[tex\](.+)\[/tex\](.+)\[/url\]&".$modificadores,
  209. "&\[url_popup\]\[cl\](.+)\[/cl\]\[tex\](.+)\[/tex\](.+)\[/url_popup\]&".$modificadores,
  210. "&\[url_transp\]\[cl\](.+)\[/cl\]\[med\](.+)\[/med\]\[tex\](.+)\[/tex\](.+)\[/url_transp\]&".$modificadores,
  211.  
  212.  
  213.  
  214.  
  215. "&\[bot\]\[nom\](.+)\[/nom\]\[val\](.+)\[/val\]\[size\](.+)\[/size\](.+)\[/bot\]&".$modificadores,
  216.  
  217.  
  218. "&\[img\](.+)\[/img\]&".$modificadores,
  219.  
  220. "&\<b\>(.+)\</b\>&".$modificadores,
  221.  
  222.  
  223. //"&\<b\>([.|/s])*\</b\>&".$modificadores,
  224.  
  225.  
  226. //"@\[li\](.+?)\[/li\]@".$modificadores,
  227.  
  228.  
  229. "@\[li\](.+?)\[/li\]@".$modificadores,
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. "&\[combo\](.+)\[/combo\]&".$modificadores
  237.  
  238. );
  239.  
  240.  
  241.  
  242.  
  243. $reemplazos = array(
  244. 'class="$1"',
  245. 'colspan="$1"',
  246.  
  247. "<a class='$1' href=".chr(34).crearLink('$3').chr(34)." >$2</a>
  248. ",
  249.  
  250. "<a class='$1' href='javascript:;' onmouseover=".chr(34)."showTitle(event,this,'$3')".chr(34)."
  251. onmouseout='hideTitle(event, this);' >$2</a>
  252. ",
  253.  
  254. "<a class='$1' href=".chr(34).crearLink('$4').chr(34)." title='info' rel='$2'>$3</a>",
  255.  
  256. '<input
  257.  
  258. type="button" value="$2" name="$1" id="$1" class="bton1" size="$3" onclick="$4" />',
  259.  
  260.  
  261.  
  262.  
  263.  
  264. "<img src=".chr(34).crearLink('$1').chr(34).">",
  265. "<span class='bold'>$1</span>",
  266. "<li>$1</li>",
  267. "$1:"
  268. );
  269.  
  270.  
  271. if ( preg_match_all($patrones[3],$text,$salida,PREG_PATTERN_ORDER) ) {
  272. $parte3=$salida[3][0];
  273.  
  274. $text=str_replace($parte3,rawurlencode($parte3),$text);
  275. }
  276.  
  277.  
  278.  
  279. $newText = preg_replace($patrones,$reemplazos, $text);
  280.  
  281.  
  282. return $this->reemplazar($newText);
  283.  
  284.  
  285. }
  286.  
  287. function reemplazar($texto) {
  288. global $datosPagina,$tiempoExpiracionMinutos,$tiempoExpiracionHoras;
  289.  
  290. $texto= str_replace(chr(13),"",$texto);
  291. $texto=str_replace(chr(10),"",$texto);
  292.  
  293. // $texto=str_replace("<br>","<br><br>",$texto);
  294.  
  295.  
  296. $texto=str_replace("#nom_pag#",$datosPagina['pag'],$texto);
  297. $texto=str_replace("#ref_pag#",$datosPagina['pag_ref'],$texto);
  298.  
  299. $texto=str_replace("#nom_emp#",'<span class="titulos">'.$datosPagina['pag_nom'].'</span>',$texto);
  300.  
  301.  
  302. $texto=str_replace("#nom_emp_notit#",$datosPagina['pag_nom'],$texto);
  303.  
  304. $texto=str_replace("#nom_emp_2#",'<span class="titulos">'.$datosPagina['pag_nom_2'].'</span>',$texto);
  305. $texto=str_replace("#nom_emp_largo#",'<span class="titulos">'.$datosPagina['pag_nom_largo'].'</span>',$texto);
  306.  
  307. $texto=str_replace("#nom_emp_largo_g#",'<span class="titulos_grande">'.$datosPagina['pag_nom_largo'].'</span>',$texto);
  308.  
  309.  
  310.  
  311.  
  312. $mail=mailicono($datosPagina['pag_mail_contacto']);
  313. $texto=str_replace("#mail_contacto#",$mail,$texto);
  314.  
  315. $mail=mailicono($datosPagina['pag_mail_busquedas']);
  316. $texto=str_replace("#mail_busquedas#",$mail,$texto);
  317.  
  318.  
  319.  
  320.  
  321. $texto=str_replace("#pin_expiracion_login#",$tiempoExpiracionMinutos,$texto);
  322. $texto=str_replace("#pin_expiracion_horas#",$tiempoExpiracionHoras,$texto);
  323.  
  324.  
  325.  
  326. $texto=str_replace('<br>','<br/>',$texto);
  327.  
  328. // $texto=str_replace('&','&',$texto);
  329.  
  330. // $texto=mb_convert_encoding($texto, "ISO-8859-15");
  331.  
  332. //$texto=mb_convert_encoding($texto, "UTF-8");
  333.  
  334. // return utf8_encode(htmlentities($texto));
  335.  
  336. // return utf8_encode($texto);
  337. // return htmlspecialchars($texto,ENT_QUOTES);
  338. return $texto;
  339.  
  340. // return iconv($this->tipo_encode($texto), "ISO-8859-1", $texto);
  341. }
  342.  
  343.  
  344. function tipo_encode($texto) {
  345.  
  346. return mb_detect_encoding($str, "auto");
  347. }
  348.  
  349.  
  350.  
  351.  
  352. /*
  353. function classLink($text,$seccionSite) {
  354. $modificadores="iS";
  355. $patrones = array(
  356. "&\[url_seccion\](.+)\[/url_seccion\]&".$modificadores,
  357.  
  358. );
  359.  
  360. // Traigo lss urls
  361. if ( preg_match_all($patrones[0],$text,$salida,PREG_PATTERN_ORDER) ) {
  362. $arrayUrls=$salida[1];
  363. }
  364. if ( count($arrayUrls) > 0 ) {
  365. // Recorro cada una de las urls
  366. foreach ($arrayUrls as $valor) {
  367. $paginaTemporal=$valor
  368. // Pregunto por la seccion de la url
  369. $patrones2 = array(
  370. "&\[seccion\](.+)\[/seccion\]&".$modificadores,
  371. );
  372. if ( preg_match($patrones2[0],$paginaTemporal,$salida2,PREG_PATTERN_ORDER) ) {
  373. $seccion=$salida2[1];
  374. if ( $seccion == $seccionSite ) {
  375.  
  376.  
  377. }
  378. }
  379.  
  380. }
  381.  
  382. $newText = preg_replace($patrones,$reemplazos, $text);
  383.  
  384.  
  385. return $this->$newText;
  386.  
  387.  
  388. }
  389. */
  390.  
  391. }
  392. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement