1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17:
18: require_once "base_facebook.php";
19:
20: 21: 22: 23:
24: class Facebook extends BaseFacebook
25: {
26: 27: 28: 29: 30: 31: 32: 33: 34:
35: public function __construct($config) {
36: if (!session_id()) {
37: session_start();
38: }
39: parent::__construct($config);
40: }
41:
42: protected static $kSupportedKeys =
43: array('state', 'code', 'access_token', 'user_id');
44:
45: 46: 47: 48: 49: 50:
51: protected function setPersistentData($key, $value) {
52: if (!in_array($key, self::$kSupportedKeys)) {
53: self::errorLog('Unsupported key passed to setPersistentData.');
54: return;
55: }
56:
57: $session_var_name = $this->constructSessionVariableName($key);
58: $_SESSION[$session_var_name] = $value;
59: }
60:
61: protected function getPersistentData($key, $default = false) {
62: if (!in_array($key, self::$kSupportedKeys)) {
63: self::errorLog('Unsupported key passed to getPersistentData.');
64: return $default;
65: }
66:
67: $session_var_name = $this->constructSessionVariableName($key);
68: return isset($_SESSION[$session_var_name]) ?
69: $_SESSION[$session_var_name] : $default;
70: }
71:
72: protected function clearPersistentData($key) {
73: if (!in_array($key, self::$kSupportedKeys)) {
74: self::errorLog('Unsupported key passed to clearPersistentData.');
75: return;
76: }
77:
78: $session_var_name = $this->constructSessionVariableName($key);
79: unset($_SESSION[$session_var_name]);
80: }
81:
82: protected function clearAllPersistentData() {
83: foreach (self::$kSupportedKeys as $key) {
84: $this->clearPersistentData($key);
85: }
86: }
87:
88: protected function constructSessionVariableName($key) {
89: return implode('_', array('fb',
90: $this->getAppId(),
91: $key));
92: }
93: }
94: