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);
     }
 }
Ejemplo n.º 2
0
	function doPostToBlogger($blogID, $title, $msg, $tags = '') {
		$rnds = rndString ( 35 );
		$blogID = trim ( $blogID );
		$gpp = "http://www.blogger.com/blogger.g?blogID=" . $blogID;
		$refPage = "http://www.blogger.com/home";
		$contents = getCurlPageX ( $gpp, $refPage, true );
		$jjs = CutFromTo ( $contents, 'BloggerClientFlags=', '_layoutOnLoadHandler' );
		$j69 = ''; // prr($contents); echo "\r\n"; echo "\r\n";
		if ($j69 == '' && strpos ( $jjs, '64:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '64:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '65:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '65:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '66:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '66:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '67:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '67:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '68:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '68:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '69:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '69:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '70:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '70:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '71:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '71:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '72:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '72:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '73:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '73:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '74:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '74:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '75:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '75:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '76:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '76:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		if ($j69 == '' && strpos ( $jjs, '77:"' ) !== false) {
			$j69 = CutFromTo ( $jjs, '77:"', '"' );
			if (strpos ( $j69, ':' ) === false || (strpos ( $j69, '/' ) !== false))
				$j69 = '';
		}
		$gpp = "http://www.blogger.com/blogger_rpc?blogID=" . $blogID;
		$refPage = "http://www.blogger.com/blogger.g?blogID=" . $blogID;
		$spar = '{"method":"editPost","params":[,1,"","",,1,0,1,3,0,2,2,,0,[,,,,,,""],"en",0,[,' . date ( "Y" ) . ',' . date ( "n" ) . ',' . date ( "j" ) . ',' . date ( "G" ) . ',' . date ( "i" ) . '],,,0,"",[,1,[,0,0,0,0,0,0,0,0,0,"0"]],3],"xsrf":"' . $j69 . '"}';
		$contents = getCurlPageX ( $gpp, $refPage, true, $spar );
		$newpostID = CutFromTo ( $contents, '"result":[null,"', '"' );
		if ($tags != '')
			$pTags = '["' . $tags . '"]';
		else
			$pTags = ''; // prr($pTags);
		$pTags = str_replace ( '!', '', $pTags );
		$pTags = str_replace ( '.', '', $pTags );
		// $spar = '{"method":"editPost","params":[,1,"'.addslashes($title).'","'.addslashes($msg).'","'.$newpostID.'",0,0,1,3,0,2,2,'.$pTags.',0,[,,,,,,""],"en",0,[,'.date("Y").','.date("n").','.date("j").','.date("G").','.date("i").'],,,0,"",[,1,[,0,0,0,0,0,0,0,0,0,"0"]],1],"xsrf":"'.$j69.'"}';
		
		$msg = str_replace ( "'", '"', $msg );
		$msg = addslashes ( $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", '\n', $msg );
		
		$spar = '{"method":"editPost","params":{"1":1,"2":"' . addslashes ( $title ) . '","3":"' . $msg . '","4":"' . $newpostID . '","5":0,"6":0,"7":1,"8":3,"9":0,"10":2,"11":2,' . ($pTags != '' ? '"12":' . $pTags . ',' : '') . '"13":0,"14":{"6":""},"15":"en","16":0,"17":{"1":' . date ( "Y" ) . ',"2":' . date ( "n" ) . ',"3":' . date ( "j" ) . ',"4":' . date ( "G" ) . ',"5":' . date ( "i" ) . '},"20":0,"21":"","22":{"1":1,"2":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":"0"}},"23":1},"xsrf":"' . $j69 . '"}';
		
		$contents = getCurlPageX ( $gpp, $refPage, false, $spar ); // prr($spar); prr($contents);
		if (stripos ( $contents ['content'], '"error":' ) !== false) {
			return "Error: " . print_r ( $contents ['content'], true );
		}
		if ($contents ['http_code'] == '200')
			return "OK";
	}
Ejemplo n.º 3
0
        function showGenNTSettings($ntOpts)
        {
            global $nxs_snapSetPgURL, $nxs_plurl, $nxs_gOptions;
            $ntInfo = $this->ntInfo;
            // V2 Auth
            if (isset($_GET['code']) && $_GET['code'] != '' && isset($_GET['state']) && substr($_GET['state'], 0, 7) == 'nxs-li-') {
                $at = $_GET['code'];
                $ii = str_replace('nxs-li-', '', $_GET['state']);
                echo "----=={ oAuth 2.0 Wordflow }==----<br/>-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>";
                $gGet = $_GET;
                unset($gGet['code']);
                unset($gGet['state']);
                unset($gGet['post_type']);
                $sturl = explode('?', $nxs_snapSetPgURL);
                $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : '');
                $nto = $ntOpts[$ii];
                $wprg = array();
                $wprg['sslverify'] = false;
                if (isset($nto['liAPIKey'])) {
                    echo "-=";
                    prr($nto);
                    // die();
                    $tknURL = 'https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=' . $at . '&redirect_uri=' . urlencode($nxs_snapSetPgURL) . '&client_id=' . $nto['liAPIKey'] . '&client_secret=' . $nto['liAPISec'];
                    $response = wp_remote_post($tknURL, $wprg);
                    prr($tknURL);
                    if (is_object($response) && isset($response->errors)) {
                        prr($response);
                        die;
                    }
                    if (is_array($response) && stripos($response['body'], '"error":') !== false) {
                        prr($response['body']);
                        prr(json_decode($response['body'], true));
                        die;
                    }
                    $resp = json_decode($response['body'], true);
                    prr($resp);
                    if (!is_array($resp) || empty($resp['access_token'])) {
                        prr($resp);
                        die;
                    }
                    if (function_exists('get_option')) {
                        $currTime = time() + get_option('gmt_offset') * HOUR_IN_SECONDS;
                    } else {
                        $currTime = time();
                    }
                    $nto['liAccessToken'] = $resp['access_token'];
                    $nto['liAccessTokenSecret'] = 'No Need for oAuth V2';
                    $nto['liOAuthVerifier'] = 'No Need for oAuth V2';
                    $nto['liAccessTokenExp'] = $currTime + $resp['expires_in'];
                    echo "<br/>----=={ Expires: " . date('Y-m-d H:i:s', $nto['liAccessTokenExp']) . " }==---- <br/>";
                    $tknURL = 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name)?format=json&oauth2_access_token=' . $nto['liAccessToken'];
                    $response = wp_remote_get($tknURL, $wprg);
                    prr($tknURL);
                    prr($response);
                    $user = json_decode($response['body'], true);
                    if (!empty($user['id'])) {
                        $nto['liUserID'] = $user['id'];
                        $nto['liUserInfo'] = $user['firstName'] . $user['lastName'] . (!empty($user['id']) ? " (" . $user['id'] . ")" : '');
                        $nto['isV2'] = true;
                        if (function_exists('get_option')) {
                            $nxs_gOptions = get_option('NS_SNAutoPoster');
                        }
                        if (!empty($nxs_gOptions)) {
                            $nxs_gOptions['li'][$ii] = $nto;
                            prr($nto);
                            nxs_settings_save($nxs_gOptions);
                        }
                        ?>
<script type="text/javascript">window.location = "<?php 
                        echo $nxs_snapSetPgURL;
                        ?>
"</script>      
        <?php 
                    }
                }
                die;
            }
            // V1 Auth
            if (isset($_GET['auth']) && $_GET['auth'] == 'li') {
                require_once 'apis/liOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $api_key = $options['liAPIKey'];
                $api_secret = $options['liAPISec'];
                $callback_url = $nxs_snapSetPgURL . "&auth=lia&acc=" . $_GET['acc'];
                $li_oauth = new nsx_LinkedIn($api_key, $api_secret, $callback_url);
                $request_token = $li_oauth->getRequestToken();
                //echo "####"; prr($request_token); die();
                if (!is_object($request_token)) {
                    echo "### LinkedIn Authorization Error:";
                    prr($request_token);
                    if (is_string($request_token) && stripos($request_token, 'timestamp') !== false) {
                        echo "Your Server Time: " . date('m/d/Y h:i:s a');
                        echo " Correct Time: " . date('m/d/Y h:i:s a', nxs_ntp_time('t1.timegps.net'));
                    }
                    die;
                }
                $options['liOAuthToken'] = $request_token->key;
                $options['liOAuthTokenSecret'] = $request_token->secret;
                // prr($li_oauth);
                switch ($li_oauth->http_code) {
                    case 200:
                        $url = $li_oauth->generateAuthorizeUrl();
                        $optionsG = get_option('NS_SNAutoPoster');
                        $optionsG['li'][$_GET['acc']] = $options;
                        update_option('NS_SNAutoPoster', $optionsG);
                        echo '<script type="text/javascript">window.location = "' . $url . '"</script>';
                        break;
                    default:
                        echo '<br/><b style="color:red">Could not connect to LinkedIn. Refresh the page or try again later.</b>';
                        die;
                }
                die;
            }
            if (isset($_GET['auth']) && $_GET['auth'] == 'lia') {
                require_once 'apis/liOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $api_key = $options['liAPIKey'];
                $api_secret = $options['liAPISec'];
                $li_oauth = new nsx_LinkedIn($api_key, $api_secret);
                $li_oauth->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
                $li_oauth->oauth_verifier = $_REQUEST['oauth_verifier'];
                $li_oauth->getAccessToken($_REQUEST['oauth_verifier']);
                $options['liOAuthVerifier'] = $_REQUEST['oauth_verifier'];
                $options['liAccessToken'] = $li_oauth->access_token->key;
                $options['liAccessTokenSecret'] = $li_oauth->access_token->secret;
                try {
                    $xml_response = $li_oauth->getProfile("~:(id,first-name,last-name)");
                } catch (Exception $o) {
                    prr($o);
                    die("<span style='color:red;'>ERROR: Authorization Error</span>");
                }
                if (stripos($xml_response, '<first-name>') !== false) {
                    $userinfo = CutFromTo($xml_response, '<id>', '</id>') . " - " . CutFromTo($xml_response, '<first-name>', '</first-name>') . " " . CutFromTo($xml_response, '<last-name>', '</last-name>');
                } else {
                    $userinfo = '';
                }
                if ($userinfo != '') {
                    $options['liUserInfo'] = $userinfo;
                    $optionsG = get_option('NS_SNAutoPoster');
                    $optionsG['li'][$_GET['acc']] = $options;
                    update_option('NS_SNAutoPoster', $optionsG);
                    echo '<script type="text/javascript">window.location = "' . $nxs_snapSetPgURL . '"</script>';
                    die;
                }
                prr($xml_response);
                die("<span style='color:red;'>ERROR: Something is Wrong with your LinkedIn account</span>");
            }
            ?>
    
    <div class="nxs_box">
      <div class="nxs_box_header"> 
        <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php 
            echo $nxs_plurl;
            ?>
img/<?php 
            echo $ntInfo['lcode'];
            ?>
16.png);"><?php 
            echo $ntInfo['name'];
            ?>
          <?php 
            $cbo = count($ntOpts);
            ?>
 
          <?php 
            if ($cbo > 1) {
                ?>
<div class="nsBigText"><?php 
                echo "(" . ($cbo == '0' ? 'No' : $cbo) . " ";
                _e('accounts', 'social-networks-auto-poster-facebook-twitter-g');
                echo ")";
                ?>
</div><?php 
            }
            ?>
        </div>
      </div>
      <div class="nxs_box_inside">
        <?php 
            foreach ($ntOpts as $indx => $pbo) {
                if (trim($pbo['nName'] == '')) {
                    $pbo['nName'] = !empty($pbo[$ntInfo['defNName']]) ? $pbo[$ntInfo['defNName']] : 'LinkedIn';
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['liAccessToken']) && $pbo['liAccessTokenSecret'] != '' ? '1' : '';
                }
                ?>
          <p style="margin:0px;margin-left:5px;"> <img id="<?php 
                echo $ntInfo['code'] . $indx;
                ?>
LoadingImg" style="display: none;" src='<?php 
                echo $nxs_plurl;
                ?>
img/ajax-loader-sm.gif' />
            <input value="0" name="<?php 
                echo $ntInfo['lcode'];
                ?>
[<?php 
                echo $indx;
                ?>
][apDo<?php 
                echo $ntInfo['code'];
                ?>
]" type="hidden" />             
            <?php 
                if ((int) $pbo['do' . $ntInfo['code']] == 1 && isset($pbo['catSel']) && (int) $pbo['catSel'] == 1) {
                    ?>
 <input type="radio" name="<?php 
                    echo $ntInfo['lcode'];
                    ?>
[<?php 
                    echo $indx;
                    ?>
][apDo<?php 
                    echo $ntInfo['code'];
                    ?>
]" id="rbtn<?php 
                    echo $ntInfo['lcode'] . $indx;
                    ?>
" value="1" checked="checked" onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);" /> <?php 
                } else {
                    ?>
            
            <input value="1" name="<?php 
                    echo $ntInfo['lcode'];
                    ?>
[<?php 
                    echo $indx;
                    ?>
][apDo<?php 
                    echo $ntInfo['code'];
                    ?>
]" type="checkbox" <?php 
                    if ((int) $pbo['do' . $ntInfo['code']] == 1 && $pbo['catSel'] != '1') {
                        echo "checked";
                    }
                    ?>
 />
           <?php 
                }
                ?>
            <?php 
                if (isset($pbo['catSel']) && (int) $pbo['catSel'] == 1) {
                    ?>
 <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php 
                    echo "*[" . (substr_count($pbo['catSelEd'], ",") + 1) . "]*";
                    ?>
</span><?php 
                }
                ?>
            <?php 
                if (isset($pbo['rpstOn']) && (int) $pbo['rpstOn'] == 1) {
                    ?>
 <span onmouseout="nxs_hidePopUpInfo('popReActive');" onmouseover="nxs_showPopUpInfo('popReActive', event);"><?php 
                    echo "*[R]*";
                    ?>
</span><?php 
                }
                ?>
            <strong><?php 
                _e('Auto-publish to', 'social-networks-auto-poster-facebook-twitter-g');
                ?>
 <?php 
                echo $ntInfo['name'];
                ?>
 <i style="color: #005800;"><?php 
                if ($pbo['nName'] != '') {
                    echo "(" . $pbo['nName'] . ")";
                }
                ?>
</i></strong>
          &nbsp;&nbsp;<?php 
                if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '')) {
                    ?>
<b style="color: #800000"><?php 
                    _e('Attention requred. Unfinished setup', 'social-networks-auto-poster-facebook-twitter-g');
                    ?>
 ==&gt;</b><?php 
                }
                ?>
 <?php 
                if (!empty($pbo['grpID'])) {
                    ?>
<b style="color: #800000"><?php 
                    _e('Attention requred. Groups are no longer supported by LinkedIn Native API', 'social-networks-auto-poster-facebook-twitter-g');
                    ?>
 ==&gt;</b><?php 
                }
                ?>
 <a id="do<?php 
                echo $ntInfo['code'] . $indx;
                ?>
