session_start();
?>
$conf_desarrollo = TRUE;
$email_admin = 'pmacias@civan.com';
?>
function phpself($qs=NULL){
//devuelve la pág. actual con el qs que se le pasa, o con el actual si no se le pasa ninguno.
if (is_null($qs)) $qs = $_SERVER['QUERY_STRING'];
$qs = str_replace('?','',$qs);
return empty($qs) ? $_SERVER['PHP_SELF'] : $_SERVER['PHP_SELF'].'?'.$qs;
}
function anade_qs($var='', $valor='', $qs = FALSE ) {
//añade (o modifica si ya existe) un par var/val en el query string
if ($qs === FALSE) $qs = $_SERVER['QUERY_STRING'];
$qs = str_replace('?','',$qs);
$vars1 = explode('&', $qs);
foreach ($vars1 as $k=>$v){
$var_val = explode('=', $v);
$vars[$var_val[0]] = $var_val[1];
}
if (!empty($var)) {
$vars[$var] = $valor;
}
if (isset($vars[$var]) && $valor === FALSE) {
unset($vars[$var]); // si ponemos un valor FALSE, borramos la variable de la qs.
}
foreach ($vars as $k=>$v){
if ($k != '') $qs_final[] = !empty($v) ? $k.'='.$v : $k;
}
return !empty($qs_final) ? '?'.implode("&", $qs_final) : '';
}
function array_f($array){
//para debug, devuelve un array de forma legible para hacer un echo.
ob_start();
print_r($array);
$a = ob_get_clean();
return "
";
}
function url_base(){
return "http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
}
function viene_de_si_misma(){
return (parse_url($_SERVER['PHP_SELF'],PHP_URL_PATH) == parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH));
}
function titulo_pag($texto){
return ($texto ? $texto." - " : '' )."Asociación Voluntariado en GeriatrÃa";
}
?>
/*
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
//$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
$theValue = mysql_real_escape_string((get_magic_quotes_gpc()) ? stripslashes($theValue) :$theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "bool":
$theValue = ($theValue) ? "1" : "0";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
*/
function query($query,$en_desarollo=NULL) {
global $conf_desarrollo, $email_admin;
$conf_desarrollo = is_null($en_desarollo) ? $conf_desarrollo : $en_desarollo;
$result = mysql_query($query);
if ($result !== FALSE) {
return $result;
} else {
if (!$conf_desarrollo) { //produccion:
$out = 'Error en la base de datos: '.' ';
$out.= ' ';
$out.= 'Host: '.$_SERVER['HTTP_HOST'].' ('.$_SERVER['SERVER_NAME'].') ';
$out.= 'Fecha/hora: Local: '.date("d-m-Y \(D\) H:i:s")." (Request serv.: ". date("d-m-Y \(D\) H:i:s",$_SERVER['REQUEST_TIME']).')'.' ';
$out.= 'Archivo: '.$_SERVER['REQUEST_URI'].', mét. '.$_SERVER['REQUEST_METHOD'].') ';
$out.= 'Error (cod. '.mysql_errno().'): '.mysql_error().''.' ';
$out.= 'Query: '.nl2br($query).''.' ';
$out.= ' ';
$out.= 'Datos remotos: '.$_SERVER['HTTP_USER_AGENT'].' ['.base64_encode($_SERVER['REMOTE_ADDR']).'] '.' ';
//enviamos email
$cuerpo_email = strip_tags(str_replace(array(' ',' '),array("\r\n","---------------------------------\r\n"),$out));
$msg = 'Error en la base de datos: '.' ';
if (!empty($email_admin) && mail($email_admin, 'Error en bdd ('.$_SERVER['HTTP_HOST'].')',$cuerpo_email)) {
$msg.= 'Se ha enviado un mensaje al administrador de la base de datos con los detalles del problema. '.' ';
} else {
$msg.= 'No se ha podido enviar un mensaje al administrador de la base de datos. '.' ';
}
die($msg);
} else { //desarrollo:
$out = 'Error en la base de datos: '.' ';
$out.= ' ';
$out.= 'Archivo: '.$_SERVER['REQUEST_URI'].', mét. '.$_SERVER['REQUEST_METHOD'].') ';
$out.= 'Error (cod. '.mysql_errno().'): '.mysql_error().''.' ';
$out.= 'Query: '.nl2br($query).''.' ';
die($out);
}
}
}
?>
function selfURL() {
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2));
}
?>
function ordenar_por($titulo, $campo_db='', $orderby_actual = '', $dir_def = '', $posicion='detras' ){
//global $orderby;
if (empty($orderby_actual)) $orderby_actual = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : trim(str_replace('ASC','',str_replace('DESC','',$orderby)));
$campo_db = empty($campo_db) ? strtolower(elimina_acentos($titulo)) : $campo_db;
if (empty($dir_def)) {
$dir_def = (strpos($campo_db, 'fecha')!== FALSE) ? 'DESC' : 'ASC'; //por defecto ASC menos si pone 'fecha' en el campo.
}
$dir_act = ($orderby_actual == $campo_db) ? $_REQUEST['dir'] : $dir_def ;
$dir_poner = $dir_def;
if ($orderby_actual == $campo_db){
$dir_poner = ($dir_act == 'ASC') ? 'DESC' : 'ASC';
$dir_poner_title = ($dir_act == 'ASC') ? 'decreciente' : 'creciente';
$indicador = ($dir_act == 'ASC') ? ' ↓' : ' ↑';
$indicador = ''.$indicador.' ';
}
if ($posicion == 'delante') $enl= $indicador .'' . htmlentities($titulo) . ' ';
else $enl= '' . htmlentities($titulo) . ' ' . $indicador;
echo $enl;
}
/*function query_paginacion(&$resultados, $from, $registros_por_pagina=NULL, $where=NULL, $select=NULL, $def_orderby=NULL, $def_dir=NULL, $pag=NULL){
//$rpp = !empty($registros_por_pagina) ? $registros_por_pagina : 10 ;
$select = !empty($select) ? $select : "*" ;
$where = !empty($where) ? $where : "" ;
$escribe_where = !empty($where) ? "WHERE $where" : "" ;
$rpp = !empty($registros_por_pagina) ? $registros_por_pagina : (!empty($_REQUEST['rpp']) ? $_REQUEST['rpp'] : 10);
$orderby = !empty($def_orderby) ? $def_orderby : (!empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'id');
$dir = !empty($def_dir) ? $def_dir : (!empty($_REQUEST['dir']) ? $_REQUEST['dir'] : 'DESC');
$pagina = !empty($pag) ? $pag : (!empty($_REQUEST['pagina']) ? $_REQUEST['pagina'] : 1);
$principio = ($pagina-1) * $rpp;
$registros = mysql_num_rows(mysql_query("SELECT $select FROM $from $escribe_where"));
$resultados = compact('pagina','registros','rpp');
$query_f = "SELECT $select FROM $from $escribe_where ORDER BY $orderby $dir LIMIT $principio,$rpp";
//$result = mysql_query("SELECT $select FROM $from WHERE $where ORDER BY $orderby $dir LIMIT $principio,$rpp") or die(mysql_error().'::'."SELECT $select FROM $from WHERE $where ORDER BY $orderby $dir LIMIT $principio,$rpp");
//return $result;
return $query_f;
}*/
function query_paginacion(&$resultados, $from, $registros_por_pagina=NULL, $where=NULL, $select=NULL, $def_orderby=NULL, $def_dir=NULL, $pag=NULL){
//$rpp = !empty($registros_por_pagina) ? $registros_por_pagina : 10 ;
$select = !empty($select) ? $select : "*" ;
$where = !empty($where) ? $where : "" ;
// $escribe_where = !empty($where) ? "WHERE $where" : "" ;
if (!empty($select) && strstr($select, 'SELECT') === FALSE) $select = "SELECT ".$select;
if (!empty($from) && strstr($from, 'FROM') === FALSE) $from = "FROM ".$from;
if (!empty($where) && strstr($where, 'WHERE') === FALSE) $where = "WHERE ".$where;
$rpp = !empty($registros_por_pagina) ? (int)$registros_por_pagina : (!empty($_REQUEST['rpp']) ? (int)$_REQUEST['rpp'] : 10);
$orderby = !empty($def_orderby) ? $def_orderby : (!empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'id');
//$orderby = mysql_real_escape_string($orderby);
$orderby = addslashes($orderby);
$dir = !empty($def_dir) ? $def_dir : (!empty($_REQUEST['dir']) ? $_REQUEST['dir'] : 'DESC');
$dir = ($dir == 'DESC') ? 'DESC' : 'ASC';
$pagina = !empty($pag) ? (int)$pag : (!empty($_REQUEST['pagina']) ? (int)$_REQUEST['pagina'] : 1);
$principio = ($pagina-1) * $rpp;
$registros = mysql_num_rows(mysql_query("$select $from $where"));
// $registros_limit = mysql_num_rows(mysql_query("$select $from $where LIMIT $principio,$rpp"));
$resultados = compact('pagina','registros','rpp');
$query_f = "$select $from $where ORDER BY $orderby $dir LIMIT $principio,$rpp";
//$result = mysql_query("SELECT $select FROM $from WHERE $where ORDER BY $orderby $dir LIMIT $principio,$rpp") or die(mysql_error().'::'."SELECT $select FROM $from WHERE $where ORDER BY $orderby $dir LIMIT $principio,$rpp");
//return $result;
return $query_f;
}
function paginacion($resultados_query,$url_o_func=FALSE, $es_funcion_javascript = FALSE, $formato_con_pags = "principio,ant,num,sig,fin",$formato_sin_pags = "", $array_rpps = FALSE) {
//se le pasa el array &$resultados que devuelve por referencia query_paginacion();
$total_pags_visibles = 11;
if (!is_array($resultados_query) || count($resultados_query) != 3) { return FALSE;}
else {
$url = $url_o_func;
$url = !empty($url) ? $url : ($_SERVER['QUERY_STRING'] ? $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'] : $_SERVER['PHP_SELF']);
extract($resultados_query); // crea variables '$pagina','$registros','$rpp'
$principio = ($pagina-1) * $rpp;
//$num_paginas = ceil($registros / $rpp);
$num_paginas = num_pags_paginacion($resultados_query);
$hay_sig = ($pagina < $num_paginas); //hay siguiente
$hay_ant = ($pagina > 1); //hay anterior
$sig = $pagina+1; $ant = $pagina-1; $pri = 1; $ult = $num_paginas;
$regs_mostrados = (($principio + $rpp) > $registros ? $registros - $principio: ($principio + $rpp - $principio));
if ($es_funcion_javascript) {
$pri = "javascript:$url_o_func($pri);"; $ant = "javascript:$url_o_func($ant);";
$sig = "javascript:$url_o_func($sig);"; $ult = "javascript:$url_o_func($ult);";
} else {
list($url_f, $qs) = explode('?',$url);
$pri = $url_f.anade_qs('pagina',$pri,$qs); $ant = $url_f.anade_qs('pagina',$ant,$qs);
$sig = $url_f.anade_qs('pagina',$sig,$qs); $ult = $url_f.anade_qs('pagina',$ult,$qs);
}
$out['principio'] = '';
//hacemos el select para elegir el núm de pags. para hacer
$select_rpp= '
';
$rpps = !empty($array_rpps) ? $array_rpps : array(25,50,100,300);
$reg_total = $rpp;
if ($rpps && !in_array($rpp, $rpps)) { //por si el usuario introduce manualmente una cantidad
$rpps[]=$rpp;
sort($rpps);
}
foreach ($rpps as $i) {
if ($i < $registros) {
$sel = ($i == $rpp) ? " selected" : '';
$select_rpp.= ' '.$i.' ';
} else {
$sel = ($registros == $rpp) ? " selected" : '';
$select_rpp.= ' '.$registros.' ';
$reg_total = $registros;
break;
}
}
$select_rpp.= ' ';
//hacemos paginación
$out['texto'] = sprintf('
Viendo %s '.(($reg_total > 1) ? 'registros' : 'registro' ).', del %s al %s de %s ',$select_rpp, $principio + 1,($principio + $rpp) > $registros ? $registros : ($principio + $rpp), $registros);
$out['texto_sin'] = sprintf('
Viendo %s '.(($regs_mostrados > 1) ? 'registros' : 'registro' ).', del %s al %s de %s ',$regs_mostrados, $principio + 1,($principio + $rpp) > $registros ? $registros : ($principio + $rpp), $registros);
if ($hay_ant) $out['ant'] = '
|« '.'- '.'« Anterior ';
else $out['ant'] = '|« '.'- '.'« Anterior ';
$out['num'] = '';
$inicio = 1;
$fin = $num_paginas;
if ($num_paginas > $total_pags_visibles) { //vemos de qúe pág. a que pág. mostrar
$inicio = (ceil($pagina - $total_pags_visibles/2) > 0) ? ceil($pagina - $total_pags_visibles/2) : 1;
$fin = (($inicio + $total_pags_visibles - 1) < $num_paginas) ? ($inicio + $total_pags_visibles - 1) : $num_paginas;
$inicio = (($fin - $total_pags_visibles + 1) < $inicio) ? ($fin - $total_pags_visibles + 1) : $inicio;
}
for ($i=$inicio; $i <= $fin; $i++) {
if ($es_funcion_javascript) $num = "javascript:$url_o_func($i);";
else {
list($url_f, $qs) = explode('?',$url);
$num = $url_f.anade_qs('pagina',$i,$qs);
}
$out['num'].= '- ';
if ($i != $pagina) $out['num'].= ''.((($i == $inicio && $inicio > 1) || ($i == $fin && $fin < $num_paginas)) ? '...' : $i ).' ';
else $out['num'].= ''.$i.' ';
} //fin for
$out['num'].= ' ';
if ($hay_sig) $out['sig']= '- '.'Siguiente » '.'- '.'»| ';
else $out['sig']= 'Siguiente » '.'»| ';
$out['fin'] = '
';
//if ($num_paginas > 1) {
$formato = ($num_paginas > 1) ? $formato_con_pags : $formato_sin_pags ;
$fmt = explode(',',$formato);
foreach ($fmt as $key => $opc){
if (isset($out[$opc])) $paginacion.=$out[$opc];
else $paginacion.=$opc;
}
echo $paginacion;
//} //fin if num_p...
}
}
function num_pags_paginacion($resultados){
return ceil($resultados['registros']/$resultados['rpp']);
}
?>
###############################
# Uso: haz_codigo_youtube($embed_o_url, $color1=NULL, $color2=NULL, $ancho=NULL, $alto=NULL);
# - $embed_o_url puede ser el código embed (del cual sacará los parámetros de color o dimensiones si los tiene)
# o la URL de la página del video (p. ej 'http://es.youtube.com/watch?v=xxXxxXxxX').
# - Los demás parámetros son opcionales.
# ej1:
# $embed = ' ';
# echo haz_codigo_youtube($embed);
# ej2:
# $url = 'http://es.youtube.com/watch?v=xxXxxXxxX';
# echo haz_codigo_youtube($url);
# - Para poner varios vídeos, separar urls o códigos embed por comas
###############################
function saca_codigo_youtube($url){
//copiado:
$qs = parse_url($url);
$qs = $qs['query'];
parse_str($qs,$vars);
return $vars['v'];
}
function saca_atributos_embed_youtube($embed) {
$parsed = parse_html($embed);
$atr_embed = $parsed['embed'][0];
array_walk($atr_embed,'trim','"');
if (!empty($atr_embed)) return $atr_embed;
else return FALSE;
}
function saca_url_embed_youtube($embed) {
$atr_embed = saca_atributos_embed_youtube($embed);
if (!empty($atr_embed['src'])) return trim($atr_embed['src'],'"');
else return FALSE;
}
function saca_codigo_url_youtube($url){
$qs = parse_url($url);
$path = $qs['path'];
$qs = strstr ($path,'&');
$dir = rtrim($path,$qs);
$codigo = ltrim($dir,'v/');
return $codigo;
}
function saca_opciones_url_youtube($url){
$qs = parse_url($url);
$path = $qs['path'];
$qs = strstr($path,'&');
parse_str($qs,$arr);
return $arr;
}
function saca_codigo_embed_youtube($embed){
return saca_codigo_url_youtube(saca_url_embed_youtube($embed));
}
function saca_opciones_embed_youtube($embed){
return saca_opciones_url_youtube(saca_url_embed_youtube($embed));
}
function parse_html($html){
$i_indicatorL = 0;
$i_indicatorR = 0;
$s_tagOption = "";
$i_arrayCounter = 0;
$s_str = trim($html);
$a_html = array();
// Search for a tag in string
while( is_int(($i_indicatorL=strpos($s_str,"<",$i_indicatorR))) ) {
// Get everything into tag...
$i_indicatorL++;
$i_indicatorR = strpos($s_str,">", $i_indicatorL);
$s_temp = substr($s_str, $i_indicatorL, ($i_indicatorR-$i_indicatorL) );
$a_tag = explode( ' ', $s_temp );
// Here we get the tag's name
list( ,$s_tagName,, ) = each($a_tag);
//$s_tagName = strtoupper($s_tagName);
// Well, I am not interesting in , or anything else like that...
// So, this is false for tags without options.
$b_boolOptions = is_array(($s_tagOption=each($a_tag))) && $s_tagOption[1];
if( $b_boolOptions ) {
// Without this, we will mess up the array
$i_arrayCounter = (int)count($a_html[$s_tagName]);
// get the tag options, like src="htt://". Here, s_tagTokOption is 'src' and s_tagTokValue is '"http://"'
do {
//$s_tagTokOption = strtoupper(strtok($s_tagOption[1], "="));
$s_tagTokOption = strtok($s_tagOption[1], "=");
$s_tagTokValue = trim(strtok(""),'"'); //cambiado para funcionar con '=' dentro de un atributo
$a_html[$s_tagName][$i_arrayCounter][$s_tagTokOption] = $s_tagTokValue;
$b_boolOptions = is_array(($s_tagOption=each($a_tag))) && $s_tagOption[1];
} while( $b_boolOptions );
}
}
return $a_html;
}
function haz_codigo_youtube($embed_o_url, $color1=NULL, $color2=NULL, $ancho=NULL, $alto=NULL, $mostrar_relacionados=NULL, $permitir_pantalla_completa=NULL, $poner_borde=NULL, $idioma=NULL){
//miramos si es un embed o un enlace normal:
if (strpos($embed_o_url,',')!== FALSE) {
$emburls = explode(',',$embed_o_url);
} else {
$emburls = array($embed_o_url);
}
$return = '';
foreach($emburls as $embed_o_url) {
$qs = '';
if (strpos($embed_o_url,'/watch?')!== FALSE) {
$codigo_video = saca_codigo_youtube($embed_o_url);
$opciones = saca_opciones_url_youtube($embed_o_url);
} else {
$atrib = saca_atributos_embed_youtube($embed_o_url);
$ancho = is_null($ancho) ? $atrib['width'] : $ancho;
$alto = is_null($alto) ? $atrib['height'] : $alto;
$codigo_video = saca_codigo_embed_youtube($embed_o_url);
$opciones = saca_opciones_embed_youtube($embed_o_url);
}
if (!is_null($color1)) $opciones['color1'] = "0x".ltrim($color1,"#0x");
if (!is_null($color2)) $opciones['color2'] = "0x".ltrim($color2,"#0x");
if (!is_null($idioma)) $opciones['hl'] = $idioma;
if (!is_null($permitir_pantalla_completa)) $opciones['fs'] = $permitir_pantalla_completa;
if (!is_null($mostrar_relacionados)) $opciones['rel'] = $mostrar_relacionados;
if (!is_null($borde)) $opciones['border'] = $borde;
if (is_null($ancho)) $ancho = 425;
if (is_null($alto)) $alto = 344;
if (!isset($opciones['hl'])) $opciones['hl'] = 'es'; //idioma
if (!isset($opciones['fs'])) $opciones['fs'] = 1; //permitir pantalla completa
if (!isset($opciones['rel'])) $opciones['rel'] = 0; //mostrar videos relacionados
if (!isset($opciones['border'])) $opciones['border'] = 0; //mostrar videos relacionados
if (!empty($opciones) && is_array($opciones)) {
foreach($opciones as $k => $v) {
if (!empty($k)) {
$qs.="&{$k}={$v}";
}
}
}
ob_start();
?>
No se puede mostrar el video.
$return.= ob_get_clean();
}
return $return;
}
function thumb_codigo_youtube($codigo_video, $grande=FALSE){
return "http://img.youtube.com/vi/".$codigo_video."/".($grande ? '0' : '2').".jpg";
}
function thumb_youtube($embed_o_url, $grande=FALSE){
if (strpos($embed_o_url,'/watch?')!== FALSE) {
$codigo_video = saca_codigo_youtube($embed_o_url);
} else {
$codigo_video = saca_codigo_embed_youtube($embed_o_url);
}
return thumb_codigo_youtube($codigo_video,$grande);
}
function enlace_youtube($embed_o_url){
if (strpos($embed_o_url,'/watch?')!== FALSE) {
$codigo_video = saca_codigo_youtube($embed_o_url);
} else {
$codigo_video = saca_codigo_embed_youtube($embed_o_url);
}
return "http://www.youtube.com/watch?v=".$codigo_video;
}
function info_codigo_youtube($codigo_video){
$url = "http://gdata.youtube.com/feeds/api/videos?lr=es&max-results=1&q=".$codigo_video;
//$url = "http://gdata.youtube.com/feeds/api/videos?max-results=1&alt=json&q=".$codigo_video;
require_once("rss-reader.inc.php");
$arr=recibe_rss($url);
//echo array_f($arr);
$datos['titulo'] = utf8_decode($arr['MEDIA:TITLE'][0]);
$datos['descripcion'] = utf8_decode($arr['DESCRIPTION'][0]);
$datos['fecha'] = utf8_decode($arr['PUBDATE'][0]);
$datos['keywords'] = utf8_decode($arr['MEDIA:KEYWORDS'][0]);
return $datos;
}
function info_youtube($embed_o_url){
if (strpos($embed_o_url,'/watch?')!== FALSE) {
$codigo_video = saca_codigo_youtube($embed_o_url);
} else {
$codigo_video = saca_codigo_embed_youtube($embed_o_url);
}
return info_codigo_youtube($codigo_video);
}
?>
##
## 12-11-08
##
function limpia_texto($texto,$entities=FALSE) {
$malos=array("`","´","’","“","”","…","«","»","€"," ",""," ",'"');
$buenos=array("‘","’","’","“","”","...","«","»","€"," ",""," ",""");
return $entities ? str_replace($malos, $buenos, nl2br(htmlentities($texto))) : str_replace($malos, $buenos, nl2br($texto));
}
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
function myTruncate2($string, $limit, $break=" ", $pad="...") {
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit) return $string;
$string = substr($string, 0, $limit);
if(false !== ($breakpoint = strrpos($string, $break))) {
$string = substr($string, 0, $breakpoint);
} return $string . $pad;
}
function corta_cadena($texto, $tamano = 130){
//corta la cadena por un espacio
$etiquetas=array('b','i','strong','em'); //etiquetas que intentará cerrar
$texto = myTruncate2($texto, $tamano, " ", '…');
foreach ($etiquetas as $k => $et){
while ( substr_count($texto,''.$et.'>') < substr_count($texto,'<'.$et.'>') ) {
$texto.=''.$et.'>';
}
}
return $texto;
}
function elimina_caracteres_malos($texto) {
$malos=array("`","´","’","“","”","…","«","»","€","@","#","$","%","&","|");
return str_replace($malos, '_', $texto);
}
function elimina_acentos($cadena,$espacios = '_'){
$tofind = "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñºª";
$replac = "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNnoa";
$a_espacios = " _-*";
return (strtr($cadena,$tofind.$a_espacios,$replac.str_repeat($espacios,strlen($a_espacios))));
}
function deja_alfanum($cadena,$sep = '_', $permitidos=''){
return strtolower(preg_replace("/[^a-zA-Z0-9".$permitidos.$sep."]/s",'',elimina_acentos(trim($cadena),$sep)));
}
function genera_password($caracteres=8) {
$totalChar = $caracteres; // number of chars in the password
$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789123456789123456789"; // salt to select chars from
srand((double)microtime()*1000000); // start the random generator
$password=""; // set the inital variable
for ($i=0;$i<$totalChar;$i++) { // loop and create password
$password = $password . substr ($salt, rand() % strlen($salt), 1);
}
return $password;
}
function valido_email($email) {
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email);
}
function tamano_archivo($archivo,$decimales=0){
$size = filesize($archivo);
$bytes=array( 'B','KB','MB','GB','TB' );
foreach( $bytes as $val ) {
if( $size > 1024 ) {
$size=$size / 1024;
} else {
break;
}
}
return round( $size,$decimales ).$val;
}
//añadido
function deja_link($cadena){
return substr(deja_alfanum($cadena,'-'),0,255);
}
?>
##
## 13-06-08
##
//// funciones fechas
function hoy(){
return date("Y-m-d");
}
function dia($datemysql) {
// recibe AAAA-MM-DD y devuelve DD
$datemysql=current(explode(" ",$datemysql));
$fecha=explode("-",$datemysql);
return $fecha[2];
}
function mes($datemysql) {
// recibe AAAA-MM-DD y devuelve MM
$datemysql=current(explode(" ",$datemysql));
$fecha=explode("-",$datemysql);
return $fecha[1];
}
function anio($datemysql) {
// recibe AAAA-MM-DD y devuelve AAAA
$datemysql=current(explode(" ",$datemysql));
$fecha=explode("-",$datemysql);
return $fecha[0];
}
function hora($datemysql) {
list($fecha,$hora)=explode(" ",$datemysql);
list($hora,$min,$seg)=explode(":",$hora);
return $hora;
}
function minuto($datemysql) {
list($fecha,$hora)=explode(" ",$datemysql);
list($hora,$min,$seg)=explode(":",$hora);
return $min;
}
function segundo($datemysql) {
list($fecha,$hora)=explode(" ",$datemysql);
list($hora,$min,$seg)=explode(":",$hora);
return $seg;
}
function haz_fecha($id_fecha="fecha"){
//se usa con los formularios de fecha creados con la función 'select_fecha'
//devuelve AAAA-MM-DD seleccionado con el mismo
if (($_POST[$id_fecha.'_dia'] > 0) && ($_POST[$id_fecha.'_mes'] > 0) && ($_POST[$id_fecha.'_anio'] > 0)) {
$ndia=$_POST[$id_fecha.'_dia'];
$nmes=$_POST[$id_fecha.'_mes'];
$nanio=$_POST[$id_fecha.'_anio'];
return $nanio.'-'.$nmes.'-'.$ndia;
} else return NULL;
}
function haz_fecha_hora($id_fecha="fecha"){
//se usa con los formularios de fecha creados con la función 'select_fecha'
//devuelve AAAA-MM-DD seleccionado con el mismo
if (($_POST[$id_fecha.'_dia'] > 0) && ($_POST[$id_fecha.'_mes'] > 0) && ($_POST[$id_fecha.'_anio'] > 0)) {
return $_POST[$id_fecha.'_anio'].'-'.$_POST[$id_fecha.'_mes'].'-'.$_POST[$id_fecha.'_dia'].' '.$_POST[$id_fecha.'_hora'].':'.$_POST[$id_fecha.'_min'].':'.$_POST[$id_fecha.'_seg'];
} else return NULL;
}
/*function select_fecha($id_fecha="fecha", $clase="" , $dia_sel=0, $mes_sel=0, $anio_sel=0, $rango_anios=2 ){
// crea dos campos 'select' con dias, meses y años. Para recuperar la fecha en formato 'DATE' de
//mysql, utilizar la función 'haz_fecha' con el mismo $id_fecha.W
$meses=array("------","Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
echo ("\r\n\t\t".'día: ');
echo ("\r\n\t\t".'');
for ($i = 0; $i <=31; $i++){
$sel="";
if ($i == $dia_sel) $sel=" selected";
$nom = $i;
if ($i == 0) $nom="--";
echo ("\r\n\t\t\t".''.$nom.' ');
}
echo ("\r\n\t\t".' ');
echo ("\r\n\t\t".'mes: ');
echo ("\r\n\t\t".'');
foreach ($meses as $num=>$nom ){
$sel="";
if ($num == $mes_sel) $sel=" selected";
echo ("\r\n\t\t\t".''.$nom.' ');
}
echo ("\r\n\t\t".' ');
echo ("\r\n\t\t".'año: ');
echo ("\r\n\t\t".'');
echo ("\r\n\t\t\t".'---- ');
if ($anio_sel<1900){
$anio_sel= date("Y");
$sin_anio_seleccionado = TRUE;
}
$anio_inicio= date("Y");
if (strstr($rango_anios, '+')) {
$rango_anios = intval(str_replace('+','',$rango_anios));
$rango_anios_abajo = 0;
$rango_anios_arriba = $rango_anios;
} else if (strstr($rango_anios, '-')) {
$rango_anios = intval(str_replace('-','',$rango_anios));
$rango_anios_abajo = $rango_anios;
$rango_anios_arriba = 0;
} else {
$rango_anios_abajo = ceil($rango_anios / 2);
$rango_anios_arriba = ceil($rango_anios / 2);
}
$primero = ($anio_sel < $anio_inicio) ? $anio_sel : $anio_inicio;
for ($i = ($anio_inicio+$rango_anios_arriba); $i >=($primero - $rango_anios_abajo); $i--){
$sel="";
if (!$sin_anio_seleccionado && $i == $anio_sel) $sel=" selected";
echo ("\r\n\t\t\t".''.sprintf("%04d",$i).' ');
}
echo ("\r\n\t\t".' ');
}*/
function formatea_fecha($datemysql){
// recibe AAAA-MM-DD y devuelve DD-MM-AAAA
if (strstr($datemysql,' ')) list($datemysql,$hora) = explode(' ',$datemysql);
$fecha=explode("-",$datemysql);
return $fecha[2].'-'.$fecha[1].'-'.$fecha[0];
}
function formatea_fecha_letra($datemysql){
// recibe AAAA-MM-DD y devuelve D de Mes de AAAA
$fecha=explode("-",$datemysql);
$meses=array("------","Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
return (intval($fecha[2]).' de '.$meses[intval($fecha[1])].' de '.$fecha[0]);
}
function formatea_fecha_mysql($mysqldate, $formato = "d-m-Y H:i" ) {
if (strlen($mysqldate) > 10) {
list($year, $month, $day_time) = explode('-', $mysqldate);
list($day, $time) = explode(" ", $day_time);
list($hour, $minute, $second) = explode(":", $time);
$ts = mktime($hour, $minute, $second, $month, $day, $year);
} else {
list($year, $month, $day) = explode('-', $mysqldate);
$ts = mktime(0, 0, 0, $month, $day, $year);
}
return date($formato,$ts);
}
function haz_fecha_noanio($id_fecha="fecha"){
//se usa con los formularios de fecha creados con la función 'select_fecha_noanio'
//devuelve AAAA-MM-DD seleccionado con el mismo
$ndia=$_POST[$id_fecha.'_dia'];
$nmes=$_POST[$id_fecha.'_mes'];
$nanio="2000"; //no importa;
return $nanio.'-'.$nmes.'-'.$ndia;
}
function select_fecha_noanio($id_fecha="fecha", $clase="",$dia_sel=0, $mes_sel=0){
// crea dos campos 'select' con los dias y los meses
$meses=array("------","Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
echo ('');
for ($i = 0; $i <=31; $i++){
$sel="";
if ($i == $dia_sel) $sel=" selected";
$nom = $i;
if ($i == 0) $nom="--";
echo (' '.$nom.' ');
}
echo (' ');
echo ('');
foreach ($meses as $num=>$nom ){
$sel="";
if ($num == $mes_sel) $sel=" selected";
echo (' '.$nom.' ');
}
echo (' ');
}
function select_anio($id_fecha="fecha", $clase="", $anio_sel=0, $rango_anios=7, $cifras_value=4 ){
// crea dos campos 'select' con dias, meses y años. Para recuperar la fecha en formato 'DATE' de
//mysql, utilizar la función 'haz_fecha' con el mismo $id_fecha.W
if ($cifras_value != 2) $cifras_value = 4;
echo ("\r\n\t\t".'año: ');
echo ("\r\n\t\t".'');
echo ("\r\n\t\t\t".'---- ');
if ($anio_sel<1900){
$anio_sel= date("Y");
$sin_anio_seleccionado = TRUE;
}
$rango_anios_abajo = 0;
$rango_anios_arriba = 0;
$anio_inicio= date("Y");
if (strstr($rango_anios, '+') && strstr($rango_anios, '-')) {
if (strpos($rango_anios, '+') < strpos($rango_anios, '-')) { // + va antes que -
list($rango_anios_arriba, $rango_anios_abajo) = explode('-',$rango_anios);
$rango_anios_arriba = intval(str_replace('+','',$rango_anios_arriba));
} else {
list($rango_anios_abajo, $rango_anios_arriba) = explode('+',$rango_anios);
$rango_anios_abajo = intval(str_replace('-','',$rango_anios_abajo));
}
} else if (strstr($rango_anios, '+')) {
$rango_anios = intval(str_replace('+','',$rango_anios));
$rango_anios_arriba = $rango_anios;
} else if (strstr($rango_anios, '-')) {
$rango_anios = intval(str_replace('-','',$rango_anios));
$rango_anios_abajo = $rango_anios;
} else {
$rango_anios_abajo = ceil($rango_anios / 2);
$rango_anios_arriba = ceil($rango_anios / 2);
}
$primero = ($anio_sel < $anio_inicio) ? $anio_sel : $anio_inicio;
for ($i = ($anio_inicio+$rango_anios_arriba); $i >=($primero - $rango_anios_abajo); $i--){
$sel="";
if (!$sin_anio_seleccionado && $i == $anio_sel) $sel=" selected";
$value = ($cifras_value == 4) ? sprintf("%04d",$i) : substr(sprintf("%04d",$i), -2, 2);
echo ("\r\n\t\t\t".''.sprintf("%04d",$i).' ');
}
echo ("\r\n\t\t".' ');
}
/*
function select_anio($id_fecha="fecha", $clase="", $anio_sel=0, $rango_anios=2, $cifras_value=4 ){
// crea dos campos 'select' con dias, meses y años. Para recuperar la fecha en formato 'DATE' de
//mysql, utilizar la función 'haz_fecha' con el mismo $id_fecha.W
if ($cifras_value != 2) $cifras_value = 4;
echo ("\r\n\t\t".'año: ');
echo ("\r\n\t\t".'');
echo ("\r\n\t\t\t".'---- ');
if ($anio_sel<1900){
$anio_sel= date("Y");
$sin_anio_seleccionado = TRUE;
}
$anio_inicio= date("Y");
if (strstr($rango_anios, '+')) {
$rango_anios = intval(str_replace('+','',$rango_anios));
$rango_anios_abajo = 0;
$rango_anios_arriba = $rango_anios;
} else if (strstr($rango_anios, '-')) {
$rango_anios = intval(str_replace('-','',$rango_anios));
$rango_anios_abajo = $rango_anios;
$rango_anios_arriba = 0;
} else {
$rango_anios_abajo = ceil($rango_anios / 2);
$rango_anios_arriba = ceil($rango_anios / 2);
}
$primero = ($anio_sel < $anio_inicio) ? $anio_sel : $anio_inicio;
for ($i = ($anio_inicio+$rango_anios_arriba); $i >=($primero - $rango_anios_abajo); $i--){
$sel="";
if (!$sin_anio_seleccionado && $i == $anio_sel) $sel=" selected";
$value = ($cifras_value == 4) ? sprintf("%04d",$i) : substr(sprintf("%04d",$i), -2, 2);
echo ("\r\n\t\t\t".''.sprintf("%04d",$i).' ');
}
echo ("\r\n\t\t".' ');
}
*/
function select_mes($id_fecha="fecha", $clase="", $mes_sel=0, $como_numero = FALSE){
// crea dos campos 'select' con dias, meses y años. Para recuperar la fecha en formato 'DATE' de
//mysql, utilizar la función 'haz_fecha' con el mismo $id_fecha.W
$meses=array("------","Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
echo ("\r\n\t\t".'mes: ');
echo ("\r\n\t\t".'');
foreach ($meses as $num=>$nom ){
$sel="";
if ($num == $mes_sel) $sel=" selected";
if ($como_numero) echo ("\r\n\t\t\t".''.(($num == 0) ? '--' : sprintf("%02d",$num)).' ');
else echo ("\r\n\t\t\t".''.$nom.' ');
}
echo ("\r\n\t\t".' ');
}
function select_dia($id_fecha="fecha", $clase="" , $dia_sel=0){
// crea dos campos 'select' con dias, meses y años. Para recuperar la fecha en formato 'DATE' de
//mysql, utilizar la función 'haz_fecha' con el mismo $id_fecha.W
echo ("\r\n\t\t".'día: ');
echo ("\r\n\t\t".'');
for ($i = 0; $i <=31; $i++){
$sel="";
if ($i == $dia_sel) $sel=" selected";
$nom = $i;
if ($i == 0) $nom="--";
echo ("\r\n\t\t\t".''.$nom.' ');
}
echo ("\r\n\t\t".' ');
}
function select_fecha($id_fecha="fecha", $clase="" , $dia_sel=0, $mes_sel=0, $anio_sel=0, $rango_anios=7, $como_numero = FALSE ){
select_dia($id_fecha, trim('dia '.$clase), $dia_sel);
select_mes($id_fecha, trim('mes '.$clase), $mes_sel, $como_numero);
select_anio($id_fecha, trim('anio '.$clase), $anio_sel, $rango_anios);
}
function select_fecha_hora($id_fecha="fecha", $clase="" , $dia_sel=0, $mes_sel=0, $anio_sel=0, $hora_sel= 0, $min_sel = 0, $seg_sel = 0, $rango_anios=7, $como_numero = FALSE ){
select_dia($id_fecha, trim('dia '.$clase), $dia_sel);
select_mes($id_fecha, trim('mes '.$clase), $mes_sel, $como_numero);
select_anio($id_fecha, trim('anio '.$clase), $anio_sel, $rango_anios);
?>
Hora:
:Min:
:Seg:
}
?>
$ar_categorias = array(
'Normativa' => '1',
'Enlaces' => '2',
'Documentos' => '3',
'Preguntas más frecuentes' => '4',
'Formación' => '5',
'Actualidad' => '6'
);
?>
Asociación de Voluntariado en Geriatría
@include('head.inc.php') ?>