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

rasskull’s picture

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

  • One base Drupal install running a bunch of sites
  • Plesk hosted, each site in a different vhost httpdocs folder
  • Each site includes the main Drupal files and modules (thinks that they reside in the domain with the help of nifty php include files), multiple symlinks, individual site settings and files in each domain
  • Multiple databases - shared users among all sites in one db, each site has their own db for settings and data

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.

Thangobrind’s picture

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:

/***************************************************/
/* Override of theme_user_picture                  */
/***************************************************/
/* Allows us to use user pics in a multisite       */
/* enviroment with single shared sign on.          */
/***************************************************/
function theme_user_picture($account) {
  if (variable_get('user_pictures', 0)) {
    if ($account->picture && file_exists($account->picture)) {

/* Do not use "file_create_url" function */
/*$picture = file_create_url($account->picture); */
/* This is a dirty hack that assumes the picture path stored in the users table
/* is properly formatted. It always appears to be ok! */
      $picture = $GLOBALS['base_url'] .'/'.$account->picture;
    }
    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'))));
      $picture = theme('image', $picture, $alt, $alt, '', FALSE);
      if (!empty($account->uid) && user_access('access user profiles')) {
        $picture = l($picture, "user/$account->uid", array('title' => t('View user profile.')), NULL, NULL, FALSE, TRUE);
      }

      return "<div class=\"picture\">$picture</div>";
    }
  }
}

This will only work if you are using PUBLIC file downloads.

Thangobrind

Izz ad-Din’s picture

does this also work for 6.x?

kind regards

Breakerandi’s picture

A solution for Drupal 6.x would be great.. This is a really big issue..

Drupal User Group Munich

sukr_s’s picture

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!

drm’s picture

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:

  <img src="http://www.domain1.org/<?php print $account->picture; ?>">

Changing a template isn't hacking core, is it?

WorldFallz’s picture

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.

yngens’s picture

Global Avatar didn't work for me. I think, for now, drm's solution is the most elegant.

cesar.brod@gmail.com’s picture

Tried to use this approach on D7, using the following on user-picture.tpl.php:

<?php if ($user_picture): ?>
  <div class="user-picture">
    <img src="http://www.domain1.org/<?php print $user_picture; ?>">
  </div>
<?php endif; ?>

No success... Has anyone been able to do this on D7?

cpliakas’s picture

A project Global Avatar has been set up to address this issue without having to make any modifications in the theme layer.

kerios83’s picture

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 ?

kerios83’s picture

I don't know how to achieve this effect. Global avatar is only for d6.