AG" href="#" onclick="doGetHideNTBlock('<?php 
                echo $ntInfo['code'];
                ?>
' , '<?php 
                echo $indx;
                ?>
');return false;">[<?php 
                _e('Show Settings', 'social-networks-auto-poster-facebook-twitter-g');
                ?>
]</a>&nbsp;&nbsp;
          <a href="#" onclick="doDelAcct('<?php 
                echo $ntInfo['lcode'];
                ?>
', '<?php 
                echo $indx;
                ?>
', '<?php 
                if (isset($pbo['bgBlogID'])) {
                    echo $pbo['nName'];
                }
                ?>
');return false;">[<?php 
                _e('Remove Account', 'social-networks-auto-poster-facebook-twitter-g');
                ?>
]</a>
          </p><div id="nxsNTSetDiv<?php 
                echo $ntInfo['code'] . $indx;
                ?>
"></div><?php 
                //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo);
            }
            ?>
      </div>
    </div> <?php 
        }
 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;     
 }              
Ejemplo n.º 5
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;
     }
 }
Ejemplo n.º 6
0
 function setNTSettings($post, $options)
 {
     $code = 'VK';
     $lcode = 'vk';
     foreach ($post as $ii => $pval) {
         if (isset($pval['apVKAppID']) && $pval['apVKAppID'] != '') {
             if (!isset($options[$ii])) {
                 $options[$ii] = array();
             }
             if (isset($pval['apDoVK'])) {
                 $options[$ii]['doVK'] = $pval['apDoVK'];
             } else {
                 $options[$ii]['doVK'] = 0;
             }
             if (isset($pval['nName'])) {
                 $options[$ii]['nName'] = trim($pval['nName']);
             }
             if (isset($pval['apVKAppID'])) {
                 $options[$ii]['vkAppID'] = trim($pval['apVKAppID']);
             }
             if (isset($pval['uName'])) {
                 $options[$ii]['uName'] = trim($pval['uName']);
             }
             if (isset($pval['uPass'])) {
                 $options[$ii]['uPass'] = '******' . nsx_doEncode($pval['uPass']);
             } else {
                 $options[$ii]['uPass'] = '';
             }
             if (isset($pval['vkPh'])) {
                 $options[$ii]['vkPh'] = trim($pval['vkPh']);
             }
             if (isset($pval['apVKAuthResp'])) {
                 $options[$ii]['apVKAuthResp'] = trim($pval['apVKAuthResp']);
                 $options[$ii]['vkAppAuthToken'] = trim(CutFromTo($pval['apVKAuthResp'] . '&', 'access_token=', '&'));
                 $options[$ii]['vkAppAuthUser'] = trim(CutFromTo($pval['apVKAuthResp'] . "&", 'user_id=', '&'));
                 $hdrsArr = nxs_getVKHeaders($pval['url']);
                 $response = wp_remote_get($pval['url'], array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr));
                 if (is_wp_error($response)) {
                     echo "ERROR: <br/>";
                     prr($response);
                     return;
                 }
                 $contents = $response['body'];
                 $contents = utf8_decode($contents);
                 if (stripos($contents, '"group_id":') !== false) {
                     $options[$ii]['pgIntID'] = '-' . CutFromTo($contents, '"group_id":', ',');
                     $type = 'all';
                 }
                 if (stripos($contents, '"public_id":') !== false) {
                     $options[$ii]['pgIntID'] = '-' . CutFromTo($contents, '"public_id":', ',');
                     $type = 'all';
                 }
                 if (stripos($contents, '"user_id":') !== false) {
                     $options[$ii]['pgIntID'] = CutFromTo($contents, '"user_id":', ',');
                     $type = 'own';
                 }
             }
             if (isset($pval['catSel'])) {
                 $options[$ii]['catSel'] = trim($pval['catSel']);
             } else {
                 $options[$ii]['catSel'] = 0;
             }
             if ($options[$ii]['catSel'] == '1' && trim($pval['catSelEd']) != '') {
                 $options[$ii]['catSelEd'] = trim($pval['catSelEd']);
             } else {
                 $options[$ii]['catSelEd'] = '';
             }
             if (isset($pval['postType'])) {
                 $options[$ii]['postType'] = trim($pval['postType']);
             }
             if (isset($pval['attch'])) {
                 $options[$ii]['attch'] = $pval['attch'];
             } else {
                 $options[$ii]['attch'] = 0;
             }
             if (isset($pval['attchAsVid'])) {
                 $options[$ii]['attchAsVid'] = $pval['attchAsVid'];
             } else {
                 $options[$ii]['attchAsVid'] = 0;
             }
             if (isset($pval['apVKImgUpl'])) {
                 $options[$ii]['imgUpl'] = $pval['apVKImgUpl'];
             } else {
                 $options[$ii]['imgUpl'] = 0;
             }
             if (isset($pval['addBackLink'])) {
                 $options[$ii]['addBackLink'] = $pval['addBackLink'];
             } else {
                 $options[$ii]['addBackLink'] = 0;
             }
             if (isset($pval['msgFrmt'])) {
                 $options[$ii]['msgFrmt'] = trim($pval['msgFrmt']);
             }
             if (isset($pval['msgAFormat'])) {
                 $options[$ii]['msgAFormat'] = trim($pval['msgAFormat']);
             }
             $options[$ii] = nxs_adjRpst($options[$ii], $pval);
             if (isset($pval['delayDays'])) {
                 $options[$ii]['nDays'] = trim($pval['delayDays']);
             }
             if (isset($pval['delayHrs'])) {
                 $options[$ii]['nHrs'] = trim($pval['delayHrs']);
             }
             if (isset($pval['delayMin'])) {
                 $options[$ii]['nMin'] = trim($pval['delayMin']);
             }
             if (isset($pval['qTLng'])) {
                 $options[$ii]['qTLng'] = trim($pval['qTLng']);
             }
             if (isset($pval['url'])) {
                 $options[$ii]['url'] = trim($pval['url']);
                 if (substr($options[$ii]['url'], 0, 4) != 'http') {
                     $options[$ii]['url'] = 'http://' . $options[$ii]['url'];
                 }
                 $vkPgID = $options[$ii]['url'];
                 if (substr($vkPgID, -1) == '/') {
                     $vkPgID = substr($vkPgID, 0, -1);
                 }
                 $vkPgID = substr(strrchr($vkPgID, "/"), 1);
                 if (strpos($vkPgID, '?') !== false) {
                     $vkPgID = substr($vkPgID, 0, strpos($vkPgID, '?'));
                 }
                 $options[$ii]['vkPgID'] = $vkPgID;
                 //echo $vkPgID;
                 if (strpos($options[$ii]['url'], '?') !== false) {
                     $options[$ii]['url'] = substr($options[$ii]['url'], 0, strpos($options[$ii]['url'], '?'));
                 }
                 // prr($pval); prr($options[$ii]); // die();
             }
         } elseif (count($pval) == 1) {
             if (isset($pval['apDo' . $code])) {
                 $options[$ii]['do' . $code] = $pval['apDo' . $code];
             } else {
                 $options[$ii]['do' . $code] = 0;
             }
         }
     }
     return $options;
 }
