示例#1
0
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value = '', $courseid = 0, $return = false, $id = '')
{
    global $CFG, $COURSE, $HTTPSPAGEREQUIRED;
    $str = '';
    if ($id === '') {
        $id = 'edit-' . $name;
    }
    if (empty($courseid)) {
        $courseid = $COURSE->id;
    }
    if ($usehtmleditor) {
        $str .= '<textarea class="form-textarea" id="' . $id . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">';
        $str .= htmlspecialchars($value);
        $str .= '</textarea><br />' . "\n";
        $toggle_ed = '<img width="50" height="17" src="' . $CFG->wwwroot . '/lib/editor/tinymce/images/toggle.gif" alt="' . get_string('toggleeditor', 'editor') . '" title="' . get_string('toggleeditor', 'editor') . '" />';
        $str .= "<a href=\"javascript:toggleEditor('" . $id . "');\">" . $toggle_ed . "</a> ";
        $str .= '<script type="text/javascript">
            document.write(\'' . addslashes_js(editorshortcutshelpbutton()) . '\');
        </script>';
    } else {
        $str .= '<textarea class="alltext" id="' . $id . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">';
        $str .= s($value);
        $str .= '</textarea>' . "\n";
    }
    if ($return) {
        return $str;
    }
    echo $str;
}
示例#2
0
/**
 * Prints a basic textarea field.
 *
 * When using this function, you should
 *
 * @uses $CFG
 * @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.
 * @param string $editorclass CSS classes to add to the textarea element when using the htmleditor. Use 'form-textarea-simple' to get a basic editor. Defaults to 'form-textarea-advanced' (complete editor). If this is null or invalid, the htmleditor will not show for this field.
 */
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value = '', $obsolete = 0, $return = false, $id = '', $editorclass = 'form-textarea-advanced')
{
    /// $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, $HTTPSPAGEREQUIRED, $THEME;
    $mincols = 65;
    $minrows = 10;
    $str = '';
    if ($id === '') {
        $id = 'edit-' . $name;
    }
    if (empty($CFG->editorsrc) && $usehtmleditor) {
        // for backward compatibility.
        if ($height && $rows < $minrows) {
            $rows = $minrows;
        }
        if ($width && $cols < $mincols) {
            $cols = $mincols;
        }
    }
    if ($usehtmleditor) {
        $THEME->htmleditors[] = $id;
    } else {
        $editorclass = '';
    }
    $str .= "\n" . '<textarea class="form-textarea ' . $editorclass . '" 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 ($usehtmleditor) {
        require_once "{$CFG->dirroot}/repository/lib.php";
        $str_toggle = '<span class="helplink"><a href="javascript:mce_toggleEditor(\'' . $id . '\');"><img width="50" height="17" src="' . $CFG->httpswwwroot . '/lib/editor/tinymce/images/toggle.gif" alt="' . get_string('editortoggle') . '" title="' . get_string('editortoggle') . '" class="icontoggle" /></a></span>';
        // Show shortcuts button if HTML editor is in use, but only if JavaScript is enabled (MDL-9556)
        if (empty($COURSE->context)) {
            $ctx = get_context_instance(CONTEXT_SYSTEM);
        } else {
            $ctx = $COURSE->context;
        }
        $client_id = uniqid();
        $ret = repository_get_client($ctx, $client_id, array('image', 'video', 'media'), '*');
        $str .= $ret['css'] . $ret['js'];
        $str .= '<div class="textareaicons">';
        $str .= '<script type="text/javascript">
//<![CDATA[
id2clientid[\'' . $id . '\']=\'' . $client_id . '\';
mce_saveOnSubmit(\'' . addslashes_js($id) . '\');
document.write(\'' . addslashes_js($str_toggle) . '\');
document.write(\'' . addslashes_js(editorshortcutshelpbutton()) . '\');
//]]>
</script>';
        $str .= '</div>';
    }
    if ($return) {
        return $str;
    }
    echo $str;
}
示例#3
0
/**
 * Prints a basic textarea field.
 *
 * @uses $CFG
 * @param boolean $usehtmleditor ?
 * @param int $rows ?
 * @param int $cols ?
 * @param null $width <b>Legacy field no longer used!</b>  Set to zero to get control over mincols
 * @param null $height <b>Legacy field no longer used!</b>  Set to zero to get control over minrows
 * @param string $name ?
 * @param string $value ?
 * @param int $courseid ?
 * @todo Finish documenting this function
 */
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value = '', $courseid = 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.
    global $CFG, $COURSE, $HTTPSPAGEREQUIRED;
    static $scriptcount = 0;
    // For loading the htmlarea script only once.
    $mincols = 65;
    $minrows = 10;
    $str = '';
    if ($id === '') {
        $id = 'edit-' . $name;
    }
    if (empty($CFG->editorsrc)) {
        // for backward compatibility.
        if (empty($courseid)) {
            $courseid = $COURSE->id;
        }
        if ($usehtmleditor) {
            if (!empty($courseid) and has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid))) {
                $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '&amp;httpsrequired=1';
                // needed for course file area browsing in image insert plugin
                $str .= $scriptcount < 1 ? '<script type="text/javascript" src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/htmlarea.php?id=' . $courseid . $httpsrequired . '"></script>' . "\n" : '';
            } else {
                $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '?httpsrequired=1';
                $str .= $scriptcount < 1 ? '<script type="text/javascript" src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/htmlarea.php' . $httpsrequired . '"></script>' . "\n" : '';
            }
            $str .= $scriptcount < 1 ? '<script type="text/javascript" src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/lang/en.php?id=' . $courseid . '"></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;
                }
            }
        }
    }
    $str .= '<textarea class="form-textarea" id="' . $id . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">';
    if ($usehtmleditor) {
        $str .= htmlspecialchars($value);
        // needed for editing of cleaned text!
    } else {
        $str .= s($value);
    }
    $str .= '</textarea>' . "\n";
    if ($usehtmleditor) {
        // Show shortcuts button if HTML editor is in use, but only if JavaScript is enabled (MDL-9556)
        $str .= '<script type="text/javascript">
//<![CDATA[
document.write(\'' . addslashes_js(editorshortcutshelpbutton()) . '\');
//]]>
</script>';
    }
    if ($return) {
        return $str;
    }
    echo $str;
}