Facebook Comment Import Fix

Viele Host unterstüzen kein Curl Foppen was dazu führt das einige WordPress Plugins welche externe Daten abfragen nicht richtig  laufen oder Fehler zurück geben. Eines der brauchbarsten Plugins ist Import Facebook Comment to WordPress Blog (letztes Update 2011) . Indem man anstelle foppen command  file_get_contents das sichere curl verwendet. Vor allem auf shared Host ist foppen meist aus Sichheitsgründen deaktiviert.

Hier eine kleine Zusamenfassung eines Workaround

Orginal in #FacebookCommentImport.php  


private function fetchCommentsFor($permalink, $locale) {        // DEBUG:        // $permalink = "https://gotvarstvo.georgievi.net/a/cvetnica";        $request_url = "https://graph.facebook.com/comments/?ids=" .                urlencode($permalink);        if ($locale != '') $request_url .= '&locale=' . $locale;

        $requests = @file_get_contents($request_url);        if ($requests === FALSE) return FALSE;

        return @current(json_decode($requests, TRUE));    }

Mit austauscht läuft das Plugin auch auf foppen disabled Domains

private function fetchCommentsFor($permalink, $locale) {				  $permalink = get_permalink();

				  $ch = curl_init();				  $timeout = 10; // set to zero for no timeout				  curl_setopt ($ch, CURLOPT_URL, "https://graph.facebook.com/comments/?ids=" .										  urlencode($permalink));				  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);				  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);				  $requests = curl_exec($ch);				  curl_close($ch);

        if ($requests === FALSE) return FALSE;

        return @current(json_decode($requests, TRUE));    }

Ähnlich kann man vorgehen bei anderen WP Plugins wie Kevinkorb vorschlägt.

Anstelle eine XML via abzufragen

$xml_string = file_get_contents("https://www.pinterest.com/rss/boards.xml");

 

Mit einer neun Classe für file_get

<?phpclass CA_HTTP {

    public static function get_contents($url) {        $ch = curl_init();        curl_setopt ($ch, CURLOPT_URL, $url);        curl_setopt ($ch, CURLOPT_HEADER, 0);        ob_start();        curl_exec ($ch);        curl_close ($ch);        return ob_get_clean();      }

}?>

Der alte code ersetzt mit der neuen classe 

<?php$url = "https://www.yahoo.com";//old, unavailable but great function.$content1 = file_get_contents($url);

//new, based on curl$content2 = CA_HTTP::get_contents($url);?>

Ein kurze suche im WP Plugin verzeichniss zeigt das einige weitere Facebook Plugins noch umgestellt gehören. Folgende nutzen noch immer foppen .

Embed Facebook , W3 Page Speed , W3 minify import prozessor , Autopost Thumbnail, WP-O-Matic 

Noch ein Fehler der Auftretten kann plus fix nach benjiballin 

Invalid argument supplied for foreach() in 

/blog/wp-content/plugins/facebook-import-comments/classes/FacebookCommentImporter.php on line 189

Zeile 39
if (is_array($locComments) && is_array($locComments['data']))

Neu:
if (is_array($locComments) && is_array($locComments['comments']['data']))

und Zeile  43
$helper->import($comments['data'], $this->importMode);

Neu:
$helper->import($comments['comments']['data'], $this->importMode);

Da weitere Änderungen am Plugin vorgenommen sind werde ich den Fix händisch ergänzen.