function fb_admin_token_generate_process in Drupal for Facebook 7.4
1 string reference to 'fb_admin_token_generate_process'
- fb_element_info in ./fb.module
- Implements hook_element_info().
File
- ./fb.admin.inc, line 1524
Code
function fb_admin_token_generate_process(&$element, &$form_state, &$form) {
$element = $element + array(
'#scope' => array(),
'#options' => array(),
);
$element['#tree'] = TRUE;
unset($element['#needs_validation']);
$all_apps = fb_admin_all_apps();
$scope = implode(',', $element['#scope']);
$new_token_options = $element['#options'] + array(
-1 => t('Do not save new token'),
);
foreach ($all_apps as $app_data) {
if (!empty($app_data['secret'])) {
$auth_url = fb_server_auth_url(array(
'fba' => $app_data['fba'],
'scope' => $scope,
));
}
elseif (!empty($app_data['data']['access_token'])) {
$auth_url = fb_client_auth_url(array(
'fba' => $app_data['fba'],
'scope' => $scope,
));
}
else {
$auth_url = fb_remote_auth_url($app_data + array(
'scope' => $scope,
));
}
$generate_links[] = array(
'title' => t('Generate new token via %application', array(
'%application' => $app_data['title'],
)),
'href' => $auth_url,
'html' => TRUE,
);
if (empty($_POST) && ($token = fb_auth_get_token($app_data))) {
if (empty($new_token_options[$token])) {
try {
$me = fb_graph('me', $token);
$app = fb_graph('app', $token);
$new_token_options[$token] = t('%user_name via the %app_name application', array(
'%user_name' => fb_get_name($me),
'%app_name' => fb_get_name($app),
));
drupal_set_message(t('Generated a new access token, but not yet saved. Remember to press the submit button.'), 'warning');
$default_token = $token;
} catch (exception $e) {
fb_log_exception($e, t('Failed to save new access token for %application.', array(
'%application' => $app['title'],
)), $token);
drupal_set_message(t('Failed to validate new token. You may <a target=_blank href=!token_debug_url>debug the token on Facebook</a>.', array(
'!token_debug_url' => 'https://developers.facebook.com/tools/debug/access_token?q=' . $token,
)), 'error');
}
try {
$accounts = fb_graph('me/accounts', $token);
foreach ($accounts['data'] as $account_data) {
if (!empty($account_data['access_token'])) {
$new_token_options[$account_data['access_token']] = t('%account_name (%account_type) via %app_name', array(
'%account_name' => fb_get_name($account_data),
'%account_type' => $account_data['category'],
'%app_name' => !empty($app) ? fb_get_name($app) : t('(could not determine application)'),
));
}
}
} catch (Exception $e) {
}
}
}
}
if (count($new_token_options) > 1) {
$element['fb_admin_token_generate_new'] = array(
'#type' => 'radios',
'#options' => $new_token_options,
'#default_value' => $default_token,
);
}
if (!empty($generate_links)) {
$element['fb_admin_token_generate_links'] = array(
'#theme' => 'links',
'#links' => $generate_links,
);
}
return $element;
}