* @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 $courseid Course ID to pass to the file manager (defaults to global $COURSE->id).
+ * @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='', $courseid=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.
+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;
- //static $scriptcount = 0; // For loading the htmlarea script only once.
- //var_dump(unserialize($COURSE->modinfo));
$mincols = 65;
$minrows = 10;
$str = '';
$id = 'edit-'.$name;
}
- if ( empty($CFG->editorsrc) ) { // for backward compatibility.
- if (empty($courseid)) {
- $courseid = $COURSE->id;
+ if ( empty($CFG->editorsrc) && $usehtmleditor ) { // for backward compatibility.
+ if ($height && ($rows < $minrows)) {
+ $rows = $minrows;
}
-
- if ($usehtmleditor) {
-
-// if (!empty($courseid) and has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid))) {
-// $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '&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"></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;
- }
- }
+ if ($width && ($cols < $mincols)) {
+ $cols = $mincols;
}
}
echo $str;
}
-/**
- * Sets up the HTML editor on textareas in the current page.
- * If a field name is provided, then it will only be
- * applied to that field - otherwise it will be used
- * on every textarea in the page.
- *
- * In most cases no arguments need to be supplied
- *
- * @param string $name Form element to replace with HTMl editor by name
- */
-function use_html_editor($name='', $editorhidebuttons='', $id='') {
- global $THEME;
-
- $editor = 'editor_'.md5($name); //name might contain illegal characters
- if ($id === '') {
- $id = 'edit-'.$name;
- }
- echo "\n".'<script type="text/javascript" defer="defer">'."\n";
- echo '//<![CDATA['."\n\n"; // Extra \n is to fix odd wiki problem, MDL-8185
- echo "$editor = new HTMLArea('$id');\n";
- echo "var config = $editor.config;\n";
-
- echo print_editor_config($editorhidebuttons);
-
- if (empty($THEME->htmleditorpostprocess)) {
- if (empty($name)) {
- echo "\nHTMLArea.replaceAll($editor.config);\n";
- } else {
- echo "\n$editor.generate();\n";
- }
- } else {
- if (empty($name)) {
- echo "\nvar HTML_name = '';";
- } else {
- echo "\nvar HTML_name = \"$name;\"";
- }
- echo "\nvar HTML_editor = $editor;";
- }
- echo '//]]>'."\n";
- echo '</script>'."\n";
-}
-
-function print_editor_config($editorhidebuttons='', $return=false) {
- global $CFG;
-
- $str = "config.pageStyle = \"body {";
-
- if (!(empty($CFG->editorbackgroundcolor))) {
- $str .= " background-color: $CFG->editorbackgroundcolor;";
- }
-
- if (!(empty($CFG->editorfontfamily))) {
- $str .= " font-family: $CFG->editorfontfamily;";
- }
-
- if (!(empty($CFG->editorfontsize))) {
- $str .= " font-size: $CFG->editorfontsize;";
- }
-
- $str .= " }\";\n";
- $str .= "config.killWordOnPaste = ";
- $str .= (empty($CFG->editorkillword)) ? "false":"true";
- $str .= ';'."\n";
- $str .= 'config.fontname = {'."\n";
-
- $fontlist = isset($CFG->editorfontlist) ? explode(';', $CFG->editorfontlist) : array();
- $i = 1; // Counter is used to get rid of the last comma.
-
- foreach ($fontlist as $fontline) {
- if (!empty($fontline)) {
- if ($i > 1) {
- $str .= ','."\n";
- }
- list($fontkey, $fontvalue) = split(':', $fontline);
- $str .= '"'. $fontkey ."\":\t'". $fontvalue ."'";
-
- $i++;
- }
- }
- $str .= '};';
-
- if (!empty($editorhidebuttons)) {
- $str .= "\nconfig.hideSomeButtons(\" ". $editorhidebuttons ." \");\n";
- } else if (!empty($CFG->editorhidebuttons)) {
- $str .= "\nconfig.hideSomeButtons(\" ". $CFG->editorhidebuttons ." \");\n";
- }
-
- if (!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) {
- $str .= print_speller_code($CFG->htmleditor, true);
- }
-
- if ($return) {
- return $str;
- }
- echo $str;
-}
-
/**
* Returns a turn edit on/off button for course in a self contained form.
* Used to be an icon, but it's now a simple form button