Index: views/filefield_handler_field_data.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filefield/views/filefield_handler_field_data.inc,v
retrieving revision 1.2
diff -u -p -r1.2 filefield_handler_field_data.inc
--- views/filefield_handler_field_data.inc	8 Jan 2010 22:38:40 -0000	1.2
+++ views/filefield_handler_field_data.inc	10 Mar 2010 21:32:47 -0000
@@ -17,12 +17,12 @@ class filefield_handler_field_data exten
 
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
+    $opts = _filefield_get_field_data();
 
     $form['data_key'] = array(
       '#title' => t('Data key'),
       '#type' => 'radios',
-      // TODO: Pull these values from the modules that extend FileField.
-      '#options' => drupal_map_assoc(array('description', 'title', 'alt')),
+      '#options' => drupal_map_assoc($opts),
       '#required' => TRUE,
       '#default_value' => $this->options['data_key'],
       '#description' => t('The data column may (or may not) contain any of the following data. Select the data that should be output for this field.'),
@@ -38,8 +38,34 @@ class filefield_handler_field_data exten
   function render($values) {
     $values = drupal_clone($values); // Prevent affecting the original.
     $data = unserialize($values->{$this->field_alias});
-    $values->{$this->field_alias} = $data[$this->options['data_key']];
+    // check if this has an array for a value (imagefield_extended uses an array, there may be others as well)
+    if (!is_array($data[$this->options['data_key']])) $values->{$this->field_alias} = $data[$this->options['data_key']];
+    // here we use the array and use formatting options if it is set
+    elseif (isset($data[$this->options['data_key']]['body']) && isset($data[$this->options['data_key']]['format'])) {
+      $values->{$this->field_alias} = ($data[$this->options['data_key']]['format'] === '') ? check_plain($data[$this->options['data_key']]['body']) : check_markup($data[$this->options['data_key']]['body'], $data[$this->options['data_key']]['format']);
+    }
     return parent::render($values);
   }
 
 }
+
+/**
+ * Utility function to pull necessary labels from the db
+ * @returns $options - array of labels
+ */
+function _filefield_get_field_data() {
+  $result = db_query("SELECT field_name FROM {content_node_field} WHERE type = 'filefield'");
+  $options = array();
+  while ($field = db_fetch_array($result)) {
+    $field = $field['field_name'];
+    $fdata = $field . '_data';
+    // we check for %s <> 'b:0;' since this is what an empty serialized string looks like (empty strings won't work)
+    $row = db_fetch_array(db_query("SELECT %s FROM %s WHERE %s <> 'b:0;' LIMIT 1", $fdata, 'content_' . $field, $fdata));
+    $data = unserialize($row[$fdata]);
+    foreach ($data as $key => $val) { // push all the keys into an array
+      $output = check_plain($key);
+      array_push($options, $output);
+    }
+  }
+  return $options; // our list of labels
+}
\ No newline at end of file
