Letting Users Upload to their folder with HTML editor (Small hack 1.7)

Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by Piotr Majewski -
Number of replies: 8
I'll bet your users would like to have opportunity to upload their own files into your Moodle. It's not normally possible with Moodle 1.7. It is possible with File Manager block, but:
  1. It's a block - not very friendly to novice users and is not working very well with blogs.
  2. There is a problem with letting everyone see your files without not user friendly manipulations (shares thing)
As long, as File Manager is useful for users to professionally manage their files, I've done a little hack to HTML editor, so that every user can upload files to his own /user/ID directory when he has no managefiles capability. He just need to click "Add image" icon in HTML editor and will see full files editor instead of simple standard one.

It works in forums and blogs for now. And it's a nice thing to course publishers - they can upload images and multimedia files that they would like to add to the description of a course.

You just have to upload 4 files into /lib/editor/htmlarea folder or if you have newer or older files, check what I changed and copy it to your files.

File:
http://www.ekademia.pl/user/file.php/7/download/userfiles_by_majewskibc.zip
(added bu user number 7 to his files smile)

Every time I've modified something in file, I've added before modification:

// modified for Ekademia.pl by MajewskiBC.pl

end after modification:

// end of modification

Except for userfiles.php which is new file made of coursefiles.php and have many but similar changes (You will find info at the beginning of the file)

TO DO:
  1. Capability to manage it better
  2. Maybe user quota
I've added this to modules DB:
http://moodle.org/mod/data/view.php?d=13&rid=1593

Have fun ;)
Peter Majewski
Ekademia.pl
Average of ratings: -
In reply to Piotr Majewski

Re: Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by shen yiching -
This function is absolutely great and helpful for students. But I can`t prevew the upload image after I install your package. Any advice will be verry appreciated!
Attachment show_image.GIF
In reply to shen yiching

Re: Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by Dan Jeffries -
Hi - this looks great!

Anyone know if it works with 1.9?

Thanks smile
In reply to Dan Jeffries

Re: Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by Kim Sihota -
I have it installed in 1.9.2 and the editor is able to upload the images to my uploaddata folder. The dir structure is uploaddata/users/userID/ images or user created folders

The problem I have is that the images do not display in the insert image dialog's preview, nor do they display on the page. I am trying to use this in the WIKI module.

The path to the image is:
""
the real path is home/mysite/uploaddata/users/6/wiki/shrooms.jpg

I assume that /user/file.php would provide the path to the moodle data folder/users

It would be great if this would work as everything else I have looked at is far too cumbersome.

If anyone knows how to fix this please let me know.

Kim

In reply to Kim Sihota

Re: Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by Shannon Morgan -
Ok I had the same issue. I removed the reference to /user/files.php for the variable called $ffurl in userfiles.php

Mine now looks like this:

if ($CFG->slasharguments) {
$ffurl = "/file.php/$id$fileurl";
} else {
$ffurl = "/file.php?file=/$id$fileurl";


Now the preview works and the images display. However, the focus for the windows is messed up. When you click on the buttonn to add the image the window is not on top. If we can figure that our we should have something that will work.

In reply to Shannon Morgan

Re: Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by Shannon Morgan -
I spoke too soon. It worked on my test site, but when I copied the files to the production server I now get no preview and no image inserted. Back to work I suppose! I would think this would be a feature that was already part of the Moodle system. I wonder would why there couldn't be an admin setting that allows this kind of feature to be enabled/disabled?
In reply to Piotr Majewski

Re: Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by Fernando Oliveira -
Picture of Plugin developers

Hi Piotr,

Thanks for this much-needed hack. Seems to work well in Moodle 1.96. Unfortunately, since it requires the "moodle/course:managefiles" capability, students are also able to edit the course files.  Not sure how to work around this, but it effectively makes this hack unusable. Any ideas on a work-around?

Thanks,

Fernando

In reply to Fernando Oliveira

Odp: Re: Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by Piotr Majewski -
Hi,

Preview not working

// $id = required_param('id', PARAM_INT);
$imageurl = required_param('imageurl', PARAM_RAW);


// if (! $course = get_record('course', 'id', $id) ) {
// error("That's an invalid course id");
// }

// require_login($course->id);
// require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id));

We commented out $id, require_login, require_capability, if (! $course

For greater security I change it to this:

$imageurl = required_param('imageurl', PARAM_RAW);
$noimage = optional_param('noimage', PARAM_INT);
 
if (!stristr($imageurl, 'user/file')) {
 
$id = required_param('id', PARAM_INT);
 
if (! $course = get_record('course', 'id', $id) ) {
error("That's an invalid course id");
}
 
require_login($course->id);
require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id));
 
}

if ($noimage == 1) {
$imagetag = clean_text(htmlSpecialChars(stripslashes_safe($imageurl)));
} else {
$imagetag = clean_text('<img src="'.htmlSpecialChars(stripslashes_safe($imageurl)).'" alt="" />');
}

If user/file - do not check capabilities. No need to.



Unfortunately, since it requires the "
moodle/course:managefiles" capability

It's not a problem: When we want enable uploading files to us folder, we have to launch:

print_textarea()

with $courseid=0 (8 param)

I think I forgot to mention this in hack files.

And then, in htmlarea.php, we have:

this._popupDialog("<?php
if(!empty($id) and has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
echo "insert_image.php?id=$id";
}

//
// modified for Ekademia.pl by MajewskiBC.pl
// in future edition we need to add some capability
// for now we just check is user is loged in and not as guest
//

else if(!empty($USER->id) && $USER->id > 1) {
echo "insert_image.php?id=0";
}

// end of modification

Best luck,
Peter


In reply to Piotr Majewski

Re: Odp: Re: Letting Users Upload to their folder with HTML editor (Small hack 1.7)

by Fernando Oliveira -
Picture of Plugin developers

Hi Peter,

Do you have an updated version of this download that includes the fixes you listed above?

Thanks,

Fernando