OXID eShop CE  4.9.9
 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 
10  return;
11 }
12 
17 class oxFb extends Facebook
18 {
19 
25  protected $_blIsConnected = null;
26 
33  public function __construct()
34  {
35  $oConfig = oxRegistry::getConfig();
36 
37  $aFbConfig["appId"] = $oConfig->getConfigParam("sFbAppId");
38  $aFbConfig["secret"] = $oConfig->getConfigParam("sFbSecretKey");
39  $aFbConfig["cookie"] = true;
40 
41  BaseFacebook::__construct($aFbConfig);
42  }
43 
49  public function isConnected()
50  {
51  $oConfig = oxRegistry::getConfig();
52 
53  if (!$oConfig->getConfigParam("bl_showFbConnect")) {
54  return false;
55  }
56 
57  if ($this->_blIsConnected !== null) {
58  return $this->_blIsConnected;
59  }
60 
61  $this->_blIsConnected = false;
62  $oUser = $this->getUser();
63 
64  if (!$oUser) {
65  $this->_blIsConnected = false;
66 
67  return $this->_blIsConnected;
68  }
69 
70  $this->_blIsConnected = true;
71  try {
72  $this->api('/me');
73  } catch (FacebookApiException $e) {
74  $this->_blIsConnected = false;
75  }
76 
77  return $this->_blIsConnected;
78  }
79 
91  protected function setPersistentData($key, $value)
92  {
93  if (!in_array($key, self::$kSupportedKeys)) {
94  self::errorLog('Unsupported key passed to setPersistentData.');
95 
96  return;
97  }
98 
99  $sSessionVarName = $this->constructSessionVariableName($key);
100  oxRegistry::getSession()->setVariable($sSessionVarName, $value);
101  }
102 
111  protected function getPersistentData($key, $default = false)
112  {
113  if (!in_array($key, self::$kSupportedKeys)) {
114  self::errorLog('Unsupported key passed to getPersistentData.');
115 
116  return $default;
117  }
118 
119  $sSessionVarName = $this->constructSessionVariableName($key);
120 
121  return (oxRegistry::getSession()->hasVariable($sSessionVarName) ?
122  oxRegistry::getSession()->getVariable($sSessionVarName) : $default);
123  }
124 
132  protected function clearPersistentData($key)
133  {
134  if (!in_array($key, self::$kSupportedKeys)) {
135  self::errorLog('Unsupported key passed to clearPersistentData.');
136 
137  return;
138  }
139 
140  $sSessionVarName = $this->constructSessionVariableName($key);
141  oxRegistry::getSession()->deleteVariable($sSessionVarName);
142  }
143 }