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