/inc-cl/fp.api.php

  1. <?php  
  2. //## NextScripts Flipboard Connection Class 
  3.  
  4. /**  
  5. 1. Options 
  6.   
  7. nName - Nickname of the account [Optional] (Presentation purposes only - No affect on functionality) 
  8. rdUName - Reddit User Name 
  9. rdPass - Reddit User Passord 
  10. rdSubReddit - Name of the Sub-Reddit 
  11. postType - A or T - "Attached link" or "Text" 
  12.   
  13. rdTitleFormat 
  14. rdTextFormat 
  15.   
  16. 2. Post Info 
  17.   
  18. url 
  19. title - [up to 300 characters long] - title of the submission 
  20. text 
  21.   
  22. */ 
  23. $nxs_snapAPINts[] = array('code'=>'FP', 'lcode'=>'fp', 'name'=>'Flipboard'); 
  24.  
  25. if (!function_exists("nxs_getFPHeaders")) { function nxs_getFPHeaders($ref, $org='', $post=false, $aj=false) { $hdrsArr = array();  
  26. $hdrsArr['Cache-Control']='max-age=0'; $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref; 
  27. $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.22 Safari/537.36';  
  28. if($post==='j') $hdrsArr['Content-Type']='application/json;charset=UTF-8'; elseif($post===true) $hdrsArr['Content-Type']='application/x-www-form-urlencoded'; 
  29. if($aj===true) $hdrsArr['X-Requested-With']='XMLHttpRequest'; if ($org!='') $hdrsArr['Origin']=$org;  
  30. $hdrsArr['Accept']='text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8';// $hdrsArr['DNT']='1'; 
  31. if (function_exists('gzdeflate')) $hdrsArr['Accept-Encoding']='gzip, deflate, sdch';  
  32. $hdrsArr['Accept-Language']='en-US, en;q=0.8'; return $hdrsArr;  
  33. }} 
  34.  
  35. if (!class_exists("nxs_class_SNAP_FP")) { class nxs_class_SNAP_FP { 
  36.  
  37. var $ntCode = 'FP'; 
  38. var $ntLCode = 'fp'; 
  39.  
  40. function createFile($imgURL) { 
  41. $remImgURL = urldecode($imgURL); $urlParced = pathinfo($remImgURL); $remImgURLFilename = $urlParced['basename'];  
  42. $imgData = wp_remote_get($remImgURL); if (is_wp_error($imgData)) { $badOut['Error'] = print_r($imgData, true)." - ERROR"; return $badOut; }  
  43. $imgData = $imgData['body']; 
  44. $tmp=array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile())));  
  45. if (!is_writable($tmp)) return "Your temporary folder or file (file - ".$tmp.") is not witable. Can't upload images to Flickr"; 
  46. rename($tmp, $tmp.='.png'); register_shutdown_function(create_function('', "unlink('{$tmp}');"));  
  47. file_put_contents($tmp, $imgData); if (!$tmp) return 'You must specify a path to a file'; if (!file_exists($tmp)) return 'File path specified does not exist'; 
  48. if (!is_readable($tmp)) return 'File path specified is not readable';  
  49. // $data['name'] = basename($tmp); 
  50. return "@$tmp"; 
  51.  
  52.  
  53. function doPost($options, $message) { if (!is_array($options)) return false; $out = array(); // return false; 
  54. foreach ($options as $ii=>$ntOpts) $out[$ii] = $this->doPostToNT($ntOpts, $message); 
  55. return $out; 
  56.  
  57. function doPostToNT($options, $message) { global $nxs_urlLen; $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); 
  58. //## Check settings 
  59. if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }  
  60. if (!isset($options['uPass']) || trim($options['uPass'])=='') { $badOut['Error'] = 'Not Authorized'; return $badOut; }  
  61. if (empty($options['imgSize'])) $options['imgSize'] = ''; 
  62. //## Format Post 
  63. if (!empty($message['pText'])) $text = $message['pText']; else $text = nxs_doFormatMsg($options['msgFrmt'], $message);  
  64. //## Make Post  
  65. if (isset($message['imageURL'])) $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize'])); else $imgURL = '';  
  66. //## Make Post  
  67. if (!empty($options['ck'])) {$ck = maybe_unserialize($options['ck']); $loginError = doCheckFlipboard($ck);} 
  68. if (empty($ck) || $loginError!==false) { $pass = substr($options['uPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['uPass'], 5)):$options['uPass'];  
  69. $loginInfo = doConnectToFlipboard($options['uName'], $pass); if (!is_array($loginInfo)) { $badOut['Error'] = print_r($loginInfo, true)." - ERROR"; return $badOut; } $ck = $loginInfo['ck'];  
  70. } $post = array('url'=>$message['url'], 'mgzURL'=>$options['mgzURL'], 'imgURL'=>$imgURL, 'text'=>$text ); 
  71. return doPostToFlipboard($ck, $post);  
  72. }  
  73. }} 
  74. ?> 
.