Exemple #1
0
 function check()
 {
     $ck = $this->ck;
     if (!empty($ck) && is_array($ck)) {
         $hdrsArr = $this->headers('https://www.deviantart.com');
         if ($this->debug) {
             echo "[DA] Checking....;<br/>\r\n";
         }
         $rep = nxs_remote_get('https://www.deviantart.com', array('headers' => $hdrsArr, 'httpversion' => '1.1', 'cookies' => $ck));
         if (is_wp_error($rep)) {
             $badOut = print_r($rep, true) . " - ERROR https://www.deviantart.com is not accessible. ";
             return $badOut;
         }
         $ck2 = $rep['cookies'];
         for ($i = 0; $i < count($ck); $i++) {
             if ($ck[$i]->name == 'userinfo') {
                 $ck[$i]->value = urlencode($ck2[0]->value);
             }
         }
         $this->ck = $ck;
         if (is_nxs_error($rep)) {
             return false;
         }
         $contents = $rep['body'];
         //if ($this->debug) prr($contents);
         $mh = CutFromTo($rep['body'], '$(\'#logoutme\').submit();">', 'data-ga_click_event');
         $mh = CutFromTo($mh, 'href="', '"');
         $this->mh = $mh;
         return stripos($contents, 'https://www.deviantart.com/users/logout') !== false;
     } else {
         return false;
     }
 }
