예제 #1
0
파일: tw.php 프로젝트: JalpMi/v2contact
 function nxs_getBackTWComments($postID, $options, $po)
 {
     $impCmnts = get_post_meta($postID, 'snapImportedComments', true);
     if (!is_array($impCmnts)) {
         $impCmnts = array();
     }
     $url = 'https://api.twitter.com/1/related_results/show/' . $po['pgID'] . '.json?include_entities=1';
     //echo $url;
     $data = json_decode($response = wp_remote_retrieve_body(wp_remote_get($url)), true);
     // prr($data[0]['results']);
     if (is_array($data) && is_array($data[0]) && is_array($data[0]['results'])) {
         foreach ($data[0]['results'] as $comment) {
             $comment = $comment['value'];
             $cid = $comment['id_str'];
             if (trim($cid) == '' || in_array('twxcw' . $cid, $impCmnts)) {
                 continue;
             } else {
                 $impCmnts[] = 'twxcw' . $cid;
             }
             // prr($impCmnts);
             $commentdata = array('comment_post_ID' => $postID, 'comment_author' => $comment['user']['name'], 'comment_author_email' => $comment['user']['screen_name'] . '@twitter.com', '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' => '');
             nxs_postNewComment($commentdata, $options['riCommentsAA'] == '1');
             $ci++;
         }
     }
     $url = 'http://search.twitter.com/search.json?rpp=100&since_id=' . $lastID . '&q=' . urlencode(get_permalink($postID));
     $data = json_decode($response = wp_remote_retrieve_body(wp_remote_get($url)), true);
     if (is_array($data) && is_array($data['results'])) {
         foreach ($data['results'] as $comment) {
             $cid = $comment['id_str'];
             if (trim($cid) == '' || in_array('twxcw' . $cid, $impCmnts) || $cid == $po['pgID']) {
                 continue;
             } else {
                 $impCmnts[] = 'twxcw' . $cid;
             }
             // prr($impCmnts);
             $commentdata = array('comment_post_ID' => $postID, 'comment_author' => $comment['from_user_name'], 'comment_author_email' => $comment['from_user'] . '@twitter.com', 'comment_author_url' => 'http://twitter.com/' . $comment['from_user'], 'comment_content' => $comment['text'], 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime($comment['created_at'])), 'comment_type' => '');
             nxs_postNewComment($commentdata, $options['riCommentsAA'] == '1');
             $ci++;
         }
     }
     delete_post_meta($postID, 'snapImportedComments');
     add_post_meta($postID, 'snapImportedComments', $impCmnts);
     if ($_POST['id'] != '') {
         printf(_n('%d comment has been imported.', '%d comments has been imported.', $ci, 'nxs_snap'), $ci);
     }
 }
 function nxs_getBackTWComments($postID, $options, $po, $twList)
 {
     $impCmnts = get_post_meta($postID, 'snapImportedComments', true);
     if (!is_array($impCmnts)) {
         $impCmnts = array();
     }
     $twsToImp = array();
     $lastID = '';
     //## Do Replies
     foreach ($twList as $tw) {
         if ($tw['in_reply_to_status_id_str'] == $po['pgID']) {
             $twsToImp[] = $tw;
         }
     }
     if (is_array($twsToImp) && count($twsToImp) > 0) {
         foreach ($twsToImp as $comment) {
             $cid = $comment['id_str'];
             if (trim($cid) == '' || in_array('twxcw' . $cid, $impCmnts)) {
                 continue;
             } else {
                 $impCmnts[] = 'twxcw' . $cid;
             }
             // prr($impCmnts);
             $commentdata = array('comment_post_ID' => $postID, 'comment_author' => $comment['user']['name'], 'comment_agent' => "SNAP||" . str_ireplace('_normal.', '_bigger.', $comment['user']['profile_image_url_https']), 'comment_author_email' => $comment['user']['screen_name'] . '@twitter.com', 'comment_author_url' => 'http://twitter.com/' . $comment['user']['screen_name'], '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' => '');
             nxs_postNewComment($commentdata, $options['riCommentsAA'] == '1');
             $ci++;
         }
     }
     //## Do mentions.
     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']));
     if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') {
         $urlToSrch = $options['urlToUse'];
     } else {
         $urlToSrch = get_permalink($postID);
     }
     $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/search/tweets'), array('rpp' => '100', 'since_id' => $lastID, 'q' => urlencode($urlToSrch)));
     if ($code == '200' && isset($tmhOAuth->response['response'])) {
         $tweets = json_decode($tmhOAuth->response['response'], true);
         //prr($tweets);
         if (is_array($tweets) && is_array($tweets['statuses'])) {
             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);
                 $commentdata = array('comment_post_ID' => $postID, 'comment_author' => $comment['user']['name'], 'comment_author_email' => $comment['user']['screen_name'] . '@twitter.com', 'comment_agent' => "SNAP||" . str_ireplace('_normal.', '_bigger.', $comment['user']['profile_image_url_https']), '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' => '');
                 nxs_postNewComment($commentdata, $options['riCommentsAA'] == '1');
                 $ci++;
             }
         }
     }
     delete_post_meta($postID, 'snapImportedComments');
     add_post_meta($postID, 'snapImportedComments', $impCmnts);
     if (isset($_POST['id']) && $_POST['id'] != '') {
         printf(_n('%d comment has been imported.', '%d comments has been imported.', $ci, 'nxs_snap'), $ci);
     }
 }
