Problems with the current editor? Use an alternative one!

Problems with the current editor? Use an alternative one!

by Dan Clarke -
Number of replies: 11

We've been having numerous problems with the bundled HTML-editor with Moodle (versions 1.4 and 1.5). The copy of IE installed on the majority of the machines in the college wouldn't play ball. The HTML editor was a fairly big feature for us so after much searching and testing different HTML editors I managed to get an open-source editor working.

Fortunately its VERY easy to integrate a new editor without breaking the existing editor (should you need to go back to it).

Go to: http://tinymce.moxiecode.com/download.php and download the standard version of the editor.

In the archive find the folder jscripts/tiny_mce. Extract tiny_mce to moodle/lib/editor.

Now open up moodle/lib/weblib.php, scroll down to function (roughly line 2965).
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0) {

Modify the code of this function to the following:

/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.

    global $CFG, $course;
    static $scriptcount; // For loading the htmlarea script only once.

    $mincols = 65;
    $minrows = 10;

    if (empty($courseid)) {
        if (!empty($course->id)) {  // search for it in global context
            $courseid = $course->id;
        }
    }

    if (empty($scriptcount)) {
        $scriptcount = 0;
    }

    /*if ($usehtmleditor) {

        if (!empty($courseid) and isteacher($courseid)) {
            echo ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea.php?id='. $courseid .'"></script>'."\n" : '';
        } else {
            echo ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/htmlarea.php"></script>'."\n" : '';
        }
        echo ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/lang/en.php"></script>'."\n" : '';
        $scriptcount++;

        if ($height) {    // Usually with legacy calls
            if ($rows < $minrows) {
                $rows = $minrows;
            }
        }
        if ($width) {    // Usually with legacy calls
            if ($cols < $mincols) {
                $cols = $mincols;
            }
        }
    }*/
 
 if ($usehtmleditor) {

        if (!empty($courseid) and isteacher($courseid)) {
            echo ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/tiny_mce/tiny_mce.js"></script>' . "\n" : '';
        } else {
            echo ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/tiny_mce/tiny_mce.js"></script>'."\n" : '';
        }
        //echo ($scriptcount < 1) ? '<script type="text/javascript" src="'. $CFG->wwwroot .'/lib/editor/lang/en.php"></script>'."\n" : '';
  echo '<script language="javascript" type="text/javascript">
    tinyMCE.init({
     mode : "textareas"
    });
    </script>';
        $scriptcount++;

        if ($height) {    // Usually with legacy calls
            if ($rows < $minrows) {
                $rows = $minrows;
            }
        }
        if ($width) {    // Usually with legacy calls
            if ($cols < $mincols) {
                $cols = $mincols;
            }
        }
    }

    echo '<textarea id="edit-'. $name .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">';
    p($value);
    echo '</textarea>'."\n";

Thats it! Its not fully integrated, but it will work and it works really quite well. I'm going to carry on customising it to match our requirements, but all options are fairly simple. I've commented out the changed code, so if you want to go back to the old version just uncomment that, and comment out the 'new' if statement.

Average of ratings: -
In reply to Dan Clarke

Re: Problems with the current editor? Use an alternative one!

by Dan Clarke -
Oh forgot you also need to comment out the code in the function 'function use_html_editor($name='', $editorhidebuttons='') {'
In reply to Dan Clarke

Re: Problems with the current editor? Use an alternative one!

by venkatesan iyengar -
Thanks for the tips. However, when I comment out the 'function_use_html_editor' functions, book module gives error. Of course I could correct it. However, I could not see all the buttons in the editor (as given in the example_full). Should I change any javascript?
Let me try with other modules and send the feedback later.
In reply to Dan Clarke

Re: Problems with the current editor? Use an alternative one!

by Kam Weng Chai -

Hi there,

I not good in programming shy!! I try to comment out this part but it halt.

Please guide me the full path to comment it out.

Thank you.

Wings

In reply to Kam Weng Chai

Re: Problems with the current editor? Use an alternative one!

by Mauno Korpelainen -

Those posts were over 3 years old (check the dates!) and since that moodle has had several integrations of tinymce. If you are not good in programming Glen's theme based integration might be the easiest solution to use:

http://moodle.org/mod/data/view.php?d=13&rid=1119&filter=1

Is your HTMLArea broken?

In reply to Mauno Korpelainen

Re: Problems with the current editor? Use an alternative one!

by Kam Weng Chai -

Hi  Mauno,

I only notice when lecturer report to me. Previously working fine. Only starting this month.

When try to compose notes with HTML ot HTML related page, the html toolbar not show up and all previous html formatted notes format run away.

I try to uses the matter posted here. It seem work - format OK but the toolbar not fully show out.

Any ideas?

Thanks.

Wings

In reply to Kam Weng Chai

Re: Problems with the current editor? Use an alternative one!

by Mauno Korpelainen -

Check the source code of your site (with browser) - if your HTMLArea suddenly stopped working your site may be hacked - there are several similar cases in these forums where spammers have injected config.php and/or several php files with their code.

To get more info write "hacked" to search box (top right corner of this forum) and click "Search moodle.org" button.

I suppose your site is rather old...

In reply to Mauno Korpelainen

Re: Problems with the current editor? Use an alternative one!

by Kam Weng Chai -

Hi Mauno,

OK. I will check on it. Thanks for the advise. Yes, our site bit old. Plan to upgraded it soon.

Thank you.

Wings

In reply to Mauno Korpelainen

Re: Problems with the current editor? Use an alternative one!

by Kam Weng Chai -

Hi Mauno,

I found the config file had injected with spam code. I change back and working fine. Thanks a lof for the info. We will quickly lokk to upgrade the version.

Thanks again,

Wings

In reply to Dan Clarke

Re: Problems with the current editor? Use an alternative one!

by Alamir Correa -
Hi, I tried your solution. However there is a response from server about unexpected/expected * in weblib.php. I have copied and pasted your solution but with no luck. I use tinymce in mambo and it is a good solution for different browsers.

Ah, I am using Moodle 1.5.2

Please help.

Alamir
In reply to Alamir Correa

Re: Problems with the current editor? Use an alternative one!

by Alamir Correa -
Found the glitch. Your code says at the end:
***************

    p($value);
    echo '</textarea>'."\n";
***************
It is missing the ending "}", thus it should be:

******************

    p($value);
    echo '</textarea>'."\n";
}

****************************

Voilá, it works!!!

All the best,

Alamir.