function nxs_CptCheckGP($o)
{
    session_id("nxs-temp-gpcpt");
    session_start();
    $sess = unserialize($_SESSION['nxs-temp-gpcpt']);
    if (!empty($_POST['c'])) {
        $ck = $sess['c'];
        $flds = $sess['f'];
        $flds['recaptcha_response_field'] = $_POST['c'];
        $liObj = new nxsAPI_GP();
        $hdrsArr = $liObj->headers('https://www.youtube.com/', 'https://www.youtube.com', 'POST', false);
        $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $flds);
        prr($advSet);
        $rep = nxs_remote_post('https://www.youtube.com/das_captcha', $advSet);
        if (is_nxs_error($rep)) {
            $badOut = print_r($rep, true) . " - ERROR";
            return $badOut;
        }
        $contents2 = $rep['body'];
        prr($rep);
        if (stripos($contents2, 'id="error-box"') !== false) {
            echo 'The verification code was invalid or has timed out. Please try again.';
            die;
        }
        if (stripos($contents2, 'The verification code was invalid') !== false) {
            echo 'The verification code was invalid or has timed out. Please try again.';
            die;
        }
        if ($rep['response']['code'] == '303' && !empty($rep['headers']['location'])) {
            echo "OK. You are In";
            $hdrsArr = $liObj->headers('http://www.youtube.com', 'https://www.youtube.com');
            $ck = $rep['cookies'];
            $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck);
            // prr($advSet);
            $rep = nxs_remote_get($rep['headers']['location'], $advSet);
            prr($ck);
            if (is_nxs_error($rep)) {
                $badOut = print_r($rep, true) . " - ERROR";
                return $badOut;
            }
            $ck = $rep['cookies'];
        }
    }
}
 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);
 }
 function nxsCptCheck_ajax()
 {
     global $nxs_gCookiesArr;
     $advSettings = array();
     if (!empty($_POST['c'])) {
         $seForDB = get_option('nxs_li_ctp_save');
         $ser = maybe_unserialize($seForDB);
         $nxs_gCookiesArr = $ser['c'];
         $ck = $nxs_gCookiesArr;
         $flds = $ser['f'];
         $flds['recaptcha_response_field'] = $_POST['c'];
         $liObj = new nxsAPI_LI();
         $hdrsArr = $liObj->headers('https://www.linkedin.com/uas/login-submit', 'https://www.linkedin.com', 'POST', false);
         $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $flds);
         // prr($advSet);
         $rep = nxs_remote_post('https://www.linkedin.com/uas/captcha-submit', $advSet);
         if (is_nxs_error($rep)) {
             $badOut = print_r($rep, true) . " - ERROR";
             return $badOut;
         }
         $contents2 = $rep['body'];
         if (stripos($contents2, '<span class="error">') !== false) {
             echo strip_tags(CutFromTo($contents2, '<span class="error">', '</span>'));
             die;
         }
         if (stripos($contents2, '<div id="global-error">') !== false) {
             echo CutFromTo($contents2, '<div role="alert" class="alert error">', '</div>');
             die;
         }
         if (stripos($contents2, 'The email address or password you provided does not match our records') !== false) {
             echo "Invalid Login/Password";
             die;
         }
         if (stripos($contents2, 'Hmm, ') !== false) {
             echo "Invalid Login/Password";
             die;
         }
         if ($rep['response']['code'] == '302' && !empty($rep['headers']['location']) && stripos($rep['headers']['location'], 'linkedin.com/uas/captcha-submit') !== false) {
             echo "Wrong Captcha. Please try Again";
         }
         if ($rep['response']['code'] == '302' && !empty($rep['headers']['location']) && (stripos($rep['headers']['location'], 'linkedin.com/nhome') !== false || stripos($rep['headers']['location'], 'linkedin.com/home') !== false)) {
             echo "OK. You are In";
             $hdrsArr = $liObj->headers('http://www.linkedin.com/home', 'https://www.linkedin.com');
             $ck = $rep['cookies'];
             $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck);
             // prr($advSet);
             $rep = nxs_remote_get('http://www.linkedin.com/profile/edit?trk=tab_pro', $advSet);
             if (is_nxs_error($rep)) {
                 $badOut = print_r($rep, true) . " - ERROR";
                 return $badOut;
             }
             $ck = $rep['cookies'];
             if ($_POST['i'] != '') {
                 global $plgn_NS_SNAutoPoster;
                 if (!isset($plgn_NS_SNAutoPoster)) {
                     return;
                 }
                 $options = $plgn_NS_SNAutoPoster->nxs_options;
                 $options['li'][$_POST['i']]['ck'] = $ck;
                 if (is_array($options)) {
                     update_option('NS_SNAutoPoster', $options);
                 }
             }
         }
     }
     if (!empty($_POST['s'])) {
         $seForDB = get_option('nxs_li_ctp_save');
         $ser = maybe_unserialize($seForDB);
         $ck = $ser['c'];
         $flds = $ser['f'];
         $flds['PinVerificationForm_pinParam'] = $_POST['s'];
         $liObj = new nxsAPI_LI();
         $hdrsArr = $liObj->headers('https://www.linkedin.com/uas/login-submit', 'https://www.linkedin.com', 'POST', true);
         $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $flds);
         // prr($advSet);
         $rep = nxs_remote_post('https://www.linkedin.com/uas/ato-pin-challenge-submit', $advSet);
         if (is_nxs_error($rep)) {
             $badOut = print_r($rep, true) . " - ERROR";
             return $badOut;
         }
         $contents2 = $rep['body'];
         // prr($rep);
         if (stripos($contents2, 'The email address or password you provided does not match our records') !== false) {
             echo "Invalid Login/Password";
             die;
         }
         if (stripos($contents2, '<div id="global-error">') !== false) {
             echo CutFromTo($contents2, '<div role="alert" class="alert error">', '</div>');
             die;
         }
         if (stripos($contents2, 'Hmm, ') !== false) {
             echo "Invalid Login/Password";
             die;
         }
         if ($rep['response']['code'] == '302' && !empty($rep['headers']['location']) && stripos($rep['headers']['location'], 'linkedin.com/uas/ato-pin-challenge-submit') !== false) {
             echo "Wrong Code. Please try Again";
         }
         if ($rep['response']['code'] == '302' && !empty($rep['headers']['location']) && (stripos($rep['headers']['location'], 'linkedin.com/nhome') !== false || stripos($rep['headers']['location'], 'linkedin.com/home') !== false)) {
             echo "OK. You are In";
         }
         $hdrsArr = $liObj->headers('http://www.linkedin.com/home', 'https://www.linkedin.com');
         $ck = $rep['cookies'];
         $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck);
         // prr($advSet);
         $rep = nxs_remote_get('http://www.linkedin.com/profile/edit?trk=tab_pro', $advSet);
         if (is_nxs_error($rep)) {
             $badOut = print_r($rep, true) . " - ERROR";
             return $badOut;
         }
         $ck = $rep['cookies'];
         if ($_POST['i'] != '') {
             global $plgn_NS_SNAutoPoster;
             if (!isset($plgn_NS_SNAutoPoster)) {
                 return;
             }
             $options = $plgn_NS_SNAutoPoster->nxs_options;
             $options['li'][$_POST['i']]['ck'] = $ck;
             if (is_array($options)) {
                 update_option('NS_SNAutoPoster', $options);
             }
         }
     }
     die;
 }
