MDL-40266 improve emulate_bound_params() for mysqli
[moodle.git] / comment / comment_post.php
CommitLineData
1bcb7eb5 1<?php
1bcb7eb5 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/*
6aee0477 18 * Handling new comments from non-js comments interface
35453657
DC
19 *
20 * @package core
21 * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1bcb7eb5 23 */
24require_once('../config.php');
88342307 25require_once($CFG->dirroot . '/comment/lib.php');
1bcb7eb5 26
c1951ea9
DC
27if (empty($CFG->usecomments)) {
28 throw new comment_exception('commentsnotenabled', 'moodle');
29}
30
1bcb7eb5 31$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
57588523 32list($context, $course, $cm) = get_context_info_array($contextid);
1bcb7eb5 33
80555111 34require_login($course, true, $cm);
2c3c4c8d 35require_sesskey();
1bcb7eb5 36
c1951ea9 37$action = optional_param('action', '', PARAM_ALPHA);
aff24313 38$area = optional_param('area', '', PARAM_AREA);
c1951ea9
DC
39$content = optional_param('content', '', PARAM_RAW);
40$itemid = optional_param('itemid', '', PARAM_INT);
1e8335fb 41$returnurl = optional_param('returnurl', '/', PARAM_LOCALURL);
aff24313 42$component = optional_param('component', '', PARAM_COMPONENT);
c1951ea9
DC
43
44// Currently this script can only add comments
45if ($action !== 'add') {
46 redirect($returnurl);
47}
1bcb7eb5 48
c1951ea9 49$cmt = new stdClass;
1bcb7eb5 50$cmt->contextid = $contextid;
57588523 51$cmt->courseid = $course->id;
c1951ea9 52$cmt->cm = $cm;
1bcb7eb5 53$cmt->area = $area;
54$cmt->itemid = $itemid;
287ccb31 55$cmt->component = $component;
1bcb7eb5 56$comment = new comment($cmt);
57
c1951ea9 58if ($comment->can_post()) {
2c3c4c8d
PS
59 $cmt = $comment->add($content);
60 if (!empty($cmt) && is_object($cmt)) {
61 redirect($returnurl);
1bcb7eb5 62 }
1bcb7eb5 63}