/** * Get the number of times this URL has been shared * @param Model_Blog_Post The post */ public function share_count(Model_Blog_Post $post) { $url = self::COUNT_URL . '?' . http_build_query(array('url' => $post->url(true))); $data = json_decode(file_get_contents($url)); if (empty($data) || empty($data->count)) { return 0; } return $data->count; }
/** * Get the number of times this URL has been shared * @param Model_Blog_Post The post */ public function share_count(Model_Blog_Post $post) { // Get the count using FQL. Returns *both* like count and share count. $query = sprintf(self::LINK_QUERY, $post->url(true)); $url = self::QUERY_URL . '?' . http_build_query(array('query' => $query)); $data = simplexml_load_file($url); if (empty($data) || empty($data->link_stat) || empty($data->link_stat->total_count)) { return 0; } return (int) $data->link_stat->total_count; }
/** * Get the number of times this URL has been shared * @param Model_Blog_Post The post */ public function share_count(Model_Blog_Post $post) { $url = self::API_URL . '?' . http_build_query(array('url' => $post->url(true))); $data = file_get_contents($url); // Ugly hack to get JSON data from the JavaScript method call $data = str_replace(array('IN.Tags.Share.handleCount(', ');'), '', $data); $data = json_decode($data); if (empty($data)) { return 0; } return $data->count; }
/** * Get the number of times this URL has been shared * @param Model_Blog_Post The post */ public function share_count(Model_Blog_Post $post) { $total = 0; $url = self::API_URL . '?' . http_build_query(array('url' => $post->url(true))); $data = json_decode(file_get_contents($url)); if (empty($data) || empty($data->data) || empty($data->data->children)) { return 0; } // Need to add up the points in every submission of this URL foreach ($data->data->children as $child) { $total += $child->data->score; } return $total; }