Beispiel #1
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['diUName']) || trim($options['diPass']) == '') {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     $email = $options['diUName'];
     $pass = substr($options['diPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['diPass'], 5)) : $options['diPass3'];
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['diMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['diMsgTFormat'], $message);
     }
     $flds = array();
     $flds['key'] = $options['diAPIKey'];
     $flds['url'] = $message['url'];
     $flds['title'] = nsTrnc($msgT, 250);
     $flds['desc'] = nsTrnc($msg, 250);
     $flds['tags'] = $message['tags'];
     $flds['shared'] = 'yes';
     //   prr($flds); die();
     $hdrsArr = $this->nxs_getDIHeaders('https://secure.diigo.com/api/v2/bookmarks', $email, $pass, true);
     $cnt = wp_remote_post('https://secure.diigo.com/api/v2/bookmarks', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds));
     //## Return
     if (is_array($cnt) && stripos($cnt['body'], '"code":1') !== false) {
         return array('postID' => 'DI', 'isPosted' => 1, 'postURL' => 'DI', 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= print_r($cnt, true);
         return $badOut;
     }
 }
 function nxs_doPublishToTW($postID, $options)
 {
     $ntCd = 'TW';
     $ntCdL = 'tw';
     $ntNm = 'Twitter';
     $imgData = '';
     $imgURL = '';
     global $plgn_NS_SNAutoPoster, $nxs_urlLen;
     $nxs_urlLen = 0;
     if (!is_array($options)) {
         $options = maybe_unserialize(get_post_meta($postID, $options, true));
     }
     //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Error', $logNT, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTW',  array($postID, $options));
     $gOptions = $plgn_NS_SNAutoPoster->nxs_options;
     if (!empty($gOptions['nxsHTSpace'])) {
         $htS = $gOptions['nxsHTSpace'];
     } else {
         $htS = '';
     }
     $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName']));
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#00FFFF">Twitter</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $options['pType']);
             return;
         }
     }
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $uln = 0;
     $extInfo = ' | PostID: ' . $postID;
     if ($options['attchImg'] == '1') {
         if (!empty($options['imgToUse'])) {
             $imgURL = $options['imgToUse'];
         } else {
             $imgURL = nxs_getPostImage($postID);
         }
         if (preg_match("/noImg.\\.png/i", $imgURL)) {
             $imgURL = '';
         }
         if (trim($imgURL) == '') {
             $options['attchImg'] = 0;
         } else {
             $imgURL = str_replace(' ', '%20', $imgURL);
             $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);
             $imgData = wp_remote_get($imgURL, $advSet);
             if (is_wp_error($imgData) || empty($imgData['body']) || !empty($imgData['headers']['content-length']) && (int) $imgData['headers']['content-length'] < 200) {
                 $options['attchImg'] = 0;
                 nxs_addToLogN('E', 'Error', $logNT, 'Could not get image (' . $imgURL . '), will post without it - Error:' . print_r($imgData, true), $extInfo);
             } else {
                 $imgData = $imgData['body'];
             }
         }
     }
     if ($options['attchImg'] == '1' && $imgData != '') {
         $twLim = 117;
     } else {
         $twLim = 140;
     }
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $msg = 'Test Post from ' . nsTrnc($blogTitle, $twLim - 24) . " - " . rand(1, 155);
         $uln = nxs_strLen($msg);
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $twMsgFormat = $options['twMsgFormat'];
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
         $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title . ' |' . $options['pType'];
         if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) {
             $twLim = $twLim - 22;
         }
         if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) {
             $aun = $post->post_author;
             $aun = get_the_author_meta('display_name', $aun);
             $twLim = $twLim - nxs_strLen($aun);
         }
         $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat);
         $noRepl = str_ireplace("%SITENAME%", "", $noRepl);
         $noRepl = str_ireplace("%URL%", "", $noRepl);
         $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl);
         $noRepl = str_ireplace("%SURL%", "", $noRepl);
         $noRepl = str_ireplace("%TEXT%", "", $noRepl);
         $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl);
         $noRepl = str_ireplace("%EXCERPT%", "", $noRepl);
         $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl);
         $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl);
         $noRepl = str_ireplace("%TAGS%", "", $noRepl);
         $noRepl = str_ireplace("%CATS%", "", $noRepl);
         $noRepl = preg_replace('/%H?C(F|T)-[a-zA-Z0-9_]+%/', '', $noRepl);
         $twLim = $twLim - nxs_strLen($noRepl);
         // prr($noRepl);
         $pTitle = nxs_doQTrans($post->post_title);
         if ($post->post_excerpt != "") {
             $exrText = nxs_doQTrans($post->post_excerpt);
         } else {
             $exrText = nxs_doQTrans($post->post_content);
         }
         $pText = empty($gOptions['brokenCntFilters']) ? apply_filters('the_content', $exrText) : $exrText;
         $pRawText = nxs_doQTrans($post->post_content);
         $pFullText = empty($gOptions['brokenCntFilters']) ? apply_filters('the_content', $pRawText) : $pRawText;
         if (stripos($twMsgFormat, '%TAGS%') !== false || stripos($twMsgFormat, '%HTAGS%') !== false) {
             $t = wp_get_object_terms($postID, 'product_tag');
             if (empty($t) || is_wp_error($pt) || !is_array($t)) {
                 $t = wp_get_post_tags($postID);
             }
             $tggs = array();
             foreach ($t as $tagA) {
                 $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&amp;', '', $tagA->name)))))));
                 if (preg_match('/\\b' . $frmTag . '\\b/iu', $pTitle)) {
                     $pTitle = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pTitle));
                 }
                 if (preg_match('/\\b' . $frmTag . '\\b/iu', $pFullText)) {
                     $pFullText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pFullText));
                 }
                 if (preg_match('/\\b' . $frmTag . '\\b/iu', $pText)) {
                     $pText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pText));
                 }
                 if (preg_match('/\\b' . $frmTag . '\\b/iu', $pRawText)) {
                     $pRawText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pRawText));
                 }
                 if (stripos($twMsgFormat, '%TITLE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pTitle) || stripos($twMsgFormat, '%TEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%EXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%FULLTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pFullText) || stripos($twMsgFormat, '%RAWTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pRawText)) {
                 } else {
                     $tggs[] = '#' . $frmTag;
                 }
             }
             $tags = implode(' ', $tggs);
             $tgsTwLim = $twLim - 20;
             $tags = nsTrnc($tags, $tgsTwLim, " ", "");
             $twMsgFormat = str_ireplace("%TAGS%", $tags, $twMsgFormat);
             $twMsgFormat = str_ireplace("%HTAGS%", $tags, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($tags);
         }
         if (stripos($twMsgFormat, '%CATS%') !== false || stripos($twMsgFormat, '%HCATS%') !== false) {
             $t = wp_get_post_categories($postID);
             $ctts = array();
             foreach ($t as $c) {
                 $cat = get_category($c);
                 //$frmTag =  trim(str_replace(' ','', str_replace('  ',' ',str_ireplace('&','&amp;',trim(ucwords($cat->name)))))); prr($frmTag);
                 $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&amp;', '', $cat->name)))))));
                 if (stripos($pTitle, $cat->name) !== false) {
                     $pTitle = str_ireplace($cat->name, '#' . $frmTag, $pTitle);
                 } elseif (stripos($pTitle, $frmTag) !== false) {
                     $pTitle = str_ireplace($frmTag, '#' . $frmTag, $pTitle);
                 }
                 if (stripos($pText, $cat->name) !== false) {
                     $pText = str_ireplace($cat->name, '#' . $frmTag, $pText);
                 } elseif (stripos($pText, $frmTag) !== false) {
                     $pText = str_ireplace($frmTag, '#' . $frmTag, $pText);
                 }
                 if (stripos($pFullText, $cat->name) !== false) {
                     $pFullText = str_ireplace($cat->name, '#' . $frmTag, $pFullText);
                 } elseif (stripos($pFullText, $frmTag) !== false) {
                     $pFullText = str_ireplace($frmTag, '#' . $frmTag, $pFullText);
                 }
                 if (stripos($pRawText, $cat->name) !== false) {
                     $pRawText = str_ireplace($cat->name, '#' . $frmTag, $pRawText);
                 } elseif (stripos($pRawText, $frmTag) !== false) {
                     $pRawText = str_ireplace($frmTag, '#' . $frmTag, $pRawText);
                 }
                 if (stripos($twMsgFormat, '%TITLE%') !== false && (stripos($pTitle, $cat->name) !== false || stripos($pTitle, $frmTag) !== false) || stripos($twMsgFormat, '%TEXT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%EXCERPT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && (stripos($exrText, $cat->name) !== false || stripos($exrText, $frmTag) !== false) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%FULLTEXT%') !== false && (stripos($pFullText, $cat->name) !== false || stripos($pFullText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWTEXT%') !== false && (stripos($pRawText, $cat->name) !== false || stripos($pRawText, $frmTag) !== false)) {
                 } else {
                     $ctts[] = '#' . $frmTag;
                 }
             }
             $cats = implode(' ', $ctts);
             $tgsTwLim = $twLim - 20;
             $cats = nsTrnc($cats, $tgsTwLim, " ", "");
             $twMsgFormat = str_ireplace("%CATS%", $cats, $twMsgFormat);
             $twMsgFormat = str_ireplace("%HCATS%", $cats, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($cats);
         }
         if (preg_match('/%H?CT-[a-zA-Z0-9_]+%/', $twMsgFormat)) {
             $msgA = explode('%CT', str_ireplace("%HCT", "%CT", $twMsgFormat));
             $mout = '';
             foreach ($msgA as $mms) {
                 if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) {
                     $mGr = CutFromTo($mms, '-', '%');
                     $cfItem = wp_get_post_terms($postID, $mGr, array("fields" => "names"));
                     if (is_nxs_error($cfItem)) {
                         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . $mGr . '|' . print_r($cfItem, true), $extInfo);
                     } else {
                         $tggs = array();
                         foreach ($cfItem as $frmTag) {
                             $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&amp;', '', $frmTag)))))));
                             $tggs[] = '#' . $frmTag;
                         }
                         $cfItem = implode(' ', $tggs);
                         $twLim = $twLim - nxs_strLen($cfItem);
                         $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms);
                     }
                 }
                 $mout .= $mms;
             }
             $twMsgFormat = $mout;
         }
         $twMsgFormat = str_ireplace("  ", " ", $twMsgFormat);
         if (stripos($twMsgFormat, '%TITLE%') !== false) {
             if (stripos($pTitle, '.co.uk') !== false) {
                 $twLim = $twLim - 14;
             }
             if (stripos($pTitle, '.com') !== false) {
                 $twLim = $twLim - 16;
             }
             if (stripos($pTitle, '.net') !== false) {
                 $twLim = $twLim - 16;
             }
             if (stripos($pTitle, '.org') !== false) {
                 $twLim = $twLim - 16;
             }
             $pTitle = html_entity_decode(strip_tags($pTitle), ENT_NOQUOTES, 'UTF-8');
             //$ttlTwLim = $twLim-20;
             $ttlTwLim = $twLim;
             $pTitle = nsTrnc($pTitle, $ttlTwLim);
             $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pTitle);
         }
         if (stripos($twMsgFormat, '%SITENAME%') !== false) {
             $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
             $siteTitle = nsTrnc($siteTitle, $twLim);
             $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($siteTitle);
         }
         if (stripos($twMsgFormat, '%TEXT%') !== false) {
             $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "...");
             $pText = nsTrnc($pText, $twLim);
             $twMsgFormat = str_ireplace("%TEXT%", $pText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pText);
         }
         if (stripos($twMsgFormat, '%EXCERPT%') !== false) {
             $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "...");
             $pText = nsTrnc($pText, $twLim);
             $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pText);
         }
         if (stripos($twMsgFormat, '%ANNOUNCE%') !== false) {
             $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "...");
             $pText = nsTrnc($pText, $twLim);
             $twMsgFormat = str_ireplace("%ANNOUNCE%", $pText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pText);
         }
         if (stripos($twMsgFormat, '%RAWEXCERPT%') !== false) {
             $exrText = nsTrnc(strip_tags(strip_shortcodes($exrText)), 140, " ", "...");
             $exrText = nsTrnc($exrText, $twLim);
             $twMsgFormat = str_ireplace("%RAWEXCERPT%", $exrText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($exrText);
         }
         if (stripos($twMsgFormat, '%FULLTEXT%') !== false) {
             $pFullText = nsTrnc(strip_tags($pFullText), $twLim);
             $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pFullText);
         }
         if (stripos($twMsgFormat, '%RAWTEXT%') !== false) {
             $pRawText = nsTrnc(strip_tags($pRawText), $twLim);
             $twMsgFormat = str_ireplace("%RAWTEXT%", $pRawText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pRawText);
         }
         $msg = nsFormatMessage($twMsgFormat, $postID, $addParams);
     }
     $msg = str_replace('&amp;#039;', "'", $msg);
     $msg = str_replace('&#039;', "'", $msg);
     $msg = str_replace('#039;', "'", $msg);
     $msg = str_replace('#039', "'", $msg);
     $msg = str_replace('&amp;#8217;', "'", $msg);
     $msg = str_replace('&#8217;', "'", $msg);
     $msg = str_replace('#8217;', "'", $msg);
     $msg = str_replace('#8217', "'", $msg);
     $msg = str_replace('&amp;#8220;', '"', $msg);
     $msg = str_replace('&#8220;', '"', $msg);
     $msg = str_replace('#8220;', '"', $msg);
     $msg = str_replace('#8220', "'", $msg);
     $msg = str_replace('&amp;#8221;', '"', $msg);
     $msg = str_replace('&#8221;', '"', $msg);
     $msg = str_replace('#8221;', '"', $msg);
     $msg = str_replace('#8221', "'", $msg);
     $msg = str_replace('&amp;#8212;', '-', $msg);
     $msg = str_replace('&#8212;', '-', $msg);
     $msg = str_replace('#8212;', '-', $msg);
     $msg = str_replace('#8212', "-", $msg);
     $msg = nxs_decodeEntitiesFull($msg);
     $message = array('message' => $msg, 'img' => $imgData, 'urlLength' => $nxs_urlLen);
     $options['twMsgFormat'] = $msg;
     //## This meta field is created by the indieweb taxonomy plugin - by David Peach
     $response = get_post_meta($postID, 'response', true);
     if (!empty($response)) {
         $reply_url = $response['url'];
         if (!empty($reply_url) && strpos($reply_url, 'twitter.com')) {
             $explode_at_domain = explode('twitter.com/', $reply_url);
             $twitter_path = end($explode_at_domain);
             $exploded_path = explode('/', $twitter_path);
             $options['in_reply_to_id'] = end($exploded_path);
         }
     }
     //prr($options);
     //## Actual Post
     $ntToPost = new nxs_class_SNAP_TW();
     $ret = $ntToPost->doPostToNT($options, $message);
     //## Process Results
     if (!is_array($ret) || $ret['isPosted'] != '1') {
         //## Error
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         // ## All Good - log it.
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap');
         } else {
             nxs_addToRI($postID);
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s')));
             $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>';
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     //## Return Result
     if ($ret['isPosted'] == '1') {
         return 200;
     } else {
         return print_r($ret, true);
     }
 }
Beispiel #3
0
 function nxs_doPublishToPK($postID, $options)
 {
     $ntCd = 'PK';
     $ntCdL = 'pk';
     $ntNm = 'Plurk';
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPK',  array($postID, $options));
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#014A76">Plurk</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             sleep(5);
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID);
             return;
         }
     }
     //## Format
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $msg = 'Test Post from ' . $blogTitle;
         $msgT = 'Test Post from ' . $blogTitle;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $twMsgFormat = $options['pkMsgFormat'];
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
         $twLim = 180;
         $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title;
         if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) {
             $twLim = $twLim - 5;
         }
         if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) {
             $aun = $post->post_author;
             $aun = get_the_author_meta('display_name', $aun);
             $twLim = $twLim - strlen($aun);
         }
         $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat);
         $noRepl = str_ireplace("%SITENAME%", "", $noRepl);
         $noRepl = str_ireplace("%URL%", "", $noRepl);
         $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl);
         $noRepl = str_ireplace("%SURL%", "", $noRepl);
         $noRepl = str_ireplace("%TEXT%", "", $noRepl);
         $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl);
         $noRepl = str_ireplace("%EXCERPT%", "", $noRepl);
         $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl);
         $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl);
         $twLim = $twLim - strlen($noRepl);
         $pTitle = $title = $post->post_title;
         if ($post->post_excerpt != "") {
             $pText = apply_filters('the_content', $post->post_excerpt);
         } else {
             $pText = apply_filters('the_content', $post->post_content);
         }
         $pFullText = apply_filters('the_content', $post->post_content);
         $pRawText = $post->post_content;
         if (stripos($twMsgFormat, '%TITLE%') !== false) {
             $pTitle = nsTrnc($pTitle, $twLim);
             $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat);
             $twLim = $twLim - strlen($pTitle);
         }
         if (stripos($twMsgFormat, '%SITENAME%') !== false) {
             $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
             $siteTitle = nsTrnc($siteTitle, $twLim);
             $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat);
             $twLim = $twLim - strlen($siteTitle);
         }
         if (stripos($twMsgFormat, '%EXCERPT%') !== false) {
             $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "...");
             $pText = nsTrnc($pText, $twLim);
             $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat);
             $twLim = $twLim - strlen($pText);
         }
         if (stripos($twMsgFormat, '%FULLTEXT%') !== false) {
             $pFullText = nsTrnc(strip_tags($pFullText), $twLim);
             $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat);
             $twLim = $twLim - strlen($pFullText);
         }
         if (stripos($twMsgFormat, '%RAWTEXT%') !== false) {
             $pRawText = nsTrnc(strip_tags($pRawText), $twLim);
             $twMsgFormat = str_ireplace("%FULLTEXT%", $pRawText, $twMsgFormat);
             $twLim = $twLim - strlen($pRawText);
         }
         $msg = nsFormatMessage($twMsgFormat, $postID);
     }
     //## Post
     require_once 'apis/plurkOAuth.php';
     $consumer_key = $options['pkConsKey'];
     $consumer_secret = $options['pkConsSec'];
     $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret, $options['pkAccessTocken'], $options['pkAccessTockenSec']);
     $pkURL = trim(str_ireplace('http://', '', $options['pkURL']));
     if (substr($pkURL, -1) == '/') {
         $pkURL = substr($pkURL, 0, -1);
     }
     if ($options['pkCat'] == '') {
         $options['pkCat'] = ':';
     }
     if ($options['attchImg'] == '1') {
         $imgURL = nxs_getPostImage($postID);
         $msg .= " " . $imgURL;
     }
     $postDate = ($post->post_date_gmt != '0000-00-00 00:00:00' ? $post->post_date_gmt : gmdate("Y-m-d H:i:s", strtotime($post->post_date))) . " GMT";
     //## Adds date to Tumblr post. Thanks to Kenneth Lecky
     $postArr = array('content' => $msg, 'qualifier' => $options['pkCat']);
     $postinfo = $tum_oauth->makeReq('http://www.plurk.com/APP/Timeline/plurkAdd', $postArr);
     // prr($postinfo);
     if (is_array($postinfo) && isset($postinfo['plurk_id'])) {
         $pkID = $postinfo['plurk_id'];
     }
     $code = $tum_oauth->http_code;
     // echo "XX".print_r($code);  prr($postinfo); // prr($msg); prr($postinfo); echo $code."VVVV"; die("|====");
     if ($code == 200) {
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo 'OK - Message Posted, please see your Plurk  Page. <br/> Result:';
         } else {
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
             nxs_metaMarkAsPosted($postID, 'PK', $options['ii'], array('isPosted' => '1', 'pgID' => $pkID, 'pDate' => date('Y-m-d H:i:s')));
         }
     } else {
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($postinfo, true), $extInfo);
         if ($postID == '0') {
             prr($postinfo);
         }
         $code .= " ERROR: - " . $postinfo['error_text'];
     }
     return $code;
 }
