Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php
+++ b/social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php
@@ -2,31 +2,108 @@
/*
Plugin Name: NextScripts: Social Networks Auto-Poster
Plugin URI: https://www.nextscripts.com/social-networks-auto-poster-for-wordpress
-Description: This plugin automatically publishes posts from your blog to your social media accounts on Twitter, FB, Telegram, LinkedIn, and 25 more networks.
+Description: This plugin automatically publishes posts from your blog to your social media accounts on X/Twitter, Facebook, Telegram, LinkedIn, and more networks.
Author: NextScripts
-Version: 4.4.8
+Version: 4.5.1
Author URI: https://www.nextscripts.com
Text Domain: social-networks-auto-poster-facebook-twitter-g
Copyright 2012-2026 NextScripts Corp
*/
-const NextScripts_SNAP_Version = '4.4.8'; const NextScripts_SNAP_Version_Date = 'Aug 12, 2026';
+const NextScripts_SNAP_Version = '4.5.1'; const NextScripts_SNAP_Version_Date = 'Nov 17, 2026';
require_once "inc/nxs_functions_wp.php"; if(!defined( 'NXSSNAP_BASENAME' ) ) define( 'NXSSNAP_BASENAME', plugin_basename( __FILE__ ) );
if (true===nxs_doSystemInitCheck()) { // error_reporting(E_ALL); ini_set('display_errors', '1');
-// $vb = get_site_option('_nxs_v5b', 0); if ($vb==1) require_once "src/smsync.php"; //## V5 Beta
- require_once "inc/nxs_functions.php"; require_once "inc/nxs_functions_adv.php"; require_once "inc/nxs_functions_engine.php"; require_once "inc/nxs_class_http.php"; require_once "inc/nxs_class_addns.php";
+ require_once "inc/nxs_functions.php"; require_once "inc/nxs_functions_adv.php"; require_once "inc/nxs_functions_ext.php"; require_once "inc/nxs_functions_engine.php"; require_once "inc/nxs_class_http.php"; require_once "inc/nxs_class_addns.php";
require_once "inc/nxs_class_snap.php"; require_once "inc/nxs_class_flt.php"; require_once "inc/nxs_class_mgmt.php"; require_once "inc/nxs_class_ntlist.php"; require_once "inc/nxs_class_oauth.php";
add_filter('get_post_metadata', 'nxs_safe_post_metadata', 10, 5);
- add_filter('is_protected_meta', function($protected, $meta_key, $meta_type){ return $meta_type === 'post' && preg_match('/^(?:snap|_snap|nxs_|_nxs_)/i', (string)$meta_key) ? true : $protected; }, 10, 3);
+ add_filter('is_protected_meta', function($protected,$meta_key,$meta_type){return $meta_type==='post'&&preg_match('/^(?:snap|_snap|nxs_|_nxs_)/i',(string)$meta_key)?true:$protected;},10,3);
//## Some Globals and Constants
global $nxs_snapAvNts, $nxs_SNAP, $nxs_snapSetPgURL, $nxs_snapThisPageUrl; $nxs_snapSetPgURL = nxs_get_admin_url('admin.php?page=nxssnap');
- $nxs_current_page = isset($_GET['page']) ? sanitize_key(wp_unslash($_GET['page'])) : 'nxssnap'; $nxs_snapThisPageUrl = esc_url_raw(add_query_arg('page', $nxs_current_page, nxs_get_admin_url('admin.php')));
+ $nxs_current_page=isset($_GET['page'])?sanitize_key(wp_unslash($_GET['page'])):'nxssnap'; $nxs_snapThisPageUrl=esc_url_raw(add_query_arg('page',$nxs_current_page,nxs_get_admin_url('admin.php')));
define( 'NXS_PLPATH', plugin_dir_path(__FILE__) ); define( 'NXS_PLURL', plugin_dir_url(__FILE__)); define( 'NXS_SETV', 350); global $nxs_plurl; $nxs_plurl = NXS_PLURL; // Remove once networks upgraded
- //## Get Available Networks
+ require_once NXS_PLPATH . 'inc/nxs_postsocial.php';
+ require_once NXS_PLPATH . 'inc/nxs_meta_direct.php';
+ //## Register Autoloader for Dynamic Network Class Loading
+ spl_autoload_register(function ($class_name) {
+ if (preg_match('/^nxs_snapClass([A-Z0-9]+)$/', $class_name, $matches)) {
+ $lcode = strtolower($matches[1]);
+ $file = NXS_PLPATH . 'inc-cl/' . $lcode . '.php';
+ if (file_exists($file)) { require_once $file; }
+ } elseif (preg_match('/^nxs_class_SNAP_([A-Z0-9]+)$/', $class_name, $matches)) {
+ $lcode = strtolower($matches[1]);
+ $file = NXS_PLPATH . 'inc-cl/' . $lcode . '.api.php';
+ if (file_exists($file)) { require_once $file; }
+ } elseif (preg_match('/^nxsAPI_([A-Z0-9]+)_Native$/', $class_name, $matches)) {
+ $lcode = strtolower($matches[1]);
+ $file = NXS_PLPATH . 'inc-cl/' . $lcode . '.php';
+ if (file_exists($file)) { require_once $file; }
+ } elseif (preg_match('/^nxsAPI_([A-Z0-9]+)$/', $class_name, $matches)) {
+ $lcode = strtolower($matches[1]);
+ $file = NXS_PLPATH . 'inc-cl/' . $lcode . '.api.php';
+ if (file_exists($file)) { require_once $file; }
+ }
+ });
+
+ //## Get Available Networks (Dynamically Registered instead of filesystem globbing)
do_action('nxs_actBeforeGetAvNetworks');
- if (!isset($nxs_snapAvNts) || !is_array($nxs_snapAvNts)) $nxs_snapAvNts = array(); $nxs_snapAPINts = array(); $nxs_avlblNTList = array();
- foreach (glob(NXS_PLPATH.'inc-cl/*.php') as $filename){ require_once $filename; $filename = explode('/', $filename); $filename = array_pop($filename); }
+ $nxs_snapAvNts = array(
+ array('code'=>'BS', 'lcode'=>'bs', 'name'=>'Bluesky', 'type'=>'Social Networks', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Publish text and images to Bluesky directly with an App Password or through Post.Social'),
+ array('code'=>'BG', 'lcode'=>'bg', 'name'=>'Blogger', 'type'=>'Blogs/Publishing Platforms', 'ptype'=>'B', 'status'=>'A', 'desc'=>'Autopost to your blog. HTML is supported'),
+ array('code'=>'DA', 'lcode'=>'da', 'name'=>'deviantART (!)', 'type'=>'Image Sharing', 'ptype'=>'F', 'status'=>'B', 'desc'=>'Autopost to your blog. HTML is supported'),
+ array('code'=>'DI', 'lcode'=>'di', 'name'=>'Diigo', 'type'=>'Link Sharing/Boormarks', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Auto-submit bookmark to your account'),
+ array('code'=>'FB', 'lcode'=>'fb', 'name'=>'Facebook', 'type'=>'Social Networks', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Publish to a Facebook Page using your own app or Post.Social'),
+ array('code'=>'FL', 'lcode'=>'fl', 'name'=>'Flickr', 'type'=>'Image Sharing', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Autopost images to your photostream and/or sets. Tags are supported'),
+ array('code'=>'GMB', 'lcode'=>'gmb', 'name'=>'Google Business Profile', 'type'=>'Blogs/Publishing Platforms', 'ptype'=>'P', 'status'=>'A', 'desc'=>'Create a Google Business Profile post'),
+ array('code'=>'IG', 'lcode'=>'ig', 'name'=>'Instagram', 'type'=>'Social Networks', 'ptype'=>'P', 'status'=>'A', 'desc'=>"Upload your blogpost's image to your Instagram account."),
+ array('code'=>'IP', 'lcode'=>'ip', 'name'=>'Instapaper', 'type'=>'Blogs/Publishing Platforms', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Autopost to your account'),
+ array('code'=>'LI', 'lcode'=>'li', 'name'=>'LinkedIn', 'type'=>'Social Networks', 'ptype'=>'B', 'status'=>'A', 'desc'=>'Publish to your profile or company page using your own app or Post.Social'),
+ array('code'=>'LJ', 'lcode'=>'lj', 'name'=>'LiveJournal', 'type'=>'Blogs/Publishing Platforms', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Auto-submit your blogpost to LiveJournal blog or community. LiveJournal engine based website DreamWidth.org is also supported'),
+ array('code'=>'LN', 'lcode'=>'ln', 'name'=>'Line', 'type'=>'Messengers', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Autopost texts, images, or links to your channel, group or chat'),
+ array('code'=>'MC', 'lcode'=>'mc', 'name'=>'MailChimp', 'type'=>'Email Marketing', 'ptype'=>'F', 'status'=>'A', 'desc'=>'One of the most popular email marketing tools. You can send your blogposts as email campaigns to specific subscribers'),
+ array('code'=>'MD', 'lcode'=>'md', 'name'=>'Medium', 'type'=>'Blogs/Publishing Platforms', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Autopost to your profile or publications'),
+ array('code'=>'OK', 'lcode'=>'ok', 'name'=>'ok.ru', 'type'=>'Social Networks', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Autopost text, image or share a link to your profile or group'),
+ array('code'=>'PN', 'lcode'=>'pn', 'name'=>'Pinterest', 'type'=>'Social Networks', 'ptype'=>'P', 'status'=>'A', 'desc'=>"Post your blogpost's image to your Pinterest board."),
+ array('code'=>'RD', 'lcode'=>'rd', 'name'=>'Reddit', 'type'=>'Link Sharing/Boormarks', 'ptype'=>'P', 'status'=>'A', 'desc'=>'Autopost to your subreddits'),
+ array('code'=>'SC', 'lcode'=>'sc', 'name'=>'Scoop.It', 'type'=>'Blogs/Publishing Platforms', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Autopost to your "Topics". Ability to attach your blogpost to scoop. Ability to make "Image" posts'),
+ array('code'=>'TG', 'lcode'=>'tg', 'name'=>'Telegram', 'type'=>'Messengers', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Autopost texts, images, or links to your channel, group or chat'),
+ array('code'=>'TH', 'lcode'=>'th', 'name'=>'Threads', 'type'=>'Social Networks', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Publish text and image posts to Threads through Post.Social or your own Threads app.'),
+ array('code'=>'TR', 'lcode'=>'tr', 'name'=>'Tumblr', 'type'=>'Blogs/Publishing Platforms', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Create text, image, audio-link or video-link posts on your Tumblr blog.'),
+ array('code'=>'TW', 'lcode'=>'tw', 'name'=>'X/Twitter', 'type'=>'Social Networks', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Autopost to your account. Ability to attach images'),
+ array('code'=>'VB', 'lcode'=>'vb', 'name'=>'vBulletin', 'type'=>'Forums', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Auto-submit your blogpost to vBulletin forums. Could create new threads or new posts'),
+ array('code'=>'VK', 'lcode'=>'vk', 'name'=>'VK.Com', 'type'=>'Social Networks', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Post text, image or share a link to your profile or group page'),
+ array('code'=>'WB', 'lcode'=>'wb', 'name'=>'Weibo', 'type'=>'Social Networks', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Biggest Chinese Microblogging Service. You can post your messages and images'),
+ array('code'=>'WP', 'lcode'=>'wp', 'name'=>'WP Based Blog', 'type'=>'Blogs/Publishing Platforms', 'ptype'=>'F', 'status'=>'A', 'desc'=>'Auto-submit your blogpost to another WordPress based site. Support for any standalone WordPress and WordPress.com, Blog.com, etc..')
+ );
+ $nxs_snapAPINts = array(
+ array('code'=>'BS', 'lcode'=>'bs', 'name'=>'Bluesky'),
+ array('code'=>'BG', 'lcode'=>'bg', 'name'=>'Blogger'),
+ array('code'=>'DA', 'lcode'=>'da', 'name'=>'deviantART'),
+ array('code'=>'DI', 'lcode'=>'di', 'name'=>'Diigo'),
+ array('code'=>'FB', 'lcode'=>'fb', 'name'=>'Facebook'),
+ array('code'=>'FL', 'lcode'=>'fl', 'name'=>'Flickr'),
+ array('code'=>'GMB', 'lcode'=>'gmb', 'name'=>'Google Business Profile'),
+ array('code'=>'IG', 'lcode'=>'ig', 'name'=>'Instagram'),
+ array('code'=>'IP', 'lcode'=>'ip', 'name'=>'Instapaper'),
+ array('code'=>'LI', 'lcode'=>'li', 'name'=>'LinkedIn'),
+ array('code'=>'LJ', 'lcode'=>'lj', 'name'=>'LiveJournal'),
+ array('code'=>'LN', 'lcode'=>'ln', 'name'=>'Line'),
+ array('code'=>'MC', 'lcode'=>'mc', 'name'=>'MailChimp'),
+ array('code'=>'MD', 'lcode'=>'md', 'name'=>'Medium'),
+ array('code'=>'OK', 'lcode'=>'ok', 'name'=>'ok.ru'),
+ array('code'=>'PN', 'lcode'=>'pn', 'name'=>'Pinterest'),
+ array('code'=>'RD', 'lcode'=>'rd', 'name'=>'Reddit'),
+ array('code'=>'SC', 'lcode'=>'sc', 'name'=>'Scoop.It'),
+ array('code'=>'TG', 'lcode'=>'tg', 'name'=>'Telegram'),
+ array('code'=>'TH', 'lcode'=>'th', 'name'=>'Threads'),
+ array('code'=>'TR', 'lcode'=>'tr', 'name'=>'Tumblr'),
+ array('code'=>'TW', 'lcode'=>'tw', 'name'=>'X/Twitter'),
+ array('code'=>'VB', 'lcode'=>'vb', 'name'=>'vBulletin'),
+ array('code'=>'VK', 'lcode'=>'vk', 'name'=>'VK.Com'),
+ array('code'=>'WB', 'lcode'=>'wb', 'name'=>'Weibo'),
+ array('code'=>'WP', 'lcode'=>'wp', 'name'=>'WP Based Blog')
+ );
+ $nxs_avlblNTList = array();
do_action('nxs_actAfterGetAvNetworks');
//## MAIN
add_action( 'init', 'nxs_initSNAP', 0 );
--- a/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/OAuth.php
+++ b/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/OAuth.php
@@ -10,6 +10,7 @@
class nsx_trOAuthConsumer {
public $key;
public $secret;
+ public $callback_url;
function __construct($key, $secret, $callback_url=NULL) {
$this->key = $key;
--- a/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/plurkOAuth.php
+++ b/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/plurkOAuth.php
@@ -1,201 +0,0 @@
-<?php
-
-define('PLURK_ACCESS_TOKEN_PATH', "/OAuth/access_token");
-define('PLURK_AUTHORIZE_PATH', "/OAuth/authorize");
-define('PLURK_REQUEST_TOKEN_PATH', "/OAuth/request_token");
-
-abstract class nxspk_SignatureMethod
-{
- abstract public function signing_base($request, $consumer, $token);
- abstract public function sign($request, $consumer, $token);
- public function check($request, $consumer, $token, $signature) {
- $built = $this->sign($request, $consumer, $token);
- return $built == $signature;
- }
-}
-
-class nxspk_SigMethod_HMAC_SHA1 extends nxspk_SignatureMethod {
- public $name = 'HMAC-SHA1';
- public function signing_base($request, $consumer_secret, $token) {
- $sig = array(rawurlencode($request['method']), rawurlencode($request['normalized_url']), rawurlencode($request['normalized_parameters']));
- $key = sprintf("%s&", rawurlencode($consumer_secret));
- if (isset($token)) $key .= rawurlencode($token->secret);
- $raw = implode('&', $sig);
- return array ($key, $raw);
- }
- public function sign($request, $consumer_secret, $token) {
- $key_raw = $this->signing_base($request, $consumer_secret, $token);// prr($key_raw);
- $basestring = base64_encode (hash_hmac('sha1', $key_raw[1], $key_raw[0], true));
- return rawurlencode($basestring);
- }
-
- public static function urlencode_rfc3986($input) {
- if (is_array($input)) {
- return array_map(array('nxspk_SigMethod_HMAC_SHA1', 'urlencode_rfc3986'), $input);
- } else if (is_scalar($input)) {
- return str_replace(
- '+',
- ' ',
- str_replace('%7E', '~', rawurlencode($input))
- );
- } else {
- return '';
- }
- }
- public function get_normalized_http_url($url) {
- $parts = parse_url($url);
-
- $port = @$parts['port'];
- $scheme = $parts['scheme'];
- $host = $parts['host'];
- $path = @$parts['path'];
-
- $port or $port = ($scheme == 'https') ? '443' : '80';
-
- if (($scheme == 'https' && $port != '443')|| ($scheme == 'http' && $port != '80')) {
- $host = "$host:$port";
- }
- return "$scheme://$host$path";
- }
- public function get_signature_base_string($url, $params) {
- $parts = array( 'GET', $this->get_normalized_http_url($url), $params); //prr($parts);
- $parts = $this->urlencode_rfc3986($parts);
- return implode('&', $parts);
- }
-
- public function sign2($request, $consumer_secret, $token){
-
- $base_string = $this->get_signature_base_string($request['normalized_url'], $request['normalized_parameters']);
- //$request->base_string = $base_string;
-
- //$key_parts = array( $consumer_secret); if ($token) $key_parts[] = $token->secret;
- $key_parts = array( $consumer_secret, ($token) ? $token : "");
-
- //$key_parts = array( $consumer_secret, "");
-
- $key_parts = $this->urlencode_rfc3986($key_parts);
- $key = implode('&', $key_parts); //prr($key); prr($base_string);
- return rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true)));
- }
-
-
- public function check($request, $consumer_secret, $token, $signature) {
- $built = $this->sign($request, $consumer_secret, $token);
- return $built == $signature;
- }
-}
-
-class wpPlurkOAuth{
- public $baseURL = 'https://www.plurk.com';
- public $http_code;
- protected $version = '1.0';
- protected $sign_method;
- protected $request_token;
- protected $access_token;
- protected $access_secret;
- protected $consumer_key;
- protected $consumer_secret;
-
- function __construct($consumer_key, $consumer_secret, $access_token = NULL, $access_secret = NULL) {
- $this->sign_method = new nxspk_SigMethod_HMAC_SHA1();
- $this->consumer_key = $consumer_key; $this->consumer_secret = $consumer_secret;
- $this->access_token = $access_token; $this->access_secret = $access_secret;
- // if (!empty($access_token) && !empty($access_secret)) $this->authorize($access_token, $access_secret);
- }
-
- function get_normalized_parameters($params) { $items = array();
- foreach ($params as $key => $value) {
- if ($key == 'oauth_signature') continue;
- if (is_array($value)) $mtems = array_merge($value, $items); else $items[$key] = $value;
- }
- ksort($items);
- $item_parts = array();
- foreach ($items as $key => $value) {
- $item_parts[] =
- sprintf("%s=%s",rawurlencode($key),rawurlencode($value));
- }
- return implode('&', $item_parts);
- }
- function genRndString($length = 8) { $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = '';
- for ($p = 0; $p < $length; $p++) $string .= $chars[mt_rand(0, strlen($chars)-1)];
- return $string;
- }
- function makeHTTPHeaders($ref, $post=false){ $hdrsArr = array();
- $hdrsArr['X-Requested-With']='XMLHttpRequest'; $hdrsArr['Referer']=$ref;
- $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.22 Safari/537.11';
- if($post) $hdrsArr['Content-Type']='application/x-www-form-urlencoded';
- $hdrsArr['Accept']='application/json, text/javascript, */*; q=0.01';
- $hdrsArr['Accept-Encoding']='gzip,deflate,sdch'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
- }
-
- function oAuthRespToArr($str){ $arr = explode('&', $str); $out = array();
- foreach ($arr as $ar) { $strr = explode('=', $ar); $out[$strr[0]] = $strr[1];} return $out;
- }
-
- function getReqToken($cbu){
- $args = array (
- 'oauth_consumer_key' => $this->consumer_key,
- 'oauth_timestamp' => time(),
- 'oauth_nonce' => $this->genRndString(),
- 'oauth_version' => $this->version,
- 'oauth_callback' => $cbu,
- 'oauth_signature_method' => 'HMAC-SHA1'
-
- );
- $req = array(); $req['method'] = 'GET';
- $req['normalized_url'] = $this->baseURL.PLURK_REQUEST_TOKEN_PATH;
- $req['normalized_parameters'] = $this->get_normalized_parameters($args);
- $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $token);
- $cbu = nxspk_SigMethod_HMAC_SHA1::urlencode_rfc3986($cbu);
- $url = $this->baseURL.PLURK_REQUEST_TOKEN_PATH.'?oauth_nonce='.$args['oauth_nonce'].'&oauth_timestamp='.$args['oauth_timestamp'].'&oauth_consumer_key='.$this->consumer_key.'&oauth_signature_method='.$args['oauth_signature_method'].'&oauth_version='.$args['oauth_version'].'&oauth_callback='.$cbu.'&oauth_signature='.$args['oauth_signature'];
- $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = $nxs_vbCkArray;
- $response = nxs_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
- if (is_nxs_error($response)){ $badOut = print_r($response, true)." - Connection ERROR"; return $badOut; }
- $this->http_code = $response['response']['code']; // prr($response);
- if (stripos($response['body'],'oauth_token_secret=')===false) echo 'Bad oAuth Login:'.esc_html($response['body']); else return $this->oAuthRespToArr($response['body']);
- }
- function getAccToken($verifier){
- $args = array (
- 'oauth_token' => $this->access_token,
- 'oauth_timestamp' => time(),
- 'oauth_nonce' => $this->genRndString(),
- 'oauth_version' => $this->version,
- 'oauth_consumer_key' => $this->consumer_key,
- 'oauth_verifier' => $verifier,
- 'oauth_signature_method' => 'HMAC-SHA1'
- );
- $req = array(); $req['method'] = 'GET'; $req['normalized_url'] = $this->baseURL.PLURK_ACCESS_TOKEN_PATH;
- $req['normalized_parameters'] = $this->get_normalized_parameters($args);
- $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $this->access_secret);
- $url = $this->baseURL.PLURK_ACCESS_TOKEN_PATH.'?oauth_nonce='.$args['oauth_nonce'].'&oauth_timestamp='.$args['oauth_timestamp'].'&oauth_signature_method='.$args['oauth_signature_method'].'&oauth_consumer_key='.$this->consumer_key.'&oauth_verifier='.rawurlencode($verifier).'&oauth_version='.$args['oauth_version'].'&oauth_token='.rawurlencode($this->access_token).'&oauth_signature='.rawurlencode($args['oauth_signature']);
- $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = array();
- $response = nxs_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
- if ( is_nxs_error($response) ) return $response;
- $this->http_code = $response['response']['code'];
- if (stripos($response['body'],'oauth_token_secret=')===false) echo 'Bad oAuth Login:'.esc_html($response['body']); else return $this->oAuthRespToArr($response['body']);
- }
- function makeReq($url, $params){
- $args = array (
- 'oauth_token' => $this->access_token,
- 'oauth_token_secret' => $this->access_secret,
- 'oauth_consumer_key' => $this->consumer_key,
- 'oauth_timestamp' => time(),
- 'oauth_nonce' => $this->genRndString(),
- 'oauth_version' => $this->version,
- 'oauth_signature_method' => 'HMAC-SHA1'
- );
- if (is_array($params)) { $argsTS = array_merge($args, $params);} else $argsTS = $args;
- $req = array(); $req['method'] = 'GET'; $req['normalized_url'] = $url;
- $req['normalized_parameters'] = $this->get_normalized_parameters($argsTS);
- $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $this->access_secret);
- if (is_array($params)) { $params = nxspk_SigMethod_HMAC_SHA1::urlencode_rfc3986($params); $args = array_merge($args, $params);} //prr($args);
- $argsStr = ''; $argsT = array(); foreach ($args as $arN=>$arV){$argsT[] = $arN.'='.$arV;} $argsStr = implode('&', $argsT); $url .= '?'.$argsStr;
- $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = '';
- $response = nxs_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); // prr($response);
- if ( is_nxs_error($response) ) return $response;
- $this->http_code = $response['response']['code'];
- return json_decode($response['body'], true);
- }
-
-}
-?>
--- a/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/scOAuth.php
+++ b/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/scOAuth.php
@@ -205,7 +205,7 @@
$response = nxs_remote_post($url, array( 'timeout' => 45, 'redirection' => 0, 'body'=>$argsStr, 'headers' => $hdrsArr)); //prr($argsStr); prr($argsT); prr($response);
}
if ( is_nxs_error($response) ) return $response;
- $this->http_code = $response['response']['code']; $body = json_decode($response['body'], true); return is_array($body) ? $body : array();
+ $this->http_code = $response['response']['code']; $body = $response['body']; $body = nxs_safe_unserialize($body, $body); if (is_array($body)) return $body; else return json_decode($body, true);
}
private function joinParameters($parameters){ $keys = array_keys($parameters); sort($keys, SORT_STRING); $keyValuePairs = array();
--- a/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/trOAuth.php
+++ b/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/trOAuth.php
@@ -13,18 +13,21 @@
* Tumblr OAuth class
*/
class TumblrOAuth {
+ public $sha1_method;
+ public $consumer;
+ public $token;
/* Contains the last HTTP status code returned. */
public $http_code;
/* Contains the last API call. */
public $url;
/* Set up the API root URL. */
- public $host = "http://api.tumblr.com/v2/";
+ public $host = "https://api.tumblr.com/v2/";
/* Set timeout default. */
public $timeout = 45;
/* Set connect timeout. */
public $connecttimeout = 45;
/* Verify SSL Cert. */
- public $ssl_verifypeer = FALSE;
+ public $ssl_verifypeer = TRUE;
/* Respons format. */
public $format = 'json';
/* Decode returned json data. */
@@ -157,6 +160,28 @@
return $response;
}
+ // NPF requests use a JSON body; OAuth 1 signs the URL and OAuth parameters.
+ function postNpf($url, $parameters, $media = null) {
+ $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'POST', $url, array());
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
+ $authorization = preg_replace('/^Authorization:s*/', '', $request->to_header());
+ $headers = array('Authorization' => $authorization, 'Accept' => 'application/json');
+ $body = wp_json_encode($parameters);
+ if (is_array($media)) {
+ $boundary = 'SNAPTumblr' . bin2hex(random_bytes(12));
+ $headers['Content-Type'] = 'multipart/form-data; boundary=' . $boundary;
+ $body = '--' . $boundary . "rnContent-Disposition: form-data; name="json"rnContent-Type: application/jsonrnrn" . $body . "rn";
+ $body .= '--' . $boundary . "rnContent-Disposition: form-data; name="" . $media['identifier'] . ""; filename="image"rnContent-Type: " . $media['mime'] . "rnrn" . $media['body'] . "rn--" . $boundary . "--rn";
+ } else $headers['Content-Type'] = 'application/json';
+ $response = nxs_remote_post($url, array('headers' => $headers, 'body' => $body, 'timeout' => $this->timeout));
+ if (is_nxs_error($response)) return (object) array('meta' => (object) array('status' => 0, 'msg' => $response->get_error_message()));
+ $this->http_code = wp_remote_retrieve_response_code($response);
+ $this->http_info = $response['response'];
+ $this->url = $url;
+ $decoded = json_decode(wp_remote_retrieve_body($response));
+ return is_object($decoded) ? $decoded : (object) array('meta' => (object) array('status' => $this->http_code, 'msg' => 'Invalid Tumblr response'));
+ }
+
/**
* DELETE wrapper for oAuthReqeust.
*/
@@ -198,4 +223,4 @@
}
return strlen($header);
}
-}
No newline at end of file
+}
--- a/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/xmlrpc-client.php
+++ b/social-networks-auto-poster-facebook-twitter-g/inc-cl/apis/xmlrpc-client.php
@@ -197,6 +197,15 @@
function parse()
{
+ // Clean up any prepended PHP warnings/errors before parsing XML
+ $xml_start = strpos($this->message, '<?xml');
+ if ($xml_start === false) {
+ $xml_start = strpos($this->message, '<methodResponse>');
+ }
+ if ($xml_start !== false) {
+ $this->message = substr($this->message, $xml_start);
+ }
+
// first remove the XML declaration
// merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
$header = preg_replace( '/<?xml.*??'.'>/', '', substr($this->message, 0, 100), 1);
@@ -428,9 +437,87 @@
function queryFS()
{
- // The legacy raw-socket path did not verify TLS and bypassed WordPress'
- // unsafe-URL checks. Keep API compatibility while using the hardened path.
- return call_user_func_array(array($this, 'query'), func_get_args());
+ $args = func_get_args();
+ $method = array_shift($args);
+ $request = new NXS_XMLRPC_Request($method, $args);
+ $length = $request->getLength();
+ $xml = $request->getXml();
+ $r = "rn";
+ $request = "POST {$this->path} HTTP/1.0$r";
+
+ // Merged from WP #8145 - allow custom headers
+ $this->headers['Host'] = $this->server;
+ $this->headers['Content-Type'] = 'text/xml';
+ $this->headers['User-Agent'] = $this->useragent;
+ //$this->headers['Content-Length']= $length;
+
+ foreach( $this->headers as $header => $value ) {
+ $request .= "{$header}: {$value}{$r}";
+ }
+ $request .= $r;
+
+ $request .= $xml;
+
+ // Now send the request
+ if ($this->debug) {
+ echo '<pre class="NXS_XMLRPC_request">'.htmlspecialchars($request)."n</pre>nn";
+ }
+
+ if ($this->timeout) {
+ $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
+ } else {
+ $fp = @fsockopen($this->server, $this->port, $errno, $errstr);
+ }
+ if (!$fp) {
+ $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - could not open socket');
+ return false;
+ }
+ fputs($fp, $request);
+ $contents = '';
+ $debugContents = '';
+ $gotFirstLine = false;
+ $gettingHeaders = true;
+ while (!feof($fp)) {
+ $line = fgets($fp, 4096);
+ if (!$gotFirstLine) {
+ // Check line for '200'
+ if (strstr($line, '200') === false) {
+ $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - HTTP status code was not 200');
+ return false;
+ }
+ $gotFirstLine = true;
+ }
+ if (trim($line) == '') {
+ $gettingHeaders = false;
+ }
+ if (!$gettingHeaders) {
+ // merged from WP #12559 - remove trim
+ $contents .= $line;
+ }
+ if ($this->debug) {
+ $debugContents .= $line;
+ }
+ }
+ if ($this->debug) {
+ echo '<pre class="NXS_XMLRPC_response">'.htmlspecialchars($debugContents)."n</pre>nn";
+ }
+
+ // Now parse what we've got back
+ $this->message = new NXS_XMLRPC_Message($contents);
+ if (!$this->message->parse()) {
+ // XML error
+ $this->error = new NXS_XMLRPC_Error(-32700, 'parse error. not well formed');
+ return false;
+ }
+
+ // Is the message a fault?
+ if ($this->message->messageType == 'fault') {
+ $this->error = new NXS_XMLRPC_Error($this->message->faultCode, $this->message->faultString);
+ return false;
+ }
+
+ // Message must be OK
+ return true;
}
/**
@@ -842,4 +929,4 @@
}
}
-?>
+?>
No newline at end of file
--- a/social-networks-auto-poster-facebook-twitter-g/inc-cl/bg.api.php
+++ b/social-networks-auto-poster-facebook-twitter-g/inc-cl/bg.api.php
@@ -13,11 +13,9 @@
}
function doPostToNT($options, $message){ $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); // prr($message); prr($options);
- //## Check API Lib
- //if (!function_exists('doConnectToBlogger')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php');
//## Check settings
if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }
- if ( (!isset($options['uName']) || empty($options['uPass'])) && empty($options['accessToken'])) { $badOut['Error'] = 'Not Configured'; return $badOut; }
+ if (empty($options['accessToken'])) { $badOut['Error'] = 'Not Configured'; return $badOut; }
//## Format
if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['msgFormat'], $message);
if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['msgTFormat'], $message);
@@ -30,47 +28,45 @@
//## Check/Fix HTML
if (class_exists('DOMDocument')) {$doc = new DOMDocument(); @$doc->loadHTML('<?xml encoding="UTF-8">' .$msg); $doc->encoding = 'UTF-8'; $msg = $doc->saveHTML(); $msg = CutFromTo($msg, '<body>', '</body>');
$msg = preg_replace('/<br(.*?)/?>/','<br$1/>',$msg); $msg = preg_replace('/<img(.*?)/?>/','<img$1/>',$msg);
- require ('apis/htmlNumTable.php'); if (is_array($HTML401NamedToNumeric)) { $msg = strtr($msg, $HTML401NamedToNumeric); $msgT = strtr($msgT, $HTML401NamedToNumeric); }
+ require(NXS_PLPATH . 'inc-cl/apis/htmlNumTable.php'); if (is_array($HTML401NamedToNumeric)) { $msg = strtr($msg, $HTML401NamedToNumeric); $msgT = strtr($msgT, $HTML401NamedToNumeric); }
}
$msg = preg_replace('/<scriptb[^>]*>(.*?)</script>/is', "", $msg); $msg = preg_replace('/<!--(.*)-->/Uis', "", $msg); $nxshf = new NXS_HtmlFixer(); $nxshf->debug = false; $msg = $nxshf->getFixedHtml($msg);
$msg = str_replace("rn","n", $msg); $msg = str_replace("nr","n", $msg); $msg = str_replace("r","n", $msg); $msg = str_replace("n","<br/>", $msg);
//## Make Post
$blogID = $options['blogID'];
- //prr($options); // prr($msgT); prr($msg); die();
- if (class_exists('nxsAPI_GP') && !empty($options['uName']) && empty($options['accessToken'])) {
- $pass = (substr($options['uPass'], 0, 5)=='n5g9a'||substr($options['uPass'], 0, 5)=='g9c1a'||substr($options['uPass'], 0, 5)=='b4d7s')?nsx_doDecode(substr($options['uPass'], 5)):$options['uPass'];
- $nt = new nxsAPI_GP(); if (!empty($options['proxy'])&&!empty($options['proxyOn'])){ $nt->proxy['proxy'] = $options['proxy']['proxy']; if (!empty($options['proxy']['up'])) $nt->proxy['up'] = $options['proxy']['up']; }
- if (!empty($options['sid'])){ $nt->session = array('ssid'=>$options['ssid'], 'sid'=>$options['sid'], 'hsid'=>$options['hsid']); }
- $loginError = $nt->connect($options['uName'], $pass, 'BG');
- if (!$loginError){
- $result = $nt -> postBG($blogID, $msgT, $msg, $tags);// prr($result);
- } else { $badOut['Error'] = "Login/Connection Error: ". print_r($loginError, true); return $badOut; }
- return $result;
- } else {
- //## Refresh token
- if (function_exists('get_option')) $currTime = time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); else $currTime = time();
- if ($options['accessTokenExp']<$currTime){
- $tknURL = 'https://www.googleapis.com/oauth2/v3/token?refresh_token='.$options['refreshToken'].'&client_id='.nxs_gak($options['appKey']).'&client_secret='.nxs_gas($options['appSec']).'&grant_type=refresh_token';
- $response = nxs_remote_post($tknURL); if (is_nxs_error($response)) return 'Token (Refresh) Connection Error: '.print_r($response, true);
- $resp = json_decode($response['body'], true); $options['accessToken'] = $resp['access_token']; $options['accessTokenExp'] = $currTime + $resp['expires_in'];
- nxs_save_glbNtwrks('bg', $options['ii'], $resp['access_token'], 'accessToken'); nxs_save_glbNtwrks('bg', $options['ii'], $options['accessTokenExp'], 'accessTokenExp');
- //nxs_addToLogN('S', 'Test', $logNT, 'Token Refreshed '.date('Y-m-d H:i:s',$options['AccessTokenExp'])."|".$tknURL.$options['AccessToken'].print_r($response, true));
- }
- //## Post
- $post = array("kind"=>"blogger#post", "blog"=>array("id"=>$blogID), "title"=> $msgT, "content" => $msg ); $post = json_encode($post); // prr($post);
- $hdrsArr = array('Content-Type'=>'application/json'); $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'body' => $post);
- $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/'.$blogID.'/posts?access_token='.$options['accessToken'].''; $ret = ''; $response = nxs_remote_post($tknURL, $advSet); //prr($tknURL); prr($response);
- if ((is_object($response) && isset($response->errors))) $badOut['Error'] = print_r($response, true); else $ret = json_decode($response['body'], true); //prr($ret);
- if (is_array($ret) && !empty($ret['id'])) return array('postID'=>$ret['id'], 'isPosted'=>1, 'postURL'=>$ret['url'], 'pDate'=>date('Y-m-d H:i:s'));
- else { $badOut['Error'].= "Error: ".print_r($ret, true); return $badOut;}
+ //## Refresh token
+ if (function_exists('get_option')) $currTime = time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); else $currTime = time();
+ if ($options['accessTokenExp']<$currTime){
+ $tknURL = 'https://oauth2.googleapis.com/token';
+ $wprg = array(
+ 'body' => array(
+ 'refresh_token' => $options['refreshToken'],
+ 'client_id' => nxs_gak($options['appKey']),
+ 'client_secret' => nxs_gas($options['appSec']),
+ 'grant_type' => 'refresh_token'
+ )
+ );
+ $response = nxs_remote_post($tknURL, $wprg); if (is_nxs_error($response)) return 'Token (Refresh) Connection Error: '.print_r($response, true);
+ $resp = json_decode($response['body'], true); $options['accessToken'] = $resp['access_token']; $options['accessTokenExp'] = $currTime + $resp['expires_in'];
+ nxs_save_glbNtwrks('bg', $options['ii'], $resp['access_token'], 'accessToken'); nxs_save_glbNtwrks('bg', $options['ii'], $options['accessTokenExp'], 'accessTokenExp');
}
- //## Return
- if (is_array($ret) && $ret['post_id']!='') {
- return array('postID'=>$ret['post_id'], 'isPosted'=>1, 'postURL'=>$ret['post_id'], 'pDate'=>date('Y-m-d H:i:s'));
- } else { $badOut['Error'] .= print_r($ret, true);
- return $badOut;
+ //## Post
+ $post = array("kind"=>"blogger#post", "blog"=>array("id"=>$blogID), "title"=> $msgT, "content" => $msg );
+ if (!empty($tags)) {
+ $post['labels'] = array_map('trim', explode(',', $tags));
}
+ $post = json_encode($post); // prr($post);
+ $hdrsArr = array(
+ 'Content-Type' => 'application/json',
+ 'Authorization' => 'Bearer ' . $options['accessToken']
+ );
+ $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'body' => $post);
+ $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/'.$blogID.'/posts';
+ $ret = ''; $response = nxs_remote_post($tknURL, $advSet); //prr($tknURL); prr($response);
+ if ((is_object($response) && isset($response->errors))) $badOut['Error'] = print_r($response, true); else $ret = json_decode($response['body'], true); //prr($ret);
+ if (is_array($ret) && !empty($ret['id'])) return array('postID'=>$ret['id'], 'isPosted'=>1, 'postURL'=>$ret['url'], 'pDate'=>date('Y-m-d H:i:s'));
+ else { $badOut['Error'].= "Error: ".print_r($ret, true); return $badOut;}
}
}}
?>
No newline at end of file
--- a/social-networks-auto-poster-facebook-twitter-g/inc-cl/bg.php
+++ b/social-networks-auto-poster-facebook-twitter-g/inc-cl/bg.php
@@ -20,17 +20,26 @@
//#### Show Common Settings
function showGenNTSettings($ntOpts){ $this->nt = $ntOpts; $this->showNTGroup(); }
//#### Show NEW Settings Page
- function showNewNTSettings($ii){ $defO = array('nName'=>'', 'do'=>'1', 'blogID'=>'', 'appKey'=>'', 'appSec'=>'', 'uName'=>'', 'uPass'=>'', 'inclTags'=>1, 'inclCatsAsTags'=>0, 'msgFormat'=>"%RAWTEXT%", 'msgTFormat'=>"%TITLE%", 'imgSize'=>'original'); $this->showGNewNTSettings($ii, $defO); }
+ function showNewNTSettings($ii){ $defO = array('nName'=>'', 'do'=>'1', 'blogID'=>'', 'appKey'=>'', 'appSec'=>'', 'inclTags'=>1, 'inclCatsAsTags'=>0, 'msgFormat'=>"%RAWTEXT%", 'msgTFormat'=>"%TITLE%", 'imgSize'=>'original'); $this->showGNewNTSettings($ii, $defO); }
//#### Show Unit Settings
- function checkIfSetupFinished($options) { return !empty($options['accessToken']) || !empty($options['uPass']); }
+ function checkIfSetupFinished($options) { return !empty($options['accessToken']); }
public function doAuth() { $ntInfo = $this->ntInfo; global $nxs_snapSetPgURL;
if (isset($_GET['code']) && $_GET['code']!='' && isset($_GET['state']) && strpos(wp_unslash($_GET['state']), 'nxs-bg-') === 0){
if (!nxs_snap_user_can_access() || !nxs_oauth_state_validate(wp_unslash($_GET['state']), 'bg', $ii) || !isset($this->nt[$ii])) wp_die(esc_html__('Invalid or expired Blogger authorization state.', 'social-networks-auto-poster-facebook-twitter-g'), '', array('response'=>403));
$at = sanitize_text_field(wp_unslash($_GET['code']));
echo "----=={ oAuth 2.0 Wordflow }==----<br/>-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>";
- $nxs_snapSetPgURL = nxs_get_admin_url('admin.php?page=nxssnap'); $options = $this->nt[$ii]; $wprg = array('sslverify'=>true);
+ $nxs_snapSetPgURL = nxs_get_admin_url('admin.php?page=nxssnap');
+ $options = $this->nt[$ii]; $wprg = array('sslverify'=>true);
if (isset($options['appKey'])){
- $response = nxs_remote_post('https://oauth2.googleapis.com/token', array('body'=>array('code'=>$at,'redirect_uri'=>$nxs_snapSetPgURL,'client_id'=>nxs_gak($options['appKey']),'client_secret'=>nxs_gas($options['appSec']),'grant_type'=>'authorization_code')));
+ $tknURL = 'https://oauth2.googleapis.com/token';
+ $wprg['body'] = array(
+ 'code' => $at,
+ 'redirect_uri' => $nxs_snapSetPgURL,
+ 'client_id' => nxs_gak($options['appKey']),
+ 'client_secret' => nxs_gas($options['appSec']),
+ 'grant_type' => 'authorization_code'
+ );
+ $response = nxs_remote_post($tknURL, $wprg);
if (is_nxs_error($response) || !is_array($response) || empty($response['body'])) die(esc_html__('Blogger token exchange failed.', 'social-networks-auto-poster-facebook-twitter-g'));
$resp = json_decode($response['body'], true); if (!is_array($resp) || empty($resp['access_token'])) { echo esc_html(isset($resp['error_description'])?$resp['error_description']:__('Blogger did not return an access token.', 'social-networks-auto-poster-facebook-twitter-g')); die(); }
if (function_exists('get_option')) $currTime = time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); else $currTime = time();
@@ -38,10 +47,12 @@
$options['accessTokenExp'] = $currTime + $resp['expires_in']; if (!empty($resp['refresh_token'])) $options['refreshToken'] = $resp['refresh_token']; echo "<br/>----=={ Expires: ".esc_html(date('Y-m-d H:i:s', $options['accessTokenExp']))." }==---- <br/>";
if (!empty($options['blogID'])){
- if (substr($options['blogID'], 0, 4)=='http') $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/byurl/?url='.rawurlencode($options['blogID']);
- else $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/'.rawurlencode($options['blogID']);
+ $tknURL = (substr($options['blogID'], 0, 4)=='http') ? 'https://www.googleapis.com/blogger/v3/blogs/byurl/?url='.urlencode($options['blogID']) : 'https://www.googleapis.com/blogger/v3/blogs/'.$options['blogID'];
+ $wprg['headers'] = array(
+ 'Authorization' => 'Bearer ' . $options['accessToken']
+ );
}
- $wprg['headers'] = array('Authorization'=>'Bearer '.$options['accessToken']); $response = nxs_remote_get($tknURL, $wprg); if (is_nxs_error($response)) die(esc_html__('Unable to retrieve Blogger account details.', 'social-networks-auto-poster-facebook-twitter-g')); $user = json_decode($response['body'], true);
+ $response = nxs_remote_get($tknURL, $wprg); if (is_nxs_error($response)) die(esc_html__('Unable to retrieve Blogger account details.', 'social-networks-auto-poster-facebook-twitter-g')); $user = json_decode($response['body'], true);
if (!empty($user['url'])) { $options['blogURL'] = $user['url']; $options['blogID'] = $user['id']; $options['blogInfo'] = $user['name']." [".$user['id']."] (".$user['url'].")"; nxs_save_glbNtwrks($ntInfo['lcode'],$ii,$options,'*');
?><script type="text/javascript">window.location = "<?php echo $nxs_snapSetPgURL; ?>"</script>
<?php }
@@ -50,45 +61,68 @@
}
}
- function accTab($ii, $options, $isNew=false){ global $nxs_snapSetPgURL; $ntInfo = $this->ntInfo; $nt = $ntInfo['lcode']; $oauth_state = nxs_oauth_state_create('bg', $ii); if (empty($options['sid'])) $options['sid']=''; if (empty($options['ssid'])) $options['ssid']=''; if (empty($options['nid'])) $options['nid']=''; if (empty($options['hsid'])) $options['hsid']='';?>
+ function accTab($ii, $options, $isNew=false){ global $nxs_snapSetPgURL; $ntInfo = $this->ntInfo; $nt = $ntInfo['lcode']; $oauth_state = nxs_oauth_state_create('bg', $ii); ?>
<div style="width:100%;"><strong><?php _e('Blogger Blog ID', 'social-networks-auto-poster-facebook-twitter-g'); ?>:</strong><i><?php _e('Log to your Blogger management panel and look at the URL of your blog: http://www.blogger.com/blogger.g?blogID=8959085979163812093#allposts. Your Blog ID will be: 8959085979163812093', 'social-networks-auto-poster-facebook-twitter-g'); ?></i></div><input name="<?php echo esc_attr($nt); ?>[<?php echo esc_attr($ii); ?>][blogID]" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['blogID'], ENT_COMPAT, "UTF-8")), 'social-networks-auto-poster-facebook-twitter-g') ?>" /><br/><br/>
- <div style="display: <?php echo (empty($options['apiToUse']))?"block":"none"; ?>;">
- <div style="width:100%; text-align: center; color:#005800; font-weight: bold; font-size: 14px;">You can choose what API you would like to use. </div>
- <span style="color:#005800; font-weight: bold; font-size: 14px;">Blogger Native API:</span> Free built-in API from Blogger. More secure, more stable. More complicated - <b style="color: red;">requires approval of access to API by Google (3-5 days)</b> and authorization. <br/><br/>
- <span style="color:#005800; font-weight: bold; font-size: 14px;">NextScripts API for Blogger:</span> Premium API with extended functionality. Easier to configure, but less secure - requires your password.<br/><br/>
- <select name="<?php echo esc_attr($nt); ?>[<?php echo esc_attr($ii); ?>][apiToUse]" onchange="if (jQuery(this).val()=='<?php echo esc_attr($nt); ?>') { jQuery('.nxs_<?php echo esc_attr($nt); ?>_nxapi_<?php echo esc_attr($ii); ?>').hide(); jQuery('.nxs_<?php echo esc_attr($nt); ?>_bgapi_<?php echo esc_attr($ii); ?>').show(); }else { jQuery('.nxs_<?php echo esc_attr($nt); ?>_bgapi_<?php echo esc_attr($ii); ?>').hide(); jQuery('.nxs_<?php echo esc_attr($nt); ?>_nxapi_<?php echo esc_attr($ii); ?>').show(); }"><option <?php echo (empty($options['apiToUse']) || $options['apiToUse'] =='bg')?"selected":""; ?> value="bg">Blogger API</option><option <?php echo (!empty($options['apiToUse']) && $options['apiToUse'] =='nx')?"selected":""; ?> value="nx">NextScripts API</option></select><hr/>
-
- </div>
-
- <div id="nxsAPIBG<?php echo esc_attr($ii); ?>" class="nxs_<?php echo esc_attr($nt); ?>_bgapi_<?php echo esc_attr($ii); ?>" style="display: <?php echo (empty($options['apiToUse']) || $options['apiToUse'] =='bg')?"block":"none"; ?>;"><h3>Blogger API</h3>
+ <div id="nxsAPIBG<?php echo esc_attr($ii); ?>" class="nxs_<?php echo esc_attr($nt); ?>_bgapi_<?php echo esc_attr($ii); ?>">
<div class="subDiv" id="sub<?php echo esc_attr($ii); ?>DivL" style="display: block;"> <?php $this->elemKeySecret($ii,'Client ID','Client Secret', $options['appKey'], $options['appSec'],'appKey','appSec','https://console.developers.google.com/'); ?>
<br/><br/>
- <?php if($options['appKey']=='') { ?>
- <b><?php _e('Authorize Your '.$ntInfo['name'].' Account', 'social-networks-auto-poster-facebook-twitter-g'); ?></b> <?php _e('Please click "Update Settings" to be able to Authorize your account.', 'social-networks-auto-poster-facebook-twitter-g');
- } else { if(!empty($options['accessToken']) && !empty($options['accessTokenSec'])) {
- _e('Your '.$ntInfo['name'].' Account has been authorized.', 'social-networks-auto-poster-facebook-twitter-g'); ?> <br/>Blog ID: <?php _e(apply_filters('format_to_edit', htmlentities($options['blogInfo'], ENT_COMPAT, "UTF-8")), 'social-networks-auto-poster-facebook-twitter-g'); ?>.
- <?php _e('You can', 'social-networks-auto-poster-facebook-twitter-g'); ?> Re- <?php } ?>
- <a href="<?php echo esc_url('https://accounts.google.com/o/oauth2/v2/auth?'.http_build_query(array('redirect_uri'=>$nxs_snapSetPgURL,'response_type'=>'code','client_id'=>nxs_gak($options['appKey']),'scope'=>'https://www.googleapis.com/auth/blogger','prompt'=>'consent','access_type'=>'offline','state'=>$oauth_state), '', '&')); ?>">Authorize Your Blogger Account</a>
- <?php if (empty($options['accessToken'])) { ?> <div class="blnkg"><=== <?php _e('Authorize your account', 'social-networks-auto-poster-facebook-twitter-g'); ?> ===</div> <?php }
- } ?><br/><br/>
+ <div id="bg_authorize_wrap_<?php echo esc_attr($ii); ?>" style="<?php echo ($options['appKey']!='') ? '' : 'display: none;'; ?>">
+ <?php if(!empty($options['accessToken']) && !empty($options['accessTokenSec'])) { ?>
+ <?php _e('Your '.$ntInfo['name'].' Account has been authorized.', 'social-networks-auto-poster-facebook-twitter-g'); ?> <br/>Blog ID: <?php _e(apply_filters('format_to_edit', htmlentities($options['blogInfo'], ENT_COMPAT, "UTF-8")), 'social-networks-auto-poster-facebook-twitter-g'); ?>.<br/>
+ <?php _e('You can', 'social-networks-auto-poster-facebook-twitter-g'); ?> Re-
+ <?php } ?>
+ <a id="bg_authLink_<?php echo esc_attr($ii); ?>" href="<?php echo esc_url('https://accounts.google.com/o/oauth2/v2/auth?'.http_build_query(array('redirect_uri'=>$nxs_snapSetPgURL,'response_type'=>'code','client_id'=>nxs_gak($options['appKey']),'scope'=>'https://www.googleapis.com/auth/blogger','prompt'=>'consent','access_type'=>'offline','state'=>$oauth_state), '', '&')); ?>" onclick="var authUrl = jQuery(this).attr('href'); nxs_svSetAdv('bg', '<?php echo esc_js($ii); ?>', '<?php echo esc_js($isNew ? 'domBG'.$ii.'Div' : 'nxsAllAccntsDiv'); ?>', '', authUrl, '1'); return false;">Authorize Your Blogger Account</a>
+ <?php if (empty($options['accessToken'])) { ?>
+ <div class="blnkg" id="bg_blnkg_<?php echo esc_attr($ii); ?>"><=== <?php _e('Authorize your account', 'social-networks-auto-poster-facebook-twitter-g'); ?> ===</div>
+ <?php } ?>
+ <br/><br/>
+ </div>
+
+ <div id="bg_notice_wrap_<?php echo esc_attr($ii); ?>" style="<?php echo ($options['appKey']=='') ? '' : 'display: none;'; ?>">
+ <b><?php _e('Authorize Your '.$ntInfo['name'].' Account', 'social-networks-auto-poster-facebook-twitter-g'); ?></b>. <?php _e('Please enter your Client ID and Client Secret above to enable authorization.', 'social-networks-auto-poster-facebook-twitter-g'); ?>
+ <br/><br/>
+ </div>
+ <?php
+ static $bg_script_printed = false;
+ if (!$bg_script_printed) {
+ $bg_script_printed = true;
+ ?>
+ <script type="text/javascript">
+ function nxs_bg_client_changed(ii, redirectUriBase, oauthState) {
+ var appKey = jQuery('#bgappKey' + ii).val().trim();
+ var authorizeWrap = jQuery('#bg_authorize_wrap_' + ii);
+ var noticeWrap = jQuery('#bg_notice_wrap_' + ii);
+ var authLink = jQuery('#bg_authLink_' + ii);
+
+ if (appKey !== '') {
+ authorizeWrap.show();
+ noticeWrap.hide();
+
+ var cleanAppKey = appKey;
+ if (cleanAppKey.indexOf('::') > -1) {
+ cleanAppKey = cleanAppKey.split('::')[0];
+ }
+
+ authLink.attr('href', "https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=" + encodeURIComponent(redirectUriBase) + "&response_type=code&client_id=" + encodeURIComponent(cleanAppKey) + "&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fblogger&prompt=consent&access_type=offline&state=" + encodeURIComponent(oauthState));
+ } else {
+ authorizeWrap.hide();
+ noticeWrap.show();
+ }
+ }
+ </script>
+ <?php
+ }
+ ?>
+ <script type="text/javascript">
+ jQuery(document).ready(function() {
+ jQuery(document).on('input', '#bgappKey<?php echo $ii; ?>, #bgappSec<?php echo $ii; ?>', function() {
+ nxs_bg_client_changed(<?php echo absint($ii); ?>, <?php echo wp_json_encode($nxs_snapSetPgURL); ?>, <?php echo wp_json_encode($oauth_state); ?>);
+ });
+ });
+ </script><br/><br/>
</div>
</div>
- <div id="nxsAPINX<?php echo esc_attr($ii); ?>" class="nxs_bg_nxapi_<?php echo esc_attr($ii); ?>" style="display: <?php echo (!empty($options['apiToUse']) && $options['apiToUse'] =='nx')?"block":"none"; ?>;"><h3>NextScripts API</h3>
- <?php if (class_exists('nxsAPI_GP')) { ?>
- <div class="subDiv" id="sub<?php echo esc_attr($ii); ?>DivN" style="display: block;"><?php $this->elemUserPass($ii, $options['uName'], $options['uPass']); ?></div>
-
-
- <div id="ups<?php echo esc_attr($nt.$ii); ?>UPS" style="padding-top: 10px;"><a href="#" onclick="jQuery('#ups<?php echo esc_attr($nt.$ii); ?>S').show();return false;">Use session</a> (Optional - use only if you are having login problems)</div>
- <div id="ups<?php echo esc_attr($nt.$ii); ?>S" class="ups<?php echo esc_attr($nt.$ii); ?>" style="padding-left: 15px; padding-top: 10px; display:none;">
- SID: <input style="width:400px;" name="<?php echo esc_attr($nt); ?>[<?php echo esc_attr($ii); ?>][sid]" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['sid'], ENT_COMPAT, "UTF-8")), 'social-networks-auto-poster-facebook-twitter-g') ?>" /> <br/>
- SSID: <input style="width:400px;" name="<?php echo esc_attr($nt); ?>[<?php echo esc_attr($ii); ?>][ssid]" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['ssid'], ENT_COMPAT, "UTF-8")), 'social-networks-auto-poster-facebook-twitter-g') ?>" /> <br/>
- HSID: <input style="width:400px;" name="<?php echo esc_attr($nt); ?>[<?php echo esc_attr($ii); ?>][hsid]" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['hsid'], ENT_COMPAT, "UTF-8")), 'social-networks-auto-poster-facebook-twitter-g') ?>" /> <br/>
- </div>
-
-
- <?php } else { nxs_show_noLibWrn('"NextScripts API Library for Blogger" is NOT installed'); } ?>
- </div><br/>
<br/><?php $this->elemTitleFormat($ii,'Message Title Format','msgTFormat',$options['msgTFormat']); $this->elemMsgFormat($ii,'Message Format','msgFormat',$options['msgFormat']); ?>
<div style="margin: 0px;"><input value="1" type="checkbox" name="<?php echo esc_attr($nt); ?>[<?php echo esc_attr($ii); ?>][inclTags]" <?php if ((int)$options['inclTags'] == 1) echo "checked"; ?> /> <strong><?php _e('Post with tags', 'social-networks-auto-poster-facebook-twitter-g'); ?></strong></div>
@@ -97,22 +131,14 @@
<?php
}
function advTab($ii, $options){ $this->showProxies($this->ntInfo['lcode'], $ii, $options); }
- //#### Set Unit Settings from POST
function setNTSettings($post, $options){ $otp = array(); //prr($options);
foreach ($options as $oo => $v){ if (isset($v['ck'])) unset($v['ck']);
- if (isset($oo) && $oo!=='' && ((!empty($v['appKey']) && !empty($v['appSec'])) || (!empty($v['uPass']) && !empty($v['uName']))) ) $otp[$oo] = $v;
+ if (isset($oo) && $oo!=='' && !empty($v['appKey']) && !empty($v['appSec'])) $otp[$oo] = $v;
} $options = $otp;
foreach ($post as $ii => $pval){
if (!empty($pval['blogID']) && !empty($pval['blogID'])){ if (!isset($options[$ii])) $options[$ii] = array(); $options[$ii] = $this->saveCommonNTSettings($pval,$options[$ii]);
- //## Uniqe Items
- if (isset($pval['sid'])) $options[$ii]['sid'] = trim($pval['sid']);
- if (isset($pval['ssid'])) $options[$ii]['ssid'] = trim($pval['ssid']);
- if (isset($pval['hsid'])) $options[$ii]['hsid'] = trim($pval['hsid']);
- if (isset($pval['nid'])) $options[$ii]['nid'] = trim($pval['nid']);
-
if (isset($pval['inclTags'])) $options[$ii]['inclTags'] = trim($pval['inclTags']); else $options[$ii]['inclTags'] = 0;
if (isset($pval['inclCatsAsTags'])) $options[$ii]['inclCatsAsTags'] = trim($pval['inclCatsAsTags']); else $options[$ii]['inclCatsAsTags'] = 0;
- if (isset($pval['apiToUse'])) $options[$ii]['apiToUse'] = trim($pval['apiToUse']);
if (isset($pval['blogID'])) $options[$ii]['blogID'] = trim($pval['blogID']);
} elseif ( count($pval)==1 ) if (isset($pval['do'])) $options[$ii]['do'] = $pval['do']; else $options[$ii]['do'] = 0;
} return $options;
--- a/social-networks-auto-poster-facebook-twitter-g/inc-cl/bs.api.php
+++ b/social-networks-auto-poster-facebook-twitter-g/inc-cl/bs.api.php
@@ -0,0 +1,141 @@
+<?php
+
+if (!class_exists('nxs_class_SNAP_BS')) { class nxs_class_SNAP_BS {
+ var $ntCode = 'BS'; var $ntLCode = 'bs';
+
+ function doPost($options, $message) {
+ if (!is_array($options)) return false;
+ $out = array(); foreach ($options as $ii => $account) $out[$ii] = $this->doPostToNT($account, $message);
+ return $out;
+ }
+
+ function doPostToNT($options, $message) {
+ $failure = array('pgID'=>'', 'postID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'postURL'=>'', 'Error'=>'');
+ if (!is_array($options) || empty($options['handle']) || empty($options['appPassword'])) { $failure['Error'] = 'Bluesky handle and App Password are required.'; return $failure; }
+ $handle = strtolower(ltrim(trim($options['handle']), '@'));
+ $password = (string) $options['appPassword'];
+ $text = !empty($message['pText']) ? (string) $message['pText'] : nxs_doFormatMsg(!empty($options['msgFormat']) ? $options['msgFormat'] : '%TITLE% - %URL%', $message);
+ $text = trim(html_entity_decode(wp_strip_all_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8'));
+ if ($text === '') { $failure['Error'] = 'The Bluesky post is empty.'; return $failure; }
+ if (function_exists('grapheme_strlen')) $length = grapheme_strlen($text);
+ else { $count = preg_match_all('/X/u', $text); $length = $count !== false ? $count : strlen($text); }
+ if ($length > 300) { $failure['Error'] = 'The Bluesky post exceeds 300 characters.'; return $failure; }
+
+ $session = $this->session($handle, $password);
+ if (is_wp_error($session)) { $failure['Error'] = $session->get_error_message(); return $failure; }
+ $record = array('$type'=>'app.bsky.feed.post', 'text'=>$text, 'createdAt'=>gmdate('Y-m-dTH:i:sZ'));
+ $facets = $this->link_facets($text);
+ if ($facets) $record['facets'] = $facets;
+ if (!empty($options['attchImg']) && !empty($message['imageURL'])) {
+ $image_url = is_array($message['imageURL']) ? nxs_getImgfrOpt($message['imageURL'], !empty($options['