nxs_getBackFBComments

The NextScripts: Social Networks Auto-Poster nxs getBackFBComments function.

Description

nxs_getBackFBComments( $postID, $options, $po ); 

Parameters (3)

0. $postid
The postid.
1. $options
The options.
2. $po
The po.

Usage

  1. if ( !function_exists( 'nxs_getBackFBComments' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/inc-cl/fb.php'; 
  3.  
  4. // The postid. 
  5. $postid = null; 
  6.  
  7. // The options. 
  8. $options = null; 
  9.  
  10. // The po. 
  11. $po = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = nxs_getBackFBComments($postid, $options, $po); 
  15.  

Defined (1)

The function is defined in the following location(s).

/inc-cl/fb.php  
  1. if (!function_exists("nxs_getBackFBComments")) { function nxs_getBackFBComments($postID, $options, $po) { $ci = 0; if (empty($options['fbAppPageAuthToken'])) return;  
  2. $options['appsecret_proof'] = hash_hmac('sha256', $options['fbAppPageAuthToken'], $options['fbAppSec']); $wprg = array('sslverify'=>false, 'timeout' => 30);  
  3. $aacct = array('access_token'=>$options['fbAppPageAuthToken'], 'appsecret_proof'=>$options['appsecret_proof'], 'method'=>'get'); $ptype = get_post_type( $postID );  
  4. $res = wp_remote_get( "https://graph.facebook.com/v2.3/".$po['pgID']."/comments?filter=toplevel&limit=250&".http_build_query($aacct, null, '&'), $wprg);  
  5. if (is_wp_error($res) || empty($res['body'])) $badOut['Error'] = ' [ERROR] '.print_r($res, true); else { //prr($res); 
  6. $ret = json_decode($res['body'], true); if (empty($ret)) $badOut['Error'] .= "JSONERROR ".print_r($res, true); else { // prr($ret);  
  7. $impCmnts = get_post_meta($postID, 'snapImportedFBComments', true); if (!is_array($impCmnts)) $impCmnts = array(); //prr($impCmnts);  
  8. if (is_array($ret) && is_array($ret['data'])) foreach ($ret['data'] as $comment) { $cid = $comment['id']; if (trim($cid)=='') continue; 
  9. if (!in_array('fbxcw'.$cid, $impCmnts)) {  
  10. $res = wp_remote_get( "https://graph.facebook.com/v2.3/".$comment['from']['id']."?".http_build_query($aacct, null, '&'), $wprg); $authData = json_decode($res['body'], true); 
  11.  
  12. if ($ptype=='topic') { $my_post = array('post_title' => '', 'post_content' => $comment['message'], 'post_status' => 'publish', 'post_parent' => $postID, 'post_author' => 0, 'post_type' => 'reply'); 
  13. $wpCid = wp_insert_post($my_post); add_post_meta($wpCid, '_bbp_anonymous_name', $comment['from']['name']); $fid = get_post_meta($postID, '_bbp_forum_id', true); 
  14. add_post_meta($wpCid, '_bbp_anonymous_email', $comment['from']['id'].'@facebook.com'); add_post_meta($wpCid, '_bbp_anonymous_website', 'http://www.facebook.com/'.$comment['from']['id']); 
  15. add_post_meta($wpCid, '_bbp_topic_id', $postID); add_post_meta($wpCid, '_bbp_forum_id', $fid); 
  16.  
  17. } else { $commentdata = array( 'comment_post_ID' => $postID, 'comment_author' => $comment['from']['name'], 'comment_author_email' => $comment['from']['id'].'@facebook.com',  
  18. 'comment_author_url' => $authData['link'], 'comment_content' => $comment['message'], 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime( $comment['created_time'] ) ), 'comment_type' => '');  
  19. $wpCid = nxs_postNewComment($commentdata, $options['riCommentsAA']=='1'); //prr($commentdata); 
  20. } $ci++; $impCmnts[$wpCid] = 'fbxcw'.$cid;  
  21. } else $wpCid = array_search('fbxcw'.$cid, $impCmnts);  
  22.  
  23. $res = wp_remote_get( "https://graph.facebook.com/v2.3/".$cid."/comments?".http_build_query($aacct, null, '&'), $wprg); $replRet = json_decode($res['body'], true); 
  24. if (is_array($replRet) && is_array($replRet['data'])) foreach ($replRet['data'] as $rComment) { $rCid = $rComment['id'];  
  25. if (trim($rCid)!='' && !in_array('fbxcw'.$rCid, $impCmnts)) { // prr($impCmnts); 
  26. $res = wp_remote_get( "https://graph.facebook.com/v2.3/".$rComment['from']['id']."?".http_build_query($aacct, null, '&'), $wprg); $authData = json_decode($res['body'], true); 
  27. if ($ptype=='topic') { $my_post = array('post_title' => '', 'post_content' => $rComment['message'], 'post_status' => 'publish', 'post_parent' => $postID, 'post_author' => 0, 'post_type' => 'reply'); 
  28. $wpCid = wp_insert_post($my_post); add_post_meta($wpCid, '_bbp_anonymous_name', $rComment['from']['name']); $fid = get_post_meta($postID, '_bbp_forum_id', true); 
  29. add_post_meta($wpCid, '_bbp_anonymous_email', $rComment['from']['id'].'@facebook.com'); add_post_meta($wpCid, '_bbp_anonymous_website', 'http://www.facebook.com/'.$rComment['from']['id']); 
  30. add_post_meta($wpCid, '_bbp_topic_id', $postID); add_post_meta($wpCid, '_bbp_forum_id', $fid);  
  31. } else { 
  32. $commentdata = array( 'comment_parent' => $wpCid, 'comment_post_ID' => $postID, 'comment_author' => $rComment['from']['name'], 'comment_author_email' => $rComment['from']['id'].'@facebook.com',  
  33. 'comment_author_url' => $authData['link'], 'comment_content' => $rComment['message'], 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime( $rComment['created_time'] ) ), 'comment_type' => ''); 
  34. // prr($commentdata); 
  35. nxs_postNewComment($commentdata, $options['riCommentsAA']=='1');  
  36. } $ci++; $impCmnts[] = 'fbxcw'.$rCid;  
  37. }  
  38. }  
  39. delete_post_meta($postID, 'snapImportedFBComments'); add_post_meta($postID, 'snapImportedFBComments', $impCmnts );  
  40. //## if Importing manually from Button echo result. 
  41. if (isset($_POST['id']) && $_POST['id']!='') printf( _n( '%d comment has been imported.', '%d comments has been imported.', $ci, 'social-networks-auto-poster-facebook-twitter-g'), $ci ); 
  42. }} 
  43. }}