summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/fb_friend.module4
-rw-r--r--contrib/fb_user_app.info5
-rw-r--r--contrib/fb_user_app.install2
-rw-r--r--contrib/fb_user_app.module103
-rw-r--r--fb_user.module15
5 files changed, 75 insertions, 54 deletions
diff --git a/contrib/fb_friend.module b/contrib/fb_friend.module
index ccb4b82..9623930 100644
--- a/contrib/fb_friend.module
+++ b/contrib/fb_friend.module
@@ -516,7 +516,7 @@ function fb_friend_request_content($invite_data, $form_data) {
function fb_friend_write_record(&$row, $update = array()) {
if (!isset($row['created']))
- $row['created'] = time();
+ $row['created'] = REQUEST_TIME;
if (!isset($row['fbu_actor']))
$row['fbu_actor'] = fb_facebook_user();
if (!isset($row->label) && isset($GLOBALS['_fb_app'])) {
@@ -527,7 +527,7 @@ function fb_friend_write_record(&$row, $update = array()) {
function fb_friend_write_records($data, $targets) {
if (!isset($data['created']))
- $data['created'] = time();
+ $data['created'] = REQUEST_TIME;
if (!isset($data['fbu_actor']))
$data['fbu_actor'] = fb_facebook_user();
if (!isset($row->label) && isset($GLOBALS['_fb_app'])) {
diff --git a/contrib/fb_user_app.info b/contrib/fb_user_app.info
index 7a7d4e7..be01ca5 100644
--- a/contrib/fb_user_app.info
+++ b/contrib/fb_user_app.info
@@ -1,6 +1,9 @@
name= App User Data (fb_user_app.module)
description = Keep records of users most recent visits to your apps. Note that this adds some overhead to each app visit.
package = Drupal for Facebook - contrib
+configure = admin/structure/fb/fb_user_app
+core = 7.x
dependencies[] = fb
dependencies[] = fb_app
-core = 6.x
+
+files[] = fb_user_app.module
diff --git a/contrib/fb_user_app.install b/contrib/fb_user_app.install
index 5a2f527..5c54bda 100644
--- a/contrib/fb_user_app.install
+++ b/contrib/fb_user_app.install
@@ -51,7 +51,7 @@ function fb_user_app_schema() {
'time_access' => array(
'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,
),
- 'session_key' => array(
+ 'session_key' => array( // Called session_key for historical reasons. Now access_token.
'type' => 'varchar', 'length' => 255, 'not null' => FALSE,
),
'session_key_expires' => array(
diff --git a/contrib/fb_user_app.module b/contrib/fb_user_app.module
index c6ecde6..e34871f 100644
--- a/contrib/fb_user_app.module
+++ b/contrib/fb_user_app.module
@@ -24,7 +24,7 @@ function fb_user_app_menu() {
$items = array();
// Admin pages overview.
- $items[FB_PATH_ADMIN . "/tracking"] = array(
+ $items[FB_PATH_ADMIN . "/fb_user_app"] = array(
'title' => 'Tracking',
'description' => 'Settings that track statistics in Drupal for Facebook',
'page callback' => 'drupal_get_form',
@@ -55,7 +55,7 @@ function fb_user_app_fb($op, $data, &$return) {
// in FB_OP_AJAX_EVENT, because it turns out this hook is invoked even on
// page not found and access denied pages.
- fb_user_app_track_user($fb, $fb_app, $user);
+ fb_user_app_track($fb, $fb_app, $user);
}
elseif ($op == FB_APP_OP_EVENT) {
@@ -66,13 +66,15 @@ function fb_user_app_fb($op, $data, &$return) {
// Ensure fb_user_app table accurately reflects whether user has authorized.
if ($event_type == FB_APP_EVENT_POST_AUTHORIZE) {
// Track new facebook user, $GLOBAL['user'] not valid dufing post-autorize.
- fb_user_app_track_user($fb, $fb_app);
+ fb_user_app_track($fb, $fb_app);
}
elseif ($event_type == FB_APP_EVENT_POST_REMOVE) {
$fbu = fb_settings(FB_SETTINGS_FBU);
// User has removed the app from their account.
- db_query("DELETE FROM {fb_user_app} WHERE apikey='%s' AND fbu=%d",
- $fb_app->apikey, $fbu);
+ db_query("DELETE FROM {fb_user_app} WHERE apikey=:apikey AND fbu=:fbu", array(
+ ':apikey' => $fb_app->apikey,
+ ':fbu' => $fbu,
+ ));
}
}
elseif ($op == FB_OP_GET_USER_SESSION) {
@@ -82,8 +84,12 @@ function fb_user_app_fb($op, $data, &$return) {
// to provide it, depending on whether the user has logged in, and whether
// the session has expired.
$fbu = $data['fbu'];
- $result = db_query("SELECT * FROM {fb_user_app} WHERE apikey = '%s' and fbu = %d AND session_key_expires > %d", $fb_app->apikey, $fbu, time());
- $data = db_fetch_object($result);
+ $result = db_query("SELECT * FROM {fb_user_app} WHERE apikey = :apikey and fbu = :fbu AND session_key_expires > :time", array(
+ ':apikey' => $fb_app->apikey,
+ ':fbu' => $fbu,
+ ':time' => REQUEST_TIME,
+ ));
+ $data = $result->fetchObject();
if ($data && $data->session_key)
// Return array with FB id and apikey.
@@ -95,23 +101,23 @@ function fb_user_app_fb($op, $data, &$return) {
// fb.js has notified us of an event via AJAX. Not the same as facebook event callback above.
if ($data['event_type'] == 'session_change' && isset($data['event_data']['fbu'])) {
// A user has logged in.
- fb_user_app_track_user($fb, $fb_app, $user);
+ fb_user_app_track($fb, $fb_app, $user);
}
}
}
/**
- * Implements hook_user().
+ * Implements hook_user_delete().
*
* @TODO confirm there is no race condition between this module and fb_user.
* That is, during delete, does fb_get_fbu() still work?
*/
-function fb_user_app_user($op, &$edit, &$account, $category = NULL) {
- if ($op == 'delete') {
- // Given the uid, fetch the fbu so that we can delete
- $fbu = fb_get_fbu($account->uid);
- db_query('DELETE FROM {fb_user_app} WHERE fbu=%d', $fbu);
- }
+function fb_user_app_user_delete($account) {
+ // Given the uid, fetch the fbu so that we can delete
+ $fbu = fb_get_fbu($account->uid);
+ db_query('DELETE FROM {fb_user_app} WHERE fbu=:fbu', array(
+ ':fbu' => $fbu,
+ ));
}
/**
@@ -121,7 +127,7 @@ function fb_user_app_user($op, &$edit, &$account, $category = NULL) {
* Historically this supported infinite sessions. I believe if this data is
* no longer necessary for the offline access extended permission.
*/
-function fb_user_app_track_user($fb, $fb_app) {
+function fb_user_app_track($fb, $fb_app) {
// Coming from a user adding the app or a page adding the app?
$fb_user_type = "user";
$fbu = fb_facebook_user($fb);
@@ -147,39 +153,44 @@ function fb_user_app_track_user($fb, $fb_app) {
$session = $fb->getSession();
$session_key = isset($session['session_key']) ? $session['session_key'] : '';
- $result = db_query("UPDATE {fb_user_app} SET time_access=%d, session_key='%s', session_key_expires=%d, user_type='%s' WHERE apikey='%s' AND fbu=%d",
- time(),
- $session_key, $session['expires'],
- $fb_user_type,
- $fb_app->apikey, fb_facebook_user($fb));
-
- if ($result && !db_affected_rows()) {
+ $result1 = db_query("UPDATE {fb_user_app} SET time_access=:time, session_key=:token, session_key_expires=:expires, user_type=:type WHERE apikey=:apikey AND fbu=:fbu", array(
+ ':time' => REQUEST_TIME,
+ ':token' => $session_key,
+ ':expires' => $session['expires'],
+ ':type' => $fb_user_type,
+ ':apikey' => $fb_app->apikey,
+ ':fbu' => fb_facebook_user($fb),
+ ));
+
+ if ($result1 && !db_affected_rows()) { // XXX upgrade to D7. how?
// The row for this user was never inserted, or it was deleted, or the times were the same.
$fbu = fb_facebook_user($fb);
if ($fbu) {
//First make sure it was not just the same time
- $result = db_query("SELECT * FROM {fb_user_app} WHERE apikey='%s' AND fbu=%d",
- $fb_app->apikey,
- $fbu);
- if (!db_fetch_object($result)) {
+ $result = db_query("SELECT * FROM {fb_user_app} WHERE apikey=:apikey AND fbu=:fbu", array(
+ ':apikey' => $fb_app->apikey,
+ ':fbu' => $fbu,
+ ));
+ if (!$result->fetchObject()) {
//This row does not exist, even with the same time. Insert now
$info = fb_users_getInfo(array($fbu), $fb);
$data = $info[0];
$fb_user_type = "user";
- $result = db_query("INSERT INTO {fb_user_app} (apikey, fbu, added, user_type, session_key, session_key_expires, time_access, proxied_email, time_cron) VALUES ('%s', %d, %d, '%s', '%s', %d, %d, '%s', %d)",
- $fb_app->apikey, $fbu,
- $data['is_app_user'],
- $fb_user_type,
- $session['session_key'],
- $session['expires'],
- time(),
- $data['proxied_email'],
- 0 // time_cron
- );
+ $result = db_query("INSERT INTO {fb_user_app} (apikey, fbu, added, user_type, session_key, session_key_expires, time_access, proxied_email, time_cron) VALUES (:apikey, :fbu, :added, :user_type, :session_key, :session_key_expires, :time_access, :proxied_email, :time_cron)", array(
+ ':apikey' => $fb_app->apikey,
+ ':fbu' => $fbu,
+ ':added' => $data['is_app_user'],
+ ':user_type' => $fb_user_type,
+ ':session_key' => $session['session_key'],
+ ':session_key_expires' => $session['expires'],
+ ':time_access' => REQUEST_TIME,
+ ':proxied_email' => $data['proxied_email'],
+ ':time_cron' => 0,
+ ));
}
}
}
- if ($result === FALSE) {
+ if ($result === FALSE) { // XXX upgrade to D7???
watchdog('fb_user_app', "Failed to update fb_user_app table.", array(), WATCHDOG_ERROR);
}
}
@@ -191,10 +202,11 @@ function fb_user_app_track_user($fb, $fb_app) {
*/
function fb_user_app_get_proxied_email($fbu, $fb_app) {
// Try to learn from local database
- $result = db_query("SELECT * FROM {fb_user_app} WHERE apikey='%s' AND fbu=%d",
- $fb_app->apikey,
- $fbu);
- if ($data = db_fetch_object($result)) {
+ $result = db_query("SELECT * FROM {fb_user_app} WHERE apikey=:apikey AND fbu=:fbu", array(
+ ':apikey' => $fb_app->apikey,
+ ':fbu' => $fbu,
+ ));
+ if ($data = $result->fetchObject()) {
$mail = $data->proxied_email;
}
@@ -206,8 +218,11 @@ function fb_user_app_get_proxied_email($fbu, $fb_app) {
$mail = $data['proxied_email'];
if ($mail && variable_get(FB_USER_APP_VAR_TRACK_USERS, TRUE)) {
// Store locally.
- $result = db_query("UPDATE {fb_user_app} SET proxied_email='%s' WHERE apikey='%s' AND fbu=%d",
- $mail, $fb_app->apikey, $fbu);
+ $result = db_query("UPDATE {fb_user_app} SET proxied_email=:mail WHERE apikey=:apikey AND fbu=:fbu", array(
+ ':mail' => $mail,
+ ':apikey' => $fb_app->apikey,
+ ':fbu' => $fbu,
+ ));
}
}
return $mail;
diff --git a/fb_user.module b/fb_user.module
index cf668a8..dd50ddd 100644
--- a/fb_user.module
+++ b/fb_user.module
@@ -159,7 +159,8 @@ function fb_user_fb($op, $data, &$return) {
if (!isset($user->roles[$rid])) {
$user->roles[$rid] = $rid; // Should be role name, but that requires db query.
// Reload user permissions.
- user_access(NULL, $user, TRUE);
+ drupal_static_reset('user_access');
+ drupal_static_reset('menu_get_item');
}
}
else {
@@ -169,7 +170,8 @@ function fb_user_fb($op, $data, &$return) {
//user was somehow saved while connected to facebook.
unset($user->roles[$rid]);
// Reload user permissions.
- user_access(NULL, $user, TRUE);
+ drupal_static_reset('user_access');
+ drupal_static_reset('menu_get_item');
}
}
}
@@ -558,7 +560,7 @@ function fb_user_form_alter(&$form, &$form_state, $form_id) {
);
}
}
- elseif ($form_id == 'contact_mail_page' && variable_get(FB_USER_VAR_ALTER_CONTACT, TRUE)) {
+ elseif ($form_id == 'contact_site_form' && variable_get(FB_USER_VAR_ALTER_CONTACT, TRUE)) {
if ($data = _fb_user_facebook_data($fb)) {
if (!$form['name']['#default_value'] || strpos($form['name']['#default_value'], '@facebook')) {
$form['name']['#default_value'] = $data['name'];
@@ -804,9 +806,10 @@ function fb_user_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
'#description' => '',
);
$form['Facebook Application']['message'] = array(
- '#markup' => t('Check box and save to connect local account !username to facebook.com.',
- array('!username' => theme('username', array('account' => $form['#user'])),
- )),
+ '#markup' => t('If checked, link local account (!username) to facebook.com account (!fb_name).', array(
+ '!username' => theme('username', array('account' => $form['#user'])),
+ '!fb_name' => "<fb:name uid=$fbu useyou=false></fb:name>",
+ )),
'#prefix' => "\n<p>",
'#suffix' => "</p>\n",
);