forked from moodleou/moodle-mod_oublog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditcomment.php
More file actions
160 lines (134 loc) · 5.3 KB
/
Copy patheditcomment.php
File metadata and controls
160 lines (134 loc) · 5.3 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
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
<?php
/**
* This page allows a user to add and edit blog comments
*
* @author Matt Clarkson <mattc@catalyst.net.nz>
* @author Sam Marshall <s.marshall@open.ac.uk>
* @package oublog
*/
require_once("../../config.php");
require_once("locallib.php");
require_once('comment_form.php');
define('OUBLOG_CONFIRMED_COOKIE', 'OUBLOG_REALPERSON');
$blog = required_param('blog', PARAM_INT); // Blog ID
$postid = required_param('post', PARAM_INT); // Post ID for editing
$commentid = optional_param('comment', 0, PARAM_INT); // Comment ID for editing
if (!$oublog = $DB->get_record("oublog", array("id"=>$blog))) {
print_error('invalidblog','oublog');
}
if (!$cm = get_coursemodule_from_instance('oublog', $blog)) {
print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record("course", array("id"=>$oublog->course))) {
print_error('coursemisconf');
}
if (!$post = $DB->get_record('oublog_posts', array('id'=>$postid))) {
print_error('invalidpost','oublog');
}
if (!$oubloginstance = $DB->get_record('oublog_instances', array('id'=>$post->oubloginstancesid))) {
print_error('invalidblog','oublog');
}
$url = new moodle_url('/mod/oublog/editcomment.php', array('blog'=>$blog, 'post'=>$postid, 'comment'=>$commentid));
$PAGE->set_url($url);
/// Check security
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
oublog_check_view_permissions($oublog, $context, $cm);
$post->userid=$oubloginstance->userid; // oublog_can_view_post needs this
if(!oublog_can_view_post($post,$USER,$context,$oublog->global)) {
print_error('accessdenied','oublog');
}
oublog_get_activity_groupmode($cm, $course);
if (!oublog_can_comment($cm, $oublog, $post)) {
print_error('accessdenied','oublog');
}
if ($oublog->allowcomments == OUBLOG_COMMENTS_PREVENT || $post->allowcomments == OUBLOG_COMMENTS_PREVENT) {
print_error('commentsnotallowed','oublog');
}
$viewurl = 'viewpost.php?post='.$post->id;
if ($oublog->global) {
$blogtype = 'personal';
if (!$oubloguser = $DB->get_record('user', array('id'=>$oubloginstance->userid))) {
print_error('invaliduserid');
}
} else {
$blogtype = 'course';
}
/// Get strings
$stroublogs = get_string('modulenameplural', 'oublog');
$stroublog = get_string('modulename', 'oublog');
$straddcomment = get_string('newcomment', 'oublog');
$moderated = !(isloggedin() && !isguestuser());
$confirmed = isset($_COOKIE[OUBLOG_CONFIRMED_COOKIE]) &&
$_COOKIE[OUBLOG_CONFIRMED_COOKIE] == get_string(
'moderated_confirmvalue', 'oublog');
$mform = new mod_oublog_comment_form('editcomment.php', array(
'maxvisibility' => $oublog->maxvisibility,
'edit' => !empty($commentid),
'blogid' => $blog,
'postid' => $postid,
'moderated' => $moderated,
'confirmed' => $confirmed
));
if ($mform->is_cancelled()) {
redirect($viewurl);
exit;
}
$PAGE->set_title(format_string($oublog->name));
$PAGE->set_heading(format_string($course->fullname));
if (!$comment = $mform->get_data()) {
$comment = new stdClass;
$comment->general = $straddcomment;
$comment->blog = $blog;
$comment->post = $postid;
$mform->set_data($comment);
// Print the header
if ($blogtype == 'personal') {
oublog_build_navigation($oublog, $oubloginstance, $oubloguser);
} else {
oublog_build_navigation($oublog, $oubloginstance, null);
$url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cm->id, 'return' => true, 'sesskey' => sesskey()));
$PAGE->set_button($OUTPUT->single_button($url, $stroublog));
}
oublog_get_post_extranav($post);
$PAGE->navbar->add($comment->general);
echo $OUTPUT->header();
echo '<br />';
$mform->display();
echo $OUTPUT->footer();
} else {
// Prepare comment for database
unset($comment->id);
$comment->userid = $USER->id;
$comment->postid = $postid;
// Special behaviour for moderated users
if ($moderated) {
// Check IP address
if (oublog_too_many_comments_from_ip()) {
print_error('error_toomanycomments', 'oublog');
}
// Set the confirmed cookie if they haven't got it yet
if (!$confirmed) {
setcookie(OUBLOG_CONFIRMED_COOKIE, $comment->confirm,
time() + 365 * 24 * 3600); // Expire in 1 year
}
if (!oublog_add_comment_moderated($oublog, $oubloginstance, $post, $comment)) {
print_error('couldnotaddcomment','oublog');
}
$approvaltime = oublog_get_typical_approval_time($post->userid);
oublog_build_navigation($oublog, $oubloginstance, isset($oubloguser) ? $oubloguser : null);
oublog_get_post_extranav($post);
$PAGE->navbar->add(get_string('moderated_submitted', 'oublog'));
echo $OUTPUT->header();
notice(get_string('moderated_addedcomment', 'oublog') .
($approvaltime ? ' ' .
get_string('moderated_typicaltime', 'oublog', $approvaltime)
: ''), 'viewpost.php?post=' . $postid, $course);
// does not continue
}
$comment->userid = $USER->id;
if (!oublog_add_comment($course,$cm,$oublog,$comment)) {
print_error('couldnotaddcomment','oublog');
}
add_to_log($course->id, "oublog", "add comment", $viewurl, $oublog->id, $cm->id);
redirect($viewurl);
}