PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/blocks/html/edit_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 92 lines | 48 code | 10 blank | 34 comment | 10 complexity | bf40946fe41185a001124a1b9af824b0 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Form for editing HTML block instances.
  18. *
  19. * @package block_html
  20. * @copyright 2009 Tim Hunt
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. /**
  24. * Form for editing HTML block instances.
  25. *
  26. * @copyright 2009 Tim Hunt
  27. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28. */
  29. class block_html_edit_form extends block_edit_form {
  30. protected function specific_definition($mform) {
  31. global $CFG;
  32. // Fields for editing HTML block title and contents.
  33. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
  34. $mform->addElement('text', 'config_title', get_string('configtitle', 'block_html'));
  35. $mform->setType('config_title', PARAM_TEXT);
  36. $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->block->context);
  37. $mform->addElement('editor', 'config_text', get_string('configcontent', 'block_html'), null, $editoroptions);
  38. $mform->addRule('config_text', null, 'required', null, 'client');
  39. $mform->setType('config_text', PARAM_RAW); // XSS is prevented when printing the block contents and serving files
  40. if (!empty($CFG->block_html_allowcssclasses)) {
  41. $mform->addElement('text', 'config_classes', get_string('configclasses', 'block_html'));
  42. $mform->setType('config_classes', PARAM_TEXT);
  43. $mform->addHelpButton('config_classes', 'configclasses', 'block_html');
  44. }
  45. }
  46. function set_data($defaults) {
  47. if (!empty($this->block->config) && is_object($this->block->config)) {
  48. $text = $this->block->config->text;
  49. $draftid_editor = file_get_submitted_draft_itemid('config_text');
  50. if (empty($text)) {
  51. $currenttext = '';
  52. } else {
  53. $currenttext = $text;
  54. }
  55. $defaults->config_text['text'] = file_prepare_draft_area($draftid_editor, $this->block->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $currenttext);
  56. $defaults->config_text['itemid'] = $draftid_editor;
  57. $defaults->config_text['format'] = $this->block->config->format;
  58. } else {
  59. $text = '';
  60. }
  61. if (!$this->block->user_can_edit() && !empty($this->block->config->title)) {
  62. // If a title has been set but the user cannot edit it format it nicely
  63. $title = $this->block->config->title;
  64. $defaults->config_title = format_string($title, true, $this->page->context);
  65. // Remove the title from the config so that parent::set_data doesn't set it.
  66. unset($this->block->config->title);
  67. }
  68. // have to delete text here, otherwise parent::set_data will empty content
  69. // of editor
  70. unset($this->block->config->text);
  71. parent::set_data($defaults);
  72. // restore $text
  73. if (!isset($this->block->config)) {
  74. $this->block->config = new stdClass();
  75. }
  76. $this->block->config->text = $text;
  77. if (isset($title)) {
  78. // Reset the preserved title
  79. $this->block->config->title = $title;
  80. }
  81. }
  82. }