nxs_class_SNAP_PN

The NextScripts: Social Networks Auto-Poster nxs class SNAP PN class.

Defined (1)

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

/inc-cl/pn.api.php  
  1. if (!class_exists("nxs_class_SNAP_PN")) { class nxs_class_SNAP_PN { 
  2.  
  3. var $ntCode = 'PN'; 
  4. var $ntLCode = 'pn';  
  5.  
  6. function doPost($options, $message) { if (!is_array($options)) return false; $out = array(); 
  7. foreach ($options as $ii=>$ntOpts) $out[$ii] = $this->doPostToNT($ntOpts, $message); 
  8. return $out; 
  9. }  
  10. function doPostToNT($options, $message) { global $nxs_gCookiesArr; $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); 
  11. //## Check settings 
  12. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }  
  13. if (!isset($options['pnUName']) || trim($options['pnPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }  
  14. $pass = substr($options['pnPass'], 0, 5)=='g9c1a'?nsx_doDecode(substr($options['pnPass'], 5)):$options['pnPass']; 
  15. if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  16. //## Format 
  17. if (!empty($message['pText'])) $msg = $message['pText']; else $msg = nxs_doFormatMsg($options['pnMsgFormat'], $message); $boardID = $options['pnBoard']; // prr($boardID); prr($_POST); die();  
  18. if (isset($message['imageURL'])) $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize'])); else $imgURL = ''; if ($imgURL=='') $badOut['Error'] .= 'NO Image.'; 
  19. $urlToGo = (!empty($message['url']))?$message['url']:''; 
  20. //## Check for existing session  
  21. if (isset($options['ck'])) $nxs_gCookiesArr = maybe_unserialize( $options['ck']); $loginError = true; if (is_array($nxs_gCookiesArr)) $loginError = doCheckPinterest();  
  22. if ($loginError!==false) $loginError = doConnectToPinterest($options['pnUName'], $pass); if ($loginError!==false) { $badOut['Error'] = print_r($loginError, true)." - BAD USER/PASS"; return $badOut; }  
  23. if (preg_match ( '/\$(\d+\.\d+)/', $msg, $matches )) $price = $matches[0]; else $price = ''; 
  24.  
  25. if (isset($options['cImgURL']) && $options['cImgURL']=='S' ) $urlToGo = nxs_mkShortURL($urlToGo); elseif (isset($options['cImgURL']) && $options['cImgURL']=='N' ) $urlToGo = ''; 
  26.  
  27. $ret = doPostToPinterest($msg, $imgURL, $urlToGo, $boardID, 'TITLE WHERE IS IT?', $price, $urlToGo."/GTH/" ); if ($ret=='OK') $ret = array("code"=>"OK", "post_id"=>''); 
  28. //prr($ret); 
  29. if (is_array($ret) && !empty($ret['post_id'])) return array('postID'=>str_ireplace('/pin/', '', $ret['post_id']), 'isPosted'=>1, 'postURL'=>$ret['post_url'], 'pDate'=>date('Y-m-d H:i:s'));  
  30. else $badOut['Error'] .= 'Something went wrong - '.print_r($ret, true);  
  31. return $badOut;  
  32. }  
  33. }}