You are here

function avatar_selection_upload_form in Avatar Selection 6

Same name and namespace in other branches
  1. 5.2 avatar_selection.module \avatar_selection_upload_form()
  2. 7 avatar_selection.admin.inc \avatar_selection_upload_form()

Create the form structure for uploading an avatar.

Return value

Return the structure of the form.

2 string references to 'avatar_selection_upload_form'
avatar_selection_menu in ./avatar_selection.module
Implementation of hook_menu().
avatar_selection_settings_page in ./avatar_selection.admin.inc
Select which form will be shown to the user, according to the permissions.

File

./avatar_selection.admin.inc, line 180
Administrative page callbacks for the avatar_selection module.

Code

function avatar_selection_upload_form() {
  if (!variable_get('user_pictures', 0)) {
    drupal_set_message(t('User Pictures option is disabled.  You will need to enable this option before you can use the Avatar Selection module.  You may configure this setting on the <a href="@url">User settings</a> page.', array(
      '@url' => url('admin/user/settings'),
    )));
  }
  $form['#attributes']['enctype'] = 'multipart/form-data';
  $form['bulk_upload'] = array(
    '#type' => 'fieldset',
    '#title' => t('Bulk Upload / Delete'),
    '#description' => t("To upload a large number of avatars, first copy the images manually to the %dir folder, using ftp for example.  To make these new avatar images available, check the 'Scan for new avatars' option. All new images will then be added to the list.  By removing files from this directory and checking the box, you can also perform a bulk delete.", array(
      '%dir' => file_create_path('avatar_selection'),
    )),
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
  );
  $form['bulk_upload']['scan_avatars'] = array(
    '#type' => 'checkbox',
    '#title' => t('Scan avatars'),
    '#description' => t('All new avatar images found will be added to the list of available avatars with the name, weight and permissions defined below.  Scanning for new avatars may be slow depending on the number of files.  All avatar entries which no longer have a corresponding file will be be removed.'),
    '#default_value' => 0,
  );
  $form['picture_upload'] = array(
    '#type' => 'file',
    '#title' => t('Upload image'),
    '#size' => 48,
    '#description' => t('A new avatar image.  Maximum dimensions are %dimensions and the maximum size is %size kB.  Images must have one of the following extensions (case sensitive): png, jpg, jpeg, gif, PNG, JPG, JPEG, GIF.', array(
      '%dimensions' => variable_get('user_picture_dimensions', '85x85'),
      '%size' => variable_get('user_picture_file_size', 30),
    )) . ' ' . variable_get('user_picture_guidelines', ''),
  );
  $form['avatar_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t("Image name or title which will be displayed when hovering over the image.  It's also used in conjunction with the weight setting for sorting the avatars."),
    '#size' => 48,
  );
  $form['avatar_weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#delta' => 100,
    '#description' => t('Avatars with a lower weight appear before higher weighted avatars in lists.'),
  );
  $form['permissions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Permissions'),
    '#weight' => 2,
  );
  $form['permissions']['access'] = array(
    '#type' => 'checkboxes',
    '#title' => t('User Roles'),
    '#options' => avatar_selection_handler_filter_role(),
    '#description' => t('Only the checked roles will be able to see this avatar icon; if no roles are checked, access will not be restricted.'),
  );
  if (module_exists('og')) {
    $form['permissions']['og_access'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Organic Groups'),
      '#options' => og_all_groups_options(),
      '#description' => t('Only users in the checked organic groups will be able to see this avatar icon; if no groups are checked, access will not be restricted.'),
    );
  }
  $form['upload'] = array(
    '#type' => 'submit',
    '#value' => t('Upload'),
    '#weight' => 10,
  );
  return $form;
}