-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathaction.php
More file actions
70 lines (64 loc) · 2.42 KB
/
action.php
File metadata and controls
70 lines (64 loc) · 2.42 KB
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
<?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 script handles actions from the single 'action form' form that is used
* to handle some discussion actions (currently: ratings and flags).
*
* There is a single form because it is desirable to edit all ratings at once,
* which means the form needs to encompass the whole page, and it is not
* possible to nest forms inside each other.
*
* This form is used only for non-Javascript support. The supported actions
* (ratings and flags) have their own scripts; this script decodes its
* parameters and than requires the relevant script to use that.
* @package mod
* @subpackage forumng
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
/**
* Checks whether a POST key matches a given action. If it matches, parameters
* are extracted from the string and hacked into the POST parameters that will
* be passed to the real script.
* @param string $key POST parameter key
* @param string $prefix Desired key name prefix
*/
function match_action($key, $prefix) {
if (strpos($key, $prefix) !== 0) {
return false;
}
$params = substr($key, strlen($prefix));
$matches = array();
while (preg_match('~^_([a-z]+)_([^_]+)(.*)$~', $params, $matches)) {
$_POST[$matches[1]] = $matches[2];
$params = $matches[3];
}
return true;
}
// Loop through all POST parameters looking for a valid action.
foreach ($_POST as $key => $value) {
if (match_action($key, 'action_flag')) {
require_once('flagpost.php');
exit;
}
if (match_action($key, 'action_rate')) {
require_once('rate.php');
exit;
}
}
// If no actions were found, print error.
throw new moodle_exception('unknownuseraction');