facebook.php

Go to the documentation of this file.
00001 <?php
00018 require_once "base_facebook.php";
00019 
00024 class Facebook extends BaseFacebook
00025 {
00035   public function __construct($config) {
00036     if (!session_id()) {
00037       session_start();
00038     }
00039     parent::__construct($config);
00040   }
00041 
00042   protected static $kSupportedKeys =
00043     array('state', 'code', 'access_token', 'user_id');
00044 
00051   protected function setPersistentData($key, $value) {
00052     if (!in_array($key, self::$kSupportedKeys)) {
00053       self::errorLog('Unsupported key passed to setPersistentData.');
00054       return;
00055     }
00056 
00057     $session_var_name = $this->constructSessionVariableName($key);
00058     $_SESSION[$session_var_name] = $value;
00059   }
00060 
00061   protected function getPersistentData($key, $default = false) {
00062     if (!in_array($key, self::$kSupportedKeys)) {
00063       self::errorLog('Unsupported key passed to getPersistentData.');
00064       return $default;
00065     }
00066 
00067     $session_var_name = $this->constructSessionVariableName($key);
00068     return isset($_SESSION[$session_var_name]) ?
00069       $_SESSION[$session_var_name] : $default;
00070   }
00071 
00072   protected function clearPersistentData($key) {
00073     if (!in_array($key, self::$kSupportedKeys)) {
00074       self::errorLog('Unsupported key passed to clearPersistentData.');
00075       return;
00076     }
00077 
00078     $session_var_name = $this->constructSessionVariableName($key);
00079     unset($_SESSION[$session_var_name]);
00080   }
00081 
00082   protected function clearAllPersistentData() {
00083     foreach (self::$kSupportedKeys as $key) {
00084       $this->clearPersistentData($key);
00085     }
00086   }
00087 
00088   protected function constructSessionVariableName($key) {
00089     return implode('_', array('fb',
00090                               $this->getAppId(),
00091                               $key));
00092   }
00093 }