| 1 |
<?php
|
| 2 |
// $Id: unique_avatar.module,v 1.1 2008/01/29 18:08:51 jscheel Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file unique_avatar.module
|
| 6 |
*
|
| 7 |
* Full module implementation, creates unique user picture filenames
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_user()
|
| 12 |
*/
|
| 13 |
function unique_avatar_user($type, &$edit, &$user, $category = NULL) {
|
| 14 |
if ($type == 'submit' && $category == 'account') {
|
| 15 |
|
| 16 |
//Is the user picture being modified?
|
| 17 |
$file = file_check_upload('picture_upload');
|
| 18 |
if ($file) {
|
| 19 |
$info = image_get_info($file->filepath);
|
| 20 |
|
| 21 |
//Rename picture with unique id
|
| 22 |
$dest = variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid . '-' . md5(time()) . '.' . $info['extension'];
|
| 23 |
if (file_move($file->filepath, $dest)) {
|
| 24 |
|
| 25 |
//Clean up existing picture
|
| 26 |
if (module_exists('imagecache')) {
|
| 27 |
imagecache_image_flush($user->picture);
|
| 28 |
}
|
| 29 |
file_delete($user->picture);
|
| 30 |
|
| 31 |
//Assign new picture
|
| 32 |
$edit['picture'] = file_directory_path() . '/' . $dest;
|
| 33 |
$user->picture = file_directory_path() . '/' . $dest;
|
| 34 |
}
|
| 35 |
}
|
| 36 |
}
|
| 37 |
}
|