Beispiel #4
0
 function nxs_doPublishToLI($postID, $options)
 {
     global $nxs_gCookiesArr;
     $ntCd = 'LI';
     $ntCdL = 'li';
     $ntNm = 'LinkedIn';
     $urlDescr = '';
     $myurl = '';
     if (!is_array($options)) {
         $options = maybe_unserialize(get_post_meta($postID, $options, true));
     }
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLI',  array($postID, $options));
     $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName']));
     if (empty($options['imgToUse'])) {
         $options['imgToUse'] = '';
     }
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#000058">LinkedIn</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             sleep(5);
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID);
             return;
         }
     }
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $imgURL = '';
     // prr($options);
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $options['liMsgFormatT'] = 'Test Post from ' . $blogTitle;
         $urlToGo = home_url();
         $options['liMsgFormat'] = 'Test Post from ' . $blogTitle . " " . $urlToGo;
         $title = $blogTitle;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $options['liMsgFormat'] = nsFormatMessage($options['liMsgFormat'], $postID, $addParams);
         $options['liMsgFormatT'] = nsTrnc(nsFormatMessage($options['liMsgFormatT'], $postID, $addParams), 200);
         //## MyURL - URLToGo code
         $options = nxs_getURL($options, $postID, $addParams);
         $urlToGo = $options['urlToUse'];
         $title = nsTrnc($post->post_title, 200);
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
         if (empty($options['postType'])) {
             if ((int) $options['liAttch'] == 1 || $isNew) {
                 $options['postType'] = 'A';
             }
         }
         if ($options['postType'] == 'A' || $options['postType'] == 'I') {
             if (trim($options['liMsgAFrmt']) != '') {
                 $urlDescr = nsFormatMessage($options['liMsgAFrmt'], $postID, $addParams);
             } else {
                 $urlDescr = trim(apply_filters('the_content', $post->post_excerpt));
                 if ($urlDescr == '') {
                     $urlDescr = apply_filters('the_content', $post->post_content);
                 }
             }
             if (trim($options['imgToUse']) != '') {
                 $imgURL = $options['imgToUse'];
             } else {
                 $imgURL = nxs_getPostImage($postID, 'full');
             }
             if (preg_match("/noImg.\\.png/i", $imgURL)) {
                 $imgURL = '';
             }
             $urlDescr = strip_tags($urlDescr);
             $urlDescr = nxs_decodeEntitiesFull($urlDescr);
             $urlDescr = nxs_html_to_utf8($urlDescr);
             $urlDescr = nsTrnc($urlDescr, 300);
         }
     }
     $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : '');
     //$images = array(nxs_getPostImage($postID, 'thumb'), nxs_getPostImage($postID, 'medium'), nxs_getPostImage($postID, 'full'), nxs_getPostImage($postID, 'original'));
     $message = array('url' => $urlToGo, 'surl' => $urlToGo, 'urlDescr' => $urlDescr, 'urlTitle' => $title, 'title' => $title, 'imageURL' => $imgURL, 'videoCode' => '', 'videoURL' => '', 'siteName' => $blogTitle, 'cats' => '', 'authorName' => '');
     //## Actual Post
     $ntToPost = new nxs_class_SNAP_LI();
     $ret = $ntToPost->doPostToNT($options, $message);
     //## Process Results
     if (!is_array($ret) || $ret['isPosted'] != '1') {
         //## Error
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         $extInfo .= ' | ' . $ret['postID'];
         // ## All Good - log it.
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'social-networks-auto-poster-facebook-twitter-g');
         } else {
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'postID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s')));
             if (!empty($ret['postURL'])) {
                 $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>';
             }
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     //## Return Result
     if ($ret['isPosted'] == '1') {
         return 200;
     } else {
         return print_r($ret, true);
     }
 }
Beispiel #5
0
 function doPostToNT($options, $message)
 {
     global $nxs_urlLen;
     $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['rdUName']) || trim($options['rdUName']) == '' || !isset($options['rdPass']) || trim($options['rdPass']) == '') {
         $badOut['Error'] = 'No username/password Found';
         return $badOut;
     }
     //## Format Post
     if (!empty($message['pTitle'])) {
         $title = $message['pTitle'];
     } else {
         $title = nxs_doFormatMsg($options['rdTitleFormat'], $message);
     }
     $title = nsTrnc($title, 300);
     if (!empty($message['pText'])) {
         $text = $message['pText'];
     } else {
         $text = nxs_doFormatMsg($options['rdTextFormat'], $message);
     }
     //## Make Post
     $pass = substr($options['rdPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['rdPass'], 5)) : $options['rdPass'];
     $hdrsArr = '';
     $loginInfo = doConnectToRD($options['rdUName'], $pass);
     if (!is_array($loginInfo)) {
         $badOut['Error'] = print_r($loginInfo, true) . " - ERROR";
         return $badOut;
     }
     $mh = $loginInfo['mh'];
     $ck = $loginInfo['ck'];
     $post = array('uh' => $mh, 'sr' => $options['rdSubReddit'], 'title' => $title, 'save' => true);
     if ($options['postType'] == 'A') {
         $post['url'] = $message['url'];
         $post['kind'] = 'link';
         $retNum = 16;
     } else {
         $post['text'] = $text;
         $post['kind'] = 'self';
         $retNum = 10;
     }
     $url = "http://www.reddit.com/api/submit";
     $postParams = array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'extension' => 'json', 'headers' => $hdrsArr, 'body' => $post, 'cookies' => $ck);
     $response = wp_remote_post($url, $postParams);
     // prr($postParams); prr($response);
     if (is_wp_error($response)) {
         $badOut['Error'] = print_r($response, true) . " - ERROR";
         return $badOut;
     }
     $response = json_decode($response['body'], true);
     $rdNewPostID = 'http://www.reddit.com';
     // prr($response);
     if (!isset($response['jquery']) || !is_array($response['jquery'])) {
         $badOut['Error'] = print_r($response, true) . " - ERROR";
         return $badOut;
     }
     $r = $response['jquery'];
     if (is_array($r[$retNum][3]) && count($r[$retNum][3]) > 0 && stripos($r[$retNum][3][0], 'http://') !== false) {
         $rdNewPostID = $r[$retNum][3][0];
     }
     if (isset($r[18]) && is_array($r[18][3]) && count($r[18][3]) > 0 && stripos($r[18][3][0], 'error.BAD_CAPTCHA') !== false) {
         $badOut['Error'] = "ERROR: Post Rejected. Reddit thinks that you don't have rights to post here";
         return $badOut;
     }
     if (isset($r[18]) && is_array($r[18][3]) && count($r[18][3]) > 0 && stripos($r[18][3][0], 'error') !== false) {
         $badOut['Error'] = "ERROR: " . $r[18][3][0];
         return $badOut;
     }
     if (is_array($r[$retNum][3]) && count($r[$retNum][3]) > 0 && stripos($r[$retNum][3][0], 'http://') === false) {
         $badOut['Error'] = print_r($r[$retNum][3][0], true) . " - ERROR";
         return $badOut;
     }
     if (isset($r[18]) && is_array($r[18][3]) && count($r[18][3]) > 0 && stripos($r[18][3][0], 'already been submitted') !== false) {
         $rdNewPostID .= str_ireplace('?already_submitted=true', '', $r[10][3][0]);
     }
     // echo "ID:".$rdNewPostID;
     if ($rdNewPostID != 'http://www.reddit.com') {
         return array('postID' => $rdNewPostID, 'isPosted' => 1, 'postURL' => $rdNewPostID, '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;
 }
Beispiel #6
0
 function nxs_doPublishToVK($postID, $options)
 {
     global $ShownAds, $nxs_vkCkArray;
     $ntCd = 'VK';
     $ntCdL = 'vk';
     $ntNm = 'vKontakte(VK)';
     $vidURL = '';
     $imgVURL = '';
     $dsc = '';
     $lng = '';
     if (!is_array($options)) {
         $options = maybe_unserialize(get_post_meta($postID, $options, true));
     }
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToVK',  array($postID, $options));
     $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName']));
     if (empty($options['imgToUse'])) {
         $options['imgToUse'] = '';
     }
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#000080">vKontakte</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $options['pType']);
             return;
         }
     }
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $urlToGo = home_url();
         $msg = 'Test Link from ' . $urlToGo;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $options['msgFrmt'] = nxs_decodeEntitiesFull(strip_tags(nsFormatMessage($options['msgFrmt'], $postID, $addParams)));
         //## MyURL - URLToGo code
         $options = nxs_getURL($options, $postID, $addParams);
         $urlToGo = $options['urlToUse'];
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
     }
     $extInfo = ' | PostID: ' . $postID . " - " . (is_object($post) ? $post->post_title : '') . ' |' . $options['pType'];
     //## Message & Format
     if (trim($options['imgToUse']) != '') {
         $imgURL = $options['imgToUse'];
     } else {
         $imgURL = nxs_getPostImage($postID, 'full');
     }
     if (preg_match("/noImg.\\.png/i", $imgURL)) {
         $imgURL = '';
     }
     if (function_exists('nxs_doPostToVK')) {
         $vids = nsFindVidsInPost($post);
         if (count($vids) > 0) {
             if (strlen($vids[0]) == 11) {
                 $vidURL = 'http://www.youtube.com/watch?v=' . $vids[0];
                 $imgURL = 'http://img.youtube.com/vi/' . $vids[0] . '/maxresdefault.jpg';
             }
             if (strlen($vids[0]) == 8) {
                 $vidURL = 'https://secure.vimeo.com/moogaloop.swf?clip_id=' . $vids[0] . '&autoplay=1';
                 //$mssg['source'] = 'http://player.vimeo.com/video/'.$vids[0];
                 $apiURL = "http://vimeo.com/api/v2/video/" . $vids[0] . ".json?callback=showThumb";
                 $json = wp_remote_get($apiURL);
                 if (!is_wp_error($json)) {
                     $json = $json['body'];
                     $json = str_replace('showThumb(', '', $json);
                     $json = str_replace('])', ']', $json);
                     $json = json_decode($json, true);
                     $imgVURL = $json[0]['thumbnail_large'];
                 }
             }
         }
     }
     if (!empty($options['attchAsVid']) && $options['attchAsVid'] == '1' && trim($imgVURL) != '') {
         $imgURL = $imgVURL;
     }
     if ($options['postType'] == 'A') {
         if (trim($options['msgAFormat']) != '') {
             $dsc = nsFormatMessage($options['msgAFormat'], $postID, $addParams);
         } else {
             if (function_exists('aioseop_mrt_fix_meta') && $dsc == '') {
                 $dsc = trim(get_post_meta($postID, '_aioseop_description', true));
             }
             if (function_exists('wpseo_admin_init') && $dsc == '') {
                 $dsc = trim(get_post_meta($postID, '_yoast_wpseo_opengraph-description', true));
             }
             if (function_exists('wpseo_admin_init') && $dsc == '') {
                 $dsc = trim(get_post_meta($postID, '_yoast_wpseo_metadesc', true));
             }
             if (is_object($post) && $dsc == '') {
                 $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng)));
             }
             if ($dsc == '') {
                 $dsc = trim(nxs_doQTrans($post->post_excerpt, $lng));
             }
             if (is_object($post) && $dsc == '') {
                 $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)));
             }
             if ($dsc == '') {
                 $dsc = trim(nxs_doQTrans($post->post_content, $lng));
             }
             if (is_object($post) && $dsc == '') {
                 $dsc = get_bloginfo('description');
             }
         }
         $dsc = strip_tags($dsc);
         $dsc = nxs_decodeEntitiesFull($dsc);
         $dsc = nsTrnc($dsc, 900, ' ');
     } else {
         $dsc = '';
     }
     $message = array('siteName' => $blogTitle, 'url' => $urlToGo, 'imageURL' => $imgURL, 'videoURL' => $vidURL, 'urlTitle' => nxs_decodeEntitiesFull(nxs_doQTrans($post->post_title, $lng)), 'urlDescr' => $dsc);
     //## Actual Post
     $ntToPost = new nxs_class_SNAP_VK();
     $ret = $ntToPost->doPostToNT($options, $message);
     //## Check Phone Req Return
     if (is_string($ret) && stripos($ret, 'Phone verification required:') !== false) {
         global $plgn_NS_SNAutoPoster;
         $gOptions = $plgn_NS_SNAutoPoster->nxs_options;
         $phtext = str_ireplace('Phone verification required: ', '', $ret);
         $ret .= ". Please refresh/reload the SNAP settings page and enter your phone.";
         $gOptions['vk'][$ii]['vkPhReq'] = $phtext;
         update_option('NS_SNAutoPoster', $gOptions);
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true) . " - BAD USER/PASS", $extInfo);
         return " -= BAD USER/PASS - Phone verification required =- ";
     }
     //## Save Session
     if (empty($options['vkSvC']) || serialize($nxs_vkCkArray) != $options['vkSvC']) {
         global $plgn_NS_SNAutoPoster;
         $gOptions = $plgn_NS_SNAutoPoster->nxs_options;
         if (isset($options['ii']) && $options['ii'] !== '') {
             $gOptions['vk'][$options['ii']]['vkSvC'] = serialize($nxs_vkCkArray);
             update_option('NS_SNAutoPoster', $gOptions);
         } else {
             foreach ($gOptions['vk'] as $ii => $gpn) {
                 $result = array_diff($options, $gpn);
                 if (!is_array($result) || count($result) < 1) {
                     $gOptions['vk'][$ii]['vkSvC'] = serialize($nxs_vkCkArray);
                     update_option('NS_SNAutoPoster', $gOptions);
                     break;
                 }
             }
         }
     }
     //## Process Results
     if (is_array($ret) && !empty($ret['err'])) {
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     }
     if (!is_array($ret) || $ret['isPosted'] != '1') {
         //## Error
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         // ## All Good - log it.
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap');
         } else {
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s')));
             $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>';
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     //## Return Result
     if ($ret['isPosted'] == '1') {
         return 200;
     } else {
         return print_r($ret, true);
     }
 }
