nxs_options = $this->getAPOptions();}
//## Constructor
function NS_SNAutoPoster() { }
//## Initialization function
function init() { $this->getAPOptions(); }
//## Administrative Functions
//## Options loader function
function getAPOptions() { global $nxs_isWPMU, $blog_id; $dbMUOptions = array();
//## Some Default Values
//$options = array('nsOpenGraph'=>1);
$dbOptions = get_option($this->dbOptionsName);
$this->nxs_ntoptions = get_site_option($this->dbOptionsName);
if ($nxs_isWPMU && $blog_id>1) { switch_to_blog(1); $dbMUOptions = get_option($this->dbOptionsName);
if (function_exists('nxs_getInitAdd')) nxs_getInitAdd($dbMUOptions); restore_current_blog();
$dbOptions['lk'] = $dbMUOptions['lk']; $dbOptions['ukver'] = $dbMUOptions['ukver']; $dbOptions['uklch'] = $dbMUOptions['uklch']; $dbOptions['uk'] = $dbMUOptions['uk'];
}
if (!empty($dbOptions) && is_array($dbOptions)) foreach ($dbOptions as $key => $option) if (trim($key)!='') $options[$key] = $option;
if ( (!$nxs_isWPMU || $blog_id==1) && function_exists('nxs_getInitAdd')) nxs_getInitAdd($options); //$ttt = function_exists('nxs_getInitAdd'); var_dump($ttt);
if (isset($options['uk']) && $options['uk']!='') $options['uk']='API';
if (defined('NXSAPIVER') && $options['ukver']!=NXSAPIVER){$options['ukver']=NXSAPIVER; update_option($this->dbOptionsName, $options);}
$options['isMA'] = function_exists('nxs_doSMAS1') && isset($options['lk']) && isset($options['uk']) && $options['uk']!='';
$options['isMU'] = function_exists('showSNAP_WPMU_OptionsPageExt') && isset($options['lk']) && isset($options['uk']) && $options['uk']!='';
$options['isMUx'] = function_exists('showSNAP_WPMU_OptionsPageExtX') && isset($options['lk']) && isset($options['uk']) && $options['uk']!=''; // prr($options);
if (!isset($options['isPro']) || $options['isPro']!='1'){ //## Upgrade from non-pro version
$optPro = array();foreach ($options as $indx => $opt){
if (substr($indx, 0, 2)=='fb') $optPro['fb'][0][$indx] = $opt;
elseif (substr($indx, 0, 2)=='gp') $optPro['gp'][0][$indx] = $opt;
elseif (substr($indx, 0, 2)=='tw') $optPro['tw'][0][$indx] = $opt;
elseif (substr($indx, 0, 2)=='tr') $optPro['tr'][0][$indx] = $opt;
elseif (substr($indx, 0, 2)=='bg') $optPro['bg'][0][$indx] = $opt;
elseif (substr($indx, 0, 2)=='li') $optPro['li'][0][$indx] = $opt;
elseif (substr($indx, 0, 2)=='pn') $optPro['pn'][0][$indx] = $opt;
elseif ($indx=='doFB') $optPro['fb'][0][$indx] = $opt;
elseif ($indx=='doGP') $optPro['gp'][0][$indx] = $opt;
elseif ($indx=='doTW') $optPro['tw'][0][$indx] = $opt;
elseif ($indx=='doTR') $optPro['tr'][0][$indx] = $opt;
elseif ($indx=='doBG') $optPro['bg'][0][$indx] = $opt;
elseif ($indx=='doLI') $optPro['li'][0][$indx] = $opt;
elseif ($indx=='doPN') $optPro['pn'][0][$indx] = $opt;
elseif (trim($indx)!='') $optPro[$indx] = $opt;
if ($options['twAccTokenSec']!='') $optPro['tw'][0]['twOK'] = '1';
if ($options['bgBlogID']!='') $optPro['bg'][0]['bgOK'] = '1';
$optPro['isPro'] = '1';
}
//## Update the options for the panel
$options = $optPro; update_option($this->dbOptionsName, $options);
}
// if(!$options['isMA']) $options = nxs_snapCleanup($options);
return $options;
}
function showSNAP_WPMU_OptionsPage(){ global $nxs_snapAvNts, $nxs_snapThisPageUrl, $nxsOne, $wpdb, $nxs_isWPMU; $nxsOne = ''; $options = $this->nxs_options;
$this->NS_SNAP_ShowPageTop();
if ($nxs_isWPMU && function_exists('showSNAP_WPMU_OptionsPageExt')) { showSNAP_WPMU_OptionsPageExt($this); } elseif ($nxs_isWPMU && function_exists('showSNAP_WPMU_OptionsPageExtX')) { ?>
You are running SNAP
This version does not fully support Wordpress Multisite (ex Wordpress MU) Advanced Features. SNAP is available for all sites/blogs in your networks and each individual blog admin can setup and manage it.
Please upgrade to SNAP For Wordpress Multisite if you need advanced Super Admin management of SNAP for sites/blogs in your networks. Please see here for more info
Please contact us if you got the SNAP PRO before Oct 1st, 2012. You may be eligible for upgrade discount.
You are running SNAP This version does not support Wordpress Multisite (ex Wordpress MU). Please upgrade to SNAP Pro for Wordpress Multisite
:
[Pro - Multiple Accounts Edition]
[Single Accounts Edition]
-
PRO - Multiple Accounts Edition
Error: No CURL Found -
Social Networks AutoPoster needs the CURL PHP extension. Please install it or contact your hosting company to install it. ");
}
if (stripos($disabled_functions, 'curl_exec')!==false) {
echo ("
curl_exec function is disabled in php.ini -
Social Networks AutoPoster needs the CURL PHP extension. Please enable it or contact your hosting company to enable it. ");
}
/*
if ((defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE==true) || (defined('MULTISITE') && MULTISITE==true) ) {
echo "
Sorry, we do not support Multiuser Wordpress at this time "; return;
}
*/
?>
deactivate Google Analytics plugin, do all authorizations and then activate it back.', 'nxs_snap' ), $plgnsLink ); ?>
nxs_options; // echo "| NS_SNAP_SavePostMetaTags - ".$id." |";
$post = get_post($id); if ($post->post_type=='revision' && $post->post_status=='inherit' && $post->post_parent!='0') return;
if (isset($_POST["snapEdIT"])) $nspost_edit = $_POST["snapEdIT"]; //echo "| snapEdIT |"; // prr($nspost_edit);
if (get_magic_quotes_gpc() || $_POST['nxs_mqTest']=="\'"){ array_walk_recursive($_POST, 'nsx_stripSlashes'); }
$snap_isAutoPosted = get_post_meta($id, 'snap_isAutoPosted', true); if ($snap_isAutoPosted=='1' && $post->post_status=='future') { delete_post_meta($id, 'snap_isAutoPosted'); add_post_meta($id, 'snap_isAutoPosted', '2'); }
if (isset($nspost_edit) && !empty($nspost_edit)) { delete_post_meta($id, 'snapEdIT'); add_post_meta($id, 'snapEdIT', '1' );
foreach ($nxs_snapAvNts as $avNt) {
if (count($options[$avNt['lcode']])>0 && isset($_POST[$avNt['lcode']]) && count($_POST[$avNt['lcode']])>0) { $savedMeta = maybe_unserialize(get_post_meta($id, 'snap'.$avNt['code'], true));
if(is_array($_POST[$avNt['lcode']])) { $ii=0;
foreach ($_POST[$avNt['lcode']] as $pst ) { // echo "#############################################################################"; prr($pst);
if (is_array($pst) && $pst['do'.$avNt['code']]=='' && $_POST[$avNt['lcode']][$ii]['do'.$avNt['code']]=='') $_POST[$avNt['lcode']][$ii]['do'.$avNt['code']]= 0; $ii++;
}
} $newMeta = $_POST[$avNt['lcode']];
if (is_array($savedMeta) && is_array($newMeta)) $newMeta = nxsMergeArraysOV($savedMeta, $newMeta); // echo "##### ".$id."| snap".$avNt['code']; prr($savedMeta); echo "||"; prr($newMeta);// $newMeta = 'AAA';
delete_post_meta($id, 'snap'.$avNt['code']); add_post_meta($id, 'snap'.$avNt['code'], serialize($newMeta));
}
}
} // prr($_POST);
}
function NS_SNAP_AddPostMetaTags() { global $post, $nxs_snapAvNts, $plgn_NS_SNAutoPoster; $post_id = $post; if (is_object($post_id)) $post_id = $post_id->ID; if (!is_object($post)) $post = get_post($post_id);
if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
?>
post_status != "publish" ) { ?>
0) { $ntClInst = new $clName(); $ntClInst->showEdPostNTSettings($options[$avNt['lcode']], $post); }
}
?>
Edit
function NS_SNAP_addCustomBoxes() { add_meta_box( 'NS_SNAP_AddPostMetaTags', __( 'NextScripts: Social Networks Auto Poster - Post Options', 'nxs_snap' ), array($this, 'NS_SNAP_AddPostMetaTags'), 'post' );
global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
if ($options['useForPages']=='1') add_meta_box( 'NS_SNAP_AddPostMetaTags', __( 'NextScripts: Social Networks Auto Poster - Post Options', 'nxs_snap' ), array($this, 'NS_SNAP_AddPostMetaTags'), 'page' );
$args=array('public'=>true, '_builtin'=>false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) $post_types=get_post_types($args, $output, $operator);
if ((isset($options['nxsCPTSeld'])) && $options['nxsCPTSeld']!='') $nxsCPTSeld = unserialize($options['nxsCPTSeld']); else $nxsCPTSeld = array_keys($post_types); //prr($nxsCPTSeld);
foreach ($post_types as $cptID=>$cptName) if (in_array($cptID, $nxsCPTSeld)){
add_meta_box( 'NS_SNAP_AddPostMetaTags', __('NextScripts: Social Networks Auto Poster - Post Options', 'nxs_snap'), array($this, 'NS_SNAP_AddPostMetaTags'), $cptID );
}
}
}
}
if (class_exists("NS_SNAutoPoster")) { nxs_checkAddLogTable(); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster(); }
//## Delete Account
if (!function_exists("ns_delNT_ajax")) { function ns_delNT_ajax(){ check_ajax_referer('nsDN'); $indx = (int)$_POST['id'];
global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
unset($options[$_POST['nt']][$indx]); if (is_array($options)) update_option('NS_SNAutoPoster', $options);
}}
if (!function_exists("nsAuthFBSv_ajax")) { function nsAuthFBSv_ajax() { check_ajax_referer('nsFB'); $pgID = $_POST['pgID']; $fbs = array();
global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
foreach ($options['fb'] as $two) { if ($two['fbPgID']==$pgID) $two['wfa']=time(); $fbs[] = $two; } $options['fb'] = $fbs; if (is_array($options)) update_option('NS_SNAutoPoster', $options);
}}
if (!function_exists("nsGetBoards_ajax")) {
function nsGetBoards_ajax() { global $nxs_gCookiesArr; check_ajax_referer('getBoards'); global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
if (get_magic_quotes_gpc() || $_POST['nxs_mqTest']=="\'") { $_POST['u'] = stripslashes($_POST['u']); $_POST['p'] = stripslashes($_POST['p']);} $_POST['p'] = trim($_POST['p']); $u = trim($_POST['u']);
$loginError = doConnectToPinterest($_POST['u'], substr($_POST['p'], 0, 5)=='g9c1a'?nsx_doDecode(substr($_POST['p'], 5)):$_POST['p'] ); if ($loginError!==false) {echo $loginError; return "BAD USER/PASS";}
$gPNBoards = doGetBoardsFromPinterest(); $options['pn'][$_POST['ii']]['pnBoardsList'] = base64_encode($gPNBoards);
$options['pn'][$_POST['ii']]['pnSvC'] = serialize($nxs_gCookiesArr); if (is_array($options)) update_option('NS_SNAutoPoster', $options); echo $gPNBoards; die();
}
}
if (!function_exists("nsGetGPCats_ajax")) {
function nsGetGPCats_ajax() { global $nxs_gCookiesArr; check_ajax_referer('getGPCats'); global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
if (get_magic_quotes_gpc() || $_POST['nxs_mqTest']=="\'") { $_POST['u'] = stripslashes($_POST['u']); $_POST['p'] = stripslashes($_POST['p']);} $_POST['p'] = trim($_POST['p']); $u = trim($_POST['u']);
$loginError = doConnectToGooglePlus2($_POST['u'], substr($_POST['p'], 0, 5)=='g9c1a'?nsx_doDecode(substr($_POST['p'], 5)):$_POST['p'] ); if ($loginError!==false) {echo $loginError; return "BAD USER/PASS";}
$gGPCCats = doGetCCatsFromGooglePlus($_POST['c']); $options['gp'][$_POST['ii']]['gpCCatsList'] = base64_encode($gGPCCats);
if (is_array($options)) update_option('NS_SNAutoPoster', $options); echo $gGPCCats; die();
}
}
if (!function_exists("nsGetWLBoards_ajax")) {
function nsGetWLBoards_ajax() { global $nxs_gCookiesArr; check_ajax_referer('getWLBoards'); global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
if (get_magic_quotes_gpc() || $_POST['nxs_mqTest']=="\'") { $_POST['u'] = stripslashes($_POST['u']); $_POST['p'] = stripslashes($_POST['p']);} $_POST['p'] = trim($_POST['p']); $u = trim($_POST['u']);
$loginError = doConnectToWaNeLo($_POST['u'], substr($_POST['p'], 0, 5)=='g9c1a'?nsx_doDecode(substr($_POST['p'], 5)):$_POST['p'] ); if ($loginError!==false) {echo $loginError; return "BAD USER/PASS";}
$gWLBoards = doGetBoardsFromWaNeLo(); $options['wl'][$_POST['ii']]['wlBoardsList'] = base64_encode($gWLBoards);
$options['wl'][$_POST['ii']]['wlSvC'] = serialize($nxs_gCookiesArr); if (is_array($options)) update_option('NS_SNAutoPoster', $options); echo $gWLBoards; die();
}
}
if (!function_exists("nxs_clLgo_ajax")) { function nxs_clLgo_ajax() { check_ajax_referer('nxsSsPageWPN'); global $wpdb;
//update_option('NS_SNAutoPosterLog', '');
$wpdb->query( 'DELETE FROM '.$wpdb->prefix . 'nxs_log' ); echo "OK";
}}
if (!function_exists("nxs_rfLgo_ajax")) { function nxs_rfLgo_ajax() { check_ajax_referer('nxsSsPageWPN'); echo "Y:";
//$log = get_option('NS_SNAutoPosterLog'); $logInfo = maybe_unserialize(get_option('NS_SNAutoPosterLog'));
$logInfo = nxs_getnxsLog();
if (is_array($logInfo))foreach (array_reverse($logInfo) as $logline) {
if ($logline['type']=='E') $actSt = "color:#FF0000;"; elseif ($logline['type']=='M') $actSt = "color:#585858;"; elseif ($logline['type']=='BG') $actSt = "color:#008000; font-weight:bold;";
elseif ($logline['type']=='I') $actSt = "color:#0000FF;"; elseif ($logline['type']=='W') $actSt = "color:#DB7224;"; elseif ($logline['type']=='BI') $actSt = "color:#0000FF; font-weight:bold;";
elseif ($logline['type']=='GR') $actSt = "color:#008080;"; elseif ($logline['type']=='S') $actSt = "color:#005800; font-weight:bold;"; else $actSt = "color:#585858;";
if ($logline['type']=='E') $msgSt = "color:#FF0000;"; elseif ($logline['type']=='BG') $msgSt = "color:#008000; font-weight:bold;"; else $msgSt = "color:#585858;";
if ($logline['nt']!='') $ntInfo = ' ['.$logline['nt'].'] '; else $ntInfo = '';
echo '
['.$logline['date'].'] -
['.$logline['act'].'] '.$ntInfo.'-
'.$logline['msg'].' '.$logline['extInfo'].'
';
}
}}
//## Initialize the admin panel if the plugin has been activated
if (!function_exists("nxs_AddSUASettings")) { function nxs_AddSUASettings() { global $plgn_NS_SNAutoPoster, $nxs_plurl; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
add_menu_page('Social Networks Auto Poster', 'Social Networks Auto Poster', 'manage_options', basename(__FILE__), array(&$plgn_NS_SNAutoPoster, 'showSNAP_WPMU_OptionsPage'), $nxs_plurl.'img/snap-icon12.png'); }}
//## Initialize the admin panel if the plugin has been activated
if (!function_exists("NS_SNAutoPoster_ap")) { function NS_SNAutoPoster_ap() { global $plgn_NS_SNAutoPoster, $nxs_plurl; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
if (function_exists('add_options_page')) { add_options_page('Social Networks Auto Poster',
'
{SNAP} Social Networks Auto Poster', 'manage_options', basename(__FILE__), array(&$plgn_NS_SNAutoPoster, 'showSNAutoPosterOptionsPage'));
}}}
if (!function_exists("NS_SNAutoPoster_apx")) { function NS_SNAutoPoster_apx() { global $plgn_NS_SNAutoPoster, $nxs_plurl; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
if (function_exists('add_options_page')) { add_options_page('Social Networks Auto Poster',
'
{SNAP} Social Networks Auto Poster', 'manage_options', basename(__FILE__), array(&$plgn_NS_SNAutoPoster, 'showSNAutoPosterOptionsPagex'));
}}}
//## Main Function to Post
if (!function_exists("nxs_snapPublishTo")) { function nxs_snapPublishTo($postArr, $type='', $aj=false) { global $plgn_NS_SNAutoPoster, $nxs_snapAvNts, $blog_id, $nxs_tpWMPU; // echo " | nxs_doSMAS2 | "; prr($postArr);
if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
if(is_object($postArr)) $postID = $postArr->ID; else { $postID = $postArr; $postArr = get_post($postID); } $isPost = isset($_POST["snapEdIT"]);
if ($isPost && $options['skipSecurity']!='1' && !current_user_can("make_snap_posts") && !current_user_can("manage_options")) { nxs_addToLogN('I', 'Skipped', '', 'Current user can\'t autopost - Post ID:('.$postID.')' ); return; }
$postUser = $postArr->post_author;
if ($options['skipSecurity']!='1' && !user_can( $postUser, "make_snap_posts" ) && !user_can( $postUser, "manage_options")){ nxs_addToLogN('I', 'Skipped', '', 'User ID '.$postUser.' can\'t autopost - Post ID:('.$postID.')' ); return; }
if ($isPost) $plgn_NS_SNAutoPoster->NS_SNAP_SavePostMetaTags($postID);
if (function_exists('nxs_doSMAS2')) { nxs_doSMAS2($postArr, $type, $aj); return; } else {
$options = $plgn_NS_SNAutoPoster->nxs_options; $ltype=strtolower($type);
if ($nxs_tpWMPU=='S') { switch_to_blog(1); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster(); $options = $plgn_NS_SNAutoPoster->nxs_options; restore_current_blog(); }
if (!isset($options['nxsHTDP']) || $options['nxsHTDP']=='S') { if(isset($_POST["snapEdIT"]) && $_POST["snapEdIT"]=='1') { $publtype='S'; $delay = rand(2,10); } else $publtype='A'; } else $publtype = 'I';
nxs_addToLogN('BG', 'Start =- ', '', '------=========#### NEW AUTO-POST REQUEST '.($blog_id>1?'BlogID:'.$blog_id:'').' PostID:('.$postID.') '.($publtype=='S'?'Scheduled +'.$delay:($publtype=='A'?'Non Human':'Immediate')).' ####=========------');
$post = get_post($postID); $args=array( 'public' => true, '_builtin' => false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) $post_types=get_post_types($args, $output, $operator);
$snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted=='1') { nxs_addToLogN('W', 'Skipped', '', 'Already Autoposted - Post ID:('.$postID.')' ); return; }
$snap_isEdIT = get_post_meta($postID, 'snapEdIT', true); if ($snap_isEdIT!='1') { $doPost = true; $exclCats = maybe_unserialize($options['exclCats']); $postCats = wp_get_post_categories($postID);
foreach ($postCats as $pCat) { if ( (is_array($exclCats)) && in_array($pCat, $exclCats)) $doPost = false; else {$doPost = true; break;}}
if (!$doPost) { nxs_addToLogN('I', 'Skipped', '', 'Non-Human Post - Category Excluded - Post ID:('.$postID.')' ); return; }
}
if ($options['nxsCPTSeld']!='') $nxsCPTSeld = unserialize($options['nxsCPTSeld']); else $nxsCPTSeld = array_keys($post_types); //prr($nxsCPTSeld);
if ($post->post_type == 'post'|| ($options['useForPages']=='1' && $post->post_type == 'page') || in_array($post->post_type, $post_types) && in_array($post->post_type, $nxsCPTSeld)) foreach ($nxs_snapAvNts as $avNt) {
if (count($options[$avNt['lcode']])>0) { $clName = 'nxs_snapClass'.$avNt['code'];
if ($isPost && isset($_POST[$avNt['lcode']])) $po = $_POST[$avNt['lcode']]; else { $po = get_post_meta($postID, 'snap'.$avNt['code'], true); $po = maybe_unserialize($po);}
if (isset($po) && is_array($po)) $isPostMeta = true; else { $isPostMeta = false; $po = $options[$avNt['lcode']]; }
delete_post_meta($postID, 'snap_isAutoPosted'); add_post_meta($postID, 'snap_isAutoPosted', '1');
$optMt = $options[$avNt['lcode']][0]; if ($isPostMeta) { $ntClInst = new $clName(); $optMt = $ntClInst->adjMetaOpt($optMt, $po[0]); }
if ($snap_isEdIT!='1') { $doPost = true;
if ( $optMt['catSel']=='1' && trim($optMt['catSelEd'])!='' ) { $inclCats = explode(',',$optMt['catSelEd']); foreach ($postCats as $pCat) { if (!in_array($pCat, $inclCats)) $doPost = false; else {$doPost = true; break;}}
if (!$doPost) { nxs_addToLogN('I', 'Skipped', $avNt['name'].' ('.$optMt['nName'].')', '[Non-Human Post] - Individual Category Excluded - Post ID:('.$postID.')' ); return; }
}
}
if ($optMt['do'.$avNt['code']]=='1') { $optMt['ii'] = 0;
if ($publtype=='A' && ($optMt['nMin']>0 || $optMt['nHrs']>0 || $optMt['nTime']!='')) $publtype='S';
if ($publtype=='S') { if (isset($optMt['nHrs']) && isset($optMt['nMin']) && ($optMt['nHrs']>0 || $optMt['nMin']>0) ) { $delay = $optMt['nMin']*60+$optMt['nHrs']*3600;
nxs_addToLogN('I', 'Delayed', $avNt['name'].' ('.$optMt['nName'].')', 'Post has been delayed for '.$delay.' Seconds ('.($optMt['nHrs']>0?$optMt['nHrs'].' Hours':'')." ".($optMt['nMin']>0?$optMt['nMin'].' Minutes':'').')' );
} else $delay = rand(2,10); $optMt['timeToRun'] = time()+$delay; $args = array($postID, $optMt); wp_schedule_single_event($optMt['timeToRun'],'ns_doPublishTo'.$avNt['code'], $args);
nxs_addToLogN('BI', 'Scheduled', $avNt['name'].' ('.$optMt['nName'].')', ' PostID:('.$postID.')' );
} else { $fname = 'nxs_doPublishTo'.$avNt['code']; $fname($postID, $optMt); }
} else { nxs_addToLogN('GR', 'Skipped', $avNt['name'].' ('.$optMt['nName'].')', '-=[Unchecked Account]=- - PostID:'.$postID.'' ); }
}
}
} if ($isS) restore_current_blog();
}}
//## AJAX to Post to Google+
//## Add settings link to plugins list
if (!function_exists("ns_add_settings_link")) { function ns_add_settings_link($links, $file) {
static $this_plugin;
if (!$this_plugin) $this_plugin = plugin_basename(__FILE__);
if ($file == $this_plugin){
$settings_link = '
'.__("Settings", "default").' ';
array_unshift($links, $settings_link);
}
return $links;
}}
//## Actions and filters
if (!function_exists("ns_custom_types_setup")) { function ns_custom_types_setup(){ global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
$args=array('public'=>true, '_builtin'=>false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) $post_types=get_post_types($args, $output, $operator);
if ( isset($options['nxsCPTSeld']) && $options['nxsCPTSeld']!='') $nxsCPTSeld = unserialize($options['nxsCPTSeld']); else $nxsCPTSeld = array_keys($post_types); //prr($nxsCPTSeld);
foreach ($post_types as $cptID=>$cptName) if (in_array($cptID, $nxsCPTSeld)){ // echo "|".$cptID."|";
add_action('future_to_publish_'.$cptID, 'nxs_snapPublishTo');
add_action('new_to_publish_'.$cptID, 'nxs_snapPublishTo');
add_action('draft_to_publish_'.$cptID, 'nxs_snapPublishTo');
add_action('pending_to_publish_'.$cptID, 'nxs_snapPublishTo');
add_action('private_to_publish_'.$cptID, 'nxs_snapPublishTo');
add_action('auto-draft_to_publish_'.$cptID, 'nxs_snapPublishTo');
}
}}
//## Process Spin
if (!function_exists("nxs_spinRecursion")) { function nxs_spinRecursion(&$txt, $startCh) { global $nxs_spin_lCh, $nxs_spin_rCh, $nxs_spin_splCh; $startPos = $startCh;
while ($startCh++ < strlen($txt)) {
if (substr($txt, $startCh, strlen($nxs_spin_lCh)) == $nxs_spin_lCh) $txt = nxs_spinRecursion($txt, $startCh);
elseif (substr($txt, $startCh, strlen($nxs_spin_rCh)) == $nxs_spin_rCh) {
$tmpTxt = substr($txt, $startPos+strlen($nxs_spin_lCh), ($startCh - $startPos)-strlen($nxs_spin_rCh));
$toRepl = nxs_spinReplace($tmpTxt); $txt = str_replace($nxs_spin_lCh.$tmpTxt.$nxs_spin_rCh, $toRepl, $txt);
}
} return $txt;
}}
if (!function_exists("nxs_spinReplace")) { function nxs_spinReplace($txt) { global $nxs_spin_splCh; $txt = explode($nxs_spin_splCh, $txt); $out = $txt[mt_rand(0,count($txt)-1)]; return $out; }}
if (!function_exists("nxs_doSpin")) { function nxs_doSpin($msg){ global $nxs_spin_lCh, $nxs_spin_rCh, $nxs_spin_splCh;
$nxs_spin_lCh = '{'; $nxs_spin_rCh='}'; $nxs_spin_splCh='|'; $msg = nxs_spinRecursion($msg, -1); return $msg;
}}
//## Format Message
if (!function_exists("nsFormatMessage")) { function nsFormatMessage($msg, $postID, $addURLParams=''){ global $ShownAds, $plgn_NS_SNAutoPoster, $nxs_urlLen; $post = get_post($postID); $options = $plgn_NS_SNAutoPoster->nxs_options;
// if ($addURLParams=='' && $options['addURLParams']!='') $addURLParams = $options['addURLParams'];
$msg = stripcslashes($msg); if (isset($ShownAds)) $ShownAdsL = $ShownAds; // $msg = htmlspecialchars(stripcslashes($msg));
$msg = nxs_doSpin($msg);
if (preg_match('%URL%', $msg)) { $url = get_permalink($postID); if($addURLParams!='') $url .= (strpos($url,'?')!==false?'&':'?').$addURLParams; $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%URL%", $url, $msg);}
if (preg_match('%SURL%', $msg)) { $url = get_permalink($postID); if($addURLParams!='') $url .= (strpos($url,'?')!==false?'&':'?').$addURLParams;
$url = nxs_mkShortURL($url, $postID); $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%SURL%", $url, $msg);
}
if (preg_match('%IMG%', $msg)) { $imgURL = nxs_getPostImage($postID); $msg = str_ireplace("%IMG%", $imgURL, $msg); }
if (preg_match('%TITLE%', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $msg = str_ireplace("%TITLE%", $title, $msg); }
if (preg_match('%STITLE%', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $title = substr($title, 0, 115); $msg = str_ireplace("%STITLE%", $title, $msg); }
if (preg_match('%AUTHORNAME%', $msg)) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun ); $msg = str_ireplace("%AUTHORNAME%", $aun, $msg);}
if (preg_match('%ANNOUNCE%', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng);
if (stripos($postContent, '')!==false) { $postContentEx = explode('',$postContent); $postContent = $postContentEx[0]; }
elseif (stripos($postContent, '<!--more-->')!==false) { $postContentEx = explode('<!--more-->',$postContent); $postContent = $postContentEx[0]; }
else $postContent = nsTrnc($postContent, $options['anounTagLimit']); $msg = str_ireplace("%ANNOUNCE%", $postContent, $msg);
}
if (preg_match('%TEXT%', $msg)) {
if ($post->post_excerpt!="") $excerpt = apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng)); else $excerpt= apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
$excerpt = nsTrnc(strip_tags(strip_shortcodes($excerpt)), 300, " ", "..."); $msg = str_ireplace("%TEXT%", $excerpt, $msg);
}
if (preg_match('%EXCERPT%', $msg)) {
if ($post->post_excerpt!="") $excerpt = apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng)); else $excerpt= apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
$excerpt = nsTrnc(strip_tags(strip_shortcodes($excerpt)), 300, " ", "..."); $msg = str_ireplace("%EXCERPT%", $excerpt, $msg);
}
if (preg_match('%RAWEXTEXT%', $msg)) {
if ($post->post_excerpt!="") $excerpt = nxs_doQTrans($post->post_excerpt, $lng); else $excerpt= nxs_doQTrans($post->post_content, $lng);
$excerpt = nsTrnc(strip_tags(strip_shortcodes($excerpt)), 300, " ", "..."); $msg = str_ireplace("%RAWEXTEXT%", $excerpt, $msg);
}
if (preg_match('%RAWEXCERPT%', $msg)) {
if ($post->post_excerpt!="") $excerpt = nxs_doQTrans($post->post_excerpt, $lng); else $excerpt= nxs_doQTrans($post->post_content, $lng);
$excerpt = nsTrnc(strip_tags(strip_shortcodes($excerpt)), 300, " ", "..."); $msg = str_ireplace("%RAWEXCERPT%", $excerpt, $msg);
}
if (preg_match('%TAGS%', $msg)) { $t = wp_get_object_terms($postID, 'product_tag'); if ( empty($t) || is_wp_error($pt) || !is_array($t) ) $t = wp_get_post_tags($postID);
$tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode(', ',$tggs); $msg = str_ireplace("%TAGS%", $tags, $msg);
}
if (preg_match('%CATS%', $msg)) { $t = wp_get_post_categories($postID); $cats = array(); foreach($t as $c){ $cat = get_category($c); $cats[] = str_ireplace('&','&',$cat->name); }
$ctts = implode(', ',$cats); $msg = str_ireplace("%CATS%", $ctts, $msg);
}
if (preg_match('%HCATS%', $msg)) { $t = wp_get_post_categories($postID); $cats = array();
foreach($t as $c){ $cat = get_category($c); $cats[] = "#".trim(str_replace(' ','', str_replace(' ', '', trim(str_ireplace('&','',str_ireplace('&','',$cat->name)))))); }
$ctts = implode(', ',$cats); $msg = str_ireplace("%HCATS%", $ctts, $msg);
}
if (preg_match('%HTAGS%', $msg)) { $t = wp_get_object_terms($postID, 'product_tag'); if ( empty($t) || is_wp_error($pt) || !is_array($t) ) $t = wp_get_post_tags($postID);
$tggs = array(); foreach ($t as $tagA) {$tggs[] = "#".trim(str_replace(' ','',preg_replace('/[^a-zA-Z0-9\p{L}\p{N}\s]/u', '', trim(ucwords(str_ireplace('&','',str_ireplace('&','',$tagA->name))))))); }
$tags = implode(', ',$tggs); $msg = str_ireplace("%HTAGS%", $tags, $msg);
}
if (preg_match('%CF-[a-zA-Z0-9]%', $msg)) { $msgA = explode('%CF', $msg); $mout = '';
foreach ($msgA as $mms) {
if (substr($mms, 0, 1)=='-' && stripos($mms, '%')!==false) { $mGr = CutFromTo($mms, '-', '%'); $cfItem = get_post_meta($postID, $mGr, true); $mms = str_ireplace("-".$mGr."%", $cfItem, $mms); } $mout .= $mms;
} $msg = $mout;
}
if (preg_match('%FULLTEXT%', $msg)) { $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)); $msg = str_ireplace("%FULLTEXT%", $postContent, $msg);}
if (preg_match('%RAWTEXT%', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng); $msg = str_ireplace("%RAWTEXT%", $postContent, $msg);}
if (preg_match('%SITENAME%', $msg)) { $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $msg = str_ireplace("%SITENAME%", $siteTitle, $msg);}
if (isset($ShownAds)) $ShownAds = $ShownAdsL; // FIX for the quick-adsense plugin
return trim($msg);
}}
if (!function_exists("nxs_adminInitFunc")) { function nxs_adminInitFunc(){ global $plgn_NS_SNAutoPoster, $nxs_snapThisPageUrl, $pagenow, $nxs_isWPMU;
$nxs_snapThisPageUrl = admin_url().($pagenow=='admin.php'?'network/':'').$pagenow.'?page=NextScripts_SNAP.php';
//## Javascript to Admin Panel
if (( ($pagenow=='options-general.php'||$pagenow=='admin.php') && isset($_GET['page']) && $_GET['page']=='NextScripts_SNAP.php') ||$pagenow=='post.php'||$pagenow=='post-new.php'){add_action('admin_head', 'jsPostToSNAP'); add_action('admin_head', 'nxs_jsPostToSNAP2');}
if (function_exists('nxsDoLic_ajax')) { add_action('wp_ajax_nxsDoLic', 'nxsDoLic_ajax'); }
if (function_exists('nxs_getInitUCheck') && (isset($plgn_NS_SNAutoPoster))) { $options = $plgn_NS_SNAutoPoster->nxs_options; if (is_array($options) && count($options)>1) nxs_getInitUCheck($options); }
}}
if (!function_exists("nxs_adminInitFunc2")) { function nxs_adminInitFunc2(){ global $plgn_NS_SNAutoPoster, $nxs_snapThisPageUrl, $pagenow; $nxs_snapThisPageUrl = admin_url().($pagenow=='admin.php'?'network/':'').$pagenow.'?page=NextScripts_SNAP.php'; //## Add MEtaBox to Post Edit Page
if (current_user_can("see_snap_box") || current_user_can("manage_options")) add_action('add_meta_boxes', array($plgn_NS_SNAutoPoster, 'NS_SNAP_addCustomBoxes'));
}}
function nxs_saveSiteSets_ajax(){ check_ajax_referer('nxssnap');
if ($_POST['sid']=='A'){ global $wpdb; $allBlogs = $wpdb->get_results("SELECT blog_id FROM wp_blogs where blog_id > 1");
foreach( $allBlogs as $aBlog ) { switch_to_blog($aBlog->blog_id); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster();
$options = $plgn_NS_SNAutoPoster->nxs_options; $options['suaMode'] = $_POST['sset']; update_option($plgn_NS_SNAutoPoster->dbOptionsName, $options);
}
} else { switch_to_blog($_POST['sid']); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster();
$options = $plgn_NS_SNAutoPoster->nxs_options; $options['suaMode'] = $_POST['sset']; update_option($plgn_NS_SNAutoPoster->dbOptionsName, $options); // prr($plgn_NS_SNAutoPoster->dbOptionsName); prr($options);
}
}
function nxs_start_ob(){ob_start( 'nxs_ogtgCallback' );}
function nxs_end_flush_ob(){ob_end_flush();}
function nxs_ogtgCallback($content){ global $post, $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options; $ogimgs = array();
if (stripos($content, 'og:title')!==false) $ogOut = "\r\n"; else {
$title = preg_match( '/
(.*)<\/title>/', $content, $title_matches );
if ($title !== false && count( $title_matches) == 2 ) $ogT =' '."\r\n"; else {
if (is_home() || is_front_page() ) $ogT = get_bloginfo( 'name' ); else $ogT = get_the_title();
$ogT = ' '."\r\n";
}
$decsription = preg_match( '/ '."\r\n"; {
if (is_singular()) {
if(has_excerpt($post->ID))$ogD=strip_tags(nxs_snapCleanHTML(get_the_excerpt($post->ID)));else $ogD= str_replace(" ", ' ', str_replace("\r\n", ' ', trim(substr(strip_tags(nxs_snapCleanHTML(strip_shortcodes($post->post_content))), 0, 200))));
} else $ogD = get_bloginfo('description'); $ogD = preg_replace('/\r\n|\r|\n/m','',$ogD);
$ogD = ' '."\r\n";
}
$ogSN = ' '."\r\n";
$ogLoc = strtolower(esc_attr(get_locale())); if (strlen($ogLoc)==2) $ogLoc .= "_".strtoupper($ogLoc);
$ogLoc = ' '."\r\n"; $iss = is_home();
$ogType = is_singular()?'article':'website'; if($vidsFromPost == false) $ogType = ' '."\r\n";
if (is_home() || is_front_page()) $ogUrl = get_bloginfo( 'url' ); else $ogUrl = 'http' . (is_ssl() ? 's' : '') . "://".$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$ogUrl = ' ' . "\r\n";
if (!is_home()) { /*
$vidsFromPost = nsFindVidsInPost($post); if ($vidsFromPost !== false && is_singular()) { echo ' '."\n";
echo ' '."\n";
echo ' '."\n";
echo ' '."\n";
echo ' '."\n";
echo ' '."\n";
} */
if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' ); $ogimgs[] = $thumbnail_src[0];
} $imgsFromPost = nsFindImgsInPost($post, (int)$options['advFindOGImg']==1);
if ($imgsFromPost !== false && is_singular() && is_array($ogimgs) && is_array($imgsFromPost)) $ogimgs = array_merge($ogimgs, $imgsFromPost);
}
//## Add default image to the endof the array
if ( count($ogimgs)<1 && isset($options['ogImgDef']) && $options['ogImgDef']!='') $ogimgs[] = $options['ogImgDef'];
//## Output og:image tags
if (!empty($ogimgs) && is_array($ogimgs)) foreach ($ogimgs as $ogimage) $ogImgsOut = ' '."\r\n";
$ogOut = "\r\n".$ogSN.$ogT.$ogD.$ogType.$ogUrl.$ogLoc.$ogImgsOut;
} $content = str_ireplace('', $ogOut, $content);
return $content;
}
function nxs_addOGTagsPreHolder() { echo "\n\r";}
if (!function_exists("nxssnap_enqueue_scripts")) { function nxssnap_enqueue_scripts(){
wp_enqueue_script( 'nxssnap-scripts', plugin_dir_url( __FILE__ ) . 'js/js.js', array( 'jquery' ) );
wp_localize_script( 'nxssnap-scripts', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nxsnapWPnonce' => wp_create_nonce( 'nxsnapWPnonce' ),));
}}
if (!function_exists("nxs_getExpSettings_ajax")) { function nxs_getExpSettings_ajax() { check_ajax_referer('nsDN'); $filename = preg_replace('/[^a-z0-9\-\_\.]/i','',$_POST['filename']);
header("Cache-Control: "); header("Content-type: text/plain"); header('Content-Disposition: attachment; filename="'.$filename.'"');
global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
echo serialize($options); die();
}}
//## Actions and filters
if (isset($plgn_NS_SNAutoPoster)) { //## Actions
//## Add the admin menu
if ($nxs_isWPMU) add_action('network_admin_menu', 'nxs_AddSUASettings'); $suOptions = array();
$suOptions = $plgn_NS_SNAutoPoster->nxs_options; if ($nxs_isWPMU) { $ntOptions = $plgn_NS_SNAutoPoster->nxs_ntoptions; if (!isset($suOptions['suaMode'])) $suOptions['suaMode'] = ''; }
$isPMB = $nxs_isWPMU && function_exists('nxs_doSMAS1') && $blog_id==1;
$isO = !$nxs_isWPMU || ($nxs_isWPMU && ($suOptions['isMU']||$suOptions['isMUx']) && ($suOptions['suaMode']=='O' || ($suOptions['suaMode']=='' && $ntOptions['nxsSUType']=='O')));
$isS = !$nxs_isWPMU || ($nxs_isWPMU && ($suOptions['isMU']||$suOptions['isMUx']) && ($suOptions['suaMode']=='S' || ($suOptions['suaMode']=='' && $ntOptions['nxsSUType']=='S')));
if ($nxs_isWPMU) { if ($isO) $nxs_tpWMPU = 'O'; elseif ($isS) $nxs_tpWMPU = 'S';} // prr($nxs_tpWMPU); prr($suOptions);
if (function_exists('nxs_doSMAS3')) nxs_doSMAS3($isS, $isO);
if (!$isO && !$isS && !$isPMB) add_action('admin_menu', 'NS_SNAutoPoster_apx');
add_action('admin_init', 'nxs_adminInitFunc');
add_action( 'admin_enqueue_scripts', 'nxssnap_enqueue_scripts' );
add_action('wp_ajax_nxscr', 'nxscr_ajax');
add_action('wp_ajax_nxs_clLgo', 'nxs_clLgo_ajax');
add_action('wp_ajax_nxs_rfLgo', 'nxs_rfLgo_ajax');
add_action('wp_ajax_nxs_prxTest', 'nxs_prxTest_ajax');
add_action('wp_ajax_nxs_prxGet', 'nxs_prxGet_ajax');
add_action('wp_ajax_nxs_getExpSettings', 'nxs_getExpSettings_ajax');
add_action('wp_ajax_nxs_hideTip', 'nxs_hideTip_ajax');
add_action('nxs_hourly_event', 'nxs_do_this_hourly');
add_action('wp', 'nxs_activation');
add_action('shutdown', 'nxs_psCron');
if ($isO || $isS) {
//## Whenever you publish a post, post to Social Networks
add_action('future_to_publish', 'nxs_snapPublishTo');
add_action('new_to_publish', 'nxs_snapPublishTo');
add_action('draft_to_publish', 'nxs_snapPublishTo');
add_action('pending_to_publish', 'nxs_snapPublishTo');
add_action('private_to_publish', 'nxs_snapPublishTo');
add_action('auto-draft_to_publish', 'nxs_snapPublishTo');
//## Add nxs_snapPublishTo to custom post types
add_action('wp_loaded', 'ns_custom_types_setup' );
foreach ($nxs_snapAvNts as $avNt) { add_action('ns_doPublishTo'.$avNt['code'], 'nxs_doPublishTo'.$avNt['code'], 1, 2); }
foreach ($nxs_snapAvNts as $avNt) { add_action('wp_ajax_rePostTo'.$avNt['code'], 'nxs_rePostTo'.$avNt['code'].'_ajax'); }
//## Add AJAX Calls for Test and Repost
add_action('wp_ajax_getBoards' , 'nsGetBoards_ajax');
add_action('wp_ajax_getGPCats' , 'nsGetGPCats_ajax');
add_action('wp_ajax_getWLBoards' , 'nsGetWLBoards_ajax');
add_action('wp_ajax_nsDN', 'ns_delNT_ajax');
}
if ($isO) {
add_action('admin_menu', 'NS_SNAutoPoster_ap');
add_action('admin_init', 'nxs_adminInitFunc2');
//## Initialize options on plugin activation
$myrelpath = preg_replace( '/.*wp-content.plugins./', '', __FILE__ );
add_action("activate_".$myrelpath, array(&$plgn_NS_SNAutoPoster, 'init'));
//## Add/Change meta on Save
add_action('edit_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
add_action('publish_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
add_action('save_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
add_action('edit_page_form', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
add_action('wp_ajax_nsAuthFBSv', 'nsAuthFBSv_ajax');
//## Custom Post Types and OG tags
add_filter('plugin_action_links','ns_add_settings_link', 10, 2 );
add_filter('get_avatar','ns_get_avatar', 10, 5 );
//## Scedulled Publish Calls
if ((int)$suOptions['nsOpenGraph'] == 1) {
add_action( 'init', 'nxs_start_ob', 0 );
add_action( 'wp_footer', 'nxs_end_flush_ob', 10000 );
add_action('wp_head', 'nxs_addOGTagsPreHolder', 150);
}
}
if ($nxs_isWPMU){
if (function_exists('nxssnapmu_columns_head')) add_filter('wpmu_blogs_columns', 'nxssnapmu_columns_head');
if (function_exists('nxssnapmu_columns_content')) add_action('manage_blogs_custom_column', 'nxssnapmu_columns_content', 10, 2);
if (function_exists('nxssnapmu_columns_content')) add_action('manage_sites_custom_column', 'nxssnapmu_columns_content', 10, 2);
if (function_exists('nxs_add_style')) add_action( 'admin_footer', 'nxs_add_style' );
if (function_exists('nxs_saveSiteSets_ajax')) add_action('wp_ajax_nxs_saveSiteSets', 'nxs_saveSiteSets_ajax');
}
}
?>