-
Notifications
You must be signed in to change notification settings - Fork 29
/
allposts.php
182 lines (157 loc) · 6.68 KB
/
allposts.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
<?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 page prints all non-private personal oublog posts
*
* @author Jenny Gray <[email protected]>
* @package oublog
*/
require_once('../../config.php');
require_once('locallib.php');
$tag = optional_param('tag', null, PARAM_TAG); // Tag to display.
$page = optional_param('page', 0, PARAM_INT);
if (!$oublog = $DB->get_record("oublog", array("global"=>1))) { // The personal blogs module.
throw new moodle_exception('personalblognotsetup', 'oublog');
}
if (!$cm = get_coursemodule_from_instance('oublog', $oublog->id)) {
throw new moodle_exception('invalidcoursemodule');
}
if (!$course = $DB->get_record("course", array("id" => $cm->course))) {
throw new moodle_exception('coursemisconf');
}
$postperpage = $oublog->postperpage;
$offset = $page * $postperpage;
$url = new moodle_url('/mod/oublog/allposts.php', array(
'page' => $page,
'tag' => $tag));
$PAGE->set_url($url);
$context = context_module::instance($cm->id);
if (!empty($CFG->oublogallpostslogin) && $oublog->maxvisibility == OUBLOG_VISIBILITY_PUBLIC) {
// Set blog visibility temporarily to loggedin user to force login to this page.
$oublog->maxvisibility = OUBLOG_VISIBILITY_LOGGEDINUSER;
oublog_check_view_permissions($oublog, $context, $cm);
$oublog->maxvisibility = OUBLOG_VISIBILITY_PUBLIC;
} else {
oublog_check_view_permissions($oublog, $context, $cm);
}
$oublogoutput = $PAGE->get_renderer('mod_oublog');
// Check security.
$blogtype = 'personal';
$returnurl = 'allposts.php?';
if ($tag) {
$returnurl .= '&tag='.urlencode($tag);
}
$canmanageposts = has_capability('mod/oublog:manageposts', $context);
$canaudit = has_capability('mod/oublog:audit', $context);
// Log view all site entries event.
$params = array(
'context' => $context,
'objectid' => $oublog->id,
'other' => array(
'pageid' => $page
)
);
$event = \mod_oublog\event\site_entries_viewed::create($params);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->trigger();
// Get strings.
$stroublog = get_string('modulename', 'oublog');
$strnewposts = get_string('newerposts', 'oublog');
$strolderposts = get_string('olderposts', 'oublog');
$strfeeds = get_string('feeds', 'oublog');
// Get Posts.
list($posts, $recordcount) = oublog_get_posts($oublog, $context, $offset, $cm, null, -1, null,
$tag, $canaudit, true);
$PAGE->set_title(format_string($oublog->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->navbar->add(format_string($oublog->name), new moodle_url('/mod/oublog/allposts.php'));
$CFG->additionalhtmlhead .= oublog_get_meta_tags($oublog, 'all', '', $cm);
// Generate extra navigation.
if ($offset) {
$a = new stdClass();
$a->from = ($offset+1);
$a->to = (($recordcount - $offset) > $postperpage) ? $offset + $postperpage : $recordcount;
$PAGE->navbar->add(get_string('extranavolderposts', 'oublog', $a));
} else if (!empty($tag)) {
$PAGE->navbar->add(get_string('extranavtag', 'oublog', $tag));
}
$url = new moodle_url("$CFG->wwwroot/course/mod.php",
array('update' => $cm->id, 'return' => true, 'sesskey' => sesskey()));
// The right column, BEFORE the middle-column.
if (isloggedin() and !isguestuser()) {
list($oublog, $oubloginstance) = oublog_get_personal_blog($USER->id);
$blogeditlink = "<br /><a href=\"view.php\" class=\"oublog-links\">$oubloginstance->name</a>";
$bc = new block_contents();
$bc->attributes['id'] = 'oublog-links';
$bc->attributes['class'] = 'oublog-sideblock block';
$bc->title = format_string($oublog->name);
$bc->content = $blogeditlink;
$PAGE->blocks->add_fake_block($bc, BLOCK_POS_RIGHT);
}
if ($oublog->statblockon) {
// 'Discovery' block.
$stats = array();
$stats[] = oublog_stats_output_participation($oublog, $cm, $oublogoutput, $course, true);
$stats[] = oublog_stats_output_commentpoststats($oublog, $cm, $oublogoutput, false, null, null,true);
$stats[] = oublog_stats_output_visitstats($oublog, $cm, $oublogoutput);
$stats[] = oublog_stats_output_poststats($oublog, $cm, $oublogoutput);
$stats[] = oublog_stats_output_commentstats($oublog, $cm, $oublogoutput);
$stats = $oublogoutput->render_stats_container('allposts', $stats);
$bc = new block_contents();
$bc->attributes['id'] = 'oublog-discover';
$bc->attributes['class'] = 'oublog-sideblock block';
$bc->title = get_string('discovery', 'oublog', oublog_get_displayname($oublog, true));
$bc->content = $stats;
if (!empty($stats)) {
$PAGE->blocks->add_fake_block($bc, BLOCK_POS_RIGHT);
}
}
// Must be called after add_fake_blocks.
echo $OUTPUT->header();
// Start main column.
print '<div id="middle-column" class="has-right-column">';
print $OUTPUT->skip_link_target();
// Renderer hook so extra info can be added to global blog pages in theme.
echo $oublogoutput->render_viewpage_prepost();
// Print blog posts.
if ($posts) {
echo "<div class='oublog-paging'>";
echo $OUTPUT->paging_bar($recordcount, $page, $postperpage, $returnurl);
echo '</div>';
echo '<div id="oublog-posts">';
$rowcounter = 1;
foreach ($posts as $post) {
$post->row = $rowcounter;
echo $oublogoutput->render_post($cm, $oublog, $post, $returnurl, $blogtype,
$canmanageposts, $canaudit, true, false);
$rowcounter++;
}
echo "<div class='oublog-paging'>";
echo $OUTPUT->paging_bar($recordcount, $page, $postperpage, $returnurl);
echo '</div>';
}
// Print information allowing the user to log in if necessary, or letting
// them know if there are no posts in the blog.
if (!isloggedin() || isguestuser()) {
print '<p class="oublog_loginnote">' . get_string('maybehiddenposts', 'oublog',
(object) array('link' => 'bloglogin.php', 'name' => oublog_get_displayname($oublog))) . '</p>';
} else if (!$posts) {
print '<p class="oublog_noposts">' . get_string('noposts', 'oublog', oublog_get_displayname($oublog)) . '</p>';
}
print '</div>';
// Finish the page.
echo $OUTPUT->footer();