From c2306e9bebb4806c99988bde57f284f1b8146e0f Mon Sep 17 00:00:00 2001 From: Mark Hamstra Date: Mon, 16 Apr 2012 02:32:06 +0300 Subject: [PATCH] Add some sanity checking We're checking if $graphdata was a valid JSON string ($response will be false if it wasn't), we check if $response is an array and if the "likes" key is actually set. --- fblikes.snippet.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fblikes.snippet.php b/fblikes.snippet.php index d0b8faa..900b002 100644 --- a/fblikes.snippet.php +++ b/fblikes.snippet.php @@ -43,6 +43,9 @@ $graphdata = file_get_contents("http://graph.facebook.com/".$pageid); // decode json response $response = $modx->fromJSON($graphdata); + if (!$response || !is_array($response) || !isset($response['likes'])) { + return 'Data currently not available.'; + } // get like number $data = $response['likes'];