Index: fb_user.info =================================================================== --- fb_user.info (revision 1.1) +++ fb_user.info (6.x working copy) @@ -1,5 +1,8 @@ name=Facebook User Management description=User handling code. package = Facebook -dependencies = fb fb_app +dependencies[] = fb +dependencies[] = fb_app +core = 6.x +version = "6.x-1.x-dev" Index: fb_user.install =================================================================== --- fb_user.install (revision 1.2) +++ fb_user.install (6.x working copy) @@ -1,39 +1,36 @@ $db_type)), 'error'); - } - foreach ($query as $q) { - $status = db_query ($q); - if (!$status) { - drupal_set_message(t('Error installing fb_user: %error %query', - array('%query' => '
'.$q.'
', - '%error' => db_error())), - 'error'); - } - } - + // Create tables. + drupal_install_schema('fb_user'); } -function fb_user_update_1() { - fb_user_install(); - db_query("DROP TABLE IF EXISTS {fb_user_app}"); -} \ No newline at end of file + +/** + * Implementation of hook_uninstall(). + */ +function fb_user_uninstall() { + // Remove tables. + drupal_uninstall_schema('fb_user'); +} + + +function fb_user_schema() { //TODO: reinstate error trapping for non-mysql db's - still needed? + $schema['fb_user_app'] = array( + 'fields' => array( + 'apikey' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, ), + 'fbu' => array('type' => 'int', 'length' => 11, 'unsigned' => TRUE, 'not null' => TRUE, ), + 'added' => array('type' => 'int', 'length' => 4, 'unsigned' => TRUE, 'not null' => TRUE, ), + 'time_cron' => array('type' => 'int', 'length' => 11, 'unsigned' => TRUE, 'not null' => TRUE, ), + 'time_access' => array('type' => 'int', 'length' => 11, 'unsigned' => TRUE, 'not null' => TRUE, ), + 'session_key' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, ), + 'session_key_expires' => array('type' => 'int', 'length' => 11, 'unsigned' => TRUE, 'not null' => TRUE, ), + ), + 'primary key' => array('apikey', 'fbu'), + ); + + return $schema; +} Index: fb_user.module =================================================================== --- fb_user.module (revision 1.10) +++ fb_user.module (6.x working copy) @@ -23,26 +23,23 @@ define('FB_USER_POST_ADD_PATH', 'fb_user/post_add'); define('FB_USER_POST_REMOVE_PATH', 'fb_user/post_remove'); -function fb_user_menu($may_cache) { - $items = array(); - if ($may_cache) { - global $user; - $items[] = array('path' => FB_USER_SYNC_PATH, - 'access' => $user->uid > 0, // TODO: support anonymous adds - 'callback' => 'fb_user_sync_cb', +function fb_user_menu() { + global $user; + $items[FB_USER_SYNC_PATH] = array( + 'access callback' => $user->uid > 0, // TODO: support anonymous adds + 'page callback' => 'fb_user_sync_cb', 'type' => MENU_CALLBACK, - ); - $items[] = array('path' => FB_USER_POST_ADD_PATH, - 'access' => TRUE, - 'callback' => 'fb_user_post_add_cb', + ); + $items[FB_USER_POST_ADD_PATH] = array( + 'access callback' => TRUE, + 'page callback' => 'fb_user_post_add_cb', 'type' => MENU_CALLBACK, - ); - $items[] = array('path' => FB_USER_POST_REMOVE_PATH, - 'access' => TRUE, - 'callback' => 'fb_user_post_remove_cb', + ); + $items[FB_USER_POST_REMOVE_PATH] = array( + 'access callback' => TRUE, + 'page callback' => 'fb_user_post_remove_cb', 'type' => MENU_CALLBACK, - ); - } + ); return $items; } @@ -140,7 +137,7 @@ } // And if the user's account is recognized, we can skip this. if ($user->uid && FALSE) { - drupal_goto(""); + drupal_goto(variable_get('site_frontpage', 'node')); //TODO: used to be "" - is this acceptable? exit(); } @@ -168,7 +165,7 @@ $form['redirect']['frontpage'] = array('#type' => 'radio', '#title' => t('I will register later', $t), '#description' => t('Use this application without registering on %sitename.', $t), - '#return_value' => '', + '#return_value' => variable_get('site_frontpage', 'node'), //TODO: used to be "" - is this acceptable? '#parents' => $parents, ); $form['submit'] = array('#type' => 'submit', @@ -179,11 +176,11 @@ return $form; } -function fb_user_post_add_form_submit($form_id, $values) { +function fb_user_post_add_form_submit($form, &$form_state) { //dpm(func_get_args(), 'fb_user_post_add_form_submit'); // Here we simply redirect the user to the appropriate page - return $values['redirect']; + return $form_state['values']['redirect']; } /** @@ -193,7 +190,7 @@ */ function fb_user_post_remove_cb() { global $fb, $fb_app, $user; - watchdog('debug', 'fb_user_post_remove_cb' . dprint_r($_REQUEST, 1) . dprint_r($user, 1) . dprint_r($fb_app, 1)); + watchdog('fb_user', 'fb_user_post_remove_cb'. dprint_r($_REQUEST, 1) . dprint_r($user, 1) . dprint_r($fb_app, 1), array(), WATCHDOG_DEBUG); // Update our database to reflect application is NOT added _fb_user_track($fb, $fb_app); // Nothing to return @@ -212,10 +209,15 @@ // so better to generate our own. $key = uniqid('fb_user_'); - cache_set($key, 'cache', serialize($cache_data), CACHE_TEMPORARY); + cache_set($key, serialize($cache_data), 'cache', CACHE_TEMPORARY); // Note that drupal_goto will fail here, but $fb->redirect succeeds. - $fb->redirect(url($redirect, 'auth_token='.$key, NULL, TRUE)); + $fb->redirect(url($redirect, array( + 'query' => 'auth_token='.$key, + 'absolute' => TRUE, + ) + ) + ); exit(); } @@ -232,7 +234,7 @@ // On canvas pages, require user to add the app... if ($fb) { - watchdog('debug', 'fb_user_sync_cb request ' . dprint_r($_REQUEST, 1)); + watchdog('fb_user', 'fb_user_sync_cb request '. dprint_r($_REQUEST, 1), array(), WATCHDOG_DEBUG); $fb->require_add(); @@ -260,27 +262,27 @@ drupal_access_denied(); exit(); } - watchdog('debug', 'got the data ' . dprint_r($data, 1)); + watchdog('fb_user', 'got the data '. dprint_r($data, 1), array(), WATCHDOG_DEBUG); $fbu = $data['fbu']; $fb_app = $data['fb_app']; drupal_set_title(t('Added %appname Application', array('%appname' => $fb_app->title))); if ($fbu && $fb_app) { $authname = _fb_user_authname($fb_app, $fbu); - watchdog('fb_user', t('Syncing local user %uid with facebook user %fbu via authmap entry %authname', + watchdog('fb_user', 'Syncing local user %uid with facebook user %fbu via authmap entry %authname', array('%fbu' => $fbu, '%uid' => $user->uid, - '%authname' => $authname))); + '%authname' => $authname)); user_set_authmaps($user, array('authname_fb_user' => $authname)); - watchdog('fb_user', t('Synced local user %uid with facebook user %fbu via authmap entry %authname', + watchdog('fb_user', 'Synced local user %uid with facebook user %fbu via authmap entry %authname', array('%fbu' => $fbu, '%uid' => $user->uid, - '%authname' => $authname))); + '%authname' => $authname)); drupal_set_message(t('Your local account is linked to your Facebook profile.', array('!localurl' => url('user/'.$user->uid), - '!facebookurl' => url('http://www.facebook.com/profile.php', 'id='.$fbu)))); + '!facebookurl' => url('http://www.facebook.com/profile.php', array('query' => 'id='. $fbu))))); // Give the user feedback that the sync has been successful. // Query facebook to learn more about their facebook account. @@ -464,7 +466,7 @@ if (user_access('administer fb apps')) { $fb_app = $node->fb_app; $output = theme('dl', array(t('Post-add URL') => "http://apps.facebook.com/{$fb_app->canvas}/".FB_USER_POST_ADD_PATH."?redirect=", - t('Post-remove URL') => url(FB_SETTINGS_APP_NID .'/'. $node->nid . '/' . FB_USER_POST_REMOVE_PATH, NULL, NULL, TRUE), + t('Post-remove URL') => url(FB_SETTINGS_APP_NID .'/'. $node->nid .'/'. FB_USER_POST_REMOVE_PATH, array('absolute' => TRUE)), t('Add URL') => "http://apps.facebook.com/{$fb_app->canvas}/".FB_USER_SYNC_PATH . '
' . t('(Send an authenticated user to this URL so that local account will be authmapped to facebook account.)'))); $node->content['fb_user'] = array('#value' => $output, '#weight' => 2, @@ -473,7 +475,7 @@ } } -function fb_user_form_alter($form_id, &$form) { +function fb_user_form_alter(&$form, &$form_state, $form_id) { //drupal_set_message("fb_user_form_alter($form_id) " . dpr($form, 1)); // Add our settings to the fb_app edit form. @@ -656,6 +658,14 @@ } } +function fb_user_theme() { + return array( + 'fb_app_name_with_links' => array( + 'arguments' => array('fb_app', 'is_added' => NULL), + ), + ); +} + function theme_fb_app_name_with_links($fb_app, $is_added = NULL) { $output = $fb_app->title; // TODO add link to about page @@ -745,7 +755,7 @@ $account = user_save('', $user_default); - watchdog('fb_user', t('New user: %name %email.', array('%name' => $name, '%email' => '<'. $mail .'>')), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit')); + watchdog('fb_user', 'New user: %name %email.', array('%name' => $name, '%email' => '<'. $mail .'>'), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit')); // Allow third-party modules to act after account creation. $config = _fb_invoke($fb_app, FB_OP_POST_USER, @@ -754,8 +764,8 @@ // TODO: move this to fb_action. Temporarily disabled. if (FALSE) { // Prepare to send an email. - $base = url('', NULL, NULL, TRUE); - $variables = array('!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'), '!password' => $user_default['pass'], '!uri' => $base, '!uri_brief' => substr($base, strlen('http://')), '!mailto' => $mail, '!date' => format_date(time()), '!login_uri' => url('user', NULL, NULL, TRUE), '!edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE), '!login_url' => user_pass_reset_url($account)); + $base = url('', array('absolute' => TRUE)); + $variables = array('!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'), '!password' => $user_default['pass'], '!uri' => $base, '!uri_brief' => substr($base, strlen('http://')), '!mailto' => $mail, '!date' => format_date(time()), '!login_uri' => url('user', array('absolute' => TRUE)), '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE)), '!login_url' => user_pass_reset_url($account)); $subject = _user_mail_text('welcome_subject', $variables); $body = _user_mail_text('welcome_body', $variables); @@ -783,7 +793,7 @@ */ function fb_user_get_local_user($fbu, $fb_app) { // TODO: this query probably needs to search for one authname or the other, not both. - $result = db_query("SELECT am.* FROM authmap am WHERE am.authname='%s' OR am.authname='%s' ORDER BY am.authname", + $result = db_query("SELECT am.* FROM {authmap} am WHERE am.authname='%s' OR am.authname='%s' ORDER BY am.authname", "$fbu-$fb_app->apikey@facebook.com", "$fbu@facebook.com"); if ($data = db_fetch_object($result)) { $account = user_load(array('uid' => $data->uid)); @@ -852,5 +862,3 @@ return $values; } - -?> \ No newline at end of file