diff --git a/lib/weblib.php b/lib/weblib.php index 1b5ae6a39fa..d4f06e90175 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3014,7 +3014,7 @@ function print_recent_activity_note($time, $user, $isteacher, $text, $link) { * @param int $courseid ? * @todo Finish documenting this function */ -function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0) { +function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $courseid=0, $return=false) { /// $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. @@ -3037,11 +3037,11 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v if ($usehtmleditor) { if (!empty($courseid) and isteacher($courseid)) { - echo ($scriptcount < 1) ? ''."\n" : ''; + $str = ($scriptcount < 1) ? ''."\n" : ''; } else { - echo ($scriptcount < 1) ? ''."\n" : ''; + $str = ($scriptcount < 1) ? ''."\n" : ''; } - echo ($scriptcount < 1) ? ''."\n" : ''; + $str .= ($scriptcount < 1) ? ''."\n" : ''; $scriptcount++; if ($height) { // Usually with legacy calls @@ -3056,13 +3056,18 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v } } - echo ''."\n"; + $str .= ''."\n"; + + if ($return) { + return $str; + } + echo $str; } /** @@ -3089,15 +3094,74 @@ function print_richedit_javascript($form, $name, $source='no') { */ function use_html_editor($name='', $editorhidebuttons='') { echo ''."\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($usehtmleditor=true, 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 @@ -4180,64 +4244,6 @@ function print_side_block_end($attributes) { } - -/** - * Prints out the HTML editor config. - * - * @uses $CFG - */ - function print_editor_config($editorhidebuttons='') { - - global $CFG; - - // print new config - echo 'var config = new HTMLArea.Config();'."\n"; - echo "config.pageStyle = \"body {"; - if(!(empty($CFG->editorbackgroundcolor))) { - echo " background-color: $CFG->editorbackgroundcolor;"; - } - - if(!(empty($CFG->editorfontfamily))) { - echo " font-family: $CFG->editorfontfamily;"; - } - - if(!(empty($CFG->editorfontsize))) { - echo " font-size: $CFG->editorfontsize;"; - } - - echo " }\";\n"; - echo "config.killWordOnPaste = "; - echo(empty($CFG->editorkillword)) ? "false":"true"; - echo ';'."\n"; - echo '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) { - echo ','."\n"; - } - list($fontkey, $fontvalue) = split(':', $fontline); - echo '"'. $fontkey ."\":\t'". $fontvalue ."'"; - - $i++; - } - } - echo '};'; - - if (!empty($editorhidebuttons)) { - echo "\nconfig.hideSomeButtons(\" ". $editorhidebuttons ." \");\n"; - } else if (!empty($CFG->editorhidebuttons)) { - echo "\nconfig.hideSomeButtons(\" ". $CFG->editorhidebuttons ." \");\n"; - } - - if(!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) { - print_speller_code($usehtmleditor=true); - } -} - /** * Prints out code needed for spellchecking. * Original idea by Ludo (Marc Alier).