]> git.mjollnir.org Git - moodle.git/commitdiff
mod-data MDL-19806 Converted remaining print_textarea's to 2.0 editors.
authorSam Hemelryk <sam@moodle.com>
Wed, 23 Dec 2009 06:19:25 +0000 (06:19 +0000)
committerSam Hemelryk <sam@moodle.com>
Wed, 23 Dec 2009 06:19:25 +0000 (06:19 +0000)
mod/data/field/textarea/field.class.php
mod/data/field/textarea/mod.html
mod/data/templates.php

index e07e7a7a46ed59e54fb0d7524647908d4fec28f7..a6d3eaa44bdb5619dd9674e0750746fe37729667 100755 (executable)
 //                                                                       //
 ///////////////////////////////////////////////////////////////////////////
 
+require_once($CFG->dirroot.'/lib/filelib.php');
+require_once($CFG->dirroot.'/repository/lib.php');
+
 class data_field_textarea extends data_field_base {
 
     var $type = 'textarea';
 
     function display_add_field($recordid=0) {
-        global $CFG, $DB, $OUTPUT;
+        global $CFG, $DB, $OUTPUT, $PAGE;
 
         $text   = '';
         $format = 0;
 
-        if ($recordid){
-            if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
-                $text   = $content->content;
-                $format = $content->content1;
-            }
-        }
-
         $str = '<div title="'.$this->field->description.'">';
 
-        if (can_use_html_editor()) {
-            // Show a rich text html editor.
-            $str .= $this->gen_textarea(true, $text);
-            $str .= $OUTPUT->help_icon(moodle_help_icon::make("richtext2", get_string("helprichtext"), 'moodle', true));
-            $str .= '<input type="hidden" name="field_' . $this->field->id . '_content1' . '" value="' . FORMAT_HTML . '" />';
-
+        editors_head_setup();
+
+        $options = array();
+        $options['trusttext'] = false;
+        $options['forcehttps'] = false;
+        $options['subdirs'] = false;
+        $options['maxfiles'] = 0;
+        $options['maxbytes'] = 0;
+        $options['changeformat'] = 0;
+        $options['noclean'] = false;
+
+        $itemid = $this->field->id;
+        $field = 'field_'.$itemid;
+
+        if ($recordid && $content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))){
+            $text   = $content->content;
+            $format = $content->content1;
+        } else if (can_use_html_editor()) {
+            $format = FORMAT_HTML;
         } else {
-            // Show a normal textarea. Also let the user specify the format to be used.
-            $str .= $this->gen_textarea(false, $text);
-
-            // Get the available text formats for this field.
-            $formatsForField = format_text_menu();
-            $str .= '<br />';
-            $select = html_select( $formatsForField, 'field_' . $this->field->id . '_content1', $format);
-            $select->nothingvalue = '';
-            $str .= $OUTPUT->select($select);
+            $format = FORMAT_PLAIN;
+        }
 
-            $str .= $OUTPUT->help_icon(moodle_help_icon::make('textformat', get_string('helpformatting'), 'moodle'));
+        $editor = get_preferred_texteditor($format);
+        $strformats = format_text_menu();
+        $formats =  $editor->get_supported_formats();
+        foreach ($formats as $fid) {
+            $formats[$fid] = $strformats[$fid];
         }
+        $editor->use_editor($field, $options);
+        $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="15" cols="80">'.s($text).'</textarea></div>';
+        $str .= '<div><select name="'.$field.'_content1">';
+        foreach ($formats as $key=>$desc) {
+            $selected = ($format == $key) ? 'selected="selected"' : '';
+            $str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>';
+        }
+        $str .= '</select>';
+        $str .= $OUTPUT->help_icon(moodle_help_icon::make('textformat', get_string('helpformatting'), 'moodle'));
+        $str .= '</div>';
+
         $str .= '</div>';
         return $str;
     }
@@ -83,12 +100,6 @@ class data_field_textarea extends data_field_base {
         return array(" ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content $ILIKE :$name) ", array($name=>"%$value%"));
     }
 
-    function gen_textarea($usehtmleditor, $text='') {
-        return print_textarea($usehtmleditor, $this->field->param3, $this->field->param2,
-                              '', '', 'field_'.$this->field->id, $text, '', true, 'field_' . $this->field->id);
-    }
-
-
     function print_after_form() {
     }
 
