oxfb.php

Go to the documentation of this file.
00001 <?php
00002 
00003 
00004 try {
00005     include_once getShopBasePath() . "core/facebook/facebook.php";
00006 } catch (Exception $oEx) {
00007     // skipping class includion if curl or json is not active
00008     oxRegistry::getConfig()->setConfigParam("bl_showFbConnect", false);
00009 
00010     return;
00011 }
00012 
00017 class oxFb extends Facebook
00018 {
00019 
00025     protected $_blIsConnected = null;
00026 
00033     public function __construct()
00034     {
00035         $oConfig = oxRegistry::getConfig();
00036 
00037         $aFbConfig["appId"] = $oConfig->getConfigParam("sFbAppId");
00038         $aFbConfig["secret"] = $oConfig->getConfigParam("sFbSecretKey");
00039         $aFbConfig["cookie"] = true;
00040 
00041         BaseFacebook::__construct($aFbConfig);
00042     }
00043 
00049     public function isConnected()
00050     {
00051         $oConfig = oxRegistry::getConfig();
00052 
00053         if (!$oConfig->getConfigParam("bl_showFbConnect")) {
00054             return false;
00055         }
00056 
00057         if ($this->_blIsConnected !== null) {
00058             return $this->_blIsConnected;
00059         }
00060 
00061         $this->_blIsConnected = false;
00062         $oUser = $this->getUser();
00063 
00064         if (!$oUser) {
00065             $this->_blIsConnected = false;
00066 
00067             return $this->_blIsConnected;
00068         }
00069 
00070         $this->_blIsConnected = true;
00071         try {
00072             $this->api('/me');
00073         } catch (FacebookApiException $e) {
00074             $this->_blIsConnected = false;
00075         }
00076 
00077         return $this->_blIsConnected;
00078     }
00079 
00091     protected function setPersistentData($key, $value)
00092     {
00093         if (!in_array($key, self::$kSupportedKeys)) {
00094             self::errorLog('Unsupported key passed to setPersistentData.');
00095 
00096             return;
00097         }
00098 
00099         $sSessionVarName = $this->constructSessionVariableName($key);
00100         oxRegistry::getSession()->setVariable($sSessionVarName, $value);
00101     }
00102 
00111     protected function getPersistentData($key, $default = false)
00112     {
00113         if (!in_array($key, self::$kSupportedKeys)) {
00114             self::errorLog('Unsupported key passed to getPersistentData.');
00115 
00116             return $default;
00117         }
00118 
00119         $sSessionVarName = $this->constructSessionVariableName($key);
00120 
00121         return (oxRegistry::getSession()->hasVariable($sSessionVarName) ?
00122             oxRegistry::getSession()->getVariable($sSessionVarName) : $default);
00123     }
00124 
00132     protected function clearPersistentData($key)
00133     {
00134         if (!in_array($key, self::$kSupportedKeys)) {
00135             self::errorLog('Unsupported key passed to clearPersistentData.');
00136 
00137             return;
00138         }
00139 
00140         $sSessionVarName = $this->constructSessionVariableName($key);
00141         oxRegistry::getSession()->deleteVariable($sSessionVarName);
00142     }
00143 }