Exemple #5
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;
 }
Exemple #6
0
 function post($post)
 {
     $ck = $this->ck;
     $sslverify = false;
     $oneTime = '0R4qFyHCMAYYclyZQFNYrOkq4uy4mN5';
     $enText = nxs_AesCtr::encrypt($post['text'], $oneTime, 256);
     $blogID = '';
     $hdrsArr = $this->headers('http://sett.com/');
     $rep = nxs_remote_get('http://sett.com/' . $post['toURL'], array('headers' => $hdrsArr, 'timeout' => 45, 'cookies' => $ck, 'httpversion' => '1.1', 'sslverify' => $sslverify));
     if (is_nxs_error($rep)) {
         $badOut = "ERROR (Blog URL): " . print_r($rep, true);
         return $badOut;
     }
     $content = $rep['body'];
     if (stripos($content, 'window.site_id =') !== false) {
         $blogID = trim(CutFromTo($content, 'window.site_id =', ';'));
     }
     if (empty($blogID)) {
         return "ERROR (NO Blog ID found): ";
     }
     //if ($_GET('page')=='NextScripts_SNAP.php') prr($admURL);
     $hdrsArr = $this->headers('http://sett.com', 'http://sett.com', 'POST');
     $flds = array('text' => $enText);
     $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'sslverify' => $sslverify, 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $flds);
     //prr($advSet);
     $rep = nxs_remote_post('http://sett.com/storetext.php', $advSet);
     if (is_nxs_error($rep)) {
         $badOut = "ERROR (Post Post):" . print_r($rep, true);
         return $badOut;
     }
     if (stripos($rep['body'], '{"id":') !== false) {
         $textPush = json_decode($rep['body'], true);
     } else {
         $badOut = "ERROR (Post Post):" . print_r($rep, true);
         return $badOut;
     }
     $pURL = 'https://sett.com/newpost.php?autosave=0&context=&is_html=&offset=&one_time=&parent_uid=&promote=&site=&submit_visible=1&to=&uid=&title=' . urlencode($post['title']) . '&url=' . $this->makeSlug($post['title']) . '&category=&allow_comments=1&allow_promoting=1&allow_indexing=1&subscribe=1&context=false&is_html=false&offset=-4&parent_uid=&promote=1&site_id=' . $blogID . '&type=post&uid=&one_time=' . $oneTime . '&text_id=' . $textPush['id'] . '&text_hash=' . $textPush['hash'];
     $ck = nxsClnCookies($ck);
     $hdrsArr = $this->headers('http://sett.com/' . $post['toURL']);
     $rep = nxs_remote_get($pURL, array('headers' => $hdrsArr, 'timeout' => 45, 'cookies' => $ck, 'httpversion' => '1.1', 'sslverify' => $sslverify));
     if (is_nxs_error($rep)) {
         $badOut = "ERROR (Post Info): " . print_r($rep, true);
         return $badOut;
     }
     if ($rep['response']['code'] == '200') {
         $content = $rep['body'];
         if (stripos($content, '{"errors":[') !== false) {
             $loginArr = json_decode($content, true);
             $err = $loginArr['errors'][0]['title'];
             return "Error: " . $err . " | \r\n<br/>\r\n" . print_r($loginArr, true);
         }
     }
     if (stripos($rep['body'], '{"uid":') !== false) {
         $content = json_decode($rep['body'], true);
         return array('isPosted' => '1', 'postID' => $content['uid'], 'postURL' => 'http://sett.com/' . $post['toURL'] . "/" . $content['uid'], 'pDate' => date('Y-m-d H:i:s'));
     }
     return 'Error: ' . print_r($rep, true);
 }
 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);
     }
 }
