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         parent::__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 
00092         $oSession = $this->getSession();
00093 
00094         if ( $oSession ) {
00095             try {
00096               if ( $this->getUser() ) {
00097                     $this->_blIsConnected = true;
00098               }
00099             } catch (FacebookApiException $e) {
00100                 $this->_blIsConnected = false;
00101             }
00102         }
00103 
00104         return $this->_blIsConnected;
00105     }
00106 }