Ejemplo n.º 7
0
 function post($post)
 {
     $ck = $this->ck;
     $mh = $this->mh;
     $hdrsArr = $this->headers('http://www.deviantart.com/');
     $badOut = '';
     $advSets = array('headers' => $hdrsArr, 'cookies' => $ck);
     // prr($advSets);
     $rep = wp_remote_get($mh . '/journal/?edit', $advSets);
     if (is_wp_error($rep)) {
         $badOut = print_r($rep, true) . " - ERROR Post 1";
         return $badOut;
     }
     $contents = CutFromTo($rep['body'], '<h3 class="journal-editor-create">', '</form>');
     // prr($contents);
     $md = array();
     while (stripos($contents, '"hidden"') !== false) {
         $contents = substr($contents, stripos($contents, '"hidden"') + 8);
         $name = trim(CutFromTo($contents, 'name="', '"'));
         if (!in_array($name, $md)) {
             $md[] = $name;
             $val = trim(CutFromTo($contents, 'value="', '"'));
             $flds[$name] = urldecode(nxs_decodeEntities($val));
         }
     }
     $flds['subject'] = nsTrnc(nxs_decodeEntities($post['title']), 50);
     $flds['body'] = trim($post['text']);
     $flds['song'] = '';
     $flds['game'] = '';
     $flds['book'] = '';
     $flds['food'] = '';
     $flds['movie'] = '';
     $flds['drink'] = '';
     $flds['flip'] = '0';
     $flds['featured'] = '1';
     $flds['portal'] = '1';
     $flds['skinlabel'] = 'No+skin';
     $flds['jheader'] = '';
     $flds['jcss'] = '';
     $flds['jfooter'] = '';
     $ck2 = $rep['cookies'];
     for ($i = 0; $i < count($ck); $i++) {
         if ($ck[$i]->name == 'userinfo') {
             $ck[$i]->value = urlencode($ck2[0]->value);
         }
     }
     $fldsOut = $flds;
     $ckk = array();
     for ($i = 0; $i < count($ck); $i++) {
         if ($ck[$i]->name == 'userinfo' || $ck[$i]->name == 'auth') {
             $ckk[] = $ck[$i];
         }
     }
     $ck = $ckk;
     sleep(16);
     //## Important.
     $hdrsArr = $this->headers($mh . '/journal/?edit', $mh, true);
     $advSets = array('method' => 'POST', 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $fldsOut, 'cookies' => $ck);
     $response = wp_remote_post($mh . '/journal/?edit', $advSets);
     // prr($advSets); prr($response);
     if ($response['response']['code'] == '200' && stripos($response['body'], 'field_error') !== false) {
         $eRRMsg = CutFromTo($response['body'], 'field_error', '</div>');
         $eRRMsg = trim(strip_tags(CutFromTo($eRRMsg . "|GGG|", '>', '|GGG|')));
         $badOut = "POST Error: " . $eRRMsg;
         return $badOut;
     }
     if ($response['response']['code'] == '302') {
         $hdrsArr = $this->headers($mh);
         $rep = wp_remote_get($mh . '/journal/', array('headers' => $hdrsArr, 'cookies' => $ck));
         $daNewPostURL = CutFromTo($rep['body'], 'a data-deviationid="', '</a>');
         $daNewPostURL = CutFromTo($daNewPostURL, 'href="', '"');
         $daNewPostID = CutFromTo($rep['body'], 'a data-deviationid="', '"');
         return array('postID' => $daNewPostID, 'isPosted' => 1, 'postURL' => $daNewPostURL, 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut .= 'Somethibng is not right';
         return $badOut;
     }
     return $badOut;
 }
Ejemplo n.º 8
0
 function post($post)
 {
     $ck = $this->ck;
     $mh = $this->mh;
     $hdrsArr = $this->headers('http://www.deviantart.com/');
     $badOut = '';
     $advSets = array('headers' => $hdrsArr, 'cookies' => $ck);
     // prr($advSets);
     $rep = wp_remote_get($mh . '/journal/?edit', $advSets);
     if (is_wp_error($rep)) {
         $badOut = print_r($rep, true) . " - ERROR Post 1";
         return $badOut;
     }
     $contents = CutFromTo($rep['body'], '<h3 class="journal-editor-create">', '</form>');
     // prr($contents);
     $md = array();
     while (stripos($contents, '"hidden"') !== false) {
         $contents = substr($contents, stripos($contents, '"hidden"') + 8);
         $name = trim(CutFromTo($contents, 'name="', '"'));
         if (!in_array($name, $md)) {
             $md[] = $name;
             $val = trim(CutFromTo($contents, 'value="', '"'));
             $flds[$name] = urldecode(nxs_decodeEntities($val));
         }
     }
     $flds['subject'] = nsTrnc(nxs_decodeEntities($post['title']), 50);
     $flds['body'] = trim($post['text']);
     $flds['song'] = '';
     $flds['game'] = '';
     $flds['book'] = '';
     $flds['food'] = '';
     $flds['movie'] = '';
     $flds['drink'] = '';
     $flds['flip'] = '0';
     $flds['featured'] = '1';
     $flds['portal'] = '1';
     $flds['skinlabel'] = 'No+skin';
     $flds['jheader'] = '';
     $flds['jcss'] = '';
     $flds['jfooter'] = '';
     $ck2 = $rep['cookies'];
     for ($i = 0; $i < count($ck); $i++) {
         if ($ck[$i]->name == 'userinfo') {
             $ck[$i]->value = urlencode($ck2[0]->value);
         }
     }
     $fldsOut = http_build_query($flds);
     $fldsOut = str_replace('No%2Bskin', 'No+skin', $fldsOut);
     $ckk = array();
     for ($i = 0; $i < count($ck); $i++) {
         if ($ck[$i]->name == 'userinfo' || $ck[$i]->name == 'auth') {
             $ckk[] = $ck[$i];
             if ($ck[$i]->name == 'userinfo') {
                 $ui = $ck[$i]->value;
             }
         }
     }
     $ck = $ckk;
     sleep(6);
     //## Important.
     $pid = CutFromTo($contents, '"pageviewID":"', '"');
     $iid = CutFromTo($contents, '"requestid":"', '"');
     $dflds = array('ui' => $ui, 'pid' => $pid, 'iid' => $iid . '-i7ex4avh-1.0', 't' => 'json');
     $dfldsq = http_build_query($dflds);
     $dfldsq1 = 'ui=' . $ui . '&c%5B%5D=%22Stash%22%2C%22create_journal%22%2C%5B%2235020854%22%2C%22' . urlencode($flds['subject']) . '%22%2C%22' . urlencode($flds['subject']) . '%22%2C%22-1%22%2C%7B%7D%5D&pid=' . $pid . '&iid=' . $iid . '-i7exlgzv-1.0&t=json';
     $hdrsArr = $this->headers($mh . '/journal/?edit', $mh, true);
     $advSets = array('method' => 'POST', 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ck);
     $advSets['body'] = $dfldsq1;
     $rep = wp_remote_post($mh . '/global/difi/?', $advSets);
     //prr($mh.'/global/difi/?');  prr($advSets);       prr($rep);
     if (is_wp_error($rep)) {
         $badOut = print_r($rep, true) . " - ERROR DFI 1";
         return $badOut;
     }
     $cnt = $rep['body'];
     if (stripos($cnt, '"status":"SUCCESS"') === false || stripos($cnt, '"args":["') === false) {
         $badOut = print_r($cnt, true) . " - ERROR DFI 1.1";
         return $badOut;
     } else {
         $npid = CutFromTo($cnt, '"args":["', '"');
     }
     $dfldsq2 = 'ui=' . $ui . '&c%5B%5D=%22Deviation%22%2C%22DeleteSingle%22%2C%5B%' . $npid . '%22%2C%221%22%5D&pid=' . $pid . '&iid=' . $iid . '-i7exlgzv-1.0&t=json';
     $advSets['body'] = $dfldsq2;
     $rep = wp_remote_post($mh . '/global/difi/?', $advSets);
     // sleep(6); //## Important.      //prr($advSets); prr($rep); die();
     $advSets['body'] = $fldsOut;
     $response = wp_remote_post($mh . '/journal/?edit', $advSets);
     //prr($mh.'/journal/?edit');  prr($advSets); prr($response);
     if ($response['response']['code'] == '200' && stripos($response['body'], 'field_error') !== false) {
         $eRRMsg = CutFromTo($response['body'], 'field_error', '</div>');
         $eRRMsg = trim(strip_tags(CutFromTo($eRRMsg . "|GGG|", '>', '|GGG|')));
         $badOut = "POST Error: " . $eRRMsg;
         return $badOut;
     }
     if ($response['response']['code'] == '302') {
         $hdrsArr = $this->headers($mh);
         $rep = wp_remote_get($mh . '/journal/', array('headers' => $hdrsArr, 'cookies' => $ck));
         $daNewPostURL = CutFromTo($rep['body'], 'a data-deviationid="', '</a>');
         $daNewPostURL = CutFromTo($daNewPostURL, 'href="', '"');
         $daNewPostID = CutFromTo($rep['body'], 'a data-deviationid="', '"');
         return array('postID' => $daNewPostID, 'isPosted' => 1, 'postURL' => $daNewPostURL, 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut .= 'Somethibng is not right';
         return $badOut;
     }
     return $badOut;
 }
Ejemplo n.º 9
0
 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";         
 }    
Ejemplo n.º 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['uName']) || trim($options['uPass']) == '') {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     $email = $options['uName'];
     $pass = substr($options['uPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['uPass'], 5)) : $options['uPass'];
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['msgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['msgTFrmt'], $message);
     }
     //######  ===============
     $hdrsArr = $this->nxs_getKTHeaders('https://kippt.com/api/clips/', $email, $pass, true);
     $hdrsArr['X-Kippt-Username'] = $email;
     $hdrsArr['X-Kippt-API-Token'] = $pass;
     $cnt = wp_remote_get('https://kippt.com/api/lists/', array('timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr));
     $lists = json_decode($cnt['body'], true);
     foreach ($lists['objects'] as $list) {
         if ($list['slug'] == $options['list']) {
             $listID = $list['resource_uri'];
         }
     }
     if (empty($listID)) {
         $listID = '';
     }
     $flds = array();
     $flds['url'] = $message['url'];
     $flds['notes'] = $msg;
     $flds['title'] = $msgT;
     $flds['list'] = $listID;
     $flds = json_encode($flds);
     // prr($flds);
     $cnt = wp_remote_post('https://kippt.com/api/clips/', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds));
     if (is_wp_error($cnt) || empty($cnt['body']) || $cnt['response']['code'] != '201') {
         return "ERROR: " . print_r($cnt, true);
     }
     //prr($cnt['body']);
     //## Return
     if (stripos($cnt['body'], '"resource_uri": "') !== false) {
         $pid = CutFromTo($cnt['body'], '"resource_uri": "', '"');
         $purl = 'https://kippt.com' . CutFromTo($cnt['body'], '"app_url": "', '"');
         return array('postID' => $pid, 'isPosted' => 1, 'postURL' => $purl, 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= print_r($cnt, true);
         return $badOut;
     }
 }
Ejemplo n.º 11
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;
     }
 }
Ejemplo n.º 12
0
 public function flUploadPhoto($imgFile, $parameters)
 {
     $url = 'https://www.flickr.com/services/upload/';
     $requestParams = $parameters == NULL ? array() : $parameters;
     $phid = '';
     $oauthParams = array('oauth_nonce' => $this->genRndString(), 'oauth_timestamp' => time(), 'oauth_token' => $this->access_token, 'oauth_consumer_key' => $this->consumer_key, 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_version' => '1.0');
     $requestParams = array_merge($requestParams, $oauthParams);
     $this->sign($url, $requestParams);
     $requestParams['photo'] = $imgFile;
     // prr($requestParams);
     $xml = $this->httpRequest($url, $requestParams);
     if (stripos($xml, '</photoid>') !== false && stripos($xml, 'stat="ok"') !== false) {
         $phid = CutFromTo($xml, '<photoid>', '</photoid>');
     }
     return empty($phid) ? "Problem: " . $xml . "<pre>" . print_r($requestParams, true) . "</pre>" : $phid;
 }
 function setNTSettings($post, $options)
 {
     $code = 'LJ';
     $lcode = 'lj';
     foreach ($post as $ii => $pval) {
         if (isset($pval['apLJUName']) && $pval['apLJUName'] != '') {
             if (!isset($options[$ii])) {
                 $options[$ii] = array();
             }
             if (isset($pval['nName'])) {
                 $options[$ii]['nName'] = trim($pval['nName']);
             }
             if (isset($pval['ljSrv'])) {
                 $options[$ii]['ljSrv'] = trim($pval['ljSrv']);
             }
             if ($options[$ii]['ljSrv'] == 'DW') {
                 $server = 'dreamwidth.org';
             } else {
                 $server = 'livejournal.com';
             }
             if (isset($pval['apLJUName'])) {
                 $options[$ii]['ljUName'] = trim($pval['apLJUName']);
             }
             $options[$ii]['ljURL'] = 'http://' . $options[$ii]['ljUName'] . "." . $server;
             if (isset($pval['apLJPass'])) {
                 $options[$ii]['ljPass'] = '******' . nsx_doEncode($pval['apLJPass']);
             } else {
                 $options[$ii]['ljPass'] = '';
             }
             if (isset($pval['apLJMsgFrmt'])) {
                 $options[$ii]['ljMsgFormat'] = trim($pval['apLJMsgFrmt']);
             }
             if (isset($pval['apLJMsgTFrmt'])) {
                 $options[$ii]['ljMsgTFormat'] = trim($pval['apLJMsgTFrmt']);
             }
             if (isset($pval['catSel'])) {
                 $options[$ii]['catSel'] = trim($pval['catSel']);
             } else {
                 $options[$ii]['catSel'] = 0;
             }
             if (isset($pval['inclTags'])) {
                 $options[$ii]['inclTags'] = $pval['inclTags'];
             } else {
                 $options[$ii]['inclTags'] = 0;
             }
             if ($options[$ii]['catSel'] == '1' && trim($pval['catSelEd']) != '') {
                 $options[$ii]['catSelEd'] = trim($pval['catSelEd']);
             } else {
                 $options[$ii]['catSelEd'] = '';
             }
             if (isset($pval['commID'])) {
                 if (stripos($pval['commID'], '.') !== false) {
                     $pval['commID'] = CutFromTo($pval['commID'], '://', '.');
                 }
                 $options[$ii]['commID'] = trim($pval['commID']);
             }
             if (isset($pval['apDoLJ'])) {
                 $options[$ii]['doLJ'] = $pval['apDoLJ'];
             } else {
                 $options[$ii]['doLJ'] = 0;
             }
             $options[$ii] = nxs_adjRpst($options[$ii], $pval);
             if (isset($pval['delayDays'])) {
                 $options[$ii]['nDays'] = trim($pval['delayDays']);
             }
             if (isset($pval['delayHrs'])) {
                 $options[$ii]['nHrs'] = trim($pval['delayHrs']);
             }
             if (isset($pval['delayMin'])) {
                 $options[$ii]['nMin'] = trim($pval['delayMin']);
             }
             if (isset($pval['qTLng'])) {
                 $options[$ii]['qTLng'] = trim($pval['qTLng']);
             }
         } elseif (count($pval) == 1) {
             if (isset($pval['apDo' . $code])) {
                 $options[$ii]['do' . $code] = $pval['apDo' . $code];
             } else {
                 $options[$ii]['do' . $code] = 0;
             }
         }
     }
     return $options;
 }
Ejemplo n.º 14
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);
 }
Ejemplo n.º 15
0
        function showGenNTSettings($ntOpts)
        {
            global $nxs_snapThisPageUrl, $nxs_plurl;
            $ntInfo = array('code' => 'LI', 'lcode' => 'li', 'name' => 'LinkedIn', 'defNName' => 'ulName', 'tstReq' => true);
            if (isset($_GET['auth']) && $_GET['auth'] == 'li') {
                require_once 'apis/liOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $api_key = $options['liAPIKey'];
                $api_secret = $options['liAPISec'];
                $callback_url = $nxs_snapThisPageUrl . "&auth=lia&acc=" . $_GET['acc'];
                $li_oauth = new nsx_LinkedIn($api_key, $api_secret, $callback_url);
                $request_token = $li_oauth->getRequestToken();
                //echo "####"; prr($request_token); die();
                $options['liOAuthToken'] = $request_token->key;
                $options['liOAuthTokenSecret'] = $request_token->secret;
                // prr($li_oauth);
                switch ($li_oauth->http_code) {
                    case 200:
                        $url = $li_oauth->generateAuthorizeUrl();
                        $optionsG = get_option('NS_SNAutoPoster');
                        $optionsG['li'][$_GET['acc']] = $options;
                        update_option('NS_SNAutoPoster', $optionsG);
                        echo '<script type="text/javascript">window.location = "' . $url . '"</script>';
                        break;
                    default:
                        echo '<br/><b style="color:red">Could not connect to LinkedIn. Refresh the page or try again later.</b>';
                        die;
                }
                die;
            }
            if (isset($_GET['auth']) && $_GET['auth'] == 'lia') {
                require_once 'apis/liOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $api_key = $options['liAPIKey'];
                $api_secret = $options['liAPISec'];
                $li_oauth = new nsx_LinkedIn($api_key, $api_secret);
                $li_oauth->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
                $li_oauth->oauth_verifier = $_REQUEST['oauth_verifier'];
                $li_oauth->getAccessToken($_REQUEST['oauth_verifier']);
                $options['liOAuthVerifier'] = $_REQUEST['oauth_verifier'];
                $options['liAccessToken'] = $li_oauth->access_token->key;
                $options['liAccessTokenSecret'] = $li_oauth->access_token->secret;
                try {
                    $xml_response = $li_oauth->getProfile("~:(id,first-name,last-name)");
                } catch (Exception $o) {
                    prr($o);
                    die("<span style='color:red;'>ERROR: Authorization Error</span>");
                }
                if (stripos($xml_response, '<first-name>') !== false) {
                    $userinfo = CutFromTo($xml_response, '<id>', '</id>') . " - " . CutFromTo($xml_response, '<first-name>', '</first-name>') . " " . CutFromTo($xml_response, '<last-name>', '</last-name>');
                } else {
                    $userinfo = '';
                }
                if ($userinfo != '') {
                    $options['liUserInfo'] = $userinfo;
                    $optionsG = get_option('NS_SNAutoPoster');
                    $optionsG['li'][$_GET['acc']] = $options;
                    update_option('NS_SNAutoPoster', $optionsG);
                    echo '<script type="text/javascript">window.location = "' . $nxs_snapThisPageUrl . '"</script>';
                    die;
                }
                prr($xml_response);
                die("<span style='color:red;'>ERROR: Something is Wrong with your LinkedIn account</span>");
            }
            ?>
    
    <div class="nxs_box">
      <div class="nxs_box_header"> 
        <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php 
            echo $nxs_plurl;
            ?>
img/<?php 
            echo $ntInfo['lcode'];
            ?>
16.png);"><?php 
            echo $ntInfo['name'];
            ?>
          <?php 
            $cbo = count($ntOpts);
            ?>
 <?php 
            wp_nonce_field('ns' . $ntInfo['code'], 'ns' . $ntInfo['code'] . '_wpnonce');
            ?>
          <?php 
            if ($cbo > 1) {
                ?>
<div class="nsBigText"><?php 
                echo "(" . ($cbo == '0' ? 'No' : $cbo) . " ";
                _e('accounts', 'nxs_snap');
                echo ")";
                ?>
</div><?php 
            }
            ?>
        </div>
      </div>
      <div class="nxs_box_inside">
        <?php 
            foreach ($ntOpts as $indx => $pbo) {
                if (trim($pbo['nName'] == '')) {
                    $pbo['nName'] = $pbo[$ntInfo['defNName']];
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['liAccessToken']) && $pbo['liAccessTokenSecret'] != '' ? '1' : '';
                }
                ?>
          <p style="margin:0px;margin-left:5px;">
            <input value="1" name="<?php 
                echo $ntInfo['lcode'];
                ?>
[<?php 
                echo $indx;
                ?>
][apDo<?php 
                echo $ntInfo['code'];
                ?>
]" onchange="doShowHideBlocks('<?php 
                echo $ntInfo['code'];
                ?>
');" type="checkbox" <?php 
                if ((int) $pbo['do' . $ntInfo['code']] == 1) {
                    echo "checked";
                }
                ?>
 /> <?php 
                if ((int) $pbo['catSel'] == 1) {
                    ?>
   <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php 
                    echo "*[" . (substr_count($pbo['catSelEd'], ",") + 1) . "]*";
                    ?>
</span><?php 
                }
                ?>
            <strong><?php 
                _e('Auto-publish to', 'nxs_snap');
                ?>
 <?php 
                echo $ntInfo['name'];
                ?>
 <i style="color: #005800;"><?php 
                if ($pbo['nName'] != '') {
                    echo "(" . $pbo['nName'] . ")";
                }
                ?>
</i></strong>
          &nbsp;&nbsp;<?php 
                if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '')) {
                    ?>
<b style="color: #800000"><?php 
                    _e('Attention requred. Unfinished setup', 'nxs_snap');
                    ?>
 ==&gt;</b><?php 
                }
                ?>
