-
Notifications
You must be signed in to change notification settings - Fork 20
/
discuss.php
128 lines (112 loc) · 4.27 KB
/
discuss.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
<?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/>.
/**
* Show discussion page.
* @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');
require_once('mod_forumng.php');
// Require discussion parameter here. Other parameters may be required in forum
// type.
$discussionid = required_param('d', PARAM_INT);
$pageparams = array('d' => $discussionid);
$cloneid = optional_param('clone', 0, PARAM_INT);
if ($cloneid) {
$pageparams['clone' ]= $cloneid;
}
$postid = optional_param('p', '', PARAM_ALPHANUM);
if ($postid) {
$pageparams['p'] = $postid;
}
// Construct discussion variable (will check id is valid)
// Retrieve new copy of discussion from database, but store it in cache
// for further use.
$discussion = mod_forumng_discussion::get_from_id($discussionid, $cloneid,
0, false, true);
$forum = $discussion->get_forum();
$course = $forum->get_course();
$cm = $forum->get_course_module();
$context = $forum->get_context();
$draftid = optional_param('draft', 0, PARAM_INT);
if ($draftid) {
$pageparams['draft'] = $draftid;
$draft = mod_forumng_draft::get_from_id($draftid);
if (!$draft->is_reply() ||
$draft->get_discussion_id() != $discussionid) {
throw new moodle_exception('draft_mismatch', 'forumng', $forum->get_url(mod_forumng::PARAM_HTML));
}
$root = $discussion->get_root_post();
$inreplyto = $root->find_child($draft->get_parent_post_id(), false);
if (!$inreplyto || !$inreplyto->can_reply($whynot) || !$discussion->can_view()) {
if (!$whynot) {
$whynot = 'reply_missing';
}
throw new moodle_exception('draft_cannotreply', 'forumng', $forum->get_url(mod_forumng::PARAM_HTML),
get_string($whynot, 'forumng'));
}
$inreplyto->force_expand();
}
// Check that discussion can be viewed [Handles all other permissions]
$beforeuserid = $USER->id;
$discussion->require_view();
if (!$beforeuserid && $USER->id) {
// If the user is now logged in, we need to reload the discussion object.
$discussion = mod_forumng_discussion::get_from_id($discussionid, $cloneid, 0, false, true);
}
// Atom header meta tag
$feedtype = $forum->get_effective_feed_option();
if ($feedtype == mod_forumng::FEEDTYPE_ALL_POSTS) {
$atomurl = $discussion->get_feed_url(mod_forumng::FEEDFORMAT_ATOM);
$meta = '<link rel="alternate" type="application/atom+xml" ' .
'title="Atom feed" href="' . htmlspecialchars($atomurl) . '" />';
} else {
$meta = '';
}
// Display header
$url = new moodle_url('/mod/forumng/discuss.php', $pageparams);
$pagename = shorten_text(s($discussion->get_subject()));
if (!defined('BEHAT_SITE_RUNNING')) {
$PAGE->set_pagelayout('base');
}
$out = $forum->init_page($url, $pagename);
print $out->header();
// Include forum JS
$forum->print_js($cm->id, true);
// If replying with a draft, we stick some JSON stuff in the page so that the draft
// can be retrieved.
if ($draftid) {
print $draft->prepare_edit_js($forum);
}
// Print main div
print '<div id="forumng-main" class="forumng-discuss forumng-nojs' .
($discussion->is_deleted() ? ' forumng-deleted-discussion' : '' ) . '">';
print $out->render_switch_link($forum);
print $OUTPUT->skip_link_target();
// Get forum type to display main part of page
$type = $forum->get_type();
$type->print_discussion_page($discussion);
print '</div>';
if ($bad = $PAGE->devicetypeinuse == 'legacy') {
print '<div class="forumng-bad-browser">'.
get_string('badbrowser', 'forumng', $bad) . '</div>';
}
// Log request
$discussion->log('view discussion');
// Display footer
print $out->footer();