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     oxConfig::getInstance()->setConfigParam( "bl_showFbConnect", false );
00009     return;
00010 }
00011 
00012 //error_reporting($iOldErrorReproting);
00013 
00018 class oxFb extends Facebook
00019 {
00025     private static $_instance = null;
00026 
00032     protected $_blIsConnected = null;
00033 
00040     public function __construct()
00041     {
00042         $oConfig = oxConfig::getInstance();
00043 
00044         $aFbConfig["appId"]  = $oConfig->getConfigParam( "sFbAppId" );
00045         $aFbConfig["secret"] = $oConfig->getConfigParam( "sFbSecretKey" );
00046         $aFbConfig["cookie"] = true;
00047 
00048         BaseFacebook::__construct( $aFbConfig );
00049     }
00050 
00056     public static function getInstance()
00057     {
00058         // disable caching for test modules
00059         if ( defined( 'OXID_PHP_UNIT' ) ) {
00060             self::$_instance = modInstances::getMod( __CLASS__ );
00061         }
00062 
00063         if ( !self::$_instance instanceof oxFb ) {
00064 
00065             self::$_instance = oxNew( 'oxFb' );
00066             if ( defined( 'OXID_PHP_UNIT' ) ) {
00067                 modInstances::addMod( __CLASS__, self::$_instance);
00068             }
00069         }
00070         return self::$_instance;
00071     }
00072 
00078     public function isConnected()
00079     {
00080         $oConfig = oxConfig::getInstance();
00081 
00082         if ( !$oConfig->getConfigParam( "bl_showFbConnect" ) ) {
00083             return false;
00084         }
00085 
00086         if ( $this->_blIsConnected !== null ) {
00087             return $this->_blIsConnected;
00088         }
00089 
00090         $this->_blIsConnected = false;
00091         $oUser = $this->getUser();
00092 
00093         if (!$oUser) {
00094             $this->_blIsConnected = false;
00095             return $this->_blIsConnected;
00096         }
00097 
00098         $this->_blIsConnected = true;
00099         try {
00100             $this->api('/me');
00101         } catch (FacebookApiException $e) {
00102             $this->_blIsConnected = false;
00103         }
00104 
00105         return $this->_blIsConnected;
00106     }
00107 
00119     protected function setPersistentData($key, $value)
00120     {
00121         if (!in_array($key, self::$kSupportedKeys)) {
00122             self::errorLog('Unsupported key passed to setPersistentData.');
00123             return;
00124         }
00125 
00126         $sSessionVarName = $this->constructSessionVariableName($key);
00127         oxSession::getInstance()->setVar($sSessionVarName, $value);
00128     }
00129 
00138     protected function getPersistentData($key, $default = false)
00139     {
00140         if (!in_array($key, self::$kSupportedKeys)) {
00141             self::errorLog('Unsupported key passed to getPersistentData.');
00142             return $default;
00143         }
00144 
00145         $sSessionVarName = $this->constructSessionVariableName($key);
00146         return (oxSession::getInstance()->hasVar($sSessionVarName) ?
00147             oxSession::getInstance()->getVar($sSessionVarName) : $default);
00148     }
00149 
00157     protected function clearPersistentData($key)
00158     {
00159         if (!in_array($key, self::$kSupportedKeys)) {
00160             self::errorLog('Unsupported key passed to clearPersistentData.');
00161             return;
00162         }
00163 
00164         $sSessionVarName = $this->constructSessionVariableName($key);
00165         oxSession::getInstance()->deleteVar($sSessionVarName);
00166     }
00167 }