nxs_doNewNPPost

The NextScripts: Social Networks Auto-Poster nxs doNewNPPost function.

Description

nxs_doNewNPPost( $options ); 

Parameters (1)

0. $options
The options.

Usage

  1. if ( !function_exists( 'nxs_doNewNPPost' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/NextScripts_SNAP.php'; 
  3.  
  4. // The options. 
  5. $options = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = nxs_doNewNPPost($options); 
  9.  

Defined (1)

The function is defined in the following location(s).

/NextScripts_SNAP.php  
  1. function nxs_doNewNPPost($options) { global $nxs_snapAvNts, $nxs_plurl; $postResults = ''; 
  2. if (!empty($_POST['mNts']) && is_array($_POST['mNts'])) { nxs_addToLogN('S', '-=== New Form Post requested ===-', 'Form', count($_POST['mNts']).' Networks', print_r($_POST['mNts'], true)); 
  3. $message = array('title'=>'', 'text'=>'', 'siteName'=>'', 'url'=>'', 'imageURL'=>'', 'videoURL'=>'', 'tags'=>'', 'urlDescr'=>'', 'urlTitle'=>'');  
  4. if (get_magic_quotes_gpc() || $_POST['nxs_mqTest']=="\'") { $_POST['mText'] = stripslashes($_POST['mText']); $_POST['mTitle'] = stripslashes($_POST['mTitle']); } 
  5. $message['pText'] = $_POST['mText']; $message['pTitle'] = $_POST['mTitle']; 
  6. //## Get URL info 
  7. if (!empty($_POST['mLink']) && substr($_POST['mLink'], 0, 4)=='http') { $message['url'] = $_POST['mLink'];  
  8. $flds = array('id'=>$message['url'], 'scrape'=>'true'); $response = wp_remote_post('https://graph.facebook.com/v2.3/', array('body' => $flds));  
  9. if (is_wp_error($response)) $badOut['Error'] = print_r($response, true)." - ERROR"; else { $response = json_decode($response['body'], true);  
  10. if (!empty($response['description'])) $message['urlDescr'] = $response['description']; if (!empty($response['title'])) $message['urlTitle'] = $response['title']; 
  11. if (!empty($response['site_name'])) $message['siteName'] = $response['site_name']; 
  12. if (!empty($response['image'][0]['url'])) $message['imageURL'] = $response['image'][0]['url']; 
  13. if (!empty($_POST['mImg']) && substr($_POST['mImg'], 0, 4)=='http') $message['imageURL'] = $_POST['mImg'];  
  14.  
  15. foreach ($_POST['mNts'] as $ntC) { $ntA = explode('--', $ntC); $ntOpts = $options[$ntA[0]][$ntA[1]];  
  16. if (!empty($ntOpts) && is_array($ntOpts)) { $logNT = $ntA[0]; $clName = 'nxs_class_SNAP_'.strtoupper($logNT);  
  17. $logNT = '<span style="color:#800000">'.strtoupper($logNT).'</span> - '.$ntOpts['nName'];  
  18. $ntOpts['postType'] = $_POST['mType']; $ntToPost = new $clName(); $ret = $ntToPost->doPostToNT($ntOpts, $message);  
  19. if (!is_array($ret) || $ret['isPosted']!='1') { //## Error  
  20. nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), ''); $postResults .= $logNT ." - Error (Please see log)<br/>"; 
  21. } else { // ## All Good - log it.  
  22. if (!empty($ret['postURL'])) $extInfo = '<a href="'.$ret['postURL'].'" target="_blank">Post Link</a>';  
  23. nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); $postResults .= $logNT ." - OK - ".$extInfo."<br/>";  
  24. } echo "Done. Results:<br/> ".$postResults; }