Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class facebook {
- static $app_key;
- static $app_secret;
- static $init = false;
- public static function init() {
- if(self::$init) return true;
- self::$app_key = @sanscode::$config['facebook']['app_id'];
- self::$app_secret = @sanscode::$config['facebook']['app_secret'];
- self::$init = true;
- }
- public static function fetch($login_callback=false, $logout_callback=false) {
- self::init();
- $app_key = self::$app_key;
- $var = <<<EOF
- <div id="fb-root"></div>
- <script src="http://connect.facebook.net/en_US/all.js"></script>
- <script>
- FB.init({appId: '$app_key', status: true, cookie: true, xfbml: true});
- FB.Event.subscribe('auth.sessionChange', function(response) {
- if (response.session) {
- $login_callback
- } else {
- $logout_callback
- }
- });
- </script>
- EOF;
- return $var;
- }
- public static function get_facebook_cookie() {
- self::init();
- $app_id = self::$app_key;
- $application_secret = self::$app_secret;
- if(!isset($_COOKIE['fbs_' . $app_id])) return null;
- $args = array();
- parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
- ksort($args);
- $payload = '';
- foreach ($args as $key => $value) {
- if ($key != 'sig') {
- $payload .= $key . '=' . $value;
- }
- }
- if (md5($payload . $application_secret) != $args['sig']) {
- return null;
- }
- return $args;
- }
- public static function user_info(){
- self::init();
- $cookie = self::get_facebook_cookie();
- if($cookie)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/me?access_token='.$cookie['access_token']);
- curl_setopt($ch, CURLOPT_PORT , 443);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $data = curl_exec($ch);
- $user = json_decode($data);
- return object2array::convert($user);
- }
- return false;
- }
- public static function login_button($perms =false)
- {
- self::init();
- return "<fb:login-button perms=\"$perms\"></fb:login-button>";
- }
- public static function installed(){
- self::init();
- if(!empty(self::$app_key) && !empty(self::$app_secret)) return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment