By theorichel on
I have a multisite with a shared user table. This works alright, but the user can only have pictures in either one of two domains, since the pics are uploaded to a directory that is relative to the domains file directory. Is there a way to bypass this (with Phpmyadmin for instance) to make sure that someone who registers at domain 2 uploads his picture to the picture directory of domain 1? So that they ar all in one dir?
Many thanks,
Theo Richel
Comments
found this while searching
It seems Drupal makes it nearly impossible to change the path for user photos, so I figured I could use symbolic links from the command line to have all the sites use a common pictures folder. Sounds like that would totally work right? Wrong! It also it seems Drupal does not let you use symlinks inside the files directory for security reasons. Looking through the PHP and researching on the forums, "realpath" check breaks the symbolic links in file directory. 2 days and countless cups of coffee later (yeah, I know... good times), time to go another direction.
Perhaps I should give some background on our Drupal setup first before I go on too much longer? Here's a quick outline of what we are doing
Ok so where were we...
Ultimately I decided not use the user pictures functionality that was provided by Drupal. I really wanted to use it, but Drupal stores the full path to the user photo in the shared users table, and that just wasn't going to work for what we wanted to do. After looking around, the decision was made to use the Content Profile Module. This would allow us the power of nodes for user content such as personal information, or user avatars with a cck imagefield. So now users can upload an image to one of the nodes assigned to them, but how do we get this image to show up as their avatar? Theme hooks!
Getting your hands a little dirty with php can be daunting, but once you see how easy it can be to use a few hook functions, you'll be hooked (excuse the lame pun). The theme hook theme_preprocess_user_picture is where the user picture gets retrieved so that is where we want to get the new image. I won't go into detail about that, but with some sql to join the content type profile and files tables, we can get our user avatar. Run that through imagecache and get a nice formatted image the way you want.
Here's how I did it
I have a multi-site setup that I got working with shared pictures (D5)
Overview
The sites are:
http://www.hollow-art.com
http://resources.hollow-art.com
The sites use one code base - Drupal 5.18
Sites use one database with the first site using "ha_" db prefix, the second "resources_" db_prefix. Shared tables (users, sessions, role, authmap sequences, profile_fields, profile_values & user_roles) have a "shared_" db prefix.
www.hollow-art.com has its file location set to "/files". resources.hollow-art.com has file location set to "/resources_files"
The Problem
When setting the default user pics location you can only reference it as a subdirectory of the sites files directory.
In this example we will assume Site 1 has the files dir set to "site1_files" and Site 2 as "site2_files".
When a user saves a picture it is saved in the users table as "//image_name.jpg". When drupal tries to display the user picture it adds the files path to the front of the stored string if the front part of the path is not already the sites files path. For eample:
User pic path as stored in Users table: "/site1_files/pictures/picture-1.jpg" (this file was uploaded from site 1)
Returned image path from site 1: "/site1_files/pictures/picture-1.jpg"
Returned image path from site 2: "/site2_files/site1_files/pictures/picture-1.jpg"
Solution
I tracked down the issue to the function "file_create_url" which creates valid file paths. That function is called from "theme_user_picture" which happily, can be easily overriden.
To fix create a new function in the template.php for your themes (on BOTH sites) called "phptemplate_user_picture".
Here is mine:
This will only work if you are using PUBLIC file downloads.
Thangobrind
does this also work for
does this also work for 6.x?
kind regards
A solution for Drupal 6.x
A solution for Drupal 6.x would be great.. This is a really big issue..
Drupal User Group Munich
Soultion for Drupal 6.x
I found a far more easier solution (hopefully acceptable to you as well).
in site 2
1. Choose administer -> site configuration -> file system
2. change the path to have the same value as mentioned in site1 administer -> site configuration -> file system
3. set pictures folder to the same value as in site 1
save and it works!
picture template
I just went into user-picture.tpl.php
It has one line where it prints $picture.
I changed it to create the img tag there, hardcode in the path to my primary domain in the multisite where the photo was uploaded and needs to be seen, and then print $account->picture.
So if domain1.com is my main domain and domain2 is a separate domain in the multisite, the line is:
Changing a template isn't hacking core, is it?
_
That depends-- which user-picture.tpl.php file did you change? The one located at /modules/user or in your theme's subdirectory? If the former, yes that's hacking core and will get overwritten whenever you do an update. To override it, as opposed to hack it, simply copy to your theme's directory and modify it there.
Global Avatar didn't work for
Global Avatar didn't work for me. I think, for now, drm's solution is the most elegant.
Tried to use this approach on
Tried to use this approach on D7, using the following on user-picture.tpl.php:
No success... Has anyone been able to do this on D7?
Global Avatar module is designed to solve this problem
A project Global Avatar has been set up to address this issue without having to make any modifications in the theme layer.
Well all mentioned code
Well all mentioned code doesn't work for me ? Could you write exactly what to change so i can share user pictures across all sites ?
I don't know how to achieve
I don't know how to achieve this effect. Global avatar is only for d6.