forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·173 lines (145 loc) · 5.69 KB
/
index.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
<?php // $Id$
/**
* file index.php
* index page to view blogs. if no blog is specified then site wide entries are shown
* if a blog id is specified then the latest entries from that blog are shown
*/
require_once('../config.php');
require_once($CFG->dirroot .'/blog/lib.php');
require_once($CFG->libdir .'/blocklib.php');
$id = optional_param('id', 0, PARAM_INT);
$start = optional_param('formstart', 0, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$tag = optional_param('tag', '', PARAM_NOTAGS);
$tagid = optional_param('tagid', 0, PARAM_INT);
$postid = optional_param('postid', 0, PARAM_INT);
$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
$filterselect = optional_param('filterselect', 0, PARAM_INT);
$edit = optional_param('edit', -1, PARAM_BOOL);
$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs and course tracking
if (empty($CFG->bloglevel)) {
print_error('blogdisable', 'blog');
}
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
// change block edit staus if not guest and logged in
if (isloggedin() and !isguest() and $edit != -1) {
$SESSION->blog_editing_enabled = $edit;
}
if (empty($filtertype)) {
if ($userid) { // default to user if specified
$filtertype = 'user';
$filterselect = $userid;
} else if (has_capability('moodle/blog:view', $sitecontext) and $CFG->bloglevel > BLOG_USER_LEVEL) {
if ($postid) {
$filtertype = 'user';
if (!$postobject = $DB->get_record('post', array('module'=>'blog', 'id'=>$postid))) {
print_error('nosuchentry', 'blog');
}
$filterselect = $postobject->userid;
} else {
$filtertype = 'site';
$filterselect = '';
}
} else {
// user might have capability to write blogs, but not read blogs at site level
// users might enter this url manually without parameters
$filtertype = 'user';
$filterselect = $USER->id;
}
}
/// check access and prepare filters
switch ($filtertype) {
case 'site':
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
print_error('siteblogdisable', 'blog');
}
if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
require_login();
}
if (!has_capability('moodle/blog:view', $sitecontext)) {
print_error('cannotviewsiteblog', 'blog');
}
break;
case 'course':
if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
print_error('courseblogdisable', 'blog');
}
if (!$course = $DB->get_record('course', array('id'=>$filterselect))) {
print_error('invalidcourseid');
}
$courseid = $course->id;
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
require_login($course);
if (!has_capability('moodle/blog:view', $coursecontext)) {
print_error('cannotviewcourseblog', 'blog');
}
break;
case 'group':
if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
print_error('groupblogdisable', 'blog');
}
// fix for MDL-9268
if (! $group = groups_get_group($filterselect)) { //TODO:check.
print_error('invalidgroupid');
}
if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
print_error('invalidcourseid');
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$courseid = $course->id;
require_login($course);
if (!has_capability('moodle/blog:view', $coursecontext)) {
print_error('cannotviewcourseorgroupblog', 'blog');
}
if (groups_get_course_groupmode($course) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
if (!groups_is_member($filterselect)) {
print_error('notmemberofgroup');
}
}
break;
case 'user':
if ($CFG->bloglevel < BLOG_USER_LEVEL) {
print_error('blogdisable', 'blog');
}
if (!$user = $DB->get_record('user', array('id'=>$filterselect))) {
print_error('invaliduserid');
}
if ($user->deleted) {
print_header();
print_heading(get_string('userdeleted'));
print_footer();
die;
}
if ($USER->id == $filterselect) {
if (!has_capability('moodle/blog:create', $sitecontext)
and !has_capability('moodle/blog:view', $sitecontext)) {
print_error('donothaveblog', 'blog');
}
} else {
$personalcontext = get_context_instance(CONTEXT_USER, $filterselect);
if (!has_capability('moodle/blog:view', $sitecontext)
and !has_capability('moodle/user:readuserblogs', $personalcontext)) {
print_error('cannotviewuserblog', 'blog');
}
if (!blog_user_can_view_user_post($filterselect)) {
print_error('cannotviewcourseblog', 'blog');
}
}
$userid = $filterselect;
if (!empty($courseid)) {
require_login($courseid);
}
break;
default:
print_error('incorrectblogfilter', 'blog');
break;
}
if (empty($courseid)) {
$courseid = SITEID;
}
include($CFG->dirroot .'/blog/header.php');
blog_print_html_formatted_entries($postid, $filtertype, $filterselect, $tagid, $tag);
add_to_log($courseid, 'blog', 'view', 'index.php?filtertype='.$filtertype.'&filterselect='.$filterselect.'&postid='.$postid.'&tagid='.$tagid.'&tag='.$tag, 'view blog entry');
include($CFG->dirroot .'/blog/footer.php');
?>