Skip to content

Commit b4e2f77

Browse files
author
nosolored
committed
Clean code and add documentation
1 parent 54e2174 commit b4e2f77

File tree

1 file changed

+54
-125
lines changed

1 file changed

+54
-125
lines changed

funciones.php

+54-125
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55
ini_set("error_reporting",0);
66

77
function conectar(){
8-
require __DIR__.'/config.php';
8+
require __DIR__.'/config.php';
99
$link = new mysqli(
1010
$config['db']['host'],
1111
$config['db']['user'],
1212
$config['db']['pass'],
1313
$config['db']['name']
1414
);
15-
if ($link->connect_errno) {
16-
die('No pudo conectarse: ' . $link->connect_error);
17-
}
18-
$link->set_charset('utf8');
19-
return $link;
15+
if ($link->connect_errno) {
16+
die('No pudo conectarse: ' . $link->connect_error);
17+
}
18+
$link->set_charset('utf8');
19+
return $link;
2020
}
2121

2222
function conectar2(){
23-
require __DIR__.'/config.php';
23+
require __DIR__.'/config.php';
2424
$link = new mysqli(
2525
$config['db']['host'],
2626
$config['db']['user'],
2727
$config['db']['pass'],
2828
$config['db']['name']
2929
);
30-
if ($link->connect_errno) {
31-
die('No pudo conectarse: ' . $link->connect_error);
32-
}
33-
//mysql_set_charset('utf8',$link);
34-
return $link;
30+
if ($link->connect_errno) {
31+
die('No pudo conectarse: ' . $link->connect_error);
32+
}
33+
//mysql_set_charset('utf8',$link);
34+
return $link;
3535
}
3636

3737

@@ -73,20 +73,6 @@ function obtener2( $tabla, $iden, $id, $campo )
7373
return $segm;
7474
}
7575

76-
function datosreg( $id, $tabla, $campo, $iden )
77-
{
78-
$sql_link = conectar();
79-
if( $id == "" || empty($id) )
80-
return "";
81-
// obtener datos del usuario
82-
$q = "SELECT * FROM ".$tabla." WHERE ".$iden." = '".$id."'";
83-
$result = $sql_link->query($q) or oiError($sql_link->error());
84-
$ret = $result->fetch_array();
85-
$segm = $ret[$campo];
86-
$result->free_result();
87-
return $segm;
88-
}
89-
9076
/**
9177
* function obtener (de_la_tabla, donde_este_campo, es_igual_a_esto, este_campo_quiero);
9278
* Obtenemos un campo especifico.
@@ -307,19 +293,31 @@ function Comprobariexplorer2($user_agent) {
307293
return false;
308294
}
309295

310-
// ENCRIPTAR
311-
296+
/**
297+
* function encriptar ($cad);
298+
* We obtain the encrypted string
299+
* @$cad: string
300+
*
301+
* return string
302+
*/
312303
function encriptar($cad){
313-
$cc = base64_encode($cad);
314-
$key = 'rnvoxjnj';
315-
$iv = '12345678';
316-
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH,'','cbc','');
317-
mcrypt_generic_init($cipher, $key, $iv);
318-
$encrypted = mcrypt_generic($cipher,$cc);
319-
mcrypt_generic_deinit($cipher);
320-
return base64_encode($encrypted);
304+
$cc = base64_encode($cad);
305+
$key = 'rnvoxjnj';
306+
$iv = '12345678';
307+
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH,'','cbc','');
308+
mcrypt_generic_init($cipher, $key, $iv);
309+
$encrypted = mcrypt_generic($cipher,$cc);
310+
mcrypt_generic_deinit($cipher);
311+
return base64_encode($encrypted);
321312
}
322313

314+
/**
315+
* function desenencriptar ($cad);
316+
* We obtain the original string
317+
* @$cad: string
318+
*
319+
* return string
320+
*/
323321
function desencriptar($cad)
324322
{
325323
$cc = base64_decode($cad);
@@ -332,99 +330,30 @@ function desencriptar($cad)
332330
return base64_decode($decrypted);
333331
}
334332