<a id="do<?php 
                echo $ntInfo['code'] . $indx;
                ?>
A" href="#" onclick="doShowHideBlocks2('<?php 
                echo $ntInfo['code'] . $indx;
                ?>
');return false;">[<?php 
                _e('Show Settings', 'nxs_snap');
                ?>
]</a>&nbsp;&nbsp;
          <a href="#" onclick="doDelAcct('<?php 
                echo $ntInfo['lcode'];
                ?>
', '<?php 
                echo $indx;
                ?>
', '<?php 
                if (isset($pbo['bgBlogID'])) {
                    echo $pbo['nName'];
                }
                ?>
');return false;">[<?php 
                _e('Remove Account', 'nxs_snap');
                ?>
]</a>
          </p><?php 
                $this->showNTSettings($indx, $pbo);
            }
            ?>
      </div>
    </div> <?php 
        }
Ejemplo n.º 16
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;
     }
 }
Ejemplo n.º 17
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);
 }
Ejemplo n.º 18
0
 function nxs_doPostToVB($url, $subj, $msg, $lnk, $tags)
 {
     global $nxs_vbCkArray;
     $hdrsArr = $this->nxs_getVBHeaders($url);
     $ckArr = $nxs_vbCkArray;
     $mids = '';
     $response = wp_remote_get($url, array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
     if (is_wp_error($response)) {
         return "Invalid Connection. " . print_r($response, true);
     }
     $contents = $response['body'];
     // $response['body'] = htmlentities($response['body']);  prr($response);    die();
     if (stripos($contents, 'base href="') !== false) {
         $baseURL = trim(CutFromTo($contents, 'base href="', '"'));
     } else {
         $uarr = explode('/', $url);
         $dd = $uarr[count($uarr) - 1];
         $baseURL = str_replace($dd, '', $url);
     }
     if (stripos($contents, 'newthread.php?do=newthread') !== false) {
         $mdd = 't';
     } elseif (stripos($contents, 'newreply.php?') !== false) {
         $mdd = 'p';
     } else {
         return "No Thread/Post Controls found";
     }
     if ($mdd == 't') {
         $fid = CutFromTo($contents, 'newthread.php?do=newthread', '"');
         // echo  $baseURL.'newthread.php?do=newthread'.str_replace('&amp;','&',$fid);
         $response = wp_remote_get($baseURL . 'newthread.php?do=newthread' . str_replace('&amp;', '&', $fid), array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
         $contents = $response['body'];
         $frmTxt = CutFromTo($contents, 'newthread.php?do=postthread', '</form>');
         $md = array();
         $flds = array();
         //prr($frmTxt);
         while (stripos($frmTxt, '<input') !== false) {
             $inpField = trim(CutFromTo($frmTxt, '<input', '>'));
             $name = trim(CutFromTo($inpField, 'name="', '"'));
             if (stripos($inpField, '"hidden"') !== false && $name != '' && !in_array($name, $md)) {
                 $md[] = $name;
                 $val = trim(CutFromTo($inpField, 'value="', '"'));
                 $flds[$name] = $val;
                 $mids .= "&" . $name . "=" . $val;
             }
             $frmTxt = substr($frmTxt, stripos($frmTxt, '<input') + 8);
         }
         $flds['subject'] = $subj;
         $flds['message'] = $msg;
         $flds['message_backup'] = $msg;
         $flds['wysiwyg'] = '1';
         $flds['do'] = 'postthread';
         $flds['taglist'] = $tags;
         $flds['parseurl'] = '1';
         $flds['sbutton'] = 'Submit+New+Thread';
         $smURL = $baseURL . 'newthread.php?do=postthread' . str_replace('&amp;', '&', $fid);
     }
     //prr($flds);
     if ($mdd == 'p') {
         $fid = CutFromTo($contents, 'newreply.php?do=newreply', '"');
         $response = wp_remote_get($baseURL . 'newreply.php?do=newreply' . str_replace('&amp;', '&', $fid), array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
         $contents = $response['body'];
         $frmTxt = CutFromTo($contents, 'newreply.php?do=postreply', '</form>');
         $md = array();
         $flds = array();
         //prr($frmTxt);
         while (stripos($frmTxt, '<input') !== false) {
             $inpField = trim(CutFromTo($frmTxt, '<input', '>'));
             $name = trim(CutFromTo($inpField, 'name="', '"'));
             if (stripos($inpField, '"hidden"') !== false && $name != '' && !in_array($name, $md)) {
                 $md[] = $name;
                 $val = trim(CutFromTo($inpField, 'value="', '"'));
                 $flds[$name] = $val;
                 $mids .= "&" . $name . "=" . $val;
             }
             $frmTxt = substr($frmTxt, stripos($frmTxt, '<input') + 8);
         }
         $flds['title'] = $subj;
         $flds['message'] = $msg;
         $flds['message_backup'] = $msg;
         $flds['wysiwyg'] = '1';
         $flds['do'] = 'postreply';
         $flds['parseurl'] = '1';
         $flds['sbutton'] = 'Submit+Reply';
         $smURL = $baseURL . 'newreply.php?do=postreply' . str_replace('&amp;', '&', $fid);
     }
     //prr($flds);
     $r2 = wp_remote_post($smURL, array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
     // prr($r2['response']);  prr(htmlentities($r2['body'])); $r2['body'] = ''; prr($r2); die();
     if (is_wp_error($r2)) {
         return "Invalid Connection. " . print_r($r2, true);
     }
     if (stripos($r2['body'], 'tag can only be ') !== false) {
         $lgLim = trim(CutFromTo($r2['body'], 'tag can only be ', ' characters'));
         $flds['taglist'] = substr($flds['taglist'], 0, $lgLim);
         $r2 = wp_remote_post($smURL, array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
     }
     if (is_wp_error($r2)) {
         return "Invalid Connection. " . print_r($r2, true);
     }
     if (stripos($r2['body'], 'errorblock') !== false) {
         return trim(strip_tags(CutFromTo($r2['body'], 'errorblock', '</div>')));
     }
     if (stripos($r2['body'], 'exec_refresh()') !== false && stripos($r2['body'], 'blockrow restore">') !== false) {
         return trim(strip_tags(CutFromTo($r2['body'], 'blockrow restore">', '</p>')));
     }
     if (stripos($r2['body'], '<error>') !== false) {
         return trim(strip_tags(CutFromTo($r2['body'], '<error>', '</error>')));
     }
     if ($r2['response']['code'] == '302' || $r2['response']['code'] == '303') {
         return array("code" => "OK", "post_id" => $r2['headers']['location']);
     }
     if (stripos($r2['body'], '<newpostid>') !== false || stripos($r2['body'], 'postbit postid="') !== false) {
         return 'OK';
     }
     return "Something wrong - Error: " . print_r($r2, 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);
 }
Ejemplo n.º 20
0
 function nxs_doPostToSU($msg, $lnk, $cat, $tags, $nsfw = false)
 {
     global $nxs_suCkArray;
     $r2 = wp_remote_get($lnk);
     $hdrsArr = $this->nxs_getSUHeaders('https://www.stumbleupon.com/submit', false, false);
     $ckArr = $nxs_suCkArray;
     $response = wp_remote_get('https://www.stumbleupon.com/submit', array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
     $ckArr2 = nxsMergeArraysOV($ckArr, $response['cookies']);
     //$nxs_suCkArray = $ckArr;
     $contents = $response['body'];
     //$response['body'] = htmlentities($response['body']);  prr($response);
     //$ckArr = nxsMergeArraysOV($ckArr, $response['cookies']);
     $hdrsArr = $this->nxs_getSUHeaders('https://www.stumbleupon.com/submit', true);
     $frmTxt = CutFromTo($contents, '<form method="post" id="submit-form"', '</form>');
     $md = array();
     $flds = array();
     $mids = '';
     // prr($contents);
     while (stripos($frmTxt, '<input') !== false) {
         $inpField = trim(CutFromTo($frmTxt, '<input', '>'));
         $name = trim(CutFromTo($inpField, 'name="', '"'));
         if (stripos($inpField, '"hidden"') !== false && $name != '' && !in_array($name, $md)) {
             $md[] = $name;
             $val = trim(CutFromTo($inpField, 'value="', '"'));
             $flds[$name] = $val;
             $mids .= "&" . $name . "=" . $val;
         }
         $frmTxt = substr($frmTxt, stripos($frmTxt, '<input') + 8);
     }
     $flds['url'] = $lnk;
     $flds['review'] = $msg;
     $flds['tags'] = $cat;
     $flds['nsfw'] = $nsfw ? 'true' : 'false';
     $flds['user-tags'] = $tags;
     $flds['_output'] = 'Json';
     $flds['_method'] = 'create';
     $flds['language'] = 'EN';
     $r2 = wp_remote_post('https://www.stumbleupon.com/submit', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
     $resp = json_decode($r2['body'], true);
     if (isset($resp['_reason']) && is_array($resp['_reason']) && count($resp['_reason']) > 0 && stripos($resp['_reason'][0]['message'], 'Failed to add URL') !== false) {
         sleep(5);
         $r2 = wp_remote_post('https://www.stumbleupon.com/submit', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
         $resp = json_decode($r2['body'], true);
     }
     if (stripos($resp['_error'], 'Invalid token') !== false) {
         // In case we got the Wrong Cookies
         $r2 = wp_remote_post('https://www.stumbleupon.com/submit', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr2));
         $resp = json_decode($r2['body'], true);
         if (stripos($resp['_reason'][0]['message'], 'Failed to add URL') !== false) {
             sleep(5);
             $r2 = wp_remote_post('https://www.stumbleupon.com/submit', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr2));
             $resp = json_decode($r2['body'], true);
             // prr($flds);  prr($resp); //nxs_addToLogN('SU', 'E', '-=DBG=- '.print_r($resp, true)." - #####", $extInfo);
         }
     }
     if (isset($resp['discovery']['publicid'])) {
         $pageID = $resp['discovery']['publicid'];
     } elseif (isset($resp['discovery']['url']['publicid'])) {
         $pageID = $resp['discovery']['url']['publicid'];
     }
     if ($resp['_success'] == '1') {
         $ckArr = nxsMergeArraysOV($ckArr, $r2['cookies']);
         $nxs_suCkArray = $ckArr;
         return array("code" => "OK", "post_id" => $pageID);
     } elseif (isset($resp['_reason'])) {
         $resp['_reason']['NXS_FIELDS'] = $flds;
         $resp['_reason']['NXS_RESP'] = $resp;
         return $resp['_reason'];
     } else {
         return "ERROR" . print_r($resp, true);
     }
 }
Ejemplo n.º 21
0
 function nxs_getPostImage($postID, $size = 'large', $def = '')
 {
     $imgURL = '';
     global $plgn_NS_SNAutoPoster;
     if (!isset($plgn_NS_SNAutoPoster)) {
         return;
     }
     $options = $plgn_NS_SNAutoPoster->nxs_options;
     $imgURL = "https://www.google.com/images/srpr/logo3w.png";
     $res = nxs_chckRmImage($imgURL);
     $imgURL = '';
     if (!$res) {
         $options['imgNoCheck'] = '1';
     }
     //## Featured Image from Specified Location
     if ((int) $postID > 0 && isset($options['featImgLoc']) && $options['featImgLoc'] !== '') {
         $afiLoc = get_post_meta($postID, $options['featImgLoc'], true);
         if (is_array($afiLoc) && $options['featImgLocArrPath'] != '') {
             $cPath = $options['featImgLocArrPath'];
             while (strpos($cPath, '[') !== false) {
                 $arrIt = CutFromTo($cPath, '[', ']');
                 $arrIt = str_replace("'", "", str_replace('"', '', $arrIt));
                 $afiLoc = $afiLoc[$arrIt];
                 $cPath = substr($cPath, strpos($cPath, ']'));
             }
         }
         $imgURL = trim($options['featImgLocPrefix']) . trim($afiLoc);
         if ($imgURL != '' && stripos($imgURL, 'http') === false) {
             $imgURL = home_url() . $imgURL;
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Featured Image
     if ($imgURL == '') {
         if ((int) $postID > 0 && function_exists("get_post_thumbnail_id")) {
             $imgURL = wp_get_attachment_image_src(get_post_thumbnail_id($postID), $size);
             $imgURL = $imgURL[0];
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## YAPB
     if ((int) $postID > 0 && class_exists("YapbImage")) {
         $imgURLObj = YapbImage::getInstanceFromDb($postID);
         if (is_object($imgURLObj)) {
             $imgURL = $imgURLObj->uri;
         }
         $stURL = site_url();
         if (substr($stURL, -1) == '/') {
             $stURL = substr($stURL, 0, -1);
         }
         if ($imgURL != '') {
             $imgURL = $stURL . $imgURL;
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Find Images in Post
     if ((int) $postID > 0 && $imgURL == '') {
         $post = get_post($postID);
         $imgsFromPost = nsFindImgsInPost($post, $options['useUnProc'] == '1');
         if (is_array($imgsFromPost) && count($imgsFromPost) > 0) {
             $imgURL = $imgsFromPost[0];
         }
     }
     //echo "##".count($imgsFromPost); prr($imgsFromPost);
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Attachements
     if ((int) $postID > 0 && $imgURL == '') {
         $attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $postID));
         if (is_array($attachments) && is_object($attachments[0])) {
             $imgURL = wp_get_attachment_image_src($attachments[0]->ID, $size);
         }
         $imgURL = $imgURL[0];
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Default
     if (trim($imgURL) == '' && trim($def) == '') {
         $imgURL = $options['ogImgDef'];
     }
     if (trim($imgURL) == '' && trim($def) != '') {
         $imgURL = $def;
     }
     return $imgURL;
 }
Ejemplo n.º 22
0
	function doPostToPinterest($msg, $imgURL, $lnk, $boardID) {
		global $nxs_gTkn, $nxs_gCookiesArr;
		$mgs = urlencode ( $msg );
		$lnk = urlencode ( $lnk );
		$fldsTxt = 'caption=' . $msg . '&board=' . $boardID . '&tags=&replies=&buyable=&title=&media_url=' . $imgURL . '&url=' . $lnk . '&via=&csrfmiddlewaretoken=' . $nxs_gTkn . '&form_url=';
		if (trim ( $boardID ) == '')
			return "Board is not Set";
		if (trim ( $imgURL ) == '')
			return "Image is not Set";
		$contents = getCurlPageX ( 'http://pinterest.com/pin/create/button/', '', true, $fldsTxt, false, '' ); // prr($contents);
		
		
		if (stripos ( $contents, 'blocked this source' ) !== false)
			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";
		if (stripos ( $contents, 'Oops' ) !== false && stripos ( $contents, '<body>' ) !== false)
			return 'Pinterest ERROR MESSAGE : ' . strip_tags ( CutFromTo ( $contents, '<body>', '</body>' ) );
		if (stripos ( $contents, 'pinSuccess' ) !== false)
			return "OK";
		else
			return $contents;
	}
Ejemplo n.º 23
0
 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;
 }
Ejemplo n.º 24
0
 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);
 }
Ejemplo n.º 25
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['ipUName']) || trim($options['ipPass']) == '') {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     $dusername = $options['ipUName'];
     $pass = substr($options['ipPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['ipPass'], 5)) : $options['ipPass'];
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['ipMsgFormat'], $message);
     }
     if (!empty($message['pTitle'])) {
         $msgT = $message['pTitle'];
     } else {
         $msgT = nxs_doFormatMsg($options['ipMsgTFormat'], $message);
     }
     $link = urlencode($message['url']);
     $desc = urlencode(substr($msgT, 0, 250));
     $ext = urlencode(substr($msg, 0, 1000));
     $tags = $message['tags'];
     if (!preg_match("@^(https?|ftp)://[^\\s/\$.?#].[^\\s]*\$@iS", $message['url'])) {
         return 'Error: Unvalid URL: ' . $message['url'];
     }
     $apicall = "https://www.instapaper.com/api/add?red=api&url={$link}&title={$desc}&selection={$ext}";
     $hdrsArr = $this->nxs_getIPHeaders($dusername . ':' . $pass);
     $cnt = wp_remote_get($apicall, array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr));
     //  prr($cnt);
     if (is_wp_error($cnt)) {
         $error_string = $cnt->get_error_message();
         if (stripos($error_string, ' timed out') !== false) {
             sleep(10);
             $cnt = wp_remote_get($apicall, array('method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr));
         }
     }
     if (is_wp_error($cnt)) {
         $ret = 'Something went wrong - ' . print_r($cnt, true);
     } else {
         if (is_array($cnt) && stripos($cnt['body'], 'bookmark_id') !== false) {
             return array('postID' => CutFromTo($cnt['body'], '"bookmark_id": ', '}'), 'isPosted' => 1, 'postURL' => 'IP', 'pDate' => date('Y-m-d H:i:s'));
         } else {
             $ret = "Error: ";
             if (is_array($cnt) && $cnt['response']['code'] == '401') {
                 $ret .= " Incorrect Username/Password ";
             } else {
                 $ret .= print_r($cnt, true);
             }
             $ret .= $cnt['response']['message'];
         }
     }
     $badOut['Error'] .= $ret;
     return $badOut;
 }