Beispiel #7
0
 function nxs_doPublishToTW($postID, $options)
 {
     $ntCd = 'TW';
     $ntCdL = 'tw';
     $ntNm = 'Twitter';
     $img = '';
     $imgURL = '';
     global $nxs_urlLen;
     $nxs_urlLen = 0;
     //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Error', $logNT, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTW',  array($postID, $options));
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#00FFFF">Twitter</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $options['pType']);
             return;
         }
     }
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $uln = 0;
     if ($options['attchImg'] == '1') {
         $imgURL = nxs_getPostImage($postID);
         if (trim($imgURL) == '') {
             $options['attchImg'] = 0;
         } else {
             if (ini_get('allow_url_fopen')) {
                 if (@getimagesize($imgURL) !== false) {
                     $img = wp_remote_get($imgURL);
                     if ($img['headers']['content-length'] < 200) {
                         $options['attchImg'] = 0;
                     } else {
                         if (is_wp_error($img)) {
                             $options['attchImg'] = 0;
                         } else {
                             $img = $img['body'];
                         }
                     }
                 } else {
                     $options['attchImg'] = 0;
                 }
             } else {
                 $img = wp_remote_get($imgURL);
                 if (is_wp_error($img)) {
                     $options['attchImg'] = 0;
                 } elseif (isset($img['body']) && trim($img['body']) != '') {
                     $img = $img['body'];
                 } else {
                     $options['attchImg'] = 0;
                 }
             }
         }
         if ($options['attchImg'] == 0) {
             nxs_addToLogN('E', 'Error', $logNT, 'Could not get image, will post without it', $extInfo);
         }
     }
     if ($options['attchImg'] == '1' && $img != '') {
         $twLim = 118;
     } else {
         $twLim = 140;
     }
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $msg = 'Test Post from ' . nsTrnc($blogTitle, $twLim - 24) . " - " . rand(1, 155);
         $uln = nxs_strLen($msg);
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $twMsgFormat = $options['twMsgFormat'];
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
         if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) {
             $twLim = $twLim - 22;
         }
         if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) {
             $aun = $post->post_author;
             $aun = get_the_author_meta('display_name', $aun);
             $twLim = $twLim - nxs_strLen($aun);
         }
         $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat);
         $noRepl = str_ireplace("%SITENAME%", "", $noRepl);
         $noRepl = str_ireplace("%URL%", "", $noRepl);
         $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl);
         $noRepl = str_ireplace("%SURL%", "", $noRepl);
         $noRepl = str_ireplace("%TEXT%", "", $noRepl);
         $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl);
         $noRepl = str_ireplace("%EXCERPT%", "", $noRepl);
         $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl);
         $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl);
         $twLim = $twLim - nxs_strLen($noRepl);
         $pTitle = $title = $post->post_title;
         if ($post->post_excerpt != "") {
             $exrText = $post->post_excerpt;
         } else {
             $exrText = $post->post_content;
         }
         $pText = apply_filters('the_content', $exrText);
         $pRawText = $post->post_content;
         $pFullText = apply_filters('the_content', $pRawText);
         if (stripos($twMsgFormat, '%TAGS%') !== false || stripos($twMsgFormat, '%HTAGS%') !== false) {
             $t = wp_get_object_terms($postID, 'product_tag');
             if (empty($t) || is_wp_error($pt) || !is_array($t)) {
                 $t = wp_get_post_tags($postID);
             }
             $tggs = array();
             foreach ($t as $tagA) {
                 $frmTag = trim(str_replace(' ', '', preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&amp;', '', $tagA->name)))))));
                 if (preg_match('/\\b' . $frmTag . '\\b/iu', $pTitle)) {
                     $pTitle = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pTitle));
                 }
                 if (preg_match('/\\b' . $frmTag . '\\b/iu', $pFullText)) {
                     $pFullText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pFullText));
                 }
                 if (preg_match('/\\b' . $frmTag . '\\b/iu', $pText)) {
                     $pText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pText));
                 }
                 if (preg_match('/\\b' . $frmTag . '\\b/iu', $pRawText)) {
                     $pRawText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pRawText));
                 }
                 if (stripos($twMsgFormat, '%TITLE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pTitle) || stripos($twMsgFormat, '%TEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%EXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%FULLTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pFullText) || stripos($twMsgFormat, '%RAWTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pRawText)) {
                 } else {
                     $tggs[] = '#' . $frmTag;
                 }
             }
             $tags = implode(' ', $tggs);
             while (count($tags) > $twLim - 10) {
                 array_pop($tggs);
                 $tags = implode(' ', $tggs);
             }
             $twMsgFormat = str_ireplace("%TAGS%", $tags, $twMsgFormat);
             $twMsgFormat = str_ireplace("%HTAGS%", $tags, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($tags);
         }
         if (stripos($twMsgFormat, '%CATS%') !== false || stripos($twMsgFormat, '%HCATS%') !== false) {
             $t = wp_get_post_categories($postID);
             $ctts = array();
             foreach ($t as $c) {
                 $cat = get_category($c);
                 $frmTag = trim(str_replace(' ', '', str_replace('  ', ' ', str_ireplace('&', '&amp;', trim(ucwords($cat->name))))));
                 if (stripos($pTitle, $cat->name) !== false) {
                     $pTitle = str_ireplace($cat->name, '#' . $frmTag, $pTitle);
                 } elseif (stripos($pTitle, $frmTag) !== false) {
                     $pTitle = str_ireplace($frmTag, '#' . $frmTag, $pTitle);
                 }
                 if (stripos($pText, $cat->name) !== false) {
                     $pText = str_ireplace($cat->name, '#' . $frmTag, $pText);
                 } elseif (stripos($pText, $frmTag) !== false) {
                     $pText = str_ireplace($frmTag, '#' . $frmTag, $pText);
                 }
                 if (stripos($pFullText, $cat->name) !== false) {
                     $pFullText = str_ireplace($cat->name, '#' . $frmTag, $pFullText);
                 } elseif (stripos($pFullText, $frmTag) !== false) {
                     $pFullText = str_ireplace($frmTag, '#' . $frmTag, $pFullText);
                 }
                 if (stripos($pRawText, $cat->name) !== false) {
                     $pRawText = str_ireplace($cat->name, '#' . $frmTag, $pRawText);
                 } elseif (stripos($pRawText, $frmTag) !== false) {
                     $pRawText = str_ireplace($frmTag, '#' . $frmTag, $pRawText);
                 }
                 if (stripos($twMsgFormat, '%TITLE%') !== false && (stripos($pTitle, $cat->name) !== false || stripos($pTitle, $frmTag) !== false) || stripos($twMsgFormat, '%TEXT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%EXCERPT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && (stripos($exrText, $cat->name) !== false || stripos($exrText, $frmTag) !== false) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%FULLTEXT%') !== false && (stripos($pFullText, $cat->name) !== false || stripos($pFullText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWTEXT%') !== false && (stripos($pRawText, $cat->name) !== false || stripos($pRawText, $frmTag) !== false)) {
                 } else {
                     $ctts[] = '#' . $frmTag;
                 }
             }
             $cats = implode(' ', $ctts);
             while (count($cats) > $twLim - 10) {
                 array_pop($ctts);
                 $cats = implode(' ', $ctts);
             }
             $twMsgFormat = str_ireplace("%CATS%", $cats, $twMsgFormat);
             $twMsgFormat = str_ireplace("%HCATS%", $cats, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($cats);
         }
         if (stripos($twMsgFormat, '%TITLE%') !== false) {
             if (stripos($pTitle, '.co.uk') !== false) {
                 $twLim = $twLim - 14;
             }
             if (stripos($pTitle, '.com') !== false) {
                 $twLim = $twLim - 16;
             }
             if (stripos($pTitle, '.net') !== false) {
                 $twLim = $twLim - 16;
             }
             if (stripos($pTitle, '.org') !== false) {
                 $twLim = $twLim - 16;
             }
             $pTitle = html_entity_decode(strip_tags($pTitle), ENT_NOQUOTES, 'UTF-8');
             $pTitle = nsTrnc($pTitle, $twLim);
             $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pTitle);
         }
         if (stripos($twMsgFormat, '%SITENAME%') !== false) {
             $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
             $siteTitle = nsTrnc($siteTitle, $twLim);
             $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($siteTitle);
         }
         if (stripos($twMsgFormat, '%TEXT%') !== false) {
             $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "...");
             $pText = nsTrnc($pText, $twLim);
             $twMsgFormat = str_ireplace("%TEXT%", $pText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pText);
         }
         if (stripos($twMsgFormat, '%EXCERPT%') !== false) {
             $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "...");
             $pText = nsTrnc($pText, $twLim);
             $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pText);
         }
         if (stripos($twMsgFormat, '%RAWEXCERPT%') !== false) {
             $exrText = nsTrnc(strip_tags(strip_shortcodes($exrText)), 300, " ", "...");
             $exrText = nsTrnc($exrText, $twLim);
             $twMsgFormat = str_ireplace("%RAWEXCERPT%", $exrText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($exrText);
         }
         if (stripos($twMsgFormat, '%FULLTEXT%') !== false) {
             $pFullText = nsTrnc(strip_tags($pFullText), $twLim);
             $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pFullText);
         }
         if (stripos($twMsgFormat, '%RAWTEXT%') !== false) {
             $pRawText = nsTrnc(strip_tags($pRawText), $twLim);
             $twMsgFormat = str_ireplace("%RAWTEXT%", $pRawText, $twMsgFormat);
             $twLim = $twLim - nxs_strLen($pRawText);
         }
         $msg = nsFormatMessage($twMsgFormat, $postID);
     }
     $message = array('message' => $msg, 'img' => $img, 'urlLength' => $nxs_urlLen);
     //## Actual Post
     $ntToPost = new nxs_class_SNAP_TW();
     $ret = $ntToPost->doPostToNT($options, $message);
     //## Process Results
     if (!is_array($ret) || $ret['isPosted'] != '1') {
         //## Error
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         // ## All Good - log it.
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap');
         } else {
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s')));
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     //## Return Result
     if ($ret['isPosted'] == '1') {
         return 200;
     } else {
         return print_r($ret, true);
     }
 }
Beispiel #8
0
 function nxs_doPublishToBG($postID, $options)
 {
     $ntCd = 'BG';
     $ntCdL = 'bg';
     $ntNm = 'Blogger';
     //  $uqID = uniqid('BG_');
     //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
     // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToBG',  array($postID, $options));
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'ACCNAME' => $options['nName'], 'POSTID' => $postID));
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#F87907">' . $ntNm . '</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate');
             return;
         }
     }
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $msgT = 'Test Post from ' . htmlentities($blogTitle);
         $link = home_url();
         $msg = 'Test Post from ' . $blogTitle . " " . $link;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $msgFormat = $options['bgMsgFormat'];
         $msg = nsFormatMessage($msgFormat, $postID, $addParams);
         $link = get_permalink($postID);
         $msgTFormat = $options['bgMsgTFormat'];
         $msgT = nsFormatMessage($msgTFormat, $postID, $addParams);
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
     }
     $extInfo = ' | PostID: ' . $postID . " - " . nxs_doQTrans($post->post_title, $lng);
     //## Actual POST Code
     $email = $options['bgUName'];
     $pass = substr($options['bgPass'], 0, 5) == 'b4d7s' ? nsx_doDecode(substr($options['bgPass'], 5)) : $options['bgPass'];
     $blogID = $options['bgBlogID'];
     //echo "###".$auth."|".$blogID."|".$msgT."|".$msg;
     if ($options['bgInclTags'] == '1') {
         $t = wp_get_post_tags($postID);
         $tggs = array();
         foreach ($t as $tagA) {
             $tggs[] = $tagA->name;
         }
         $tags = implode('","', $tggs);
         $tags = nsTrnc($tags, 195, ',', '');
     }
     if (substr($tags, -1) == '"') {
         $tags = substr($tags, 0, -1);
     }
     if (class_exists('DOMDocument')) {
         $doc = new DOMDocument();
         @$doc->loadHTML('<?xml encoding="UTF-8">' . $msg);
         $doc->encoding = 'UTF-8';
         $msg = $doc->saveHTML();
         $msg = CutFromTo($msg, '<body>', '</body>');
         $msg = preg_replace('/<br(.*?)\\/?>/', '<br$1/>', $msg);
         $msg = preg_replace('/<img(.*?)\\/?>/', '<img$1/>', $msg);
         require_once 'apis/htmlNumTable.php';
         if (is_array($HTML401NamedToNumeric)) {
             $msg = strtr($msg, $HTML401NamedToNumeric);
             $msgT = strtr($msgT, $HTML401NamedToNumeric);
         }
     }
     //  prr($text);
     // prr($msg); echo " =HT= ";
     $msg = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $msg);
     $msg = preg_replace('/<!--(.*)-->/Uis', "", $msg);
     $nxshf = new NXS_HtmlFixer();
     $nxshf->debug = false;
     $msg = $nxshf->getFixedHtml($msg);
     $msg = str_replace("\r\n", "\n", $msg);
     $msg = str_replace("\n\r", "\n", $msg);
     $msg = str_replace("\r", "\n", $msg);
     $msg = str_replace("\n", "<br/>", $msg);
     //  prr($msg); die();
     if (function_exists("doConnectToBlogger")) {
         $auth = doConnectToBlogger($email, $pass);
         if ($auth !== false) {
             $ret = $auth;
         } else {
             $ret = doPostToBlogger($blogID, $msgT, $msg, $tags);
         }
     } else {
         $auth = nsBloggerGetAuth($email, $pass);
         if ($auth === false) {
             $ret = 'Incorrect Username/Password';
         } else {
             $msgT = str_ireplace('&amp;', '&', $msgT);
             $msgT = utf8_encode(str_ireplace('&', '&amp;', $msgT));
             $msg = utf8_encode($msg);
             $ret = nsBloggerNewPost($auth, $blogID, $msgT, $msg);
         }
     }
     //## /Actual POST Code
     if (!is_array($ret) && $ret != 'OK') {
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . strip_tags(print_r($ret, true)), $extInfo);
         return $ret;
     } else {
         if ($postID == '0') {
             echo 'OK - Message Posted, please see your ' . $ntNm . ' Page ';
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             return 201;
         } else {
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s')));
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
         return 200;
     }
 }