335-
// COMPLETAR CON CEROS A LA IZQUIERDA
336-
/////////////////////////////////////
337-
function completar($valor, $digitos){
338-
$resultado='';
339-
if(strlen($valor)<$digitos){
340-
341-
$ceros=$digitos-strlen(ceil($valor));
342-
for($i=0;$i<$ceros;$i++){
333+
/**
334+
* function completar ($valor, $digitos);
335+
* Completed variable with zeros to the left
336+
* @$valor: variable
337+
* @digitos: size of variable
338+
*
339+
* return string
340+
*/
341+
function completar($valor, $digitos)
342+
{
343+
$resultado='';
344+
if(strlen($valor)<$digitos)
345+
{
346+
$ceros=$digitos-strlen(ceil($valor));
347+
for($i=0;$i<$ceros;$i++)
348+
{
343349
$resultado.='0';
344350
}
345351
}
346-
$resultado.=$valor;
347-
return $resultado;
348-
}
349-
350-
////////////////////////////////////////////////////
351-
352-
//Convierte fecha de mysql a normal
353-
354-
////////////////////////////////////////////////////
355-
356-
function fechanormal($fecha){
357-
if($fecha>0){
358-
ereg( "([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})", $fecha, $mifecha);
359-
360-
$lafecha=$mifecha[3]."/".$mifecha[2]."/".$mifecha[1];
361-
}
362-
else {
363-
$lafecha="";
364-
}
365-
return $lafecha;
366-
352+
$resultado .= $valor;
353+
return $resultado;
367354
}
368355

369-
// MESES EN ESPAÑOL DE ESPAÑA
370-
/////////////////////////////////
371-
function meses($valor){
372-
if($valor==1){
373-
$resultado="Enero";
374-
}
375-
if($valor==2){
376-
$resultado="Febrero";
377-
}
378-
if($valor==3){
379-
$resultado="Marzo";
380-
}
381-
if($valor==4){
382-
$resultado="Abril";
383-
}
384-
if($valor==5){
385-
$resultado="Mayo";
386-
}
387-
if($valor==6){
388-
$resultado="Junio";
389-
}
390-
if($valor==7){
391-
$resultado="Julio";
392-
}
393-
if($valor==8){
394-
$resultado="Agosto";
395-
}
396-
if($valor==9){
397-
$resultado="Septiembre";
398-
}
399-
if($valor==10){
400-
$resultado="Octubre";
401-
}
402-
if($valor==11){
403-
$resultado="Noviembre";
404-
}
405-
if($valor==12){
406-
$resultado="Diciembre";
407-
}
408-
return $resultado;
409-
}
410-
411-
// DATOS TABLA POR COD
412-
/////////////////////
413-
/*
414-
function datosreg($codigo, $tabla, $campo, $campocod='cod'){
415-
$query=mysql_query("select ".$campo." as valor from ".$tabla." where ".$campocod."='".$codigo."';" );
416-
if(mysql_errno()!=0){
417-
$resultado=mysql_error();
418-
} else {
419-
while($rows=mysql_fetch_array($query)){
420-
$resultado=$rows["valor"];
421-
}
422-
}
423-
return $resultado;
424-
}
425-
*/
426356
//QUITAR CODIFICACION HTML ACENTOS, EÑES...
427-
428357
function quitar_html($cadena){
429358
$txt=str_replace("<br />",chr(13).chr(10),$cadena);
430359
$txt=str_replace("<br>",chr(13).chr(10),$txt);
@@ -455,7 +384,7 @@ function quitar_html($cadena){
455384
$txt=str_replace("&ordm;",'º',$txt);
456385
$txt=str_replace("&amp;",'&',$txt);
457386
$txt=str_replace("&bull;",'',$txt);
458-
$txt=str_replace("&euro;",'',$txt);
387+
$txt=str_replace("&euro;",'',$txt);
459388

460389
return $txt;
461390
}
@@ -809,4 +738,4 @@ function limpiar($valor){
809738
$valor = htmlentities($valor);
810739
return $valor;
811740
}
812-
?>
741+
?>

0 commit comments

Comments
 (0)