function _fb_social_comments_comments_count in Facebook social plugins integration 6.2
Same name and namespace in other branches
- 7.2 plugins/fb_plugin/comments.inc \_fb_social_comments_comments_count()
Get the nr of fb comments given an url (node url)
1 call to _fb_social_comments_comments_count()
- _fb_social_comments_link in plugins/
fb_plugin/ comments.inc - Pseudo hook_link for this plugin
File
- plugins/
fb_plugin/ comments.inc, line 250
Code
function _fb_social_comments_comments_count($url, $preset) {
$cache_key = md5('fb_social_comments_count' . $url);
$cache_length = $preset->settings['plugin_comments_count']['cache'];
$nr_comments = 0;
if ($cache = cache_get($cache_key)) {
$nr_comments = $cache->data;
}
else {
$req_url = "https://graph.facebook.com/?ids=" . $url;
$request = drupal_http_request($req_url);
if ($request->code == 200) {
$result = json_decode($request->data);
if (isset($result->{$url}->comments)) {
$nr_comments = $result->{$url}->comments;
}
}
cache_set($cache_key, $nr_comments, 'cache', REQUEST_TIME + 60 * $cache_length);
}
return $nr_comments;
}