Beispiel #9
0
 function doPostToNT($options, $message)
 {
     $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     // prr($message);  prr($options);
     //## Check API Lib
     //if (!function_exists('doConnectToBlogger')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php');
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if ((!isset($options['bgUName']) || empty($options['bgPass'])) && empty($options['AccessToken'])) {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['bgMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['bgMsgTFormat'], $message);
     }
     if ($options['bgInclTags'] == '1') {
         $tags = nsTrnc($message['tags'], 195, ',', '');
     } else {
         $tags = '';
     }
     //## Check/Fix HTML
     if (class_exists('DOMDocument')) {
         $doc = new DOMDocument();
         @$doc->loadHTML('<?xml encoding="UTF-8">' . $msg);
         $doc->encoding = 'UTF-8';
         $msg = $doc->saveHTML();
         $msg = CutFromTo($msg, '<body>', '</body>');
         $msg = preg_replace('/<br(.*?)\\/?>/', '<br$1/>', $msg);
         $msg = preg_replace('/<img(.*?)\\/?>/', '<img$1/>', $msg);
         require 'apis/htmlNumTable.php';
         if (is_array($HTML401NamedToNumeric)) {
             $msg = strtr($msg, $HTML401NamedToNumeric);
             $msgT = strtr($msgT, $HTML401NamedToNumeric);
         }
     }
     $msg = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $msg);
     $msg = preg_replace('/<!--(.*)-->/Uis', "", $msg);
     $nxshf = new NXS_HtmlFixer();
     $nxshf->debug = false;
     $msg = $nxshf->getFixedHtml($msg);
     $msg = str_replace("\r\n", "\n", $msg);
     $msg = str_replace("\n\r", "\n", $msg);
     $msg = str_replace("\r", "\n", $msg);
     $msg = str_replace("\n", "<br/>", $msg);
     //## Make Post
     $email = $options['bgUName'];
     $pass = substr($options['bgPass'], 0, 5) == 'b4d7s' ? nsx_doDecode(substr($options['bgPass'], 5)) : $options['bgPass'];
     $blogID = $options['bgBlogID'];
     // prr($msgT); prr($msg); die();
     if (class_exists('nxsAPI_GP') && !empty($options['bgUName']) && empty($options['APIKey'])) {
         $nt = new nxsAPI_GP();
         if (!empty($options['ck'])) {
             $nt->ck = $options['ck'];
         }
         $nt->debug = false;
         $loginError = $nt->connect($email, $pass, 'BG');
         if (!$loginError) {
             $result = $nt->postBG($blogID, $msgT, $msg, $tags);
             // prr($result);
         } else {
             $badOut['Error'] = "Login/Connection Error: " . print_r($loginError, true);
             return $badOut;
         }
         if (is_array($result) && $result['isPosted'] == '1') {
             nxs_save_glbNtwrks('bg', $options['ii'], $nt->ck, 'ck');
         }
         return $result;
     } else {
         //## Refresh token
         if (function_exists('get_option')) {
             $currTime = time() + get_option('gmt_offset') * HOUR_IN_SECONDS;
         } else {
             $currTime = time();
         }
         if ($options['AccessTokenExp'] < $currTime) {
             $tknURL = 'https://www.googleapis.com/oauth2/v3/token?refresh_token=' . $options['RefreshToken'] . '&client_id=' . $options['APIKey'] . '&client_secret=' . $options['APISec'] . '&grant_type=refresh_token';
             $response = wp_remote_post($tknURL);
             $resp = json_decode($response['body'], true);
             $options['AccessToken'] = $resp['access_token'];
             $options['AccessTokenExp'] = $currTime + $resp['expires_in'];
             nxs_save_glbNtwrks('bg', $options['ii'], $resp['access_token'], 'AccessTokenExp');
             nxs_save_glbNtwrks('bg', $options['ii'], $options['AccessTokenExp'], 'AccessTokenExp');
             //nxs_addToLogN('S', 'Test', $logNT, 'Token Refreshed '.date('Y-m-d H:i:s',$options['AccessTokenExp'])."|".$tknURL.$options['AccessToken'].print_r($response, true));
         }
         //## Post
         $post = array("kind" => "blogger#post", "blog" => array("id" => $blogID), "title" => $msgT, "content" => $msg);
         $post = json_encode($post);
         // prr($post);
         $hdrsArr = array('Content-Type' => 'application/json');
         $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'body' => $post);
         $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/' . $blogID . '/posts?access_token=' . $options['AccessToken'] . '';
         $ret = '';
         $response = wp_remote_post($tknURL, $advSet);
         //prr($tknURL); prr($response);
         if (is_object($response) && isset($response->errors)) {
             $badOut['Error'] = print_r($response, true);
         } else {
             $ret = json_decode($response['body'], true);
         }
         //prr($ret);
         if (is_array($ret) && !empty($ret['id'])) {
             return array('postID' => $ret['id'], 'isPosted' => 1, 'postURL' => $ret['url'], 'pDate' => date('Y-m-d H:i:s'));
         } else {
             $badOut['Error'] .= "Error: " . print_r($ret, true);
             return $badOut;
         }
     }
     //## Return
     if (is_array($ret) && $ret['post_id'] != '') {
         return array('postID' => $ret['post_id'], 'isPosted' => 1, 'postURL' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= print_r($ret, true);
         return $badOut;
     }
 }
 function doPostToNT($options, $message)
 {
     $badOut = array('Warning' => '', 'Error' => '');
     $wprg = array('sslverify' => false, 'timeout' => 30);
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if (empty($options['fbAppAuthToken']) && empty($options['atpKey']) && empty($options['uName'])) {
         $badOut['Error'] = 'No Auth Token Found/Not configured';
         return $badOut;
     }
     //## Make Post
     // $facebook = new NXS_Facebook(array( 'appId' => $options['fbAppID'], 'secret' => $options['fbAppSec'], 'cookie' => true ));
     if (!empty($options['fbAppAuthToken'])) {
         if (!isset($options['fbAppPageAuthToken']) || trim($options['fbAppPageAuthToken']) == '') {
             $options['fbAppPageAuthToken'] = $options['fbAppAuthToken'];
         }
     }
     //## Some OLD Format Conversion
     if (!isset($options['attachType']) && isset($options['fbAttch'])) {
         $options['attachType'] = $options['fbAttch'];
     }
     if (!isset($options['postType']) && isset($options['fbPostType'])) {
         $options['postType'] = $options['fbPostType'];
     }
     $fbPostType = $options['postType'];
     //## Compatibility with v <3.2
     if (!isset($options['pgID']) && isset($options['fbPgID'])) {
         $options['pgID'] = $options['fbPgID'];
     }
     if ($fbPostType != 'I' && $fbPostType != 'T') {
         $url = $message['url'];
         $flds = array('id' => $url, 'scrape' => 'true');
         sleep(2);
     }
     //## Get URL info.
     if ($fbPostType != 'I' && $fbPostType != 'T' && !empty($options['atchUse']) && $options['atchUse'] == 'F') {
         $response = wp_remote_post('http://graph.facebook.com', array('body' => $flds, 'sslverify' => false, 'timeout' => 30));
         if (is_wp_error($response)) {
             $badOut['Error'] = "Error(URL-Info): " . print_r($response, true);
         } else {
             $response = json_decode($response['body'], true);
             //  prr($response);     die();
             if (!empty($response['description'])) {
                 $message['urlDescr'] = $response['description'];
             }
             if (!empty($response['title'])) {
                 $message['urlTitle'] = $response['title'];
             }
             if (!empty($response['site_name'])) {
                 $message['siteName'] = $response['site_name'];
             } elseif ($message['siteName'] == '') {
                 $message['siteName'] = $message['title'];
             }
             if (!empty($response['image'][0]['url'])) {
                 $message['imageURL'] = $response['image'][0]['url'];
             }
         }
     }
     // prr($message);
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['fbMsgFormat'], $message);
     }
     $imgURL = nxs_getImgfrOpt($message['imageURL']);
     $fbWhere = 'feed';
     $attachType = $options['attachType'];
     if ($attachType == '1') {
         $attachType = 'A';
     } else {
         $attachType = 'S';
     }
     if ($options['imgUpl'] != '2') {
         $options['imgUpl'] = 'T';
     } else {
         $options['imgUpl'] = 'A';
     }
     if (stripos($options['fbURL'], '/groups/') != false) {
         $options['destType'] == 'gr';
     }
     if (!empty($options['destType']) && $options['destType'] == 'pr') {
         $page_id = $options['fbAppAuthUser'];
     } else {
         $page_id = $options['pgID'];
     }
     $msg = strip_tags($msg);
     $msg = str_ireplace('&lt;(")', '<(")', $msg);
     //## FB Smiles FIX 3
     if (substr($msg, 0, 1) == '@') {
         $msg = ' ' . $msg;
     }
     // ERROR] couldn't open file fix
     //## Own App Post
     if (!empty($options['fbAppPageAuthToken'])) {
         if (empty($options['appsecret_proof'])) {
             $options['appsecret_proof'] = hash_hmac('sha256', $options['fbAppPageAuthToken'], $options['fbAppSec']);
         }
         $mssg = array('access_token' => $options['fbAppPageAuthToken'], 'appsecret_proof' => $options['appsecret_proof'], 'method' => 'post', 'message' => $msg);
         if ($fbPostType == 'I' && trim($imgURL) == '') {
             $fbPostType = 'T';
         }
         if ($fbPostType == 'A' && !preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $message['url'])) {
             $badOut['Warning'] = 'Unvalid URL: ' . $message['url'] . '| Will be posting as text message';
             $fbPostType = 'T';
         }
         if ($fbPostType == 'A' || $fbPostType == '') {
             if ($attachType == 'A' || $attachType == 'S') {
                 $message['urlTitle'] = nsTrnc($message['urlTitle'], 250, " ", "...");
                 $attArr = array('name' => $message['urlTitle'], 'caption' => $message['siteName'], 'link' => $message['url'], 'description' => $message['urlDescr']);
                 $mssg = array_merge($mssg, $attArr);
             }
             if ($attachType == 'A') {
                 $mssg['actions'] = json_encode(array('name' => $message['siteName'], 'link' => $message['url']));
             }
             if (trim($imgURL) != '') {
                 $mssg['picture'] = $imgURL;
             }
             //if (trim($message['videoURL'])!='') $mssg['source'] = $message['videoURL'];
         } elseif ($fbPostType == 'I') {
             /* $facebook->setFileUploadSupport(true); */
             $fbWhere = 'photos';
             $mssg['url'] = $imgURL;
             if ($options['imgUpl'] == 'T') {
                 //## Try to Post to TImeline
                 $aacct = array('access_token' => $options['fbAppPageAuthToken'], 'appsecret_proof' => $options['appsecret_proof'], 'method' => 'get');
                 $res = wp_remote_get("https://graph.facebook.com/{$page_id}/albums?" . http_build_query($aacct, null, '&'), $wprg);
                 if (is_wp_error($res) || empty($res['body'])) {
                     $badOut['Error'] = ' [ERROR(Albums)] ' . print_r($res, true);
                 } else {
                     $albums = json_decode($res['body'], true);
                     if (empty($albums)) {
                         $badOut['Error'] .= "JSON ERROR (Albums): " . print_r($res, true);
                     } else {
                         if (is_array($albums) && is_array($albums["data"])) {
                             foreach ($albums["data"] as $album) {
                                 if ($album["type"] == "wall") {
                                     $chosen_album = $album;
                                     break;
                                 }
                             }
                         }
                         if (isset($chosen_album) && isset($chosen_album["id"])) {
                             $page_id = $chosen_album["id"];
                         }
                     }
                 }
             }
         }
         //## Actual Post
         $destURL = "https://graph.facebook.com/{$page_id}/" . $fbWhere;
         //  prr($destURL); prr($args);   prr($mssg); //die();
         $response = wp_remote_post($destURL, array('method' => 'POST', 'httpversion' => '1.1', 'timeout' => 30, 'sslverify' => false, 'redirection' => 0, 'body' => $mssg));
     }
     if (is_wp_error($response) || empty($response['body'])) {
         return "ERROR: " . print_r($response, true);
     }
     $res = json_decode($response['body'], true);
     if (empty($res)) {
         return "JSON ERROR: " . print_r($response, true);
     }
     if (!empty($res['error'])) {
         if (!empty($res['error']['message'])) {
             $badOut['Error'] .= $res['error']['message'];
             //## Some Known Errors
             if (stripos($res['error']['message'], 'This API call requires a valid app_id') !== false) {
                 if (!is_numeric($page_id) && stripos($options['fbURL'], '/groups/') != false) {
                     $badOut['Error'] .= ' [ERROR] Unrecognized Facebook Group ID. Please use numeric ID. Please see <a href="http://gd.is/f412">FAQ 4.12</a>';
                 } else {
                     $badOut['Error'] .= " [ERROR] (invalid app_id) Authorization Error. <br/>\r\n<br/>\r\n Possible Reasons: <br/>\r\n 1. Your app is not authorized. Please go to the Plugin Settings - Facebook and authorize it.<br/>\r\n 2. The current authorized user have no rights to post to the specified page. Please login to Facebook as the correct user and Re-Authorize the Plugin.<br/>\r\n 3. You clicked 'Skip' or unchecked the 'Manage Pages' or 'Post on your behalf' permissions when Authorization wizard asked you. Please Re-Authorize the Plugin<br/>\r\n";
                 }
             }
             if (stripos($res['error']['message'], 'Some of the aliases you requested do not exist') !== false) {
                 $badOut['Error'] .= '| Please check what do you have in the "Facebook URL" field.';
             }
             if (stripos($res['error']['message'], 'Unsupported post request') !== false) {
                 $badOut['Error'] .= "<br/>\r\n" . '| Are you posting to a secret group? Please see: <a href="http://gd.is/fbe2">http://gd.is/fbe2</a>';
             }
             if (stripos($res['error']['message'], 'The target user has not authorized this action') !== false) {
                 $badOut['Error'] .= '| Please Authorize the plugin from the plugin settings Page - Facebook.';
             }
             return $badOut;
         } else {
             return print_r($res['error'], true);
         }
     }
     if (empty($res['id'])) {
         return print_r($res, true);
     }
     //## All Good!
     $pgID = isset($res['post_id']) && strpos($res['post_id'], '_') !== false ? $res['post_id'] : $res['id'];
     $pgg = explode('_', $pgID);
     $postID = $pgg[1];
     $pgURL = 'http://www.facebook.com/' . $options['pgID'] . '/posts/' . $postID;
     return array('isPosted' => '1', 'postID' => $pgID, 'postURL' => $pgURL, 'pDate' => date('Y-m-d H:i:s'), 'log' => $badOut);
 }
Beispiel #11
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['dlUName']) || trim($options['dlPass']) == '') {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     $email = $options['dlUName'];
     $pass = substr($options['dlPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['dlPass'], 5)) : $options['dlPass'];
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['dlMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['dlMsgTFormat'], $message);
     }
     $tags = nsTrnc($message['tags'], 195, ',', '');
     $link = $message['url'];
     $desc = substr($msgT, 0, 250);
     $ext = substr($msg, 0, 1000);
     $hdrsArr = $this->getHeaders('https://delicious.com', 'https://delicious.com', true);
     $flds = array('username' => $email, 'password' => base64_encode(strrev($pass)));
     $cnt = wp_remote_post('https://avosapi.delicious.com/api/v1/account/login', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'body' => $flds, 'headers' => $hdrsArr));
     if (is_nxs_error($cnt)) {
         $badOut = "ERROR (Login Form): " . print_r($rep, true);
         return $badOut;
     }
     $rep = json_decode($cnt['body'], true);
     if ($rep['status'] != 'success') {
         $badOut = "ERROR (Login): " . print_r($rep, true);
         return $badOut;
     }
     $ck = $cnt['cookies'];
     $flds = array('url' => $link, 'description' => $desc, 'tags' => $tags, 'note' => $ext, 'replace' => 'true', 'private' => 'false', 'share' => '');
     $advSts = array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'body' => $flds, 'cookies' => $ck, 'headers' => $hdrsArr);
     //prr($advSts);
     $cnt = wp_remote_post('https://avosapi.delicious.com/api/v1/posts/addoredit', $advSts);
     if (is_nxs_error($cnt)) {
         $badOut = "ERROR (Login Form): " . print_r($rep, true);
         return $badOut;
     }
     $rep = json_decode($cnt['body'], true);
     if ($rep['status'] != 'success') {
         $badOut = "ERROR (Login): " . print_r($rep, true);
         return $badOut;
     }
     return array('postID' => md5($message['url']), 'isPosted' => 1, 'postURL' => 'https://delicious.com/link/' . md5($message['url']), 'pDate' => date('Y-m-d H:i:s'));
 }
Beispiel #12
0
 function nxs_doPublishToDI($postID, $options)
 {
     global $nxs_diCkArray;
     $ntCd = 'DI';
     $ntCdL = 'di';
     $ntNm = 'Diigo';
     //  if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToDI',  array($postID, $options));
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#000080">Diigo</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             sleep(5);
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate');
             return;
         }
     }
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $link = home_url();
         $msg = 'Test Message from ' . $link;
         $msgT = 'Test Link from ' . $link;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $link = get_permalink($postID);
         $msgFormat = $options['diMsgFormat'];
         $diCat = $options['diCat'];
         $msg = nsFormatMessage($msgFormat, $postID);
         $msgFormatT = $options['diMsgTFormat'];
         $msgT = nsFormatMessage($msgFormatT, $postID);
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
     }
     $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title;
     //## Actual POST Code
     $email = $options['diUName'];
     $pass = substr($options['diPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['diPass'], 5)) : $options['diPass'];
     $dusername = $options['diUName'];
     //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500));
     $t = wp_get_post_tags($postID);
     $tggs = array();
     foreach ($t as $tagA) {
         $tggs[] = $tagA->name;
     }
     $tags = implode(',', $tggs);
     $tags = str_replace(' ', '+', $tags);
     $flds = array();
     $flds['key'] = $options['diAPIKey'];
     $flds['url'] = $link;
     $flds['title'] = nsTrnc($msgT, 250);
     $flds['desc'] = nsTrnc($msg, 250);
     $flds['tags'] = $tags;
     $flds['shared'] = 'yes';
     $hdrsArr = nxs_getDIHeaders('https://secure.diigo.com/api/v2/bookmarks', $dusername, $pass, true);
     $cnt = wp_remote_post('https://secure.diigo.com/api/v2/bookmarks', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds));
     if (is_wp_error($cnt)) {
         $ret = 'Something went wrong - ';
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . $ret . "ERR: " . print_r($cnt, true), $extInfo);
     } else {
         if (is_array($cnt) && stripos($cnt['body'], '"code":1') !== false) {
             $ret = 'OK';
             nxs_metaMarkAsPosted($postID, 'DI', $options['ii'], array('isPosted' => '1', 'pgID' => 'DI', 'pDate' => date('Y-m-d H:i:s')));
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         } else {
             if ($cnt['response']['code'] == '401') {
                 $ret = " Incorrect Username/Password ";
             } else {
                 $ret = 'Something went wrong - ';
             }
             nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . $ret . "ERR: " . print_r($cnt, true), $extInfo);
         }
     }
     if ($ret != 'OK') {
         if ($postID == '0') {
             echo $ret;
         }
     } else {
         if ($postID == '0') {
             echo 'OK - Message Posted, please see your Diigo Page';
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
         }
     }
     if ($ret == 'OK') {
         return 200;
     } else {
         return $ret;
     }
 }
