Foros del Web » Creando para Internet » Sistemas de gestión de contenidos » WordPress »

Error en el plugin Flickr comment Importer: Invalid argument supplied for foreach()

Estas en el tema de Error en el plugin Flickr comment Importer: Invalid argument supplied for foreach() en el foro de WordPress en Foros del Web. Hola, Tengo instalado el plugin "Flickr comment Importer" y alguna vez que he entrado en el panel de Wordpress me sale arriba el siguiente error: ...
  #1 (permalink)  
Antiguo 05/12/2009, 11:48
Avatar de ACALU  
Fecha de Ingreso: marzo-2008
Ubicación: Malaga
Mensajes: 123
Antigüedad: 16 años, 1 mes
Puntos: 0
Error en el plugin Flickr comment Importer: Invalid argument supplied for foreach()

Hola,

Tengo instalado el plugin "Flickr comment Importer" y alguna vez que he entrado en el panel de Wordpress me sale arriba el siguiente error:

Cita:
Warning: Invalid argument supplied for foreach() in /homepages/33/d282044401/htdocs/wp-content/plugins/flickr-comment-importer/flickr-comment-importer.php on line 19
Dejo por aqui el codigo del plugin:

Código PHP:
<?php
/*
Plugin Name: Flickr comment Importer
Plugin URI: http://inphotos.org/
Description: Add Flickr comments to your blog posts. <a href='options-general.php?page=flickr-comment-importer.php'>Configuration Page</a>
Author: Donncha O Caoimh
Version: 0.1
Author URI: http://inphotos.org/
*/ 

require_once (ABSPATH WPINC '/rss.php');

function 
flickr_comment_importer() {
    global 
$wpdb;
    
$url get_option'flickrcommenturl' );
    if( !
$url )
        return;
    
$rss = @fetch_rss$url );
    foreach( 
$rss->items as $item ) {
        
$post_name        str_replace"comment-about-"""sanitize_title$item['title'] ) );
        
$comment_author        addslasheswp_specialchars"Flickr: " substrstr_replace"[email protected] ("""wp_specialchars$item'author' ] ) ), 0, -) ) );
        
$comment_author_email    '[email protected]';
        
$comment_author_url    wp_specialchars$item'link' ] );
        
$comment_content    addslashesstrip_tags$item'description' ] ) );
        
$comment_content    substr$comment_contentstrpos$comment_content'comment:' ) + );
        
$comment_type        '';
        
$user_ID        '';

        
$comment_date date("Y-m-d h:i:s"strtotime$item'pubdate' ] ) );
        
$comment_date_gmt date("Y-m-d h:i:s"strtotime$item'pubdate' ] ) + 28800 );
        if( isset( 
$cached_details$post_name ] ) == false ) {
            
$cached_details$post_name ] = $wpdb->get_var"SELECT ID FROM {$wpdb->posts} WHERE post_name = '$post_name'" );
        }
        if( 
$cached_details$post_name ] != null && null == $wpdb->get_var"SELECT comment_ID FROM {$wpdb->comments} WHERE comment_author_url='{$comment_author_url}'" ) ) {
            
$comment_post_ID $cached_details$post_name ];
            
$commentdata compact('comment_post_ID''comment_author''comment_author_email''comment_author_url''comment_content''comment_type''user_ID');
            
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
            
$commentdata['user_ID']         = (int) $commentdata['user_ID'];
            
$commentdata['comment_date']     = $comment_date;
            
$commentdata['comment_date_gmt'] = $comment_date_gmt;

            
$commentdata['comment_author_IP'] = '127.0.0.1';
            
$commentdata['comment_agent']     = "Flickr Add Comment Agent";
            
$commentdata['comment_approved'] = 0;
            
$comment_ID wp_insert_comment($commentdata);
        }
    }
}

if ( ! 
function_exists('wp_nonce_field') ) {
    function 
fci_nonce_field($action = -1) {
        return;    
    }
    
$fci_nonce = -1;
} else {
    function 
fci_nonce_field($action = -1) {
        return 
wp_nonce_field($action);
    }
    
$fci_nonce 'fci-update-key';
}

function 
fci_config_page() {
    global 
$wpdb;
    if ( 
function_exists('add_submenu_page') )
        
add_submenu_page('options-general.php'__('Flickr Comments'), __('Flickr Comments'), 'manage_options'__FILE__'fci_conf');
}

function 
fci_conf() {
    global 
$fci_nonce;
    if ( isset(
$_POST['submit']) ) {
        if ( 
function_exists('current_user_can') && !current_user_can('manage_options') )
            die(
__('Cheatin’ uh?'));

        
check_admin_referer($fci_nonce);
        
$rss = @fetch_rss$_POST'flickrcommenturl' ] );
        if( 
is_object$rss ) == false || empty( $rss->items ) ) {
            
$invalid_url true;
        } else {
            
update_option'flickrcommenturl'$_POST'flickrcommenturl' ] );
        }
    }
?>

