You are here

public function ShareaholicShareCount::fancy_count_callback in Share Buttons, Related Posts, Content Analytics - Shareaholic 8

Same name and namespace in other branches
  1. 7.3 lib/social-share-counts/share_count.php \ShareaholicShareCount::fancy_count_callback()

Callback function for Fancy count API Gets the Fancy counts from response

Parameters

Array $response The response from calling the API:

Return value

mixed The counts from the API or false if error

File

lib/social-share-counts/share_count.php, line 265

Class

ShareaholicShareCount
An abstract class Share Counts to be extended

Code

public function fancy_count_callback($response) {
  if ($this
    ->has_http_error($response)) {
    return false;
  }

  // Fancy always provides a JS callback like this in the response:
  // '__FIB.collectCount({"url": "http://www.google.com", "count": 26, "thing_url": "http://fancy.com/things/263001623/Google%27s-Jim-Henson-75th-Anniversary-logo", "showcount": 1});'
  // strip out the callback and parse the JSON from there
  $response['body'] = str_replace('__FIB.collectCount(', '', $response['body']);
  $response['body'] = substr($response['body'], 0, strlen($response['body']) - 2);
  $body = json_decode($response['body'], true);
  return isset($body['count']) ? intval($body['count']) : false;
}