Beispiel #13
0
 function nxs_doPublishToVK($postID, $options)
 {
     global $ShownAds, $nxs_vkCkArray;
     $ntCd = 'VK';
     $ntCdL = 'vk';
     $ntNm = 'vKontakte(VK)';
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToVK',  array($postID, $options));
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#000080">vKontakte</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $options['pType']);
             return;
         }
     }
     $email = $options['uName'];
     $pass = substr($options['uPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['uPass'], 5)) : $options['uPass'];
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $link = home_url();
         $msg = 'Test Link from ' . $link;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $msgFormat = $options['msgFrmt'];
         $msg = strip_tags(nsFormatMessage($msgFormat, $postID));
         $link = get_permalink($postID);
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
     }
     $dusername = $options['uName'];
     $postType = $options['postType'];
     //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500));
     $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title . ' |' . $options['pType'];
     $imgURL = nxs_getPostImage($postID);
     $vids = nsFindVidsInPost($post);
     if (count($vids) > 0) {
         if (strlen($vids[0]) == 11) {
             $vidURL = 'http://www.youtube.com/watch?v=' . $vids[0];
             $imgURL = 'http://img.youtube.com/vi/' . $vids[0] . '/maxresdefault.jpg';
         }
         if (strlen($vids[0]) == 8) {
             $vidURL = 'https://secure.vimeo.com/moogaloop.swf?clip_id=' . $vids[0] . '&autoplay=1';
             //$mssg['source'] = 'http://player.vimeo.com/video/'.$vids[0];
             $apiURL = "http://vimeo.com/api/v2/video/" . $vids[0] . ".json?callback=showThumb";
             $json = wp_remote_get($apiURL);
             if (!is_wp_error($json)) {
                 $json = $json['body'];
                 $json = str_replace('showThumb(', '', $json);
                 $json = str_replace('])', ']', $json);
                 $json = json_decode($json, true);
                 $imgURL = $json[0]['thumbnail_large'];
             }
         }
     }
     $msgOpts = array();
     $msgOpts['uid'] = $options['vkPgID'];
     // if ($link!='') $msgOpts['link'] = $link;
     if ($vidURL != '' && $postType == "I") {
         $postType = 'A';
         $link = $vidURL;
         $msgOpts['vID'] = $vids[0];
     }
     if ($postType == 'I' && trim($imgURL) == '') {
         $postType = 'T';
     }
     $msgOpts['type'] = $postType;
     if ($postType == 'A' && $link != '') {
         //## Login
         if (isset($options['vkSvC'])) {
             $nxs_vkCkArray = maybe_unserialize($options['vkSvC']);
         }
         $loginError = true;
         if (is_array($nxs_vkCkArray)) {
             $loginError = nxs_doCheckVK();
         }
         if ($loginError != false) {
             $loginError = nxs_doConnectToVK($email, $pass);
         }
         if (serialize($nxs_vkCkArray) != $options['vkSvC']) {
             global $plgn_NS_SNAutoPoster;
             $gOptions = $plgn_NS_SNAutoPoster->nxs_options;
             if (isset($options['ii']) && $options['ii'] !== '') {
                 $gOptions['vk'][$options['ii']]['vkSvC'] = serialize($nxs_vkCkArray);
                 update_option('NS_SNAutoPoster', $gOptions);
             } else {
                 foreach ($gOptions['vk'] as $ii => $gpn) {
                     $result = array_diff($options, $gpn);
                     if (!is_array($result) || count($result) < 1) {
                         $gOptions['vk'][$ii]['vkSvC'] = serialize($nxs_vkCkArray);
                         update_option('NS_SNAutoPoster', $gOptions);
                         break;
                     }
                 }
             }
         }
         if ($loginError !== false) {
             if ($postID == '0') {
                 prr($loginError);
             }
             nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($loginError, true) . " - BAD USER/PASS", $extInfo);
             return " -= BAD USER/PASS =- ";
         }
         //## Post
         if (trim($fbMsgAFormat) != '') {
             $dsc = nsFormatMessage($fbMsgAFormat, $postID);
         } else {
             if (function_exists('aioseop_mrt_fix_meta') && $dsc == '') {
                 $dsc = trim(get_post_meta($postID, '_aioseop_description', true));
             }
             if (function_exists('wpseo_admin_init') && $dsc == '') {
                 $dsc = trim(get_post_meta($postID, '_yoast_wpseo_opengraph-description', true));
             }
             if (function_exists('wpseo_admin_init') && $dsc == '') {
                 $dsc = trim(get_post_meta($postID, '_yoast_wpseo_metadesc', true));
             }
             if ($dsc == '') {
                 $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng)));
             }
             if ($dsc == '') {
                 $dsc = trim(nxs_doQTrans($post->post_excerpt, $lng));
             }
             if ($dsc == '') {
                 $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)));
             }
             if ($dsc == '') {
                 $dsc = trim(nxs_doQTrans($post->post_content, $lng));
             }
             if ($dsc == '') {
                 $dsc = get_bloginfo('description');
             }
         }
         $dsc = strip_tags($dsc);
         $dsc = nxs_decodeEntitiesFull($dsc);
         $dsc = nsTrnc($dsc, 900, ' ');
         $msgOpts['url'] = $link;
         $msgOpts['urlTitle'] = nxs_doQTrans($post->post_title, $lng);
         $msgOpts['urlDesc'] = $dsc;
         $msgOpts['imgURL'] = $imgURL;
         $ret = nxs_doPostToVK($msg, $options['url'], $msgOpts);
         //  prr($ret);
     }
     //prr($postType);
     if ($postType == 'I') {
         $imgUpld = nxs_uplImgtoVK($imgURL, $options);
         if (is_object($imgUpld)) {
             $imgID = $imgUpld->id;
             $atts[] = $imgID;
         }
     }
     if ($postType != 'A') {
         if ($options['addBackLink'] == '1') {
             $atts[] = $link;
         }
         if (is_array($atts)) {
             $atts = implode(',', $atts);
         }
         $postUrl = 'https://api.vkontakte.ru/method/wall.post?owner_id=' . $options['pgIntID'] . '&access_token=' . $options['vkAppAuthToken'] . '&from_group=1&message=' . urlencode($msg) . '&attachment=' . urlencode($atts);
         $response = wp_remote_get($postUrl);
         // prr($atts); prr($postUrl);
         if (is_wp_error($response) || is_object($response) && isset($response->errors) || is_array($response) && stripos($response['body'], '"error":') !== false) {
             $ret = $response['body'];
         } else {
             $respJ = json_decode($response['body'], true);
             $ret = array("code" => "OK", "post_id" => $options['pgIntID'] . '_' . $respJ['response']['post_id']);
         }
     }
     if (is_array($ret) && $ret['code'] == 'OK') {
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo ' OK - Message Posted, please see your VK Page ';
         } else {
             nxs_metaMarkAsPosted($postID, 'VK', $options['ii'], array('isPosted' => '1', 'pgID' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s')));
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
             return 200;
         }
     } else {
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     }
 }
 function postYT($msg, $ytUrl, $vURL = '', $ytGPPageID='') { $ck = $this->ck; $sslverify = false; 
   $ytUrl = str_ireplace('/feed','',$ytUrl); if (substr($ytUrl, -1)=='/') $ytUrl = substr($ytUrl, 0, -1); $ytUrl .= '/feed'; $hdrsArr = $this->headers('http://www.youtube.com/');
   if ($ytGPPageID!=''){ $pgURL = 'https://www.youtube.com/signin?authuser=0&action_handle_signin=true&pageid='.$ytGPPageID;      if ($this->debug) echo "[YT] G SW to page: ".$ytGPPageID."<br/>\r\n";
     $rep = nxs_remote_get($pgURL, array('headers' => $hdrsArr, 'httpversion' => '1.1', 'redirection' => 0, 'cookies' => $ck, 'sslverify'=>$sslverify)); if (is_nxs_error($rep)) return "ERROR: ".print_r($rep, true);
     if (!empty($rep['cookies'])) foreach ($rep['cookies'] as $ccN) { $fdn = false; foreach ($ck as $ci=>$cc) if ($ccN->name == $cc->name) { $fdn = true; $ck[$ci] = $ccN;  } if (!$fdn) $ck[] = $ccN; }       
   } $rep = nxs_remote_get($ytUrl, array('headers' => $hdrsArr, 'httpversion' => '1.1', 'redirection' => 0, 'cookies' => $ck, 'sslverify'=>$sslverify)); if (is_nxs_error($rep)) return "ERROR: ".print_r($rep, true);
   //## Merge CK
   if (!empty($rep['cookies'])) foreach ($rep['cookies'] as $ccN) { $fdn = false; foreach ($ck as $ci=>$cc) if ($ccN->name == $cc->name) { $fdn = true; $ck[$ci] = $ccN;  } if (!$fdn) $ck[] = $ccN; }      
   $contents = $rep['body']; $gpPageMsg = "Either BAD YouTube USER/PASS or you are trying to post from the wrong account/page. Make sure you have Google+ page ID if your YouTube account belongs to the page.";
   $actFormCode = 'channel_ajax'; if (stripos($contents, 'action="/c4_feed_ajax?')!==false) $actFormCode = 'c4_feed_ajax';
   if (stripos($contents, 'action="/'.$actFormCode.'?')) $frmData = CutFromTo($contents, 'action="/'.$actFormCode.'?', '</form>'); else { 
     if (stripos($contents, 'property="og:url"')) {  $ytUrl = CutFromTo($contents, 'property="og:url" content="', '"').'/feed'; 
       $rep = nxs_remote_get($ytUrl, array('headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck, 'sslverify'=>$sslverify)); if (is_nxs_error($rep)) return "ERROR: ".print_r($rep, true); if (!empty($rep['cookies'])) $ck = $rep['cookies'];  $contents = $rep['body'];        
       if (stripos($contents, 'action="/'.$actFormCode.'?')) $frmData = CutFromTo($contents, 'action="/'.$actFormCode.'?', '</form>'); else return 'OG - Form not found. - '. $gpPageMsg;
     } else { $eMsg = "No Form/No OG - ". $gpPageMsg; return $eMsg; }
   }      
   $md = array(); $flds = array(); if ($vURL!='' && stripos($vURL, 'http')===false) $vURL = 'https://www.youtube.com/watch?v='.$vURL; $msg = strip_tags($msg); $msg = nsTrnc($msg, 500);
   while (stripos($frmData, '"hidden"')!==false){$frmData = substr($frmData, stripos($frmData, '"hidden"')+8); $name = trim(CutFromTo($frmData,'name="', '"'));
     if (!in_array($name, $md)) {$md[] = $name; $val = trim(CutFromTo($frmData,'value="', '"')); $flds[$name]= $val;}
   } $flds['message'] = $msg; $flds['video_url'] = $vURL; // prr($flds);
   $ytGPPageID = 'https://www.youtube.com/channel/'.$ytGPPageID; $hdrsArr = $this->headers($ytGPPageID, 'https://www.youtube.com/', 'POST', false); 
   $hdrsArr['X-YouTube-Page-CL'] = '67741289'; $hdrsArr['X-YouTube-Page-Timestamp'] = date("D M j H:i:s Y", time()-54000)." (".time().")"; //'Thu May 22 00:31:51 2014 (1400743911)';
   $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $flds, 'sslverify'=>$sslverify); //prr($advSet);
   $rep = nxs_remote_post('https://www.youtube.com/'.$actFormCode.'?action_add_bulletin=1', $advSet); 
   if (is_nxs_error($rep)) {  $badOut = print_r($rep, true)." - ERROR YT"; return $badOut; }  $contents = $rep['body'];// prr('https://www.youtube.com/'.$actFormCode.'?action_add_bulletin=1'); prr($rep);
           
   if ($rep['response']['code']=='200' && $contents = '{"code": "SUCCESS"}') return array("isPosted"=>"1", "postID"=>'', 'postURL'=>'', 'pDate'=>date('Y-m-d H:i:s')); else return $rep['response']['code']."|".$contents;     
 }              
Beispiel #15
0
 function doPostToNT($options, $message)
 {
     global $nxs_urlLen;
     $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['accessToken']) || trim($options['accessToken']) == '') {
         $badOut['Error'] = 'Not Authorized';
         return $badOut;
     }
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     //## Format Post
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['msgFrmt'], $message);
     }
     //## Make Post
     if (isset($message['imageURL'])) {
         $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize']));
     } else {
         $imgURL = '';
     }
     $postType = $options['postType'];
     require_once 'apis/scOAuth.php';
     $tum_oauth = new wpScoopITOAuth($options['appKey'], $options['appSec'], $options['accessToken'], $options['accessTokenSec']);
     $tum_oauth->baseURL = 'https://api.xing.com';
     $msg = str_replace('&amp;#039;', "'", $msg);
     $msg = str_replace('&#039;', "'", $msg);
     $msg = str_replace('#039;', "'", $msg);
     $msg = str_replace('#039', "'", $msg);
     $msg = str_replace('&amp;#8217;', "'", $msg);
     $msg = str_replace('&#8217;', "'", $msg);
     $msg = str_replace('#8217;', "'", $msg);
     $msg = str_replace('#8217', "'", $msg);
     $msg = str_replace('&amp;#8220;', '"', $msg);
     $msg = str_replace('&#8220;', '"', $msg);
     $msg = str_replace('#8220;', '"', $msg);
     $msg = str_replace('#8220', "'", $msg);
     $msg = str_replace('&amp;#8221;', '"', $msg);
     $msg = str_replace('&#8221;', '"', $msg);
     $msg = str_replace('#8221;', '"', $msg);
     $msg = str_replace('#8221', "'", $msg);
     $msg = str_replace('&amp;#8212;', '-', $msg);
     $msg = str_replace('&#8212;', '-', $msg);
     $msg = str_replace('#8212;', '-', $msg);
     $msg = str_replace('#8212', "-", $msg);
     if ($postType == 'A') {
         $postArr = array('uri' => urlencode($message['url']), 'text' => nsTrnc($msg, 420));
         $postinfo = $tum_oauth->makeReq('https://api.xing.com/v1/users/me/share/link', $postArr, 'POST');
     } else {
         $postArr = array('message' => nsTrnc($msg, 420), 'id' => $options['appAppUserID']);
         $postinfo = $tum_oauth->makeReq('https://api.xing.com/v1/users/' . $options['appAppUserID'] . '/status_message', $postArr, 'POST');
         // prr($postinfo);
     }
     $code = $tum_oauth->http_code;
     if ($code == '201') {
         if (!empty($postinfo) && is_array($postinfo) && !empty($postinfo['ids']) && !empty($postinfo['ids'][0])) {
             $apNewPostID = $postinfo['ids'][0];
         }
         $np = explode('_', $apNewPostID);
         $apNewPostURL = 'https://www.xing.com/feedy/stories/' . $np[0];
     } else {
         $apNewPostID = '';
         $apNewPostURL = 'https://www.xing.com/profile/' . $options['appPGUserName'] . '/activities';
     }
     if (!empty($apNewPostID) || $code == '201') {
         return array('postID' => $apNewPostID, 'isPosted' => 1, 'postURL' => $apNewPostURL, 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= print_r($postinfo, true) . " Code:" . $tum_oauth->http_code;
         return $badOut;
     }
     return $badOut;
 }
Beispiel #16
0
 function nxs_doPublishToPK($postID, $options)
 {
     $ntCd = 'PK';
     $ntCdL = 'pk';
     $ntNm = 'Plurk';
     if (!is_array($options)) {
         $options = maybe_unserialize(get_post_meta($postID, $options, true));
     }
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPK',  array($postID, $options));
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName']));
     if (empty($options['imgToUse'])) {
         $options['imgToUse'] = '';
     }
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#014A76">Plurk</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             sleep(5);
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID);
             return;
         }
     }
     //## Format
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $msg = 'Test Post from ' . $blogTitle;
         $msgT = 'Test Post from ' . $blogTitle;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $twMsgFormat = $options['pkMsgFormat'];
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
         $twLim = 180;
         $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title;
         if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) {
             $twLim = $twLim - 5;
         }
         if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) {
             $aun = $post->post_author;
             $aun = get_the_author_meta('display_name', $aun);
             $twLim = $twLim - strlen($aun);
         }
         $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat);
         $noRepl = str_ireplace("%SITENAME%", "", $noRepl);
         $noRepl = str_ireplace("%URL%", "", $noRepl);
         $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl);
         $noRepl = str_ireplace("%SURL%", "", $noRepl);
         $noRepl = str_ireplace("%TEXT%", "", $noRepl);
         $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl);
         $noRepl = str_ireplace("%EXCERPT%", "", $noRepl);
         $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl);
         $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl);
         $twLim = $twLim - strlen($noRepl);
         $pTitle = $title = $post->post_title;
         if ($post->post_excerpt != "") {
             $pText = apply_filters('the_content', $post->post_excerpt);
         } else {
             $pText = apply_filters('the_content', $post->post_content);
         }
         $pFullText = apply_filters('the_content', $post->post_content);
         $pRawText = $post->post_content;
         if (stripos($twMsgFormat, '%TITLE%') !== false) {
             $pTitle = nsTrnc($pTitle, $twLim);
             $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat);
             $twLim = $twLim - strlen($pTitle);
         }
         if (stripos($twMsgFormat, '%SITENAME%') !== false) {
             $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
             $siteTitle = nsTrnc($siteTitle, $twLim);
             $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat);
             $twLim = $twLim - strlen($siteTitle);
         }
         if (stripos($twMsgFormat, '%EXCERPT%') !== false) {
             $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "...");
             $pText = nsTrnc($pText, $twLim);
             $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat);
             $twLim = $twLim - strlen($pText);
         }
         if (stripos($twMsgFormat, '%FULLTEXT%') !== false) {
             $pFullText = nsTrnc(strip_tags($pFullText), $twLim);
             $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat);
             $twLim = $twLim - strlen($pFullText);
         }
         if (stripos($twMsgFormat, '%RAWTEXT%') !== false) {
             $pRawText = nsTrnc(strip_tags($pRawText), $twLim);
             $twMsgFormat = str_ireplace("%FULLTEXT%", $pRawText, $twMsgFormat);
             $twLim = $twLim - strlen($pRawText);
         }
         $options['pkMsgFormat'] = nsFormatMessage($twMsgFormat, $postID, $addParams);
     }
     if (isset($options['attchImg']) && $options['attchImg'] == '1') {
         if (!empty($options['imgToUse'])) {
             $imgURL = $options['imgToUse'];
         } else {
             $imgURL = nxs_getPostImage($postID, 'full');
         }
     } else {
         $imgURL = '';
     }
     if (preg_match("/noImg.\\.png/i", $imgURL)) {
         $imgURL = '';
     }
     //## Post
     $message = array('siteName' => $blogTitle, 'tags' => '', 'imageURL' => $imgURL);
     // prr($message);
     //## Actual Post
     $ntToPost = new nxs_class_SNAP_PK();
     $ret = $ntToPost->doPostToNT($options, $message);
     //## Process Results
     if (!is_array($ret) || $ret['isPosted'] != '1') {
         //## Error
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         // ## All Good - log it.
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap');
         } else {
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s')));
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     //## Return Result
     if ($ret['isPosted'] == '1') {
         return 200;
     } else {
         return print_r($ret, true);
     }
 }
