4 * Editor class for Moodle.
6 * This library is made to make easier to intergrate
7 * WYSIWYG editors into Moodle.
9 * @author Janne Mikkonen
11 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * @package editorObject
17 * Holds the internal $USER standard object.
23 * Holds the course id.
29 * Hold the internal $CFG standard class.
35 * PHP4 style class constructor.
39 function editorObject () {
43 $this->courseid
= NULL;
47 * PHP5 style class constructor.
50 function __construct() {
51 $this->editorObject();
55 * Method to load necessary editor codes to
56 * $CFG->editorsrc array.
59 * @param mixed $args Course id or associative array holding course id and editor name.
61 function loadeditor($args) {
65 if ( is_array($args) ) {
66 // If args is an array search keys courseid and name.
67 // Name represents editor name to load.
68 if ( !array_key_exists('courseid', $args) ) {
69 error("Required variable courseid is missing!");
72 if ( !array_key_exists('name', $args) ) {
73 error("Required variable name is missing!");
76 $courseid = clean_param($args['courseid'], PARAM_INT
);
77 $editorname = strtolower(clean_param($args['name'], PARAM_ALPHA
));
79 // If only single argument is passed
80 // this must be course id.
81 $courseid = clean_param($args, PARAM_INT
);
84 $htmleditor = !empty($editorname) ?
$editorname : intval($USER->htmleditor
);
86 if ( can_use_html_editor() ) {
87 $CFG->editorsrc
= array();
88 $editorbaseurl = $CFG->httpswwwroot
.'/lib/editor';
89 $editorbasedir = $CFG->dirroot
.'/lib/editor';
91 switch ($htmleditor) {
94 array_push($CFG->editorsrc
, "$editorbaseurl/htmlarea/htmlarea.php?id={$courseid}");
95 array_push($CFG->editorsrc
, "$editorbaseurl/htmlarea/lang/en.php");
96 $classfile = "$editorbasedir/htmlarea/htmlarea.class.php";
97 include_once($classfile);
98 return (new htmlarea($courseid));
102 array_push($CFG->editorsrc
, "$editorbaseurl/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php");
103 array_push($CFG->editorsrc
, "$editorbaseurl/tinymce/moodledialog.js");
104 $classfile = "$editorbasedir/tinymce/tinymce.class.php";
105 include_once($classfile);
106 return (new tinymce($courseid));
115 * Print out error message and stop outputting.
117 * @param string $message
119 function error($message) {
120 echo '<div style="text-align: center; font-weight: bold; color: red;">';
121 echo '<span style="color: black;">editorObject error:</span> ';
122 echo s($message, true);