Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Submit the image upload form in the Avatar Selection administration page.
- *
- * @param $form
- * General variable used in drupal, defining the structure & the fields of a
- * form.
- * @param &$form_state
- * General reference, used to control the processing of the form.
- */
- function avatar_selection_upload_form_submit($form, &$form_state) {
- $op = $form_state['values']['op'];
- if ($op == t('Upload')) {
- // Get access settings.
- $access = array_keys(array_filter($form_state['values']['access']));
- // $og = array();
- // if (module_exists('og')) {
- // $og = array_keys(array_filter($form_state['values']['og_access']));
- // }
- $name = $form_state['values']['avatar_name'];
- $weight = $form_state['values']['avatar_weight'];
- // Scan for new files.
- if ($form_state['values']['scan_avatars'] == 1) {
- $count = _avatar_selection_scan_images($name, $access, /*$og, */$weight);
- drupal_set_message(t('Scan complete: %added new avatars found. %deleted avatars removed.', array('%added' => $count['add'], '%deleted' => $count['delete'])));
- }
- // Save uploaded files.
- $dir = file_build_uri('avatar_selection');
- $is_writable = file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
- if ($is_writable) {
- // If required, validate the uploaded picture.
- $validators = array(
- 'file_validate_is_image' => array(),
- 'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
- 'file_validate_size' => array(variable_get('user_picture_file_size', 30) * 1024),
- );
- if ($file = file_save_upload('picture_upload', $validators, $dir, FILE_EXISTS_RENAME)) {
- if (image_get_info($file->uri)) {
- $info = image_get_info($file->uri);
- global $user;
- $file->status = FILE_STATUS_PERMANENT;
- $file->filename = 'avatar' . '-' . $user->uid . '-' . REQUEST_TIME . '.' . $info['extension'];
- $file = file_save($file);
- _avatar_selection_save_avatar_info(0, $file->filename, $name, $access, /*$og, */$weight);
- drupal_set_message(t('New image saved.'));
- }
- else {
- file_delete($file->uri);
- drupal_set_message(t('Uploaded file does not appear to be a valid image file. Please try again.'));
- }
- }
- }
- else {
- form_set_error('picture_upload', t('Directory not writable: !dir', array('!dir' => $dir)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement