/** * Constructor * * @param string $elementName (optional) name of the editor * @param string $elementLabel (optional) editor label * @param array $attributes (optional) Either a typical HTML attribute string * or an associative array * @param array $options set of options to initalize filepicker */ function MoodleQuickForm_editor($elementName = null, $elementLabel = null, $attributes = null, $options = null) { global $CFG, $PAGE; $options = (array) $options; foreach ($options as $name => $value) { if (array_key_exists($name, $this->_options)) { $this->_options[$name] = $value; } } if (!empty($options['maxbytes'])) { $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); } if (!$this->_options['context']) { // trying to set context to the current page context to make legacy files show in filepicker (e.g. forum post) if (!empty($PAGE->context->id)) { $this->_options['context'] = $PAGE->context; } else { $this->_options['context'] = context_system::instance(); } } $this->_options['trusted'] = trusttext_trusted($this->_options['context']); parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes); // Note: for some reason the code using this setting does not like bools. $this->_options['subdirs'] = (int) ($this->_options['subdirs'] == 1); editors_head_setup(); }
/** * Constructor * * @param string $elementName (optional) name of the html editor * @param string $elementLabel (optional) editor label * @param array $options set of options to create html editor * @param array $attributes (optional) Either a typical HTML attribute string * or an associative array */ function MoodleQuickForm_htmleditor($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes); // set the options, do not bother setting bogus ones if (is_array($options)) { foreach ($options as $name => $value) { if (array_key_exists($name, $this->_options)) { if (is_array($value) && is_array($this->_options[$name])) { $this->_options[$name] = @array_merge($this->_options[$name], $value); } else { $this->_options[$name] = $value; } } } } if ($this->_options['canUseHtmlEditor'] == 'detect') { $this->_options['canUseHtmlEditor'] = can_use_html_editor(); } if ($this->_options['canUseHtmlEditor']) { $this->_type = 'htmleditor'; //$this->_elementTemplateType='wide'; } else { $this->_type = 'textarea'; } $this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor']; editors_head_setup(); }
/** * @param string $name * @param string $visiblename * @param string $description * @param mixed $defaultsetting string or array * @param mixed $paramtype */ public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype = PARAM_RAW, $cols = '60', $rows = '8', $filearea = 'bcumarketingimages') { $this->rows = $rows; $this->cols = $cols; $this->filearea = $filearea; parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype); editors_head_setup(); }
function display_add_field($recordid = 0) { global $CFG, $DB, $OUTPUT, $PAGE; $text = ''; $format = 0; $str = '<div title="' . $this->field->description . '">'; 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; $text = clean_text($text, $format); } else { if (can_use_html_editor()) { $format = FORMAT_HTML; } else { $format = FORMAT_PLAIN; } } $editor = editors_get_preferred_editor($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="' . $this->field->param3 . '" cols="' . $this->field->param2 . '">' . 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 .= '</div>'; $str .= '</div>'; return $str; }
/** * Constructor * * @param string $elementName (optional) name of the html editor * @param string $elementLabel (optional) editor label * @param array $options set of options to create html editor * @param array $attributes (optional) Either a typical HTML attribute string * or an associative array */ function MoodleQuickForm_htmleditor($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes); // set the options, do not bother setting bogus ones if (is_array($options)) { foreach ($options as $name => $value) { if (array_key_exists($name, $this->_options)) { if (is_array($value) && is_array($this->_options[$name])) { $this->_options[$name] = @array_merge($this->_options[$name], $value); } else { $this->_options[$name] = $value; } } } } $this->_type = 'htmleditor'; editors_head_setup(); }
function MoodleQuickForm_editor($elementName = null, $elementLabel = null, $attributes = null, $options = null) { global $CFG, $PAGE; $options = (array) $options; foreach ($options as $name => $value) { if (array_key_exists($name, $this->_options)) { $this->_options[$name] = $value; } } if (!empty($options['maxbytes'])) { $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); } if (!$this->_options['context']) { $this->_options['context'] = get_context_instance(CONTEXT_SYSTEM); } $this->_options['trusted'] = trusttext_trusted($this->_options['context']); parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes); editors_head_setup(); }
function display_add_field($recordid = 0) { global $CFG, $DB, $OUTPUT, $PAGE, $USER; $text = ''; $format = 0; $str = '<div title="' . $this->field->description . '">'; editors_head_setup(); $options = $this->get_options(); $itemid = $this->field->id; $field = 'field_' . $itemid; if ($recordid && ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) { $format = $content->content1; $text = clean_text($content->content, $format); $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text); } else { $draftitemid = file_get_unused_draft_itemid(); } $updatecontrol = $field; $idcontrol = $field . '_itemid'; $str .= '<input type="hidden" id="' . $updatecontrol . '" name="' . $updatecontrol . '" value="empty" />'; $str .= '<input type="hidden" name="' . $idcontrol . '" value="' . $draftitemid . '" />'; // $type = DBP_AUDIOMP3; $usercontextid = context_user::instance($USER->id)->id; switch ($this->field->param4) { case DBP_AUDIO: $str .= fetchAudioRecorderForSubmission('auto', 'ignore', $updatecontrol, $usercontextid, "user", "draft", $draftitemid); break; case DBP_VIDEO: $str .= fetchVideoRecorderForSubmission('auto', 'ignore', $updatecontrol, $usercontextid, "user", "draft", $draftitemid); break; case DBP_AUDIOMP3: $str .= fetchMP3RecorderForSubmission($updatecontrol, $usercontextid, "user", "draft", $draftitemid); break; case DBP_WHITEBOARDSIMPLE: case DBP_WHITEBOARDFULL: $str .= fetchWhiteboardForSubmission($updatecontrol, $usercontextid, "user", "draft", $draftitemid); break; case DBP_SNAPSHOT: $str .= fetchSnapshotCameraForSubmission($updatecontrol, 'apic.jpg', 350, 400, $usercontextid, "user", "draft", $draftitemid); break; } return $str; }
/** * Calls parent::__construct with specific arguments */ public function __construct() { parent::__construct('summary', get_string('frontpagedescription'), get_string('frontpagedescriptionhelp'), NULL); editors_head_setup(); }
function display_add_field($recordid=0) { global $CFG, $DB, $OUTPUT, $PAGE; $text = ''; $format = 0; $str = '<div title="'.$this->field->description.'">'; editors_head_setup(); $options = $this->get_options(); $itemid = $this->field->id; $field = 'field_'.$itemid; if ($recordid && $content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))){ $format = $content->content1; $text = clean_text($content->content, $format); $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text); } else { $draftitemid = file_get_unused_draft_itemid(); if (can_use_html_editor()) { $format = FORMAT_HTML; } else { $format = FORMAT_PLAIN; } } // get filepicker info // $fpoptions = array(); if ($options['maxfiles'] != 0 ) { $args = new stdClass(); // need these three to filter repositories list $args->accepted_types = array('web_image'); $args->return_types = (FILE_INTERNAL | FILE_EXTERNAL); $args->context = $this->context; $args->env = 'filepicker'; // advimage plugin $image_options = initialise_filepicker($args); $image_options->context = $this->context; $image_options->client_id = uniqid(); $image_options->maxbytes = $options['maxbytes']; $image_options->env = 'editor'; $image_options->itemid = $draftitemid; // moodlemedia plugin $args->accepted_types = array('video', 'audio'); $media_options = initialise_filepicker($args); $media_options->context = $this->context; $media_options->client_id = uniqid(); $media_options->maxbytes = $options['maxbytes']; $media_options->env = 'editor'; $media_options->itemid = $draftitemid; // advlink plugin $args->accepted_types = '*'; $link_options = initialise_filepicker($args); $link_options->context = $this->context; $link_options->client_id = uniqid(); $link_options->maxbytes = $options['maxbytes']; $link_options->env = 'editor'; $link_options->itemid = $draftitemid; $fpoptions['image'] = $image_options; $fpoptions['media'] = $media_options; $fpoptions['link'] = $link_options; } $editor = editors_get_preferred_editor($format); $strformats = format_text_menu(); $formats = $editor->get_supported_formats(); foreach ($formats as $fid) { $formats[$fid] = $strformats[$fid]; } $editor->use_editor($field, $options, $fpoptions); $str .= '<input type="hidden" name="'.$field.'_itemid" value="'.$draftitemid.'" />'; $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" cols="'.$this->field->param2.'">'.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 .= '</div>'; $str .= '</div>'; return $str; }
/** * Prints a basic textarea field. * * @deprecated since Moodle 2.0 * * When using this function, you should * * @global object * @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. * @return string|void depending on the value of $return */ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=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. // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.'); global $CFG; $mincols = 65; $minrows = 10; $str = ''; if ($id === '') { $id = 'edit-'.$name; } if ($usehtmleditor) { if ($height && ($rows < $minrows)) { $rows = $minrows; } if ($width && ($cols < $mincols)) { $cols = $mincols; } } if ($usehtmleditor) { editors_head_setup(); $editor = editors_get_preferred_editor(FORMAT_HTML); $editor->use_editor($id, array('legacy'=>true)); } else { $editorclass = ''; } $str .= "\n".'<textarea class="form-textarea" 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 ($return) { return $str; } echo $str; }
} } } } else { echo '<div class="template_heading">' . get_string('header' . $mode, 'data') . '</div>'; } /// If everything is empty then generate some defaults if (empty($data->addtemplate) and empty($data->singletemplate) and empty($data->listtemplate) and empty($data->rsstemplate)) { data_generate_default_template($data, 'singletemplate'); data_generate_default_template($data, 'listtemplate'); data_generate_default_template($data, 'addtemplate'); data_generate_default_template($data, 'asearchtemplate'); //Template for advanced searches. data_generate_default_template($data, 'rsstemplate'); } editors_head_setup(); $format = FORMAT_HTML; if ($mode === 'csstemplate' or $mode === 'jstemplate') { $disableeditor = true; } if ($disableeditor) { $format = FORMAT_PLAIN; } $editor = editors_get_preferred_editor($format); $strformats = format_text_menu(); $formats = $editor->get_supported_formats(); foreach ($formats as $fid) { $formats[$fid] = $strformats[$fid]; } $options = array(); $options['trusttext'] = false;
/** * @param string $name * @param string $visiblename * @param string $description * @param mixed $defaultsetting string or array * @param mixed $paramtype */ public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $cols='60', $rows='8') { parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype, $cols, $rows); $this->set_force_ltr(false); editors_head_setup(); }
/** * @see lib/moodle_html_component#prepare() * @return void */ public function prepare() { $this->add_class('form-textarea'); if (empty($this->id)) { $this->id = "edit-{$this->name}"; } if ($this->usehtmleditor) { editors_head_setup(); $editor = get_preferred_texteditor(FORMAT_HTML); $editor->use_editor($this->id, array('legacy' => true)); $this->value = htmlspecialchars($value); } parent::prepare(); }
public function advanced_editor() { // Only output editor if preferred editor is Atto - tiny mce not supported yet. editors_head_setup(); $editor = editors_get_preferred_editor(FORMAT_HTML); if (get_class($editor) == 'atto_texteditor') { $editor->use_editor('hiddenadvancededitor'); return '<div id="hiddenadvancededitorcont"><textarea style="display:none" id="hiddenadvancededitor"></textarea></div>'; } return ''; }
public static function format_editor_field($datafield, $title, $rows = 3, $cols = 40) { $content = $datafield->contentparam; $format = $datafield->formatparam; $context = $datafield->context; $field = $datafield->field; $itemid = $field->id; $name = 'field_' . $itemid; editors_head_setup(); $options = self::get_fileoptions($context); if ($itemid) { $draftitemid = 0; $text = clean_text($field->{$content}, $field->{$format}); $text = file_prepare_draft_area($draftitemid, $context->id, 'mod_data', 'content', $itemid, $options, $text); } else { $draftitemid = file_get_unused_draft_itemid(); $text = ''; } // get filepicker options, if required if (empty($options['maxfiles'])) { $filepicker_options = array(); } else { $filepicker_options = self::get_filepicker_options($context, $draftitemid, $options['maxbytes']); } // set up editor $editor = editors_get_preferred_editor($field->{$format}); $editor->set_text($text); $editor->use_editor('id_' . $name . '_content', $options, $filepicker_options); // format editor $output = ''; $output .= self::format_editor_content($draftitemid, $name, $field->{$content}, $rows, $cols); $output .= self::format_editor_formats($editor, $name, $field->{$format}); return html_writer::tag('div', $output, array('title' => $title)); }
function display_add_field($recordid = 0, $formdata = null) { global $CFG, $DB, $OUTPUT, $PAGE; $text = ''; $format = 0; $str = '<div title="' . s($this->field->description) . '">'; $str .= '<label for="field_' . $this->field->id . '" class="accesshide">'; $str .= html_writer::span($this->field->name); if ($this->field->required) { $image = html_writer::img($OUTPUT->pix_url('req'), get_string('requiredelement', 'form'), array('class' => 'req', 'title' => get_string('requiredelement', 'form'))); $str .= html_writer::div($image, 'inline-req'); } $str .= '</label>'; editors_head_setup(); $options = $this->get_options(); $itemid = $this->field->id; $field = 'field_'.$itemid; if ($formdata) { $fieldname = 'field_' . $this->field->id . '_content1'; if (isset($formdata->$fieldname)) { $format = $formdata->$fieldname; } else { $format = file_get_unused_draft_itemid(); } $fieldname = 'field_' . $this->field->id . '_itemid'; if (isset($formdata->$fieldname)) { $draftitemid = clean_param($formdata->$fieldname, PARAM_INT); } else { $draftitemid = file_get_unused_draft_itemid(); } $fieldname = 'field_' . $this->field->id; if (isset($formdata->$fieldname)) { $text = $formdata->$fieldname; } } else if ($recordid && $content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { $format = $content->content1; $text = clean_text($content->content, $format); $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text); } else { $draftitemid = file_get_unused_draft_itemid(); $format = FORMAT_HTML; } // get filepicker info // $fpoptions = array(); if ($options['maxfiles'] != 0 ) { $args = new stdClass(); // need these three to filter repositories list $args->accepted_types = array('web_image'); $args->return_types = (FILE_INTERNAL | FILE_EXTERNAL); $args->context = $this->context; $args->env = 'filepicker'; // advimage plugin $image_options = initialise_filepicker($args); $image_options->context = $this->context; $image_options->client_id = uniqid(); $image_options->maxbytes = $options['maxbytes']; $image_options->env = 'editor'; $image_options->itemid = $draftitemid; // moodlemedia plugin $args->accepted_types = array('video', 'audio'); $media_options = initialise_filepicker($args); $media_options->context = $this->context; $media_options->client_id = uniqid(); $media_options->maxbytes = $options['maxbytes']; $media_options->env = 'editor'; $media_options->itemid = $draftitemid; // advlink plugin $args->accepted_types = '*'; $link_options = initialise_filepicker($args); $link_options->context = $this->context; $link_options->client_id = uniqid(); $link_options->maxbytes = $options['maxbytes']; $link_options->env = 'editor'; $link_options->itemid = $draftitemid; $fpoptions['image'] = $image_options; $fpoptions['media'] = $media_options; $fpoptions['link'] = $link_options; } $editor = editors_get_preferred_editor($format); $strformats = format_text_menu(); $formats = $editor->get_supported_formats(); foreach ($formats as $fid) { $formats[$fid] = $strformats[$fid]; } $editor->set_text($text); $editor->use_editor($field, $options, $fpoptions); $str .= '<input type="hidden" name="'.$field.'_itemid" value="'.s($draftitemid).'" />'; $str .= '<div class="mod-data-input">'; $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" cols="'.$this->field->param2.'" spellcheck="true">'.s($text).'</textarea></div>'; $str .= '<div><label class="accesshide" for="' . $field . '_content1">' . get_string('format') . '</label>'; $str .= '<select id="' . $field . '_content1" name="'.$field.'_content1">'; foreach ($formats as $key=>$desc) { $selected = ($format == $key) ? 'selected="selected"' : ''; $str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>'; } $str .= '</select>'; $str .= '</div>'; $str .= '</div>'; $str .= '</div>'; return $str; }