Skip to content

Commit

Permalink
MDL-14741: clean up some old code. This needs to be confirmed backwar…
Browse files Browse the repository at this point in the history
…d-compatible.
  • Loading branch information
scyrma committed Aug 29, 2008
1 parent 991c9c3 commit 88c8d16
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 135 deletions.
3 changes: 3 additions & 0 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,6 @@ function table_column($table, $oldfield, $field, $type='integer', $size='10',
error('table_column() was removed, please use new ddl functions');
}

function use_html_editor($name='', $editorhidebuttons='', $id='') {
error('use_html_editor() not available anymore');
}
2 changes: 1 addition & 1 deletion lib/form/htmleditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function toHtml(){
$this->_options['height'],
$this->getName(),
preg_replace("/(\r\n|\n|\r)/", '
',$this->getValue()),
$this->_options['course'],
0, // unused anymore
true,
$this->getAttribute('id'));
}
Expand Down
143 changes: 9 additions & 134 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4809,19 +4809,17 @@ function print_recent_activity_note($time, $user, $text, $link, $return=false, $
* @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 = '';
Expand All @@ -4830,38 +4828,12 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
$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) ? '' : '&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"></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;
}
}

Expand Down Expand Up @@ -4909,103 +4881,6 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
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
Expand Down

0 comments on commit 88c8d16

Please sign in to comment.