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

/mod/wiki/edit_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 118 lines | 66 code | 18 blank | 34 comment | 11 complexity | 890f00dc0b64dd2daf89c2ac5f53a2c3 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. * This file contains all necessary code to define and process an edit form
  18. *
  19. * @package mod-wiki-2.0
  20. * @copyrigth 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
  21. * @copyrigth 2009 Universitat Politecnica de Catalunya http://www.upc.edu
  22. *
  23. * @author Josep Arus
  24. *
  25. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26. */
  27. if (!defined('MOODLE_INTERNAL')) {
  28. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  29. }
  30. require_once($CFG->dirroot . '/mod/wiki/editors/wikieditor.php');
  31. class mod_wiki_edit_form extends moodleform {
  32. protected function definition() {
  33. global $CFG;
  34. $mform = $this->_form;
  35. // BEWARE HACK: In order for things to work we need to override the form id and set it to mform1.
  36. // The first form to be instantiated never gets displayed so this should be safe.
  37. $mform->updateAttributes(array('id' => 'mform1'));
  38. $version = $this->_customdata['version'];
  39. $format = $this->_customdata['format'];
  40. if (empty($this->_customdata['contextid'])) {
  41. // Hack alert
  42. // This is being done ONLY to aid those who may have created there own wiki pages. It should be removed sometime
  43. // after the release of 2.3 (not creating an issue because this whole thing should be reviewed)
  44. debugging('You must always provide mod_wiki_edit_form with a contextid in its custom data', DEBUG_DEVELOPER);
  45. global $PAGE;
  46. $contextid = $PAGE->context->id;
  47. } else {
  48. $contextid = $this->_customdata['contextid'];
  49. }
  50. if (isset($this->_customdata['pagetitle'])) {
  51. // Page title must be formatted properly here as this is output and not an element.
  52. $pagetitle = get_string('editingpage', 'wiki', format_string($this->_customdata['pagetitle'], true, array('context' => context::instance_by_id($contextid, MUST_EXIST))));
  53. } else {
  54. $pagetitle = get_string('editing', 'wiki');
  55. }
  56. //editor
  57. $mform->addElement('header', 'general', $pagetitle);
  58. $fieldname = get_string('format' . $format, 'wiki');
  59. if ($format != 'html') {
  60. // Use wiki editor
  61. $extensions = file_get_typegroup('extension', 'web_image');
  62. $fs = get_file_storage();
  63. $tree = $fs->get_area_tree($contextid, 'mod_wiki', $this->_customdata['filearea'], $this->_customdata['fileitemid']);
  64. $files = array();
  65. foreach ($tree['files'] as $file) {
  66. $filename = $file->get_filename();
  67. foreach ($extensions as $ext) {
  68. if (preg_match('#'.$ext.'$#i', $filename)) {
  69. $files[] = $filename;
  70. }
  71. }
  72. }
  73. $mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 100, 'rows' => 20, 'wiki_format' => $format, 'files'=>$files));
  74. $mform->addHelpButton('newcontent', 'format'.$format, 'wiki');
  75. $mform->setType('newcontent', PARAM_RAW); // processed by trust text or cleaned before the display
  76. } else {
  77. $mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_wiki_edit::$attachmentoptions);
  78. $mform->addHelpButton('newcontent_editor', 'formathtml', 'wiki');
  79. $mform->setType('newcontent_editor', PARAM_RAW); // processed by trust text or cleaned before the display
  80. }
  81. //hiddens
  82. if ($version >= 0) {
  83. $mform->addElement('hidden', 'version', $version);
  84. $mform->setType('version', PARAM_FLOAT);
  85. }
  86. $mform->addElement('hidden', 'contentformat', $format);
  87. $mform->setType('contentformat', PARAM_ALPHANUMEXT);
  88. if (!empty($CFG->usetags)) {
  89. $mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
  90. $mform->addElement('tags', 'tags', get_string('tags'));
  91. $mform->setType('tags', PARAM_TEXT);
  92. }
  93. $buttongroup = array();
  94. $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('save', 'wiki'), array('id' => 'save'));
  95. $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('preview'), array('id' => 'preview'));
  96. $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('cancel'), array('id' => 'cancel'));
  97. $mform->addGroup($buttongroup, 'buttonar', '', array(' '), false);
  98. $mform->closeHeaderBefore('buttonar');
  99. }
  100. }