images uploaded in wysiwyg editor

images uploaded in wysiwyg editor

by Laurent Picard -
Number of replies: 3

Greetings all,

is it possible to re-use images uploaded on moodle into the wysiwyg editor (with the "insert image" button)?

I tried to do some modification on the lib/rte/dlg_ins_image.html, and i have the list of uploaded files instead of the url box, but i've got an error message when i try to insert it  angry.gif

I rename this file in .php

at the begining

<?

 require_once("../../config.php");
    require_once("lib.php");

    require_login();

    global $basedir;
    global $id;

?>

line150 :

<td width="70">Url:</td><td valign="middle" colspan="3">
<? $rootdir = $CFG->dataroot."/".$course->id;
                          $coursedirs = get_directory_list($rootdir, $CFG->moddata);
                          foreach ($coursedirs as $dir) {
                              $options["$dir"] = $dir;
                          }
                          choose_from_menu ($options, "reference", $form->reference);
                        ?>

</td>

 

Any idea?

Average of ratings: -
In reply to Laurent Picard

Re: images uploaded in wysiwyg editor

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I gather that code is from the resource module. You'll have to do more here to get this working.

For example the field is probably not called "reference" within the editor, and $course and $form won't be available. Also, the $options should contain full URLs to the images,

eg: $options["$dir"] = "$CFG->wwwroot/file.php/$course->id/$dir";

In reply to Martin Dougiamas

Re: images uploaded in wysiwyg editor

by Laurent Picard -

Hi,

 

First of all, thank you for your answer , it helped me because i’m not a developer.

So, now it works, not exactly as I would like but it‘s not so bad.

 

The last problem is that there are a lot of files that are displayed in the list, even doc or xls files. Is it possible to filter this list and to display only the images files?

 

So the modifications are:

 

the lib/rte/dlg_ins_image.html file is renamed in dlg_ins_image.php.

at the beginning, insert:

<?

 require_once("../../config.php");
    require_once("lib.php");

    require_login();

    global $basedir;
    global $id;

?>

line 71 :

function insertImage() {

        window.returnValue = '<IMG' + attr("alt", alt.value) + attr("src", "http://url_of_your_web_server/moodle/file.php/"+url.value)

 

line150 :

<td width="70">Url:</td><td valign="middle" colspan="3">
<? $rootdir = $CFG->dataroot."/".$course->id;
                          $coursedirs = get_directory_list($rootdir, $CFG->moddata);
                          foreach ($coursedirs as $dir) {
                             
$options["$dir"] = "$CFG->wwwroot/file.php/$course->id/$dir";
                          }
                          choose_from_menu ($options);
                        ?>

</td>

You also have to modify rte.js (line 193-194) to link to the file dlg_ins_image.php, and to change the dimensions of the popup window.

I think there are a lot of errors in the code, but it works…
In reply to Laurent Picard

Re: images uploaded in wysiwyg editor

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Is it possible to filter this list and to display only the images files?

Yes. See how it's done in mod/quiz/question.php - search in there for "mime". You'll see one "require_once" line up near the top, and later a small loop that creates an array called $images of only image files.