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     return;
00010 }
00011 
00016 class oxFb extends Facebook
00017 {
00023     protected $_blIsConnected = null;
00024 
00031     public function __construct()
00032     {
00033         $oConfig = oxRegistry::getConfig();
00034 
00035         $aFbConfig["appId"]  = $oConfig->getConfigParam( "sFbAppId" );
00036         $aFbConfig["secret"] = $oConfig->getConfigParam( "sFbSecretKey" );
00037         $aFbConfig["cookie"] = true;
00038 
00039         BaseFacebook::__construct( $aFbConfig );
00040     }
00041 
00049     public static function getInstance()
00050     {
00051         return oxRegistry::get("oxFb");
00052     }
00053 
00059     public function isConnected()
00060     {
00061         $oConfig = oxRegistry::getConfig();
00062 
00063         if ( !$oConfig->getConfigParam( "bl_showFbConnect" ) ) {
00064             return false;
00065         }
00066 
00067         if ( $this->_blIsConnected !== null ) {
00068             return $this->_blIsConnected;
00069         }
00070 
00071         $this->_blIsConnected = false;
00072         $oUser = $this->getUser();
00073 
00074         if (!$oUser) {
00075             $this->_blIsConnected = false;
00076             return $this->_blIsConnected;
00077         }
00078 
00079         $this->_blIsConnected = true;
00080         try {
00081             $this->api('/me');
00082         } catch (FacebookApiException $e) {
00083             $this->_blIsConnected = false;
00084         }
00085 
00086         return $this->_blIsConnected;
00087     }
00088 
00100     protected function setPersistentData($key, $value)
00101     {
00102         if (!in_array($key, self::$kSupportedKeys)) {
00103             self::errorLog('Unsupported key passed to setPersistentData.');
00104             return;
00105         }
00106 
00107         $sSessionVarName = $this->constructSessionVariableName($key);
00108         oxRegistry::getSession()->setVar($sSessionVarName, $value);
00109     }
00110 
00119     protected function getPersistentData($key, $default = false)
00120     {
00121         if (!in_array($key, self::$kSupportedKeys)) {
00122             self::errorLog('Unsupported key passed to getPersistentData.');
00123             return $default;
00124         }
00125 
00126         $sSessionVarName = $this->constructSessionVariableName($key);
00127         return (oxRegistry::getSession()->hasVar($sSessionVarName) ?
00128             oxRegistry::getSession()->getVar($sSessionVarName) : $default);
00129     }
00130 
00138     protected function clearPersistentData($key)
00139     {
00140         if (!in_array($key, self::$kSupportedKeys)) {
00141             self::errorLog('Unsupported key passed to clearPersistentData.');
00142             return;
00143         }
00144 
00145         $sSessionVarName = $this->constructSessionVariableName($key);
00146         oxRegistry::getSession()->deleteVar($sSessionVarName);
00147     }
00148 }