فهرست منبع

Add Imagecache support to user picture.

Frederic G. MARAND 13 سال پیش
والد
کامیت
520614cc60
4فایلهای تغییر یافته به همراه105 افزوده شده و 0 حذف شده
  1. 2 0
      tweak.info
  2. 8 0
      tweak.module
  3. 33 0
      views/tweak.views.inc
  4. 62 0
      views/tweak_handler_field_user_picture_preset.inc

+ 2 - 0
tweak.info

@@ -5,3 +5,5 @@ name = Tweak
 description = "Tweak Drupal features"
 
 configure = admin/build/tweak
+
+dependencies[] = imagecache

+ 8 - 0
tweak.module

@@ -65,3 +65,11 @@ function tweak_form_system_modules_alter(&$form, &$form_state) {
 function tweak_init() {
   drupal_add_css(drupal_get_path('module', 'tweak') . '/theme/tweak.css');
 }
+
+function tweak_views_api() {
+  $ret = array(
+    'api' => 2,
+    'path' => drupal_get_path('module', 'tweak') . '/views',
+  );
+  return $ret;
+}

+ 33 - 0
views/tweak.views.inc

@@ -0,0 +1,33 @@
+<?php
+/**
+ * @file
+ * Provides support for Views integration.
+ */
+
+/**
+ * Implements hook_views_data_alter().
+ *
+ * Add Imagecache support to user picture
+ */
+function tweak_views_data_alter(&$data) {
+  $data['users']['picture']['field']['handler'] = 'tweak_handler_field_user_picture_preset';
+}
+
+/**
+ * Implements hook_views_handlers().
+ *
+ * Declare the "user picture with imagecache preset" field handler
+ */
+function tweak_views_handlers() {
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'tweak') .'/views',
+    ),
+    'handlers' => array(
+      'tweak_handler_field_user_picture_preset' => array(
+        'parent' => 'views_handler_field_user_picture',
+      ),
+    ),
+  );
+}
+

+ 62 - 0
views/tweak_handler_field_user_picture_preset.inc

@@ -0,0 +1,62 @@
+<?php
+/**
+ * Field handler to provide simple renderer that allows using a themed user link
+ */
+class tweak_handler_field_user_picture_preset extends views_handler_field_user_picture {
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['preset'] = array(
+      'default' => $this->definition['title'],
+      'translatable' => FALSE,
+    );
+    return $options;
+  }
+
+  /**
+   * Choose a preset
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $options = array('0' => t('None'));
+    foreach (imagecache_presets() as $pid => $preset) {
+      $options[$pid] = $preset['presetname'];
+    }
+    $form['preset'] = array(
+      '#type' => 'select',
+      '#title' => t('Imagecache preset'),
+      '#options' => $options,
+      '#default_value' => $this->options['preset'],
+    );
+
+    if (!empty($form_state['exposed'])) {
+      $identifier = $this->options['expose']['identifier'];
+      if (!isset($form_state['input'][$identifier])) {
+        $form_state['input'][$identifier] = $this->value;
+      }
+    }
+  }
+
+  function admin_summary() {
+    $pid = $this->options['preset'];
+    if ($pid) {
+      $preset = imagecache_preset($pid);
+      $ret = $preset['presetname'];
+    }
+    else {
+      $ret = t('Raw');
+    }
+    return $ret;
+  }
+
+  function render($values) {
+    $pid = $this->options['preset'];
+    if ($pid) {
+      $preset = imagecache_preset($pid);
+      return theme_imagecache($preset['presetname'], $values->{$this->field_alias});
+    }
+    else {
+      return parent::render($values);
+    }
+  }
+}