Example #1
0
 /**
  * Returns an XHTML string for the editor
  *
  * @param string $data
  * @param string $query
  * @return string XHTML string for the editor
  */
 public function output_html($data, $query = '')
 {
     $default = $this->get_defaultsetting();
     $defaultinfo = $default;
     if (!is_null($default) and $default !== '') {
         $defaultinfo = "\n" . $default;
     }
     $editor = get_preferred_texteditor(FORMAT_HTML);
     $editor->use_editor($this->get_id(), array('noclean' => true));
     return format_admin_setting($this, $this->visiblename, '<div class="form-textarea"><textarea rows="' . $this->rows . '" cols="' . $this->cols . '" id="' . $this->get_id() . '" name="' . $this->get_full_name() . '">' . s($data) . '</textarea></div>', $this->description, true, '', $defaultinfo, $query);
 }
Example #2
0
 /**
  * @see lib/moodle_html_component#prepare()
  * @return void
  */
 public function prepare()
 {
     $this->add_class('form-textarea');
     if (empty($this->id)) {
         $this->id = "edit-{$this->name}";
     }
     if ($this->usehtmleditor) {
         editors_head_setup();
         $editor = get_preferred_texteditor(FORMAT_HTML);
         $editor->use_editor($this->id, array('legacy' => true));
         $this->value = htmlspecialchars($value);
     }
     parent::prepare();
 }
Example #3
0
 function toHtml()
 {
     global $CFG, $COURSE, $PAGE;
     if ($this->_flagFrozen) {
         return $this->getFrozenHtml();
     }
     $id = $this->_attributes['id'];
     $elname = $this->_attributes['name'];
     $subdirs = $this->_options['subdirs'];
     $maxbytes = $this->_options['maxbytes'];
     $maxfiles = $this->_options['maxfiles'];
     $changeformat = $this->_options['changeformat'];
     // TO DO: implement as ajax calls
     $text = $this->_values['text'];
     $format = $this->_values['format'];
     $draftitemid = $this->_values['itemid'];
     // security - never ever allow guest/not logged in user to upload anything
     if (isguestuser() or !isloggedin()) {
         $maxfiles = 0;
     }
     $str = $this->_getTabs();
     $str .= '<div>';
     $editor = get_preferred_texteditor($format);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     /// print text area - TODO: add on-the-fly switching, size configuration, etc.
     $editor->use_editor($id, $this->_options);
     $ctx = $this->_options['context'];
     $str .= '<div><textarea id="' . $id . '" name="' . $elname . '[text]" rows="15" cols="80">';
     $str .= s($text);
     $str .= '</textarea></div>';
     $str .= '<div>';
     $str .= '<select name="' . $elname . '[format]">';
     foreach ($formats as $key => $desc) {
         $selected = $format == $key ? 'selected="selected"' : '';
         $str .= '<option value="' . s($key) . '" ' . $selected . '>' . $desc . '</option>';
     }
     $str .= '</select>';
     $str .= '</div>';
     if ($maxfiles != 0) {
         // 0 means no files, -1 unlimited
         if (empty($draftitemid)) {
             // no existing area info provided - let's use fresh new draft area
             require_once "{$CFG->libdir}/filelib.php";
             $this->setValue(array('itemid' => file_get_unused_draft_itemid()));
             $draftitemid = $this->_values['itemid'];
         }
         $str .= '<div><input type="hidden" name="' . $elname . '[itemid]" value="' . $draftitemid . '" /></div>';
         /// embedded image files - TODO: hide on the fly when switching editors
         $str .= '<div id="' . $id . '_filemanager">';
         $editorurl = "{$CFG->wwwroot}/repository/filepicker.php?action=embedded&amp;itemid={$draftitemid}&amp;subdirs={$subdirs}&amp;maxbytes={$maxbytes}&amp;ctx_id=" . $ctx->id;
         $str .= '<object type="text/html" data="' . $editorurl . '" height="160" width="600" style="border:1px solid #000">Error</object>';
         // TODO: localise, fix styles, etc.
         $str .= '</div>';
         require_once $CFG->dirroot . '/repository/lib.php';
         $client_id = uniqid();
         $repojs = repository_get_client($ctx, $client_id, array('image', 'video', 'media'), '*');
         $str .= $repojs;
         $str .= $PAGE->requires->js_function_call('id2_add_clientid', array($id, $client_id))->asap();
         $str .= $PAGE->requires->js_function_call('id2_add_itemid', array($id, $draftitemid))->asap();
         if ($editor->supports_repositories()) {
             $str .= $PAGE->requires->js_function_call('hide_item', array("{$id}_filemanager"))->asap();
         }
     }
     $str .= '</div>';
     return $str;
 }
Example #4
0
/**
 * Prints a basic textarea field.
 *
 * @deprecated since Moodle 2.0
 *
 * When using this function, you should
 *
 * @global object
 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
 * @param int $rows Number of rows to display  (minimum of 10 when $height is non-null)
 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
 * @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
 * @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored.
 * @param string $name Name to use for the textarea element.
 * @param string $value Initial content to display in the textarea.
 * @param int $obsolete deprecated
 * @param bool $return If false, will output string. If true, will return string value.
 * @param string $id CSS ID to add to the textarea element.
 * @return string|void depending on the value of $return
 */
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value = '', $obsolete = 0, $return = false, $id = '')
{
    /// $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.
    debugging('print_textarea() has been deprecated. Please change your code to use $OUTPUT->textarea().');
    global $CFG;
    $mincols = 65;
    $minrows = 10;
    $str = '';
    if ($id === '') {
        $id = 'edit-' . $name;
    }
    if ($usehtmleditor) {
        if ($height && $rows < $minrows) {
            $rows = $minrows;
        }
        if ($width && $cols < $mincols) {
            $cols = $mincols;
        }
    }
    if ($usehtmleditor) {
        editors_head_setup();
        $editor = get_preferred_texteditor(FORMAT_HTML);
        $editor->use_editor($id, array('legacy' => true));
    } else {
        $editorclass = '';
    }
    $str .= "\n" . '<textarea class="form-textarea" id="' . $id . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . "\n";
    if ($usehtmleditor) {
        $str .= htmlspecialchars($value);
        // needed for editing of cleaned text!
    } else {
        $str .= s($value);
    }
    $str .= '</textarea>' . "\n";
    if ($return) {
        return $str;
    }
    echo $str;
}