If you choose HTML as insert mode when trying to add an image and press Insert you will get the front page in the popup window and no image is inserted in the textarea. (At least when using img_assist as a standalone module – without TinyMCE.)

Comments

moonray’s picture

Assigned: Unassigned » moonray
Status: Active » Needs review
StatusFileSize
new2.41 KB

Patch attached to fix this issue.

mlsamuelson’s picture

I've tested the patch and it solves the issue.

Thanks for the fix, Moonray!

mlsamuelson

darren oh’s picture

Status: Needs review » Reviewed & tested by the community

That's a review.

mlsamuelson’s picture

Thanks for pointing that out. I think I've done a few reviews without changing the status today. I'm just getting the hang of reviewing patches. Will pay more attention to setting the status. (Didn't know I had the authority to do that.)

mlsamuelson

zoo33’s picture

I'll take a look at this as soon as possible.

mariagwyn’s picture

I am having the same problem (insert bumps to front page in html mode). I tried to apply the patch, but I keep getting the error:

patch unexpectedly ends in middle of line.  
patch: ****only garbage was found in the patch input.

This is what I typed in terminal (I am a bit of a patch noob), from the img_assist folder where I uploaded the patch:
patch < img-assist.patch
I tried it multiple times, I even took out the long line of *** at the bottom. Any suggestions? I would love it to work b/c I use img_assist all the time!

Thanks,
Maria

mariagwyn’s picture

I decided to apply the patch manually, and it appears to fix the error. Thank you!
Maria

zoo33’s picture

That's wierd – it doesn't work for me! Patch applies successfully but there's no change in the behavior.

I'm curious – what's the reasoning behind changing $edit to $edited? And where is that variable (which is passed as an invisible form field) picked up and used? My guess is it's supposed to tell whether or not the user is currently adding or editing an image to the post. On line 991 is a variable called $update which is not defined anywhere – maybe that's actually supposed to be $edit? But I don't think that solves this particular issue.

zoo33’s picture

Status: Reviewed & tested by the community » Needs review

Oops, it does work. I wasn't patching the same copy as I was testing....

My questions remain though. I'm not really comfortable with committing this since I'm not sure why it works... My first guess was that the actual fix was the addition of the form builder function img_assist_insert_html_form, but it doesn't seem to work if I keep the variable named $edit...

mariagwyn’s picture

I do not do code, but since I manually patched this, I noticed that most of the changes were from 'edit' to 'edited' (which struck me as odd). However, the last two changes (lines 1023 and 1031) appear to move the output up the page, under a different function, with this difference: 'img_assist_insert_html', $form is now 'img_assist_insert_html_form'. Maybe that is the key change?

zoo33’s picture

Yes, that's what I thought, but the $edit > $edited changes are also required.

moonray’s picture

The reason I had to change it from $form['edit'] to $form['edited'] is because, even though MOST of drupal code got rewritten to use $_POST as the form variables array instead of $_POST['edit'], it still checks for $_POST['edit'] to see if it exist in the drupal_goto() function (common.inc). Now, in 4.7 our local form variable used to be $form['edit']['edit'], which was fine. Now, in 5, where $form['edit'] got dropped (and residual old code still exists) drupal gets confused.

In short, there was a conflict in variable names.

See common.inc, lines 299-304

  if (isset($_REQUEST['destination'])) {
    extract(parse_url(urldecode($_REQUEST['destination'])));
  }
  else if (isset($_REQUEST['edit']['destination'])) {
    extract(parse_url(urldecode($_REQUEST['edit']['destination'])));
  }

Somehow, the else part resolves to true, which overrides the destination to '', sending us to the front page of our drupal site.

moonray’s picture

In the above post I used $form and $_POST interchangeably, which is not entirely correct. Read it all as $_POST (instead of $form) and it should make sense (I think... urgh... too... early!)

Leming15’s picture

Hi!
I have problems with patching the file, can you please write how should i do that or attach the allready patched module file.
thanks!

Leming15
www.excondo.com

zoo33’s picture

StatusFileSize
new5.53 KB

Right, i suspected it had to do with "edit" being a reserved word. Now I also figured out what the $edit variable is supposed to do. It's used in img_assist_tinymce.js to determine if it should load existing values of previously added images into the properties form. There was also the mysterious variable $update in img_assist_properties_form() which is probably supposed to have the same value as $edit (it controls whether the submit button should be named Insert or Update).

So, the variable $edit has to be renamed. I thought "edited" wasn't very accurate, since the form is supposed to edit the image – it's not edited yet. So i took the $update variable and used that name consistently instead.

Also, when I looked at img_assist_tinymce.js I found some remaining 'edit[xxxx]' that I renamed to 'edit-xxxx' which will possibly make Image assist work with TinyMCE, although I haven't tested it. There, I've broken the don't-do-more-than-one-thing-in-each-patch rule again!

Please take a look at the attached patch and try it out! Comments are welcome.

moonray’s picture

Status: Needs review » Needs work

I applied the patch, and it seems to work properly. I don't use tinyMCE, so I can't comment on that part.

I think, actually, that edited was the correct terminology. It's false the first time the form is requested. Once you hit the Insert button, it will re-request the form, this time with $edited being true, upon which it will use javascript magic to insert it into the parent textarea.

But I leave it up to you to decide which word to use for the variable. The code works. :-)

p.s.
You can attach .patch files (no need to append .txt)

zoo33’s picture

Hm, yeah if that's the case I misunderstood what that variable is used for. But i didn't find $edit used anywhere in the code exept for img_assist_tinymce.js:

  if (formObj['edit[edit]'].value == 1) {

My understanding of what happens there is that if a user has already inserted an image with tinymce and img_assist and then hits the img_assist button again to edit the image, the $edit variable is passed through arg(3) and then as a hidden form field to img_assist_tinymce.js which populates the form with the existing values.

If $edit is picked up by a javascript like you suggest, even without tinymce, then we should be required to change "edit" to "edited" somewhere in the javascript too, right? Please point me to any other places where $edit is used and I'll take a look. Or explain to me why I'm wrong. :)

(My editor keeps adding that .txt extension all the time and I was too lazy to remove it...)

moonray’s picture

Status: Needs work » Reviewed & tested by the community

I looked through the JS and the module's code, and it looks like you are right. The edit (now update) variable isn't really used other than in the tinyMCE's JS.

When the module calls drupal_get_form, that function checks for submission, and then proceeds with handling it.

I'd say you're good to commit.

zoo33’s picture

Status: Reviewed & tested by the community » Fixed

Committed!
Thanks a lot Moonray for the fix.

I actually tested this briefly with TinyMCE (HEAD version) and that seems to work too!

Anonymous’s picture

Status: Fixed » Closed (fixed)