Use $this->error for only error report
[moodle-linuxchix.git] / lib / editorlib.php
blob439792b6a48b9da8a2725c6796e67eba75b389db
1 <?php // $Id$
3 /**
4 * Editor class for Moodle.
6 * This library is made to make easier to intergrate
7 * WYSIWYG editors into Moodle.
9 * @author Janne Mikkonen
10 * @version $Id$
11 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * @package editorObject
14 class editorObject {
16 /**
17 * Holds the internal $USER standard object.
18 * @var object $user
20 var $user;
22 /**
23 * Holds the course id.
24 * @var int $courseid
26 var $courseid;
28 /**
29 * Hold the internal $CFG standard class.
30 * @var object $cfg
32 var $cfg;
34 /**
35 * PHP4 style class constructor.
37 * @uses $CFG, $USER
39 function editorObject () {
40 global $CFG, $USER;
41 $this->cfg = &$CFG;
42 $this->user = &$USER;
43 $this->courseid = NULL;
46 /**
47 * PHP5 style class constructor.
50 function __construct() {
51 $this->editorObject();
54 /**
55 * Method to load necessary editor codes to
56 * $CFG->editorsrc array.
58 * @todo example code.
59 * @param mixed $args Course id or associative array holding course id and editor name.
61 function loadeditor($args) {
63 global $CFG, $USER;
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));
78 } else {
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) {
92 case 1:
93 case 'htmlarea':
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));
99 break;
100 case 2:
101 case 'tinymce':
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));
107 break;
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);
123 echo '</div>';
124 exit;