From 03e9cf6cc165ad782fa3a30b7bf08431267d09a2 Mon Sep 17 00:00:00 2001
From: Jesse Hofmann-Smith <jesse@opensourcery.com>
Date: Sat, 2 Jun 2012 03:19:05 -0700
Subject: [PATCH] add user image imagecache preset to admin page

---
 activity_log.admin.inc |   16 ++++++++++++++++
 activity_log.module    |   17 +++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/activity_log.admin.inc b/activity_log.admin.inc
index 0a385ee..2941627 100644
--- a/activity_log.admin.inc
+++ b/activity_log.admin.inc
@@ -35,6 +35,22 @@ function activity_log_admin($form_state) {
     '#options' => $options,
     '#default_value' => variable_get('activity_log_comments_bump', array('status' => 'status')),
   );
+  if (module_exists('imagecache_profiles')) {
+    $options = array();
+    foreach (imagecache_presets() as $preset) {
+      $options[$preset['presetid']] = $preset['presetname'];
+    }
+    // Use the first default imagecache preset, if the variable is not yet set.
+    $default = module_invoke_all('imagecache_default_presets');
+    $default_preset = reset(array_keys($default));
+    $form['activity_log_imagecache_preset'] = array(
+      '#type' => 'select',
+      '#title' => t('ImageCache preset for user pictures'),
+      '#description' => t('Select the imagecache preset to be used for Rules token replacement.'),
+      '#options' => $options,
+      '#default_value' => variable_get('activity_log_imagecache_preset', $default_preset),
+    );
+  }
   $form['activity_log_clear_cache'] = array(
     '#type' => 'submit',
     '#value' => t('Clear all message caches'),
diff --git a/activity_log.module b/activity_log.module
index d6a6ea4..5c3d0e1 100644
--- a/activity_log.module
+++ b/activity_log.module
@@ -500,8 +500,25 @@ function activity_log_token_values($type, $object = NULL, $options = array()) {
     if (module_exists('imagecache_profiles') && module_exists('facebook_status')) {
       $account->imagecache_preset = variable_get('facebook_status_imagecache_preset', variable_get('user_picture_imagecache_profiles_default', ''));
     }
+    elseif (module_exists('imagecache_profiles')) {
+      // Use the first default imagecache preset if the variable is not yet set.
+      $default_preset = _activity_log_default_imagecache_preset();
+      $account->imagecache_preset = variable_get('activity_log_imagecache_preset', $default_preset);
+    }
     $values['picture'] = theme('user_picture', $account);
     $values['username-themed'] = theme('username', $account);
   }
   return $values;
 }
+/**
+ * Helper function to return a default ImageCache preset.
+ */
+function _activity_log_default_imagecache_preset() {
+  static $default_preset;
+  if (empty($default_preset)) {
+    $default = module_invoke_all('imagecache_default_presets');
+    // reset() returns the first element of the array.
+    $default_preset = reset(array_keys($default));
+  }
+  return $default_preset;
+}
-- 
1.7.5.4

