Images in Moodle 2.0 (In Lessons, as of now)

Images in Moodle 2.0 (In Lessons, as of now)

by Matt Fedorko -
Number of replies: 14

This might not belong here -- HTML Editor forum, maybe?

We are just now figuring out how to handle images in Moodle 2.0 (we used to use a dedicated file structure kind of thing). I told my instructor that I think the way things should work now is to just insert the image into the pages of the Lessons. He did so yesterday.

Today we come back and all of the images he inserted are broken links. It has saved the sizing, but the link to the image is no longer valid. I would be happy to post screenshots, but really it just looks like a broken image link -- red X in a empty block.

I have not been able to replicate it, though I have placed an image in a Lesson in some hidden corners, and will come back later to see if they are broken after some period of time.

Anyone have any idea what could be causing this?

Average of ratings: -
In reply to Matt Fedorko

Re: Images in Moodle 2.0 (In Lessons, as of now)

by ben reynolds -

Hi Matt,

When you say "insert the image into the pages," do you mean just paste the image into the html editor? Or, do you mean upload the image using the insert image button?

You can right click on the missing image and some browsers will let you copy the link location, which might tell you a lot about what's wrong.

In reply to ben reynolds

Re: Images in Moodle 2.0 (In Lessons, as of now)

by Matt Fedorko -

We are using the "Insert image" button.

Here's a URL for a "broken" picture:

http://---outwebsite----.org/classroom/draftfile.php?file=%2F140%2Fuser%2Fdraft%2F161369980%2FTrusses.jpg

Here's a URL for a picture I just inserted beside the broken picture, that is currently displaying:

http://--ourwebsite-----.org/classroom/draftfile.php?file=%2F137%2Fuser%2Fdraft%2F598076586%2Fdc%20vs%20ac%20copy.jpg

In reply to Matt Fedorko

Re: Images in Moodle 2.0 (In Lessons, as of now)

by Matt Fedorko -

Let me first say something.

This instructor who just lost his images was having this problem:

http://moodle.org/mod/forum/discuss.php?d=165666

We could not figure out what was going on, as the problem was not repeatable unless you logged into his account. My last ditch way of fixing this problem was to DELETE his account and RECREATE it again. As of right now, he can now see the menus just fine.

However, did deleting his account create the problem he's experienced here -- that the images are now broken? I thought when you uploaded images they became part of the Lesson or page or whatever, and weren't necessarily connected to who uploaded them.

Thoughts?

In reply to Matt Fedorko

Re: Images in Moodle 2.0 (In Lessons, as of now)

by ben reynolds -

Hi Matt,

I spent some time playing on the Moodle 2.0 demo site today. http://school.demo.moodle.net/

I built a lesson and inserted pictures. The URLs for the pictures looked like this. I'm inserting an image because, for unknown reasons, the actual URL doesn't show up when posted.

Moodle Graphics URLS from 2.0 Demo

Those %20 = a space in file name. Notice that the images belong to the lesson mod_lesson/page_contents

Your URLs have /user/ in them. Again, I don't know the 2.0 filepicker system, but that /user/ says to me they may be private files. If they're private files they won't be available to the public.

In reply to ben reynolds

Re: Images in Moodle 2.0 (In Lessons, as of now)

by Matt Fedorko -

Which tells me there's a bug! Hahaha...

They can't be private files, or aren't supposed to be private files. Inserting Images is how you build a page, pages are supposed to be public, therefore, images inserted into pages should be public, right? Gotta be a bug!

In reply to Matt Fedorko

Re: Images in Moodle 2.0 (In Lessons, as of now)

by ben reynolds -

I think you're right Matt. Google turned up http://docs.moodle.org/en/Development:Repository_API which refers, in "Case 3: As part of a HTML editor," to "1. The moodleform for a textarea (HTML editor) will require a path to the filearea associated with this HTML. eg wwwroot/pluginfile.php/13/content/0/. This would have to be the user_draft area if the filearea doesn't exist yet eg wwwroot/draftfile.php/userid/tempfile/uniquelementid"

