-
Notifications
You must be signed in to change notification settings - Fork 46
/
index.php
222 lines (163 loc) · 8.31 KB
/
index.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?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/>.
/**
* Web interface for generating plugins.
*
* @package tool_pluginskel
* @copyright 2016 Alexandru Elisei
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use Monolog\Logger;
use Monolog\Handler\BrowserConsoleHandler;
// @codingStandardsIgnoreStart
if (!empty($_REQUEST['buttondownloadskel'])) {
// We are going to download a ZIP file via this script. Disable debugging
// to prevent corruption of the file. This must be done before booting up
// the Moodle core so we need to use the low-level access to the
// superlobal $_REQUEST here and make the code checker to ignore this.
define('NO_DEBUG_DISPLAY', true);
}
// @codingStandardsIgnoreEnd
require(__DIR__.'/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/moodlelib.php');
require_once(__DIR__.'/vendor/autoload.php');
admin_externalpage_setup('tool_pluginskel');
$url = new moodle_url('/admin/tool/pluginskel/index.php');
$PAGE->set_url($url);
$PAGE->set_title(get_string('generateskel', 'tool_pluginskel'));
$PAGE->set_heading(get_string('generateskel', 'tool_pluginskel'));
$step = optional_param('step', '0', PARAM_INT);
$component = optional_param('component1', '', PARAM_TEXT);
$returnurl = new moodle_url('/admin/tool/pluginskel/index.php');
if ($step == 0) {
$mform0 = new tool_pluginskel_step0_form();
$formdata = $mform0->get_data();
$PAGE->requires->js_call_amd('tool_pluginskel/showtypeprefix', 'init');
if (!empty($formdata)) {
$data = array();
$recipe = array();
$componenttype = '';
if (!empty($formdata->proceedmanually)) {
if (empty($formdata->componentname)) {
throw new moodle_exception('emptypluginname', 'tool_pluginskel', $returnurl);
}
$recipe['component'] = $formdata->componenttype.'_'.$formdata->componentname;
$componenttype = $formdata->componenttype;
} else {
if (!empty($formdata->proceedrecipefile)) {
$recipestring = $mform0->get_file_content('recipefile');
} else if (!empty($formdata->proceedrecipe)) {
$recipestring = $formdata->recipe;
}
if (empty($recipestring)) {
throw new moodle_exception('emptyrecipecontent', 'tool_pluginskel', $returnurl);
}
$recipe = tool_pluginskel\local\util\yaml::decode_string($recipestring);
list($componenttype, $componentname) = core_component::normalize_component($recipe['component']);
$generalvars = tool_pluginskel\local\util\manager::get_general_variables();
$componentvars = tool_pluginskel\local\util\manager::get_component_variables($recipe['component']);
$featuresvars = tool_pluginskel\local\util\manager::get_features_variables();
$rootvars = array_merge($generalvars, $featuresvars);
$rootvarscount = tool_pluginskel\local\util\index_helper::get_array_variable_count_from_recipe($rootvars, $recipe);
$componentfeatures = $componenttype.'_features';
$componentvarscount = array();
if (!empty($recipe[$componentfeatures])) {
$componentvarscount = tool_pluginskel\local\util\index_helper::get_array_variable_count_from_recipe(
$componentvars,
$recipe[$componentfeatures],
$componentfeatures
);
}
$data = array_merge($rootvarscount, $componentvarscount);
}
$data['recipe'] = $recipe;
$mform1 = new tool_pluginskel_step1_form(null, $data);
$PAGE->requires->js_call_amd('tool_pluginskel/addmore', 'addMore');
echo $OUTPUT->header();
$mform1->display();
echo $OUTPUT->footer();
} else {
echo $OUTPUT->header();
$mform0->display();
echo $OUTPUT->footer();
}
} else if ($step == 1) {
// Reconstructing the form elements.
$generalvars = tool_pluginskel\local\util\manager::get_general_variables();
$componentvars = tool_pluginskel\local\util\manager::get_component_variables($component);
$featuresvars = tool_pluginskel\local\util\manager::get_features_variables();
$rootvars = array_merge($generalvars, $featuresvars);
$rootvarscount = tool_pluginskel\local\util\index_helper::get_array_variable_count_from_form($rootvars);
list($componenttype, $componentname) = core_component::normalize_component($component);
$componentfeatures = $componenttype.'_features';
$componentvarscount = tool_pluginskel\local\util\index_helper::get_array_variable_count_from_form($componentvars,
$componentfeatures);
$data = array_merge($rootvarscount, $componentvarscount);
$data['recipe'] = array('component' => $component);
$mform1 = new tool_pluginskel_step1_form(null, $data);
$formdata = (array) $mform1->get_data();
$recipe = $mform1->get_recipe();
if (!empty($formdata['buttondownloadskel'])) {
tool_pluginskel\local\util\index_helper::download_plugin_skeleton($recipe);
} else if (!empty($formdata['buttondownloadrecipe'])) {
$recipestring = tool_pluginskel\local\util\yaml::encode($recipe);
tool_pluginskel\local\util\index_helper::download_recipe($recipestring);
} else if (!empty($formdata['buttonshowrecipe'])) {
$data = array('recipe' => $recipe);
$mform2 = new tool_pluginskel_step2_form(null, $data);
echo $OUTPUT->header();
$mform2->display();
echo $OUTPUT->footer();
}
} else if ($step == 2) {
// Reconstruct the form.
$recipestub = array('component' => $component);
$data = array('recipe' => $recipestub);
$mform2 = new tool_pluginskel_step2_form(null, $data);
$formdata = (array) $mform2->get_data();
$recipestring = $formdata['recipe'];
if (!empty($formdata['buttondownloadrecipe'])) {
tool_pluginskel\local\util\index_helper::download_recipe($recipestring);
} else if (!empty($formdata['buttondownloadskel'])) {
$recipe = tool_pluginskel\local\util\yaml::decode_string($recipestring);
tool_pluginskel\local\util\index_helper::download_plugin_skeleton($recipe);
} else if (!empty($formdata['buttonback'])) {
$recipe = tool_pluginskel\local\util\yaml::decode_string($recipestring);
$generalvars = tool_pluginskel\local\util\manager::get_general_variables();
$componentvars = tool_pluginskel\local\util\manager::get_component_variables($recipe['component']);
$featuresvars = tool_pluginskel\local\util\manager::get_features_variables();
$rootvars = array_merge($generalvars, $featuresvars);
$rootvarscount = tool_pluginskel\local\util\index_helper::get_array_variable_count_from_recipe($rootvars, $recipe);
list($componenttype, $componentname) = core_component::normalize_component($component);
$componentfeatures = $componenttype.'_features';
$componentvarscount = array();
if (!empty($recipe[$componentfeatures])) {
$componentvarscount = tool_pluginskel\local\util\index_helper::get_array_variable_count_from_recipe(
$componentvars,
$recipe[$componentfeatures],
$componentfeatures
);
}
$data = array_merge($rootvarscount, $componentvarscount);
$data['recipe'] = $recipe;
$mform1 = new tool_pluginskel_step1_form(null, $data);
$PAGE->requires->js_call_amd('tool_pluginskel/addmore', 'addMore');
echo $OUTPUT->header();
$mform1->display();
echo $OUTPUT->footer();
}
}