facebook_album.admin.inc in Facebook Album 7.3
Same filename and directory in other branches
facebook_album.admin.inc Facebook Album administration pages.
File
facebook_album.admin.incView source
<?php
/**
* @file facebook_album.admin.inc
* Facebook Album administration pages.
*/
/**
* Implements hook_admin().
*
*/
function facebook_album_admin_form() {
$form = array();
$form = system_settings_form($form);
$form['facebook_album_appID'] = array(
'#type' => 'textfield',
'#title' => t('Facebook Application ID'),
'#default_value' => variable_get('facebook_album_appID', ''),
'#description' => t("The application ID specified in your Facebook App's dashboard page."),
);
$form['facebook_album_appSecret'] = array(
'#type' => 'password',
'#title' => t('Facebook Application Secret'),
'#default_value' => '',
'#description' => t("The application secret specified in your Facebook App's dashboard page. This field remains blank for security purposes. If you have already saved your application secret, leave this field blank, unless you wish to update it."),
);
$form['facebook_album_block_num'] = array(
'#title' => t('Number of Blocks Needed'),
'#type' => 'select',
'#options' => array(
1 => 1,
2 => 2,
3 => 3,
4 => 4,
),
'#default_value' => variable_get('facebook_album_block_num', 1),
);
array_unshift($form['#submit'], 'facebook_album_admin_form_submit');
return $form;
}
/**
* Implements hook_admin()
*
* Attempts to fetch an application access token from facebook
* based off of the app ID and app secret specified in the form
*/
function facebook_album_admin_form_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
variable_set('facebook_album_access_token', NULL);
$app_id = $form_state['values']['facebook_album_appID'];
$app_secret = $form_state['values']['facebook_album_appSecret'];
if (empty($app_secret) || strlen(trim($app_secret)) < 1) {
$app_secret = variable_get('facebook_album_appSecret');
unset($form_state['values']['facebook_album_appSecret']);
}
$token = _facebook_album_fetch_application_access_token($app_id, $app_secret);
if (isset($token['error'])) {
$message = _facebook_album_translate_api_error($token['error']['code'], $token['error']['message']);
if ($message == 'Invalid Client ID') {
form_set_error('facebook_album_appID', $message);
}
elseif ($token['error']['code'] == 1) {
form_set_error('facebook_album_appID', $message);
form_set_error('facebook_album_appSecret');
}
else {
drupal_set_message(check_plain($message), 'error');
}
}
else {
variable_set('facebook_album_access_token', $token['access_token']);
}
}
/**
* Implements hook_validate()
*/
function facebook_album_admin_form_validate($form, &$form_state) {
$app_secret = $form_state['values']['facebook_album_appSecret'];
$stored_app_secret = variable_get('facebook_album_appSecret');
if (empty($stored_app_secret) && empty($app_secret)) {
form_set_error('facebook_album_appSecret', t("Missing Application Secret"));
}
}
/**
* Build and make the api call for retrieving application access tokens
* from the facebook api.
*
* @param $app_id
* The application ID specified in the settings menu
* @param $app_secret
* The application secret specified in the settings menu
* @return mixed
* A response rendered as an array
*/
function _facebook_album_fetch_application_access_token($app_id, $app_secret) {
$url = _facebook_album_build_api_request(API_AUTH_PATH . 'access_token', array(
'client_id' => $app_id,
'client_secret' => $app_secret,
'grant_type' => 'client_credentials',
));
return _facebook_album_fetch_api_response($url);
}
Functions
Name | Description |
---|---|
facebook_album_admin_form | Implements hook_admin(). |
facebook_album_admin_form_submit | Implements hook_admin() |
facebook_album_admin_form_validate | Implements hook_validate() |
_facebook_album_fetch_application_access_token | Build and make the api call for retrieving application access tokens from the facebook api. |