Looks to me like the images aren't really getting out of the draft file state, but that's way more than I know smile

In reply to Matt Fedorko

Re: Images in Moodle 2.0 (In Lessons, as of now)

by ben reynolds -

You are the second or third person using 2.0 having this problem today. Sorry to say I'm not using 2.0 at this point, and it has a totally different file system from 1.9+.

I am wondering why Moodle feels the need to change the / into %2F halfway through the file path. But this is so far out of my area of expertise. Sorry.

In reply to ben reynolds

Re: Images in Moodle 2.0 (In Lessons, as of now)

by Matt Fedorko -

You are right, Ben, that this is the same problem. I didn't think it was because of what I did with the teacher's account, but I see now that I was wrong. I will be monitoring the discussion here from now on:

http://moodle.org/mod/forum/discuss.php?d=165467

In reply to Matt Fedorko

Re: Images in Moodle 2.0 (In Lessons, as of now)

by Mike Holzer -

It looks like there's a bug in the editor when the system has slasharguments disabled. I was able to recreate the problem on my local system that was working before I disabled slasharguments.

It's supposed to be replacing the "draftfile.php?file=%2F170%2Fuser%2Fdraft%2F113943279%2F/filename" with "@@PLUGINFILE@@" but it doesn't appear to actually be doing it.

If you look at file_save_draft_area_files() in /lib/filelib.php you can see the replacement at the bottom of the function. Could the $draftbase string be wrong?

In reply to Mike Holzer

Re: Images in Moodle 2.0 (In Lessons, as of now)

by Mike Holzer -

AFAIK, this bug is actually only occuring if the slasharguments paramter is disabled.

Alright, so the problem lies in the fact that when you first upload the file, the filepath is url encoded (that's what the %2F is). When it goes to save the content of the section, it attampts to swap out the "draft file" url for @@PLUGINFILE@@. Because the filepath doesn't match the draft file url, the encoded filepath gets saved in the DB and is returned any time the page is loaded.

Using the hack below will correct for all future inserts. You'll either have to manually redo all your existing images or change the URLs of the images in the DB.

 

Hack to Fix:

In /lib/filelib.php go to file_save_draft_area_files(). Go to the bottom of the function. Find the line that begins  $text = str_ireplace($draftbase,...) (somewhere around line 727 in Moodle 2.0.1)

Add the following line immediately above that line:
$text = str_ireplace('%2F', '/', $text);

Save the file and add your images! Remember, previously saved images will either have to be manually swapped out in your sections or updated in the database.

In reply to Mike Holzer

Re: Images in Moodle 2.0 (In Lessons, as of now)

by James Snell -

I tried toggling my slasharguments parameter and re-uploading the images on Moodle 2.0.1 - it didn't have any effect. The URLs were the same.

I did apply your hack and everything seems correct now.

Maybe the slasharguments parameter doesn't effect my install as it was upgraded originally from something like 1.9.8 (give or take a minor version), to 2.0.0 RC1 to 2.0.0 to 2.0.1

Anyway, thanks for the code snippet, you're awesome chief!

In reply to Mike Holzer

Re: Images in Moodle 2.0 (In Lessons, as of now)

by Katie Fraser -

Hi Mike!

Over the past few months I've been developing an online course and building a number of lessons in Moodle 2.0 using internet explorer.  For whatever reason, yesterday, some of my images stopped displaying in the lesson. I think I might be having the same problem as discussed as this thread, though I'm not certain because:

1) I have slash arguments enabled (I think you stated this only happens if disabled?

2) Pictures that are no longer appearing do NOT work in admin  OR in student (I think others said they could still see in admin?...)

I did notice that when I click on properties on the images that don't appear it sites "draftfile" whereas the images that do appear site "pluginfile" in their address.

Do you think this hack could still work for me?  And if so, what do you mean by "previously saved images will either have to be manually swapped out in your sections or updated in the database" --- How do I update them in the database??  And do the pictures that ARE visable have to be updated or swapped out too?

Hoping you can help me once again with this one !! Thanks in advance --