You are here

function flickrapi_admin_settings in Flickr API 7.2

Same name and namespace in other branches
  1. 5 flickrapi.module \flickrapi_admin_settings()
  2. 6 flickrapi.module \flickrapi_admin_settings()
  3. 7 flickrapi.admin.inc \flickrapi_admin_settings()

Admin settings form

1 string reference to 'flickrapi_admin_settings'
flickrapi_menu in ./flickrapi.module
Implements hook_menu().

File

./flickrapi.admin.inc, line 11
Admin settings form and OAuth authentication integration

Code

function flickrapi_admin_settings() {
  $form = array();
  $api_key = variable_get('flickrapi_api_key', '');
  $form['flickrapi_api_key'] = array(
    '#type' => 'textfield',
    '#title' => t('API Key'),
    '#required' => TRUE,
    '#default_value' => $api_key,
  );
  if (empty($api_key)) {
    $form['flickrapi_api_key']['#description'] = t('API Key from Flickr. !link', array(
      '!link' => l(t('Get one!'), 'http://www.flickr.com/services/apps/by/me'),
    ));
  }
  else {
    $form['flickrapi_api_key']['#description'] = t('API Key from Flickr.');
  }
  $form['flickrapi_api_secret'] = array(
    '#type' => 'textfield',
    '#title' => t('API Shared Secret'),
    '#required' => TRUE,
    '#default_value' => variable_get('flickrapi_api_secret', ''),
    '#description' => t("API key's secret from Flickr."),
  );
  if (!_flickrapi_is_authenticated()) {
    $form['flickr_api_verified'] = array(
      'heading' => array(
        '#markup' => t('<label>OAuth verification status</label>'),
      ),
      'image' => array(
        '#theme' => 'image',
        '#path' => drupal_get_path('module', 'flickrapi') . '/images/false.png',
        '#attributes' => array(
          'style' => 'float: left; margin: 10px 10px 0 0; ',
        ),
      ),
      'text' => array(
        '#markup' => '<p>' . t('Not verified yet') . '<br />' . t('Save this settings form to verify your credentials.') . '</p>',
      ),
    );
  }
  else {
    $form['flickr_api_verified'] = array(
      'heading' => array(
        '#markup' => t('<label>OAuth verification status</label>'),
      ),
      'image' => array(
        '#theme' => 'image',
        '#path' => drupal_get_path('module', 'flickrapi') . '/images/true.png',
        '#attributes' => array(
          'style' => 'float: left; margin: 10px 10px 0 0; ',
        ),
      ),
      'text' => array(
        '#markup' => '<p>' . t('Verified') . '<br />' . l(t('Delete access token'), 'admin/config/media/flickrapi/clear') . '</p>',
      ),
    );
  }
  $times = array(
    900,
    1800,
    2700,
    3600,
    7200,
    10800,
    14400,
    18000,
    21600,
    43200,
    86400,
  );
  $ageoptions = drupal_map_assoc($times, 'format_interval');
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => variable_get('flickrapi_access_permissions', array(
      'read',
    )) == 'read' && variable_get('flickrapi_cache', TRUE) == TRUE ? TRUE : FALSE,
  );
  $form['advanced']['flickrapi_access_permissions'] = array(
    '#type' => 'radios',
    '#title' => t('Flickr Access Permissions'),
    '#options' => array(
      'read' => t('Read only (default)'),
      'write' => t('Read & Write'),
      'delete' => t('Read, Write & Delete'),
    ),
    '#description' => t('If you change the access permissions after authentication, you need to re-authenticate your website.'),
    '#default_value' => variable_get('flickrapi_access_permissions', 'read'),
  );
  $form['advanced']['caching'] = array(
    '#type' => 'fieldset',
    '#title' => t('Cache settings'),
    '#description' => t('Caching can improve page loading speeds for your users if you are calling the same Flickr requests frequently. You may want to disable it for testing, to save on your own bandwidth costs, or if you have concerns about keeping images on your own server. Note that some Flickr methods enforce restrictions on the frequency with which they may be called, !documented.', array(
      '!documented' => l(t('as per the documentation'), 'http://www.flickr.com/services/api/'),
    )),
    '#collapsible' => TRUE,
  );
  $form['advanced']['caching']['flickrapi_cache'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow Flickr API to store results on your server'),
    '#default_value' => variable_get('flickrapi_cache', TRUE),
  );
  $form['advanced']['caching']['flickrapi_cache_path'] = array(
    '#title' => t('Flickr Cache Path'),
    '#description' => t('Location on the server file system where the results will be cached.'),
    '#type' => 'textfield',
    '#default_value' => variable_get('flickrapi_cache_path', variable_get('file_public_path', 'sites/default/files') . '/flickr'),
    '#states' => array(
      'visible' => array(
        ':input[name="flickrapi_cache"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['advanced']['caching']['flickrapi_cache_duration'] = array(
    '#type' => 'select',
    '#title' => t('Update Interval'),
    '#options' => $ageoptions,
    '#default_value' => variable_get('flickrapi_cache_duration', 3600),
    '#description' => t('How often you want to check cached Flickr API calls are up to date?'),
    '#states' => array(
      'visible' => array(
        ':input[name="flickrapi_cache"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['#validate'][] = 'flickrapi_admin_settings_validate';
  $form['#submit'][] = 'flickrapi_admin_settings_submit';
  return system_settings_form($form);
}