OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxfb.php
Go to the documentation of this file.
1 <?php
2 
3 
4 try {
5  include_once getShopBasePath() . "core/facebook/facebook.php";
6 } catch ( Exception $oEx ) {
7  // skipping class includion if curl or json is not active
8  oxRegistry::getConfig()->setConfigParam( "bl_showFbConnect", false );
9  return;
10 }
11 
16 class oxFb extends Facebook
17 {
23  protected $_blIsConnected = null;
24 
31  public function __construct()
32  {
33  $oConfig = oxRegistry::getConfig();
34 
35  $aFbConfig["appId"] = $oConfig->getConfigParam( "sFbAppId" );
36  $aFbConfig["secret"] = $oConfig->getConfigParam( "sFbSecretKey" );
37  $aFbConfig["cookie"] = true;
38 
39  BaseFacebook::__construct( $aFbConfig );
40  }
41 
49  public static function getInstance()
50  {
51  return oxRegistry::get("oxFb");
52  }
53 
59  public function isConnected()
60  {
61  $oConfig = oxRegistry::getConfig();
62 
63  if ( !$oConfig->getConfigParam( "bl_showFbConnect" ) ) {
64  return false;
65  }
66 
67  if ( $this->_blIsConnected !== null ) {
68  return $this->_blIsConnected;
69  }
70 
71  $this->_blIsConnected = false;
72  $oUser = $this->getUser();
73 
74  if (!$oUser) {
75  $this->_blIsConnected = false;
76  return $this->_blIsConnected;
77  }
78 
79  $this->_blIsConnected = true;
80  try {
81  $this->api('/me');
82  } catch (FacebookApiException $e) {
83  $this->_blIsConnected = false;
84  }
85 
86  return $this->_blIsConnected;
87  }
88 
100  protected function setPersistentData($key, $value)
101  {
102  if (!in_array($key, self::$kSupportedKeys)) {
103  self::errorLog('Unsupported key passed to setPersistentData.');
104  return;
105  }
106 
107  $sSessionVarName = $this->constructSessionVariableName($key);
108  oxRegistry::getSession()->setVar($sSessionVarName, $value);
109  }
110 
119  protected function getPersistentData($key, $default = false)
120  {
121  if (!in_array($key, self::$kSupportedKeys)) {
122  self::errorLog('Unsupported key passed to getPersistentData.');
123  return $default;
124  }
125 
126  $sSessionVarName = $this->constructSessionVariableName($key);
127  return (oxRegistry::getSession()->hasVar($sSessionVarName) ?
128  oxRegistry::getSession()->getVar($sSessionVarName) : $default);
129  }
130 
138  protected function clearPersistentData($key)
139  {
140  if (!in_array($key, self::$kSupportedKeys)) {
141  self::errorLog('Unsupported key passed to clearPersistentData.');
142  return;
143  }
144 
145  $sSessionVarName = $this->constructSessionVariableName($key);
146  oxRegistry::getSession()->deleteVar($sSessionVarName);
147  }
148 }