Hi Michelle,
I used the new 3.0 version of imagefield cck for the user profile image instead on enabling picture support in the user settings because I think it offers some benefits in user experience:
- This allowed me integrate it into the User Registration form right up front where it cannot be overlooked.
- If the user chooses not to upload an image, I am able to show a default one
- After uploading an image, the user is able to see the image immediately and can choose to replace/remove it.
- I turned on the progress bar on the cck imagefield, so it's nice if the user uploads a large image
(I also made an 'About' text field set to Required, so proflles are always created on registration)
In addition, in the advanced profile author pane template, I changed the $picture variable to show my imagecache preset of the cck field instead of the default user image. So the right image is now showing on the user's profile.
That' all I've gotten to so far, and I am hoping to see if I can get this to work in other areas. Do you think approach this will be problematic overall for other parts of APK? I have yet to take a look at the friends gallery and other views.
Also, I really want to thank you for all your hard work in producing your tutorials. I've been following them since you did your first tutorial on profiles!
Comments
Comment #1
arcane commentedI wrote a quick module that updates the user account image to match the cck image in the content profile whenever it is changed. The module then hides the user picture fields in the user account edit screen. The code for the module follows.
Some things to do before enabling the module.
1. Set a default image in the cck type (you will need to upload one)
2. Get the path on the server to where the default image is stored. Linux: sudo locate filename
3. Go to User settings and enable user pictures
4. Copy the path in step 2 to the field 'default picture'. In my case it was: imagefield_default_images/anonymous_avatar.png
This will ensure that the anonymous user 'default pictures' are set to the same setting
Comment #2
michelle@arcane: Sorry for the delay. I haven't been in APK "mode" recently. I just wanted to chime in and say this sounds really useful. I've thought about making the user picture a CCK field before but the core user picture is used so many places and I wanted them to match. I'm not sure when I'll be able to dig into this but I at least wanted to say thanks.
Michelle
Comment #3
arcane commentedSure I'm glad I can help and thanks for our reply. I know you aren't officially supporting apk while it is in alpha. If you have a To-Do list maybe others can help out.
Comment #4
michelleI don't have a specific to do list. Mostly getting integrations with other modules finished up. The 1.0 release is going to be basically a dupe of the 5.x version. I'll work on making it more "advanced" in 2.x.
Michelle
Comment #5
pribeh commentedHey Arcane, this is really cool. Is it possible to let users upload multiple images? Here are some possibilities you could play around with:
1. user uploads multiple images into x # imagefields
2. images are then displayed in a mini-gallery (wrap gallery inside jcarousel or cycle or scrollable)
3. users can then browse the various user uploaded images
you could then simply set 0 as the default image to display as a site-wide avatar/picture, or let users pick one from the gallery using some sort of js call-back (?). It would be uber cool to display the gallery right inside the author pane. I think vimeo does something like this. I'll try and get a screen grab later or do a mockup of what I'm talking about later tonight. I've had a lot of users request said feature.
Comment #6
michelleLetting users upload multiple images and then pick one for their avatar is something I have wanted to do on my site but it's more of a long term plan thing and not anything I was going to get to soon. If someone wants to take up the task, that would be awesome. I can see this code living in APK.
Thanks,
Michelle
Comment #7
arcane commentedThere is a module that provides this, http://drupal.org/project/avatar_selection, I have not checked it out yet.. The module allows the user to pick an avatar image from a list already loaded by an administrative user (not user uploaded however).
Comment #8
pribeh commentedYa, unfortunately that module doesn't allow for user uploading of images into a user specific avatar gallery, just the selection of an avatar from a general gallery (predetermined by the admin). Also, avatar selection doesn't use imagecache or any cycle/slider jquery (not a requirement for something like this but would be cool).
I think the aim would be to have a user specific gallery of avatars that allows users the ability to browse and choose their own default avatar that works within a user-profile panel (which means, apk should provide it).
Comment #9
arcane commentedImageCache Profile module takes the standard user picture and makes it use imagecache. My guess is that it would be possible to use this with Avatar Selection but I would have to look at the code. Maybe I'll get some ideas.
Comment #10
michelle@arcane: Yeah, what pribeh said. :)
Michelle
Comment #11
pribeh commentedYa, I was going to suggest looking at those modules to see if you can extract any useful snippets.
Comment #12
rajaito commentedThis is all very interesting. To implement this where would I put this code you have posted above?
Comment #13
dddave commented@ #12
You would have to build your own custom module.
Comment #14
mrfelton commented@arcane thanks for posting that sample module. +1 for the idea of per-user avatar galleries!
Comment #15
arcane commentedGlad it was useful!
Comment #16
jrust commentedGreat contribution! Here's my quick little hack to convert existing user pictures into the CCK field:
Comment #17
XerraX commentedsubscribing and http://drupal.org/project/reg_with_pic
Comment #18
michelleI'm going to postpone this for now. There's some great ideas here and I'll probably do something with CCK field for picture at some point but not likely in 1.x.
Michelle
Comment #19
Sunshiney commentedJrust --- where does a non-developer sort like me insert your hack? Do I have to change anything in your hack for it to run on my site?
Comment #20
jrust commentedThe easiest way to use that bit of code is to install the devel module and then it has a link that allows you to execute PHP code within your drupal install. Just paste that code into the text box and run it.
Comment #21
XerraX commentedyou really should do a database backup first!
Comment #22
boblangdon commented@arcane: Thank you!
I spent the past week looking for a simple, effective way to allow users to upload and crop their profile pictures.
Using Advanced_profile, content_profile, author_pane, imagefield, and imagefield_crop, I was able to add the crop/upload form to the user profile edit page, but getting the images to appear in author_pane, and getting rid of the upload form on the "user account" page were giving me fits.
All I had to do was add an info file, wrap up your module and change:
if ($node->type == 'profile') {
to
if ($node->type == 'uprofile') {
(and, of course, update the CCK imagefield name) to use this with APK.
You really should wrap this up and submit to the module repository. I think a LOT of people would find this very helpful.
Thanks again.
@jrust: Since my site is still in the development stage, I didn't get a chance to try your addition, but it looks like it, too, would be very helpful to those using this on a production site that's already populated with $picture variables.
(NOTE: _IF_ you change the name of the module to something shorter, like "custom_user_pic", DON'T FORGET TO CHANGE THE NAMES OF THE HOOKS/Functions!... DOH!)
Comment #23
arcane commentedGlad you found it useful. I never thought it was enough to create a full fledged module out of that bit of code.. I suppose I could spruce it up..
Comment #24
boblangdon commentedIt's not "elaborate," no, but judging by some of the posts I've read while researching this "problem," there seems to be a considerable need for something just like this. And, in my book, simple is always better. Maybe you could add a cute little admin interface where users could choose from several different fields to use as $picture... just window dressing, mind you, but if you're worried about it not being "substantial" enough... (and it would prevent the inevitable: "What do I do with this code?!" questions.
8^/
Comment #25
pribeh commentedbump what boblangdon is suggesting.
Comment #26
boblangdon commented@arcance: BTW: What's this you write about a "progress bar on the cck imagefield"??????
Where is this setting?
Comment #27
dddave commented@#26
http://drupal.org/project/filefield
It is described under the "Features" section.
Comment #28
boblangdon commented@27: Thanks dddave,
I was afraid of that. My host doesn't have the PECL extension installed.
:-(
Comment #29
foodbo commentedsubscribing
Comment #30
pribeh commentedHey, I've tried making a module combining arcane's original code with the addition of jrust's in #16 and boblangdon's in #22 but to no avail. Could anyone help me assemble such a thing? :) I'm trying to achieve this on an existing site.
Comment #31
ed_conolly commentedHi,
I can't seem to get the Arcane's module to work. I'm pretty new to module stuff, I'll outline what I've done and then if somebody could tell me where I'm not getting it that would be great.
So i took the code and made the file cckimage_profile.module file and a cckimage_profile.info file. Popped them in a folder and put them in the module directory.
I added a <?php to the start of the module and changed the field to be my field (field_profilepicture).
I've then done the steps stated by arcane and then installed the module to no avail. No error messages just nothing happening.
Any thoughts would be amazing.
Thanks
Comment #32
boblangdon commented@#31
Did the module show up in your modules list?
Here's what I did:
1) created an info file named "custom_user_pic.info:
; $Id$
name = custom user pic
description = Use CCK Imagefield picture for user picture
core = 6.x
package = Other
2) Using arcane's code (changing the 2 function names to reflect my naming convention), created a file called "custom_user_pic.module":
<?php
// $Id$
/**
* @file
*Allows CCK imagefield picture to replace core user picture
*/
function custom_user_pic_nodeapi(&$node, $op, $teaser=NULL, $page=NULL) {
global $ob_file;
switch ($op) {
case 'insert':
case 'update':
if ($node->type == 'uprofile') {
$cck_image = $node->field_cck_user_pic[0]['filepath'];
// Update the user's account picture
db_query('UPDATE {users} SET picture = "%s" WHERE uid = %d', $cck_image, $node->uid);
}
break;
}
}
function custom_user_pic_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_profile_form') {
unset($form['picture']);
}
}
(I changed "profile" type to "uprofile" only because I'm using Advance_Profile_Kit module. You'll note I also changed the $cck_image" variable value to reflect my naming convention. [ FROM "$cck_image = $node->field_profile_image" TO --> "$cck_image = $node->field_cck_user_pic" ])
3) Dropped them both (plus a README file linking to this page) into: "/sites/all/modules/custom/custom_user_pic/" and enabled it on my modules admin page under "Other."
4) created a content type called "cck_user_pic" with an imagefield called "cck_user_pic" using the widget type "image with cropping."
Hope that helps.
@#30: Can't speak to jrusts' code, I haven't tried it.
Comment #33
oeaton commentedsubscribing
Comment #34
xqbzzr commentedHi!
Ive had similar trouble getting the module to work. Me being neighter coder nor phpist at all giving some hints on what i did.
It seems to be important to have the function "function custom_user_pic_nodeapi(&$no....." and "function custom_user_pic_form_alter(&$form, &$f" named exactly after the name of your module.
And on my first shot I closed the document with the typical php-eding ?>. After deleting that one and clearing the cache several times, the module finally worked.
So beware your namings!
Good Luck!
Comment #35
michelleI added a link to this on the tips and tricks page: http://drupal.org/node/658026 . I won't be doing anything with it in APK itself.
Michelle
Comment #36
pribeh commentedGreat idea Michelle.
Comment #37
silkscreen commentedThis has been a very helpful thread, and I want to thank everyone.
:) Thank you
Comment #38
crea commentedSubscribing. Very nice idea.
Comment #39
crea commentedJust a note. I have created a module based on code from this issue. http://drupal.org/project/imagefield_avatar
Comment #40
michelleOh, very nice!
Michelle
Comment #41
Hardrocker commentedUnfortunately i am having a problem whereby everytime i enable the imagecache presets in imacecache profile it breaks my images. I am trying to use imagefield for the user pictures and installed imagecache avatar to hide the default user picture support, but I'm baffled as t to why my images aren't showing up. Any help would be appreciated. Thanks
Comment #42
tryitonce commentedsubscribing
Comment #43
radune commentedArcane,
Thanks a lot. It did help me a lot!
Thank you,
Radu