forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·166 lines (136 loc) · 4.81 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
<?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
*/
if (!file_exists('../config.php')) {
header('Location: ../install.php');
die;
}
require_once('../config.php');
require_once($CFG->dirroot .'/blog/lib.php');
require_once($CFG->libdir .'/blocklib.php');
$id = optional_param('id', 0, PARAM_INT);
$limit = optional_param('limit', 0, PARAM_INT);
$start = optional_param('formstart', 0, PARAM_INT);
$userid = optional_param('userid',0,PARAM_INT);
$courseid = optional_param('courseid',SITEID,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);
if (empty($CFG->bloglevel)) {
error('Blogging is disabled!');
}
/// overwrite filter code here
if ($filtertype) {
switch ($filtertype) {
case 'site':
if ($filterselect) {
$userid = $filterselect;
} else {
$userid = 0;
}
$course = get_site();
$courseid = SITEID;
break;
case 'course':
if ($filterselect) {
$courseid = $filterselect;
$course = get_record('course','id',$courseid);
}
$userid =0;
$groupid = 0;
break;
case 'group':
if ($filterselect) {
$groupid = $filterselect;
$group = get_record('groups','id',$groupid);
$course = get_record('course','id',$group->courseid);
$courseid = $course->id;
} else {
$groupid = 0;
}
$userid = 0;
break;
case 'user':
if ($filterselect) {
$userid = $filterselect;
}
$groupid = 0;
break;
default:
break;
}
} else if ($userid) { // default to user
$filtertype = 'user';
$filterselect = $userid;
} else {
$filtertype = 'site';
$filterselect = '';
}
/// Rights checking.
switch ($filtertype) {
case 'site':
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
error('Site blogs is not enabled');
} else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
require_login();
}
break;
case 'course':
$context = get_context_instance(CONTEXT_COURSE, $courseid);
if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
error('Course blogs is not enabled');
}
break;
case 'group':
$context = get_context_instance(CONTEXT_GROUP, $groupid);
if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
error ('Group blogs is not enabled');
}
if (groupmode($course) == SEPARATEGROUPS &&
!has_capability('moodle/site:accessallgroups', $context)) {
if (!ismember($filterselect)) {
error ('You are not a member of this group');
}
}
/// check if user is editting teacher, or if spg, is member
break;
case 'user':
$context = get_context_instance(CONTEXT_USER, $userid);
if ($CFG->bloglevel < BLOG_USER_LEVEL) {
error ('Blogs is not enabled');
}
if ($CFG->bloglevel == BLOG_USER_LEVEL && $USER->id != $filterselect) {
error ('Under this setting, you can only view your own blogs');
}
/// check to see if the viewer is sharing no_group, visible group course.
/// if not , check if the viewer is in any spg group as the user
blog_user_can_view_user_post($filterselect);
break;
default:
break;
}
if (!has_capability('moodle/blog:view', $context)) {
error('You do not have the required permissions to to view blogs');
}
// first set the start and end day equal to the day argument passed in from the get vars
if ($limit == 'none') {
$limit = get_user_preferences('blogpagesize', 10);
}
include($CFG->dirroot .'/blog/header.php');
// prints the tabs
$currenttab = 'blogs';
$user = $USER;
if (!$course) {
$course = get_record('course', 'id', optional_param('courseid', SITEID, PARAM_INT));
}
$blogpage = optional_param('blogpage', 0, PARAM_INT);
blog_print_html_formatted_entries($userid, $postid, $limit, ($blogpage * $limit) ,$filtertype, $filterselect, $tagid, $tag, $filtertype, $filterselect);
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');
?>