Beispiel #17
0
 function nxs_doPublishToFB($postID, $options)
 {
     global $ShownAds;
     $ntCd = 'FB';
     $ntCdL = 'fb';
     $ntNm = 'Facebook';
     $dsc = '';
     $vidURL = '';
     if (!is_array($options)) {
         $options = maybe_unserialize(get_post_meta($postID, $options, true));
     }
     if (!class_exists('nxs_class_SNAP_FB')) {
         nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No Facebook API Lib Detected', '');
         return "No Facebook API Lib Detected";
     }
     $fbWhere = 'feed';
     $page_id = $options['fbPgID'];
     if (isset($ShownAds)) {
         $ShownAdsL = $ShownAds;
     }
     $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName']));
     //## Some Common stuff
     if (empty($options['postType']) && !empty($options['fbPostType'])) {
         $options['postType'] = $options['fbPostType'];
         unset($options['fbPostType']);
     }
     //## Compatibility with v <3.2
     if (empty($options['postType']) && !empty($options['PostType'])) {
         $pt = $options['PostType'];
         unset($options['PostType']);
         $options['postType'] = $pt;
     }
     //## Compatibility with v <3.2
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#0000FF">Facebook</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $options['pType']);
             return;
         }
     }
     //## Make the post
     if (isset($options['qTLng'])) {
         $lng = $options['qTLng'];
     } else {
         $lng = '';
     }
     if (!isset($options['fbAppPageAuthToken'])) {
         $options['fbAppPageAuthToken'] = '';
     }
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     //## Initiate Posting Array
     $message = array('message' => '', 'link' => '', 'title' => '', 'description' => '', 'imageURL' => '', 'videoURL' => '', 'siteName' => $blogTitle);
     $imgURL = '';
     if ($postID == '0') {
         $options['fbMsgFormat'] = 'Test Post, Please Ignore';
         $dsc = 'Test Post, Description';
         $urlTitle = 'Test Post - Title';
         $urlToGo = home_url();
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $msg = nsFormatMessage($options['fbMsgFormat'], $postID, $addParams);
         $fbPostType = $options['postType'];
         if ($fbPostType == 'A') {
             $fbPostType = (int) $options['fbAttch'] == 2 ? 'S' : 'A';
         }
         $isAttachVidFB = $options['fbAttchAsVid'];
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
         $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? nxs_doQTrans($post->post_title, $lng) : '') . ' |' . $options['pType'];
         if ($fbPostType == 'A') {
             $imgURL = nxs_getPostImage($postID, 'medium');
         }
         // prr($options); echo "PP - ".$postID; prr($src);
         if ($fbPostType == 'I' || $fbPostType == 'S') {
             $imgURL = nxs_getPostImage($postID, 'full');
         }
         // prr($options); echo "PP - ".$postID; prr($src);
         if ($fbPostType == 'A' || $fbPostType == 'S') {
             //## AUTO - Get Post Descr from SEO Plugins or make it.
             if (trim($options['fbMsgAFrmt']) != '') {
                 $dsc = nsFormatMessage($options['fbMsgAFrmt'], $postID, $addParams);
             } else {
                 if (function_exists('aioseop_mrt_fix_meta') && $dsc == '') {
                     $dsc = trim(get_post_meta($postID, '_aioseop_description', true));
                 }
                 if (function_exists('wpseo_admin_init') && $dsc == '') {
                     $dsc = trim(get_post_meta($postID, '_yoast_wpseo_opengraph-description', true));
                 }
                 if (function_exists('wpseo_admin_init') && $dsc == '') {
                     $dsc = trim(get_post_meta($postID, '_yoast_wpseo_metadesc', true));
                 }
                 if ($dsc == '') {
                     $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng)));
                 }
                 if ($dsc == '') {
                     $dsc = trim(nxs_doQTrans($post->post_excerpt, $lng));
                 }
                 if ($dsc == '') {
                     $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)));
                 }
                 if ($dsc == '') {
                     $dsc = trim(nxs_doQTrans($post->post_content, $lng));
                 }
                 if ($dsc == '') {
                     $dsc = get_bloginfo('description');
                 }
             }
             $dsc = strip_tags(strip_shortcodes($dsc));
             $dsc = nxs_decodeEntitiesFull($dsc);
             $dsc = nsTrnc($dsc, 900, ' ');
         }
         $msg = str_replace('<br>', "\n", $msg);
         $msg = str_replace('<br/>', "\n", $msg);
         $msg = str_replace('<br />', "\n", $msg);
         $msg = str_ireplace('<3', '&lt;3', $msg);
         $msg = str_ireplace('<(', '&lt;(', $msg);
         //## FB Smiles FIX.
         $msg = strip_tags($msg);
         $msg = nxs_decodeEntitiesFull($msg);
         $msg = str_ireplace('&#039;', "'", $msg);
         $msg = str_ireplace('&039;', "'", $msg);
         $msg = str_ireplace('&#39;', "'", $msg);
         $msg = str_ireplace('<3', '&lt;3', $msg);
         $msg = str_ireplace('<(', '&lt;(', $msg);
         //## FB Smiles FIX 2.
         if ($isAttachVidFB == '1') {
             $vids = nsFindVidsInPost($post, false);
             if (count($vids) > 0) {
                 if (strlen($vids[0]) == 11) {
                     $vidURL = 'http://www.youtube.com/v/' . $vids[0];
                     $imgURL = nsGetYTThumb($vids[0]);
                 }
                 if (strlen($vids[0]) == 8) {
                     $vidURL = 'https://secure.vimeo.com/moogaloop.swf?clip_id=' . $vids[0] . '&autoplay=1';
                     $apiURL = "http://vimeo.com/api/v2/video/" . $vids[0] . ".json?callback=showThumb";
                     $json = wp_remote_get($apiURL);
                     if (!is_wp_error($json)) {
                         $json = $json['body'];
                         $json = str_replace('showThumb(', '', $json);
                         $json = str_replace('])', ']', $json);
                         $json = json_decode($json, true);
                         $imgURL = $json[0]['thumbnail_large'];
                     }
                 }
             }
         }
         if (trim($options['imgToUse']) != '') {
             $imgURL = $options['imgToUse'];
         }
         if (preg_match("/noImg.\\.png/i", $imgURL)) {
             $imgURL = 'http://www.noimage.faketld';
         }
         //$imgURL = 'http://cdn.gtln.us/img/t1x1.gif';
         //## MyURL - URLToGo code
         if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') {
             $myurl = trim(get_post_meta($postID, 'snap_MYURL', true));
         }
         if ($myurl != '') {
             $options['urlToUse'] = $myurl;
         }
         if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') {
             $urlToGo = $options['urlToUse'];
             $options['useFBGURLInfo'] = true;
         } else {
             $urlToGo = get_permalink($postID);
         }
         if ($addParams != '') {
             $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addParams;
         }
         //prr($options);
         $urlTitle = nxs_doQTrans($post->post_title, $lng);
         $options['fbMsgFormat'] = $msg;
         $urlTitle = strip_tags(strip_shortcodes($urlTitle));
     }
     $message = array('url' => $urlToGo, 'urlTitle' => $urlTitle, 'urlDescr' => $dsc, 'imageURL' => $imgURL, 'videoURL' => $vidURL, 'siteName' => $blogTitle);
     if (isset($ShownAds)) {
         $ShownAds = $ShownAdsL;
     }
     // FIX for the quick-adsense plugin
     //## Actual Post
     $ntToPost = new nxs_class_SNAP_FB();
     $ret = $ntToPost->doPostToNT($options, $message);
     //## Process Results
     if (!is_array($ret) || $ret['isPosted'] != '1') {
         //## Error
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         // ## All Good - log it.
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap');
         } else {
             nxs_addToRI($postID);
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s')));
             $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>';
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     //## Return Result
     if ($ret['isPosted'] == '1') {
         return 200;
     } else {
         return print_r($ret, true);
     }
 }
 function doPostToNT($options, $message)
 {
     global $nxs_urlLen;
     $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['apAppAuthToken']) || trim($options['apAppAuthToken']) == '') {
         $badOut['Error'] = 'Not Authorized';
         return $badOut;
     }
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     //## Format Post
     if (!empty($message['pText'])) {
         $text = $message['pText'];
     } else {
         $text = nxs_doFormatMsg($options['apTextFormat'], $message);
     }
     $text = nsTrnc($text, 256);
     //## Make Post
     if (isset($message['imageURL'])) {
         $img = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize']));
     } else {
         $img = '';
     }
     if ($options['attchImg'] != false && $img != '') {
         $remoteImg = $this->createFile($img, $options['apAppAuthToken']);
     }
     $ann = array();
     if (is_array($remoteImg)) {
         $ann[] = array("type" => "net.app.core.oembed", "value" => array("+net.app.core.file" => array("file_id" => $remoteImg['id'], "file_token" => $remoteImg['file_token'], "format" => "oembed")));
     }
     $url = "https://alpha-api.app.net/stream/0/posts?include_post_annotations=1&access_token=" . $options['apAppAuthToken'];
     $flds = array('text' => $text, 'annotations' => $ann);
     $flds = json_encode($flds);
     $hdrsArr = array('Content-Type' => 'application/json');
     $response = wp_remote_post($url, array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds));
     if (is_wp_error($response)) {
         $badOut['Error'] = print_r($response, true) . " - ERROR";
         return $badOut;
     }
     $response = json_decode($response['body'], true);
     //prr($response); die();
     //## Check Result
     if (!is_array($response) || !isset($response['meta']) || $response['meta']['code'] != '200' || $response['data']['canonical_url'] == '') {
         $badOut['Error'] = print_r($response, true) . " - ERROR";
         return $badOut;
     }
     $apNewPostURL = $response['data']['canonical_url'];
     $apNewPostID = $response['data']['id'];
     if ($apNewPostID != '') {
         return array('postID' => $apNewPostID, 'isPosted' => 1, 'postURL' => $apNewPostURL, '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;
 }
Beispiel #19
0
 function doPostToNT($options, $message)
 {
     global $nxs_urlLen;
     $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     //## Check settings
     if (!is_array($options)) {
         $badOut = 'No Options';
         return $badOut;
     }
     if (!isset($options['daUName']) || trim($options['daUName']) == '' || !isset($options['daPass']) || trim($options['daPass']) == '') {
         $badOut = 'No username/password Found';
         return $badOut;
     }
     //## Format Post
     if (!empty($message['pTitle'])) {
         $title = $message['pTitle'];
     } else {
         $title = nxs_doFormatMsg($options['daTitleFormat'], $message);
     }
     $title = nsTrnc($title, 300);
     if (!empty($message['pText'])) {
         $text = $message['pText'];
     } else {
         $text = nxs_doFormatMsg($options['daTextFormat'], $message);
     }
     //## Make Post
     if (!empty($options['ck'])) {
         $ck = maybe_unserialize($options['ck']);
     }
     if (!empty($options['mh'])) {
         $mh = maybe_unserialize($options['mh']);
     }
     $pass = substr($options['daPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['daPass'], 5)) : $options['uPass'];
     $nt = new nxsAPI_DA();
     $nt->debug = false;
     if (!empty($ck)) {
         $nt->ck = $ck;
     }
     if (!empty($mh)) {
         $nt->mh = $mh;
     }
     $loginErr = $nt->connect($options['daUName'], $pass);
     if (!$loginErr) {
         $post = array('title' => $title, 'text' => $text);
         $ret = $nt->post($post);
         if (is_array($ret)) {
             $ret['ck'] = $nt->ck;
             $ret['mh'] = $nt->mh;
             return $ret;
         } else {
             return print_r($ret, true);
         }
     } else {
         return print_r($loginErr, true);
     }
 }
Beispiel #20
0
 function nxs_doPublishToLI($postID, $options)
 {
     global $nxs_gCookiesArr;
     $ntCd = 'LI';
     $ntCdL = 'li';
     $ntNm = 'LinkedIn';
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLI',  array($postID, $options));
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#000058">LinkedIn</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             sleep(5);
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID);
             return;
         }
     }
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     // prr($options);
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $msgT = 'Test Post from ' . $blogTitle;
         $link = home_url();
         $msg = 'Test Post from ' . $blogTitle . " " . $link;
         $isAttachLI = '';
         $title = $blogTitle;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $liMsgFormat = $options['liMsgFormat'];
         $msg = nsFormatMessage($liMsgFormat, $postID);
         $msgT = nsFormatMessage($options['liMsgFormatT'], $postID);
         $link = get_permalink($postID);
         $isAttachLI = $options['liAttch'];
         $title = nsTrnc($post->post_title, 200);
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
     }
     $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title;
     $msgT = nsTrnc($msgT, 200);
     if ($isAttachLI == '1') {
         $src = nxs_getPostImage($postID);
         $dsc = trim(apply_filters('the_content', $post->post_excerpt));
         if ($dsc == '') {
             $dsc = apply_filters('the_content', $post->post_content);
         }
         $dsc = strip_tags($dsc);
         $dsc = nxs_decodeEntitiesFull($dsc);
         $dsc = nxs_html_to_utf8($dsc);
         $dsc = nsTrnc($dsc, 300);
     }
     $msg = nxs_html_to_utf8($msg);
     $msgT = nxs_html_to_utf8($msgT);
     if (function_exists("doConnectToLinkedIn") && $options['ulName'] != '' && $options['uPass'] != '') {
         $auth = doConnectToLinkedIn($options['ulName'], $options['uPass'], $options['ii']);
         if ($auth !== false) {
             die($auth);
         }
         $to = $options['uPage'] != '' ? $options['uPage'] : 'http://www.linkedin.com/home';
         $lnk = array();
         $msg = str_ireplace('&nbsp;', ' ', $msg);
         $msg = nsTrnc(strip_tags($msg), 700);
         if ($postID == '0') {
             $lnk['title'] = get_bloginfo('name');
             $lnk['desc'] = get_bloginfo('description');
             $lnk['url'] = home_url();
         } else {
             if ($isAttachLI == '1') {
                 $lnk['title'] = nsTrnc(strip_tags($post->post_title), 200);
                 $lnk['postTitle'] = $msgT;
                 $lnk['desc'] = $dsc;
                 $lnk['url'] = get_permalink($postID);
                 $lnk['img'] = $src;
             }
         }
         //prr($msg);
         $ret = doPostToLinkedIn($msg, $lnk, $to);
         $liPostID = $options['uPage'];
     } else {
         require_once 'apis/liOAuth.php';
         $linkedin = new nsx_LinkedIn($options['liAPIKey'], $options['liAPISec']);
         $linkedin->oauth_verifier = $options['liOAuthVerifier'];
         $linkedin->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
         $linkedin->access_token = new nsx_trOAuthConsumer($options['liAccessToken'], $options['liAccessTokenSecret'], 1);
         $msg = nsTrnc($msg, 700);
         if ($options['grpID'] != '') {
             try {
                 //  prr($msgT); prr($msg); prr($options['grpID']); prr($src);  prr($dsc); $purl = get_permalink($postID); prr($purl);
                 if ($isAttachLI == '1') {
                     $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID'], get_permalink($postID), $src, $dsc);
                 } else {
                     $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID']);
                 }
                 $liPostID = 'http://www.linkedin.com/groups?gid=' . $options['grpID'];
             } catch (Exception $o) {
                 nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . "Linkedin Status couldn't be updated! - " . print_r($o, true));
                 $ret = "ERROR:" . print_r($o, true);
             }
         } else {
             try {
                 if ($isAttachLI == '1') {
                     $ret = $linkedin->postShare($msg, nsTrnc($post->post_title, 200), get_permalink($postID), $src, $dsc);
                 } else {
                     $ret = $linkedin->postShare($msg);
                 }
             } catch (Exception $o) {
                 nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . "<br/>Linkedin Status couldn't be updated! - " . print_r($o, true));
                 $ret = "ERROR:" . print_r($o, true);
             }
         }
         //$liPostID = $linkedin->getCurrentShare(); prr($liPostID);
         if ($liPostID == '') {
             $liPostID = $options['liUserInfo'];
         }
     }
     if (stripos($ret, 'update-url') !== false) {
         $liPostID = CutFromTo($ret, '<update-url>', '</update-url>');
         $ret = '201';
     }
     if ($ret != '201') {
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         if ($postID == '0') {
             echo 'OK - Linkedin status updated successfully';
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
         } else {
             nxs_metaMarkAsPosted($postID, 'LI', $options['ii'], array('isPosted' => '1', 'pgID' => $liPostID, 'pDate' => date('Y-m-d H:i:s')));
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     if ($ret == '201') {
         return true;
     } else {
         return 'Something Wrong';
     }
 }
Beispiel #21
0
 function doPostToNT($options, $message)
 {
     $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     //prr($message); prr($options);
     //## Check API Lib
     //if (!function_exists('doConnectToBlogger')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php');
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if (!isset($options['bgUName']) || trim($options['bgPass']) == '') {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['bgMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['bgMsgTFormat'], $message);
     }
     if ($options['bgInclTags'] == '1') {
         $tags = nsTrnc($message['tags'], 195, ',', '');
     } else {
         $tags = '';
     }
     //## Check/Fix HTML
     if (class_exists('DOMDocument')) {
         $doc = new DOMDocument();
         @$doc->loadHTML('<?xml encoding="UTF-8">' . $msg);
         $doc->encoding = 'UTF-8';
         $msg = $doc->saveHTML();
         $msg = CutFromTo($msg, '<body>', '</body>');
         $msg = preg_replace('/<br(.*?)\\/?>/', '<br$1/>', $msg);
         $msg = preg_replace('/<img(.*?)\\/?>/', '<img$1/>', $msg);
         require 'apis/htmlNumTable.php';
         if (is_array($HTML401NamedToNumeric)) {
             $msg = strtr($msg, $HTML401NamedToNumeric);
             $msgT = strtr($msgT, $HTML401NamedToNumeric);
         }
     }
     $msg = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $msg);
     $msg = preg_replace('/<!--(.*)-->/Uis', "", $msg);
     $nxshf = new NXS_HtmlFixer();
     $nxshf->debug = false;
     $msg = $nxshf->getFixedHtml($msg);
     $msg = str_replace("\r\n", "\n", $msg);
     $msg = str_replace("\n\r", "\n", $msg);
     $msg = str_replace("\r", "\n", $msg);
     $msg = str_replace("\n", "<br/>", $msg);
     //## Make Post
     $email = $options['bgUName'];
     $pass = substr($options['bgPass'], 0, 5) == 'b4d7s' ? nsx_doDecode(substr($options['bgPass'], 5)) : $options['bgPass'];
     $blogID = $options['bgBlogID'];
     // prr($msgT); prr($msg); die();
     if (function_exists("doConnectToBlogger")) {
         $auth = doConnectToBlogger($email, $pass);
         if ($auth !== false) {
             $ret = $auth;
         } else {
             $ret = doPostToBlogger($blogID, $msgT, $msg, $tags);
         }
     } else {
         $auth = $this->nsBloggerGetAuth($email, $pass);
         if ($auth === false) {
             $ret = 'Incorrect Username/Password';
         } else {
             if (is_array($auth)) {
                 $ret = $auth['error'];
             } else {
                 $msgT = str_ireplace('&amp;', '&', $msgT);
                 $msgT = utf8_encode(str_ireplace('&', '&amp;', $msgT));
                 $msg = utf8_encode($msg);
                 $ret = $this->nsBloggerNewPost($auth, $blogID, $msgT, $msg);
             }
         }
     }
     //## Return
     if (is_array($ret) && $ret['post_id'] != '') {
         return array('postID' => $ret['post_id'], 'isPosted' => 1, 'postURL' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= print_r($ret, true);
         return $badOut;
     }
 }
Beispiel #22
0
 function nsFormatMessage($msg, $postID, $addURLParams = '')
 {
     global $ShownAds, $plgn_NS_SNAutoPoster, $nxs_urlLen;
     $post = get_post($postID);
     $options = $plgn_NS_SNAutoPoster->nxs_options;
     // if ($addURLParams=='' && $options['addURLParams']!='') $addURLParams = $options['addURLParams'];
     $msg = stripcslashes($msg);
     if (isset($ShownAds)) {
         $ShownAdsL = $ShownAds;
     }
     // $msg = htmlspecialchars(stripcslashes($msg));
     $msg = nxs_doSpin($msg);
     if (preg_match('%URL%', $msg)) {
         $url = get_permalink($postID);
         if ($addURLParams != '') {
             $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams;
         }
         $nxs_urlLen = nxs_strLen($url);
         $msg = str_ireplace("%URL%", $url, $msg);
     }
     if (preg_match('%SURL%', $msg)) {
         $url = get_permalink($postID);
         if ($addURLParams != '') {
             $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams;
         }
         $url = nxs_mkShortURL($url, $postID);
         $nxs_urlLen = nxs_strLen($url);
         $msg = str_ireplace("%SURL%", $url, $msg);
     }
     if (preg_match('%IMG%', $msg)) {
         $imgURL = nxs_getPostImage($postID);
         $msg = str_ireplace("%IMG%", $imgURL, $msg);
     }
     if (preg_match('%TITLE%', $msg)) {
         $title = nxs_doQTrans($post->post_title, $lng);
         $msg = str_ireplace("%TITLE%", $title, $msg);
     }
     if (preg_match('%STITLE%', $msg)) {
         $title = nxs_doQTrans($post->post_title, $lng);
         $title = substr($title, 0, 115);
         $msg = str_ireplace("%STITLE%", $title, $msg);
     }
     if (preg_match('%AUTHORNAME%', $msg)) {
         $aun = $post->post_author;
         $aun = get_the_author_meta('display_name', $aun);
         $msg = str_ireplace("%AUTHORNAME%", $aun, $msg);
     }
     if (preg_match('%ANNOUNCE%', $msg)) {
         $postContent = nxs_doQTrans($post->post_content, $lng);
         if (stripos($postContent, '<!--more-->') !== false) {
             $postContentEx = explode('<!--more-->', $postContent);
             $postContent = $postContentEx[0];
         } elseif (stripos($postContent, '&lt;!--more--&gt;') !== false) {
             $postContentEx = explode('&lt;!--more--&gt;', $postContent);
             $postContent = $postContentEx[0];
         } else {
             $postContent = nsTrnc($postContent, $options['anounTagLimit']);
         }
         $msg = str_ireplace("%ANNOUNCE%", $postContent, $msg);
     }
     if (preg_match('%TEXT%', $msg)) {
         if ($post->post_excerpt != "") {
             $excerpt = apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng));
         } else {
             $excerpt = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
         }
         $excerpt = nsTrnc(strip_tags(strip_shortcodes($excerpt)), 300, " ", "...");
         $msg = str_ireplace("%TEXT%", $excerpt, $msg);
     }
     if (preg_match('%EXCERPT%', $msg)) {
         if ($post->post_excerpt != "") {
             $excerpt = apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng));
         } else {
             $excerpt = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
         }
         $excerpt = nsTrnc(strip_tags(strip_shortcodes($excerpt)), 300, " ", "...");
         $msg = str_ireplace("%EXCERPT%", $excerpt, $msg);
     }
     if (preg_match('%RAWEXTEXT%', $msg)) {
         if ($post->post_excerpt != "") {
             $excerpt = nxs_doQTrans($post->post_excerpt, $lng);
         } else {
             $excerpt = nxs_doQTrans($post->post_content, $lng);
         }
         $excerpt = nsTrnc(strip_tags(strip_shortcodes($excerpt)), 300, " ", "...");
         $msg = str_ireplace("%RAWEXTEXT%", $excerpt, $msg);
     }
     if (preg_match('%RAWEXCERPT%', $msg)) {
         if ($post->post_excerpt != "") {
             $excerpt = nxs_doQTrans($post->post_excerpt, $lng);
         } else {
             $excerpt = nxs_doQTrans($post->post_content, $lng);
         }
         $excerpt = nsTrnc(strip_tags(strip_shortcodes($excerpt)), 300, " ", "...");
         $msg = str_ireplace("%RAWEXCERPT%", $excerpt, $msg);
     }
     if (preg_match('%TAGS%', $msg)) {
         $t = wp_get_object_terms($postID, 'product_tag');
         if (empty($t) || is_wp_error($pt) || !is_array($t)) {
             $t = wp_get_post_tags($postID);
         }
         $tggs = array();
         foreach ($t as $tagA) {
             $tggs[] = $tagA->name;
         }
         $tags = implode(', ', $tggs);
         $msg = str_ireplace("%TAGS%", $tags, $msg);
     }
     if (preg_match('%CATS%', $msg)) {
         $t = wp_get_post_categories($postID);
         $cats = array();
         foreach ($t as $c) {
             $cat = get_category($c);
             $cats[] = str_ireplace('&', '&amp;', $cat->name);
         }
         $ctts = implode(', ', $cats);
         $msg = str_ireplace("%CATS%", $ctts, $msg);
     }
     if (preg_match('%HCATS%', $msg)) {
         $t = wp_get_post_categories($postID);
         $cats = array();
         foreach ($t as $c) {
             $cat = get_category($c);
             $cats[] = "#" . trim(str_replace(' ', '', str_replace('  ', '', trim(str_ireplace('&', '', str_ireplace('&amp;', '', $cat->name))))));
         }
         $ctts = implode(', ', $cats);
         $msg = str_ireplace("%HCATS%", $ctts, $msg);
     }
     if (preg_match('%HTAGS%', $msg)) {
         $t = wp_get_object_terms($postID, 'product_tag');
         if (empty($t) || is_wp_error($pt) || !is_array($t)) {
             $t = wp_get_post_tags($postID);
         }
         $tggs = array();
         foreach ($t as $tagA) {
             $tggs[] = "#" . trim(str_replace(' ', '', preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&amp;', '', $tagA->name)))))));
         }
         $tags = implode(', ', $tggs);
         $msg = str_ireplace("%HTAGS%", $tags, $msg);
     }
     if (preg_match('%CF-[a-zA-Z0-9]%', $msg)) {
         $msgA = explode('%CF', $msg);
         $mout = '';
         foreach ($msgA as $mms) {
             if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) {
                 $mGr = CutFromTo($mms, '-', '%');
                 $cfItem = get_post_meta($postID, $mGr, true);
                 $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms);
             }
             $mout .= $mms;
         }
         $msg = $mout;
     }
     if (preg_match('%FULLTEXT%', $msg)) {
         $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
         $msg = str_ireplace("%FULLTEXT%", $postContent, $msg);
     }
     if (preg_match('%RAWTEXT%', $msg)) {
         $postContent = nxs_doQTrans($post->post_content, $lng);
         $msg = str_ireplace("%RAWTEXT%", $postContent, $msg);
     }
     if (preg_match('%SITENAME%', $msg)) {
         $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
         $msg = str_ireplace("%SITENAME%", $siteTitle, $msg);
     }
     if (isset($ShownAds)) {
         $ShownAds = $ShownAdsL;
     }
     // FIX for the quick-adsense plugin
     return trim($msg);
 }
 function nxs_doPublishToBG($postID, $options)
 {
     $ntCd = 'BG';
     $ntCdL = 'bg';
     $ntNm = 'Blogger';
     if (!is_array($options)) {
         $options = maybe_unserialize(get_post_meta($postID, $options, true));
     }
     //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
     // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToBG',  array($postID, $options));
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'ACCNAME' => $options['nName'], 'POSTID' => $postID));
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#F87907">' . $ntNm . '</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate');
             return;
         }
     }
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $options['bgMsgTFormat'] = 'Test Post from ' . htmlentities($blogTitle);
         $link = home_url();
         $options['bgMsgFormat'] = 'Test Post from ' . $blogTitle . " " . $link;
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $options['bgMsgFormat'] = nsFormatMessage($options['bgMsgFormat'], $postID, $addParams);
         $options['bgMsgTFormat'] = nsFormatMessage($options['bgMsgTFormat'], $postID, $addParams);
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
     }
     $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : '');
     //## Actual POST Code
     if ($options['bgInclTags'] == '1') {
         $t = wp_get_post_tags($postID);
         $tggs = array();
         foreach ($t as $tagA) {
             $tggs[] = $tagA->name;
         }
         $tags = implode('","', $tggs);
         $tags = nsTrnc($tags, 195, ',', '');
     }
     if (substr($tags, -1) == '"') {
         $tags = substr($tags, 0, -1);
     }
     if (substr($tags, -1) == ',') {
         $tags = substr($tags, 0, -1);
     }
     if (substr($tags, -1) == '"') {
         $tags = substr($tags, 0, -1);
     }
     //## Set Message
     $message = array('title' => '', 'announce' => '', 'text' => '', 'url' => '', 'surl' => '', 'urlDescr' => '', 'urlTitle' => '', 'imageURL' => array(), 'videoCode' => '', 'videoURL' => '', 'siteName' => $blogTitle, 'tags' => $tags, 'cats' => '', 'authorName' => '');
     //## Actual Post
     $ntToPost = new nxs_class_SNAP_BG();
     $ret = $ntToPost->doPostToNT($options, $message);
     //## Process Results
     if (!is_array($ret) || $ret['isPosted'] != '1') {
         //## Error
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         // ## All Good - log it.
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap');
         } else {
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s')));
             $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>';
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     //## Return Result
     if ($ret['isPosted'] == '1') {
         return 200;
     } else {
         return print_r($ret, true);
     }
 }
 function nxs_doFormatMsg($format, $message, $addURLParams = '')
 {
     global $nxs_urlLen;
     $msg = nxs_doSpin($format);
     // prr($msg); prr($message);// Make "message default"
     $msgDef = array('title' => '', 'announce' => '', 'text' => '', 'url' => '', 'surl' => '', 'urlDescr' => '', 'urlTitle' => '', 'imageURL' => array(), 'videoCode' => '', 'videoURL' => '', 'siteName' => '', 'tags' => '', 'cats' => '', 'authorName' => '', 'orID' => '');
     $message = array_merge($msgDef, $message);
     if (preg_match('/%URL%/', $msg)) {
         $url = $message['url'];
         if ($addURLParams != '') {
             $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams;
         }
         $nxs_urlLen = nxs_strLen($url);
         $msg = str_ireplace("%URL%", $url, $msg);
     }
     if (preg_match('/%SURL%/', $msg)) {
         if (isset($message['surl']) && $message['surl'] != '') {
             $url = $message['surl'];
         } else {
             $url = $message['url'];
             if ($addURLParams != '') {
                 $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams;
             }
             $url = nxs_mkShortURL($url);
         }
         $nxs_urlLen = nxs_strLen($url);
         $msg = str_ireplace("%SURL%", $url, $msg);
     }
     if (preg_match('/%IMG%/', $msg)) {
         if (isset($message['imgURL']) && is_array($message['imgURL'])) {
             $imgURL = trim($message['imgURL']['large']);
             if ($imgURL == '') {
                 $imgURL = trim($message['imgURL']['medium']);
             }
             if ($imgURL == '') {
                 $imgURL = trim($message['imgURL']['original']);
             }
             if ($imgURL == '') {
                 $imgURL = trim($message['imgURL']['thumb']);
             }
         } elseif (!empty($message['imgURL'])) {
             $imgURL = $message['imgURL'];
         } else {
             $imgURL = '';
         }
         $msg = str_ireplace("%IMG%", $imgURL, $msg);
     }
     if (preg_match('/%IMGLARGE%/', $msg)) {
         $msg = str_ireplace("%IMG%", trim($message['imgURL']['large'], $msg));
     }
     if (preg_match('/%IMGMEDIUM%/', $msg)) {
         $msg = str_ireplace("%IMGMEDIUM%", trim($message['imgURL']['medium'], $msg));
     }
     if (preg_match('/%IMGTHUMB%/', $msg)) {
         $msg = str_ireplace("%IMGTHUMB%", trim($message['imgURL']['thumb'], $msg));
     }
     if (preg_match('/%IMGORIGINAL%/', $msg)) {
         $msg = str_ireplace("%IMGORIGINAL%", trim($message['imgURL']['original'], $msg));
     }
     if (preg_match('/%ORID%/', $msg)) {
         $msg = str_ireplace("%ORID%", $message['orID'], $msg);
     }
     if (preg_match('/%TITLE%/', $msg)) {
         $msg = str_ireplace("%TITLE%", $message['title'], $msg);
     }
     if (preg_match('/%STITLE%/', $msg)) {
         $title = substr($message['title'], 0, 115);
         $msg = str_ireplace("%STITLE%", $title, $msg);
     }
     if (preg_match('/%AUTHORNAME%/', $msg)) {
         $msg = str_ireplace("%AUTHORNAME%", $message['authorName'], $msg);
     }
     if (preg_match('/%SITENAME%/', $msg)) {
         $msg = str_ireplace("%SITENAME%", $message['siteName'], $msg);
     }
     if (preg_match('/%ANNOUNCE%/', $msg)) {
         $sText = trim($message['announce']) != '' ? $message['announce'] : nsTrnc($message['description'], 300, " ", "...");
         $msg = str_ireplace("%ANNOUNCE%", $sText, $msg);
     }
     if (preg_match('/%EXCERPT%/', $msg)) {
         $sText = trim($message['announce']) != '' ? $message['announce'] : nsTrnc($message['description'], 300, " ", "...");
         $msg = str_ireplace("%EXCERPT%", $sText, $msg);
     }
     if (preg_match('/%RAWEXCERPT%/', $msg)) {
         $sText = trim($message['announce']) != '' ? $message['announce'] : nsTrnc($message['description'], 300, " ", "...");
         $msg = str_ireplace("%RAWEXCERPT%", $sText, $msg);
     }
     if (preg_match('/%TEXT%/', $msg)) {
         $msg = str_ireplace("%TEXT%", $message['description'], $msg);
     }
     if (preg_match('/%FULLTEXT%/', $msg)) {
         $msg = str_ireplace("%FULLTEXT%", $message['description'], $msg);
     }
     if (preg_match('/%RAWTEXT%/', $msg)) {
         $msg = str_ireplace("%RAWTEXT%", $message['description'], $msg);
     }
     if (preg_match('/%TAGS%/', $msg)) {
         $tags = nxs_doProcessTags($message['tags']);
         $msg = str_ireplace("%TAGS%", $tags['tags'], $msg);
     }
     if (preg_match('/%HTAGS%/', $msg)) {
         $tags = nxs_doProcessTags($message['tags']);
         $msg = str_ireplace("%HTAGS%", $tags['htags'], $msg);
     }
     if (preg_match('/%CATS%/', $msg)) {
         $tags = nxs_doProcessTags($message['cats']);
         $msg = str_ireplace("%CATS%", $tags['cats'], $msg);
     }
     if (preg_match('/%HCATS%/', $msg)) {
         $tags = nxs_doProcessTags($message['hcats']);
         $msg = str_ireplace("%HCATS%", $tags['hcats'], $msg);
     }
     if (preg_match('/%+CF-[a-zA-Z0-9-_]+%/', $msg)) {
         $msgA = explode('%CF', $msg);
         $mout = '';
         foreach ($msgA as $mms) {
             if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) {
                 $mGr = CutFromTo($mms, '-', '%');
                 $cfItem = $message[$mGr];
                 $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms);
             }
             $mout .= $mms;
         }
         $msg = $mout;
     }
     return trim($msg);
 }
