function connect($u,$p){ $badOut = 'Error: '; // $this->debug = true; //## Check if alrady IN if (!$this->check($u)){ if ($this->debug) echo "[PN] NO Saved Data; Logging in...<br/>\r\n"; $hdrsArr = $this->headers('https://www.pinterest.com/login/'); $rep = nxs_remote_get('https://www.pinterest.com/login/', array('headers' => $hdrsArr, 'timeout' => 45, 'httpversion' => '1.1')); if (is_nxs_error($rep)) { $badOut = print_r($rep, true)." - ERROR -01-"; return $badOut; } $ck = $rep['cookies']; $contents = $rep['body']; prr($contents); $apVer = trim(CutFromTo($contents,'"app_version": "', '"')); $fldsTxt = 'data=%7B%22options%22%3A%7B%22username_or_email%22%3A%22'.urlencode($u).'%22%2C%22password%22%3A%22'.str_replace('%5C','%5C%5C',urlencode($p)).'%22%7D%2C%22context%22%3A%7B%22app_version%22%3A%22'.$apVer. '%22%7D%7D&source_url=%2Flogin%2F&module_path=App()%3ELoginPage()%3ELogin()%3EButton(class_name%3Dprimary%2C+text%3DLog+in%2C+type%3Dsubmit%2C+tagName%3Dbutton%2C+size%3Dlarge)'; foreach ($ck as $c) if ($c->name=='csrftoken') $xftkn = $c->value; //## ACTUAL LOGIN $hdrsArr = $this->headers('https://www.pinterest.com/login/', 'https://www.pinterest.com', 'POST', true); $hdrsArr['X-NEW-APP']='1'; $hdrsArr['X-APP-VERSION']=$apVer; $hdrsArr['X-CSRFToken']=$xftkn; $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'body' => $fldsTxt); // prr($advSet); $rep = nxs_remote_post('https://www.pinterest.com/resource/UserSessionResource/create/', $advSet); if (is_nxs_error($rep)) { $badOut = print_r($rep, true)." - ERROR -02-"; return $badOut; } if (!empty($rep['body'])) { $contents = $rep['body']; $resp = json_decode($contents, true); } else { $badOut = print_r($rep, true)." - ERROR -03-"; return $badOut; } if (is_array($resp) && empty($resp['resource_response']['error'])) { $ck = $rep['cookies']; foreach ($ck as $ci=>$cc) $ck[$ci]->value = str_replace(' ','+', $cc->value); $hdrsArr = $this->headers('https://www.pinterest.com/login'); $rep=nxs_remote_get('https://www.pinterest.com/', array('headers' => $hdrsArr, 'timeout' => 45, 'redirection' => 0, 'cookies' => $ck, 'httpversion' => '1.1')); if (is_nxs_error($rep)) { $badOut = print_r($rep, true)." - ERROR -02.1-"; return $badOut; } 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; } foreach ($ck as $ci=>$cc) $ck[$ci]->value = str_replace(' ','+', $cc->value); $this->tk = $xftkn; $this->ck = $ck; $this->apVer = $apVer; if ($this->debug) echo "[PN] You are IN;<br/>\r\n"; return false; // echo "You are IN"; } elseif (is_array($resp) && isset($resp['resource_response']['error'])) return "ERROR -04-: ".$resp['resource_response']['error']['http_status']." | ".$resp['resource_response']['error']['message']; 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, 'IP because of suspicious activity')!==false) return 'Pinterest blocked logins from this IP because of suspicious activity'; elseif (stripos($contents, 've detected a bot!')!==false) return 'Pinterest has your IP ('.CutFromTo($contents, 'ess: <b>','<').') blocked. Please <a target="_blank" class="link" href="//help.pinterest.com/entries/22914692">Contact Pinterest</a> and ask them to unblock your IP. '; elseif (stripos($contents, 'bot running on your network')!==false) return 'Pinterest has your IP ('.CutFromTo($contents, 'Your IP is:','<').') blocked. Please <a target="_blank" class="link" href="//help.pinterest.com/entries/22914692">Contact Pinterest</a> and ask them to unblock your IP. '; else return 'Pinterest login failed. Unknown Error. Please contact support.'; return 'Pinterest login failed. Unknown Error #2. Please contact support.'; } else { if ($this->debug) echo "[PN] Saved Data is OK;<br/>\r\n"; return false; } }
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['ljUName']) || trim($options['ljPass']) == '') { $badOut['Error'] = 'Not Configured'; return $badOut; } $pass = substr($options['ljPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['ljPass'], 5)) : $options['ljPass']; //## Format if (!empty($message['pText'])) { $msg = $message['pText']; } else { $msg = nxs_doFormatMsg($options['ljMsgFormat'], $message); } if (!empty($message['pTitle'])) { $msgT = $message['pTitle']; } else { $msgT = nxs_doFormatMsg($options['ljMsgTFormat'], $message); } require_once 'apis/xmlrpc-client.php'; if (!empty($options['ljSrv']) && $options['ljSrv'] == 'DW') { $server = 'dreamwidth.org'; } else { $server = 'livejournal.com'; } $nxsToLJclient = new NXS_XMLRPC_Client('http://www.' . $server . '/interface/xmlrpc'); $nxsToLJclient->debug = false; $date = time(); $year = date("Y", $date); $mon = date("m", $date); $day = date("d", $date); $hour = date("G", $date); $min = date("i", $date); $nxsToLJContent = array("username" => $options['ljUName'], "password" => $pass, "event" => $msg, "subject" => $msgT, "lineendings" => "unix", "year" => $year, "mon" => $mon, "day" => $day, "hour" => $hour, "min" => $min, "ver" => 2); if (!empty($options['commID']) && $options['commID'] != '') { $nxsToLJContent["usejournal"] = $options['commID']; } if (!empty($options['inclTags']) && $options['inclTags'] == '1' && !empty($message['tags'])) { $nxsToLJContent['props'] = array('taglist' => $message['tags']); } // prr($nxsToLJContent); if (!$nxsToLJclient->query('LJ.XMLRPC.postevent', $nxsToLJContent)) { prr($nxsToLJclient); $ret = 'Something went wrong - ' . $nxsToLJclient->getErrorCode() . ' : ' . $nxsToLJclient->getErrorMessage(); } else { $ret = 'OK'; } $pid = $nxsToLJclient->getResponse(); if (is_array($pid) && !empty($pid['url'])) { return array('postID' => $pid['url'], 'isPosted' => 1, 'postURL' => $pid['url'], 'pDate' => date('Y-m-d H:i:s')); } else { $badOut['Error'] .= 'Something went wrong - NO PID ' . print_r($pid, true); } return $badOut; }
function postShare($tkn, $msg, $title = '', $url = '', $imgURL = '', $dsc = '') { $nURL = 'https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token=' . $tkn; $dsc = nxs_decodeEntitiesFull(strip_tags($dsc)); $msg = strip_tags(nxs_decodeEntitiesFull($msg)); $title = nxs_decodeEntitiesFull(strip_tags($title)); $xml = '<?xml version="1.0" encoding="UTF-8"?><share><comment>' . htmlspecialchars($msg, ENT_NOQUOTES, "UTF-8") . '</comment>' . ($url != '' ? '<content><title>' . htmlspecialchars($title, ENT_NOQUOTES, "UTF-8") . '</title><submitted-url>' . $url . '</submitted-url>' . (!empty($imgURL) ? '<submitted-image-url>' . $imgURL . '</submitted-image-url>' : '') . '<description>' . htmlspecialchars($dsc, ENT_NOQUOTES, "UTF-8") . '</description></content>' : '') . '<visibility><code>anyone</code></visibility></share>'; $hdrsArr = array(); $hdrsArr['Content-Type'] = 'application/xml'; prr($xml); $wprg = array('method' => 'POST', 'headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'body' => $xml); $wprg['sslverify'] = false; $response = wp_remote_post($nURL, $wprg); if (is_wp_error($response) || empty($response['body'])) { return "ERROR: " . print_r($response, true); } $post = json_decode($response['body'], true); return $post; }
function showGenNTSettings($ntOpts) { global $nxs_snapSetPgURL, $nxs_plurl, $nxs_gOptions; $ntInfo = $this->ntInfo; if (isset($_GET['auth']) && $_GET['auth'] == 'tr') { require_once 'apis/trOAuth.php'; $options = $ntOpts[$_GET['acc']]; $consumer_key = $options['trConsKey']; $consumer_secret = $options['trConsSec']; $callback_url = $nxs_snapSetPgURL . "&auth=tra&acc=" . $_GET['acc']; $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret); prr($tum_oauth); $request_token = $tum_oauth->getRequestToken($callback_url); echo "####"; prr($request_token); $options['trOAuthToken'] = $request_token['oauth_token']; $options['trOAuthTokenSecret'] = $request_token['oauth_token_secret']; // prr($tum_oauth ); die(); switch ($tum_oauth->http_code) { case 200: $url = $tum_oauth->getAuthorizeURL($options['trOAuthToken']); if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions['tr'][$_GET['acc']] = $options; nxs_settings_save($nxs_gOptions); } echo '<script type="text/javascript">window.location = "' . $url . '"</script>'; break; default: echo '<br/><b style="color:red">Could not connect to Tumblr. Refresh the page or try again later.</b>'; die; } die; } if (isset($_GET['auth']) && $_GET['auth'] == 'tra') { require_once 'apis/trOAuth.php'; $options = $ntOpts[$_GET['acc']]; prr($options); $consumer_key = $options['trConsKey']; $consumer_secret = $options['trConsSec']; $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trOAuthToken'], $options['trOAuthTokenSecret']); $options['trAccessTocken'] = $tum_oauth->getAccessToken($_REQUEST['oauth_verifier']); // prr($_GET); prr($_REQUEST); prr($options['trAccessTocken']); $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trAccessTocken']['oauth_token'], $options['trAccessTocken']['oauth_token_secret']); if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions['tr'][$_GET['acc']] = $options; nxs_settings_save($nxs_gOptions); } $userinfo = $tum_oauth->get('http://api.tumblr.com/v2/user/info'); prr($userinfo); prr($tum_oauth); // prr($url); die(); if (is_array($userinfo->response->user->blogs)) { foreach ($userinfo->response->user->blogs as $blog) { if (stripos($blog->url, $options['trPgID']) !== false) { $gGet = $_GET; unset($gGet['auth']); unset($gGet['acc']); unset($gGet['oauth_token']); unset($gGet['oauth_verifier']); unset($gGet['post_type']); $sturl = explode('?', $nxs_snapSetPgURL); $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : ''); echo '<script type="text/javascript">window.location = "' . $nxs_snapSetPgURL . '"</script>'; die; } } prr($userinfo); die("<span style='color:red;'>ERROR: Authorized USER don't have access to the specified blog: <span style='color:darkred; font-weight: bold;'>" . $options['trPgID'] . "</span></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', 'nxs_snap'); echo ")"; ?> </div><?php } ?> </div> </div> <div class="nxs_box_inside"> <?php foreach ($ntOpts as $indx => $pbo) { if (trim($pbo['nName'] == '')) { $pbo['nName'] = str_ireplace('https://', '', str_ireplace('http://', '', $pbo['trURL'])); } if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') { $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['trOAuthTokenSecret']) && $pbo['trOAuthTokenSecret'] != '' ? '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', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if ($pbo['nName'] != '') { echo "(" . $pbo['nName'] . ")"; } ?> </i></strong> <?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'); ?> ==></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', 'nxs_snap'); ?> ]</a> <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><div id="nxsNTSetDiv<?php echo $ntInfo['code'] . $indx; ?> "></div><?php //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo); } ?> </div> </div> <?php }
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-bg-') { $at = $_GET['code']; $ii = str_replace('nxs-bg-', '', $_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['APIKey'])) { echo "-="; prr($nto); // die(); $tknURL = 'https://www.googleapis.com/oauth2/v3/token?code=' . $at . '&redirect_uri=' . urlencode($nxs_snapSetPgURL) . '&scope=&client_id=' . $nto['APIKey'] . '&client_secret=' . $nto['APISec'] . '&grant_type=authorization_code'; $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['AccessToken'] = $resp['access_token']; $nto['AccessTokenSecret'] = 'No Need for oAuth V2'; $nto['OAuthVerifier'] = 'No Need for oAuth V2'; $nto['AccessTokenExp'] = $currTime + $resp['expires_in']; $nto['RefreshToken'] = $resp['refresh_token']; echo "<br/>----=={ Expires: " . date('Y-m-d H:i:s', $nto['AccessTokenExp']) . " }==---- <br/>"; if (!empty($nto['bgBlogID'])) { if (substr($nto['bgBlogID'], 0, 4) == 'http') { $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/byurl/?url=' . $nto['bgBlogID'] . '?access_token=' . $nto['AccessToken']; } else { $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/' . $nto['bgBlogID'] . '?access_token=' . $nto['AccessToken']; } } $response = wp_remote_get($tknURL, $wprg); prr($tknURL); prr($response); $user = json_decode($response['body'], true); prr($user); if (!empty($user['url'])) { $nto['blogURL'] = $user['url']; $nto['bgBlogID'] = $user['id']; $nto['blogInfo'] = $user['name'] . " [" . $user['id'] . "] (" . $user['url'] . ")"; if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions['bg'][$ii] = $nto; prr($nto); nxs_settings_save($nxs_gOptions); } ?> <script type="text/javascript">window.location = "<?php echo $nxs_snapSetPgURL; ?> "</script> <?php } } die; } ?> <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']] : 'Blogger'; } if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') { $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['AccessToken']) && $pbo['AccessTokenSecret'] != '' ? '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> <?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'); ?> ==></b><?php } ?> <?php if (!class_exists('nxsAPI_GP') && !empty($pbo['bgUName']) && empty($pbo['APIKey'])) { ?> <b style="color: #800000"><?php _e('Attention requred. "ClientLogin" authentication method is no longer supported by Blogger', 'social-networks-auto-poster-facebook-twitter-g'); ?> ==></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> <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 showGenNTSettings($ntOpts) { global $nxs_plurl, $nxs_snapSetPgURL, $nxs_gOptions; $ntInfo = $this->ntInfo; if (isset($_GET['auth']) && $_GET['auth'] == $ntInfo['lcode']) { require_once 'apis/scOAuth.php'; $options = $ntOpts[$_GET['acc']]; $consumer_key = $options['appKey']; $consumer_secret = $options['appSec']; $callback_url = $nxs_snapSetPgURL . "&auth=" . $ntInfo['lcode'] . "a&acc=" . $_GET['acc']; $tum_oauth = new wpScoopITOAuth($consumer_key, $consumer_secret); $tum_oauth->baseURL = 'https://www.flickr.com/services'; $tum_oauth->request_token_path = '/oauth/request_token'; $tum_oauth->access_token_path = '/oauth/access_token'; $request_token = $tum_oauth->getReqToken($callback_url); $options['oAuthToken'] = $request_token['oauth_token']; $options['oAuthTokenSecret'] = $request_token['oauth_token_secret']; switch ($tum_oauth->http_code) { case 200: $url = 'https://www.flickr.com/services/oauth/authorize?oauth_token=' . $options['oAuthToken']; if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions[$ntInfo['lcode']][$_GET['acc']] = $options; nxs_settings_save($nxs_gOptions); } echo '<br/><br/>All good?! Redirecting ..... <script type="text/javascript">window.location = "' . $url . '"</script>'; break; default: echo '<br/><b style="color:red">Could not connect to Flickr. Refresh the page or try again later.</b>'; die; } die; } if (isset($_GET['auth']) && $_GET['auth'] == $ntInfo['lcode'] . 'a') { require_once 'apis/scOAuth.php'; $options = $ntOpts[$_GET['acc']]; $consumer_key = $options['appKey']; $consumer_secret = $options['appSec']; $tum_oauth = new wpScoopITOAuth($consumer_key, $consumer_secret, $options['oAuthToken'], $options['oAuthTokenSecret']); //prr($tum_oauth); $tum_oauth->baseURL = 'https://www.flickr.com/services'; $tum_oauth->request_token_path = '/oauth/request_token'; $tum_oauth->access_token_path = '/oauth/access_token'; $access_token = $tum_oauth->getAccToken($_GET['oauth_verifier']); prr($access_token); $options['accessToken'] = $access_token['oauth_token']; $options['accessTokenSec'] = $access_token['oauth_token_secret']; if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions[$ntInfo['lcode']][$_GET['acc']] = $options; nxs_settings_save($nxs_gOptions); } $tum_oauth = new wpScoopITOAuth($consumer_key, $consumer_secret, $options['accessToken'], $options['accessTokenSec']); echo "OK. Let's Get Profile: "; prr($access_token); $params = array('format' => 'php_serial', 'method' => 'flickr.urls.getUserProfile'); $uinfo = $tum_oauth->makeReq('https://api.flickr.com/services/rest/', $params); // prr($uinfo);die(); if (is_array($uinfo) && isset($uinfo['user'])) { $options['appAppUserName'] = $access_token['username'] . "(" . urldecode($access_token['fullname']) . ")"; $options['appAppUserID'] = urldecode($uinfo['user']['nsid']); $options['userURL'] = urldecode($uinfo['user']['url']); if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions[$ntInfo['lcode']][$_GET['acc']] = $options; nxs_settings_save($nxs_gOptions); } } //die(); if (!empty($options['appAppUserID'])) { $gGet = $_GET; unset($gGet['auth']); unset($gGet['acc']); unset($gGet['oauth_token']); unset($gGet['oauth_verifier']); unset($gGet['post_type']); $sturl = explode('?', $nxs_snapSetPgURL); $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : ''); echo '<br/><br/>All good?! Redirecting ..... <script type="text/javascript">window.location = "' . $nxs_snapSetPgURL . '"</script>'; break; die; } else { die("<span style='color:red;'>ERROR: Authorization Error: <span style='color:darkred; font-weight: bold;'>" . print_r($uinfo, true) . "</span></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', 'nxs_snap'); echo ")"; ?> </div><?php } ?> </div> </div> <div class="nxs_box_inside"> <?php foreach ($ntOpts as $indx => $pbo) { if (trim($pbo['nName'] == '')) { $pbo['nName'] = $ntInfo['name']; } if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') { $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['appAppUserID']) && $pbo['appAppUserID'] > 1 ? '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' /> <?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="0" name="<?php echo $ntInfo['lcode']; ?> [<?php echo $indx; ?> ][apDo<?php echo $ntInfo['code']; ?> ]" type="hidden" /> <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', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if ($pbo['nName'] != '') { echo "(" . $pbo['nName'] . ")"; } ?> </i></strong> <?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'); ?> ==></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', 'nxs_snap'); ?> ]</a> <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><div id="nxsNTSetDiv<?php echo $ntInfo['code'] . $indx; ?> "></div><?php //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo); } ?> </div> </div> <?php }
function httpRequest($url, $auth_header, $method, $body = NULL) { // $this->debug = true; //if (!is_array($auth_header)) $auth_header = array($auth_header); if (!is_array($auth_header)) { $auth_header = array($auth_header); } if (!$method) { $method = "GET"; } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, $auth_header); // Set the headers. if ($body) { $auth_header[] = "Content-Type: text/xml;charset=utf-8"; curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_HTTPHEADER, $auth_header); } global $nxs_skipSSLCheck; if ($nxs_skipSSLCheck === true) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); } $data = curl_exec($curl); $errmsg = curl_error($curl); //prr($data);// die(); //## NextScripts Fix if (curl_errno($curl) == 60 || stripos($errmsg, 'SSL') !== false) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $data = curl_exec($curl); } if (curl_errno($curl) > 0) { $err = curl_errno($curl); $errmsg = curl_error($curl); prr($errmsg); prr($err); } //## /NextScripts Fix $header = curl_getinfo($curl); curl_close($curl); // prr($header); if ($this->debug) { echo $data . "\n"; } if (trim($data) == '' && ($header['http_code'] == '201' || $header['http_code'] == '200' || $header['http_code'] == '202')) { $data = '201'; } return $data; }
function getCurlPageMC($ch, $ref = '', $ctOnly = false, $fields = '', $dbg = false, $advSettings = '') { $ccURL = curl_getinfo ( $ch, CURLINFO_EFFECTIVE_URL ); if ($dbg) echo '<br/><b style="font-size:16px;color:green;">#### START CURL:' . $ccURL . '</b><br/>'; static $curl_loops = 0; static $curl_max_loops = 20; global $nxs_gCookiesArr; $cookies = cookArrToStr ( $nxs_gCookiesArr ); if ($dbg) { echo '<br/><b style="color:#005800;">## Request Cookies:</b><br/>'; prr ( $cookies ); } if ($curl_loops ++ >= $curl_max_loops) { $curl_loops = 0; return false; } $headers = array (); $headers [] = 'Accept: text/html, application/xhtml+xml, */*'; $headers [] = 'Cache-Control: no-cache'; $headers [] = 'Connection: Keep-Alive'; $headers [] = 'Accept-Language: en-us'; // $headers[] = 'Accept-Encoding: // gzip, deflate'; if ($fields != '') { if ((stripos ( $ccURL, 'http://www.blogger.com/blogger_rpc' ) !== false)) $headers [] = 'Content-Type: application/json; charset=utf-8'; else $headers [] = 'Content-Type: application/x-www-form-urlencoded;charset=utf-8'; } if (stripos ( $ccURL, 'http://www.blogger.com/blogger_rpc' ) !== false) { $headers [] = 'X-GWT-Permutation: 767A98E1C0A5F1D22D727BB9E37360B2'; $headers [] = 'X-GWT-Module-Base: http://www.blogger.com/static/v1/gwt/'; } if (isset ( $advSettings ['liXMLHttpRequest'] )) { $headers [] = 'X-Requested-With: XMLHttpRequest'; } if (isset ( $advSettings ['Origin'] )) { $headers [] = 'Origin: ' . $advSettings ['Origin']; } if (stripos ( $ccURL, 'blogger.com' ) !== false && (isset ( $advSettings ['cdomain'] ) && $advSettings ['cdomain'] == 'google.com')) $advSettings ['cdomain'] = 'blogger.com'; if (isset ( $advSettings ['noSSLSec'] )) { curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); } curl_setopt ( $ch, CURLOPT_HEADER, true ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $ch, CURLOPT_COOKIE, $cookies ); curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers ); curl_setopt ( $ch, CURLINFO_HEADER_OUT, true ); if ($ref != '') curl_setopt ( $ch, CURLOPT_REFERER, $ref ); curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" ); if ($fields != '') { curl_setopt ( $ch, CURLOPT_POST, true ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields ); } else { curl_setopt ( $ch, CURLOPT_POST, false ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, '' ); curl_setopt ( $ch, CURLOPT_HTTPGET, true ); } $content = curl_exec ( $ch ); // prr($content); $errmsg = curl_error ( $ch ); if (isset ( $errmsg ) && stripos ( $errmsg, 'SSL' ) !== false) { curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); $content = curl_exec ( $ch ); } $ndel = strpos ( $content, "\n\n" ); $rndel = strpos ( $content, "\r\n\r\n" ); if ($ndel == false) $ndel = 100000; if ($rndel == false) $rndel = 100000; $rrDel = $rndel < $ndel ? "\r\n\r\n" : "\n\n"; list ( $header, $content ) = explode ( $rrDel, $content, 2 ); if ($ctOnly !== true) { $nsheader = curl_getinfo ( $ch ); $err = curl_errno ( $ch ); $errmsg = curl_error ( $ch ); $nsheader ['errno'] = $err; $nsheader ['errmsg'] = $errmsg; $nsheader ['headers'] = $header; $nsheader ['content'] = $content; } $http_code = curl_getinfo ( $ch, CURLINFO_HTTP_CODE ); $headers = curl_getinfo ( $ch ); if ($dbg) { echo '<br/><b style="color:#005800;">## Headers:</b><br/>'; prr ( $headers ); prr ( $header ); } $results = array (); $cookies = ''; preg_match_all ( '|Set-Cookie: (.*);|U', $header, $results ); $carTmp = $results [1]; // $nxs_gCookiesArr // = // array_merge($nxs_gCookiesArr, // $ret['cookies']); preg_match_all ( '/Set-Cookie: (.*)\b/', $header, $xck ); $xck = $xck [1]; if ($dbg) { echo "Full Resp Cookies"; prr ( $xck ); echo "Plain Resp Cookies"; prr ( $carTmp ); } if (isset ( $advSettings ['cdomain'] ) && $advSettings ['cdomain'] != '') { foreach ( $carTmp as $iii => $cTmp ) if (stripos ( $xck [$iii], 'Domain=' ) === false || stripos ( $xck [$iii], 'Domain=.' . $advSettings ['cdomain'] . ';' ) !== false) { $ttt = explode ( '=', $cTmp, 2 ); $nxs_gCookiesArr [$ttt [0]] = $ttt [1]; } } else { foreach ( $carTmp as $cTmp ) { $ttt = explode ( '=', $cTmp, 2 ); $nxs_gCookiesArr [$ttt [0]] = $ttt [1]; } } if ($dbg) { echo '<br/><b style="color:#005800;">## Response/Common Cookies:</b><br/>'; prr ( $nxs_gCookiesArr ); } if ($dbg && $http_code == 200) { $contentH = htmlentities ( $content ); prr ( $contentH ); } $rURL = ''; if ($http_code == 200 && stripos ( $content, 'http-equiv="refresh" content="0; url='' ) !== false) { $http_code = 301; $rURL = CutFromTo ( $content, 'http-equiv="refresh" content="0; url='', ''"' ); $nxs_gCookiesArr = array (); } elseif ($http_code == 200 && stripos ( $content, 'location.replace' ) !== false) { $http_code = 301; $rURL = CutFromTo ( $content, 'location.replace("', '"' ); } // echo // "~~~~~~~~~~~~~~~~~~~~~~".$rURL."|".$http_code; if ($http_code == 301 || $http_code == 302) { if ($rURL != '') { $rURL = str_replace ( '\x3d', '=', $rURL ); $rURL = str_replace ( '\x26', '&', $rURL ); $url = @parse_url ( $rURL ); } else { $matches = array (); preg_match ( '/Location:(.*?)\n/', $header, $matches ); $url = @parse_url ( trim ( array_pop ( $matches ) ) ); } $rURL = ''; // echo // "#######"; // prr($url); if (! $url) { $curl_loops = 0; return ($ctOnly === true) ? $content : $nsheader; } $last_url = parse_url ( curl_getinfo ( $ch, CURLINFO_EFFECTIVE_URL ) ); if (! $url ['scheme']) $url ['scheme'] = $last_url ['scheme']; if (! $url ['host']) $url ['host'] = $last_url ['host']; if (! $url ['path']) $url ['path'] = $last_url ['path']; if (! isset ( $url ['query'] )) $url ['query'] = ''; $new_url = $url ['scheme'] . '://' . $url ['host'] . $url ['path'] . ($url ['query'] ? '?' . $url ['query'] : ''); curl_setopt ( $ch, CURLOPT_URL, $new_url ); if ($dbg) echo '<br/><b style="color:#005800;">Redirecting to:</b>' . $new_url . "<br/>"; return getCurlPageMC ( $ch, $last_url, $ctOnly, '', $dbg, $advSettings ); } else { $curl_loops = 0; return ($ctOnly === true) ? $content : $nsheader; } }
function nxs_doPublishToKT($postID, $options) { global $nxs_ktCkArray; $ntCd = 'KT'; $ntCdL = 'kt'; $ntNm = 'Kippt'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToDI', array($postID, $options)); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000080">Kippt</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { sleep(5); nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate'); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $link = home_url(); $options['msgFormat'] = 'Test Message from ' . $link; } else { $post = get_post($postID); if (!$post) { return; } $link = get_permalink($postID); $options['msgFrmt'] = nsFormatMessage($options['msgFrmt'], $postID, $addParams); $options['msgTFrmt'] = nsFormatMessage($options['msgTFrmt'], $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); //## Create and Format message $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(',', $tggs); $tags = str_replace(' ', '+', $tags); $message = array('url' => $link, 'surl' => $link, 'siteName' => $blogTitle, 'tags' => $tags); //## Actual Post $ntToPost = new nxs_class_SNAP_KT(); $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. ', 'social-networks-auto-poster-facebook-twitter-g'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToTW($postID, $options) { $ntCd = 'TW'; $ntCdL = 'tw'; $ntNm = 'Twitter'; $img = ''; $imgURL = ''; global $nxs_urlLen; $nxs_urlLen = 0; //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Error', $logNT, 'I am here - '.$ntCd."|".print_r($backtrace, true), ''); //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTW', array($postID, $options)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#00FFFF">Twitter</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $options['pType']); return; } } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $uln = 0; if ($options['attchImg'] == '1') { $imgURL = nxs_getPostImage($postID); if (trim($imgURL) == '') { $options['attchImg'] = 0; } else { if (ini_get('allow_url_fopen')) { if (@getimagesize($imgURL) !== false) { $img = wp_remote_get($imgURL); if ($img['headers']['content-length'] < 200) { $options['attchImg'] = 0; } else { if (is_wp_error($img)) { $options['attchImg'] = 0; } else { $img = $img['body']; } } } else { $options['attchImg'] = 0; } } else { $img = wp_remote_get($imgURL); if (is_wp_error($img)) { $options['attchImg'] = 0; } elseif (isset($img['body']) && trim($img['body']) != '') { $img = $img['body']; } else { $options['attchImg'] = 0; } } } if ($options['attchImg'] == 0) { nxs_addToLogN('E', 'Error', $logNT, 'Could not get image, will post without it', $extInfo); } } if ($options['attchImg'] == '1' && $img != '') { $twLim = 118; } else { $twLim = 140; } if ($postID == '0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from ' . nsTrnc($blogTitle, $twLim - 24) . " - " . rand(1, 155); $uln = nxs_strLen($msg); } else { $post = get_post($postID); if (!$post) { return; } $twMsgFormat = $options['twMsgFormat']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) { $twLim = $twLim - 22; } if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun); $twLim = $twLim - nxs_strLen($aun); } $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl); $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl); $noRepl = str_ireplace("%SURL%", "", $noRepl); $noRepl = str_ireplace("%TEXT%", "", $noRepl); $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl); $noRepl = str_ireplace("%EXCERPT%", "", $noRepl); $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl); $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $twLim = $twLim - nxs_strLen($noRepl); $pTitle = $title = $post->post_title; if ($post->post_excerpt != "") { $exrText = $post->post_excerpt; } else { $exrText = $post->post_content; } $pText = apply_filters('the_content', $exrText); $pRawText = $post->post_content; $pFullText = apply_filters('the_content', $pRawText); if (stripos($twMsgFormat, '%TAGS%') !== false || stripos($twMsgFormat, '%HTAGS%') !== false) { $t = wp_get_object_terms($postID, 'product_tag'); if (empty($t) || is_wp_error($pt) || !is_array($t)) { $t = wp_get_post_tags($postID); } $tggs = array(); foreach ($t as $tagA) { $frmTag = trim(str_replace(' ', '', preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $tagA->name))))))); if (preg_match('/\\b' . $frmTag . '\\b/iu', $pTitle)) { $pTitle = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pTitle)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pFullText)) { $pFullText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pFullText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pText)) { $pText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pRawText)) { $pRawText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pRawText)); } if (stripos($twMsgFormat, '%TITLE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pTitle) || stripos($twMsgFormat, '%TEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%EXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%FULLTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pFullText) || stripos($twMsgFormat, '%RAWTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pRawText)) { } else { $tggs[] = '#' . $frmTag; } } $tags = implode(' ', $tggs); while (count($tags) > $twLim - 10) { array_pop($tggs); $tags = implode(' ', $tggs); } $twMsgFormat = str_ireplace("%TAGS%", $tags, $twMsgFormat); $twMsgFormat = str_ireplace("%HTAGS%", $tags, $twMsgFormat); $twLim = $twLim - nxs_strLen($tags); } if (stripos($twMsgFormat, '%CATS%') !== false || stripos($twMsgFormat, '%HCATS%') !== false) { $t = wp_get_post_categories($postID); $ctts = array(); foreach ($t as $c) { $cat = get_category($c); $frmTag = trim(str_replace(' ', '', str_replace(' ', ' ', str_ireplace('&', '&', trim(ucwords($cat->name)))))); if (stripos($pTitle, $cat->name) !== false) { $pTitle = str_ireplace($cat->name, '#' . $frmTag, $pTitle); } elseif (stripos($pTitle, $frmTag) !== false) { $pTitle = str_ireplace($frmTag, '#' . $frmTag, $pTitle); } if (stripos($pText, $cat->name) !== false) { $pText = str_ireplace($cat->name, '#' . $frmTag, $pText); } elseif (stripos($pText, $frmTag) !== false) { $pText = str_ireplace($frmTag, '#' . $frmTag, $pText); } if (stripos($pFullText, $cat->name) !== false) { $pFullText = str_ireplace($cat->name, '#' . $frmTag, $pFullText); } elseif (stripos($pFullText, $frmTag) !== false) { $pFullText = str_ireplace($frmTag, '#' . $frmTag, $pFullText); } if (stripos($pRawText, $cat->name) !== false) { $pRawText = str_ireplace($cat->name, '#' . $frmTag, $pRawText); } elseif (stripos($pRawText, $frmTag) !== false) { $pRawText = str_ireplace($frmTag, '#' . $frmTag, $pRawText); } if (stripos($twMsgFormat, '%TITLE%') !== false && (stripos($pTitle, $cat->name) !== false || stripos($pTitle, $frmTag) !== false) || stripos($twMsgFormat, '%TEXT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%EXCERPT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && (stripos($exrText, $cat->name) !== false || stripos($exrText, $frmTag) !== false) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%FULLTEXT%') !== false && (stripos($pFullText, $cat->name) !== false || stripos($pFullText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWTEXT%') !== false && (stripos($pRawText, $cat->name) !== false || stripos($pRawText, $frmTag) !== false)) { } else { $ctts[] = '#' . $frmTag; } } $cats = implode(' ', $ctts); while (count($cats) > $twLim - 10) { array_pop($ctts); $cats = implode(' ', $ctts); } $twMsgFormat = str_ireplace("%CATS%", $cats, $twMsgFormat); $twMsgFormat = str_ireplace("%HCATS%", $cats, $twMsgFormat); $twLim = $twLim - nxs_strLen($cats); } if (stripos($twMsgFormat, '%TITLE%') !== false) { if (stripos($pTitle, '.co.uk') !== false) { $twLim = $twLim - 14; } if (stripos($pTitle, '.com') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.net') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.org') !== false) { $twLim = $twLim - 16; } $pTitle = html_entity_decode(strip_tags($pTitle), ENT_NOQUOTES, 'UTF-8'); $pTitle = nsTrnc($pTitle, $twLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($pTitle); } if (stripos($twMsgFormat, '%SITENAME%') !== false) { $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($siteTitle); } if (stripos($twMsgFormat, '%TEXT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%TEXT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%EXCERPT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%RAWEXCERPT%') !== false) { $exrText = nsTrnc(strip_tags(strip_shortcodes($exrText)), 300, " ", "..."); $exrText = nsTrnc($exrText, $twLim); $twMsgFormat = str_ireplace("%RAWEXCERPT%", $exrText, $twMsgFormat); $twLim = $twLim - nxs_strLen($exrText); } if (stripos($twMsgFormat, '%FULLTEXT%') !== false) { $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pFullText); } if (stripos($twMsgFormat, '%RAWTEXT%') !== false) { $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%RAWTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pRawText); } $msg = nsFormatMessage($twMsgFormat, $postID); } $message = array('message' => $msg, 'img' => $img, 'urlLength' => $nxs_urlLen); //## Actual Post $ntToPost = new nxs_class_SNAP_TW(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToDA($postID, $options) { $ntCd = 'DA'; $ntCdL = 'da'; $ntNm = 'deviantART'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">deviantART</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' . ' |' . $uqID); return; } } $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => ''); if ($postID == '0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['url'] = home_url(); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $options['daTitleFormat'] = nsFormatMessage($options['daTitleFormat'], $postID, $addParams); $options['daTextFormat'] = nsFormatMessage($options['daTextFormat'], $postID, $addParams); // prr($options['daTextFormat']); echo $postID; $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); } //## Actual Post $ntToPost = new nxs_class_SNAP_DA(); $ret = $ntToPost->doPostToNT($options, $message); // echo "~~~"; prr($ret); echo "+++"; //## Save Session if (empty($options['ck'])) { $options['ck'] = ''; } if (!empty($ret) && is_array($ret) && !empty($ret['ck']) && !empty($ret['ck']) && serialize($ret['ck']) != $options['ck']) { $options['ck'] = serialize($ret['ck']); $options['mh'] = serialize($ret['mh']); if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions['da'][$ii] = $options; nxs_settings_save($nxs_gOptions); } } //## 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. ', 'social-networks-auto-poster-facebook-twitter-g'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToWP($postID, $options) { $ntCd = 'WP'; $ntCdL = 'wp'; $ntNm = 'WP Based Blog'; global $plgn_NS_SNAutoPoster; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToWP', array($postID, $options)); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#1A9EE6">WP</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { sleep(5); nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $urlToGo = home_url(); $options['wpMsgTFormat'] = 'Test Link from ' . $urlToGo; $options['wpMsgFormat'] = 'Test post please ignore'; } else { $post = get_post($postID); if (!$post) { return; } $link = get_permalink($postID); $options['wpMsgFormat'] = nsFormatMessage($options['wpMsgFormat'], $postID); $options['wpMsgTFormat'] = nsFormatMessage($options['wpMsgTFormat'], $postID); //## MyURL - URLToGo code if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') { $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); } if ($myurl != '') { $options['urlToUse'] = $myurl; } if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else { $urlToGo = get_permalink($postID); } $gOptions = $plgn_NS_SNAutoPoster->nxs_options; $addURLParams = trim($gOptions['addURLParams']); if ($addURLParams != '') { $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addURLParams; } nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(',', $tggs); $postCats = wp_get_post_categories($postID); $cats = array(); foreach ($postCats as $c) { $cat = get_category($c); $cats[] = str_ireplace('&', '&', $cat->name); } // $cats = implode(',',$catsA); $extInfo = ' | PostID: ' . $postID . " - " . (!empty($post) && is_object($post) ? $post->post_title : ''); //## Message & Format if (trim($options['imgToUse']) != '') { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'full'); } $message = array('siteName' => $blogTitle, 'url' => $urlToGo, 'imageURL' => $imgURL, 'tags' => $tags, 'cats' => $cats, 'authorName' => '', 'orID' => $postID); //## Actual Post $ntToPost = new nxs_class_SNAP_WP(); $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. ', 'social-networks-auto-poster-facebook-twitter-g'); } else { do_action('nxs_actOnWP', array('postID' => $postID, 'pgID' => $ret['postID'], 'wpURL' => $options['wpURL'], 'ii' => $ii)); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_snapAjax() { check_ajax_referer('nxsSsPageWPN'); global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) { return; } $options = $plgn_NS_SNAutoPoster->nxs_options; if ($_POST['nxsact'] == 'getNTset') { $ii = $_POST['ii']; $nt = $_POST['nt']; $ntl = strtolower($nt); $pbo = $options[$ntl][$ii]; $pbo['ntInfo']['lcode'] = $ntl; $clName = 'nxs_snapClass' . $nt; $ntObj = new $clName(); $ntObj->showNTSettings($ii, $pbo); } if ($_POST['nxsact'] == 'svEdFlds') { $cn = str_replace(']', '', $_POST['cname']); $cna = explode('[', $cn); prr($cna); $id = $_POST['pid']; $nt = $cna[0]; $ntU = strtoupper($nt); $ii = $cna[1]; $fname = $cna[2]; $savedMeta = maybe_unserialize(get_post_meta($id, 'snap' . $ntU, true)); $savedMeta[$ii][$fname] = $_POST['cval']; prr($savedMeta); delete_post_meta($id, 'snap' . $ntU); add_post_meta($id, 'snap' . $ntU, str_replace('\\', '\\\\', serialize($savedMeta))); } if ($_POST['nxsact'] == 'getNewPostDlg') { nxs_showNewPostForm($options); } if ($_POST['nxsact'] == 'doNewPost') { nxs_doNewNPPost($options); } if ($_POST['nxsact'] == 'nxsCptCheckGP') { nxs_CptCheckGP($options); } die; }
function nxs_cURLTest($url, $msg, $testText) { echo "<br/>--== Test Requested ... " . $url . "<br/>"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); $response = curl_exec($ch); $errmsg = curl_error($ch); $cInfo = curl_getinfo($ch); curl_close($ch); echo "Testing ... " . $url . " - " . $cInfo['url'] . "<br/>"; if (stripos($response, $testText) !== false) { echo "...." . $msg . " - OK<br/>"; } else { echo "....<b style='color:red;'>" . $msg . " - Problem</b><br/>"; prr($response); prr($errmsg); prr($cInfo); echo nxs_cURLTestCode($url); } }
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> <?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'); ?> ==></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> <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 }
function showGenNTSettings($ntOpts) { global $nxs_plurl, $nxs_snapSetPgURL, $nxs_gOptions; $ntInfo = $this->ntInfo; if (isset($_GET['code']) && $_GET['code'] != '' && (isset($_GET['state']) && stripos($_GET['state'], 'ap-') !== false)) { $at = $_GET['code']; $to = explode('-', $_GET['state']); $_GET['acc'] = $to[1]; echo "-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>"; $fbo = $ntOpts[$_GET['acc']]; $wprg = array(); $response = wp_remote_get('https://graph.facebook.com/nextscripts', $wprg); echo $nxs_snapSetPgURL . '&auth=ap&acc=' . $_GET['acc'] . "||"; if (stripos($nxs_snapSetPgURL, 'page=NextScripts_SNAP.php') === false) { $newURL = explode('?', $nxs_snapSetPgURL); $nxs_snapSetPgURL = $newURL[0]; } if (is_wp_error($response) && isset($response->errors['http_request_failed']) && stripos($response->errors['http_request_failed'][0], 'SSL') !== false) { prr($response->errors); $wprg['sslverify'] = false; } if (isset($fbo['appID'])) { echo "-="; prr($fbo); $wprg['body'] = array('client_id' => $fbo['appID'], 'client_secret' => $fbo['appSec'], 'grant_type' => 'authorization_code', 'redirect_uri' => $nxs_snapSetPgURL, 'state' => 'ap-' . $_GET['acc'], 'code' => $at); prr($wprg); $response = wp_remote_post('https://account.app.net/oauth/access_token', $wprg); if (is_object($response) && isset($response->errors) || is_array($response) && stripos($response['body'], '"error":') !== false) { prr($response); die; } $params = json_decode($response['body'], true); $fbo['apAppAuthToken'] = $params['access_token']; if ($params['user_id'] > 0) { $fbo['appAppUserID'] = $params['user_id']; $fbo['appAppUserName'] = $params['username']; } if ($params['user_id'] > 0) { if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions['ap'][$_GET['acc']] = $fbo; nxs_settings_save($nxs_gOptions); } ?> <script type="text/javascript">window.location = "<?php echo $nxs_snapSetPgURL; ?> "</script> <?php } die; } } ?> <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', 'nxs_snap'); echo ")"; ?> </div><?php } ?> </div> </div> <div class="nxs_box_inside"> <?php foreach ($ntOpts as $indx => $pbo) { if (trim($pbo['nName'] == '')) { $pbo['nName'] = 'App.Net'; } if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') { $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['appAppUserID']) && $pbo['appAppUserID'] > 1 ? '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', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if ($pbo['nName'] != '') { echo "(" . $pbo['nName'] . ")"; } ?> </i></strong> <?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'); ?> ==></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', 'nxs_snap'); ?> ]</a> <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><div id="nxsNTSetDiv<?php echo $ntInfo['code'] . $indx; ?> "></div><?php //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo); } ?> </div> </div> <?php }
function nxs_doPublishToSU($postID, $options) { global $nxs_suCkArray; $ntCd = 'SU'; $ntCdL = 'su'; $ntNm = 'StumbleUpon'; //$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_doPublishToSU', array($postID, $options)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000080">StumbleUpon</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['reset'] != '1' && $options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { sleep(5); nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID); return; } } $suCat = $options['suCat']; // if (function_exists("get_post_thumbnail_id") ){ $src = wp_get_attachment_image_src(get_post_thumbnail_id($postID), 'thumbnail'); $src = $src[0];} $email = $options['suUName']; $pass = substr($options['suPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['suPass'], 5)) : $options['suPass']; if ($postID == '0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msg = 'Test Link from ' . $link; } else { $post = get_post($postID); if (!$post) { return; } $msgFormat = $options['suMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID); $link = get_permalink($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $dusername = $options['suUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500)); $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; if ($options['suInclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = urlencode(implode(',', $tggs)); $tags = str_replace(' ', '+', $tags); } else { $tags = ''; } if (isset($options['suSvC'])) { $nxs_suCkArray = maybe_unserialize($options['suSvC']); } $loginError = true; if (is_array($nxs_suCkArray)) { $loginError = nxs_doCheckSU(); } if ($loginError != false) { $loginError = nxs_doConnectToSU($email, $pass); } if (serialize($nxs_suCkArray) != $options['suSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; if (isset($options['ii']) && $options['ii'] !== '') { $gOptions['su'][$options['ii']]['suSvC'] = serialize($nxs_suCkArray); update_option('NS_SNAutoPoster', $gOptions); } else { foreach ($gOptions['su'] as $ii => $gpn) { $result = array_diff($options, $gpn); if (!is_array($result) || count($result) < 1) { $gOptions['su'][$ii]['suSvC'] = serialize($nxs_suCkArray); update_option('NS_SNAutoPoster', $gOptions); break; } } } } if ($loginError !== false) { if ($postID == '0') { prr($loginError); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($loginError, true) . " - BAD USER/PASS", $extInfo); return " -= BAD USER/PASS =- "; } $ret = nxs_doPostToSU($msg, $link, $options['suCat'], $tags, $options['nsfw'] == '1'); // $extInfo .= "++".$msg."|".$link."|".$options['suCat']."|".$tags."|".$options['nsfw']; if ($ret == 'OK') { $ret = array("code" => "OK", "post_id" => ''); } if (!is_array($ret) && $ret != 'OK') { if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } elseif ($ret['code'] == 'OK') { if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo ' OK - Message Posted, please see your StumbleUpon Page '; } else { nxs_metaMarkAsPosted($postID, 'SU', $options['ii'], array('isPosted' => '1', 'pgID' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); return 200; } } else { if ($options['reset'] == '1') { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR TRY #2=- ' . print_r($ret, true), $extInfo . $options['reset']); return "ERROR = " . print_r($ret, true); } else { $options['reset'] = '1'; $options['suSvC'] = ''; return nxs_doPublishToSU($postID, $options); } } }
function nxs_cURLTest($url, $msg, $testText) { echo "<br/>--== Test Requested ... " . $url . "<br/>"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.39 Safari/537.36"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); $response = curl_exec($ch); $errmsg = curl_error($ch); $cInfo = curl_getinfo($ch); curl_close($ch); echo "Testing ... " . $url . " - " . $cInfo['url'] . "<br/>"; if (stripos($response, $testText) !== false) { echo "...." . $msg . " - OK<br/>"; } else { echo "....<b style='color:red;'>" . $msg . " - Problem</b><br/>"; prr($response); prr($errmsg); prr($cInfo); echo nxs_cURLTestCode($url); } }
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('&', '&', $msgT); $msgT = utf8_encode(str_ireplace('&', '&', $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; } }
$numChecks = count($checks); echo '<div style="font-family:\'Open Sans\',sans-serif;font-size: 15px;">'; if ($cr['cronCheckStartTime'] + 900 > time()) { echo "<b>Cron Check is in Progress.....</b> will be finished in " . ($cr['cronCheckStartTime'] + 900 - time()) . ' seconds. Please <input type="button" value="Reload" onClick="location.reload()"> this page to see more results.... <br/><br/>'; } else { echo "Cron Check Results:<br/>"; echo '<span style="color:#761616"> ==== Cron was executed <b>' . $numChecks . '</b> times in 15 minutes ===</span>'; if ($numChecks > 15 || $numChecks < 2) { echo '<b style="color:#FF0000"><br/><br/>Your WP Cron is not healthy</b><br/><br/><span style="color:#761616">' . ($numChecks > 15 ? 'WP Cron should NOT be executed more then once per minute.' : 'WP Cron should be executed at least once in 5-10 minutes.') . ' Some functionality (like auto-reposting) will be disabled.</span><br/><br/><span style="color:#005858; font-weight:bold;">Why this is important?</span><br/><span style="color:#005858">Please see this post: <a href="http://www.nextscripts.com/blog/troubles-wp-cron-existing-posts-auto-reposter/" target="_blank">Troubles with WP Cron and existing posts auto-reposter</a></span><br/><br/><span style="color:#005858; font-weight:bold;">Solution</span><br/><span style="color:#005858">Please see the instructions for the correct WP Cron setup: <a href="http://www.nextscripts.com/tutorials/wp-cron-scheduling-tasks-in-wordpress/" target="_blank">WP-Cron: Scheduling Tasks in WordPress</a></span>'; } else { echo '<b style="color:#0000FF"><br/><br/>Your WP Cron is OK</b>'; } } ?> <br/><br/><span style="color:#000058; font-weight:normal;">Technical Info:</span> <?php prr($cr); ?> ==== <a href="<?php echo $nxs_snapThisPageUrl; ?> &do=crtest&redo=1">Re-do Cron Check</a> (it will take 15 minutes to complete)<?php } else { echo 'Check is not started yet... Please <input type="button" value="Reload" onClick="location.reload()"> this page in couple minutes.'; } echo '</div>'; die; } //## Delete Account if (!function_exists("ns_delNT_ajax")) { function ns_delNT_ajax() {
function nxs_doPublishToVB($postID, $options) { global $nxs_vbCkArray, $plgn_NS_SNAutoPoster; $ntCd = 'VB'; $ntCdL = 'vb'; $ntNm = 'vBulletin'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToVB', array($postID, $options)); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#000080">vBulletin</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { sleep(5); nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $urlToGo = home_url(); $options['vbMsgFormat'] = 'Test Message from ' . $urlToGo; $options['vbMsgTFormat'] = 'Test Link from ' . $urlToGo; } else { $post = get_post($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $options['vbMsgFormat'] = nsFormatMessage($options['vbMsgFormat'], $postID, $addParams); $options['vbMsgTFormat'] = nsFormatMessage($options['vbMsgTFormat'], $postID, $addParams); //## MyURL - URLToGo code if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') { $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); } if ($myurl != '') { $options['urlToUse'] = $myurl; } if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else { $urlToGo = get_permalink($postID); } $gOptions = $plgn_NS_SNAutoPoster->nxs_options; $addURLParams = trim($gOptions['addURLParams']); if ($addURLParams != '') { $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addURLParams; } } $dusername = $options['vbUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500)); $extInfo = ' | PostID: ' . $postID . " - " . (!empty($post) && is_object($post) ? $post->post_title : ''); //## Message & Format if ($options['vbInclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode(', ', $tggs); /* $tags = str_replace(' ','+',$tags); */ } else { $tags = ''; } $message = array('siteName' => $blogTitle, 'tags' => $tags); //## Actual Post $ntToPost = new nxs_class_SNAP_VB(); $ret = $ntToPost->doPostToNT($options, $message); //## Save Session if (empty($options['vkSvC']) || serialize($nxs_vbCkArray) != $options['vbSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; if (isset($options['ii']) && $options['ii'] !== '') { $gOptions['vb'][$options['ii']]['vbSvC'] = serialize($nxs_vbCkArray); update_option('NS_SNAutoPoster', $gOptions); } else { foreach ($gOptions['vb'] as $ii => $gpn) { $result = array_diff($options, $gpn); if (!is_array($result) || count($result) < 1) { $gOptions['vb'][$ii]['vbSvC'] = serialize($nxs_vbCkArray); update_option('NS_SNAutoPoster', $gOptions); break; } } } } //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
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('&', '', $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('&','&',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('&', '', $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('&', '', $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('&#039;', "'", $msg); $msg = str_replace(''', "'", $msg); $msg = str_replace('#039;', "'", $msg); $msg = str_replace('#039', "'", $msg); $msg = str_replace('&#8217;', "'", $msg); $msg = str_replace('’', "'", $msg); $msg = str_replace('#8217;', "'", $msg); $msg = str_replace('#8217', "'", $msg); $msg = str_replace('&#8220;', '"', $msg); $msg = str_replace('“', '"', $msg); $msg = str_replace('#8220;', '"', $msg); $msg = str_replace('#8220', "'", $msg); $msg = str_replace('&#8221;', '"', $msg); $msg = str_replace('”', '"', $msg); $msg = str_replace('#8221;', '"', $msg); $msg = str_replace('#8221', "'", $msg); $msg = str_replace('&#8212;', '-', $msg); $msg = str_replace('—', '-', $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); } }
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; }
function nxs_doPublishToGP($postID, $options) { $ntCd = 'GP'; $ntCdL = 'gp'; $ntNm = 'Google+'; if (!function_exists('doConnectToGooglePlus2') || !function_exists('doPostToGooglePlus2')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No G+ API Lib Detected', ''); return "No G+ API Lib Detected"; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">Google+</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' . ' |' . $uqID); return; } } $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => ''); if ($postID == '0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['link'] = home_url(); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $gpMsgFormat = $options['gpMsgFormat']; $gpPostType = $options['postType']; $msg = nsFormatMessage($gpMsgFormat, $postID); // prr($msg); echo $postID; $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; if ($gpPostType == 'I') { $vids = nsFindVidsInPost($post, false); if (count($vids) > 0) { $ytCode = $vids[0]; } if (trim($ytCode) == '') { $options['trPostType'] = 'T'; } } if ($gpPostType == 'A') { $imgURL = nxs_getPostImage($postID, 'medium'); } if ($gpPostType == 'I') { $imgURL = nxs_getPostImage($postID, 'full'); } $message = array('message' => $msg, 'link' => get_permalink($postID), 'imageURL' => $imgURL, 'videoCode' => $ytCode); } //## Actual Post $ntToPost = new nxs_class_SNAP_GB(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToBG($postID, $options) { $ntCd = 'BG'; $ntCdL = 'bg'; $ntNm = 'Blogger'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), ''); // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToBG', array($postID, $options)); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'ACCNAME' => $options['nName'], 'POSTID' => $postID)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#F87907">' . $ntNm . '</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate'); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $options['bgMsgTFormat'] = 'Test Post from ' . htmlentities($blogTitle); $link = home_url(); $options['bgMsgFormat'] = 'Test Post from ' . $blogTitle . " " . $link; } else { $post = get_post($postID); if (!$post) { return; } $options['bgMsgFormat'] = nsFormatMessage($options['bgMsgFormat'], $postID, $addParams); $options['bgMsgTFormat'] = nsFormatMessage($options['bgMsgTFormat'], $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); } $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : ''); //## Actual POST Code if ($options['bgInclTags'] == '1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $tggs[] = $tagA->name; } $tags = implode('","', $tggs); $tags = nsTrnc($tags, 195, ',', ''); } if (substr($tags, -1) == '"') { $tags = substr($tags, 0, -1); } if (substr($tags, -1) == ',') { $tags = substr($tags, 0, -1); } if (substr($tags, -1) == '"') { $tags = substr($tags, 0, -1); } //## Set Message $message = array('title' => '', 'announce' => '', 'text' => '', 'url' => '', 'surl' => '', 'urlDescr' => '', 'urlTitle' => '', 'imageURL' => array(), 'videoCode' => '', 'videoURL' => '', 'siteName' => $blogTitle, 'tags' => $tags, 'cats' => '', 'authorName' => ''); //## Actual Post $ntToPost = new nxs_class_SNAP_BG(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToRD($postID, $options) { $ntCd = 'RD'; $ntCdL = 'rd'; $ntNm = 'Reddit'; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">Reddit</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); 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; } } $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => ''); if ($postID == '0') { echo "Testing ... <br/><br/>"; $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['url'] = home_url(); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $rdPostType = $options['postType']; $options['rdTitleFormat'] = nsFormatMessage($options['rdTitleFormat'], $postID); $options['rdTextFormat'] = nsFormatMessage($options['rdTextFormat'], $postID); // prr($msg); echo $postID; $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title; $options = nxs_getURL($options, $postID, $addParams); $urlToGo = $options['urlToUse']; $message = array('message' => $options['rdTextFormat'], 'url' => $urlToGo, 'title' => $options['rdTitleFormat']); } //## Actual Post $ntToPost = new nxs_class_SNAP_RD(); $ret = $ntToPost->doPostToNT($options, $message); // echo "~~~"; prr($ret); echo "+++"; //## 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. ', 'social-networks-auto-poster-facebook-twitter-g'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToYT($postID, $options) { $ntCd = 'YT'; $ntCdL = 'yt'; $ntNm = 'YouTube'; $post = ''; global $nxs_gCookiesArr; $vUrl = ''; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } // $backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), ''); //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToYT', array($postID, $options)); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } if (empty($options['ytGPPageID'])) { $options['ytGPPageID'] = ''; } // if (empty($options['imgSize'])) $options['imgSize'] = ''; if (!function_exists('doConnectToGooglePlus2') || !function_exists('doPostToGooglePlus2')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No G+ API Lib Detected', ''); return "No G+ API Lib Detected"; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#800000">YouTube</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { sleep(5); nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID); return; } } if ($postID == '0') { $options['ytMsgFormat'] = 'Test Post, Please Ignore'; } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $post = get_post($postID); if (!$post) { return; } $options['ytMsgFormat'] = nsFormatMessage($options['ytMsgFormat'], $postID, $addParams); // prr($msg); echo $postID; } $extInfo = ' | PostID: ' . $postID . " - " . (is_object($post) ? $post->post_title : ''); //## Message & Format $vids = nsFindVidsInPost($post); if (count($vids) > 0) { $vUrl = $vids[0]; } $message = array('siteName' => $blogTitle, 'videoURL' => $vUrl); //## Actual Post $ntToPost = new nxs_class_SNAP_YT(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function showGenNTSettings($ntOpts) { global $nxs_snapSetPgURL, $nxs_plurl; $ntInfo = array('code' => 'FB', 'lcode' => 'fb', 'name' => 'Facebook', 'defNName' => 'dlUName', 'tstReq' => true); if (isset($_GET['code']) && $_GET['code'] != '' && isset($_GET['state']) && substr($_GET['state'], 0, 7) == 'nxs-fb-') { $at = $_GET['code']; $ii = str_replace('nxs-fb-', '', $_GET['state']); echo "-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>"; $gGet = array(); if (!empty($_SERVER['QUERY_STRING'])) { parse_str($_SERVER['QUERY_STRING'], $gGet); } elseif (!empty($_SERVER['argv'][0])) { parse_str($_SERVER['argv'][0], $gGet); } else { $gGet = $_GET; prr($_GET); unset($gGet['post_type']); } prr($gGet); unset($gGet['code']); unset($gGet['state']); prr($gGet); $sturl = explode('?', $nxs_snapSetPgURL); $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : ''); $fbo = $ntOpts[$ii]; $wprg = array(); $response = wp_remote_get('https://graph.facebook.com/nextscripts', $wprg); if (is_wp_error($response) && isset($response->errors['http_request_failed']) && stripos($response->errors['http_request_failed'][0], 'SSL') !== false) { prr($response->errors); $wprg['sslverify'] = false; } if (isset($fbo['fbPgID'])) { echo "-="; prr($fbo); // die(); $tknURL = 'https://graph.facebook.com/oauth/access_token?client_id=' . $fbo['fbAppID'] . '&state=nxs-fb-' . $ii . '&redirect_uri=' . urlencode($nxs_snapSetPgURL) . '&client_secret=' . $fbo['fbAppSec'] . '&code=' . $at; $response = wp_remote_get($tknURL, $wprg); prr($tknURL); if (is_object($response) && isset($response->errors) || is_array($response) && stripos($response['body'], '"error":') !== false) { prr($response); die; } parse_str($response['body'], $params); $at = $params['access_token']; prr($response); prr($params); $response = wp_remote_get('https://graph.facebook.com/oauth/access_token?client_secret=' . $fbo['fbAppSec'] . '&client_id=' . $fbo['fbAppID'] . '&grant_type=fb_exchange_token&fb_exchange_token=' . $at, $wprg); if (is_object($response) && isset($response->errors)) { prr($response); die; } parse_str($response['body'], $params); $at = $params['access_token']; $fbo['fbAppAuthToken'] = $at; $appsecret_proof = hash_hmac('sha256', $fbo['fbAppAuthToken'], $fbo['fbAppSec']); $aacct = array('access_token' => $fbo['fbAppAuthToken'], 'appsecret_proof' => $appsecret_proof, 'method' => 'get'); $res = wp_remote_get("https://graph.facebook.com/me?" . http_build_query($aacct, null, '&')); if (is_wp_error($res) || empty($res['body'])) { echo "Can't get Facebook User."; prr($res); die; } else { $user = json_decode($res['body'], true); if (empty($user)) { echo "Can't get Facebook User. JSON Error. "; prr($res); die; } else { if (!empty($user['id'])) { echo "-= Got user: "******"-= Authorizing Page =-"; if (!is_numeric($page_id) && stripos($fbo['fbURL'], '/groups/') != false) { //$fbPgIDR = wp_remote_get('nxs.php?g='.$fbo['fbURL']); // TODO - how to replace $fbPgIDR = trim($fbPgIDR['body']); $page_id = $fbPgIDR != '' ? $fbPgIDR : $page_id; } $aacct = array('access_token' => $fbo['fbAppAuthToken'], 'appsecret_proof' => $appsecret_proof, 'method' => 'get'); $fbo['destType'] = ''; echo "https://graph.facebook.com/{$page_id}?fields=access_token&" . http_build_query($aacct, null, '&'); $res = wp_remote_get("https://graph.facebook.com/{$page_id}?fields=access_token&" . http_build_query($aacct, null, '&')); prr($res); if (is_wp_error($res) || empty($res['body'])) { echo "Can't get Page Token."; prr($res); die; } else { $token = json_decode($res['body'], true); if (empty($token)) { echo "Can't get Page Token. JSON Error. "; prr($res); die; } else { if (!empty($token['error'])) { if (!empty($token['error']['message'])) { $errMsg = $token['error']['message']; if (stripos($errMsg, 'Unknown fields: access_token') !== false || stripos($errMsg, 'Cannot query users by their username') !== false || stripos($errMsg, 'node type (User)') !== false) { $token['access_token'] = $fbo['fbAppAuthToken']; $fbo['destType'] = stripos($fbo['fbURL'], '/groups/') != false ? 'gr' : 'pr'; } else { if (stripos($errMsg, 'Unsupported get request') !== false) { echo "<b style='color:red;'>Error </b>: Your Facebook URL ( <i>" . $fbo['fbURL'] . "</i> ) is either incorrect or authorzing user don't have rights to post there.<br/>"; } echo '<br/>Reported Error: ', $errMsg, "\n"; die; } } } if (!empty($token['access_token'])) { $fbo['fbAppPageAuthToken'] = $token['access_token']; } else { echo "Can't get Page Token. NO TOKEN RETURNED. Are you sure that user you are trying to authorize is an admin of the page? This message means user was authorized as profile, but page refused to return authorization token. This usually happens when user has <b>no rights</b> to post to that page. "; prr($res); die; } } } } else { echo "Can't get User. NO USER RETURNED. "; prr($res); die; } } } if (!empty($user['id'])) { $fbo['fbAppAuthUser'] = $user['id']; $fbo['fbAppAuthUserName'] = $user['name'] . (!empty($user['username']) ? " (" . $user['username'] . ")" : ''); if (function_exists('get_option')) { $nxs_gOptions = get_option('NS_SNAutoPoster'); } if (!empty($nxs_gOptions)) { $nxs_gOptions['fb'][$ii] = $fbo; nxs_settings_save($nxs_gOptions); } ?> <script type="text/javascript">window.location = "<?php echo $nxs_snapSetPgURL; ?> "</script> <?php } die; } } $ntParams = array('ntInfo' => $ntInfo, 'nxs_plurl' => $nxs_plurl, 'ntOpts' => $ntOpts, 'chkField' => 'fbAppAuthUser'); nxs_showListRow($ntParams); }
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> <?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'); ?> ==></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'); ?> ==></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> <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 nxs_doPublishToPN($postID, $options) { global $nxs_gCookiesArr, $plgn_NS_SNAutoPoster; $ntCd = 'PN'; $ntCdL = 'pn'; $ntNm = 'Pinterest'; $price = ''; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } // $backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), ''); //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPN', array($postID, $options)); $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } if (empty($options['imgToUse'])) { $options['imgToUse'] = ''; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } if (empty($options['cImgURL'])) { $options['cImgURL'] = 'R'; } $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#FA5069">Pinterest</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); $isAttachVid = $options['isAttachVid']; if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { sleep(5); nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate |' . $uqID); return; } } if ($postID == '0') { echo "Testing ... <br/><br/>"; $options['pnMsgFormat'] = 'Test Post from ' . $blogTitle; $urlToGo = home_url(); if ($options['pnDefImg'] != '') { $imgURL = $options['pnDefImg']; } else { $imgURL = "http://direct.gtln.us/img/nxs/NXS-Lama.jpg"; } } else { $post = get_post($postID); if (!$post) { return; } $options['pnMsgFormat'] = nsFormatMessage($options['pnMsgFormat'], $postID, $addParams); //## MyURL - URLToGo code if (!isset($options['urlToUse']) || trim($options['urlToUse']) == '') { $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); } if ($myurl != '') { $options['urlToUse'] = $myurl; } if (isset($options['urlToUse']) && trim($options['urlToUse']) != '') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else { $urlToGo = get_permalink($postID); } if ($addParams != '') { $urlToGo .= (strpos($urlToGo, '?') !== false ? '&' : '?') . $addParams; } if (is_object($post)) { $urlToGo = apply_filters('nxs_adjust_ex_url', $urlToGo, $post->post_content); } if (!empty($options['imgToUse'])) { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID, 'full', $options['pnDefImg']); } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; } if ($isAttachVid == '1') { $vids = nsFindVidsInPost($post); if (count($vids) > 0) { $vidURL = 'http://www.youtube.com/v/' . $vids[0]; $imgURL = 'http://img.youtube.com/vi/' . $vids[0] . '/0.jpg'; } } $extInfo = ' | PostID: ' . $postID . " - " . is_object($post) ? $post->post_title : ''; } if ($options['cImgURL'] == 'S') { $options['cImgURL'] = 'R'; } //## Pinterest no longer allows shorthened URLs. //## Post $message = array('siteName' => $blogTitle, 'tags' => '', 'url' => $urlToGo, 'imageURL' => $imgURL); // prr($message); //## Actual Post $ntToPost = new nxs_class_SNAP_PN(); $ret = $ntToPost->doPostToNT($options, $message); //## Save Session if (serialize($nxs_gCookiesArr) != $options['ck']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; // prr($gOptions['pn']); if (isset($options['ii']) && $options['ii'] !== '') { $gOptions['pn'][$options['ii']]['ck'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); } else { foreach ($gOptions['pn'] as $ii => $gpn) { $result = array_diff($options, $gpn); if (!is_array($result) || count($result) < 1) { $gOptions['pn'][$ii]['ck'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); break; } } } } //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], '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); } } //prr($ret); //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }