Index: flickrfield.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flickr/field/flickrfield.install,v
retrieving revision 1.1
diff -u -r1.1 flickrfield.install
--- flickrfield.install	1 Apr 2008 06:01:28 -0000	1.1
+++ flickrfield.install	11 Sep 2008 15:55:44 -0000
@@ -1,16 +1,10 @@
 <?php
 // $Id: flickrfield.install,v 1.1 2008/04/01 06:01:28 drewish Exp $
-
-// Borrowed shamelessly from cck/text.install
-
-// Updates happen in random order, whether or not the module is enabled,
-// so include critical code here just to be sure.
-include_once('./'. drupal_get_path('module', 'content') .'/content.module');
-
 /**
  * Implementation of hook_install().
  */
 function flickrfield_install() {
+  drupal_load('module', 'content');
   content_notify('install', 'flickrfield');
 }
 
@@ -18,6 +12,7 @@
  * Implementation of hook_uninstall().
  */
 function flickrfield_uninstall() {
+  drupal_load('module', 'content');
   content_notify('uninstall', 'flickrfield');
 }
 
@@ -27,6 +22,7 @@
  * Notify content module when this module is enabled.
  */
 function flickrfield_enable() {
+  drupal_load('module', 'content');
   content_notify('enable', 'flickrfield');
 }
 
@@ -36,5 +32,6 @@
  * Notify content module when this module is disabled.
  */
 function flickrfield_disable() {
+  drupal_load('module', 'content');
   content_notify('disable', 'flickrfield');
 }