<div class="wrap">
<h2><?php _e('Flickr Comment Importer'); ?></h2>
    <p><?php _e"If you use Flickr to host your photos this plugin will import the comments from your Flickr stream into your blog. Enter the RSS feed on Flickr's <a href='http://www.flickr.com/recent_activity.gne'>recent activity page</a> in the box below." );?></p>
    <p><?php _e"<strong>Usage and Restrictions</strong><br /><ul><li> Your posts must have the same name as the Flickr photo. For example, <a href='http://inphotos.org/the-thieving-duck/'>The Thieving Duck</a> blog post matches <a href='http://www.flickr.com/photos/donncha/222686138/'>The Thieving Duck</a> on Flickr. It's ok to have multiple Flickr photos with the same name as one blog post.</li><li> You can't import all your old comments. It will only work with whatever Flickr puts in it's comment feed which is the last ten comments.</li><li> Your comments are imported when you're doing stuff in your WordPress backend and placed into the moderation queue. Make sure you login to WordPress often if you have a busy Flickr stream!</li></ul>" );?></p>

<form action="" method="post" id="fci-conf" style="margin: auto; ">
<?php fci_nonce_field($fci_nonce?>
<h3><label for="key"><?php _e('Flickr Recent Activity RSS Feed'); ?></label></h3>
<p><input id="url" name="flickrcommenturl" type="text" size="85" maxlength="200" value="<?php echo get_option('flickrcommenturl'); ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /></p>
<?php if ( $invalid_url ) { ?>
    <p style="padding: .5em; background-color: #f33; color: #fff; font-weight: bold; width: 30em"><?php _e('That URL is not a RSS feed. Double-check it.'); ?></p>
<?php ?>
    <p class="submit"><input type="submit" name="submit" value="<?php _e('Update RSS Feed &raquo;'); ?>" /></p>
</form>
<p><?php _e"Don't forget to visit <a href='http://inphotos.org/'>In Photos</a>!" ); ?>
</div>
<?php
}

add_action('admin_head''flickr_comment_importer');
add_action('admin_menu''fci_config_page');

?>
¿Alguien sabe por que puede ser?

Un saludo y gracias.
__________________
Fotoblog | http://acalu.es/
  #2 (permalink)  
Antiguo 06/12/2009, 04:03
Avatar de kok
kok
 
Fecha de Ingreso: agosto-2006
Mensajes: 138
Antigüedad: 17 años, 8 meses
Puntos: 2
Respuesta: Error en el plugin Flickr comment Importer: Invalid argument supplied for

A mí me parece que a la persona que escribió el plugin no se le ocurrió verificar que $rss en fetch_rss() se haya obtenido de verdad y foreach() marca error por no pasarle un objeto del tipo adecuado.

Tal vez alguien pueda dar una mejor respuesta. Añadiendo un simple if se puede eliminar el error, pero en ese momento no se va a crear el comentario si hubo un error de comunicación entre el servidor del hosting y Flickr. No siempre se puede contar con poder leer información de otro sitio.

Código PHP:
    $rss = @fetch_rss$url ); 
    if( !
$rss )
        return; 
o

Código PHP:
    $rss = @fetch_rss$url ); 
    if( 
$rss ) {
        foreach(....) {
        ....
        }
    } 
  #3 (permalink)  
Antiguo 08/12/2009, 10:13
Avatar de ACALU  
Fecha de Ingreso: marzo-2008
Ubicación: Malaga
Mensajes: 123
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Error en el plugin Flickr comment Importer: Invalid argument supplied for

Uff, lo siento mucho, pero se me va de las manos, no entiendo tanto de codigo y no entiendo muy bien lo que me dices.

Un saludo.
__________________
Fotoblog | http://acalu.es/
  #4 (permalink)  
Antiguo 21/02/2010, 05:37
Avatar de ACALU  
Fecha de Ingreso: marzo-2008
Ubicación: Malaga
Mensajes: 123
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Error en el plugin Flickr comment Importer: Invalid argument supplied for

El error me sigue saliendo y no encuentro la manera de solucionarlo, ¿alguien me podria ayudar?

Un saludo y gracias.
__________________
Fotoblog | http://acalu.es/
  #5 (permalink)  
Antiguo 16/09/2010, 02:42
Avatar de ACALU  
Fecha de Ingreso: marzo-2008
Ubicación: Malaga
Mensajes: 123
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Error en el plugin Flickr comment Importer: Invalid argument supplied for

Hola de nuevo,

Ahora, sin haber tocado nada, a parte del error, no me importa al fotoblog ningun comentario de Flickr.

Lo de añadir el codigo anterior que me decian, ¿que lo tendria que poner de esta manera?

Código:
$rss = @fetch_rss( $url );
if( !$rss )
        return;
	foreach( $rss->items as $item ) {
Un saludo.
__________________
Fotoblog | http://acalu.es/
  #6 (permalink)  
Antiguo 17/09/2010, 01:36
Avatar de ACALU  
Fecha de Ingreso: marzo-2008
Ubicación: Malaga
Mensajes: 123
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Error en el plugin Flickr comment Importer: Invalid argument supplied for

Harta de este plugin he encontrado otro que hace la misma funcion (y encima importa tambien los comentarios que hago yo misma), se llama "Live Flickr comment importer" (creo que para este asunto solo existen estos 2).

Un saludo.
__________________
Fotoblog | http://acalu.es/
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:52.