Index: audio_attach.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/contrib/attach/audio_attach.info,v
retrieving revision 1.4
diff -u -p -r1.4 audio_attach.info
--- audio_attach.info	2 Oct 2008 07:12:34 -0000	1.4
+++ audio_attach.info	25 Nov 2008 18:44:35 -0000
@@ -2,5 +2,8 @@
 name = Audio Attach
 description = Allows audio files to be attached to any node type.
 package = "Audio"
-;WAITING ON UPDATE: core = 6.x
+;WAITING ON UPDATE: 
+core = 6.x
 dependencies[] = audio
+dependencies[] = content
+dependencies[] = nodereference
Index: audio_attach.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/contrib/attach/audio_attach.install,v
retrieving revision 1.4
diff -u -p -r1.4 audio_attach.install
--- audio_attach.install	25 May 2008 17:21:27 -0000	1.4
+++ audio_attach.install	25 Nov 2008 18:44:36 -0000
@@ -5,43 +5,32 @@
  * Implementation of hook_install().
  */
 function audio_attach_install() {
-  drupal_install_schema('audio_attach');
+  drupal_load('module', 'content');
+  content_notify('install', 'audio_attach');
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function audio_attach_uninstall() {
-  drupal_uninstall_schema('audio_attach');
+  drupal_load('module', 'content');
+  content_notify('uninstall', 'audio_attach');
 }
 
 /**
- * Implementation of hook_schema().
+ * Implementation of hook_enable().
  */
-function audio_attach_schema() {
-  $schema['audio_attach'] = array(
-    'description' => t('Attaches an audio node to another node.'),
-    'fields' => array(
-      'nid' => array(
-        'type' => 'int',
-        'size' => 'medium',
-        'not null' => TRUE,
-      ),
-      'aid' => array(
-        'type' => 'int',
-        'size' => 'medium',
-        'not null' => TRUE,
-      ),
-      'weight' => array(
-        'type' => 'int',
-        'size' => 'medium',
-        'not null' => TRUE,
-        'default' => 0,
-      ),
-    ),
-    'primary key' => array('nid', 'aid', 'weight'),
-  );
-  return $schema;
+function audio_attach_enable() {
+  drupal_load('module', 'content');
+  content_notify('enable', 'audio_attach');
+}
+
+/**
+ * Implementation of hook_disable().
+ */
+function audio_attach_disable() {
+  drupal_load('module', 'content');
+  content_notify('disable', 'audio_attach');
 }
 
 /**
@@ -61,3 +50,134 @@ function audio_attach_update_1() {
   db_add_primary_key($ret, 'audio_attach', array('nid', 'aid', 'weight'));
   return $ret;
 }
+
+/**
+ * Create a CCK nodereference field and migrate the data to it.
+ */
+function audio_attach_update_6000() {
+  // Make sure they've enabled CCK
+  if (!drupal_load('module', 'content') || !drupal_load('module', 'nodereference') || !function_exists('content_check_update')) {
+    $ret['#abort'] = array('success' => FALSE, 'query' => t('Audio Attach now requires CCK be installed. Some updates are still pending.<br/>Please re-run the update script.'));
+  }
+  if ($abort = content_check_update('fieldgroup')) {
+    return $abort;
+  }
+
+  // Need to load the CCK include file where content_field_instance_create()
+  // is defined.
+  module_load_include('inc', 'content', 'includes/content.crud');
+
+  // var_export(content_fields('field_audio_attach', 'story'));
+  $field = array (
+    'field_name' => 'field_audio_attach',
+    'display_settings' =>
+    array (
+      'weight' => '31',
+      'parent' => '',
+      'label' =>
+      array (
+        'format' => 'above',
+      ),
+      'teaser' =>
+      array (
+        'format' => 'audio_attach',
+        'exclude' => 0,
+      ),
+      'full' =>
+      array (
+        'format' => 'audio_attach',
+        'exclude' => 0,
+      ),
+      4 =>
+      array (
+        'format' => 'default',
+        'exclude' => 0,
+      ),
+      2 =>
+      array (
+        'format' => 'default',
+        'exclude' => 0,
+      ),
+      3 =>
+      array (
+        'format' => 'default',
+        'exclude' => 0,
+      ),
+      'token' =>
+      array (
+        'format' => 'default',
+        'exclude' => 0,
+      ),
+    ),
+    'widget_active' => '1',
+    'type' => 'nodereference',
+    'required' => '0',
+    'multiple' => '1',
+    'db_storage' => '0',
+    'module' => 'nodereference',
+    'active' => '1',
+    'locked' => '0',
+    'columns' =>
+    array (
+      'nid' =>
+      array (
+        'type' => 'int',
+        'unsigned' => true,
+        'not null' => false,
+      ),
+    ),
+    'referenceable_types' =>
+    array (
+      'audio' => 'audio',
+    ),
+    'advanced_view' => '--',
+    'advanced_view_args' => '',
+    'widget' =>
+    array (
+      'autocomplete_match' => 'contains',
+      'default_value' =>
+      array (
+        0 =>
+        array (
+          'nid' => NULL,
+          '_error_element' => 'default_value_widget][field_audio_attach][0][nid][nid',
+        ),
+      ),
+      'default_value_php' => NULL,
+      'label' => 'Attached audio files',
+      'weight' => '31',
+      'description' => '',
+      'type' => 'nodereference_autocomplete',
+      'module' => 'nodereference',
+    ),
+  );
+
+  // Now create the fields for each node type that audio_attach is enabled on.
+  foreach (node_get_types() as $type) {
+    if (variable_get('audio_attach_'. $type, 0)) {
+      $field['type_name'] = $type->type;
+      content_field_instance_create($field);
+    }
+  }
+
+  // Now the tricky part is to migrate the data...
+  // GREAT BIG ASSUMPTION: We created the field to accept unlimited values so
+  // it should have $field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD for
+  // all instances of the field. If not this code will probably not work right.
+  $db_info = content_database_info($field);
+  $table = $db_info['table'];
+  $column = $db_info['columns']['nid']['column'];
+
+  $ret[] = update_sql("INSERT INTO {$table} (nid, vid, delta, $column) SELECT n.nid, n.vid, a.weight, a.aid FROM {audio_attach} a INNER JOIN {node} n ON a.nid = n.nid");
+
+
+  // Remove the old variables.
+#  foreach (node_get_types() as $type) {
+#    variable_del('audio_attach_'. $type);
+#  }
+
+  // And drop the old table.
+#  db_drop_table($ret, 'audio_attach');
+
+  return $ret;
+}
Index: audio_attach.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/contrib/attach/audio_attach.module,v
retrieving revision 1.9
diff -u -p -r1.9 audio_attach.module
--- audio_attach.module	25 May 2008 17:21:27 -0000	1.9
+++ audio_attach.module	25 Nov 2008 18:44:37 -0000
@@ -18,30 +18,43 @@ function audio_attach_help($section, $ar
   }
 }
 
+///**
+// * Implementation of hook_menu
+// */
+//function audio_attach_menu() {
+//  $items = array();
+//
+//  // For example: audio_attach/remove/314/1
+//  $items['audio_attach/%op/%node/%index'] = array(
+//    'page callback' => '_audio_attach_action',
+//    'page arguments' => array(1, 2, 3),
+//    'access callback' => 'node_access',
+//    'access arguments' => array('update', 2),
+//    'type' => MENU_CALLBACK,
+//  );
+//
+//  return $items;
+//}
+
 /**
- * Implementation of hook_menu
+ * Implementation of hook_perm
  */
-function audio_attach_menu() {
-  $items = array();
-
-  // For example: audio_attach/remove/314/1
-  $items['audio_attach/%op/%node/%index'] = array(
-    'page callback' => '_audio_attach_action',
-    'page arguments' => array(1, 2, 3),
-    'access callback' => 'node_access',
-    'access arguments' => array('update', 2),
-    'type' => MENU_CALLBACK,
+function audio_attach_perm() {
+  return array(
+    'attach any existing audio file'
   );
-
-  return $items;
 }
 
 /**
- * Implementation of hook_perm
+ * Implementation of hook_field_formatter_info().
  */
-function audio_attach_perm() {
+function audio_attach_field_formatter_info() {
   return array(
-    'attach any existing audio file'
+    'audio_attach' => array(
+      'label' => t('Attached audio'),
+      'field types' => array('nodereference'),
+      'multiple values' => CONTENT_HANDLE_MODULE,
+    ),
   );
 }
 
@@ -50,35 +63,64 @@ function audio_attach_perm() {
  */
 function audio_attach_theme() {
   return array(
-    'audio_attach_list' => array(
-      'arguments' => array('nids', 'teaser' => FALSE),
+    'audio_attach_formatter_audio_attach' => array(
+      'arguments' => array('element' => NULL, 'teaser' => FALSE),
     ),
+//    'audio_attach_list' => array(
+//      'arguments' => array('nids', 'teaser' => FALSE),
+//    ),
   );
 }
 
+
+/**
+ * Theme function for 'attached_audio' nodereference field formatter.
+ */
+function theme_audio_attach_formatter_audio_attach($element, $teaser = FALSE) {
+  $items = array();
+
+  foreach (element_children($element) as $item) {
+    if (!empty($element[$item]['#item']['nid'])) {
+      $audio = node_load($element[$item]['#item']['nid']);
+      if ($audio->nid) {
+        $audio = node_prepare($audio, $teaser);
+        $title = $audio->status ? l($audio->title, 'node/'. $audio->nid, array('html' => TRUE)) : check_plain($audio->title);
+        $items[] = '<div class="title">'. $title .'</div>'. theme('audio_teaser', $audio);
+      }
+    }
+  }
+
+  if (count($items)) {
+    drupal_add_css(drupal_get_path('module', 'audio_attach') .'/audio_attach.css');
+    return theme('item_list', $items, null, 'ol', array('class' => 'audio-attach-list'));
+  }
+
+  return '';
+}
+
 /**
  * Implementation of hook_form_alter()
  */
 function audio_attach_form_alter(&$form, &$form_state, $form_id) {
   switch ($form_id) {
-    // checkbox in the node's content type configuration page.
-    case 'node_type_form':
-      if (isset($form['identity']['type'])) {
-          $form['workflow']['audio_attach'] = array(
-            '#type' => 'radios',
-            '#title' => t('Attach audio files'),
-            '#default_value' => variable_get('audio_attach_'. $form['#node_type']->type, 0),
-            '#options' => array(t('Disabled'), t('Enabled')),
-            '#description' => t('Should this node allows users to attach audio files?')
-          );
-        }
-      break;
+//    // checkbox in the node's content type configuration page.
+//    case 'node_type_form':
+//      if (isset($form['identity']['type'])) {
+//          $form['workflow']['audio_attach'] = array(
+//            '#type' => 'radios',
+//            '#title' => t('Attach audio files'),
+//            '#default_value' => variable_get('audio_attach_'. $form['#node_type']->type, 0),
+//            '#options' => array(t('Disabled'), t('Enabled')),
+//            '#description' => t('Should this node allows users to attach audio files?')
+//          );
+//        }
+//      break;
 
     // FIXME: This is broken; I'm not sure what $form['type']['#value'] is
     // expected to be, but it certainly doesn't always exist.
     // if enabled adjust the form
     //case $form['type']['#value'] .'_node_form':
-    case 'FIXME_node_form':
+    case 'TYPE_node_form':
       if (variable_get('audio_attach_'. $form['type']['#value'], 0)) {
         $node = $form['#node'];
         $form['#attributes'] = array("enctype" => "multipart/form-data");
@@ -135,16 +177,18 @@ function audio_attach_form_alter(&$form,
  */
 function audio_attach_nodeapi(&$node, $op, $teaser, $page) {
   global $user;
-  // delete all references from other nodes if audio node is deleted 24/08/2006 sun
-  if ($node->type == 'audio' && $op == 'delete') {
-    db_query("DELETE FROM {audio_attach} WHERE aid = %d", $node->nid);
-    return;
-  }
+
+//  // delete all references from other nodes if audio node is deleted 24/08/2006 sun
+//  if ($node->type == 'audio' && $op == 'delete') {
+//    db_query("DELETE FROM {audio_attach} WHERE aid = %d", $node->nid);
+//    return;
+//  }
   if ($node->type == 'audio' || !variable_get("audio_attach_$node->type", 0)) {
     return;
   }
   switch ($op) {
     case 'prepare':
+      break;
       $audio->title_format = check_plain($_POST['audio_title']);
       $audio->status = check_plain($_POST['audio_publish']) ? 1 : 0;
       $audio->uid = $user->uid;
@@ -162,226 +206,226 @@ function audio_attach_nodeapi(&$node, $o
       }
       break;
 
-    case 'insert':
-    case 'update':
-      if ($node->audio_aid) {
-        audio_attach_add_child($node->nid, $node->audio_aid);
-      }
-      if ($node->audio_existing_aid) {
-        audio_attach_add_child($node->nid, $node->audio_existing_aid);
-      }
-      break;
-
-    case 'delete':
-      audio_attach_remove($node->nid);
-      break;
-
-    case 'load':
-      $audio_attach = audio_attach_get_children($node->nid);
-      return array('audio_attach' => $audio_attach);
-
-    case 'view':
-      if (is_array($node->audio_attach) && count($node->audio_attach) > 0) {
-        $node->content['attach_audio'] = array(
-          '#value' => theme('audio_attach_list', $node->audio_attach, $teaser),
-          '#weight' => 10,
-        );
-      }
-      break;
-  }
-}
-
-/**
- * Menu callback, perform an action on attachments.
- */
-function _audio_attach_action($op, $nid, $index) {
-
-  switch ($op) {
-    case 'remove':
-      // remove the element index b from the array. rebuild the array, and save.
-      $children = audio_attach_get_children($nid);
-      $items = array();
-      foreach ($children as $weight => $aid) {
-        if ($weight != $index) {
-          $items[] = $aid;
-        }
-      }
-      _audio_attach_save_order($nid, $items);
-      break;
-    case 'up':
-      // take the element and move it up if possible in the array.
-      $items = audio_attach_get_children($nid);
-      if (isset($items[$index - 1])) {
-        $temp = $items[$index];
-        $temp2 = $items[$index - 1];
-        $items[$index] = $temp2;
-        $items[$index - 1] = $temp;
-      }
-      _audio_attach_save_order($nid, $items);
-      break;
-    case 'down':
-      // take the element and move it down if possible in the array.
-      $items = audio_attach_get_children($nid);
-
-      if (isset($items[$index + 1])) {
-        $temp = $items[$index];
-        $temp2 = $items[$index + 1];
-        $items[$index] = $temp2;
-        $items[$index + 1] = $temp;
-      }
-      _audio_attach_save_order($nid, $items);
-      break;
-  }
-
-  // Clear the node cache to get the updated audio_attach list
-  $update_node = node_load($nid, NULL, TRUE);
- 
-  _audio_attach_ahah_update($nid);
-
-}
-
-/**
- * Input a parent node id, and return an array of children id's ordered by their weight.
- */
-function audio_attach_get_children($nid) {
-  $children = array();
-  $result = db_query("SELECT aid, weight FROM {audio_attach} WHERE nid = %d ORDER BY weight ASC", $nid);
-  while ($row = db_fetch_object($result)) {
-    $children[$row->weight] = $row->aid;
+//    case 'insert':
+//    case 'update':
+//      if ($node->audio_aid) {
+//        audio_attach_add_child($node->nid, $node->audio_aid);
+//      }
+//      if ($node->audio_existing_aid) {
+//        audio_attach_add_child($node->nid, $node->audio_existing_aid);
+//      }
+//      break;
+//
+//    case 'delete':
+//      audio_attach_remove($node->nid);
+//      break;
+//
+//    case 'load':
+//      $audio_attach = audio_attach_get_children($node->nid);
+//      return array('audio_attach' => $audio_attach);
+//
+//    case 'view':
+//      if (is_array($node->audio_attach) && count($node->audio_attach) > 0) {
+//        $node->content['attach_audio'] = array(
+//          '#value' => theme('audio_attach_list', $node->audio_attach, $teaser),
+//          '#weight' => 10,
+//        );
+//      }
+//      break;
   }
-  return $children;
 }
 
-/**
- * Add a new child to a parent node
- */
-function audio_attach_add_child($nid, $aid, $stack_bottom = TRUE) {
-  $weight = audio_attach_get_next_weight($nid);
-  $result = db_query("INSERT INTO {audio_attach} (nid, aid, weight) VALUES (%d, %d, %d)", $nid, $aid, $weight);
-}
-
-/**
- * Delete a child node from a given parent node.  If no parent node is
- * specified, it deletes the child from all parent nodes.  Returns true if
- * successful.
- */
-function audio_attach_remove_child($aid, $nid, $weight) {
-  $result = db_query("DELETE FROM {audio_attach} WHERE nid = %d AND aid = %d AND weight = %d", $nid, $aid, $weight);
-  return db_affected_rows($result);
-}
-
-/**
- * Delete a parent node. Returns true if successful.
- */
-function audio_attach_remove($nid) {
-  $result = db_query("DELETE FROM {audio_attach} WHERE nid = %d", $nid);
-  return db_affected_rows($result);
-}
-
-/**
- * Get next weight in a given list.
- */
-function audio_attach_get_next_weight($nid) {
-  $max = db_result(db_query("SELECT MAX(weight) FROM {audio_attach} WHERE nid = %d", $nid));
-  return (is_null($max)) ? 0 : ++$max;
-}
-
-/**
- * Save a new order
- * $nid = node we are attaching files to
- * $order = a list of audio nids
- * return true if successful.
- */
-function _audio_attach_save_order($nid, $items) {
-  // clear out old entries for this nid.
-  if (is_array($items)) {
-    $cleared = audio_attach_remove($nid);
-    foreach ($items as $aid) {
-      audio_attach_add_child($nid, $aid);
-    }
-    return TRUE;
-  }
-}
-
-/**
- * Theme used if multiple files are attached
- */
-function theme_audio_attach_list($nids, $teaser = FALSE) {
-  drupal_add_css(AUDIO_ATTACH_PATH .'/audio_attach.css');
-  foreach ($nids as $aid) {
-    $audio = node_load($aid);
-    $audio = node_prepare($audio, $teaser);
-    $title = $audio->status ? l($audio->title, 'node/'. $audio->nid, array('html' => TRUE)) : check_plain($audio->title);
-    $items[] = '<div class="title">'. $title .'</div>'. theme('audio_teaser', $audio);
-  }
-  return theme('item_list', $items, null, 'ol', array('class' => 'audio-attach-list'));
-}
-
-
-/**
- * Fetch an array of all candidate referenced nodes, for use in presenting the selection form to the user.
- */
-function audio_attach_get_audio_nodes() {
-  global $user;
-  $rows = array(0 => '<none>');
-  $sql = "SELECT n.nid, n.title FROM {node} n WHERE n.status=1 AND type='audio' ";
-  $sql .= !user_access("attach any existing audio file") ? "AND n.uid = $user->uid " : "";
-  $sql .= "ORDER BY n.sticky DESC, n.title ASC";
-  $result = db_query(db_rewrite_sql($sql));
-  while ($node = db_fetch_object($result)) {
-      $rows[$node->nid] = $node->title;
-  }
-  return $rows;
-}
-
-/**
- * Return a list of currently attached audio files for a node.  Used in edit form.
- * TODO: This is clunky. Needs to be leaner.
- */
-function _audio_attach_current_list($nid) {
-  drupal_add_css(AUDIO_ATTACH_PATH .'/audio_attach.css');
-  drupal_add_js(AUDIO_ATTACH_PATH .'/audio_attach.js');
-  $node = node_load($nid);
-  $items = array();
-  $i = 0;
-  if (is_array($node->audio_attach) && count($node->audio_attach) > 0) {
-    foreach ($node->audio_attach as $weight => $aid) {
-      $audio = node_load($aid);
-      $drag = theme('image', AUDIO_ATTACH_PATH .'/images/drag_me.gif');
-      $link = l($audio->title, 'node/'. $audio->nid, array('html' => TRUE));
-      $trashcan = l(theme('image', AUDIO_ATTACH_PATH .'/images/user-trash.png'),
-        "audio_attach/remove/$node->nid/$i", array(
-          'attributes' => array('class' => 'audio-attach-quick-link'),
-          'query' => drupal_get_destination(),
-          'absolute' => true,
-        )
-      );
-      $up = $i > 0 ? l(theme('image', AUDIO_ATTACH_PATH .'/images/go-up.png'),
-        "audio_attach/up/$node->nid/$i", array(
-          'attributes' => array('class' => 'audio-attach-quick-link'),
-          'query' => drupal_get_destination(),
-          'absolute' => true,
-        )
-      ) : '' ;
-      $down = $i < count($node->audio_attach) - 1 ? l(theme('image', AUDIO_ATTACH_PATH .'/images/go-down.png'),
-        "audio_attach/down/$node->nid/$i", array(
-          'attributes' => array('class' => 'audio-attach-quick-link'),
-          'query' => drupal_get_destination(),
-          'absolute' => true,
-        )
-      ) : '';
-      $items[] = array($i + 1, $link, $down, $up, $trashcan);
-      $i++;
-    }
-    $output = theme('table', array('#', 'Title', array('data' => 'Actions', 'colspan' => 3)), $items, array('id' => 'audio-attach-items-table'));
-  }
-  return $output;
-}
-
-/**
- * Ajax/Ahah callback to update the attached list table
- */
-function _audio_attach_ahah_update($nid) {
-  print _audio_attach_current_list($nid);
-  exit();
-}
+///**
+// * Menu callback, perform an action on attachments.
+// */
+//function _audio_attach_action($op, $nid, $index) {
+//
+//  switch ($op) {
+//    case 'remove':
+//      // remove the element index b from the array. rebuild the array, and save.
+//      $children = audio_attach_get_children($nid);
+//      $items = array();
+//      foreach ($children as $weight => $aid) {
+//        if ($weight != $index) {
+//          $items[] = $aid;
+//        }
+//      }
+//      _audio_attach_save_order($nid, $items);
+//      break;
+//    case 'up':
+//      // take the element and move it up if possible in the array.
+//      $items = audio_attach_get_children($nid);
+//      if (isset($items[$index - 1])) {
+//        $temp = $items[$index];
+//        $temp2 = $items[$index - 1];
+//        $items[$index] = $temp2;
+//        $items[$index - 1] = $temp;
+//      }
+//      _audio_attach_save_order($nid, $items);
+//      break;
+//    case 'down':
+//      // take the element and move it down if possible in the array.
+//      $items = audio_attach_get_children($nid);
+//
+//      if (isset($items[$index + 1])) {
+//        $temp = $items[$index];
+//        $temp2 = $items[$index + 1];
+//        $items[$index] = $temp2;
+//        $items[$index + 1] = $temp;
+//      }
+//      _audio_attach_save_order($nid, $items);
+//      break;
+//  }
+//
+//  // Clear the node cache to get the updated audio_attach list
+//  $update_node = node_load($nid, NULL, TRUE);
+//
+//  _audio_attach_ahah_update($nid);
+//
+//}
+//
+///**
+// * Input a parent node id, and return an array of children id's ordered by their weight.
+// */
+//function audio_attach_get_children($nid) {
+//  $children = array();
+//  $result = db_query("SELECT aid, weight FROM {audio_attach} WHERE nid = %d ORDER BY weight ASC", $nid);
+//  while ($row = db_fetch_object($result)) {
+//    $children[$row->weight] = $row->aid;
+//  }
+//  return $children;
+//}
+//
+///**
+// * Add a new child to a parent node
+// */
+//function audio_attach_add_child($nid, $aid, $stack_bottom = TRUE) {
+//  $weight = audio_attach_get_next_weight($nid);
+//  $result = db_query("INSERT INTO {audio_attach} (nid, aid, weight) VALUES (%d, %d, %d)", $nid, $aid, $weight);
+//}
+//
+///**
+// * Delete a child node from a given parent node.  If no parent node is
+// * specified, it deletes the child from all parent nodes.  Returns true if
+// * successful.
+// */
+//function audio_attach_remove_child($aid, $nid, $weight) {
+//  $result = db_query("DELETE FROM {audio_attach} WHERE nid = %d AND aid = %d AND weight = %d", $nid, $aid, $weight);
+//  return db_affected_rows($result);
+//}
+//
+///**
+// * Delete a parent node. Returns true if successful.
+// */
+//function audio_attach_remove($nid) {
+//  $result = db_query("DELETE FROM {audio_attach} WHERE nid = %d", $nid);
+//  return db_affected_rows($result);
+//}
+//
+///**
+// * Get next weight in a given list.
+// */
+//function audio_attach_get_next_weight($nid) {
+//  $max = db_result(db_query("SELECT MAX(weight) FROM {audio_attach} WHERE nid = %d", $nid));
+//  return (is_null($max)) ? 0 : ++$max;
+//}
+//
+///**
+// * Save a new order
+// * $nid = node we are attaching files to
+// * $order = a list of audio nids
+// * return true if successful.
+// */
+//function _audio_attach_save_order($nid, $items) {
+//  // clear out old entries for this nid.
+//  if (is_array($items)) {
+//    $cleared = audio_attach_remove($nid);
+//    foreach ($items as $aid) {
+//      audio_attach_add_child($nid, $aid);
+//    }
+//    return TRUE;
+//  }
+//}
+//
+///**
+// * Theme used if multiple files are attached
+// */
+//function theme_audio_attach_list($nids, $teaser = FALSE) {
+//  drupal_add_css(AUDIO_ATTACH_PATH .'/audio_attach.css');
+//  foreach ($nids as $aid) {
+//    $audio = node_load($aid);
+//    $audio = node_prepare($audio, $teaser);
+//    $title = $audio->status ? l($audio->title, 'node/'. $audio->nid, array('html' => TRUE)) : check_plain($audio->title);
+//    $items[] = '<div class="title">'. $title .'</div>'. theme('audio_teaser', $audio);
+//  }
+//  return theme('item_list', $items, null, 'ol', array('class' => 'audio-attach-list'));
+//}
+//
+//
+///**
+// * Fetch an array of all candidate referenced nodes, for use in presenting the selection form to the user.
+// */
+//function audio_attach_get_audio_nodes() {
+//  global $user;
+//  $rows = array(0 => '<none>');
+//  $sql = "SELECT n.nid, n.title FROM {node} n WHERE n.status=1 AND type='audio' ";
+//  $sql .= !user_access("attach any existing audio file") ? "AND n.uid = $user->uid " : "";
+//  $sql .= "ORDER BY n.sticky DESC, n.title ASC";
+//  $result = db_query(db_rewrite_sql($sql));
+//  while ($node = db_fetch_object($result)) {
+//      $rows[$node->nid] = $node->title;
+//  }
+//  return $rows;
+//}
+//
+///**
+// * Return a list of currently attached audio files for a node.  Used in edit form.
+// * TODO: This is clunky. Needs to be leaner.
+// */
+//function _audio_attach_current_list($nid) {
+//  drupal_add_css(AUDIO_ATTACH_PATH .'/audio_attach.css');
+//  drupal_add_js(AUDIO_ATTACH_PATH .'/audio_attach.js');
+//  $node = node_load($nid);
+//  $items = array();
+//  $i = 0;
+//  if (is_array($node->audio_attach) && count($node->audio_attach) > 0) {
+//    foreach ($node->audio_attach as $weight => $aid) {
+//      $audio = node_load($aid);
+//      $drag = theme('image', AUDIO_ATTACH_PATH .'/images/drag_me.gif');
+//      $link = l($audio->title, 'node/'. $audio->nid, array('html' => TRUE));
+//      $trashcan = l(theme('image', AUDIO_ATTACH_PATH .'/images/user-trash.png'),
+//        "audio_attach/remove/$node->nid/$i", array(
+//          'attributes' => array('class' => 'audio-attach-quick-link'),
+//          'query' => drupal_get_destination(),
+//          'absolute' => true,
+//        )
+//      );
+//      $up = $i > 0 ? l(theme('image', AUDIO_ATTACH_PATH .'/images/go-up.png'),
+//        "audio_attach/up/$node->nid/$i", array(
+//          'attributes' => array('class' => 'audio-attach-quick-link'),
+//          'query' => drupal_get_destination(),
+//          'absolute' => true,
+//        )
+//      ) : '' ;
+//      $down = $i < count($node->audio_attach) - 1 ? l(theme('image', AUDIO_ATTACH_PATH .'/images/go-down.png'),
+//        "audio_attach/down/$node->nid/$i", array(
+//          'attributes' => array('class' => 'audio-attach-quick-link'),
+//          'query' => drupal_get_destination(),
+//          'absolute' => true,
+//        )
+//      ) : '';
+//      $items[] = array($i + 1, $link, $down, $up, $trashcan);
+//      $i++;
+//    }
+//    $output = theme('table', array('#', 'Title', array('data' => 'Actions', 'colspan' => 3)), $items, array('id' => 'audio-attach-items-table'));
+//  }
+//  return $output;
+//}
+//
+///**
+// * Ajax/Ahah callback to update the attached list table
+// */
+//function _audio_attach_ahah_update($nid) {
+//  print _audio_attach_current_list($nid);
+//  exit();
+//}
