public function __construct() { if (!self::$Facebook) { FacebookInfo::getConfig(); self::$Facebook = new Facebook(FacebookInfo::$configs); } }
/** * HTML XMLNS tag (required) * Facebook Auth 2.0 support * @param array $options * @example $this->Facebook->init(); * @return string of scriptBlock for FB.init() or error */ public function init($options = null, $reload = true) { $options = array_merge(array('perms' => 'email'), (array) $this->loginOptions); if ($appId = FacebookInfo::getConfig('appId')) { $init = '<div id="fb-root"></div>'; $init .= $this->Html->scriptBlock("\n\twindow.fbAsyncInit = function() {\n\t\tFB.init({\n\t\t\tappId : '{$appId}', // App ID\n\t\t\tchannelURL : '../../Vendor/channel.php', // Channel File\n\t\t\tstatus : true, // check login status\n\t\t\tcookie : true, // enable cookies to allow the server to access the session\n\t\t\toauth : true, // enable OAuth 2.0\n\t\t\txfbml : true // parse XFBML\n\t\t});\n\n\n\t\t// Checks whether the user is logged in\n\t\tFB.getLoginStatus(function(response) {\n\t\t\tif (response.authResponse) {\n\t\t\t\t// logged in and connected user, someone you know\n\t\t\t\t// alert('You are connected');\n\t\t\t} else {\n\t\t\t\t// no user session available, someone you dont know\n\t\t\t\t// alert('You are disconnected');\n\t\t\t}\n\t\t});\n\n\t\tFB.Event.subscribe('auth.authResponseChange', function(response) {\n\t\t\tif (response.authResponse) {\n\t\t\t\t// the user has just logged in\n\t\t\t\t// alert('You just logged in facebook from somewhere');\n\t\t\t} else {\n\t\t\t\t// the user has just logged out\n\t\t\t\t// alert('You just logged out from faceboook');\n\t\t\t}\n\t\t});\n\n\t\t// Other javascript code goes here!\n\n\t};\n\n\t// logs the user in the application and facebook\n\tfunction login(redirection){\n\t\tFB.login(function (response) {\n\t\t\tif(response.authResponse) {\n\t\t\t\t// user is logged in\n\t\t\t\t// console.log('Welcome!');\n\t\t\t\tif(redirection != null && redirection != ''){\n\t\t\t\t\ttop.location.href = redirection;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// user could not log in\n\t\t\t\tconsole.log('User cancelled login or did not fully authorize.');\n\t\t\t}\n\t\t}, {scope: '" . $options['perms'] . "'});\n\t}\n\n\t// logs the user out of the application and facebook\n\tfunction logout(redirection){\n\t\tif (FB.getAuthResponse()) {\n\t\t\tFB.logout(function(response) {\n\t // user is logged out\n\t // redirection if any\n\t if(redirection != null && redirection != ''){\n\t top.location.href = redirection;\n\t }\n\t });} else {\n\t\t if(redirection != null && redirection != ''){\n \ttop.location.href = redirection;\n \t }\n\t };\n\t}\n\n\t// Load the SDK Asynchronously\n\t(function() {\n\tvar e = document.createElement('script'); e.async = true;\n\te.src = document.location.protocol\n\t+ '//connect.facebook.net/" . $this->locale . "/all.js';\n\tdocument.getElementById('fb-root').appendChild(e);\n\t}());"); return $init; } else { return "<span class='error'>No Facebook configuration detected. Please add the facebook configuration file to your config folder.</span>"; } }
/** * HTML XMLNS tag (required) * @param array $options * @example $this->Facebook->init(); * @return string of scriptBlock for FB.init() or error */ function init($options = null, $reload = true) { if (empty($options)) { $options = array(); } if ($appId = FacebookInfo::getConfig('appId')) { $session = json_encode($this->Session->read('FB.Session')); if ($reload) { $callback = "FB.Event.subscribe('auth.login',function(){window.location.reload()});"; } else { $callback = "if(typeof(facebookReady)=='function'){facebookReady()}"; } $init = '<div id="fb-root"></div>'; $init .= $this->Html->scriptBlock(<<<JS window.fbAsyncInit = function() { \tFB.init({ \t\tappId : '{$appId}', \t\tstatus : true, // check login status \t\tcookie : true, // enable cookies to allow the server to access the session \t\txfbml : true, // parse XFBML \t\toauth : true // use Oauth \t}); \t{$callback} }; (function() { \tvar e = document.createElement('script'); \te.src = document.location.protocol + '//connect.facebook.net/{$this->locale}/all.js'; \te.async = true; \tdocument.getElementById('fb-root').appendChild(e); }()); JS , $options); return $init; } else { return "<span class='error'>No Facebook configuration detected. Please add the facebook configuration file to your config folder.</span>"; } }
/** * HTML XMLNS tag (required) * @param array of options * @example $this->Facebook->init(); * @return string of scriptBlock for FB.init() or error * @access public */ function init($options = array()) { if (FacebookInfo::getConfig('appId')) { $appId = FacebookInfo::getConfig('appId'); $session = json_encode($this->Session->read('FB.Session')); $init = '<div id="fb-root"></div>'; $init .= $this->Html->scriptBlock("\n\t\t window.fbAsyncInit = function() {\n\t\t FB.init({\n\t\t appId : '{$appId}',\n\t\t session : {$session}, // don't refetch the session when PHP already has it\n\t\t status : true, // check login status\n\t\t cookie : true, // enable cookies to allow the server to access the session\n\t\t xfbml : true // parse XFBML\n\t\t });\n\t\t // whenever the user logs in, we refresh the page\n\t\t FB.Event.subscribe('auth.login', function() {\n\t\t window.location.reload();\n\t\t });\n\t\t };\n\t\t (function() {\n\t\t var e = document.createElement('script');\n\t\t e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';\n\t\t e.async = true;\n\t\t document.getElementById('fb-root').appendChild(e);\n\t\t }());\n \t", $options); return $init; } else { return "<span class='error'>No Facebook configuration detected. Please add the facebook configuration file to your config folder.</span>"; } }
/** * Initialize a new instance if none exists */ private function __initInstance() { if (empty(self::$Facebook)) { self::$Facebook = new Facebook(FacebookInfo::getConfig()); } }
public function __construct() { if (empty(self::$Facebook)) { self::$Facebook = new Facebook(FacebookInfo::getConfig()); } }