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);
     }
 }
Example #2
0
 function doPostToNT($options, $message)
 {
     global $nxs_urlLen;
     $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     if (!function_exists('nxs_remote_get') && function_exists('wp_remote_get')) {
         function nxs_remote_get($url)
         {
             return wp_remote_get($url);
         }
     }
     if (!function_exists('is_nxs_error') && function_exists('is_wp_error')) {
         function is_nxs_error($a)
         {
             return is_wp_error($a);
         }
     }
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if (!isset($options['twAccToken']) || trim($options['twAccToken']) == '') {
         $badOut['Error'] = 'No Auth Token Found';
         return $badOut;
     }
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     //## Old Settings Fix
     if ($options['attchImg'] == '1') {
         $options['attchImg'] = 'large';
     }
     if ($options['attchImg'] == '0') {
         $options['attchImg'] = false;
     }
     if (isset($message['img']) && is_string($message['img'])) {
         $img = trim($message['img']);
     } else {
         $img = '';
     }
     //## Format Post
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['twMsgFormat'], $message);
     }
     if ($options['attchImg'] != false) {
         if (isset($message['imageURL'])) {
             $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize']));
         } else {
             $imgURL = '';
         }
     }
     if (empty($imgURL) && $img == '') {
         $options['attchImg'] = false;
     }
     //## Make Post
     //$options['attchImg']='1'; $imgURL = 'http://ecx.images-amazon.com/images/I/41caE5Uc5ML._AA160_.jpg';
     $hdrsArr['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0';
     $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'sslverify' => false);
     //$msg = $message['message']; $imgURL = trim($message['imageURL']); $img = trim($message['img']); $nxs_urlLen = $message['urlLength'];
     if ($options['attchImg'] != false && $img == '' && $imgURL != '') {
         $imgURL = str_replace(' ', '%20', $imgURL);
         if (ini_get('allow_url_fopen')) {
             if (getimagesize($imgURL) !== false) {
                 $img = nxs_remote_get($imgURL, $advSet);
                 if (is_nxs_error($img)) {
                     $options['attchImg'] = false;
                 } else {
                     $img = $img['body'];
                 }
             } else {
                 $options['attchImg'] = false;
             }
         } else {
             $img = nxs_remote_get($imgURL, $advSet);
             if (is_nxs_error($img)) {
                 $options['attchImg'] = false;
             } elseif (isset($img['body']) && trim($img['body']) != '') {
                 $img = $img['body'];
             } else {
                 $options['attchImg'] = false;
             }
         }
     }
     if ($options['attchImg'] != false && $img != '') {
         $twLim = 118;
     } else {
         $twLim = 140;
     }
     require_once 'apis/tmhOAuth.php';
     if ($nxs_urlLen > 0) {
         $msg = nsTrnc($msg, $twLim - 22 + $nxs_urlLen);
     } else {
         $msg = nsTrnc($msg, $twLim);
     }
     //prr($msg); die('TTWWW');
     if (substr($msg, 0, 1) == '@') {
         $msg = ' ' . $msg;
     }
     //prr(urlencode($msg));  $msg = html_entity_decode($msg);  prr(urlencode($msg));   die();
     $tmhOAuth = new NXS_tmhOAuth(array('consumer_key' => $options['twConsKey'], 'consumer_secret' => $options['twConsSec'], 'user_token' => $options['twAccToken'], 'user_secret' => $options['twAccTokenSec']));
     if ($options['attchImg'] != false && $img != '') {
         $params_array = array('media[]' => $img, 'status' => $msg);
     } else {
         $params_array = array('status' => $msg);
     }
     if (!empty($options['in_reply_to_id'])) {
         $params_array['in_reply_to_status_id'] = $options['in_reply_to_id'];
     }
     if ($options['attchImg'] != false && $img != '') {
         $code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json', $params_array, true, true);
     } else {
         $code = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update'), $params_array);
     }
     //prr($msg);
     if ($code == '403' && stripos($tmhOAuth->response['response'], 'User is over daily photo limit') !== false && $options['attchImg'] != false && $img != '') {
         $badOut['Error'] .= "User is over daily photo limit. Will post without image\r\n";
         $code = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update'), array('status' => $msg));
     }
     if ($code == 200) {
         $twResp = json_decode($tmhOAuth->response['response'], true);
         if (is_array($twResp) && isset($twResp['id_str'])) {
             $twNewPostID = $twResp['id_str'];
         }
         if (is_array($twResp) && isset($twResp['user'])) {
             $twPageID = $twResp['user']['screen_name'];
         }
         return array('postID' => $twNewPostID, 'isPosted' => 1, 'postURL' => 'https://twitter.com/' . $twPageID . '/status/' . $twNewPostID, 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= "Resp: " . print_r($tmhOAuth->response['response'], true) . "| Error: " . print_r($tmhOAuth->response['error'], true) . "| MSG: " . print_r($msg, true);
         return $badOut;
     }
     return $badOut;
 }
