function fb_test_accounts_form_submit in Drupal for Facebook 7.3
Same name and namespace in other branches
- 6.3 contrib/fb_test.module \fb_test_accounts_form_submit()
File
- contrib/
fb_test.module, line 155 - http://developers.facebook.com/docs/test_users
Code
function fb_test_accounts_form_submit($form, &$form_state) {
$values = $form_state['values'];
$fb_app = $form['#fb_app'];
$fb = fb_api_init($fb_app);
try {
if ($values['operation'] == 'friends') {
foreach ($values['checkboxes'] as $fbu => $selected) {
if ($selected && isset($form['#fb_test_accounts'][$fbu]['access_token'])) {
foreach ($values['checkboxes'] as $fbu2 => $selected2) {
if ($selected2 && $fbu != $fbu2) {
try {
$result = $fb
->api("{$fbu}/friends/{$fbu2}", "POST", array(
'access_token' => $form['#fb_test_accounts'][$fbu]['access_token'],
));
if ($result) {
drupal_set_message(t("User %fbu is friends with {$fbu2}.", array(
'%fbu' => $fbu,
'%fbu2' => $fbu2,
)));
}
} catch (Exception $e) {
$message = t("Failed to create friendship between %fbu and %fbu2.", array(
'%fbu' => $fbu,
'%fbu2' => $fbu2,
));
fb_log_exception($e, $message);
}
}
}
}
}
}
elseif ($values['operation'] == 'delete') {
foreach ($values['checkboxes'] as $fbu => $selected) {
if ($selected) {
$result = $fb
->api($fbu, 'DELETE', array(
'access_token' => fb_get_token($fb),
));
if ($result) {
drupal_set_message(t('Deleted test account %fbu', array(
'%fbu' => $fbu,
)));
}
}
}
}
else {
if (function_exists('dpm')) {
dpm("Operation {$values['operation']} not implemented.", __FUNCTION__);
}
}
} catch (Exception $e) {
fb_log_exception($e, t('Failed to perform operation.'));
}
}