function reg_with_pic_user in Register with Picture 5
Same name and namespace in other branches
- 6 reg_with_pic.module \reg_with_pic_user()
Implementation of hook_user()
File
- ./
reg_with_pic.module, line 10 - This module allows a user picture to be uploaded at registration time.
Code
function reg_with_pic_user($op, &$edit, &$user, $category = null) {
if (variable_get('user_pictures', 0)) {
switch ($op) {
case 'register':
// setup picture upload in registration form
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['picture'] = array(
'#type' => 'fieldset',
'#title' => t('Picture'),
'#weight' => 1,
);
$form['picture']['picture_upload_register'] = array(
'#type' => 'file',
'#title' => t('Upload picture'),
'#description' => t('<br>Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array(
'%dimensions' => variable_get('user_picture_dimensions', '85x85'),
'%size' => variable_get('user_picture_file_size', '30'),
)) . ' ' . variable_get('user_picture_guidelines', ''),
);
return $form;
break;
case 'validate':
// validate uploaded picture
if ($file = file_check_upload('picture_upload_register')) {
reg_with_pic_validate_picture($file, $edit, $user);
}
break;
case 'insert':
// copy picture to the proper directory now that we have the userid.
$file = file_check_upload('picture_upload_register');
$info = image_get_info($file->filepath);
// upload file and write path to user record
if ($file = file_save_upload('picture_upload_register', variable_get('user_picture_path', 'pictures') . '/picture-' . $user->uid . '.' . $info['extension'], 1)) {
db_query("UPDATE {users} SET picture='%s' WHERE uid=%d", $file->filepath, $user->uid);
}
break;
}
}
}