Index: flickrfield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flickr/field/flickrfield.module,v
retrieving revision 1.3
diff -u -r1.3 flickrfield.module
--- flickrfield.module	24 Mar 2008 19:56:09 -0000	1.3
+++ flickrfield.module	11 Sep 2008 17:04:35 -0000
@@ -1,285 +1,232 @@
-<?php
-// $Id: flickrfield.module,v 1.3 2008/03/24 19:56:09 drewish Exp $
-
-/**
- * @file
- * Defines a Flickr field type.
- *
- * @todo - think about how to control access to photos, might be tricky because of CCK caching.
- */
-
-/**
- * Include css unconditionally.
- */
-function flickrfield_init() {
-  drupal_add_css(drupal_get_path('module', 'flickr') .'/flickr.css');
-}
-
-/**
- * Implementation of hook_help().
- */
-function flickrfield_help($section, $arg) {
-  switch ($section) {
-    case 'admin/help#flickrfield':
-      return t('Flickrfields display Flickr photos or photosets. Input the user id of the photo owner and the photo or photoset id. The id is visible in the url when you view the photo or photoset on Flickr.');
-  }
-}
-
-/**
- * Implementation of hook_field_info().
- */
-function flickrfield_field_info() {
-  return array(
-    'flickrfield' => array(
-      'label' => 'Flickr Photo',
-      'description' => t('Blargh! Flickr photo!'),
-    ),
-  );
-}
-
-/**
- * Implementation of hook_field_settings().
- */
-function flickrfield_field_settings($op, $field) {
-  switch ($op) {
-    case 'database columns':
-      $columns = array(
-        'id' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE),
-        'type' => array('type' => 'varchar', 'length' => 10, 'not null' => FALSE, 'sortable' => TRUE),
-        'nsid' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE),
-      );
-      return $columns;
-
-    case 'filters':
-      // This will provide a Views filter by photo or photoset id.
-      return array(
-        'default' => array(
-          'operator' => 'views_handler_operator_like',
-          'handler' => 'views_handler_filter_like',
-        ),
-      );
-      break;
-  }
-}
-
-/**
- * Implementation of hook_widget_info().
- */
-function flickrfield_widget_info() {
-  return array(
-    'flickrfield' => array(
-      'label' => 'Flickr Photo',
-      'field types' => array('flickrfield'),
-      'multiple values' => CONTENT_HANDLE_CORE,
-      'callbacks' => array(
-        'default value' => CONTENT_CALLBACK_DEFAULT,
-      ),
-    ),
-  );
-}
-
-function flickrfield_elements() {
-  return array(
-    'flickrfield' => array(
-      '#input' => TRUE,
-      //'#columns' => array('type', 'id', 'uid'),
-      //'#process' => array('flickrfield_process'),
-    ),
-  );
-}
-
-function flickrfield_widget(&$form, &$form_state, $field, $items, $delta = 0) {
-  $element = array(
-    '#type' => $field['widget']['type'],
-    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
-  );
-  return $element;
-}
-
-/*
-function flickrfield_process($element, $edit, $form_state, $form) {
-  $field_key = $element['#columns'][0];
-  $element[$field_key] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Item',
-    '#default_value' => isset($element['#value']) ? $element['#value'] : '',
-    '#element_validate' => array('flickrfield_validate'),
-
-    // The following values were set by the content module and need
-    // to be passed down to the nested element.
-    '#field_name' => $element['#field_name'],
-    '#delta' => $element['#delta'],
-    '#columns' => $element['#columns'],
-    '#title' => $element['#title'],
-    '#required' => $element['#required'],
-    '#description' => $element['#description'],
-  );
-  $element[$field_key]['type'] = array(
-    '#type' => 'select',
-    '#title' => t('Item Type'),
-    '#default_value' => 'nubba',
-    '#options' => array('photo_id' => t('Photo'), 'set_id' => t('Photoset')),
-  );
-  return $element;
-}
- */
-
-function theme_flickrfield($element) {
-  var_dump($element);
-  return theme('form_element', array(
-      '#title' => 'Item',
-      '#description' => 'Noooooo!',
-      '#type' => 'text',
-    ),
-    $element['#value']
-  );
-}
-
-/**
- * Implementation of hook_widget().
- */
-function flickrfield_widgeto($op, &$node, $field, &$items) {
-  switch ($op) {
-    case 'form':
-      $form = array();
-      $form['flickr']['#type'] = 'fieldset';
-      $form['flickr']['#title'] = t('Flickr Photos');
-      $form['flickr']['#description'] = t($field['widget']['description']);
-
-      $options = array();
-      $options['photo_id'] = t("Photo");
-      $options['set_id'] = t("Photoset");
-
-      $delta = 0;
-      $range = $field['multiple'] ? sizeof($items) + 2 : 0;
-      foreach (range($delta, $range) as $delta) {
-        $form['flickr']['field_'. $delta][$field['field_name']] = array('#tree' => TRUE);
-        if ($field['multiple']) {
-          $form['flickr']['field_'. $delta][$field['field_name']]['#type'] = 'fieldset';
-          $form['flickr']['field_'. $delta][$field['field_name']]['#title'] = t('Item #@no', array('@no' => intval($delta + 1)));
-          $form['flickr']['field_'. $delta][$field['field_name']]['#collapsible'] = 1;
-          $form['flickr']['field_'. $delta][$field['field_name']]['#collapsed'] = ($delta == 0 || !empty($items[$delta]['type'])) ? 0 : 1;
-        }
-        $form['flickr']['field_'. $delta][$field['field_name']][$delta]['type'] = array(
-           '#type' => 'select',
-           '#title' => t('Item Type'),
-           '#default_value' => $items[$delta]['type'],
-           '#options' => $options,
-           '#required' => $delta == 0 && $field['required'] ? TRUE : FALSE,
-        );
-        $form['flickr']['field_'. $delta][$field['field_name']][$delta]['id'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Id'),
-          '#default_value' => $items[$delta]['id'],
-          '#description' => t("The photo or photoset id."),
-          '#required' => $delta == 0 && $field['required'] ? TRUE : FALSE,
-        );
-        $form['flickr']['field_'. $delta][$field['field_name']][$delta]['nsid'] = array(
-          '#type' => 'textfield',
-          '#title' => t('User Id'),
-          '#default_value' => !empty($items[$delta]['nsid']) ? $items[$delta]['nsid'] : variable_get('flickr_default_userid', ''),
-          '#description' => t("The user id of the Flickr user who owns the photos. If this is left blank, the sites's default user will be used. Current default id is @id.", array('@id' => variable_get('flickr_default_userid', ''))),
-          '#required' => $delta == 0 && $field['required'] ? TRUE : FALSE,
-        );
-      }
-      return $form;
-
-    case 'process form values':
-      // Don't save empty fields except the first value
-      foreach ($items as $delta => $item) {
-        if ($item['id'] == '' && $delta > 0) {
-          unset($items[$delta]);
-        }
-      }
-      break;
-  }
-}
-
-/**
- * Implementation of hook_content_is_empty().
- */
-function flickrfield_content_is_empty($item, $field) {
-  return empty($item['id']);
-}
-
-/**
- * Implementation of hook_field_formatter_info().
- */
-function flickrfield_field_formatter_info() {
-  require_once(drupal_get_path('module', 'flickr') .'/flickr.inc');
-  foreach (flickr_photo_sizes() as $size => $info) {
-    $formatters[$size] = array(
-      'label' => $info['label'],
-      'field types' => array('flickrfield'),
-      );
-  }
-  return $formatters;
-}
-
-/**
- * Implementation of hook_field_formatter().
- *
- */
-function flickrfield_field_formatter($field, $item, $formatter, $node) {
-  require_once(drupal_get_path('module', 'flickr') .'/flickr.inc');
-  switch ($item['type']) {
-    case 'photo_id':
-      $photo_data = flickr_photo_get_info($item['id']);
-      $img = flickr_img($photo_data, $formatter);
-      $photo_url = flickr_photo_page_url($photo_data['owner'], $photo_data['id']);
-      return theme('flickrfield_photo', $img, $photo_url, $formatter, $photo_data, $node);
-    case 'set_id':
-      $photo_data = flickr_photoset_get_info($item['id']);
-      $img = flickr_img($photo_data, $formatter);
-      $photo_url = flickr_photo_page_url($photo_data['owner'], $photo_data['id']);
-      return theme('flickrfield_photoset', $img, $photo_url, $formatter, $photo_data, $node);
-  }
-}
-
-/**
- * Implementation of hook_theme().
- */
-function flickrfield_theme() {
-  return array(
-    'flickrfield_photo' => array(
-      'arguments' => array('img', 'photo_url', 'formatter', 'photo_data', 'node'),
-    ),
-    'flickrfield_photoset' => array(
-      'arguments' => array('img', 'photo_url', 'formatter', 'photo_data', 'node'),
-    ),
-    'flickrfield' => array(
-      'arguments' => array('element'),
-    ),
-  );
-}
-
-/**
- * Flickrfield photo themes.
- *
- * If we are not on the node, make the photo link back to the node,
- * otherwise just display the image. To comply with Flickr terms of service
- * add a link back to the Flickr page.
- */
-function theme_flickrfield_photo($img, $photo_url, $formatter, $photo_data, $node) {
-  $title = is_array($photo_data['title']) ? $photo_data['title']['_content'] : $photo_data['title'];
-  if (arg(0) == 'node' && arg(1) == $node->nid) {
-    $output = '<div class="flickr-photo-img">'. $img .'</div>';
-  }
-  else {
-    $output = '<div class="flickr-photo-img">'. l($img, 'node/'. $node->nid, array('title' => $title), NULL, NULL, TRUE, TRUE) . '</div>';
-  }
-  $output .= '<div class="flickr-citation"><cite>'. l(t('Source: Flickr'), $photo_url) .'</cite></div>';
-  return $output;
-}
-
-function theme_flickrfield_photoset($img, $photo_url, $formatter, $photo_data, $node) {
-  $title = is_array($photo_data['title']) ? $photo_data['title']['_content'] : $photo_data['title'];
-  if (arg(0) == 'node' && arg(1) == $node->nid) {
-    $output = '<div class="flickr-photoset-img">'. $img .'</div>';
-  }
-  else {
-    $output = '<div class="flickr-photoset-img">'. l($img, 'node/'. $node->nid, array('title' => $title), NULL, NULL, TRUE, TRUE) . '</div>';
-  }
-  $output .= '<div class="flickr-citation"><cite>'. l(t('Source: Flickr'), $photo_url) .'</cite></div>';
-  return $output;
-}
+<?php
+// $Id: flickrfield.module,v 1.3 2008/03/24 19:56:09 drewish Exp $
+
+/**
+ * @file
+ * Defines a Flickr field type.
+ *
+ * @todo - think about how to control access to photos, might be tricky because of CCK caching.
+ */
+
+/**
+ * Include css unconditionally.
+ */
+function flickrfield_init() {
+  drupal_add_css(drupal_get_path('module', 'flickr') .'/flickr.css');
+}
+
+/**
+ * Implementation of hook_help().
+ */
+function flickrfield_help($section, $arg) {
+  switch ($section) {
+    case 'admin/help#flickrfield':
+      return t('Flickrfields display Flickr photos or photosets. Input the user id of the photo owner and the photo or photoset id. The id is visible in the url when you view the photo or photoset on Flickr.');
+  }
+}
+
+/**
+ * Implementation of hook_field_info().
+ */
+function flickrfield_field_info() {
+  return array(
+    'flickrfield' => array(
+      'label' => 'Flickr Photo',
+      'description' => t('Store Flickr Photo or Photoset ids and display the photos in nodes and views.'),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_field_settings().
+ */
+function flickrfield_field_settings($op, $field) {
+  switch ($op) {
+    case 'database columns':
+      $columns = array(
+        'id' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE),
+        'type' => array('type' => 'varchar', 'length' => 10, 'not null' => FALSE, 'sortable' => TRUE),
+        'nsid' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'sortable' => TRUE),
+      );
+      return $columns;
+  }
+}
+
+/**
+ * Implementation of hook_widget_info().
+ */
+function flickrfield_widget_info() {
+  return array(
+    'flickrfield' => array(
+      'label' => 'Flickr Photo',
+      'field types' => array('flickrfield'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+      'callbacks' => array(
+        'default value' => CONTENT_CALLBACK_DEFAULT,
+      ),
+    ),
+  );
+}
+
+function flickrfield_elements() {
+  return array(
+    'flickrfield' => array(
+      '#input' => TRUE,
+      '#columns' => array('type', 'id', 'uid'),
+      '#process' => array('flickrfield_process'),
+    ),
+  );
+}
+
+function flickrfield_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+  $element = array(
+    '#type' => $field['widget']['type'],
+    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
+  );
+  return $element;
+}
+
+function flickrfield_process($element, $edit, $form_state, $form) {
+  $options = array();
+  $options['photo_id'] = t("Photo");
+  $options['set_id'] = t("Photoset");
+  $element['type'] = array(
+    '#type' => 'select',
+    '#title' => t('Item Type'),
+    '#default_value' => !empty($element['#value']['type']) ? $element['#value']['type'] : '',
+    '#options' => $options,
+  );
+  $element['id'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Id'),
+    '#default_value' => !empty($element['#value']['id']) ? $element['#value']['id'] : '',
+  );
+  $element['nsid'] = array(
+    '#type' => 'textfield',
+    '#title' => t('User Id'),
+    '#default_value' => !empty($element['#value']['nsid']) ? $element['#value']['nsid'] : variable_get('flickr_default_userid', ''),
+    '#required' => $element['#required'],
+    '#description' => t("The user id of the Flickr user who owns the photos. If this is left blank, the sites's default user will be used. Current default id is @id.", array('@id' => variable_get('flickr_default_userid', ''))),
+  );
+  return $element;
+}
+
+/**
+ * Implementation of hook_content_is_empty().
+ */
+function flickrfield_content_is_empty($item, $field) {
+  return empty($item['id']);
+}
+
+/**
+ * Implementation of hook_field_formatter_info().
+ */
+function flickrfield_field_formatter_info() {
+  require_once(drupal_get_path('module', 'flickr') .'/flickr.inc');
+  foreach (flickr_photo_sizes() as $size => $info) {
+    $formatters[$size] = array(
+      'label' => $info['label'],
+      'field types' => array('flickrfield'),
+      );
+  }
+  return $formatters;
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function flickrfield_theme() {
+  require_once(drupal_get_path('module', 'flickr') .'/flickr.inc');
+  $themes = array();
+  foreach (flickr_photo_sizes() as $size => $info) {
+    $themes['flickrfield_formatter_'. $size] = array(
+      'arguments' => array('element'),
+      'function' => 'theme_flickrfield_field_formatter',
+      );
+  }
+  return $themes + array(
+    'flickrfield_photo' => array(
+      'arguments' => array('img', 'photo_url', 'formatter', 'photo_data', 'node'),
+    ),
+    'flickrfield_photoset' => array(
+      'arguments' => array('img', 'photo_url', 'formatter', 'photo_data', 'node'),
+    ),
+    'flickrfield' => array(
+      'arguments' => array('element'),
+    ),
+  );
+}
+
+/**
+ * Basic flickrfield formatter.
+ */
+function theme_flickrfield_field_formatter($element) {
+  require_once(drupal_get_path('module', 'flickr') .'/flickr.inc');
+  $item = $element['#item'];
+  $node = $element['#node'];
+  $formatter = $element['#formatter'];
+  $field_name = $element['#field_name'];
+  switch ($item['type']) {
+    case 'photo_id':
+      $photo_data = flickr_photo_get_info($item['id']);
+      $img = flickr_img($photo_data, $formatter);
+      $photo_url = flickr_photo_page_url($photo_data['owner'], $photo_data['id']);
+      return theme('flickrfield_photo', $img, $photo_url, $formatter, $photo_data, $node);
+    case 'set_id':
+      $photo_data = flickr_photoset_get_info($item['id']);
+      $img = flickr_img($photo_data, $formatter);
+      $photo_url = flickr_photo_page_url($photo_data['owner'], $photo_data['id']);
+      return theme('flickrfield_photoset', $img, $photo_url, $formatter, $photo_data, $node);
+  }
+}
+
+/**
+ * Flickrfield photo themes.
+ *
+ * If we are not on the node, make the photo link back to the node,
+ * otherwise just display the image. To comply with Flickr terms of service
+ * add a link back to the Flickr page.
+ */
+function theme_flickrfield_photo($img, $photo_url, $formatter, $photo_data, $node) {
+  $title = is_array($photo_data['title']) ? $photo_data['title']['_content'] : $photo_data['title'];
+  if (arg(0) == 'node' && arg(1) == $node->nid) {
+    $output = '<div class="flickr-photo-img">'. $img .'</div>';
+  }
+  else {
+    $output = '<div class="flickr-photo-img">'. l($img, 'node/'. $node->nid, array('title' => $title), NULL, NULL, TRUE, TRUE) . '</div>';
+  }
+  $output .= '<div class="flickr-citation"><cite>'. l(t('Source: Flickr'), $photo_url) .'</cite></div>';
+  return $output;
+}
+
+function theme_flickrfield_photoset($img, $photo_url, $formatter, $photo_data, $node) {
+  $title = is_array($photo_data['title']) ? $photo_data['title']['_content'] : $photo_data['title'];
+  if (arg(0) == 'node' && arg(1) == $node->nid) {
+    $output = '<div class="flickr-photoset-img">'. $img .'</div>';
+  }
+  else {
+    $output = '<div class="flickr-photoset-img">'. l($img, 'node/'. $node->nid, array('title' => $title), NULL, NULL, TRUE, TRUE) . '</div>';
+  }
+  $output .= '<div class="flickr-citation"><cite>'. l(t('Source: Flickr'), $photo_url) .'</cite></div>';
+  return $output;
+}
+
+/**
+ * Theme for the form element.
+ * 
+ * The form is already rendered by the child elements by the time it comes back here,
+ * just group each delta grouping into its own fieldset.
+ */
+function theme_flickrfield($element) {
+  $fields = content_fields();
+  $field = $fields[$element['#field_name']];
+  $fieldset = array(
+    '#title' => $field['widget']['label'] .' '. ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''),
+    '#value' => $element['#children'],
+    '#collapsible' => FALSE,
+    '#collapsed' => FALSE,
+    '#description' => $element['#description'],
+    '#attributes' => array(),
+  );
+  return theme('fieldset', $fieldset);
+}

