File: editorlib.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (128 lines) | stat: -rw-r--r-- 3,700 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php // $Id: editorlib.php,v 1.3 2006/04/22 16:36:35 skodak Exp $

/**
 * Editor class for Moodle.
 *
 * This library is made to make easier to intergrate
 * WYSIWYG editors into Moodle.
 *
 * @author Janne Mikkonen
 * @version $Id: editorlib.php,v 1.3 2006/04/22 16:36:35 skodak Exp $
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package editorObject
 */
class editorObject {

    /**
    * Holds the internal $USER standard object.
    * @var object $user
    */
    var $user;

    /**
    * Holds the course id.
    * @var int $courseid
    */
    var $courseid;

    /**
    * Hold the internal $CFG standard class.
    * @var object $cfg
    */
    var $cfg;

    /**
    * PHP4 style class constructor.
    *
    * @uses $CFG, $USER
    */
    function editorObject () {
        global $CFG, $USER;
        $this->cfg  = &$CFG;
        $this->user = &$USER;
        $this->courseid = NULL;
    }

    /**
    * PHP5 style class constructor.
    *
    */
    function __construct() {
        $this->editorObject();
    }

    /**
    * Method to load necessary editor codes to
    * $CFG->editorsrc array.
    *
    * @todo example code.
    * @param mixed $args Course id or associative array holding course id and editor name.
    */
    function loadeditor($args) {

        global $CFG, $USER;

        if ( is_array($args) ) {
            // If args is an array search keys courseid and name.
            // Name represents editor name to load.
            if ( !array_key_exists('courseid', $args) ) {
                error("Required variable courseid is missing!");
            }

            if ( !array_key_exists('name', $args) ) {
                error("Required variable name is missing!");
            }

            $courseid   = clean_param($args['courseid'], PARAM_INT);
            $editorname = strtolower(clean_param($args['name'], PARAM_ALPHA));
        } else {
            // If only single argument is passed
            // this must be course id.
            $courseid = clean_param($args, PARAM_INT);
        }

        $htmleditor = !empty($editorname) ? $editorname : intval($USER->htmleditor);

        if ( can_use_html_editor() ) {
            $CFG->editorsrc = array();
            $editorbaseurl = $CFG->httpswwwroot .'/lib/editor';
            $editorbasedir = $CFG->dirroot .'/lib/editor';

            switch ($htmleditor) {
                case 1:
                case 'htmlarea':
                    array_push($CFG->editorsrc, "$editorbaseurl/htmlarea/htmlarea.php?id={$courseid}");
                    array_push($CFG->editorsrc, "$editorbaseurl/htmlarea/lang/en.php");
                    $classfile = "$editorbasedir/htmlarea/htmlarea.class.php";
                    include_once($classfile);
                    return (new htmlarea($courseid));
                break;
                case 2:
                case 'tinymce':
                    array_push($CFG->editorsrc, "$editorbaseurl/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php");
                    array_push($CFG->editorsrc, "$editorbaseurl/tinymce/moodledialog.js");
                    $classfile = "$editorbasedir/tinymce/tinymce.class.php";
                    include_once($classfile);
                    return (new tinymce($courseid));
                break;
            }

        }

    }

    /**
    * Print out error message and stop outputting.
    *
    * @param string $message
    */
    function error($message) {
        echo '<div style="text-align: center; font-weight: bold; color: red;">';
        echo '<span style="color: black;">editorObject error:</span> ';
        echo s($message, true);
        echo '</div>';
        exit;
    }

}
?>