nxs_class_SNAP_FL

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

Defined (1)

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

/inc-cl/fl.api.php  
  1. if (!class_exists("nxs_class_SNAP_FL")) { class nxs_class_SNAP_FL { 
  2.  
  3. var $ntCode = 'FL'; 
  4. var $ntLCode = 'fl'; 
  5.  
  6. function createFile($imgURL) { 
  7. $remImgURL = urldecode($imgURL); $urlParced = pathinfo($remImgURL); $remImgURLFilename = $urlParced['basename']; 
  8. $imgData = wp_remote_get($remImgURL, array('timeout' => 45)); if (is_wp_error($imgData)) { $badOut['Error'] = print_r($imgData, true)." - ERROR"; return $badOut; } 
  9. if (isset($imgData['content-type'])) $cType = $imgData['content-type']; $imgData = $imgData['body']; 
  10. $tmp=array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile()))); 
  11. if (!is_writable($tmp)) { $badOut['Error'] = "Your temporary folder or file (file - ".$tmp.") is not witable. Can't upload images to Flickr"; return $badOut; } 
  12. rename($tmp, $tmp.='.png'); register_shutdown_function(create_function('', "unlink('{$tmp}');")); 
  13. file_put_contents($tmp, $imgData); if (!$tmp) { $badOut['Error'] = 'You must specify a path to a file'; return $badOut; } 
  14. if (!file_exists($tmp)) { $badOut['Error'] = 'File path specified does not exist'; return $badOut; } 
  15. if (!is_readable($tmp)) { $badOut['Error'] = 'File path specified is not readable'; return $badOut; } 
  16. $cfile = curl_file_create($tmp, $cType, 'nxstmp'); return $cfile; 
  17.  
  18. function doPost($options, $message) { if (!is_array($options)) return false; $out = array(); // return false; 
  19. foreach ($options as $ii=>$ntOpts) $out[$ii] = $this->doPostToNT($ntOpts, $message); 
  20. return $out; 
  21.  
  22. function doPostToNT($options, $message) { global $nxs_urlLen; $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); 
  23. //## Check settings 
  24. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; } 
  25. if (!isset($options['accessToken']) || trim($options['accessToken'])=='') { $badOut['Error'] = 'Not Authorized'; return $badOut; } 
  26. if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  27. //## Format Post 
  28. if (!empty($message['pText'])) $text = $message['pText']; else $text = nxs_doFormatMsg($options['msgFrmt'], $message); 
  29. if (!empty($message['pTitle'])) $msgT = $message['pTitle']; else $msgT = nxs_doFormatMsg($options['msgTFrmt'], $message); 
  30. //## Make Post 
  31. if (isset($message['imageURL'])) $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize'])); else $imgURL = ''; $postType = $options['postType']; 
  32.  
  33. if (empty($imgURL)) { $badOut['Error'] = 'No Image. Flickr is an image-sharing network. You can\'t post to Flickr without image.'; return $badOut; } 
  34.  
  35. require_once('apis/scOAuth.php'); $tum_oauth = new wpScoopITOAuth($options['appKey'], $options['appSec'], $options['accessToken'], $options['accessTokenSec']); 
  36. $tum_oauth->baseURL = 'https://www.flickr.com/services'; $tum_oauth->request_token_path = '/oauth/request_token'; $tum_oauth->access_token_path = '/oauth/access_token'; 
  37.  
  38. $tags = $message['tags']; $postArr = array('title'=>$msgT, 'description'=>$text, 'tags'=>$tags, 'is_public'=>1, 'safety_level'=>1, 'content_type'=>1, 'hidden'=>1); 
  39. $imgFile = $this->createFile($imgURL); if (empty($imgFile) || is_array($imgFile)) { $badOut['Error'] = 'Image Error - '.print_r($imgFile, true); return $badOut; } 
  40.  
  41. $phiID = $tum_oauth->flUploadPhoto($imgFile, $postArr); // prr($phiID); 
  42.  
  43. if (!empty($phiID) && strpos($phiID, 'Problem: ')===false) { 
  44. $params = array ('format' => 'php_serial', 'method'=>'flickr.photosets.addPhoto', 'photo_id'=>$phiID, 'photoset_id'=>$options['setID']); 
  45. $uinfo = $tum_oauth->makeReq('https://api.flickr.com/services/rest/', $params); 
  46.  
  47. if (!empty($message['latitude']) && !empty($message['longitude'])) { 
  48.  
  49. $params = array ( 
  50. 'format' => 'php_serial',  
  51. 'method'=>'flickr.photos.geo.setLocation',  
  52. 'photo_id'=>$phiID,  
  53. 'lat'=>$message['latitude'],  
  54. 'lon'=>$message['longitude'],  
  55. ); 
  56.  
  57. $uinfo = $tum_oauth->makeReq('https://api.flickr.com/services/rest/', $params); 
  58.  
  59.  
  60. if (!empty($phiID) && strpos($phiID, 'Problem: ')===false) { 
  61. return array('postID'=>$phiID, 'isPosted'=>1, 'postURL'=> str_ireplace('people', 'photos', $options['userURL']).$phiID, 'pDate'=>date('Y-m-d H:i:s')); 
  62. } else { $badOut['Error'] .= print_r($phiID, true)." Code:".$tum_oauth->http_code; 
  63. return $badOut; 
  64. return $badOut; 
  65.  
  66. }}