? global_avatar-639722-2.patch
Index: global_avatar.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/global_avatar/global_avatar.module,v
retrieving revision 1.1
diff -u -p -r1.1 global_avatar.module
--- global_avatar.module	19 Nov 2009 19:53:55 -0000	1.1
+++ global_avatar.module	23 Nov 2009 16:36:35 -0000
@@ -45,13 +45,8 @@ function global_avatar_form_user_admin_s
     '#maxlength' => 255,
     '#description' => t('Directory under the Drupal root directory where the global avatars are stored.'),
     '#weight' => -30,
+    '#after_build' => array('system_check_directory'),
   );
-
-  // If picture support is enabled, check whether the picture directory exists:
-  if (variable_get('user_pictures', 0)) {
-    $global_path = file_create_path(variable_get('global_avatar:path', file_directory_path() .'/pictures'));
-    file_check_directory($global_path, 1, 'global_avatar:path');
-  }
 }
 
 /**
@@ -86,3 +81,58 @@ function global_avatar_validate_picture(
     }
   }
 }
+
+/**
+ * Process variables for user-picture.tpl.php.  This function overrides
+ * template_preprocess_user_picture().
+ *
+ * @param $variables
+ *   An array contains the following arguments: $account
+ * @return
+ *   NULL
+ * @see user-picture.tpl.php
+ * @see template_preprocess_user_picture()
+ * @see global_avatar_create_url()
+ */
+function global_avatar_preprocess_user_picture(&$variables) {
+  $variables['picture'] = '';
+  if (variable_get('user_pictures', 0)) {
+    $account = $variables['account'];
+    if (!empty($account->picture) && file_exists($account->picture)) {
+      $picture = global_avatar_create_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'))));
+      $variables['picture'] = theme('image', $picture, $alt, $alt, '', FALSE);
+      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);
+      }
+    }
+  }
+}
+
+/**
+ * The core file_create_url() function is dependent on files being under
+ * file_directory_path().  Since our global avatars will be outside of this
+ * path for at least one of the multisite installations, this function will take
+ * the path as-is from the user table.
+ *
+ * @param $path
+ *   A string containing the path.
+ * @see file_create_url()
+ */
+function global_avatar_create_url($path) {
+  // We only include relative paths in urls.
+  $path = trim($path, '\\/');
+  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
+    case FILE_DOWNLOADS_PUBLIC:
+      return $GLOBALS['base_url'] .'/'. str_replace('\\', '/', $path);
+    case FILE_DOWNLOADS_PRIVATE:
+      return url('system/files/'. $path, array('absolute' => TRUE));
+  }
+}