index abe706dbce7d6a6493ca65ac13814c4e768ac6b5..c53a69a5eaf004f1ee52ef84a01ca74789ed4e00 100755 (executable)
@@ -39,3 +39,4 @@
         </td>
     </tr>
 </table>
+<input type="hidden" name="param4" id="param4" value="<?php echo FORMAT_HTML; ?>" />
index 21214c43d7856384502b903cac07c579546fd280..b486af70a3f57f632c41014a544b73e3994852f9 100755 (executable)
@@ -151,6 +151,22 @@ if (empty($data->addtemplate) and empty($data->singletemplate) and
     data_generate_default_template($data, 'rsstemplate');
 }
 
+editors_head_setup();
+$format = FORMAT_HTML;
+$editor = get_preferred_texteditor($format);
+$strformats = format_text_menu();
+$formats =  $editor->get_supported_formats();
+foreach ($formats as $fid) {
+    $formats[$fid] = $strformats[$fid];
+}
+$options = array();
+$options['trusttext'] = false;
+$options['forcehttps'] = false;
+$options['subdirs'] = false;
+$options['maxfiles'] = 0;
+$options['maxbytes'] = 0;
+$options['changeformat'] = 0;
+$options['noclean'] = false;
 
 echo '<form id="tempform" action="templates.php?d='.$data->id.'&amp;mode='.$mode.'" method="post">';
 echo '<div>';
@@ -172,7 +188,11 @@ if ($mode == 'listtemplate'){
     echo '<td>&nbsp;</td>';
     echo '<td>';
     echo '<div style="text-align:center"><label for="edit-listtemplateheader">'.get_string('header','data').'</label></div>';
-    print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplateheader', $data->listtemplateheader);
+
+    $field = 'listtemplateheader';
+    $editor->use_editor($field, $options);
+    echo '<div><textarea id="'.$field.'" name="'.$field.'" rows="15" cols="80">'.s($data->listtemplateheader).'</textarea></div>';
+
     echo '</td>';
     echo '</tr>';
 }
@@ -263,7 +283,9 @@ if ($mode == 'listtemplate'){
     echo '<div style="text-align:center"><label for="edit-template">'.get_string($mode,'data').'</label></div>';
 }
 
-print_textarea($usehtmleditor, 20, 72, 0, 0, 'template', $data->{$mode});
+$field = 'template';
+$editor->use_editor($field, $options);
+echo '<div><textarea id="'.$field.'" name="'.$field.'" rows="15" cols="80">'.s($data->{$mode}).'</textarea></div>';
 echo '</td>';
 echo '</tr>';
 
@@ -272,7 +294,10 @@ if ($mode == 'listtemplate'){
     echo '<td>&nbsp;</td>';
     echo '<td>';
     echo '<div style="text-align:center"><label for="edit-listtemplatefooter">'.get_string('footer','data').'</label></div>';
-    print_textarea($usehtmleditor, 10, 72, 0, 0, 'listtemplatefooter', $data->listtemplatefooter);
+
+    $field = 'listtemplatefooter';
+    $editor->use_editor($field, $options);
+    echo '<div><textarea id="'.$field.'" name="'.$field.'" rows="15" cols="80">'.s($data->listtemplatefooter).'</textarea></div>';
     echo '</td>';
     echo '</tr>';
 } else if ($mode == 'rsstemplate') {
@@ -280,7 +305,10 @@ if ($mode == 'listtemplate'){
     echo '<td>&nbsp;</td>';
     echo '<td>';
     echo '<div style="text-align:center"><label for="edit-rsstitletemplate">'.get_string('rsstitletemplate','data').'</label></div>';
-    print_textarea($usehtmleditor, 10, 72, 0, 0, 'rsstitletemplate', $data->rsstitletemplate);
+
+    $field = 'rsstitletemplate';
+    $editor->use_editor($field, $options);
+    echo '<div><textarea id="'.$field.'" name="'.$field.'" rows="15" cols="80">'.s($data->rsstitletemplate).'</textarea></div>';
     echo '</td>';
     echo '</tr>';
 }