Example #3
0
 function doPostToNT($options, $message)
 {
     $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if (!isset($options['twAccToken']) || trim($options['twAccToken']) == '') {
         $badOut['Error'] = 'No Auth Token Found';
         return $badOut;
     }
     //## Make Post
     $msg = $message['message'];
     $imgURL = trim($message['imageURL']);
     $img = trim($message['img']);
     $nxs_urlLen = $message['urlLength'];
     if ($options['attchImg'] == '1' && $img == '' && $imgURL == '') {
         $options['attchImg'] = 0;
     }
     if ($options['attchImg'] == '1' && $img == '' && $imgURL != '') {
         if (ini_get('allow_url_fopen')) {
             if (getimagesize($imgURL) !== false) {
                 $img = nxs_remote_get($imgURL);
                 if (is_nxs_error($img)) {
                     $options['attchImg'] = 0;
                 } else {
                     $img = $img['body'];
                 }
             } else {
                 $options['attchImg'] = 0;
             }
         } else {
             $img = nxs_remote_get($imgURL);
             if (is_nxs_error($img)) {
                 $options['attchImg'] = 0;
             } elseif (isset($img['body']) && trim($img['body']) != '') {
                 $img = $img['body'];
             } else {
                 $options['attchImg'] = 0;
             }
         }
     }
     if ($options['attchImg'] == '1' && $img != '') {
         $twLim = 118;
     } else {
         $twLim = 140;
     }
     require_once 'apis/tmhOAuth.php';
     require_once 'apis/tmhUtilities.php';
     if ($nxs_urlLen > 0) {
         $msg = nsTrnc($msg, $twLim - 22 + $nxs_urlLen);
     } else {
         $msg = nsTrnc($msg, $twLim);
     }
     $tmhOAuth = new NXS_tmhOAuth(array('consumer_key' => $options['twConsKey'], 'consumer_secret' => $options['twConsSec'], 'user_token' => $options['twAccToken'], 'user_secret' => $options['twAccTokenSec']));
     if ($options['attchImg'] == '1' && $img != '') {
         $code = $tmhOAuth->request('POST', 'http://upload.twitter.com/1/statuses/update_with_media.json', array('media[]' => $img, 'status' => $msg), true, true);
     } else {
         $code = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update'), array('status' => $msg));
     }
     if ($code == '403' && stripos($tmhOAuth->response['response'], 'User is over daily photo limit') !== false && $options['attchImg'] == '1' && $img != '') {
         $badOut['Error'] .= "User is over daily photo limit. Will post without image\r\n";
         $code = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update'), array('status' => $msg));
     }
     if ($code == 200) {
         $twResp = json_decode($tmhOAuth->response['response'], true);
         if (is_array($twResp) && isset($twResp['id_str'])) {
             $twNewPostID = $twResp['id_str'];
         }
         if (is_array($twResp) && isset($twResp['user'])) {
             $twPageID = $twResp['user']['screen_name'];
         }
         return array('postID' => $twNewPostID, 'isPosted' => 1, 'postURL' => 'https://twitter.com/' . $twPageID . '/status/' . $twNewPostID, 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= print_r($tmhOAuth->response['response'], true) . " MSG:" . print_r($msg, true);
         return $badOut;
     }
     return $badOut;
 }