Beispiel #25
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;
 }
 function doPostToNT($options, $message)
 {
     $badOut = array('postID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     $liPostID = '';
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if ((!isset($options['ulName']) || trim($options['uPass']) == '') && empty($options['liOAuthVerifier'])) {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     if (empty($options['liMsgFormatT'])) {
         $options['liMsgFormatT'] = '%TITLE%';
     }
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['liMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['liMsgFormatT'], $message);
     }
     if (empty($options['postType'])) {
         if ((int) $options['liAttch'] == 1 || $isNew) {
             $options['postType'] = 'A';
         }
     }
     if ($options['postType'] == 'A' || $options['postType'] == 'I') {
         if (isset($message['imageURL'])) {
             $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize']));
         } else {
             $imgURL = '';
         }
         if (preg_match("/noImg.\\.png/i", $imgURL)) {
             $imgURL = '';
         }
         if (!empty($message['urlDescr'])) {
             $dsc = $message['urlDescr'];
         } else {
             $dsc = $msg;
         }
         $dsc = strip_tags($dsc);
         $dsc = nxs_decodeEntitiesFull($dsc);
         $dsc = nxs_html_to_utf8($dsc);
         $dsc = nsTrnc($dsc, 300);
     }
     $msg = strip_tags($msg);
     $msg = nxs_html_to_utf8($msg);
     $msgT = nxs_html_to_utf8($msgT);
     $urlToGo = $message['url'];
     if (function_exists("doConnectToLinkedIn") && $options['ulName'] != '' && $options['uPass'] != '') {
         $dusername = $options['ulName'];
         $pass = substr($options['uPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['uPass'], 5)) : $options['uPass'];
         // ??? Do we need that??????
         $auth = doConnectToLinkedIn($options['ulName'], $options['uPass'], $options['ii']);
         if ($auth != false) {
             $badOut['Error'] .= "|Auth Error - " . $auth;
             return $badOut;
         }
         $to = $options['uPage'] != '' ? $options['uPage'] : 'https://www.linkedin.com/home';
         $lnk = array();
         $msg = str_ireplace('&nbsp;', ' ', $msg);
         $msg = nsTrnc(strip_tags($msg), 700);
         $lnk['postTitle'] = $msgT;
         if ($options['postType'] == 'A') {
             $lnk['title'] = $message['urlTitle'];
             $lnk['desc'] = $message['urlDescr'];
             $lnk['url'] = $urlToGo;
             $lnk['img'] = $imgURL;
             $lnk['postType'] = 'A';
         }
         if ($options['postType'] == 'I') {
             $lnk['title'] = '';
             $lnk['desc'] = '';
             $lnk['url'] = $imgURL;
             $lnk['img'] = $imgURL;
             $lnk['postType'] = 'I';
             $lnk['postTitle'] = $msgT;
         }
         if ($options['postType'] == 'T') {
             $lnk['postType'] = 'T';
         }
         global $nxs_gCookiesArr;
         $li = new nxsAPI_LI();
         $li->debug = false;
         if (!empty($nxs_gCookiesArr)) {
             $li->ck = $nxs_gCookiesArr;
         }
         $ret = $li->post($msg, $lnk, $to);
         if (is_array($ret) && !empty($ret['isPosted'])) {
             return $ret;
         }
         $liPostID = $options['uPage'];
     } else {
         if (!empty($options['isV2'])) {
             //## V2
             if ($options['grpID'] != '') {
                 try {
                     if ($msgT == '') {
                         $msgT = ' ';
                     }
                     if ($options['postType'] == 'A') {
                         $ret = $this->postToGroup($options['liAccessToken'], $msg, $msgT, $options['grpID'], str_replace('&', '&amp;', $urlToGo), $imgURL, $dsc);
                     } else {
                         $ret = $this->postToGroup($options['liAccessToken'], $msg, $msgT, $options['grpID']);
                     }
                     $liPostID = 'http://www.linkedin.com/groups?gid=' . $options['grpID'];
                 } catch (Exception $o) {
                     $ret = "ERROR: " . print_r($o, true);
                 }
             } else {
                 //echo $msg ."|". nsTrnc($msgT, 200) ."|". $urlToGo ."|". $imgURL ."|". $dsc;
                 if ($options['postType'] == 'A') {
                     $ret = $this->postShare($options['liAccessToken'], $msg, nsTrnc($msgT, 200), str_replace('&', '&amp;', $urlToGo), $imgURL, $dsc);
                 } else {
                     $ret = $this->postShare($options['liAccessToken'], $msg);
                 }
             }
         } else {
             //## V1
             require_once 'apis/liOAuth.php';
             $linkedin = new nsx_LinkedIn($options['liAPIKey'], $options['liAPISec']);
             $linkedin->oauth_verifier = $options['liOAuthVerifier'];
             $linkedin->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
             $linkedin->access_token = new nsx_trOAuthConsumer($options['liAccessToken'], $options['liAccessTokenSecret'], 1);
             $msg = nsTrnc($msg, 700);
             //prr($urlToGo);  $urlToGo = urlencode($urlToGo);   prr($urlToGo); die();
             if ($options['grpID'] != '') {
                 try {
                     if ($msgT == '') {
                         $msgT = ' ';
                     }
                     if ($options['postType'] == 'A') {
                         $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID'], str_replace('&', '&amp;', $urlToGo), $imgURL, $dsc);
                     } else {
                         $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID']);
                     }
                     $liPostID = 'http://www.linkedin.com/groups?gid=' . $options['grpID'];
                     if ($ret == '201') {
                         $ret = array('updateUrl' => $liPostID);
                     }
                 } catch (Exception $o) {
                     $ret = "ERROR: " . print_r($o, true);
                 }
             } else {
                 //echo $msg ."|". nsTrnc($msgT, 200) ."|". $urlToGo ."|". $imgURL ."|". $dsc;
                 try {
                     if ($options['postType'] == 'A') {
                         $ret = $linkedin->postShare($msg, nsTrnc($msgT, 200), str_replace('&', '&amp;', $urlToGo), $imgURL, $dsc);
                     } else {
                         $ret = $linkedin->postShare($msg);
                     }
                 } catch (Exception $o) {
                     $ret = "ERROR:" . print_r($o, true);
                 }
             }
         }
         if ($liPostID == '') {
             $liPostID = $options['liUserInfo'];
         }
     }
     // prr($ret);
     if (!is_array($ret) && stripos($ret, '<update-url>') !== false) {
         $rurl = CutFromTo($ret, '<update-url>', '</update-url>');
         $ret = array('updateUrl' => $rurl);
     }
     if (is_array($ret) && !empty($ret['updateUrl'])) {
         if (stripos($ret['updateUrl'], 'topic=') !== false) {
             $liPostID = CutFromTo($ret['updateUrl'], 'topic=', '&');
         } else {
             $liPostID = '';
         }
         return array('isPosted' => '1', 'postID' => $liPostID, 'postURL' => $ret['updateUrl'], 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= print_r($ret, true);
     }
     return $badOut;
 }
 function nsFormatMessage($msg, $postID, $addURLParams = '', $lng = '')
 {
     global $ShownAds, $plgn_NS_SNAutoPoster, $nxs_urlLen;
     $post = get_post($postID);
     $options = $plgn_NS_SNAutoPoster->nxs_options;
     if (!empty($options['brokenCntFilters'])) {
         $msg = str_replace('%FULLTITLE%', '%TITLE%', $msg);
         $msg = str_replace('%PANNOUNCE%', '%ANNOUNCE%', $msg);
         $msg = str_replace('%PANNOUNCER%', '%ANNOUNCER%', $msg);
         $msg = str_replace('%EXCERPT%', '%RAWEXCERPT%', $msg);
         $msg = str_replace('%FULLTEXT%', '%RAWTEXT%', $msg);
     }
     if (!empty($options['nxsHTSpace'])) {
         $htS = $options['nxsHTSpace'];
     } else {
         $htS = '';
     }
     if (!empty($options['nxsHTSepar'])) {
         $htSep = $options['nxsHTSepar'];
     } else {
         $htSep = ', ';
     }
     $htSep = str_replace('_', ' ', $htSep);
     $htSep = str_replace('c', ',', $htSep);
     // if ($addURLParams=='' && $options['addURLParams']!='') $addURLParams = $options['addURLParams'];
     $msg = str_replace('%TEXT%', '%EXCERPT%', $msg);
     $msg = str_replace('%RAWEXTEXT%', '%RAWEXCERPT%', $msg);
     $msg = stripcslashes($msg);
     if (isset($ShownAds)) {
         $ShownAdsL = $ShownAds;
     }
     // $msg = htmlspecialchars(stripcslashes($msg));
     $msg = nxs_doSpin($msg);
     if (preg_match('/%URL%/', $msg)) {
         $url = get_permalink($postID);
         if ($addURLParams != '') {
             $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams;
         }
         $nxs_urlLen = nxs_strLen($url);
         $msg = str_ireplace("%URL%", $url, $msg);
     }
     if (preg_match('/%MYURL%/', $msg)) {
         $url = get_post_meta($postID, 'snap_MYURL', true);
         if ($addURLParams != '') {
             $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams;
         }
         $nxs_urlLen = nxs_strLen($url);
         $msg = str_ireplace("%MYURL%", $url, $msg);
     }
     // prr($msg);
     if (preg_match('/%SURL%/', $msg)) {
         $url = get_permalink($postID);
         if ($addURLParams != '') {
             $url .= (strpos($url, '?') !== false ? '&' : '?') . $addURLParams;
         }
         $url = nxs_mkShortURL($url, $postID);
         $nxs_urlLen = nxs_strLen($url);
         $msg = str_ireplace("%SURL%", $url, $msg);
     }
     if (preg_match('/%ORID%/', $msg)) {
         $msg = str_ireplace("%ORID%", $postID, $msg);
     }
     if (preg_match('/%IMG%/', $msg)) {
         $imgURL = nxs_getPostImage($postID);
         $msg = str_ireplace("%IMG%", $imgURL, $msg);
     }
     if (preg_match('/%TITLE%/', $msg)) {
         $title = nxs_doQTrans($post->post_title, $lng);
         $msg = str_ireplace("%TITLE%", $title, $msg);
     }
     if (preg_match('/%FULLTITLE%/', $msg)) {
         $title = apply_filters('the_title', nxs_doQTrans($post->post_title, $lng));
         $msg = str_ireplace("%FULLTITLE%", $title, $msg);
     }
     if (preg_match('/%STITLE%/', $msg)) {
         $title = nxs_doQTrans($post->post_title, $lng);
         $title = substr($title, 0, 115);
         $msg = str_ireplace("%STITLE%", $title, $msg);
     }
     if (preg_match('/%AUTHORNAME%/', $msg)) {
         $aun = $post->post_author;
         $aun = get_the_author_meta('display_name', $aun);
         $msg = str_ireplace("%AUTHORNAME%", $aun, $msg);
     }
     if (preg_match('/%AUTHORTWNAME%/', $msg)) {
         $aun = $post->post_author;
         $aun = get_the_author_meta('twitter', $aun);
         $msg = str_ireplace("%AUTHORTWNAME%", $aun, $msg);
     }
     if (preg_match('/%ANNOUNCE%/', $msg)) {
         $postContent = nxs_doQTrans($post->post_content, $lng);
         $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("&lt;!--more--&gt;", '<!--more-->', $postContent))));
         if (stripos($postContent, '#####!--more--!#####') !== false) {
             $postContentEx = explode('#####!--more--!#####', $postContent);
             $postContent = $postContentEx[0];
         } else {
             $postContent = nsTrnc($postContent, $options['anounTagLimit'], ' ', '');
         }
         $msg = str_ireplace("%ANNOUNCE%", $postContent, $msg);
     }
     if (preg_match('/%PANNOUNCE%/', $msg)) {
         $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
         $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("&lt;!--more--&gt;", '<!--more-->', $postContent))));
         if (stripos($postContent, '#####!--more--!#####') !== false) {
             $postContentEx = explode('#####!--more--!#####', $postContent);
             $postContent = $postContentEx[0];
         } else {
             $postContent = nsTrnc($postContent, $options['anounTagLimit'], ' ', '');
         }
         $msg = str_ireplace("%PANNOUNCE%", $postContent, $msg);
     }
     if (preg_match('/%ANNOUNCER%/', $msg)) {
         $postContent = nxs_doQTrans($post->post_content, $lng);
         $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("&lt;!--more--&gt;", '<!--more-->', $postContent))));
         if (stripos($postContent, '#####!--more--!#####') !== false) {
             $postContentEx = explode('#####!--more--!#####', $postContent);
             $postContent = $postContentEx[1];
         } else {
             $postContent = str_replace(nsTrnc($postContent, $options['anounTagLimit'], ' ', ''), '', $postContent);
         }
         $msg = str_ireplace("%ANNOUNCER%", $postContent, $msg);
     }
     if (preg_match('/%PANNOUNCER%/', $msg)) {
         $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
         $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("&lt;!--more--&gt;", '<!--more-->', $postContent))));
         if (stripos($postContent, '#####!--more--!#####') !== false) {
             $postContentEx = explode('#####!--more--!#####', $postContent);
             $postContent = $postContentEx[1];
         } else {
             $postContent = str_replace(nsTrnc($postContent, $options['anounTagLimit'], ' ', ''), '', $postContent);
         }
         $msg = str_ireplace("%PANNOUNCER%", $postContent, $msg);
     }
     if (preg_match('/%EXCERPT%/', $msg)) {
         if ($post->post_excerpt != "") {
             $excerpt = strip_tags(strip_shortcodes(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng))));
         } else {
             $excerpt = nsTrnc(strip_tags(strip_shortcodes(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)))), 300, " ", "...");
         }
         $msg = str_ireplace("%EXCERPT%", $excerpt, $msg);
     }
     if (preg_match('/%RAWEXCERPT%/', $msg)) {
         if ($post->post_excerpt != "") {
             $excerpt = strip_tags(strip_shortcodes(nxs_doQTrans($post->post_excerpt, $lng)));
         } else {
             $excerpt = nsTrnc(strip_tags(strip_shortcodes(nxs_doQTrans($post->post_content, $lng))), 300, " ", "...");
         }
         $msg = str_ireplace("%RAWEXCERPT%", $excerpt, $msg);
     }
     if (preg_match('/%RAWEXCERPTHTML%/', $msg)) {
         if ($post->post_excerpt != "") {
             $excerpt = strip_shortcodes(nxs_doQTrans($post->post_excerpt, $lng));
         } else {
             $excerpt = nsTrnc(strip_tags(strip_shortcodes(nxs_doQTrans($post->post_content, $lng))), 300, " ", "...");
         }
         $msg = str_ireplace("%RAWEXCERPTHTML%", $excerpt, $msg);
     }
     if (preg_match('/%TAGS%/', $msg)) {
         $t = wp_get_object_terms($postID, 'product_tag');
         if (empty($t) || is_wp_error($pt) || !is_array($t)) {
             $t = wp_get_post_tags($postID);
         }
         $tggs = array();
         foreach ($t as $tagA) {
             $tggs[] = $tagA->name;
         }
         $tags = implode(', ', $tggs);
         $msg = str_ireplace("%TAGS%", $tags, $msg);
     }
     if (preg_match('/%CATS%/', $msg)) {
         $t = wp_get_post_categories($postID);
         $cats = array();
         foreach ($t as $c) {
             $cat = get_category($c);
             $cats[] = str_ireplace('&', '&amp;', $cat->name);
         }
         $ctts = implode(', ', $cats);
         $msg = str_ireplace("%CATS%", $ctts, $msg);
     }
     if (preg_match('/%HCATS%/', $msg)) {
         $t = wp_get_post_categories($postID);
         $cats = array();
         foreach ($t as $c) {
             $cat = get_category($c);
             $cats[] = "#" . trim(str_replace(' ', $htS, str_replace('  ', ' ', trim(str_ireplace('&', '', str_ireplace('&amp;', '', $cat->name))))));
         }
         $ctts = implode($htSep, $cats);
         $msg = str_ireplace("%HCATS%", $ctts, $msg);
     }
     if (preg_match('/%HTAGS%/', $msg)) {
         $t = wp_get_object_terms($postID, 'product_tag');
         if (empty($t) || is_wp_error($pt) || !is_array($t)) {
             $t = wp_get_post_tags($postID);
         }
         $tggs = array();
         foreach ($t as $tagA) {
             $tggs[] = "#" . trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(nxs_ucwords(str_ireplace('&', '', str_ireplace('&amp;', '', $tagA->name)))))));
         }
         $tags = implode($htSep, $tggs);
         $msg = str_ireplace("%HTAGS%", $tags, $msg);
     }
     if (preg_match('/%+CF-[a-zA-Z0-9-_]+%/', $msg)) {
         $msgA = explode('%CF', $msg);
         $mout = '';
         foreach ($msgA as $mms) {
             if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) {
                 $mGr = CutFromTo($mms, '-', '%');
                 $cfItem = get_post_meta($postID, $mGr, true);
                 $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms);
             }
             $mout .= $mms;
         }
         $msg = $mout;
     }
     $mm = array();
     if (preg_match_all('/%H?CT-[a-zA-Z0-9_]+%/', $msg, $mm)) {
         $msgA = explode('%CT', str_ireplace("%HCT", "%CT", $msg));
         $mout = '';
         $i = 0;
         foreach ($msgA as $mms) {
             if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) {
                 $h = strpos($mm[0][$i], '%HCT-') !== false;
                 $i++;
                 $mGr = CutFromTo($mms, '-', '%');
                 $cfItem = wp_get_post_terms($postID, $mGr, array("fields" => "names"));
                 if (is_nxs_error($cfItem)) {
                     nxs_addToLogN('E', 'Error', 'MSG', '-=ERROR=- ' . $mGr . '|' . print_r($cfItem, true), '');
                     $mms = str_ireplace("-" . $mGr . "%", '', $mms);
                 } else {
                     $tggs = array();
                     foreach ($cfItem as $frmTag) {
                         if ($h) {
                             $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(nxs_ucwords(str_ireplace('&', '', str_ireplace('&amp;', '', $frmTag)))))));
                         }
                         $tggs[] = ($h ? '#' : '') . $frmTag;
                     }
                     $cfItem = implode(' ', $tggs);
                     $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms);
                 }
             }
             $mout .= $mms;
         }
         $msg = $mout;
     }
     if (preg_match('/%FULLTEXT%/', $msg)) {
         $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
         $msg = str_ireplace("%FULLTEXT%", $postContent, $msg);
     }
     if (preg_match('/%RAWTEXT%/', $msg)) {
         $postContent = nxs_doQTrans($post->post_content, $lng);
         $msg = str_ireplace("%RAWTEXT%", $postContent, $msg);
     }
     if (preg_match('/%SITENAME%/', $msg)) {
         $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
         $msg = str_ireplace("%SITENAME%", $siteTitle, $msg);
     }
     if (isset($ShownAds)) {
         $ShownAds = $ShownAdsL;
     }
     // FIX for the quick-adsense plugin
     return trim($msg);
 }
Beispiel #28
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;
 }