Hi,

I don't know exactly how people made it work on Drupal 7.

I read : "Optionally, administrators can select one site's picture image path to store all of the avatars. This can be done by visiting Administer -> User Management -> Global avatar in the site where the avatars should be stored and selecting the checkbox. Enable the bundled Global Avatar Migrate module and click the "Migrate avatars" button in the admin page listed above to move all current avatars to the selected global avatar directory.", but this only for Drupal 6 !!!

Here is how I made it work with Drupal 7.

1) First create another stream wrapper, let's call it "global://"

/**
 * Implements hook_stream_wrappers().
 */
function MYMODULE_stream_wrappers() {
  return array(
    'global' => array(
      'name' => t('Default distribution files'),
      'class' => 'GlobalStreamWrapper',
      'description' => t('Global files served by the webserver.'),
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
    ),
  );
}
/**
 * Default files (global://) stream wrapper class.
 */
class GlobalStreamWrapper extends DrupalLocalStreamWrapper {
  /**
   * Implements abstract public function getDirectoryPath()
   */
  public function getDirectoryPath() {
    return conf_path() . '/global';
  }

  /**
   * Overrides getExternalUrl().
   *
   * Return the HTML URI of a public file.
   */
  function getExternalUrl() {
    $path = str_replace('\\', '/', $this->getTarget());
    return $GLOBALS['base_url'] . '/' . self::getDirectoryPath() . '/' . drupal_encode_path($path);
  }
}

2) Then, for each site create a symbolic link so that your new global path ends in the same place

Example:

cd /mnt/nfs/files/
mkdir global
cd /var/www/drupal/sites/first_site
ln -s /mnt/nfs/files/global global
cd /var/www/drupal/sites/second_site
ln -s /mnt/nfs/files/global global

etc...


3) Install and configure your global_avatar module : admin/config/people/global-avatar and put : global://global_avatar
Don't forget to share your "global_avatar" table https://drupal.org/node/22267 (Don't worry with the "not recommended", it works fine)

4) If you wish to use your image style, just add in your modules

function MYMODULE_menu() {
  $items = array();
  
  $directory_path = file_stream_wrapper_get_instance_by_scheme('global')->getDirectoryPath();
  $items[$directory_path . '/styles/%image_style'] = array(
    'title' => 'Generate image style',
    'page callback' => 'image_style_deliver',
    'page arguments' => array(count(explode('/', $directory_path)) + 1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  
  return $items;  
}

Cheers

Comments

Arono_’s picture

Hello,

i'm using an Hosting server and i don't have permissions to create symbolic link on the server, anyone have a idea for this ?

Thanks,