You are here

function gravatar_admin_settings in Gravatar integration 5

Same name and namespace in other branches
  1. 6 gravatar.admin.inc \gravatar_admin_settings()
  2. 7 gravatar.admin.inc \gravatar_admin_settings()

Administration settings form.

See also

system_settings_form()

1 string reference to 'gravatar_admin_settings'
gravatar_menu in ./gravatar.module
Implementation of hook_menu().

File

./gravatar.module, line 277
Integrates gravatar service for comment user pictures.

Code

function gravatar_admin_settings() {
  $form = array();

  // Display settings.
  $form['display'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display'),
  );
  $form['display']['gravatar_prepend'] = array(
    '#type' => 'radios',
    '#title' => t('Display method'),
    '#default_value' => gravatar_var('prepend'),
    '#options' => array(
      1 => t('Prepend the Gravatar picture to the comment'),
      0 => t('Leave it up to the theme to add (<a href="@readme">Only if supported by your theme</a>)', array(
        '@readme' => url(drupal_get_path('module', 'gravatar') . '/README.txt'),
      )),
    ),
  );
  $form['display']['gravatar_size'] = array(
    '#type' => 'item',
    '#title' => t('Image size'),
    '#description' => t('The preferred image size (maximum 512 pixels). This setting can be adjusted in the <a href="@user-picture-link">user pictures settings</a>.', array(
      '@user-picture-link' => url('admin/user/settings', NULL, 'edit-user-picture-default'),
    )),
    '#value' => t('@sizex@size pixels', array(
      '@size' => _gravatar_get_size(),
    )),
  );
  $form['display']['gravatar_rating'] = array(
    '#type' => 'select',
    '#title' => t('Image maturity filter'),
    '#default_value' => gravatar_var('rating'),
    '#options' => drupal_map_assoc(array(
      'G',
      'PG',
      'R',
      'X',
    )),
    '#description' => theme('item_list', array(
      t('G: Suitable for display on all websites with any audience type.'),
      t('PG: May contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence.'),
      t('R: May contain such things as harsh profanity, intense violence, nudity, or hard drug use.'),
      t('X: May contain hardcore sexual imagery or extremely disturbing violence.'),
    )),
  );
  $form['display']['gravatar_default'] = array(
    '#type' => 'radios',
    '#title' => t('Default image'),
    '#description' => t('Specifies an image that should be returned if either the requested e-mail address has no associated gravatar, or that gravatar has a rating higher than is allowed by the maturity filter.'),
    '#options' => array(
      GRAVATAR_DEFAULT_GLOBAL => t('Global default user image'),
      GRAVATAR_DEFAULT_MODULE => t('Module default image (white background)'),
      GRAVATAR_DEFAULT_MODULE_CLEAR => t('Module default image (transparent background)'),
      GRAVATAR_DEFAULT_IDENTICON => t('Gravatar.com identicon (generated)'),
      GRAVATAR_DEFAULT_WAVATAR => t('Gravatar.com wavatar (generated)'),
      GRAVATAR_DEFAULT_MONSTERID => t('Gravatar.com monsterid (generated)'),
      GRAVATAR_DEFAULT_LOGO => t('Gravatar.com logo'),
    ),
    '#default_value' => gravatar_var('default'),
    '#prefix' => '<div class="picture js-show">' . theme('image', '', t('Default picture example'), t('Default picture example'), array(
      'id' => 'gravatar-imagepreview',
    ), FALSE) . '</div>',
  );

  // Add JavaScript and CSS to swap the defalut image previews.
  drupal_add_js(drupal_get_path('module', 'gravatar') . '/gravatar.js');
  drupal_add_css(drupal_get_path('module', 'gravatar') . '/gravatar.css');

  // Add default picture options manually so we can disable individual radios.
  foreach ($form['display']['gravatar_default']['#options'] as $option_index => $option_title) {
    $option_element =& $form['display']['gravatar_default'][$option_index];
    $option_element = array(
      '#type' => 'radio',
      '#title' => $option_title,
      '#return_value' => $option_index,
      '#default_value' => gravatar_var('default'),
      '#parents' => array(
        'gravatar_default',
      ),
      '#disabled' => FALSE,
    );
    switch ($option_index) {
      case GRAVATAR_DEFAULT_GLOBAL:
        $option_element['#description'] = t('This setting can be adjusted in the <a href="@user-picture-link">user pictures settings</a>.', array(
          '@user-picture-link' => url('admin/user/settings', NULL, 'edit-user-picture-default'),
        ));

        // If the global user picture is empty, disable the respective option.
        if (!variable_get('user_picture_default', '')) {
          $option_element['#disabled'] = TRUE;
          $option_element['#description'] = t('There currently is not a global default user picture specified.') . ' ' . $option_element['#description'];
        }
        break;
    }

    // Add an image to preview this default image option.
    $attributes = array(
      'id' => 'gravatar-imagepreview-' . $option_index,
      // Hide the image if the respective option is disabled.
      'class' => 'js-hide' . ($option_element['#disabled'] ? ' hide' : ''),
    );
    $option_element['#suffix'] = theme('image', _gravatar_get_gravatar(array(
      'default' => _gravatar_get_default_image($option_index),
    )), $option_title, $option_title, $attributes, FALSE);
  }

  // Advanced settings.
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced'),
    '#description' => t('Do not modify these options unless you know what you are doing!'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['gravatar_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Gravatar URL'),
    '#default_value' => variable_get('gravatar_url', 'http://www.gravatar.com/avatar/'),
  );
  return system_settings_form($form);
}