Tema: Validar URL
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/01/2016, 23:08
Juanjo87
 
Fecha de Ingreso: enero-2016
Mensajes: 19
Antigüedad: 8 años, 4 meses
Puntos: 0
Respuesta: AYUDA!Validar URL

Código PHP:
function peliculas_meta(){
    global $nombre_servidor;
    global $tipo_audio;
    global $tipo_calidad;
    global $enlace_roto;
    global $post;
    $data = get_post_meta($post->ID, "peliculas_data", true);
    echo '<div id="peliculas_items">';
    if (!empty($data)) {
        foreach((array)$data as $c => $p ){  
            if (isset($p['calidad']) || isset($p['audio']) || isset($p['servidor']) || isset($p['enlace']) || isset($p['user']) || isset($p['roto'])){
                echo Print_peliculas_fileds($c, $p);
            }
        }
    }
    echo '</div>';
?>
        <span id="here"></span>
        <span class="add"><?php
    
echo __('Nueva Pelicula');
    
    
$add_to_ID get_post_meta($post->ID,"_linksAutoincrement",true);
    if ( empty( 
$add_to_ID ) )
        
$add_to_ID 0;
    
$add_to_ID $add_to_ID 1;
?></span>
        <script>
            var $ =jQuery.noConflict();
                $(document).ready(function() {
                var count = <?php echo $add_to_ID;?>;
                $(".add").click(function() {
                    count = count + 1;
                    $('#peliculas_items').append('<p style="margin-bottom: 22px;"><label>Servidor</label><select name="peliculas_data[' + count + '][servidor] id="servidor"><?php
    
foreach ($nombre_servidor as $nombre_servidores) {
        echo 
'<option value="' $nombre_servidores '">' $nombre_servidores '</option>';
    }
?></select><label>Audio</label><select name="peliculas_data[' + count + '][audio] id="audio"><?php
    
foreach ($tipo_audio as $tipo_audios) {
        echo 
'<option value="' $tipo_audios '">' $tipo_audios '</option>';
    }
?></select><label>Calidad</label><select name="peliculas_data[' + count + '][calidad] id="calidad"><?php
    
foreach ($tipo_calidad as $tipo_calidades) {
        echo 
'<option value="' $tipo_calidades '">' $tipo_calidades '</option>';
    }
?></select><label>Enlace roto:</label><select name="peliculas_data[' + count + '][roto] id="roto"><?php
    
foreach ($enlace_roto as $enlace_rotos) {
        echo 
'<option value="' $enlace_rotos '">' $enlace_rotos '</option>';
    }
?></select></br><label>enlace :</label><br><input type="text" style="width: 80%;" name="peliculas_data[' + count + '][enlace]" value=""/><br>    <label>usuario:</label><br><input type="text" style="width: 80%;" name="peliculas_data[' + count + '][user]" value=""/><br> <input type="hidden" name="peliculas_data[' + count + '][new]" value="1"/>  <input type="hidden" name="peliculas_data[' + count + '][removed]" class="removeinput" value="0"/>  <input type="hidden" name="peliculas_data[' + count + '][idlink]" value="' + count + '"/>  <span class="remove">Remove</span></p>');
                   return false;
                });
                $(".remove").live('click', function() {
                    $(this).parent().find(".removeinput").val("1").parent().hide();
                });
            });
        </script>
        <style>#peliculas_items {list-style: none;}</style>
    <?php
}

//Save product peliculas
add_action('save_post''guardar_peliculas');

function 
guardar_peliculas($post_id){
    global 
$post;
    
// to prevent metadata or custom fields from disappearing... 
    
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return 
$post_id;
    
// OK, we're authenticated: we need to find and save the data
    
if (isset($_POST['peliculas_data'])) {
        
$data $_POST['peliculas_data']; 
        
    
$existing_list get_post_meta($post->ID,"peliculas_data",true); 
    if (empty(
$existing_list))
        
$existing_list = array();
    
    
$add_to_ID get_post_meta($post->ID,"_linksAutoincrement",true);
    if ( empty( 
$add_to_ID ) )
        
$add_to_ID 0;
        
    foreach((array)
$data as $p ){ //proceso cada link de la peticion editando el array de links de la base de datos por si alguien agrego un link mientras editaba
        
if ( ! is_numeric$p["idlink"] ) )
            die(
"Wrong ID!");
        
$p["idlink"] = abs(intval($p["idlink"]));
        if ( ! 
$p["idlink"])
            die(
"Wrong ID!");
        if (
$p["new"]=="1"){ //link nuevo
            
if ($p["removed"]=="0"){ //si la agrego y elimino en la misma edicion no se hace nada
                
$add_to_ID $add_to_ID 1;
                if (isset(
$existing_list[$add_to_ID]))
                    die(
"Ya existe el ID: ".$add_to_ID);
                unset(
$p["removed"]);
                unset(
$p["new"]);
                unset(
$p["idlink"]);
                if (
validarLink($p)==false)
                    die(
"Un campo no esta entre los permitidos");
                if (
filter_var($p['enlace'], FILTER_VALIDATE_URL) !== false){
                    
$existing_list[$add_to_ID] = $p;
                }else{
                    die(
"enlace no valido: " htmlspecialchars($p['enlace']));
                }
            }
        }else if (
$p["removed"]=="1"){ //link removido
            
if (isset($existing_list[$p["idlink"]]))
                unset(
$existing_list[$p["idlink"]]); //elimino el link (no re-indexa)
        
}else if (isset($existing_list[$p["idlink"]])){
            unset(
$p["removed"]);
            unset(
$p["new"]);
            
$id $p["idlink"];
            unset(
$p["idlink"]);
            if (
validarLink($p)==false)
                die(
"Un campo no esta entre los permitidos");
            if (
filter_var($p['enlace'], FILTER_VALIDATE_URL) !== false){
                
$existing_list[$id] = $p;
            }else{
                die(
"enlace no valido: " htmlspecialchars($p['enlace']));
            }
        }
    }
    
update_post_meta($post_id'peliculas_data'$existing_list);
    
update_post_meta($post->ID'_linksAutoincrement'$add_to_ID);
    }
}


function 
validarLink($p){
    global 
$nombre_servidor;
    global 
$tipo_audio;
    global 
$tipo_calidad;
    global 
$enlace_roto;
    if (
in_array($p['servidor'],$nombre_servidor)){
        if (
in_array($p['audio'],$tipo_audio)){
            if (
in_array($p['calidad'],$tipo_calidad)){
                if (
in_array($p['roto'],$enlace_roto)){
                    return 
true;
                }
            }
        }
    }
    return 
false;
}
?>