/** * Returns Facebook Post * * @param string * @return Eden_Facebook_Post */ public function post($message) { return Eden_Facebook_Post::i($this->_token, $message); }
if(!class_exists('Eden_Facebook_Graph')){class Eden_Facebook_Graph extends Eden_Class{const GRAPH_URL='https://graph.facebook.com/';const LOGOUT_URL='https://www.facebook.com/logout.php?next=%s&access_token=%s';protected $_token=NULL;protected $_list=array( 'Friends','Home','Feed','Likes','Movies','Music','Books','Photos','Albums','Videos','VideoUploads','Events','Groups','Checkins');protected $_search=array( 'Posts','Users','Pages','Likes','Places','Events','Groups','Checkins');public static function i(){return self::_getMultiple(__CLASS__);}public function __call($name,$args){if(strpos($name,'get')===0 && in_array(substr($name,3),$this->_list)){$key=preg_replace("/([A-Z])/","/$1",$name);$key=strtolower(substr($key,4));$id='me';if(!empty($args)){$id=array_shift($args);}array_unshift($args,$id,$key);return call_user_func_array(array($this,'_getList'),$args);}else if(strpos($name,'search')===0 && in_array(substr($name,6),$this->_search)){$key=strtolower(substr($name,6));array_unshift($args,$key);return call_user_func_array(array($this,'_search'),$args);}}public function __construct($token){$this->_token=$token;}public function addAlbum($id,$name,$message){Eden_Facebook_Error::i()->argument(1,'string','int')->argument(2,'string')->argument(3,'string');$url=self::GRAPH_URL.$id.'/albums';$post=array('name'=>$name,'message'=>$message);$query=array('access_token'=>$this->_token);$url.='?'.http_build_query($query);$results=json_decode($this->_call($url,$post),true);return $results['id'];}public function addComment($id,$message){Eden_Facebook_Error::i()->argument(1,'int')->argument(2,'string');$url=self::GRAPH_URL.$id.'/comments';$post=array('message'=>$message);$query=array('access_token'=>$this->_token);$url.='?'.http_build_query($query);$results=json_decode($this->_call($url,$post),true);return $results['id'];}public function attendEvent($id){Eden_Facebook_Error::i()->argument(1,'int');$url=self::GRAPH_URL.$id.'/attending';$query=array('access_token'=>$this->_token);$url.='?'.http_build_query($query);json_decode($this->_call($url),true);return $this;}public function checkin($id,$message,$latitude,$longitude,$place,$tags){Eden_Facebook_Error::i()->argument(1,'string','int')->argument(2,'string')->argument(3,'float')->argument(4,'float')->argument(5,'int')->argument(6,'string','array');$url=self::GRAPH_URL.$id.'/checkins';$post=array('message'=>$message);$query=array('access_token'=>$this->_token);$url.='?'.http_build_query($query);if($message){$post['message']=$message;}if($latitude && $longitute){$post['coordinates']=json_encode(array( 'latitude'=>$latitude,'longitude'=>$longitude));}if($place){$post['place']=$place;}if($tags){$post['tags']=$tags;}$results=json_decode($this->_call($url,$post),true);return $results['id'];}public function createNote($id='me',$subject,$message){Eden_Facebook_Error::i()->argument(1,'string','int')->argument(2,'string')->argument(3,'string');$url=self::GRAPH_URL.$id.'/notes';$post=array('subject'=>$subject,'message'=>$message);$query=array('access_token'=>$this->_token);$url.='?'.http_build_query($query);$results=json_decode($this->_call($url,$post),true);return $results['id'];}public function declineEvent($id){Eden_Facebook_Error::i()->argument(1,'int');$url=self::GRAPH_URL.$id.'/declined';$query=array('access_token'=>$this->_token);$url.='?'.http_build_query($query);json_decode($this->_call($url),true);return $this;}public function event($name,$start,$end){return Eden_Facebook_Event::i($this->_token,$name,$start,$end);}public function getFields($id='me',$fields){Eden_Facebook_Error::i()->argument(1,'string','int')->argument(2,'string','array');if(is_array($fields)){$fields=implode(',',$fields);}return $this->getObject($id,NULL,array('fields'=>$fields));}public function getLogoutUrl($redirect){Eden_Facebook_Error::i()->argument(1,'url');return sprintf(self::LOGOUT_URL,urlencode($redirect),$this->_token);}public function getObject($id='me',$connection=NULL,array $query=array(),$auth=true){Eden_Facebook_Error::i()->argument(1,'string','int')->argument(2,'string','null')->argument(3,'array')->argument(4,'bool');if($connection){$connection='/'.$connection;}$url=self::GRAPH_URL.$id.$connection;if($auth){$query['access_token']=$this->_token;}if(!empty($query)){$url.='?'.http_build_query($query);}$object=$this->_call($url);$object=json_decode($object,true);if (isset($object['error'])){Eden_Facebook_Error::i()->setMessage(Eden_Facebook_Error::GRAPH_FAILED)->addVariable($url)->addVariable($object['error']['type'])->addVariable($object['error']['message'])->trigger();}return $object;}public function getPermissions($id='me'){Eden_Facebook_Error::i()->argument(1,'string','int');$permissions=$this->getObject($id,'permissions');return $permissions['data'];}public function getPictureUrl($id='me',$token=true){Eden_Facebook_Error::i()->argument(1,'string','int')->argument(2,'bool');$url=self::GRAPH_URL.$id.'/picture';if($token){$url.='?access_token='.$this->_token;}return $url;}public function getUser(){return $this->getObject('me');}public function like($id){Eden_Facebook_Error::i()->argument(1,'string','int');$url=self::GRAPH_URL.$id.'/likes';$query=array('access_token'=>$this->_token);$url.='?'.http_build_query($query);$this->_call($url);return $this;}public function link($url){return Eden_Facebook_Link::i($this->_token,$url);}public function maybeEvent($id){Eden_Facebook_Error::i()->argument(1,'int');$url=self::GRAPH_URL.$id.'/maybe';$query=array('access_token'=>$this->_token);$url.='?'.http_build_query($query);json_decode($this->_call($url),true);return $this;}public function post($message){return Eden_Facebook_Post::i($this->_token,$message);}public function uploadPhoto($albumId,$file,$message=NULL){Eden_Facebook_Error::i()->argument(1,'string','int')->argument(2,'file')->argument(3,'string','null');$url=self::GRAPH_URL.$albumId.'/photos';$post=array('source'=>'@'.$file);$query=array('access_token'=>$this->_token);if($message){$post['message']=$message;}$url.='?'.http_build_query($query);$results=Eden_Curl::i()->setUrl($url)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->setUserAgent(Eden_Facebook_Auth::USER_AGENT)->setHeaders('Expect')->when(!empty($post),2)->setPost(true)->setPostFields($post)->getJsonResponse();return $results['id'];}protected function _call($url,array $post=array()){return Eden_Curl::i()->setUrl($url)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->setUserAgent(Eden_Facebook_Auth::USER_AGENT)->setHeaders('Expect')->when(!empty($post),2)->setPost(true)->setPostFields(http_build_query($post))->getResponse();}protected function _getList($id,$connection,$start=0,$range=0,$since=0,$until=0,$dateFormat=NULL){$query=array();if($start > 0){$query['offset']=$start;}if($range > 0){$query['limit']=$range;}if(is_string($since)){$since=strtotime($since);}if(is_string($until)){$until=strtotime($until);}if($since !==0){$query['since']=$since;}if($until !==0){$query['until']=$until;}$list=$this->getObject($id,$connection,$query);return $list['data'];}protected function _search($connection,$query,$fields=NULL){$query=array('type'=>$connection,'q'=>$query);if(is_array($fields)){$fields=implode(',',$fields);}if($fields){$query['fields']=$fields;}$results=$this->getObject('search',NULL,$query);return $results['data'];}}}