Hello,
I am trying to attach an audio file to a file product so that people can listen to part of a song before they buy it. I have run into some really serious issues when I try to edit an attached audio node. Whenever I first create the audio attachment everything goes well. Here is the var_dump($node) output of the very first audio_validate call, which is where I have run into some issues. All is well so far...
object(stdClass)(9) {
["title"]=>
string(17) "%title by %artist"
["status"]=>
int(1)
["uid"]=>
string(1) "1"
["name"]=>
string(5) "admin"
["created"]=>
int(1154295588)
["type"]=>
string(5) "audio"
["audio_file"]=>
object(stdClass)(6) {
["filename"]=>
string(19) "Seasons excerpt.mp3"
["filepath"]=>
string(35) "files/tmp/audio/Seasons excerpt.mp3"
["filemime"]=>
string(11) "audio/x-mp3"
["filesize"]=>
int(990792)
["source"]=>
string(12) "audio_upload"
["newfile"]=>
bool(true)
}
["audio_fileinfo"]=>
array(9) {
["fileformat"]=>
string(3) "mp3"
["mimetype"]=>
string(10) "audio/mpeg"
["playtime"]=>
string(4) "1:02"
["bitrate"]=>
int(128000)
["bitrate_mode"]=>
string(3) "cbr"
["channel_mode"]=>
string(6) "stereo"
["sample_rate"]=>
int(44100)
["downloadable"]=>
NULL
["filesize"]=>
int(990792)
}
["audio_tags"]=>
array(0) {
}
}
Note: I only have the title and the author tags defined in settings because they are the only ones required and I did not need the rest.
Now here is where things start to get a little tricky. I uploaded an mp3 file that did not have the title and the artist embedded in the file. Well, the title and the author defaulted to blank leaving the title for the audio file at 'by' because of the '%title by %author' default title. This is obviously not a very convienient title for a song so I tried to edit the audio node to manually fill in the title and the author tags. The song excerpt was correctly placed into the files/audio/ directory (This seemingly irrelevant information will be useful in a moment!). First things first, I get two errors;
* warning: Invalid argument supplied for foreach() in /usr/home/kw88keys/public_html/modules/audio/audio.module on line 1590.
* A file must be provided.
I have already attached a file though. But here is the funny part to me. When I do the same var_dump($node) as above in the audio_validate module where I get this 'A file must be provided.' error, I notice that it is called twice with different node variables...
object(stdClass)(7) {
["title"]=>
string(17) "%title by %artist"
["status"]=>
int(1)
["uid"]=>
string(1) "1"
["name"]=>
string(5) "admin"
["created"]=>
string(10) "1154295589"
["type"]=>
string(5) "audio"
["audio_file"]=>
object(stdClass)(5) {
["origname"]=>
string(19) "Seasons excerpt.mp3"
["filename"]=>
string(19) "Seasons excerpt.mp3"
["filepath"]=>
string(31) "files/audio/Seasons excerpt.mp3"
["filemime"]=>
string(11) "audio/x-mp3"
["filesize"]=>
string(6) "990792"
}
}
This is the first node that goes into the audio_validate hook. This node passes the validation with flying colors because of the $node->audio_file. I think this one is coming out of the audio_attach nodeapi hook. But the second confuses me. This is the dump of the second node passed into the audio_validate function (on the same submit).
object(stdClass)(35) {
["nid"]=>
string(3) "109"
["vid"]=>
string(3) "109"
["uid"]=>
string(1) "1"
["created"]=>
string(10) "1154295589"
["changed"]=>
string(10) "1154295589"
["type"]=>
string(5) "audio"
["title_format"]=>
string(17) "%title by %artist"
["body"]=>
string(0) ""
["format"]=>
string(1) "1"
["audio_upload"]=>
NULL
["audio_fileinfo"]=>
array(10) {
["downloadable"]=>
int(0)
["play_count"]=>
string(1) "0"
["download_count"]=>
string(1) "0"
["fileformat"]=>
string(3) "mp3"
["filesize"]=>
string(6) "990792"
["playtime"]=>
string(4) "1:02"
["sample_rate"]=>
string(5) "44100"
["channel_mode"]=>
string(6) "stereo"
["bitrate"]=>
string(6) "128000"
["bitrate_mode"]=>
string(3) "cbr"
}
["audio_tags"]=>
array(2) {
["artist"]=>
string(9) "Kent Webb"
["title"]=>
string(7) "Seasons"
}
["name"]=>
string(5) "admin"
["date"]=>
string(25) "2006-07-30 16:39:49 -0500"
["status"]=>
int(1)
["moderate"]=>
int(0)
["promote"]=>
int(1)
["sticky"]=>
int(0)
["revision"]=>
int(0)
["preview"]=>
string(7) "Preview"
["submit"]=>
string(6) "Submit"
["delete"]=>
string(6) "Delete"
["form_id"]=>
string(15) "audio_node_form"
["aid"]=>
int(111)
["audio_title"]=>
string(17) "%title by %artist"
["audio_publish"]=>
int(1)
["category"]=>
array(2) {
[87]=>
string(1) "0"
[50]=>
string(1) "0"
}
["comment"]=>
string(1) "0"
["ptype"]=>
string(1) "0"
["product_add"]=>
string(12) "Add to store"
["menu"]=>
array(7) {
["title"]=>
string(0) ""
["description"]=>
string(0) ""
["pid"]=>
string(1) "1"
["path"]=>
string(0) ""
["weight"]=>
string(1) "0"
["mid"]=>
int(0)
["type"]=>
string(2) "86"
}
["path"]=>
string(0) ""
["taxonomy"]=>
array(2) {
[87]=>
string(1) "0"
[50]=>
string(1) "0"
}
["upload"]=>
NULL
["attach"]=>
string(31) "http://webbtracks.com/upload/js"
}
This is more of a complete node structure and it is also the one that trips the validation error because of the lack of the audio_file attribute. It has audio_fileinfo but no audio_file, but you can clearly see that there is a file present but it lacks any reference to the file or the file path. So because of the failed validation none of the changes stick in the node and it reverts back to the original audio node information.
I really do not know why this validation is divided among two calls. Maybe it is because the audio attach is calling a separate validation but it REALLY, REALLY hinders the functionality of this audio_attach module. Could it be something I am doing or is no one else in need of editing an audio node and saving the changes. Whatever the case, this problem has me confused.
Thanks a lot for your help.
Adrian
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | audio_attach.module_76316.patch | 1.33 KB | drewish |
| #3 | write.php.txt | 23.16 KB | awebb |
| #2 | audio_attach.module | 6.46 KB | awebb |
Comments
Comment #1
Tracy Dean commentedNo, it's not just you. I'm having the same problems.
When I go to the edit page for an audio node, it had a section headed "Audio File Info" which includes a textbox labeled "Replace this with a new file:", and a section headed "Attached audio files" which includes a textbox labeled "Add a new audio file:"
UPDATE
Went to Home » administer » settings » content types » audio:configure and disabled "Attach audio files". This has got rid of the section headed "Attached audio files" from the edit screen and allows me to edit audio nodes. I'm still getting the following errors though:
Love to get rid of the error messages so any help appreciated.
Tracy
Comment #2
awebb commentedOK, I've been playing around with this error for a while and I realized what the problem was. When ever we are working with an audio node (trying to edit it) audio_attach interferes with the process and screws it up because it goes into the case prepare in the audio_attach_nodeapi which then tries to create a new node because it passes an unitialized node (minus the already existing nid) into node save which in turn calls the audio_insert hook instead of the correct audio_update. When I disabled the audio_attach module, the audio module worked like a charm, so I realized that audio_attach has absolutely no business getting called when we are working with an audio node. This is causing the multiple nodes being passed into the audio_validate hook that I mentioned above. So I made a few adjustments and I was finally able to get these errors that I had been experiencing (such as the 'A file must be provided.' and the foreach error) to go away.
First I changed the initial exit condition in the audio_attach_nodeapi to include the condition [ $node->type == 'audio' ] as shown below, because we do not need to include the node attach functionality when we are dealing with an audio node itself. The audio module doesn't need any help doing it's job. This fixed the problems with the editing of the audio node while still keeping the functionality correct for all others with audio attachments enabled.
function audio_attach_nodeapi(&$node, $op, $teaser, $page) {
if($node->type == 'audio' || variable_get('audio_attach_'. $node->type, 0) == 0){
return;
}
switch ($op) {
...
}
}
I had also noticed when I went to create or edit an audio node two boxes would show up one that was put there by the audio.module and one by the audio_attach module. This was very annoying to have duplicate file input forms on the same page so I went into the audio_attach_form_alter hook and noticed that drewish apparently meant to correct for this problem but there was a problem that I found with his initial exit condition. He was checking to see if the $form['type'] array is set to 'audio'. Well, a few lines down he sets $type = $form['type']['#value'] so his initial exit condition was not getting triggered because the array can not equal a string. It's a simple typo. So I changed the initial part of the hook audio_attach_form_alter to look like the below and that fixed the issue. I just moved his $type declaration above the condition and checked whether $type == 'audio'. He makes use of this functionality quite a few times in the function. It's what cued me onto the error.
function audio_attach_form_alter($form_id, &$form) {
// Make a copy of the type to shorten up the code
$type = $form['type']['#value'];
if (!isset($form['type']) || $type == 'audio') {
return;
}
$enabled = variable_get('audio_attach_'. $type, 0);
$getid3_path = variable_get('audio_getid3_path', drupal_get_path('module', 'audio') .'/getid3/getid3/');
switch ($form_id) {
...
}
}
Those two corrections solve most of the errors I've experienced except one. I noticed that the title, if set in the audio_attach form, always resets back to the '%title by %author' title_format (even on initial creation). I have found out why this is, though. $audio->title is the first property set in the prepare case in the nodeapi hook, but later node_submit is called, which calls audio_submit, which calls audio_set_title, which sets the title back to the title_format. So the form entry for the title never sticks. I think this could be fixed by moving the $audio->title = $_POST['edit']['audio_title']; to the line after the $audio = node_submit($audio); statement, but I have not changed this so I do not know for sure. I should work in theory.
I have attached the audio_attach.module that I updated to this post so that you can download and try the changes if you wish. Nothing has been changed but the two areas I have described above. I hope that these changes work for you. If there is a better way to accomplish the same thing I welcome your suggestions.
Take care,
Adrian
Comment #3
awebb commentedBy the way, when I first installed the audio.module I had the exact same problem with the getid3 library. The problem is that when you have empty tags, the function FormatDataForID3v1() in the class getid3_writetags passes empty values into implode statements for several hardcoded tags that you might not have defined, such as album, year, track number, and comments. I made a few adjustments to this file and I got the warnings to go away. Specifically, I enclosed those statements in conditionals that check for valid content within the array variables before they go into the implode statement or else it just assigns the results an empty string. I have attached the modified write.php file. This should eliminate all of those annoying warnings. I think that the problem stemmed from lazy coding or maybe it's that drupal prints out the warnings. I think that they were trying to suppress the errors with the &implode but this obviouly does not work when run inside drupal.
Comment #4
awebb commentedI just found out that apparently the publish checkbox does not work on edit either. I now must manually go into the audio node and adjust the publish settings but then the publish box still remains checked on the node that has the audio attachment. Apparently the title field and the publish checkbox don't really do anything. Any thoughts? I'm thinking about doing away with them.
Comment #5
yched commentedabout comment#3 :
&implode ?
I think the syntax for preventing warning output should be @implode...
Comment #6
awebb commentedsorry about that. my bad. It is @ not & in the write.php file.
Comment #7
Tracy Dean commentedThat works great - thanks.
Hugs
Tracy
Comment #8
awebb commentedi was wrong about the publish checkbox in comment #4. It works but I failed to see that it is only suppose to mark it publlished or unpublished on creation of the node, not on edit.
Comment #9
zirafa commentedHi, I'm maintainer of the audio_attach module. I was initially confused by this error because I couldn't think of why anyone would enable audio attachments to audio nodes. That should of course be prevented in the nodeapi code itself. Thanks to awebb for catching this error and providing some suggested fixes. I'll try the updates he's suggested and submit the code to be committed. Thanks.
Farsheed
Comment #10
drewish commentedzirafa, i've rolled awebb's changes (plus one whitespace fix) into a patch. if it looks good let me know and i'll commit it.
Comment #11
zirafa commented+1 Patch looks good. Drewish you can go ahead and commit if you'd like.
Comment #12
drewish commentedthanks awebb and zirafa, it's been committed.
Comment #13
(not verified) commented