| 1 |
<?php |
<?php |
| 2 |
// $Id: facebook_auth.module,v 1.9 2007/09/06 07:25:03 halkeye Exp $ |
// $Id: facebook_auth.module,v 1.9.4.1 2008/02/18 06:40:45 halkeye Exp $ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Facebook authentication. |
| 7 |
|
* |
| 8 |
|
* Essentially wrappers around any code that is required to do basic authentication |
| 9 |
|
* with facebook. |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
if (substr(phpversion(), 0, 1) == '4') { |
if (substr(phpversion(), 0, 1) == '4') { |
| 13 |
if (file_exists(dirname(__FILE__) . '/facebook-platform/php4client/facebook.php')) { |
if (file_exists(dirname(__FILE__) .'/facebook-platform/php4client/facebook.php')) { |
| 14 |
require_once('facebook-platform/php4client/facebook.php'); |
require_once('facebook-platform/php4client/facebook.php'); |
| 15 |
} |
} |
| 16 |
else { |
else { |
| 18 |
} |
} |
| 19 |
} |
} |
| 20 |
else { |
else { |
| 21 |
if (file_exists(dirname(__FILE__) . '/facebook-platform/client/facebook.php')) { |
if (file_exists(dirname(__FILE__) .'/facebook-platform/client/facebook.php')) { |
| 22 |
require_once('facebook-platform/client/facebook.php'); |
require_once('facebook-platform/client/facebook.php'); |
| 23 |
} |
} |
| 24 |
|
elseif (file_exists(dirname(__FILE__) .'/facebook-platform/php/facebook.php')) { |
| 25 |
|
require_once('facebook-platform/php/facebook.php'); |
| 26 |
|
} |
| 27 |
else { |
else { |
| 28 |
drupal_set_message('Platform needs to be installed. See readme file'); |
drupal_set_message('Platform needs to be installed. See readme file'); |
| 29 |
} |
} |
| 30 |
} |
} |
| 31 |
|
|
| 32 |
function facebook_auth_help($section) { |
function facebook_auth_help($path, $arg) { |
| 33 |
switch($section) { |
switch ($path) { |
| 34 |
case 'admin/settings': |
case 'admin/settings': |
| 35 |
return t('Configure your API and Secret Key provided by facebook.'); |
return t('Configure your API and Secret Key provided by facebook.'); |
| 36 |
case 'admin/settings/facebook_auth': |
case 'admin/settings/facebook_auth': |
| 37 |
return t('Sign up for a new application at !url. Fill in provided keys here.', |
return t('Sign up for a new application at !url. Fill in provided keys here.', |
| 38 |
array('!url'=>l(t('facebook developer page'), 'http://www.facebook.com/developers/')) |
array('!url' => l(t('facebook developer page'), 'http://www.facebook.com/developers/')) |
| 39 |
); |
); |
| 40 |
} |
} |
| 41 |
} |
} |
| 69 |
//'file' => 'tracker.pages.inc', |
//'file' => 'tracker.pages.inc', |
| 70 |
); |
); |
| 71 |
$items['user/%user/facebook_auth/delete'] = array( |
$items['user/%user/facebook_auth/delete'] = array( |
| 72 |
'title' => t('Delete Facebook'), |
'title' => 'Delete Facebook', |
| 73 |
'page callback' => 'facebook_auth_user_delete', |
'page callback' => 'facebook_auth_user_delete', |
| 74 |
'page arguments' => array(1), |
'page arguments' => array(1), |
| 75 |
'access callback' => 'facebook_auth_access_user', |
'access callback' => 'facebook_auth_access_user', |
| 145 |
return $page_content; |
return $page_content; |
| 146 |
} |
} |
| 147 |
|
|
| 148 |
|
function facebook_auth_user($op, &$edit, &$account, $category = NULL) { |
| 149 |
|
if ($op == 'logout') { |
| 150 |
|
$count = db_result(db_query("SELECT count(*) FROM {authmap} WHERE module='facebook_auth' AND uid=%d", $account->uid)); |
| 151 |
|
if ($count) { |
| 152 |
|
$api_key = variable_get('facebook_apikey', ''); |
| 153 |
|
$secret = variable_get('facebook_secretkey', ''); |
| 154 |
|
// initiate class |
| 155 |
|
$facebook = @new Facebook($api_key, $secret); |
| 156 |
|
$facebook->expire_session(); |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 162 |
function facebook_auth_admin($form_state) { |
function facebook_auth_admin($form_state) { |
| 163 |
$form = array(); |
$form = array(); |
| 188 |
function facebook_auth_form_alter(&$form, $form_state, $form_id) { |
function facebook_auth_form_alter(&$form, $form_state, $form_id) { |
| 189 |
$api_key = variable_get('facebook_apikey', ''); |
$api_key = variable_get('facebook_apikey', ''); |
| 190 |
$secret = variable_get('facebook_secretkey', ''); |
$secret = variable_get('facebook_secretkey', ''); |
| 191 |
if (!$secret || !$api_key) { return; } |
if (!$secret || !$api_key) { |
| 192 |
if (!variable_get('facebook_auth_enable_loginblock', FALSE)) { return; } |
return; |
| 193 |
|
} |
| 194 |
|
if (!variable_get('facebook_auth_enable_loginblock', FALSE)) { |
| 195 |
|
return; |
| 196 |
|
} |
| 197 |
if ($form_id == 'user_login_block' || $form_id == 'user_login') { |
if ($form_id == 'user_login_block' || $form_id == 'user_login') { |
| 198 |
$img = theme('image', |
$img = theme('image', |
| 199 |
variable_get('facebook_auth_image', 'http://static.ak.facebook.com/images/devsite/facebook_login.gif'), |
variable_get('facebook_auth_image', 'http://static.ak.facebook.com/images/devsite/facebook_login.gif'), |
| 201 |
); |
); |
| 202 |
$form['facebook_link'] = array( |
$form['facebook_link'] = array( |
| 203 |
'#type' => 'markup', |
'#type' => 'markup', |
| 204 |
'#value' => l($img, 'facebook', array('query' => 'destination='.$_GET['q'], 'html' => TRUE)), |
'#value' => l($img, 'facebook', array('query' => 'destination='. $_GET['q'], 'html' => TRUE)), |
| 205 |
); |
); |
| 206 |
} |
} |
| 207 |
return $form; |
return $form; |
| 219 |
return $blocks; |
return $blocks; |
| 220 |
} |
} |
| 221 |
else if ($op == 'view') { |
else if ($op == 'view') { |
| 222 |
switch($delta) { |
switch ($delta) { |
| 223 |
case 0: |
case 0: |
| 224 |
if ($user && $user->uid) { return; } |
if ($user && $user->uid) { |
| 225 |
|
return; |
| 226 |
|
} |
| 227 |
$image = theme('image', |
$image = theme('image', |
| 228 |
variable_get('facebook_auth_image', 'http://static.ak.facebook.com/images/devsite/facebook_login.gif'), |
variable_get('facebook_auth_image', 'http://static.ak.facebook.com/images/devsite/facebook_login.gif'), |
| 229 |
t('Login to facebook'), t('Login to facebook'), NULL, FALSE |
t('Login to facebook'), t('Login to facebook'), NULL, FALSE |
| 230 |
); |
); |
| 231 |
$block = array( |
$block = array( |
| 232 |
'subject' => t('Login with facebook'), |
'subject' => t('Login with facebook'), |
| 233 |
'content' => l($image, 'facebook', array('query' => 'destination='.$_GET['q'], 'html' => TRUE)), |
'content' => l($image, 'facebook', array('query' => 'destination='. $_GET['q'], 'html' => TRUE)), |
| 234 |
); |
); |
| 235 |
break; |
break; |
| 236 |
} |
} |
| 252 |
$form['fb_uid'] = array('#type' => 'value', '#value' => $u); |
$form['fb_uid'] = array('#type' => 'value', '#value' => $u); |
| 253 |
return confirm_form( |
return confirm_form( |
| 254 |
$form, |
$form, |
| 255 |
t('Are you sure you want to link %fbname to %username?',array('%fbname' => $username, '%username' => $user->name)), |
t('Are you sure you want to link %fbname to %username?', array('%fbname' => $username, '%username' => $user->name)), |
| 256 |
'<front>', // Not sure what to provide here |
'<front>', // Not sure what to provide here |
| 257 |
NULL, |
NULL, |
| 258 |
t('Link'), |
t('Link'), |
| 262 |
|
|
| 263 |
function facebook_auth_user_assoc_submit($form, &$form_state) { |
function facebook_auth_user_assoc_submit($form, &$form_state) { |
| 264 |
global $user; |
global $user; |
| 265 |
user_save($user, array('auth_facebook_auth' => $form_state['values']['fb_uid'] . '@facebook' ), ''); |
user_save($user, array('auth_facebook_auth' => $form_state['values']['fb_uid'] .'@facebook' ), ''); |
| 266 |
return drupal_goto('user/'. $user->uid .'/edit'); |
$form_state['redirect'] = 'user/'. $user->uid .'/edit'; |
| 267 |
} |
} |
| 268 |
|
|
| 269 |
function facebook_auth_user_identities($account) { |
function facebook_auth_user_identities($account) { |
| 272 |
|
|
| 273 |
$result = db_query("SELECT * FROM {authmap} WHERE module='facebook_auth' AND uid=%d", $account->uid); |
$result = db_query("SELECT * FROM {authmap} WHERE module='facebook_auth' AND uid=%d", $account->uid); |
| 274 |
while ($identity = db_fetch_object($result)) { |
while ($identity = db_fetch_object($result)) { |
| 275 |
list($userId) = explode('@',$identity->authname); |
list($uid) = explode('@', $identity->authname); |
| 276 |
$rows[] = array( |
$rows[] = array( |
| 277 |
l($userId,'http://www.facebook.com/profile.php?id='.$userId), |
l($uid, 'http://www.facebook.com/profile.php?id='. $uid), |
| 278 |
l(t('Delete'), 'user/'. $account->uid .'/facebook_auth/delete/'. $identity->aid) |
l(t('Delete'), 'user/'. $account->uid .'/facebook_auth/delete/'. $identity->aid) |
| 279 |
); |
); |
| 280 |
} |
} |
| 287 |
), |
), |
| 288 |
'facebook', |
'facebook', |
| 289 |
array( |
array( |
| 290 |
'query' => 'destination='.$_GET['q'], |
'query' => 'destination='. $_GET['q'], |
| 291 |
'html' => TRUE, |
'html' => TRUE, |
| 292 |
) |
) |
| 293 |
); |
); |