Posted by AsVit on April 14, 2009 at 1:52pm
Hello!
Sorry for my english.
I have a question. D6, Content profile, cck + imagefield.
I have user profile created with the help of Content profile and CCK + imagefield, for photo gallery.
I need to change the user avatar from profile -to the picture from the content profile + cck imagefield gallery. (For forums, blogs, and comments) and the user can to choose which of the 1 photo from gallery for his avatar. if the user did not choose, then use the first loaded image in the photo album. How can i make this? Snx!
Comments
I want to know too
i am looking for a simlar solution that allows users to have a photo album....and be able to select any picture from thier photo album as theirprofile picture
Ditto
I want to pull the picture from my "Author Bio" CCK content type into the View that I'm using for my blogs page. Each blogger has a bio that contains a picture; when they put up a blog post, I want that picture to appear next to it. Surely this nut has been cracked by someone. (BTW, in my Blog Page View, I tried adding a Relationship to the Author Picture field, with no luck.)
Any thoughts are welcome.
Me too
I'm using content profile which is great, and I'd love to have the imagefield photo show up as the user picture.
Bump... I too am looking to
Bump...
I too am looking to use the image submitted via the CCK FILE / IMAGE field of my created content type (student profile) to override the default USER PHOTO (which isn't being used at all) that the forum would normally pull the avatar from. Can anyone help?
if someone can help i'm stuck
if someone can help i'm stuck too i want to place the content profile user picture in the comments
I been using these code to
I been using these code to replace Drupal user picture, with the photo loaded trough a imagefield in the content profile node, two things to note:
1- replace imagecache_preset with your imagecache preset name
2- replace field_profile_picture, with the name of the picture field at the content profile CCK.
I load this code from a custom module.
/**
* Implementation of user_picture_preprocess_HOOK()
*/
function your_module_name_profile_preprocess_user_picture(&$variables) {
$variables['picture'] = '';
if (variable_get('user_pictures', 0)) {
$account = $variables['account'];
if (!empty($account->picture) && file_exists($account->picture)) {
$picture = file_create_url($account->picture);
}
if(user_picture_replace($account->uid)){
$profile_image = field_file_load(user_picture_replace($account->uid));
$picture = $profile_image['filepath'];
}
else if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
if (isset($picture)) {
$alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
$variables['picture'] = theme('imagecache', 'imagecache_preset',$picture, $alt, $alt, $attributes);
if(!empty($account->uid) && user_access('access user profiles')) {
$attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
$variables['picture'] = l($variables['picture'], "user/$account->uid", $attributes);
}
}
}
}
/**
* Replace drupal system user picture with content profile loaded picture.
*/
function user_picture_replace($uid){
$sql = "SELECT node.nid AS nid,
node_data_field_profile_picture.field_profile_picture_fid AS fid,
node.type AS node_type,
node.vid AS node_vid
FROM node node
INNER JOIN users users ON node.uid = users.uid
LEFT JOIN content_type_profile node_data_field_profile_picture ON node.vid = node_data_field_profile_picture.vid
WHERE (node.type in ('%s')) AND (users.uid = %d)";
$result = db_query($sql, 'profile', $uid);
while ($picture = db_fetch_object($result)) {
$output = $picture->fid;
}
return $output;
}
A different approach
I implemented your code above and it worked - thanks. However, organic groups was calling preprocess_user_picture when it wasn't needed, so your user_picture_replace query became taxing on the site. Rather than mess with the mess that is the current state of OG for D6 i decided to take a different approach.
In the comment.tpl.php replace 'print $picture' with the following code (rename your_module and your_imagecache):
<?php$user_image = your_module_get_user_profile_image($comment->uid);
if ($user_image['image']['filepath'] != '') {
print '<div class="picture">';
print theme('imagecache', 'your_imagecache', $user_image['image']['filepath'], $user_image['alt'], $user_image['alt']);
print '</div>';
}
?>
In "your_module" insert the following code (replace "field_user_image" with the name of the field user image in your content profile):
function your_module_get_user_profile_image($uid) {$user_image_fid_result = db_query("SELECT content_type_profile.field_user_image_fid FROM {content_type_profile} INNER JOIN {node} ON content_type_profile.nid = node.nid WHERE node.uid = %d AND node.type = '%s'", $uid, 'profile');
$user_image_fid_object = db_fetch_object($user_image_fid_result);
$user_image['image'] = field_file_load($user_image_fid_object->field_user_image_fid);
if ($user_image['image']['filepath'] == '') { //there was no image so get the default image for the field
$user_image_default_result = db_query("SELECT content_node_field_instance.widget_settings FROM {content_node_field_instance} WHERE content_node_field_instance.field_name = '%s'", 'field_user_image');
$user_image_widget_object = db_fetch_object($user_image_default_result);
$user_image_widget_settings = unserialize($user_image_widget_object->widget_settings);
$user_image['image'] = $user_image_widget_settings['default_image'];
}
$user = user_load($uid);
$user_image['alt'] = $user->name;
return $user_image;
}
This solution will also work for nodes - just pass the $node->uid from your node template instead of $comment->uid.
Also you can disable "user picture in nodes" & "user picture in comments" in the admin of your theme.
Imaginariums
Thanks for posting this! It
Thanks for posting this! It worked beautifully - especially after several failed attempts to "get there." The Content Profile photos are now displaying on my nodes and comments.
wouldn't be easier to use the
wouldn't be easier to use the user picture and try to put the user picture of the node in the node profile? why to use a cck for user picture where we already have a user picture ? I think you should copy all cck's as user pictures
to put user picture in a profile node use contemplate and this simple code to put the user picture on the profile
<img src="/<?php print $node->picture; ?>" />HEDAC FTW
Dude, so FTW it's sick.
So easy. Thanks.
-------------------------------------
miche | scentsy
Apparently you two are not
Apparently you two are not familiar with the benefits of cck imagefield instead of d6's core user picture. Search about it or irc chat. There is a reason why the title of this post is "User picture from CCK imagefield for forums, blogs, and comments (Replace user picture in profile)"
Imaginariums
How can this be achieved in
How can this be achieved in D7?
Content profile CCK imagefield into comment.tpl.php
After searching all over and doing trial and error the whole evening to get a content profile image into my comments this worked for me:
In comment.tpl.php I used:
<?php$profile = content_profile_load('profile', $comment->uid);
print theme_imagecache('User-small', $profile->field_image[0]['filepath']);
?>
Hope that helps
Many thanks, mate. You have
Many thanks, mate. You have saved lot of hours for me! Cheers!
There's also my small modification with a link on user-profile page for the code above:
<?php
$profile = content_profile_load('profile', $comment->uid);
$ava = theme_imagecache('user_small', $profile->field_photo[0]['filepath']);
print l($ava, 'user/' . $comment->uid, array('attributes' => array('title' => $profile->title), 'html' => 'true'));
?>
In a healthy body - healthy mind