Created
December 1, 2010 20:02
-
-
Save gurkanoluc/724117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ob_start(); | |
// Dirty hack for IE Iframe Cookie Problem | |
header('P3P: CP="ALL DSP LAW CUR DEVi PSAa CONi OUR IND PHY ONL UNI PUR COM CNT"'); | |
include_once APPPATH .'libraries/facebook-php-sdk/src/facebook.php'; | |
class Facebook_Client | |
{ | |
/** | |
* | |
* Facebook Client | |
* @var Object | |
*/ | |
private $_facebook; | |
/** | |
* Access token of user | |
* @var string | |
*/ | |
private $_accessToken; | |
/** | |
* Facebook user id of user | |
* @var integer | |
*/ | |
private $_uid; | |
/** | |
* CodeIgniter Base Object | |
* @var object | |
*/ | |
private $_CI; | |
/** | |
* Configurations for Facebook Application | |
* @var array | |
*/ | |
private $_config; | |
public function __construct() { | |
$this->_CI =& get_instance(); | |
// Load CodeIgniter Configuration File | |
$this->_CI->load->config('facebook', TRUE); | |
$this->_config = $this->_CI->config->item('facebook'); | |
// Initialize facebook client | |
$this->_facebook = new Facebook($this->_config['application']); | |
} | |
/** | |
* Gets authentication url for application | |
* @param array $options | |
* @return string | |
*/ | |
public function getLoginUrl($options = array()) | |
{ | |
$this->_config['auth']['fbconnect'] = 0; | |
$this->_config['auth']['display'] = 'page'; | |
$this->_config['auth']['canvas'] = 1; | |
$options = array_merge($this->_config['auth'], $options); | |
return $this->_facebook->getLoginUrl($options); | |
} | |
/** | |
* Gets active facebook user's uid, access token information | |
* @return array | bool | |
*/ | |
public function getSession() | |
{ | |
$session = $this->_facebook->getSession(); | |
if($session) | |
{ | |
/** | |
* TODO : Use setters in here | |
*/ | |
$this->_accessToken = $session['access_token']; | |
$this->_uid = $session['uid']; | |
return $session; | |
} | |
return false; | |
} | |
/** | |
* Redirection to Facebook login page | |
* @param string $loginUrl | |
* @param bool $notDie | |
* @return void | string | |
*/ | |
public function redirect($loginUrl = '', $notDie = false) | |
{ | |
if($loginUrl) | |
{ | |
$output = sprintf(" | |
<script type=\"text/javascript\"> | |
top.location.href = '%s'; | |
</script>", $loginUrl); | |
if($notDie != false) | |
die($redirect); | |
else | |
return $output; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment