summaryrefslogtreecommitdiffabout
authorWojciech Polak <polak@gnu.org>2010-04-28 16:57:27 (GMT)
committer Wojciech Polak <polak@gnu.org>2010-04-28 16:57:27 (GMT)
commitf0cb1cdb39370971010723ab4f7f5a95f845eca6 (patch) (side-by-side diff)
tree4058dd9deaf80eca3aed529ab57eca90d06080bc
parent2dba4fd46dbaece7a6e5e9a67bd41f1fd8a01560 (diff)
downloadcheetah-f0cb1cdb39370971010723ab4f7f5a95f845eca6.tar.gz
cheetah-f0cb1cdb39370971010723ab4f7f5a95f845eca6.tar.bz2
Switch to new FB API.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--.gitignore2
-rw-r--r--frontend/fb_connect.php61
-rw-r--r--frontend/lib/config-sample.php1
-rw-r--r--frontend/lib/session.class.php7
-rw-r--r--frontend/login.php39
-rw-r--r--frontend/reader.php7
-rw-r--r--js/v2/boot.js5
-rw-r--r--js/v2/gui.js6
8 files changed, 70 insertions, 58 deletions
diff --git a/.gitignore b/.gitignore
index 9a0ae5e..d5db7f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,14 +1,14 @@
*~
*.o
*.mo
*.so
.htaccess
errorlog
-frontend/facebook-platform/
frontend/lib/config.php
frontend/lib/d-sigs.php
+frontend/lib/facebook.php
frontend/trs/*
gen/popular.xml
po/*-js.po
po/*-php.po
src/mod_jspp.c
diff --git a/frontend/fb_connect.php b/frontend/fb_connect.php
index 603f9b5..d5bf81b 100644
--- a/frontend/fb_connect.php
+++ b/frontend/fb_connect.php
@@ -15,14 +15,14 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-require 'facebook-platform/facebook.php';
require_once 'lib/include.php';
+require_once 'lib/facebook.php';
start_session (null, true);
$session->auth ('iflogged');
$message = '';
$auth = true;
@@ -34,25 +34,27 @@ if ($session->status['afterlogged'] != 'yes' ||
$message = _('You are using a guest account. You must register in order to do this.');
$auth = false;
}
else if ($link == '1')
{
try {
- $fb = new Facebook ($CONF['fb.api_key'], $CONF['fb.secret_key']);
- $fb_user = $fb->get_loggedin_user ();
- if ($fb_user) {
- $db = new Database ();
- $db->query ("UPDATE user SET fbUID=".$fb_user." WHERE id='".
- $session->id."'");
- }
- else {
- $fb->set_user (null, null);
+ $fb = new Facebook (array ('appId' => $CONF['fb.app_id'],
+ 'secret' => $CONF['fb.secret_key'],
+ 'cookie' => true));
+ $fb_session = $fb->getSession ();
+ if ($fb_session) {
+ $fb_uid = $fb->getUser ();
+ if ($fb_uid) {
+ $db = new Database ();
+ $db->query ("UPDATE user SET fbUID=".$fb_uid." WHERE id='".
+ $session->id."'");
+ }
}
}
- catch (Exception $e) {
- echo $e->getMessage ();
+ catch (FacebookApiException $e) {
+ error_log ($e);
}
}
else if ($link == '0')
{
$db->query ("UPDATE user SET fbUID=0 WHERE id='".$session->id."'");
}
@@ -62,18 +64,28 @@ if ($auth) {
$db = new Database ();
$db->query ("SELECT fbUID FROM user WHERE id='".$session->id."'");
if ($db->next_record ()) {
$fbUID = $db->f ('fbUID');
- $fb = new Facebook ($CONF['fb.api_key'], $CONF['fb.secret_key']);
- $fb_user = $fb->get_loggedin_user ();
- if ($fb_user) {
- $ud = $fb->api_client->users_getInfo ($fb_user, array ('profile_url'));
- if ($ud && isset ($ud[0]['profile_url']))
- $profile_url = $ud[0]['profile_url'];
+ try {
+ $fb = new Facebook (array ('appId' => $CONF['fb.app_id'],
+ 'secret' => $CONF['fb.secret_key'],
+ 'cookie' => true));
+ $fb_session = $fb->getSession ();
+ if ($fb_session) {
+ $fb_uid = $fb->getUser ();
+ if ($fb_uid) {
+ $me = $fb->api ('/me');
+ if ($me && isset ($me['link']))
+ $profile_url = $me['link'];
+ }
+ }
+ }
+ catch (FacebookApiException $e) {
+ error_log ($e);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -105,23 +117,22 @@ if ($auth) {
else
echo $fbUID;
echo '</p>';
}
else {
echo '<p>Your account is not connected with Facebook</p>'."\n";
- echo '<p><fb:login-button length="long" background="light" size="medium" onlogin="fb_link()"></fb:login-button></p>'."\n";
+ echo '<p><fb:login-button length="long" onlogin="fb_link()" perms="email" /></p>'."\n";
}
?>
-<?php if (isset ($CONF['fb.api_key'])) { ?>
-<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
+<?php if (isset ($CONF['fb.app_id'])) { ?>
+<div id="fb-root"></div>
+<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
function fb_link () { window.location = 'fb_connect?link=1'; }
- FB_RequireFeatures (['XFBML'], function () {
- FB.init ('<?=$CONF["fb.api_key"]?>', 'xd_receiver.html',
- {'permsToRequestOnConnect': 'email'});
- });
+ FB.init ({appId: '<?=$CONF['fb.app_id']?>', status: true, cookie: true,
+ xfbml: true});
</script>
<?php } }?>
</body>
</html>
diff --git a/frontend/lib/config-sample.php b/frontend/lib/config-sample.php
index f4ff687..1be1afd 100644
--- a/frontend/lib/config-sample.php
+++ b/frontend/lib/config-sample.php
@@ -24,12 +24,11 @@ $CONF['trsExpireDays'] = 7;
$CONF['feedEngine'] = 'cth';
$CONF['google.key'] = 'GOOGLE-API-KEY';
$CONF['google.mapkey'] = 'GOOGLE-MAP-KEY';
$CONF['google.analytics'] = 'GA-CODE';
$CONF['fb.app_id'] = 'FACEBOOK-APP-ID';
-$CONF['fb.api_key'] = 'FACEBOOK-API-KEY';
$CONF['fb.secret_key'] = 'FACEBOOK-SECRET-KEY';
$CONF['whatsnew'] = false;
?>
diff --git a/frontend/lib/session.class.php b/frontend/lib/session.class.php
index 8a18f18..b1f7208 100644
--- a/frontend/lib/session.class.php
+++ b/frontend/lib/session.class.php
@@ -272,16 +272,15 @@ class Session
$r = 'http://'.$CONF['site'].'/';
}
redirect ($r);
}
else
{
- $user_details = $fb->api_client->users_getInfo ($fb_uid,
- array ('email'));
- if ($user_details && isset ($user_details[0]['email']))
- $email = $user_details[0]['email'];
+ $me = $fb->api ('/me');
+ if ($me && isset ($me['email']))
+ $email = $me['email'];
else
return _('E-mail address is required.');
$db->query ("SELECT id FROM user WHERE email='".$db->escape($email)."'");
if ($db->next_record ()) {
return _('To link your Facebook account, please visit Menu/User Settings');
diff --git a/frontend/login.php b/frontend/login.php
index bce0377..a864280 100644
--- a/frontend/login.php
+++ b/frontend/login.php
@@ -74,24 +74,26 @@ if (isset ($_GET['openid_mode']) && !empty ($_GET['openid_mode']))
if (isset ($sreg['email']))
$email = strip_tags ($sreg['email']);
$message = $_SESSION['session']->openid2 ($response->identity_url,
$email);
}
}
-else if ($fbConnect && isset ($CONF['fb.api_key']) &&
+else if ($fbConnect && isset ($CONF['fb.app_id']) &&
isset ($CONF['fb.secret_key'])) {
- require 'facebook-platform/facebook.php';
- $fb = new Facebook ($CONF['fb.api_key'], $CONF['fb.secret_key']);
- $fb_uid = $fb->get_loggedin_user ();
- if ($fb_uid) {
- $insideFB = $fb_sig_in_iframe == '1' ? true : false;
- $message = $_SESSION['session']->fb_login ($fb, $fb_uid, $insideFB,
- $feedurl);
- }
- else {
- $fb->set_user (null, null);
+ require 'lib/facebook.php';
+ $fb = new Facebook (array ('appId' => $CONF['fb.app_id'],
+ 'secret' => $CONF['fb.secret_key'],
+ 'cookie' => true));
+ $fb_session = $fb->getSession ();
+ if ($fb_session) {
+ $fb_uid = $fb->getUser ();
+ if ($fb_uid) {
+ $insideFB = $fb_sig_in_iframe == '1' ? true : false;
+ $message = $_SESSION['session']->fb_login ($fb, $fb_uid, $insideFB,
+ $feedurl);
+ }
}
}
else if ($SignIn)
{
if (!empty ($openid_identifier)) {
$message = $_SESSION['session']->openid1 ($openid_identifier, $feedurl);
@@ -202,13 +204,13 @@ echo '<html xmlns="http://www.w3.org/1999/xhtml"
class="openid_identifier" style="width:90%" maxlength="255" />
</td>
</tr>
<tr id="trFBConnect">
<td align="right"><?php echo 'Facebook: '; ?></td>
<td align="left">
- <fb:login-button length="long" background="light" size="medium" onlogin="fb_login()"></fb:login-button>
+ <fb:login-button length="long" onlogin="fb_login()" perms="email" />
</td>
</tr>
<tr>
<td align="right"></td>
<td align="left">
<span id="useOpenID" class="link" style="display:none"><?php echo _('Use OpenID'); ?></span>
@@ -262,13 +264,13 @@ echo '<html xmlns="http://www.w3.org/1999/xhtml"
var addthis_url = 'http://www.cheetah-news.com/';
var addthis_title = 'Cheetah News -- Web-based Personal News Aggregator';
var addthis_logo = 'http://www.cheetah-news.com/favicon.ico';
var addthis_logo_background = 'ffffff';
var addthis_logo_color = '666699';
var addthis_brand = 'Cheetah News';
- var addthis_options = 'favorites,email,delicious,twitter,facebook,friendfeed,google,digg,reddit,more';
+ var addthis_options = 'delicious,twitter,facebook,friendfeed,googlebuzz,google,stumbleupon,digg,reddit,more';
</script>
<a href="http://www.addthis.com/bookmark.php?v=20" onmouseover="return addthis_open(this, '', 'http://www.cheetah-news.com/', 'Cheetah News -- Web-based Personal News Aggregator')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="images/share.png" width="83" height="16" alt="Bookmark and Share" style="border-style:none" /></a>
<?php if (isset ($_SERVER['HTTPS'])) { ?>
<script type="text/javascript" src="https://secure.addthis.com/js/200/addthis_widget.js"></script>
<?php } else { ?>
<script type="text/javascript" src="http://s7.addthis.com/js/200/addthis_widget.js"></script>
@@ -354,19 +356,18 @@ echo '<html xmlns="http://www.w3.org/1999/xhtml"
if ($message)
echo '<div id="message">'.$message.'</div>';
?>
</div>
-<?php if (isset ($CONF['fb.api_key'])) { ?>
-<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
+<?php if (isset ($CONF['fb.app_id'])) { ?>
+<div id="fb-root"></div>
+<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
-FB_RequireFeatures (['XFBML'], function () {
- FB.init ('<?=$CONF["fb.api_key"]?>', 'xd_receiver.html',
- {'permsToRequestOnConnect': 'email'});
-});
+ FB.init ({appId: '<?=$CONF['fb.app_id']?>', status: true, cookie: true,
+ xfbml: true});
</script>
<?php } ?>
<?php if (isset ($CONF['google.analytics']) && !isset ($_GET['openid_mode'])) { ?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
diff --git a/frontend/reader.php b/frontend/reader.php
index 370895b..37a2dea 100644
--- a/frontend/reader.php
+++ b/frontend/reader.php
@@ -352,16 +352,17 @@ var SIGS = {'js':'".$SIGS["js"]."', 'tr':'".$SIGS["tr"]."', 'wt':'".
<span id="menuOpenCWindow2" class="linkCM">&nbsp;<img src="images/t.gif" width="16" height="16" alt="" /></span>
<span id="menuOpenCWindow3" class="linkCM">&nbsp;<img src="images/t.gif" width="16" height="16" alt="" /></span>
<span id="menuOpenCWindow4" class="linkCM">&nbsp;<img src="images/t.gif" width="16" height="16" alt="" /></span>
<hr /><span id="logout" class="linkCM">&nbsp;<img src="images/t.gif" width="16" height="16" alt="" /></span>
</div>
-<?php if (isset ($CONF['fb.api_key'])) { ?>
-<script type="text/javascript">CONF.fb_api_key = '<?=$CONF["fb.api_key"]?>';</script>
+<?php if (isset ($CONF['fb.app_id'])) { ?>
+<script type="text/javascript">CONF.fb_app_id = '<?=$CONF["fb.app_id"]?>';</script>
+<div id="fb-root"></div>
<div id="fbFanbox" style="display:none">
- <fb:fan profile_id="<?=$CONF['fb.app_id']?>" stream="0" connections="10" logobar="1" width="500" height="300"></fb:fan>
+ <iframe src="http://www.facebook.com/plugins/fan.php?id=<?=$CONF['fb.app_id']?>&amp;width=500&amp;height=300&amp;connections=10&amp;stream=false&amp;header=false" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:500px; height:300px"></iframe>
</div>
<?php } ?>
<?php if (isset ($CONF['google.analytics'])) { ?>
<script type="text/javascript">
var tracker;
diff --git a/js/v2/boot.js b/js/v2/boot.js
index 4f4f38e..a2d80b8 100644
--- a/js/v2/boot.js
+++ b/js/v2/boot.js
@@ -78,12 +78,13 @@ function dsp (res, p) {
d += '&v=' + SIGS[res];
if (p) d += p;
return d;
}
function load_fb () {
- $.getScript ('http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php',
- function () { FB.init (CONF.fb_api_key, 'xd_receiver.html'); });
+ $.getScript ('http://connect.facebook.net/en_US/all.js', function () {
+ FB.init ({appId: CONF.fb_app_id, status: true});
+ });
}
setTimeout (load_fb, 2500);
window.onload = reader;
diff --git a/js/v2/gui.js b/js/v2/gui.js
index df9e7b4..bcab5ce 100644
--- a/js/v2/gui.js
+++ b/js/v2/gui.js
@@ -344,15 +344,15 @@ function initMenu () {
menuLink.oncontextmenu = showMenu;
}
setCmhLink (GID ('logout'), function () {
if (cheetahData.fbUID && typeof FB != 'undefined') {
if (confirm (_('Log out also from Facebook?'))) {
- FB.Connect.get_status ().waitUntilReady (function (status) {
- if (status == FB.ConnectState.connected)
- FB.Connect.logoutAndRedirect ('logout');
+ FB.getLoginStatus (function (res) {
+ if (res.session)
+ FB.logout (function (r) { window.location = 'logout'; });
else
window.location = 'logout';
});
return;
}
}

Return to:

Send suggestions and report system problems to the System administrator.