Index: audio.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.module,v
retrieving revision 1.29
diff -u -r1.29 audio.module
--- audio.module	4 Dec 2005 02:44:23 -0000	1.29
+++ audio.module	14 Dec 2005 22:42:00 -0000
@@ -41,8 +41,8 @@
 /**
  * Implementation of hook_node_name
  */
-function audio_node_name() {
-  return t('audio');
+function audio_node_info() {
+  return array('audio' => array('name' => t('audio'), 'base' => 'audio'));
 }
 
 /**
@@ -77,11 +77,41 @@
  */
 function audio_settings() {
   _audio_check_settings();
-  $output.= form_hidden('audio_updated', time());
-  $paths .= form_textfield(t('Path to uploaded audio files'), 'audio_default_path', variable_get('audio_default_path', 'audio'), 30, 255, t('Subdirectory in the directory "%dir" where audio files will be stored.', array('%dir' => '<em>'. variable_get('file_directory_path', 'files') .'/</em>')));
-  $paths .= form_textfield(t('Path to the \'getID3\' folder'), 'audio_getid3_path', variable_get('audio_getid3_path', drupal_get_path('module', 'audio').'/getid3/'), 30, 255, t('The path to the \'getid3\' library folder. (include trailing slash.)'));
-  $output.= form_group(t('File paths'), $paths);
-  return $output;
+
+  $form['audio_updated'] = array(
+    '#type' => 'hidden',
+    '#value' => time()
+  );
+
+  $form[$paths] = array(
+    '#type' => 'fieldset',
+    '#title' => t('File paths')
+  );
+  $form[$paths]['audio_default_path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to uploaded audio files'),
+    '#default_value' => variable_get('audio_default_path', 'audio'),
+    '#size' => 30,
+    '#maxlength' => 255,
+    '#description' => t('Subdirectory in the directory "%dir" where audio files will be stored.', array('%dir' => '<em>'. variable_get('file_directory_path', 'files') .'/</em>'))
+  );
+  $form[$paths]['audio_getid3_path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to the \'getID3\' folder'),
+    '#default_value' => variable_get('audio_getid3_path', drupal_get_path('module', 'audio').'/getid3/'),
+    '#size' => 30,
+    '#maxlength' => 255,
+    '#description' => t('The path to the \'getid3\' library folder. (include trailing slash.)')
+  );
+
+/* TODO: CHECK SETTINGS
+  // check for id3 library
+  $id3_path = variable_get('audio_getid3_path', drupal_get_path('module', 'audio').'/getid3/');
+  if (!file_exists($id3_path.'getid3.php')) {
+    form_set_error('audio_getid3_path', t('The audio module requires that getId3 be installed.'));
+  }
+*/
+  return $form;
 }
 
 /**
@@ -91,45 +121,69 @@
   $items = array();
 
   if ($may_cache) {
-    $items[] = array('path' => 'node/add/audio', 
-                     'title' => t('audio'),
-                     'access' => user_access('create audio'), 
-                     'type' => MENU_NORMAL_ITEM);
-                     
-    $items[] = array('path' => 'audio', 'title' => t('audio files'),
-                     'access' => user_access('access content'),
-                     'type' => MENU_SUGGESTED_ITEM,
-                     'callback' => 'audio_page');
-             
-                     
-    $items[] = array('path' => 'audio/download', 'title' => t('audio'),
-                     'access' => user_access('access content'),
-                     'type' => MENU_CALLBACK,
-                     'callback' => 'audio_fetch');
-                     
-    $items[] = array('path' => 'audio/play', 'title' => t('audio'),
-                     'access' => user_access('access content'),
-                     'type' => MENU_CALLBACK,
-                     'callback' => 'audio_play');
-                     
-                                
-    $items[] = array('path' => 'admin/audio/add', 'title' => t('add audio'),
-                     'access' => user_access('administer audio'),
-                     'type' => MENU_LOCAL_TASK);
-                        
+    $items[] = array(
+      'path' => 'node/add/audio',
+      'title' => t('audio'),
+      'access' => user_access('create audio'),
+      'type' => MENU_NORMAL_ITEM);
+
+    $items[] = array(
+      'path' => 'audio', 'title' => t('audio files'),
+      'access' => user_access('access content'),
+      'type' => MENU_SUGGESTED_ITEM,
+      'callback' => 'audio_page');
+
+    $items[] = array(
+      'path' => 'audio/download', 'title' => t('audio'),
+      'access' => user_access('access content'),
+      'type' => MENU_CALLBACK,
+      'callback' => 'audio_fetch');
+
+    $items[] = array(
+      'path' => 'audio/play', 'title' => t('audio'),
+      'access' => user_access('access content'),
+      'type' => MENU_CALLBACK,
+      'callback' => 'audio_play');
+
+    $items[] = array(
+      'path' => 'admin/audio/add', 'title' => t('add audio'),
+      'access' => user_access('administer audio'),
+      'type' => MENU_LOCAL_TASK);
   }
   return $items;
 }
 
+/**
+ * Filemanager API hooks
+ */
+function audio_filemanager_areas() {
+  return array(
+    array(
+      'area' => 'audio',
+      'name' => t('Audio'),
+      'description' => t('Files attached to audio nodes.')
+    )
+  );
+}
 
