summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Cohen2011-08-01 18:29:56 (GMT)
committer Dave Cohen2011-08-01 18:29:56 (GMT)
commitde5d0e5a2e54aa129d32a35651986722bd03bda5 (patch)
tree60120d3f7bd73523e425d5e596c0ab156ebc5400
parent9c55934d6d6198fa8cc3443d0246e2bc37853025 (diff)
Clean up op constants for hook_fb().
Added fb_api_batch() helper (but likely to change it in the near future, work in progress).
-rw-r--r--contrib/fb_example.module2
-rw-r--r--contrib/fb_rules.module4
-rw-r--r--fb.module32
-rw-r--r--fb_user.module8
4 files changed, 33 insertions, 13 deletions
diff --git a/contrib/fb_example.module b/contrib/fb_example.module
index 5fbd534..04d50b2 100644
--- a/contrib/fb_example.module
+++ b/contrib/fb_example.module
@@ -314,7 +314,7 @@ function fb_example_fb($op, $data, &$return) {
* asking for information.
* - FB_USER_OP_PRE_USER - You have a chance to the name or other account
* attributes, before a new user account is created.
- * - FB_OP_POST_USER - A new user account was created for a facebook user
+ * - FB_USER_OP_POST_USER - A new user account was created for a facebook user
* who authorized an app.
*
* @param $data
diff --git a/contrib/fb_rules.module b/contrib/fb_rules.module
index 620cad8..690dbeb 100644
--- a/contrib/fb_rules.module
+++ b/contrib/fb_rules.module
@@ -17,10 +17,10 @@ function fb_rules_fb_user($op, $data, &$return) {
// Use devel module to figure out when this hook is called and what it is passed.
// dpm(func_get_args(), "fb_rules_fb($op) called"); // debug
- if ($op == FB_OP_POST_USER_CONNECT) { // User connected local account with FB account
+ if ($op == FB_USER_OP_POST_USER_CONNECT) { // User connected local account with FB account
rules_invoke_event('fb_user_connected', $user);
}
- elseif ($op == FB_OP_POST_USER_DISCONNECT) { // User disconnected local account from FB account
+ elseif ($op == FB_USER_OP_POST_USER_DISCONNECT) { // User disconnected local account from FB account
rules_invoke_event('fb_user_disconnected', $user);
}
elseif ($op == FB_USER_OP_POST_EXTERNAL_LOGIN) { // User logged in through FB
diff --git a/fb.module b/fb.module
index 1259e70..297f96f 100644
--- a/fb.module
+++ b/fb.module
@@ -24,14 +24,7 @@ define('FB_OP_GET_FBU', 'get_fbu'); // Query the local user's FB account
define('FB_OP_GET_UID', 'get_uid'); // Query the facebook user's local account
define('FB_OP_GET_USER_SESSION', 'get_user_sess');
-// These have moved to fb_user.module!
-//define('FB_OP_PRE_USER', 'pre_user'); // Before account creation, fb_user.module
-//define('FB_OP_POST_USER', 'post_user'); // After account creation, fb_user.module
-//define('FB_OP_POST_EXTERNAL_LOGIN', 'post_external_login'); // user map has changed global user.
-
define('FB_OP_APP_IS_AUTHORIZED', 'app_authorized'); // Invoked if user has authorized an app. Triggers creation of user accounts or fb_user entries
-define('FB_OP_POST_USER_CONNECT', 'post_user_connect'); // Connected local account to FB account, fb_user.module
-define('FB_OP_POST_USER_DISCONNECT', 'post_user_disconnect'); // Disconnected local account from FB account, fb_user.module
define('FB_OP_JS', 'fb_op_js'); // A chance to inject javascript onto the page.
define('FB_OP_AJAX_EVENT', 'fb_op_ajax'); // Notification of an event via ajax.
@@ -551,6 +544,31 @@ function fb_fql_query($fb, $query, $params = array()) {
return $result;
}
+/**
+ * Helper function for facebook's batch graph api.
+ *
+ * It's relatively painful to decode all the data.
+ *
+ * @TODO clean up api for this function, parameters a likely to change, use with caution.
+ */
+function fb_api_batch($fb, $queries, $params) {
+ $data = array();
+
+ $wrapped_data = $fb->api('/?batch=' . json_encode($queries), 'POST', $params);
+
+ foreach ($wrapped_data as $w_d) {
+ if ($w_d['code'] == 200 && isset($w_d['body'])) {
+ $data[] = json_decode($w_d['body'], TRUE);
+ }
+ else {
+ // Unexpected code
+ $data[] = $w_d;
+ }
+ }
+
+ return $data;
+}
+
/**
* Implements hook_footer().
diff --git a/fb_user.module b/fb_user.module
index faa24e3..e2a1dff 100644
--- a/fb_user.module
+++ b/fb_user.module
@@ -47,6 +47,8 @@ define('FB_USER_CONTROL_NO_REDIRECT', 'fb_user_no_redirect');
define('FB_USER_OP_PRE_USER', 'pre_user'); // Before account creation, fb_user.module
define('FB_USER_OP_POST_USER', 'post_user'); // After account creation, fb_user.module
define('FB_USER_OP_POST_EXTERNAL_LOGIN', 'post_external_login'); // user map has changed global user.
+define('FB_USER_OP_POST_USER_CONNECT', 'post_user_connect'); // Connected local account to FB account, fb_user.module
+define('FB_USER_OP_POST_USER_DISCONNECT', 'post_user_disconnect'); // Disconnected local account from FB account, fb_user.module
/**
@@ -298,7 +300,7 @@ function _fb_user_create_map() {
!$account &&
!fb_controls(FB_USER_CONTROL_NO_CREATE_MAP)) {
_fb_user_set_map($GLOBALS['user'], $fbu);
- fb_invoke(FB_OP_POST_USER_CONNECT, array('account' => $GLOBALS['user']), NULL, 'fb_user');
+ fb_invoke(FB_USER_OP_POST_USER_CONNECT, array('account' => $GLOBALS['user']), NULL, 'fb_user');
return TRUE;
}
}
@@ -313,7 +315,7 @@ function _fb_user_create_map_by_email() {
($email_account = fb_user_get_local_user_by_email($fbu)) &&
!fb_controls(FB_USER_CONTROL_NO_CREATE_MAP)) {
_fb_user_set_map($email_account, $fbu);
- fb_invoke(FB_OP_POST_USER_CONNECT, array('account' => $GLOBALS['user']), NULL, 'fb_user');
+ fb_invoke(FB_USER_OP_POST_USER_CONNECT, array('account' => $GLOBALS['user']), NULL, 'fb_user');
return TRUE;
}
return FALSE;
@@ -727,7 +729,7 @@ function fb_user_user($op, &$edit, &$account, $category = NULL) {
else {
// Delete account mapping, because administrator has unchecked the connect option.
db_query('DELETE FROM {fb_user} WHERE uid=%d', $account->uid);
- fb_invoke(FB_OP_POST_USER_DISCONNECT, array('account' => $account), NULL, 'fb_user');
+ fb_invoke(FB_USER_OP_POST_USER_DISCONNECT, array('account' => $account), NULL, 'fb_user');
}
}
elseif ($op == 'delete') {