forked from NMAI-lab/moodle-mod_socialwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_form.php
executable file
·119 lines (104 loc) · 5.17 KB
/
edit_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains all necessary code to define and process an edit form
*
* @package mod_socialwiki
* @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Josep Arus
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
require($CFG->dirroot . '/mod/socialwiki/editors/wikieditor.php');
/**
* Form used for editing and creating new pages/versions.
*
* @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_socialwiki_edit_form extends moodleform {
/**
* Build the full form.
*/
protected function definition() {
$mform = $this->_form;
// BEWARE HACK: In order for things to work we need to override the form id and set it to mform1.
// The first form to be instantiated never gets displayed so this should be safe.
$mform->updateAttributes(array('id' => 'mform1'));
$format = $this->_customdata['format'];
if (empty($this->_customdata['contextid'])) {
// Hack alert.
// This is being done ONLY to aid those who may have created there own wiki pages. It should be removed sometime
// after the release of 2.3 (not creating an issue because this whole thing should be reviewed).
debugging('You must always provide mod_socialwiki_edit_form with a contextid in its custom data', DEBUG_DEVELOPER);
global $PAGE;
$contextid = $PAGE->context->id;
} else {
$contextid = $this->_customdata['contextid'];
}
if (isset($this->_customdata['pagetitle'])) {
// Page title must be formatted properly here as this is output and not an element.
$pagetitle = get_string('editingpage', 'socialwiki', format_string(
$this->_customdata['pagetitle'], true,
array('context' => context::instance_by_id($contextid, MUST_EXIST))));
} else {
$pagetitle = get_string('editing', 'socialwiki');
}
// Editor.
$fieldname = get_string('format' . $format, 'socialwiki');
if ($format != 'html') {
// Use wiki editor.
$extensions = file_get_typegroup('extension', 'web_image');
$fs = get_file_storage();
$tree = $fs->get_area_tree($contextid, 'mod_socialwiki',
$this->_customdata['filearea'], $this->_customdata['fileitemid']);
$files = array();
foreach ($tree['files'] as $file) {
$filename = $file->get_filename();
foreach ($extensions as $ext) {
if (preg_match('#' . $ext . '$#i', $filename)) {
$files[] = $filename;
}
}
}
// Good here.
$mform->addElement('socialwikieditor', 'newcontent', $fieldname,
array('cols' => 100, 'rows' => 20, 'socialwiki_format' => $format, 'files' => $files));
// Not good here.
$mform->addHelpButton('newcontent', 'format' . $format, 'socialwiki');
$mform->setType('newcontent', PARAM_RAW); // Processed by trust text or cleaned before the display.
} else {
// Not good here.
$mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_socialwiki_edit::$attachmentoptions);
$mform->addHelpButton('newcontent_editor', 'formathtml', 'socialwiki');
$mform->setType('newcontent_editor', PARAM_RAW); // Processed by trust text or cleaned before the display.
}
// Ends here.
$mform->addElement('hidden', 'contentformat', $format);
$mform->setType('contentformat', PARAM_ALPHANUMEXT);
$buttongroup = array();
$buttongroup[] = $mform->createElement('submit', 'editoption', get_string('save', 'socialwiki'), array('id' => 'save'));
$buttongroup[] = $mform->createElement('submit', 'editoption', get_string('preview'), array('id' => 'preview'));
$buttongroup[] = $mform->createElement('submit', 'editoption', get_string('cancel'), array('id' => 'cancel'));
$mform->addGroup($buttongroup, 'buttonar', "", array(' '), false);
}
}