Exemple #8
0
 function getReqToken($cbu)
 {
     $args = array('oauth_consumer_key' => $this->consumer_key, 'oauth_timestamp' => time(), 'oauth_nonce' => $this->genRndString(), 'oauth_version' => $this->version, 'oauth_callback' => $cbu, 'oauth_signature_method' => 'HMAC-SHA1');
     $req = array();
     $req['method'] = 'GET';
     $req['normalized_url'] = $this->baseURL . PLURK_REQUEST_TOKEN_PATH;
     $req['normalized_parameters'] = $this->get_normalized_parameters($args);
     $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $token);
     $cbu = nxspk_SigMethod_HMAC_SHA1::urlencode_rfc3986($cbu);
     $url = $this->baseURL . PLURK_REQUEST_TOKEN_PATH . '?oauth_nonce=' . $args['oauth_nonce'] . '&oauth_timestamp=' . $args['oauth_timestamp'] . '&oauth_consumer_key=' . $this->consumer_key . '&oauth_signature_method=' . $args['oauth_signature_method'] . '&oauth_version=' . $args['oauth_version'] . '&oauth_callback=' . $cbu . '&oauth_signature=' . $args['oauth_signature'];
     echo "<br/>REQ Token URL: " . $url . "<br/>";
     $hdrsArr = $this->makeHTTPHeaders($url);
     $ckArr = $nxs_vbCkArray;
     $response = wp_remote_get($url, array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
     if (is_nxs_error($response)) {
         $badOut = print_r($response, true) . " - Connection ERROR";
         return $badOut;
     }
     $this->http_code = $response['response']['code'];
     //  prr($response);
     if (stripos($response['body'], 'oauth_token_secret=') === false) {
         echo 'Bad oAuth Login:'******'body'];
     } else {
         return $this->oAuthRespToArr($response['body']);
     }
 }
 function post($msg, $imgURL, $lnk, $boardID, $title = '', $price='', $via=''){ 
   $tk = $this->tk; $ck = $this->ck; $apVer = $this->apVer; if ($this->debug) echo "[PN] Posting to ...".$boardID."<br/>\r\n";      
   foreach ($ck as $c) if ( is_object($c) && $c->name=='csrftoken') $tk = $c->value; $msg = strip_tags($msg); $msg = substr($msg, 0, 480); $tgs = ''; $this->tk = $tk;
   if ($msg=='') $msg = '&nbsp;';  if (trim($boardID)=='') return "Board is not Set";  if (trim($imgURL)=='') return "Image is not Set";   $msg = str_ireplace(array("\r\n", "\n", "\r"), " ", $msg); 
   $msg = strip_tags($msg); if (function_exists('nxs_decodeEntitiesFull')) $msg = nxs_decodeEntitiesFull($msg, ENT_QUOTES); 
   $mgsOut = urlencode($msg); $mgsOut = str_ireplace(array('%28', '%29', '%27', '%21', '%22', '%09'), array("(", ")", "'", "!", "%5C%22", '%5Ct'), $mgsOut);     
   $fldsTxt = 'source_url=%2Fpin%2Ffind%2F%3Furl%3D'.urlencode(urlencode($lnk)).'&data=%7B%22options%22%3A%7B%22board_id%22%3A%22'.$boardID.'%22%2C%22description%22%3A%22'.$mgsOut.'%22%2C%22link%22%3A%22'.urlencode($lnk).'%22%2C%22share_twitter%22%3Afalse%2C%22image_url%22%3A%22'.urlencode($imgURL).'%22%2C%22method%22%3A%22scraped%22%7D%2C%22context%22%3A%7B%7D%7D';
   $hdrsArr = $this->headers('https://www.pinterest.com/resource/PinResource/create/ ', 'https://www.pinterest.com', 'POST', true);       
   $hdrsArr['X-NEW-APP']='1'; $hdrsArr['X-APP-VERSION']=$apVer; $hdrsArr['X-CSRFToken']=$tk; $hdrsArr['X-Pinterest-AppState']='active';  $hdrsArr['Accept'] = 'application/json, text/javascript, */*; q=0.01';      
   $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $fldsTxt); 
   $rep = nxs_remote_post('https://www.pinterest.com/resource/PinResource/create/', $advSet); if (is_nxs_error($rep)) {  $badOut = print_r($rep, true)." - ERROR"; return $badOut; }       
   $contents = $rep['body']; $resp = json_decode($contents, true); //  prr($advSet);  prr($resp);   prr($fldsTxt); // prr($contents);    
   if (is_array($resp)) {
     if (isset($resp['resource_response']) && isset($resp['resource_response']['error']) && $resp['resource_response']['error']!='' ) return print_r($resp['resource_response']['error'], true); 
     elseif (isset($resp['resource_response']) && isset($resp['resource_response']['data']) && $resp['resource_response']['data']['id']!=''){ // gor JSON
       if (isset($resp['resource_response']) && isset($resp['resource_response']['error']) && $resp['resource_response']['error']!='') return print_r($resp['resource_response']['error'], true);
       else return array("isPosted"=>"1", "postID"=>$resp['resource_response']['data']['id'], 'pDate'=>date('Y-m-d H:i:s'), "postURL"=>"http://www.pinterest.com/pin/".$resp['resource_response']['data']['id']);
     }    
   }elseif (stripos($contents, 'blocked this')!==false) { $retText = trim(str_replace(array("\r\n", "\r", "\n"), " | ", strip_tags(CutFromTo($contents, '</head>', '</body>'))));
     return "Pinterest ERROR: 'The Source is blocked'. Please see https://support.pinterest.com/entries/21436306-why-is-my-pin-or-site-blocked-for-spam-or-inappropriate-content/ for more info | Pinterest Message:".$retText;
   }  
   elseif (stripos($contents, 'image you tried to pin is too small')!==false) { $retText = trim(str_replace(array("\r\n", "\r", "\n"), " | ", strip_tags(CutFromTo($contents, '</head>', '</body>'))));
     return "Image you tried to pin is too small | Pinterest Message:".$retText;
   }  
   elseif (stripos($contents, 'CSRF verification failed')!==false) { $retText = trim(str_replace(array("\r\n", "\r", "\n"), " | ", strip_tags(CutFromTo($contents, '</head>', '</body>'))));
     return "CSRF verification failed - Please contact NextScripts Support | Pinterest Message:".$retText;
   }
   elseif (stripos($contents, 'Oops')!==false && stripos($contents, '<body>')!==false ) return 'Pinterest ERROR MESSAGE : '.trim(str_replace(array("\r\n", "\r", "\n"), " | ", strip_tags(CutFromTo($contents, '</head>', '</body>'))));
   else return "Somethig is Wrong - Pinterest Returned Error 502";         
 }    
Exemple #10
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'));
 }
 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;     
 }              
Exemple #12
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;
 }