예제 #3
0
파일: fb.php 프로젝트: voquanghoa/WebPhim
 function nxs_getBackFBComments($postID, $options, $po)
 {
     $ci = 0;
     if (empty($options['fbAppPageAuthToken'])) {
         return;
     }
     $options['appsecret_proof'] = hash_hmac('sha256', $options['fbAppPageAuthToken'], $options['fbAppSec']);
     $aacct = array('access_token' => $options['fbAppPageAuthToken'], 'appsecret_proof' => $options['appsecret_proof'], 'method' => 'get');
     $res = wp_remote_get("https://graph.facebook.com/" . $po['pgID'] . "/comments?filter=toplevel&limit=250&" . http_build_query($aacct, null, '&'));
     if (is_wp_error($res) || empty($res['body'])) {
         $badOut['Error'] = ' [ERROR] ' . print_r($res, true);
     } else {
         $ret = json_decode($res['body'], true);
         if (empty($ret)) {
             $badOut['Error'] .= "JSON ERROR: " . print_r($res, true);
         } else {
             $impCmnts = get_post_meta($postID, 'snapImportedFBComments', true);
             if (!is_array($impCmnts)) {
                 $impCmnts = array();
             }
             //prr($impCmnts);
             if (is_array($ret) && is_array($ret['data'])) {
                 foreach ($ret['data'] as $comment) {
                     $cid = $comment['id'];
                     if (trim($cid) == '') {
                         continue;
                     }
                     if (!in_array('fbxcw' . $cid, $impCmnts)) {
                         $res = wp_remote_get("https://graph.facebook.com/" . $comment['from']['id'] . "?" . http_build_query($aacct, null, '&'));
                         $authData = json_decode($res['body'], true);
                         $commentdata = array('comment_post_ID' => $postID, 'comment_author' => $comment['from']['name'], 'comment_author_email' => $comment['from']['id'] . '@facebook.com', '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' => '');
                         //prr($commentdata);
                         $wpCid = nxs_postNewComment($commentdata, $options['riCommentsAA'] == '1');
                         $ci++;
                         $impCmnts[$wpCid] = 'fbxcw' . $cid;
                     } else {
                         $wpCid = array_search('fbxcw' . $cid, $impCmnts);
                     }
                     $res = wp_remote_get("https://graph.facebook.com/" . $cid . "/comments?" . http_build_query($aacct, null, '&'));
                     $replRet = json_decode($res['body'], true);
                     if (is_array($replRet) && is_array($replRet['data'])) {
                         foreach ($replRet['data'] as $rComment) {
                             $rCid = $rComment['id'];
                             if (trim($rCid) != '' && !in_array('fbxcw' . $rCid, $impCmnts)) {
                                 // prr($impCmnts);
                                 $res = wp_remote_get("https://graph.facebook.com/" . $rComment['from']['id'] . "?" . http_build_query($aacct, null, '&'));
                                 $authData = json_decode($res['body'], true);
                                 $commentdata = array('comment_parent' => $wpCid, 'comment_post_ID' => $postID, 'comment_author' => $rComment['from']['name'], 'comment_author_email' => $rComment['from']['id'] . '@facebook.com', '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' => '');
                                 // prr($commentdata);
                                 nxs_postNewComment($commentdata, $options['riCommentsAA'] == '1');
                                 $ci++;
                                 $impCmnts[] = 'fbxcw' . $rCid;
                             }
                         }
                     }
                 }
             }
             delete_post_meta($postID, 'snapImportedFBComments');
             add_post_meta($postID, 'snapImportedFBComments', $impCmnts);
             //## if Importing manually from Button echo result.
             if (isset($_POST['id']) && $_POST['id'] != '') {
                 printf(_n('%d comment has been imported.', '%d comments has been imported.', $ci, 'nxs_snap'), $ci);
             }
         }
     }
 }
예제 #4
0
파일: fb.php 프로젝트: JalpMi/v2contact
 function nxs_getBackFBComments($postID, $options, $po)
 {
     require_once 'apis/facebook.php';
     $opts = array('access_token' => $options['fbAppPageAuthToken']);
     $facebook = new NXS_Facebook(array('appId' => $options['fbAppID'], 'secret' => $options['fbAppSec'], 'cookie' => true));
     $ci = 0;
     $ret = $facebook->api($po['pgID'] . "/comments", "GET", $opts);
     $impCmnts = get_post_meta($postID, 'snapImportedComments', true);
     // prr($impCmnts); // $impCmnts = array();
     if (is_array($ret) && is_array($ret['data'])) {
         foreach ($ret['data'] as $comment) {
             $cid = $comment['id'];
             if (trim($cid) == '' || in_array('fbxcw' . $cid, $impCmnts)) {
                 continue;
             } else {
                 $impCmnts[] = 'fbxcw' . $cid;
             }
             // prr($impCmnts);
             $authData = $facebook->api($comment['from']['id'], "GET", $opts);
             $commentdata = array('comment_post_ID' => $postID, 'comment_author' => $comment['from']['name'], 'comment_author_email' => $comment['from']['id'] . '@facebook.com', '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' => '');
             // prr($commentdata);
             nxs_postNewComment($commentdata, $options['riCommentsAA'] == '1');
             $ci++;
         }
     }
     delete_post_meta($postID, 'snapImportedComments');
     add_post_meta($postID, 'snapImportedComments', $impCmnts);
     if ($_POST['id'] != '') {
         printf(_n('%d comment has been imported.', '%d comments has been imported.', $ci, 'nxs_snap'), $ci);
     }
 }