+/**
+ * Filemanager API hooks
+ */
+function audio_filemanager_download($file) {
+  if ($file->area == 'audio') {
+    return TRUE;
+  }
+}
 
 /**
  * Implementation of hook_link.
  */
 function audio_link($type, $node, $main = 0) {
   $links = array();
-  if ($type == 'node' && $node->type == 'audio' && _is_downloadable($node->audio['fid']))
+  $downloadable = db_result(db_query("SELECT downloadable FROM {audio} WHERE nid=%d", $node->nid));
+  if ($type == 'node' && $node->type == 'audio' && $downloadable) {
     $links[] = l(t('download audio file'), 'audio/download/'.$node->nid, NULL);
+  }
   return $links;
 }
 
@@ -141,16 +195,20 @@
   switch ($op) {
     case 'rss item':
       //NOTE: RSS only allows one enclosure per item
-      if ($node->type == 'audio' && $node->audio['fid']) {
+      if ($node->type == 'audio' && $node->fid) {
         $node->teaser = db_result(db_query("SELECT body FROM {node} WHERE nid=%d", $node->nid));
-      $file = db_fetch_object(db_query("SELECT * FROM {files} WHERE nid=%d", $node->nid));
-
-      return array(array('key' => 'enclosure',
-		'attributes' => array('url' => $GLOBALS['base_url'].'/'.variable_get('file_directory_path', 'files')
-																			.'/'.variable_get('audio_default_path', 'audio')
-																			.'/'. rawurlencode($file->filename),
-      						 'length' => $file->filesize,
-						         'type' => $file->filemime)));
+        $file = db_fetch_object(db_query("SELECT * FROM {files} WHERE nid=%d", $node->nid));
+        $path = $GLOBALS['base_url']
+          .'/'. variable_get('file_directory_path', 'files')
+          .'/'. variable_get('audio_default_path', 'audio')
+          .'/'. rawurlencode($file->filename);
+        // package it for return
+        $item['key'] = 'enclosure';
+        $item['attributes'] = array(
+          'url' => $path,
+          'length' => $file->filesize,
+          'type' => $file->filemime);
+        return $item;
       }
     break;
   }
@@ -215,56 +273,171 @@
 /**
  * Implementation of hook_form
  */
-function audio_form(&$node, &$param) {
+function audio_form(&$node) {
   _audio_check_settings();
   
   
   // This sets the form param reference.
-  $param['options'] = array("enctype" => "multipart/form-data",  "name" => "audio_forms");
+  $form['#attributes'] = array('enctype' => 'multipart/form-data');
 
-  
-  $output .= form_textarea(t('Description'), 'body', $node->body, 60, 20, '', NULL, TRUE);
-  
-  
-  $output .= form_hidden('audio_file_tmp', _is_set_or($node->audio['filepath'], $node->audio_file_tmp->filepath));
-  
-  // Taxonomy select form
-  if (module_exist('taxonomy'))
-    $output .= implode('', taxonomy_node_form('audio', $node));
+  $form['body'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Description'),
+    '#default_value' => $node->body,
+    '#cols' => 60,
+    '#rows' => 5,
+    '#required' => TRUE
+  );
 
+  //make this required... only if the file has not been uploaded..
+  $form['file'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Audio File'),
+    '#weight' => -14,
+  );
+  // for validation
+  $form['file']['audio_current_file'] = array(
+    '#type' => 'value',
+    '#value' => $node->file,
+  );
   //show the user their current file, if one exists..
-  if ($node->audio['title'] || $node->audio_file_tmp->filename){
-       $file_output.= form_item(t('Current Audio File'),
-        t("Your current audio file is:")."<b>" . _is_set_or($node->audio['title'], 
-       $node->audio_file_tmp->filename) . 
-       "</b><br/>".t("Use the 'browse' button below to upload a different audio file, or do nothing to keep it the same."));
+  if ($node->file){
+    $form['file']['current'] = array(
+      '#type' => 'item',
+      '#title' => t('Current audio file'),
+      '#value' => t("The file <b>%filename</b> is attached to this node.", array('%filename' => _is_set_or($node->audio['title'], $node->file->filename))),
+      '#description' => t("Use the 'browse' button below to upload a different audio file, or do nothing to keep it the same."),
+    );
   }
-  
-  //make this required... only if the file has not been uploaded..
-  $file_output .= form_file(t('Audio File'), 'audio_file', 50, t('Click "Browse..." to select an audio file to upload.'), TRUE);
-  $file_output .= form_checkbox(t('Allow file downloads.'), 'audio][downloadable', 1, _is_set_or($node->audio['downloadable'],1) , t('If checked, people will be able to download this audio file on to their own computer.'), NULL, FALSE);
-  $output .= form_group(t('Audio File'), $file_output); 
-  
+  else {
+    $form['file']['current'] = array(
+      '#type' => 'item',
+      '#title' => t('Current Audio File'),
+      '#value' => t('No file is attached.'),
+    );
+  }
+  $form['file']['audio_new_file'] = array(
+    '#type' => 'file',
+    '#title' => t('Add a new audio file'),
+    '#size' => 50,
+    '#description' => t('Click "Browse..." to select an audio file to upload.'),
+  );
+
   //show all current file metadata, if an audio file has been uploaded, or is being previewed...
-  if (!empty($node->audio)) {
-    $audio_output .= form_textfield(t("Song Title"), 'audio][title', $node->audio['title'], 40, 80);
-    $audio_output .= form_textfield(t("Artist"), 'audio][artist', $node->audio['artist'], 40, 80);
-    $audio_output .= form_textfield(t("Album"), 'audio][album', $node->audio['album'], 40, 80);
-    $audio_output .= form_textfield(t("Year"), 'audio][year', $node->audio['year'], 10, 15);
-    $audio_output .= form_textfield(t("Track Number"), 'audio][track', $node->audio['track'], 5, 10,t('Enter a single number here. "1" means that this is the first track on the album.'));
-    $audio_output .= form_textfield(t("Genre"), 'audio][genre', $node->audio['genre'], 20, 40);
+  if (isset($node->audio)) {
+    $form['audio'] = array(
+      '#type' => 'fieldset',
+      '#title' => t("Audio File Information"),
+      '#tree' => TRUE,
+      '#weight' => -15,
+    );
+    $form['audio']['downloadable'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Allow file downloads.'),
+      '#return_value' => 1,
+      '#default_value' => _is_set_or($node->audio['downloadable'],1),
+      '#description' => t('If checked, people will be able to download this audio file on to their own computer.'),
+      '#required' => FALSE
+    );
+    $form['audio']['title'] = array(
+      '#type' => 'textfield',
+      '#title' => t("Song Title"),
+      '#default_value' => $node->audio['title'],
+      '#size' => 40,
+      '#maxlength' => 80
+    );
+    $form['audio']['artist'] = array(
+      '#type' => 'textfield',
+      '#title' => t("Artist"),
+      '#default_value' => $node->audio['artist'],
+      '#size' => 40,
+      '#maxlength' => 80
+    );
+    $form['audio']['album'] = array(
+      '#type' => 'textfield',
+      '#title' => t("Album"),
+      '#default_value' => $node->audio['album'],
+      '#size' => 40,
+      '#maxlength' => 80
+    );
+    $form['audio']['year'] = array(
+      '#type' => 'textfield',
+      '#title' => t("Year"),
+      '#default_value' => $node->audio['year'],
+      '#size' => 10,
+      '#maxlength' => 15
+    );
+    $form['audio']['track'] = array(
+      '#type' => 'textfield',
+      '#title' => t("Track Number"),
+      '#default_value' => $node->audio['track'],
+      '#size' => 5,
+      '#maxlength' => 10,
+      '#description' => t('Enter a single number here. "1" means that this is the first track on the album.')
+    );
+    $form['audio']['genre'] = array(
+      '#type' => 'textfield',
+      '#title' => t("Genre"),
+      '#default_value' => $node->audio['genre'],
+      '#size' => 20,
+      '#maxlength' => 40
+    );
+  }
+  return $form;
+}
 
-    $output .= form_group(t("Audio File Information"), $audio_output);
+/**
+ * Implementation of hook_validate
+ */
+function audio_validate(&$node) {
+//debug_print_backtrace();
+var_dump("validating..");
+  // Check for a new file upload.
+  if ($node->audio_current_file) {
+    $file = filemanager_add_upload('audio_new_file', 'audio', false, $node->audio_current_file);
+  } else {
+    $file = filemanager_add_upload('audio_new_file', 'audio');
+  }
+
+  if ($file) {
+    $node->file = $file;
+    $node->fid = $file->fid;
+  }
+
+  // make sure we've got a file
+  $file = filemanager_get_working_copy($node->fid, false);
+  if (!$file) {
+    form_set_error('audio_file', t('A file must be provided.'));
+  }
+  else {
+    $path = realpath(filemanager_create_path($file, TRUE));
+    // load the id3 tag info
+    $node->audio = audio_get_info($path);
+    if (!empty($node->audio['error'])) {
+      form_set_error('audio_file', 'The file\'s ID3 tags could not be read. ' . implode(' ', $node->audio['error']));
+    }
   }
-  return $output;
+}
+
+function audio_execute(&$node) {
+var_dump("executing..");
+  // Check for a new file upload.
+  if ($file = filemanager_add_upload('audio_file', 'audio', false, $node->file)) {
+    $node->file = $file;
+    $node->audio = audio_get_info($file->filepath);
+    $node->audio_tmp_file = TRUE;
+    _copy_fileinfo($node, $file);
+  }
+var_dump($file);
 }
 
 /**
  * Implementation of hook_view
  */
-function audio_view(&$node, $main = 0, $page = 0) {
-  $node = node_prepare($node, $main);
-  $node->teaser = theme('audio_display_teaser', $node);
+function audio_view(&$node, $teaser = FALSE, $page = FALSE) {
+  $node = node_prepare($node, $teaser);
+  $node->title = $node->audio['title'];
+  $node->teaser = theme('audio_display_teaser', $teaser);
   $node->body = audio_display($node) . $node->body;
 }
 
@@ -393,28 +566,50 @@
  * Implementation of hook_user().
  */
 function audio_user($type, &$edit, &$user) {
-  if ($type == 'view') { //&& user_access('edit own blog', $user) //Not needed??...
-    return array(t('History') => form_item(t('Audio'), l(t('listen to the most recent audio files added'), "audio/$user->uid", array('title' => t("Listen to %username's latest audio files.", array('%username' => $user->name))))));
+  if ($type == 'view') {
+    // TODO: this isn't showing up for me.
+    $ret[t('History')] = l(
+      t('listen to the most recently added audio files'),
+      	"audio/$user->uid",
+      	array('title' => t("Listen to %username's latest audio files.", array('%username' => $user->name_))
+      )
+    );
+    return $ret;
   }
 }
 
 /**
  * Implementation of hook_load
  */
-function audio_load(&$node) {
-  $fid = db_result(db_query("SELECT fid FROM {files} WHERE nid=%d limit 1", $node->nid));
-  if ($fid){
-    //If a file has been uploaded and is located in the file table...
-    $node->audio = db_fetch_array(db_query("SELECT * FROM {audio_node_metadata} WHERE fid=%d", $fid));    
-        
-    $params->url = url('audio/play/'.$node->nid, NULL, NULL, TRUE);
-    $params->title = $node->audio['title'];
-    //if there is no theme function that provides a player of this file type, use the default.
-    //The defualt just shows a bare link to the file...
-    if (!($player = theme($node->audio['fileformat'] . '_player', $params)))
-      $player = theme('audio_player', $params);
-    $node->audio['player'] = $player;
+function audio_load($node) {
+var_dump("loading..");
+  $ret = array();
+
+  // load the audio records
+  $ret['audio'] = db_fetch_array(db_query("SELECT * FROM {audio} WHERE nid=%d", $node->nid));
+
+  // load the file
+  if ($file = filemanager_get_file_info($ret['audio']['fid'])) {
+    $ret['file'] = $file;
+  }
+
+  // move the fid to the node
+  $ret['fid'] = $ret['audio']['fid'];
+  unset($ret['audio']['fid']);
+
+  // setup the audio player
+  // TODO: fix this URL to use the filemanger
+  $params->url = url('audio/play/'.$node->nid, NULL, NULL, TRUE);
+  $params->title = $ret['audio']['title'];
+  $player = theme($ret['audio']['fileformat'] . '_player', $params);
+  if (!$player) {
+    //if there is no theme function that provides a player of this file type,
+    // use the default which just shows a bare link to the file...
+    $player = theme('audio_player', $params);
   }
+  $ret['audio']['player'] = $player;
+
+  return $ret;
 }
 
 /**
@@ -447,24 +642,13 @@
  * Implementation of hook_insert
  */
 function audio_insert(&$node) {
-  $dest = variable_get('audio_default_path', 'audio')."/". basename($node->audio['filepath']);
- 
-  if (file_copy($node->audio['filepath'], $dest)) {
-
-    $fid = db_next_id('{files}_fid');
-    //insert into file table...
-    db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)",
-             $fid, $node->nid, $node->audio['filename'], $node->audio['filepath'], 
-             $node->audio['filemime'], $node->audio['filesize'], 0);
-    
-    //insert into audio_node table
-    db_query("INSERT INTO {audio_node_metadata} (fid, playcount, fileformat, bitrate, sample_rate, 
-               playtime_seconds, title, artist, album, year, track, genre, comment, downloadable) 
-            VALUES (%d, %d, '%s', %f, %f, %d, '%s', '%s', '%s', '%s', %d, '%s', '%s', %d)",
-             $fid, 0, $node->audio['fileformat'], $node->audio['bitrate'], $node->audio['sample_rate'], $node->audio['playtime_seconds'], 
-             $node->audio['title'], $node->audio['artist'], $node->audio['album'], $node->audio['year'], 
-             $node->audio['track'], $node->audio['genre'], $node->audio['comment'], $node->audio['downloadable']);
-  }
+  //insert into audio_node table
+  db_query("INSERT INTO {audio} (nid, fid, playcount, fileformat, bitrate, sample_rate,
+    playtime_seconds, title, artist, album, year, track, genre, comment, downloadable)
+    VALUES (%d, %d, %d, '%s', %f, %f, %d, '%s', '%s', '%s', '%s', %d, '%s', '%s', %d)",
+    $node->nid, $node->fid, $node->audio['fileformat'], $node->audio['bitrate'], $node->audio['sample_rate'], $node->audio['playtime_seconds'],
+    $node->audio['title'], $node->audio['artist'], $node->audio['album'], $node->audio['year'],
+    $node->audio['track'], $node->audio['genre'], $node->audio['comment'], $node->audio['downloadable']);
   return $node->nid;
 }
 
@@ -533,10 +717,14 @@
 
 function audio_api_delete($nid = false){
   global $user;
-  if (!$nid) return;
+  if (!$nid) {
+    return;
+  }
   $audio_node = node_load(array('nid' => $nid));
   //check for user permission...
-  if (!audio_access('delete', $audio_node)) drupal_access_denied();
+  if (!audio_access('delete', $audio_node)) {
+    drupal_access_denied();
+  }
   //otherwise...
   audio_delete($audio_node);
 }
@@ -547,68 +735,21 @@
 function audio_update(&$node) {
   //if a new file has been uploaded, delete all meta information and read in new info from file...
   if ($node->audio_file_tmp) {
-    $file = db_fetch_object(db_query("SELECT * FROM {files} WHERE nid=%d", $node->nid));
-    file_delete(file_create_path($file->filepath));
-        //delete from the files table...
-        db_query("DELETE FROM {files} WHERE filename='%s' AND nid=%d", $file->filename, $node->nid);
-        //delete from the audio_node_meta table...
-        db_query("DELETE FROM {audio_node_metadata} WHERE fid=%d", $file->fid);
-
-        //insert the new audio file...
-        audio_insert($node);
-    } else {
-      $fid = db_result(db_query("SELECT fid FROM {files} WHERE nid=%d limit 1", $node->nid));
-    //no new file.. Just updating the meta fields...        
-
-    db_query("UPDATE {audio_node_metadata} SET title = '%s',
-                artist = '%s', album = '%s', year = '%s', track =%d, genre = '%s', 
-                downloadable = %d WHERE fid = %d", 
-               $node->audio['title'], $node->audio['artist'], $node->audio['album'], 
-                $node->audio['year'], $node->audio['track'], $node->audio['genre'], 
-                $node->audio['downloadable'], $fid);
-        
-        //update ID3 info in the actual file...
-        audio_write_ID3tags($node);
-    }
-}
-
-/**
- * Implementation of hook_validate
- */
-function audio_validate(&$node) {
-
-  if (!empty($_FILES['edit']['name']['audio_file'])) {
-
-    $file = file_check_upload('audio_file');
-    if (!empty($file)) {
-
-      $file = file_save_upload($file);
-      $node->audio = audio_get_info($file->filepath);
-
-      if (!empty($node->audio['error'])){
-        form_set_error('audio_file', t('Uploaded file is not an audio file'));
-      } else {
-
-        $node->audio_file_tmp = $file;
-        _copy_fileinfo($node, $file);
-        
-        //add "downloadable" field to the audio array. This field is a bit of a lost dog since
-        //it is the only field in the $node->audio array that is set in the form, rather then
-        //by the getID3 function...
-        $node->audio['downloadable'] = $_POST['edit']['audio']['downloadable'];
-      }
-    }
-  }
-  elseif (isset($_POST['edit']['audio']) || $_POST['op'] == "Preview") {
-    $node->audio = array_merge(audio_get_info($_POST['edit']['audio_file_tmp']), $_POST['edit']['audio']);
-    
-    if ($_SESSION['file_uploads']){
-      _copy_fileinfo($node, $_SESSION['file_uploads']['audio_file']);
-    }
+    // delete the old node...
+    audio_delete($node);
+    // insert a new one...
+    audio_insert($node);
   }
-  
-  if ($_POST['edit']['audio_file_tmp']){
-    $node->audio_file_tmp = $_POST['edit']['audio_file_tmp'];
+  else {
+    //  no new file.. Just updating the meta fields...
+    db_query("UPDATE {audio} SET fid = %d, title = '%s', artist = '%s',
+      album = '%s', year = '%s', track =%d, genre = '%s', downloadable = %d WHERE nid = %d",
+      $node->fid, $node->audio['title'], $node->audio['artist'],
+      $node->audio['album'], $node->audio['year'], $node->audio['track'],
+      $node->audio['genre'], $node->audio['downloadable'], $node->nid);
+
+    //update ID3 info in the actual file...
+    audio_write_ID3tags($node);
   }
 }
 
@@ -674,7 +815,7 @@
  */
 function audio_write_ID3tags(&$node){
   //grab the fid based on nid, since there is only one file per node...
-  $fid = db_result(db_query("SELECT fid FROM {files} WHERE nid=%d limit 1", $node->nid));
+  $fid = db_result(db_query("SELECT fid FROM {audio} WHERE nid=%d limit 1", $node->nid));
   //include the getid3 library files...
   $id3_path = variable_get('audio_getid3_path', drupal_get_path('module', 'audio').'/getid3/');
   require_once($id3_path.'getid3.php');
@@ -687,46 +828,45 @@
   // NOTE: Because of their wanky includes, this file must be included
   // AFTER an instance of the getID3 class is instantiated.
   require_once($id3_path.'write.php');
-    $tagwriter = new getid3_writetags;
-    $tagwriter->filename       = file_create_path($node->files[$fid]->filepath); //needs to be full path
-    $tagwriter->tagformats     = array('id3v1', 'id3v2.3');
-    
-    // set various options (optional)
-    $tagwriter->overwrite_tags = true;
-    $tagwriter->tag_encoding   = 'UTF-8';
-    $tagwriter->remove_other_tags = true;
-                    
-    //populate data array. Ugly mapping, but what can one do?...
-    $tag_data['title'][]   = $node->audio['title'];
-    $tag_data['artist'][]  = $node->audio['artist'];
-    $tag_data['album'][]   = $node->audio['album'];
-    $tag_data['year'][]    = $node->audio['year'];
-    $tag_data['genre'][]   = $node->audio['genre'];
-    $tag_data['comment'][] = $node->audio['comment'];
-    $tag_data['track'][]   = $node->audio['track'];
-    $tagwriter->tag_data = $tag_data;
-    
-    // write tags
-    //TODO: error handling!....
-    if ($tagwriter->WriteTags()) {
-        //echo 'Successfully wrote tags<br>';
-        if (!empty($tagwriter->warnings)) {
-            //echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings);
-        }
-    } else {
-        //echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors);
-    }
+  $tagwriter = new getid3_writetags;
 
+  // filename needs to be full path
+  $tagwriter->filename       = realpath(filemanager_create_path($node->fid));
+  $tagwriter->tagformats     = array('id3v1', 'id3v2.3');
+
+  // set various options (optional)
+  $tagwriter->overwrite_tags = true;
+  $tagwriter->tag_encoding   = 'UTF-8';
+  $tagwriter->remove_other_tags = true;
+
+  //populate data array. Ugly mapping, but what can one do?...
+  $tag_data['title'][]   = $node->audio['title'];
+  $tag_data['artist'][]  = $node->audio['artist'];
+  $tag_data['album'][]   = $node->audio['album'];
+  $tag_data['year'][]    = $node->audio['year'];
+  $tag_data['genre'][]   = $node->audio['genre'];
+  $tag_data['comment'][] = $node->audio['comment'];
+  $tag_data['track'][]   = $node->audio['track'];
+  $tagwriter->tag_data = $tag_data;
+
+  // write tags
+  //TODO: error handling!....
+  if ($tagwriter->WriteTags()) {
+      //echo 'Successfully wrote tags<br>';
+      if (!empty($tagwriter->warnings)) {
+        //echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings);
+      }
+  } else {
+      //echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors);
+  }
 }
 
 /**
  * Implementation of hook_delete.
  */
 function audio_delete($node) {
-    file_delete(file_create_path($node->audio['filepath']));
-    db_query("DELETE FROM {files} WHERE filename='%s' AND nid=%d", $label, $node->nid);
-    //delete from the audio_node_meta table...
-    db_query("DELETE FROM {audio_node_metadata} WHERE fid=%d", $node->audio['fid']);
+  filemanager_delete($node->fid);
+  db_query("DELETE FROM {audio} WHERE nid=%d", $node->nid);
 }
 
 /**
@@ -770,7 +910,8 @@
   return l($node->audio['title'], 'node/'.$node->nid) . $node->audio['player']. "<br/>";
 }
 
-/* returns nodes (or html) representation of audio files specified by taxonomy id,
+/**
+ * returns nodes (or html) representation of audio files specified by taxonomy id,
  * or all audio files, if no tid is present...
  */
 function audio_get_files($tid = NULL, $as_html = TRUE){
@@ -854,10 +995,6 @@
     echo '</pre>';
 }
 
-function _is_downloadable($fid) {
-  return db_result(db_query("SELECT downloadable FROM {audio_node_metadata} WHERE fid=%d", $fid));
-}
-
 function _is_set_or($var, $default){
   return (isset($var)) ? $var : $default;
 }
Index: audio.mysql
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.mysql,v
retrieving revision 1.1
diff -u -r1.1 audio.mysql
--- audio.mysql	11 Aug 2005 22:51:35 -0000	1.1
+++ audio.mysql	6 Dec 2005 08:27:27 -0000
@@ -1,4 +1,5 @@
-CREATE TABLE `audio_node_metadata` (
+CREATE TABLE `audio` (
+  `nid` int(10) NOT NULL default '0',
   `fid` int(10) NOT NULL default '0',
   `playcount` int(10) NOT NULL default '0',
   `downloadable` tinyint(1) NOT NULL default '1',
@@ -13,5 +14,6 @@
   `track` int(7) NOT NULL default '0',
   `genre` varchar(255) NOT NULL default '',
   `comment` varchar(255) NOT NULL default '',
-  PRIMARY KEY  (`fid`)
-) TYPE=MyISAM;
+  PRIMARY KEY  (`nid`),
+  KEY `audio_fid` (`fid`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
\ No newline at end of file

