Skip to content

Instantly share code, notes, and snippets.

@ravikiranj
Created May 6, 2011 04:44
Show Gist options
  • Save ravikiranj/958452 to your computer and use it in GitHub Desktop.
Save ravikiranj/958452 to your computer and use it in GitHub Desktop.
Show Connect to FB
<?php
/*
* function to show connectToFB button
*/
function showConnectToFB($sessionExpired = false){
$params = array();
/* You will need to request additional permissions if you want to access user's and his/her friends interests */
/* Comment out the below 2 lines if you don't need so */
$params = array("req_perms" => "user_interests,user_likes,user_status,friends_interests,friends_likes,friends_status",
"fbconnect" => 0);
$loginUrl = $this->fb->getLoginUrl($params);
$sessionExpiredMsg = '';
if($sessionExpired){
$sessionExpiredMsg = <<<SESSIONEXPIRED
<h3 style="color: red; padding-bottom: 20px;">Your Facebook session has expired.</h3>
SESSIONEXPIRED;
}
$html =<<<HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Recoread</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.9.0/build/reset-fonts-grids/reset-fonts-grids.css">
<style type="text/stylesheet">
#doc{
border: 1px solid #C0C0C0;
border-radius: 10px 10px 10px 10px;
padding: 25px;
width: 780px;
margin-top: 200px;
}
#hd{
text-align: center;
margin: auto;
margin-bottom: 25px;
}
#bd{
text-align: center;
margin: auto;
}
h3{
font-size: 110%;
}
</style>
</head>
<body>
<!-- the id on the containing div determines the page width. -->
<!-- #doc = 750px; #doc2 = 950px; #doc3 = 100%; #doc4 = 974px -->
<div id="doc">
<div id="hd">
{$sessionExpiredMsg}
<h3>You will need to authorize "Recoread" application by connecting with Facebook</h3>
</div>
<div id="bd">
<a href="{$loginUrl}"><img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif"></a>
</div>
<div id="ft">
</div>
</div>
</body>
</html>
HTML;
echo $html;
}
public function displayHTML(){
try {
$this->session = $this->fb->getSession();
}catch(FacebookApiException $e){
error_log($e);
//Session expired or user de-authenticated the app
$this->showConnectToFB(true);
}
if(!$this->session){
//No credentials present, show user the login screen
$this->showConnectToFB();
return;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment