Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added functionality to decrease comment count after deleting a comment

  • Loading branch information...
commit 21f75c6f0f3ebe9fd3a272849a02e0e5645f8fc9 1 parent 5fa4bda
@selfthinker selfthinker authored
Showing with 25 additions and 6 deletions.
  1. +9 −3 facebook-comments-ajax.php
  2. +16 −3 facebook-comments-display.php
View
12 facebook-comments-ajax.php
@@ -14,18 +14,24 @@
}
global $fbc_options;
+ $count = get_option("fbComments_commentCount_{$_POST['xid']}");
// Check if we want to update the comment count or send a notification email
switch ($_POST['fn']) {
// Update Facebook comment count
case "addComment":
+ $newCount = $count+1;
+ // no break on purpose
+
+ case "removeComment":
+ $newCount = $count-1;
+
fbComments_log('In ' . basename(__FILE__) . " with fn={$_POST['fn']}, xid={$_POST['xid']}");
- $count = get_option("fbComments_commentCount_{$_POST['xid']}");
- if (update_option("fbComments_commentCount_{$_POST['xid']}", $count+1)) {
+ if (update_option("fbComments_commentCount_{$_POST['xid']}", $newCount)) {
fbComments_log(sprintf(' Updated Facebook comment count from %d to %d', $count, $count+1));
echo 'true';
} else {
- fbComments_log(sprintf(' FAILED to update Facebook comment count from %d to %d', $count, $count+1));
+ fbComments_log(sprintf(' FAILED to update Facebook comment count from %d to %d', $count, $newCount));
echo 'false';
}
View
19 facebook-comments-display.php
@@ -146,12 +146,12 @@ function fbComments_printCommentCatchAndNotificationScripts($xid, $postTitle, $p
<script type='text/javascript'>
var addedComment = function(response) {
//console.log('fbComments: Caught added comment');
- //console.log('fbComments: Making AJAX call to update Facebook comment count');
+ //console.log('fbComments: Making AJAX call to update (increase) Facebook comment count');
jQuery.post('" . FBCOMMENTS_PATH . "facebook-comments-ajax.php', { fn: 'addComment', xid: '$xid' }, function(resp) {
if (resp === 'true') {
- //console.log('fbComments: Updated and cached Facebook comment count for post with xid=$xid');
+ //console.log('fbComments: Updated (increased) and cached Facebook comment count for post with xid=$xid');
} else {
- //console.log('fbComments: FAILED to update Facebook comment count for post with xid=$xid');
+ //console.log('fbComments: FAILED to update (increase) Facebook comment count for post with xid=$xid');
}
});\n";
@@ -170,7 +170,20 @@ function fbComments_printCommentCatchAndNotificationScripts($xid, $postTitle, $p
echo "
};
+ var removedComment = function(response) {
+ //console.log('fbComments: Caught removed comment');
+ //console.log('fbComments: Making AJAX call to update (decrease) Facebook comment count');
+ jQuery.post('" . FBCOMMENTS_PATH . "facebook-comments-ajax.php', { fn: 'removeComment', xid: '$xid' }, function(resp) {
+ if (resp === 'true') {
+ //console.log('fbComments: Updated (decreased) and cached Facebook comment count for post with xid=$xid');
+ } else {
+ //console.log('fbComments: FAILED to update (decrease) Facebook comment count for post with xid=$xid');
+ }
+ });
+ }
+
FB.Event.subscribe('comment.create', addedComment);
+ FB.Event.subscribe('comment.remove', removedComment);
</script>\n";
}
Please sign in to comment.
Something went wrong with that request. Please try again.