--- path to module/avatarcrop/avatarcrop.module 2009-11-26 18:40:44.000000000 +0500 +++ path to module/avatarcrop/avatarcrop.module 2010-01-14 10:20:49.000000000 +0500 @@ -17,9 +17,7 @@ function avatarcrop_init() { drupal_add_js(drupal_get_path('module','avatarcrop').'/js/jquery.Jcrop.js'); drupal_add_css(drupal_get_path('module','avatarcrop').'/css/jquery.Jcrop.css'); drupal_add_css(drupal_get_path('module','avatarcrop').'/avatarcrop.css'); - - - + } function avatarcrop_menu() { @@ -27,14 +25,14 @@ function avatarcrop_menu() { $items = array(); $items['user/cropimage'] = array( - 'title' => '', + 'title' => t('Crop Image'), 'page callback' => 'drupal_get_form', 'page arguments' => array('cropUserPic'), 'access arguments' => avatarcrop_perm(), 'type' => MENU_CALLBACK ); $items['user/getimage'] = array( - 'title' => '', + 'title' => t('Upload Image'), 'page callback' => 'drupal_get_form', 'page arguments' => array('avatarcrop_form'), 'access arguments' => avatarcrop_perm(), @@ -50,10 +48,10 @@ function avatarcrop_user($op, &$edit, &$ $enablePicture=variable_get('user_pictures','0'); if($enablePicture) { if($users->picture){ - $pictureMsg = 'Change Avatar'; + $pictureMsg = t('Change Avatar'); } else { - $pictureMsg = 'Upload Picture'; + $pictureMsg = t('Upload Picture'); } $base=base_path(); global $user; @@ -85,7 +83,7 @@ $form = array(); $form['avatar_crop_title']=array( '#prefix' => '
', '#suffix' => '
', - '#value' => 'Choose profile picture.', + '#value' => t('Choose profile picture.'), ); $form['file_upload'] = array( '#title' => t('Upload file'), @@ -104,7 +102,7 @@ $form = array(); $form2['user_picture_disable']=array( '#prefix' => '
', '#suffix' => '
', - '#value' => 'Please enable user picture first to use Avatar crop.', + '#value' => t('Please enable user picture first to use Avatar crop.'), ); return $form2; } @@ -122,11 +120,28 @@ function avatarcrop_form_submit($form, & $filepath=file_directory_path(); $dest = $filepath . '/' .$upload_dir; $file = file_save_upload('file_upload', $validators, $dest); + global $user; + $owner=$user->uid; + $filetype; + $filetype = $file->filemime; + $extension=''; + switch ($filetype) { + case 'image/jpeg': + $extension='jpg'; + break; + case 'image/png': + $extension='png'; + break; + case 'image/gif': + $extension='gif'; + break; + } + $dest = variable_get('user_picture_path', 'pictures') .'/picture-'. $owner .'.'. $extension; if ($file != 0) { //$dest_path = 'files/upload_directory'; - $result = file_copy($file, $dest, FILE_EXISTS_RENAME); + $result = file_move($file, $dest, FILE_EXISTS_REPLACE); if ($result == 1) { $_SESSION['filepath']=$file->filepath; @@ -168,7 +183,7 @@ function cropUserPic() { $form['avatar_crop_title']=array( '#prefix' => '
', '#suffix' => '
', - '#value' => 'Make a selection on the below image to define the crop area.', + '#value' => t('Make a selection on the below image to define the crop area.'), ); $form['imageview']= array( '#value' => '', @@ -213,7 +228,7 @@ function cropUserPic_validate($form, &$f $h=$form_state['values']['h']; if(!$h){ - form_set_error('','Please crop the image to continue.'); + form_set_error('',t('Please crop the image to continue.')); } } @@ -236,6 +251,15 @@ function cropUserPic_submit($form, &$for $src = $_SESSION['filepath']; + $dot = strrpos($src, '.'); + if (!($dot === false)) + { + $newsrc = substr($src, 0, $dot) . rand() . substr($src, $dot); + if (rename($src, $newsrc)) + { + $src = $newsrc; + } + } $filetype=$_SESSION['filetype']; $dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); @@ -260,12 +284,11 @@ function cropUserPic_submit($form, &$for global $user; db_query("update {users} set picture='%s' where uid=%d",$src,$user->uid); ///cleaning the sessions - $_SESSION['filepath']=NULL; + $_SESSION['filepath']=NULL; $_SESSION['fid']=NULL; $_SESSION['filetype']=NULL; - drupal_goto('user/'.$user->uid); - + drupal_goto('user/'.$user->uid.'/edit'); } @@ -281,12 +304,13 @@ function cropUserPic_submit($form, &$for function avatarcrop_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'user_profile_form') { -/* $base=base_path(); + + $base=base_path(); + $description_upload = $form['picture']['picture_upload']['#description']; $form['picture']['picture_upload'] = array( - '#value' => ''. 'Upload picture' .'', - );*/ - $form['picture']=array(); - - + '#value' => ''. t('Upload picture') .'', + ); + $form['picture']['#description'] = $description_upload; } } +