警告foreach()的参数无效

时间:2015-04-04 22:38:20

标签: php wordpress plugins foreach

好的,我最近购买了一个名为WPArcade的wordpress插件,但是,我遇到了一些问题。特别是我不能让我的游戏像他们想象的那样提供。当我试图从像Kongregate这样的游戏中提供游戏时,它会发现0个游戏,但也给了我这个错误:

警告:在第113行的C:\ Program Files(x86)\ ampps \ www \ wp \ wp-content \ plugins \ wparcade-plugin \ feeds \ kongregate \ kongregate.php中为foreach()提供的参数无效

我正在本地服务器上测试该网站,这就是它在C盘中的原因。

Kongregates feed:http://www.kongregate.com/games_for_your_site.xml

插件中的每个发布者都会发生这种情况,但不会向我发出警告。

第113至155行:Kongregate

$xml = simplexml_load_string($get_kongregate_feed);

foreach($xml->game as $game) {  
    $id = intval($game->id);
    $name = mysql_real_escape_string($game->title);
    $check_id = $wpdb->get_var("SELECT id FROM ".$wpdb->prefix."wparcade_kongregate_games WHERE id = '$id'");
    $count = mysql_result(mysql_query("SELECT COUNT(*) as newgames FROM ".$wpdb->prefix."wparcade_kongregate_games WHERE id = '$check_id'"),0);

    if($count !== '1') {
        $name = mysql_real_escape_string($game->title);
        $slug = mysql_real_escape_string($game->title);
        $slug = wparcade_stringforslug($slug);
        $category = mysql_real_escape_string($game->category);
        $category = wparcade_strstr_before($category, " & ");
        if(!$category) $category = mysql_real_escape_string($game->category);
        $categories = mysql_real_escape_string($game->category);
        $categories = str_replace(' & ', ', ', $categories);
        if(!$categories) $categories = mysql_real_escape_string($game->category);
        $description = mysql_real_escape_string($game->description);
        $instructions = mysql_real_escape_string($game->instructions);
        $thumbnail_url = mysql_real_escape_string($game->thumbnail);
        $swf_url = mysql_real_escape_string($game->flash_file);
        $width = $game->width;
        $height = $game->height;
        $tags = strtolower($categories);
        $author = mysql_real_escape_string($game->developer_name);
        $wparcade_kongregate_feed_game_status = $options['kongregate_feed_game_status'];
        $status = $wparcade_kongregate_feed_game_status;
        $feedsinglecat_id = $options['kongregate_feed_single_cat'];
        $feedcategory = get_cat_name($feedsinglecat_id);
        if($feedsinglecat_id !== 'none') { 
            $categories = $feedcategory;
            $category = $feedcategory;
        }

        $sql = "INSERT INTO ".$wpdb->prefix."wparcade_kongregate_games (id, name, slug, description, thumbnail_url, swf_url, width, height, author, categories, category, tags, instructions, status) VALUES ('$id', '$name', '$slug', '$description', '$thumbnail_url', '$swf_url', '$width', '$height', '$author', '$categories', '$category', '$tags', '$instructions', '$status')";

        $list .= '<li class="wparcade_new_games""><strong>'.$name.'</strong></li>';
        $wpdb->query($sql);
        $inserted++;

    } else {
        $list .= '<li class="wparcade_old_games"><strong>'.$name.'</strong></li>';
    }
}

以防万一,这是唯一有效的Feed代码:

$xml = simplexml_load_string($get_scirra_feed);

foreach($xml->game as $game) {  
    $id = intval($game->gameid);
    $name = mysql_real_escape_string($game->name);
    $count = mysql_result(mysql_query("SELECT COUNT(*) as newgames FROM ".$wpdb->prefix."wparcade_scirra_games WHERE id = '$id'"),0);
    $category = mysql_real_escape_string($game->category);
    $slug = mysql_real_escape_string($game->name);
    $slug = wparcade_stringforslug($slug);
    $check_for = $wpdb->get_var("SELECT name FROM ".$wpdb->prefix."wparcade_scirra_games WHERE slug = '$slug'");

    if($count !== '1' && $category !== 'Example' && !$check_for) {
        $name = mysql_real_escape_string($game->name);
        $slug = mysql_real_escape_string($game->name);
        $slug = wparcade_stringforslug($slug);
        $category = mysql_real_escape_string($game->category);
        $category = str_replace('Shooter', 'Shooting', $category);
        $category = str_replace('Defence', 'Defense', $category);
        $category = str_replace('Puzzle', 'Puzzles', $category);
        $category = str_replace('Rotary', 'Arcade, Rotary', $category);
        $categories = $category;
        $description = strip_tags(mysql_real_escape_string($game->description));
        $instructions = strip_tags(mysql_real_escape_string($game->instructions));
        $thumbnail_url = $game->images->small;
        $thumbnail_large_url = $game->images->medium;
        $screen1_url = $game->images->big;
        $embed_url = mysql_real_escape_string($game->embedurl);
        $embed_url = str_replace('http://', '//', $embed_url);
        $embed_url = str_replace('//', 'http://', $embed_url);
        $width = $game->width;
        $height = $game->height;
        $tags = strtolower($categories);
        $author = mysql_real_escape_string($game->author->username);
        $wparcade_scirra_feed_game_status = $options['scirra_feed_game_status'];
        $status = $wparcade_scirra_feed_game_status;
        $feedsinglecat_id = $options['scirra_feed_single_cat'];
        $feedcategory = get_cat_name($feedsinglecat_id);
        if($feedsinglecat_id !== 'none') { 
            $categories = $feedcategory;
            $category = $feedcategory;
        }

        $sql = "INSERT INTO ".$wpdb->prefix."wparcade_scirra_games (id, name, slug, description, thumbnail_url, thumbnail_large_url, screen1_url, embed_url, width, height, author, categories, category, tags, instructions, status) VALUES ('$id', '$name', '$slug', '$description','$thumbnail_url', '$thumbnail_large_url', '$screen1_url', '$embed_url', '$width', '$height', '$author', '$categories', '$category', '$tags', '$instructions', '$status')";

        $list .= '<li class="wparcade_new_games""><strong>'.$name.'</strong></li>';
        $wpdb->query($sql);
        $inserted++;

    } else {
        $list .= '<li class="wparcade_old_games"><strong>'.$name.'</strong></li>';
    }
}

感谢您提前提供任何帮助。

P.S。我在插件的支持网站上询问过,但已经差不多一周了,没有回答。

1 个答案:

答案 0 :(得分:0)

这里的问题是对于Kongregate $ xml-&gt;游戏不是可迭代的对象(如数组)。最简单的调试方法是在第113行尝试插入类似的东西:

print_r($xml->game); 
//or
print_r($xml);

获取数据可见性和不起作用可能有助于您更好地理解为什么这不起作用。祝你好运!