nxs_getBackTWComments

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

Description

nxs_getBackTWComments( $postID, $options, $po, $twList ); 

Parameters (4)

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

Usage

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

Defined (1)

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

/inc-cl/tw.php  
  1. if (!function_exists("nxs_getBackTWComments")) { function nxs_getBackTWComments($postID, $options, $po, $twList) { $impCmnts = get_post_meta($postID, 'snapImportedComments', true);  
  2. if(!is_array($impCmnts)) $impCmnts = array(); $twsToImp = array(); $lastID = ''; 
  3. //## Do Replies 
  4. foreach ($twList as $tw) if ($tw['in_reply_to_status_id_str'] == $po['pgID']) $twsToImp[] = $tw; 
  5. if (is_array($twsToImp) && count($twsToImp)>0) 
  6. foreach ($twsToImp as $comment) { $cid = $comment['id_str']; if (trim($cid)=='' || in_array('twxcw'.$cid, $impCmnts)) continue; else $impCmnts[] = 'twxcw'.$cid; // prr($impCmnts); 
  7. $commentdata = array( 'comment_post_ID' => $postID, 'comment_author' => $comment['user']['name'], 'comment_agent' => "SNAP||".str_ireplace('_normal.', '_bigger.', $comment['user']['profile_image_url_https']),  
  8. 'comment_author_email' => $comment['user']['screen_name'].'@twitter.com', 'comment_author_url' => 'http://twitter.com/'.$comment['user']['screen_name'],  
  9. 'comment_content' => str_ireplace('@'.$comment['in_reply_to_screen_name'], '', $comment['text']), 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime( $comment['created_at'] ) ), 'comment_type' => ''); 
  10. nxs_postNewComment($commentdata, $options['riCommentsAA']=='1'); $ci++; 
  11. }  
  12.  
  13. //## Do mentions. 
  14. require_once ('apis/tmhOAuth.php'); $tmhOAuth = new NXS_tmhOAuth(array( 'consumer_key' => $options['twConsKey'], 'consumer_secret' => $options['twConsSec'], 'user_token' => $options['twAccToken'], 'user_secret' => $options['twAccTokenSec']));  
  15. if (isset($options['urlToUse']) && trim($options['urlToUse'])!='') $urlToSrch = $options['urlToUse']; else $urlToSrch = get_permalink($postID);  
  16. $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/search/tweets'), array('rpp'=>'100', 'since_id'=>$lastID, 'q'=> urlencode($urlToSrch)));  
  17. if ($code=='200' && isset($tmhOAuth->response['response']) ) { $tweets = json_decode($tmhOAuth->response['response'], true); //prr($tweets); 
  18. if (is_array($tweets) && is_array($tweets['statuses'])) {  
  19. foreach ($tweets['statuses'] as $comment) { $cid = $comment['id_str']; if (trim($cid)=='' || in_array('twxcw'.$cid, $impCmnts) || $cid==$po['pgID']) continue; else $impCmnts[] = 'twxcw'.$cid; // prr($impCmnts); 
  20. $commentdata = array( 'comment_post_ID' => $postID, 'comment_author' => $comment['user']['name'], 'comment_author_email' => $comment['user']['screen_name'].'@twitter.com',  
  21. 'comment_agent' => "SNAP||".str_ireplace('_normal.', '_bigger.', $comment['user']['profile_image_url_https']),  
  22. 'comment_author_url' => 'http://twitter.com/'.$comment['user']['screen_name'], 'comment_content' => $comment['text'], 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime( $comment['created_at'] ) ), 'comment_type' => ''); 
  23. nxs_postNewComment($commentdata, $options['riCommentsAA']=='1'); $ci++; 
  24. }} 
  25. delete_post_meta($postID, 'snapImportedComments'); add_post_meta($postID, 'snapImportedComments', $impCmnts );  
  26. 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 ); 
  27. }}