? .audio.module.swp
? audio_image.patch
? db_audio.sql
Index: audio.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.install,v
retrieving revision 1.22
diff -u -p -r1.22 audio.install
--- audio.install 14 Aug 2008 20:42:04 -0000 1.22
+++ audio.install 1 Oct 2008 23:46:40 -0000
@@ -41,6 +41,12 @@ function audio_schema() {
'not null' => TRUE,
'default' => 0,
),
+ 'fid' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'description' => t('Primary Key: The {files}.fid.'),
+ ),
'title_format' => array(
'type' => 'varchar',
'length' => 128,
@@ -64,36 +70,12 @@ function audio_schema() {
'not null' => TRUE,
'default' => 1,
),
- 'file_format' => array(
+ 'format' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'default' => '',
),
- 'file_mime' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'file_name' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'file_path' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'file_size' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
'sample_rate' => array(
'type' => 'int',
'size' => 'medium',
@@ -126,6 +108,9 @@ function audio_schema() {
),
),
'primary key' => array('vid'),
+ 'indexes' => array(
+ 'audio_fid' => array('fid'),
+ ),
);
$schema['audio_metadata'] = array(
'description' => t('Extended data about audio files.'),
@@ -533,3 +518,50 @@ function audio_update_6001() {
db_add_primary_key($ret, 'audio_metadata', array('vid', 'tag', 'value'));
return $ret;
}
+
+/**
+ * Move the audio files from the {audio} table to the {files} table and then
+ * remove the columns.
+ *
+ * @return unknown
+ */
+function audio_update_6002() {
+ $ret = array();
+
+ // Create the fid field so we've got a place to store the file id's as we
+ // migrate them.
+ $fid_field = array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'description' => t('Primary Key: The {files}.fid.'),
+ );
+ db_add_field($ret, 'audio', 'fid', $fid_field);
+ db_add_index($ret, 'audio', 'audio_fid', array('fid'));
+
+ // Load all the distinct filepaths, note that this may update multiple audio
+ // rows at once.
+ $result = db_query("SELECT DISTINCT file_path FROM {audio} WHERE fid IS NULL OR fid = 0");
+ while ($file = db_fetch_object($result)) {
+ // Then move the data into the files table.
+ db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) SELECT n.uid, '%s', ai.file_path, ai.file_mime, ai.file_size, 1, n.created AS timestamp FROM {node} n INNER JOIN {audio} ai ON n.vid = ai.vid WHERE ai.file_path = '%s' LIMIT 1", array(basename($file->file_path), $file->file_path));
+ db_query("UPDATE {audio} SET fid = %d WHERE file_path = '%s'", db_last_insert_id('files', 'fid'), $file->file_path);
+ }
+
+ // Drop the old fields.
+ db_drop_field($ret, 'audio', 'file_mime');
+ db_drop_field($ret, 'audio', 'file_name');
+ db_drop_field($ret, 'audio', 'file_path');
+ db_drop_field($ret, 'audio', 'file_size');
+
+ // Rename the file_format field to format.
+ $format_field = array(
+ 'type' => 'varchar',
+ 'length' => 10,
+ 'not null' => TRUE,
+ 'default' => '',
+ );
+ db_change_field($ret, 'audio', 'file_format', 'format', $format_field);
+
+ return $ret;
+}
\ No newline at end of file
Index: audio.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.module,v
retrieving revision 1.144
diff -u -p -r1.144 audio.module
--- audio.module 30 Sep 2008 05:00:52 -0000 1.144
+++ audio.module 1 Oct 2008 23:46:40 -0000
@@ -276,7 +276,7 @@ function audio_access($op, $node = NULL)
* boolean indicating if it's allowed.
*/
function _audio_allow_download($node) {
- if ($node->type == 'audio' && isset($node->url_download) && $node->audio_file['downloadable']) {
+ if ($node->type == 'audio' && isset($node->url_download) && $node->audio['downloadable']) {
$result = audio_invoke_audioapi('access', $node, 'download');
if (in_array(TRUE, $result)) {
@@ -341,13 +341,13 @@ function audio_link($type, $node, $main
);
if ($link_access) {
$links['audio_download_count'] = array(
- 'title' => t('@download_count downloads', array('@download_count' => $node->audio_file['download_count'])),
+ 'title' => t('@download_count downloads', array('@download_count' => $node->audio['download_count'])),
);
}
}
if (_audio_allow_play($node) && $link_access) {
$links['audio_play_count'] = array(
- 'title' => t('@play_count plays', array('@play_count' => $node->audio_file['play_count'])),
+ 'title' => t('@play_count plays', array('@play_count' => $node->audio['play_count'])),
);
}
}
@@ -377,8 +377,8 @@ function audio_nodeapi(&$node, $op, $arg
'key' => 'enclosure',
'attributes' => array(
'url' => $node->url_download,
- 'length' => $node->audio_file['file_size'],
- 'type' => $node->audio_file['file_mime']
+ 'length' => $node->audio['file']->filesize,
+ 'type' => $node->audio['file']->filemime
));
// Provide very basic iTunes support.
$ret[] = array(
@@ -386,7 +386,7 @@ function audio_nodeapi(&$node, $op, $arg
);
$ret[] = array(
'key' => 'itunes:duration',
- 'value' => $node->audio_file['playtime'],
+ 'value' => $node->audio['playtime'],
);
$ret[] = array(
'key' => 'itunes:author',
@@ -433,8 +433,7 @@ function audio_view(&$node, $teaser = FA
* Implementation of hook_validate().
*/
function audio_validate(&$node, &$form) {
- $nid = ($node->nid) ? $node->nid : 'new_node';
- if (!isset($node->audio_file['file_path'])) {
+ if (!isset($node->audio['file']->filepath)) {
form_set_error('audio_upload', t("A file must be provided. If you tried uploading a file, make sure it's less than the upload size limit."));
}
@@ -450,35 +449,34 @@ function audio_load($node) {
if ($node->vid) {
// This is a wonky way to load the fields but its handy right now while
// I'm renaming fields in the databases.
- $fields = db_fetch_array(db_query("SELECT * FROM {audio} WHERE vid=%d", $node->vid));
+ $fields = db_fetch_array(db_query("SELECT a.* FROM {audio} a WHERE vid=%d", $node->vid));
+ $file = db_fetch_object(db_query("SELECT * FROM {files} WHERE fid=%d", $fields['fid']));
+
$ret = array(
'title_format' => $fields['title_format'],
- 'audio_file' => array(
+ 'audio' => array(
'play_count' => $fields['play_count'],
'download_count' => $fields['download_count'],
'downloadable' => $fields['downloadable'],
- 'file_format' => $fields['file_format'],
- 'file_mime' => $fields['file_mime'],
- 'file_name' => $fields['file_name'],
- 'file_path' => $fields['file_path'],
- 'file_size' => $fields['file_size'],
+ 'format' => $fields['format'],
'sample_rate' => $fields['sample_rate'],
'channel_mode' => $fields['channel_mode'],
'bitrate' => $fields['bitrate'],
'bitrate_mode' => $fields['bitrate_mode'],
'playtime' => $fields['playtime'],
'bitrate' => $fields['bitrate'],
+ 'file' => $file,
),
);
- if (file_exists($fields['file_path'])) {
+ if (isset($file->filepath) && file_exists($file->filepath)) {
// TODO: should these links be by vid?
$ret['url_play'] = url('audio/play/'. $node->nid, array('absolute' => TRUE));
- if ($ret['audio_file']['downloadable']) {
+ if ($ret['audio']['downloadable']) {
// iTunes and other podcasting programs check the url to determine the
// file type. we'll add the original file name on to the end. see issues
// #35398 and #68716 for more info.
- $url = 'audio/download/'. $node->nid .'/'. $fields['file_name'];
+ $url = 'audio/download/'. $node->nid .'/'. $file->filename;
$ret['url_download'] = url($url, array('absolute' => TRUE));
}
}
@@ -499,83 +497,75 @@ function audio_load($node) {
* Implementation of hook_insert().
*/
function audio_insert(&$node) {
- file_move($node->audio_file['file_path'], audio_get_directory(), FILE_EXISTS_RENAME);
-
- $f = $node->audio_file;
- db_query("INSERT INTO {audio} (vid, nid, title_format, downloadable, file_format, file_name, file_path, file_mime, file_size, bitrate, bitrate_mode, sample_rate, channel_mode, playtime)
- VALUES (%d, %d, '%s', %d, '%s', '%s', '%s', '%s', %d, %f, '%s', %d, '%s', '%s')",
- $node->vid, $node->nid, $node->title_format, $f['downloadable'], $f['file_format'], $f['file_name'], $f['file_path'], $f['file_mime'], filesize($f['file_path']), $f['bitrate'], $f['bitrate_mode'], $f['sample_rate'], $f['channel_mode'], $f['playtime']);
-
- _audio_save_tags_to_db($node);
-
- // Unset the new file flag incase this node is re-saved.
- unset($node->audio_file['newfile']);
+ file_move($node->audio['file']->filepath, audio_get_directory(), FILE_EXISTS_RENAME);
+ _audio_save($node);
}
/**
- * Insert a new node revision.
- *
- * If a new file wasn't uploaded, make a copy of the existing file.
+ * Implementation of hook_update().
*/
-function audio_insert_revision($node) {
- if (isset($node->audio_file['newfile'])) {
- file_move($node->audio_file['file_path'], audio_get_directory(), FILE_EXISTS_RENAME);
+function audio_update(&$node) {
+ // If there's a new file we need to move it to the correct location.
+ if (isset($node->audio['newfile'])) {
+ if (!$node->revision) {
+ // If it's not a revision the existing file needs to be removed.
+ $oldfile = db_fetch_object(db_query('SELECT f.* FROM {files} f INNER JOIN {audio} a ON f.fid = a.fid WHERE a.vid = %d', $node->vid));
+ _audio_file_delete($oldfile);
+ }
+ file_move($node->audio['file']->filepath, audio_get_directory(), FILE_EXISTS_RENAME);
}
- else {
- $newname = file_create_filename($node->audio_file['file_name'], audio_get_directory());
- file_copy($node->audio_file['file_path'], $newname);
+ else if ($node->revision) {
+ // New revision using existing file so we need to copy it.
+ file_copy($node->audio['file']->filepath, file_create_filename($node->audio['file']->filename, audio_get_directory()));
+ // Unset the fid so a new record is created.
+ $node->audio['file']->fid = NULL;
}
- $f = $node->audio_file;
- db_query("INSERT INTO {audio} (vid, nid, title_format, downloadable, file_format, file_name, file_path, file_mime, file_size, bitrate, bitrate_mode, sample_rate, channel_mode, playtime)
- VALUES (%d, %d, '%s', %d, '%s', '%s', '%s', '%s', %d, %f, '%s', %d, '%s', '%s')",
- $node->vid, $node->nid, $node->title_format, $f['downloadable'], $f['file_format'], $f['file_name'], $f['file_path'], $f['file_mime'], filesize($f['file_path']), $f['bitrate'], $f['bitrate_mode'], $f['sample_rate'], $f['channel_mode'], $f['playtime']);
-
- _audio_save_tags_to_db($node);
+ _audio_save($node, array('vid'));
}
/**
- * Implementation of hook_update().
+ * Handle the busy work of saving the node's audio and file records.
+ *
+ * @param $node Node opject.
+ * @param $update Array of fields to match for an update, empty array inserts
+ * a new record.
*/
-function audio_update(&$node) {
- // Check for new revsion.
- if ($node->revision) {
- return audio_insert_revision($node);
- }
+function _audio_save(&$node, $update = array()) {
+ // Save the file
+ $node->audio['file']->timestamp = time();
+ $node->audio['file']->filesize = filesize($node->audio['file']->filepath);
+ $node->audio['file']->status |= FILE_STATUS_PERMANENT;
+ // If there's an fid update, otherwise insert.
+ drupal_write_record('files', $node->audio['file'], empty($node->audio['file']->fid) ? array() : array('fid'));
- if (isset($node->audio_file['newfile'])) {
- unset($node->audio_file['newfile']);
+ // Save the audio row.
+ $audio = array_merge($node->audio, array('nid' => $node->nid, 'vid' => $node->vid, 'title_format' => $node->title_format, 'fid' => $node->audio['file']->fid));
+ drupal_write_record('audio', $audio, $update);
- // Remove the old file.
- $oldfile = db_fetch_object(db_query('SELECT file_path FROM {audio} f WHERE f.vid = %d', $node->vid));
- file_delete($oldfile->file_path);
+ // Remove any existing metadata.
+ db_query("DELETE FROM {audio_metadata} WHERE vid=%d", $node->vid);
- // Save the new one.
- file_move($node->audio_file['file_path'], audio_get_directory(), FILE_EXISTS_RENAME);
+ // Save the new tags.
+ $allowed_tags = audio_get_tags_allowed();
+ foreach ($node->audio_tags as $tag => $value) {
+ if (in_array($tag, $allowed_tags) && $value) {
+ $metadata = array('vid' => $node->vid, 'tag' => $tag, 'value' => $value, 'clean' => audio_clean_tag($value));
+ drupal_write_record('audio_metadata', $metadata);
+ }
}
- // Do a delete and insert rather than an update to ensure that we've got db
- // records. it takes a bit longer but it allows us to carry on if one of the
- // records wasn't created by audio_insert().
- db_query("DELETE FROM {audio} WHERE vid=%d", $node->vid);
-
- $f = $node->audio_file;
- db_query("INSERT INTO {audio} (vid, nid, title_format, play_count, download_count, downloadable, file_format, file_name, file_path, file_mime, file_size, bitrate, bitrate_mode, sample_rate, channel_mode, playtime)
- VALUES (%d, %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', %d, %f, '%s', %d, '%s', '%s')",
- $node->vid, $node->nid, $node->title_format, $f['play_count'], $f['download_count'], $f['downloadable'], $f['file_format'], $f['file_name'], $f['file_path'], $f['file_mime'], filesize($f['file_path']), $f['bitrate'], $f['bitrate_mode'], $f['sample_rate'], $f['channel_mode'], $f['playtime']);
-
- _audio_save_tags_to_db($node);
+ // Unset the new file flag incase this node is re-saved.
+ unset($node->audio['newfile']);
}
/**
* Implementation of hook_delete().
*/
function audio_delete($node) {
- $result = db_query('SELECT vid, file_path FROM {audio} WHERE nid = %d', $node->nid);
+ $result = db_query('SELECT a.vid, f.* FROM {audio} a LEFT JOIN {files} f ON a.fid = f.fid WHERE nid = %d', $node->nid);
while ($o = db_fetch_object($result)) {
- if (isset($o->file_path)) {
- file_delete($o->file_path);
- }
+ _audio_file_delete($o);
db_query('DELETE FROM {audio_metadata} WHERE vid = %d', $o->vid);
}
db_query('DELETE FROM {audio} WHERE nid = %d', $node->nid);
@@ -585,15 +575,28 @@ function audio_delete($node) {
* Delete a single revision.
*/
function audio_delete_revision($node) {
- if ($filepath = db_result(db_query('SELECT file_path FROM {audio} WHERE vid = %d', $node->vid))) {
- file_delete($filepath);
- }
+ $file = db_result(db_query('SELECT a.vid, f.* FROM {audio} a LEFT JOIN {files} f ON a.fid = f.fid WHERE vid = %d', $node->vid));
+ _audio_file_delete($file);
db_query('DELETE FROM {audio_metadata} WHERE vid = %d', $node->vid);
db_query('DELETE FROM {audio} WHERE vid = %d', $node->vid);
}
/**
+ * Handle the busy work of deleting the file record and the file.
+ *
+ * @param unknown_type $file
+ */
+function _audio_file_delete($file) {
+ if (!empty($file->filepath)) {
+ file_delete($file->filepath);
+ }
+ if (!empty($file->fid)) {
+ db_query('DELETE FROM {files} WHERE fid = %d', array($file->fid));
+ }
+}
+
+/**
* Implementation of hook_form().
*/
function audio_form(&$node, &$form_state) {
@@ -630,7 +633,7 @@ function audio_form(&$node, &$form_state
}
- $form['audio_file'] = array(
+ $form['audio'] = array(
'#type' => 'fieldset',
'#title' => t('Audio File Info'),
'#collapsible' => TRUE,
@@ -640,112 +643,104 @@ function audio_form(&$node, &$form_state
// Place a visible copy of the file path on the form (after removing the
// directory info from non-admins).
- $form['audio_file']['display_file_path'] = array(
+ $form['audio']['display_filepath'] = array(
'#type' => 'item',
'#title' => t('Current File'),
- '#value' => empty($node->audio_file['file_path']) ? t('No file is attached.') : (user_access('administer audio') ? $node->audio_file['file_path'] : basename($node->audio_file['file_path'])),
+ '#value' => empty($node->audio['file']->filepath) ? t('No file is attached.') : (user_access('administer audio') ? $node->audio['file']->filepath : basename($node->audio['file']->filepath)),
);
// If we've got a file, add the file information fields.
- if (!empty($node->audio_file['file_name'])) {
- $form['audio_file']['#theme'] = 'audio_file_form';
+ if (!empty($node->audio['file']->filename)) {
+ $form['audio']['#theme'] = 'audio_file_form';
// Store the non-user editable file information as values.
- $form['audio_file']['file_path'] = array(
- '#type' => 'value',
- '#value' => $node->audio_file['file_path'],
- );
- $form['audio_file']['file_name'] = array(
- '#type' => 'value',
- '#value' => $node->audio_file['file_name'],
- );
- $form['audio_file']['file_mime'] = array(
+ $form['audio']['file'] = array(
'#type' => 'value',
- '#value' => $node->audio_file['file_mime'],
+ '#value' => $node->audio['file'],
);
- $form['audio_file']['file_format'] = array(
+ $form['audio']['format'] = array(
'#type' => 'select',
'#title' => t('Format'),
- '#default_value' => $node->audio_file['file_format'],
+ '#default_value' => $node->audio['format'],
'#options' => drupal_map_assoc(array('', 'aac', 'ac3', 'au', 'avr', 'flac', 'midi', 'mod', 'mp3', 'mpc', 'ogg', 'voc'), 'drupal_strtoupper'),
);
- $form['audio_file']['file_size'] = array(
+ $form['audio']['file_size'] = array(
'#type' => 'textfield',
'#title' => t('File Size'),
- '#default_value' => $node->audio_file['file_size'],
+ '#default_value' => $node->audio['file']->filesize,
);
- $form['audio_file']['playtime'] = array(
+ $form['audio']['playtime'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
- '#default_value' => $node->audio_file['playtime'],
+ '#default_value' => $node->audio['playtime'],
'#description' => t('The format is hours:minutes:seconds.'),
);
- $form['audio_file']['sample_rate'] = array(
+ $form['audio']['sample_rate'] = array(
'#type' => 'select',
'#title' => t('Sample rate'),
- '#default_value' => $node->audio_file['sample_rate'],
+ '#default_value' => $node->audio['sample_rate'],
'#options' => array('' => '', '48000' => '48,000 Hz', '44100' => '44,100 Hz', '32000' => '32,000 Hz', '22050' => '22,050 Hz', '11025' => '11,025 Hz', '8000' => '8,000 Hz'),
);
- $form['audio_file']['channel_mode'] = array(
+ $form['audio']['channel_mode'] = array(
'#type' => 'select',
'#title' => t('Channel mode'),
- '#default_value' => $node->audio_file['channel_mode'],
+ '#default_value' => $node->audio['channel_mode'],
'#options' => array('stereo' => t('Stereo'), 'mono' => t('Mono')),
);
- $form['audio_file']['bitrate'] = array(
+ $form['audio']['bitrate'] = array(
'#type' => 'textfield',
'#title' => t('Bitrate'),
- '#default_value' => $node->audio_file['bitrate'],
+ '#default_value' => $node->audio['bitrate'],
);
- $form['audio_file']['bitrate_mode'] = array(
+ $form['audio']['bitrate_mode'] = array(
'#type' => 'select',
'#title' => t('Bitrate mode'),
- '#default_value' => $node->audio_file['bitrate_mode'],
+ '#default_value' => $node->audio['bitrate_mode'],
'#options' => array('' => '', 'cbr' => t('Constant'), 'vbr' => t('Variable')),
);
// Users shouldn't be able to change the play and download counts so we'll
// put these for viewing...
- $form['audio_file']['display_play_count'] = array(
+ $form['audio']['display_play_count'] = array(
'#type' => 'item',
'#title' => t('Play count'),
- '#value' => $node->audio_file['play_count'],
+ '#value' => $node->audio['play_count'],
);
- $form['audio_file']['display_download_count'] = array(
+ $form['audio']['display_download_count'] = array(
'#type' => 'item',
'#title' => t('Download count'),
- '#value' => $node->audio_file['download_count'],
+ '#value' => $node->audio['download_count'],
);
// ...and these are what we'll save back to the node.
- $form['audio_file']['play_count'] = array(
+ $form['audio']['play_count'] = array(
'#type' => 'value',
- '#value' => $node->audio_file['play_count'],
+ '#value' => $node->audio['play_count'],
);
- $form['audio_file']['download_count'] = array(
+ $form['audio']['download_count'] = array(
'#type' => 'value',
- '#value' => $node->audio_file['download_count'],
+ '#value' => $node->audio['download_count'],
);
}
- $form['audio_file']['audio_upload'] = array(
+ $form['audio']['audio_upload'] = array(
'#tree' => FALSE,
'#type' => 'file',
- '#title' => empty($node->audio_file['file_name']) ? t('Add a new audio file') : t('Replace this with a new file'),
+ '#title' => empty($node->audio['file']->filename) ? t('Add a new audio file') : t('Replace this with a new file'),
'#description' => t('Click "Browse..." to select an audio file to upload. Only files with the following extensions are allowed: %allowed-extensions.', array('%allowed-extensions' => variable_get('audio_allowed_extensions', 'mp3 wav ogg'))) .'
'
. t('NOTE: the current PHP configuration limits uploads to %maxsize.', array('%maxsize' => format_size(file_upload_max_size()))),
);
- $form['audio_file']['downloadable'] = array(
+ $form['audio']['downloadable'] = array(
'#type' => 'checkbox',
'#title' => t('Allow file downloads.'),
- '#default_value' => !empty($node->audio_file['downloadable']) ? $node->audio_file['downloadable'] : variable_get('audio_default_downloadable', 1),
+ '#default_value' => !empty($node->audio['downloadable']) ? $node->audio['downloadable'] : variable_get('audio_default_downloadable', 1),
'#description' => t('If checked, a link will be displayed allowing visitors to download this audio file on to their own computer.') .'
'
. t('WARNING: even if you leave this unchecked, clever users will be able to find a way to download the file. This just makes them work a little harder to find the link.'),
);
// If we've got a file, add the fields for editing meta data.
- if (!empty($node->audio_file['file_path'])) {
+ if (!empty($node->audio['file']->filepath)) {
$form['audio_tags'] = array(
'#type' => 'fieldset',
'#title' => t('Audio Metadata'),
@@ -802,15 +797,12 @@ function audio_node_form_validate($form,
);
if ($file = file_save_upload('audio_upload', $validators)) {
$node = (object) $form_state['values'];
- $node->audio_file = array(
+ $node->audio = array(
'newfile' => TRUE,
'play_count' => 0,
'download_count' => 0,
- 'downloadable' => (bool) $form_state['values']['audio_file']['downloadable'],
- 'file_name' => $file->filename,
- 'file_path' => $file->filepath,
- 'file_mime' => $file->filemime,
- 'file_size' => $file->filesize,
+ 'downloadable' => (bool) $form_state['values']['audio']['downloadable'],
+ 'file' => $file,
);
// Allow other modules to modify the node.
@@ -820,8 +812,9 @@ function audio_node_form_validate($form,
// form. Note that we do this after calling we called our api hook with
// the upload operation, it gives the audio_id3 module a chance to read
// the tags.
- $form_state['values']['audio_file'] = $node->audio_file;
+ $form_state['values']['audio'] = $node->audio;
$form_state['values']['audio_tags'] = $node->audio_tags;
+ $form_state['values']['audio_images'] = $node->audio_images;
}
}
@@ -904,7 +897,7 @@ function audio_user($op, &$edit, &$user,
function audio_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
- $blocks[2]['info'] = t('audio: Browse by');
+ $blocks[2]['info'] = t('Audio: Browse by');
return $blocks;
case 'view':
@@ -1089,7 +1082,7 @@ function audio_get_players($op = 'names'
*/
function audio_get_node_player($node, $playername = NULL) {
if (_audio_allow_play($node)) {
- $format = $node->audio_file['file_format'];
+ $format = $node->audio['format'];
if (!isset($playername)) {
$playername = variable_get('audio_player_'. $format, '1pixelout');
}
@@ -1166,7 +1159,16 @@ function audio_api_insert($filepath, $ti
drupal_access_denied();
}
- $filepath = realpath($filepath);
+ // Begin building file object.
+ $file = new stdClass();
+ $file->uid = $user->uid;
+ $file->filepath = $filepath;
+ $file->filename = basename($file->filepath);
+ $file->filemime = module_exists('mimedetect') ? mimedetect_mime($file->filepath) : file_get_mimetype($file->filepath);
+ $file->filesize = filesize($file->filepath);
+ $file->timestamp = time();
+ $file->status = FILE_STATUS_TEMPORARY;
+ drupal_write_record('files', $file);
$node = new stdClass();
$node->nid = NULL;
@@ -1190,15 +1192,12 @@ function audio_api_insert($filepath, $ti
$node->audio_tags = array();
$node->audio_images = array();
- $node->audio_file = array(
+ $node->audio = array(
'newfile' => TRUE,
'downloadable' => variable_get('audio_default_downloadable', 1),
'play_count' => 0,
'download_count' => 0,
- 'file_size' => filesize($filepath),
- 'file_name' => basename($filepath),
- 'file_path' => $filepath,
- 'file_mime' => module_exists('mimedetect') ? mimedetect_mime($filepath) : file_get_mimetype($filepath),
+ 'file' => $file,
);
node_object_prepare($node);
@@ -1228,27 +1227,6 @@ function audio_api_insert($filepath, $ti
}
/**
- * Save the node's ID3 tags into the database.
- *
- * @param $node
- * Node object.
- */
-function _audio_save_tags_to_db($node) {
- $allowed_tags = audio_get_tags_allowed();
-
- // Remove any existing metadata.
- db_query("DELETE FROM {audio_metadata} WHERE vid=%d", $node->vid);
-
- // Save the new tags.
- foreach ($node->audio_tags as $tag => $value) {
- if (in_array($tag, $allowed_tags) && $value) {
- db_query("INSERT INTO {audio_metadata} (vid, tag, value, clean) VALUES (%d, '%s', '%s', '%s')",
- $node->vid, $tag, $value, audio_clean_tag($value));
- }
- }
-}
-
-/**
* Parse an array into a valid urlencoded query string.
*
* This function is a work-around for a drupal_urlencode issue in core.
@@ -1298,7 +1276,7 @@ function audio_query_string_encode($quer
*/
function audio_is_flash_playable($node) {
// Flash only supports a limited range of sample rates.
- switch ($node->audio_file['sample_rate']) {
+ switch ($node->audio['sample_rate']) {
case '44100': case '22050': case '11025':
return TRUE;
default:
@@ -1332,14 +1310,14 @@ function audio_token_values($type, $obje
}
// Formatted file info.
- $tokens['audio-length'] = theme('audio_format_filelength', $node->audio_file);
- $tokens['audio-format'] = theme('audio_format_fileformat', $node->audio_file);
+ $tokens['audio-length'] = theme('audio_format_filelength', $node->audio);
+ $tokens['audio-format'] = theme('audio_format_fileformat', $node->audio);
// Raw file info.
- $keys = array('file_format', 'file_name', 'file_path', 'file_mime', 'file_size', 'sample_rate', 'channel_mode', 'bitrate', 'bitrate_mode', 'playtime');
+ $keys = array('format', 'filename', 'filepath', 'filemime', 'file_size', 'sample_rate', 'channel_mode', 'bitrate', 'bitrate_mode', 'playtime');
foreach ($keys as $key) {
- if (isset($node->audio_file[$key])) {
- $tokens['audio-'. strtr($key, '_', '-')] = check_plain($node->audio_file[$key]);
+ if (isset($node->audio[$key])) {
+ $tokens['audio-'. strtr($key, '_', '-')] = check_plain($node->audio[$key]);
}
}
// Play and download links.
Index: audio.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.pages.inc,v
retrieving revision 1.1
diff -u -p -r1.1 audio.pages.inc
--- audio.pages.inc 30 Sep 2008 05:00:52 -0000 1.1
+++ audio.pages.inc 1 Oct 2008 23:46:40 -0000
@@ -75,7 +75,7 @@ function audio_download($node) {
// The mime_header_encode function does not (yet) support
// quoted-string encoding of ASCII strings with special
// characters. See discussion at http://drupal.org/node/82614
- $filename = $node->audio_file['file_name'];
+ $filename = $node->audio['file']->filename;
// If the string contains non-ASCII characters, process it through
// the mime_header_encode function.
if (preg_match('/[^\x20-\x7E]/', $filename)) {
@@ -87,11 +87,11 @@ function audio_download($node) {
$filename = '"'. str_replace('"', '\"', $filename) .'"';
}
$headers = array(
- 'Content-Type: '. mime_header_encode($node->audio_file['file_mime']),
- 'Content-Length: '. $node->audio_file['file_size'],
+ 'Content-Type: '. mime_header_encode($node->audio['file']->filemime),
+ 'Content-Length: '. $node->audio['file']->filesize,
'Content-Disposition: attachment; filename='. $filename,
);
- audio_file_transfer($node->audio_file['file_path'], $headers);
+ audio_file_transfer($node->audio['file']->filepath, $headers);
}
/**
@@ -114,14 +114,14 @@ function audio_play($node = FALSE) {
'Pragma: public',
'Expires: 0',
'Cache-Control: must-revalidate, post-check=0, pre-check=0, private',
- 'Content-Type: '. mime_header_encode($node->audio_file['file_mime']),
- 'Content-Length: '. $node->audio_file['file_size'],
+ 'Content-Type: '. mime_header_encode($node->audio['file']->filemime),
+ 'Content-Length: '. $node->audio['file']->filesize,
'Content-Disposition: inline;',
'Content-Transfer-Encoding: binary',
);
// Required for IE, otherwise Content-disposition is ignored.
ini_set('zlib.output_compression', 'Off');
- audio_file_transfer($node->audio_file['file_path'], $headers);
+ audio_file_transfer($node->audio['file']->filepath, $headers);
}
/**
Index: audio.theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/audio/audio.theme.inc,v
retrieving revision 1.1
diff -u -p -r1.1 audio.theme.inc
--- audio.theme.inc 25 May 2008 23:10:50 -0000 1.1
+++ audio.theme.inc 1 Oct 2008 23:46:40 -0000
@@ -23,8 +23,8 @@ function theme_audio_display($node) {
. theme('audio_format_tag', $tag, $node->audio_tags[$tag], $setting);
}
}
- $items[] = ''. t('Length') .': '. theme('audio_format_filelength', $node->audio_file);
- $items[] = ''. t('Format') .': '. theme('audio_format_fileformat', $node->audio_file);
+ $items[] = ''. t('Length') .': '. theme('audio_format_filelength', $node->audio);
+ $items[] = ''. t('Format') .': '. theme('audio_format_fileformat', $node->audio);
$output = "