Using Moodle
Using Moodle
Αναζήτηση 
Problems with the current editor? Use an alternative one!
από Dan Clarke - Monday, 26 September 2005, 09:15 PM
 

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 Xlanguage="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.

Re: Problems with the current editor? Use an alternative one!
από Dan Clarke - Monday, 26 September 2005, 09:56 PM
  Oh forgot you also need to comment out the code in the function 'function use_html_editor($name='', $editorhidebuttons='') {'
Re: Problems with the current editor? Use an alternative one!
από venkatesan iyengar - Wednesday, 28 September 2005, 12:26 PM
  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.
Re: Problems with the current editor? Use an alternative one!
από Alamir Correa - Thursday, 27 October 2005, 01:10 AM
  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
Re: Problems with the current editor? Use an alternative one!
από Alamir Correa - Friday, 28 October 2005, 05:32 AM
  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.