Formatting cleanups and comments
[moodle.git] / blog / index.php
CommitLineData
4a173181 1<?php // $Id$
2
3/**
4 * file index.php
5 * index page to view blogs. if no blog is specified then site wide entries are shown
6 * if a blog id is specified then the latest entries from that blog are shown
7 */
8
9if (!file_exists('../config.php')) {
10 header('Location: ../install.php');
11 die;
12}
4a173181 13
eccfc1ca 14require_once('../config.php');
4a173181 15require_once($CFG->dirroot .'/blog/lib.php');
16require_once($CFG->libdir .'/blocklib.php');
17
5c625033 18$id = optional_param('id', 0, PARAM_INT);
19$limit = optional_param('limit', 0, PARAM_INT);
e17426ca 20$start = optional_param('formstart', 0, PARAM_INT);
4a173181 21$userid = optional_param('userid',0,PARAM_INT);
9fad492e 22$courseid = optional_param('courseid',SITEID,PARAM_INT);
61ca5f8d 23$tag = s(urldecode(optional_param('tag', '', PARAM_NOTAGS)));
5c625033 24$tagid = optional_param('tagid', 0, PARAM_INT);
516194d0 25$postid = optional_param('postid',0,PARAM_INT);
9154b440 26$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
27$filterselect = optional_param('filterselect', 0, PARAM_INT);
4a173181 28
bbbf2d40 29
30
4a173181 31/// overwrite filter code here
4a173181 32
33if ($filtertype) {
34 switch ($filtertype) {
35
36 case 'site':
37 if ($filterselect) {
38 $userid = $filterselect;
39 } else {
40 $userid = 0;
41 }
42 $course = get_site();
43 $courseid = SITEID;
44 break;
45
46 case 'course':
47 if ($filterselect) {
48 $courseid = $filterselect;
49 $course = get_record('course','id',$courseid);
50 }
51 $userid =0;
52 $groupid = 0;
4a173181 53 break;
54
55 case 'group':
56 if ($filterselect) {
57 $groupid = $filterselect;
58 $group = get_record('groups','id',$groupid);
59 $course = get_record('course','id',$group->courseid);
60 $courseid = $course->id;
61 } else {
62 $groupid = 0;
63 }
64 $userid = 0;
4a173181 65 break;
66
67 case 'user':
68 if ($filterselect) {
69 $userid = $filterselect;
70 }
71 $groupid = 0;
4a173181 72 break;
73 default:
74 break;
75 }
76
bbbf2d40 77} else if ($userid) { // default to user
4a173181 78 $filtertype = 'user';
79 $filterselect = $userid;
80} else {
81 $filtertype = 'site';
82 $filterselect = '';
83}
84
bbbf2d40 85
86
87/// Rights checking.
4a173181 88
89switch ($filtertype) {
90 case 'site':
bbbf2d40 91 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
92 if ($CFG->bloglevel < BLOG_SITE_LEVEL &&
0468976c 93 !has_capability('moodle/site:config', $context)) {
bbbf2d40 94 error('Site blogs is not enabled');
9154b440 95 } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
4a173181 96 require_login();
97 }
98 break;
99 case 'course':
bbbf2d40 100 $context = get_context_instance(CONTEXT_COURSE, $courseid);
101 if ($CFG->bloglevel < BLOG_COURSE_LEVEL &&
0468976c 102 !has_capability('moodle/course:update', $context)) {
bbbf2d40 103 error('Course blogs is not enabled');
4a173181 104 }
0468976c 105 if (!has_capability('moodle/blog:readentry', $context)) {
bbbf2d40 106 error('You do not have the required permissions to to view course blogs');
4a173181 107 }
4a173181 108 break;
109 case 'group':
bbbf2d40 110 $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
111 $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
112 if ($CFG->bloglevel < BLOG_GROUP_LEVEL &&
0468976c 113 !has_capability('moodle/site:config', $sitecontext)) {
bbbf2d40 114 error ('Group blogs is not enabled');
4a173181 115 }
0468976c 116 if (!has_capability('moodle/course:update', $coursecontext) &&
bbbf2d40 117 groupmode($course) == SEPARATEGROUPS) {
4a173181 118 if (!ismember($filterselect)) {
bbbf2d40 119 error ('You are not a member of this group');
4a173181 120 }
121 }
122 /// check if user is editting teacher, or if spg, is member
123 break;
124 case 'user':
0468976c 125 $context = get_context_instance(CONTEXT_SYSTEM, $context->id); /// XXXXX TODO
bbbf2d40 126 if ($CFG->bloglevel < BLOG_USER_LEVEL &&
127 !has_capability('moodle/site:config', SITEID)) {
4a173181 128 error ('Blogs is not enabled');
129 }
bbbf2d40 130 if ($CFG->bloglevel == BLOG_USER_LEVEL && $USER->id != $filterselect &&
0468976c 131 !has_capability('moodle/site:config', $context)) {
f4c85f46 132 error ('Under this setting, you can only view your own blogs');
133 }
516194d0 134
4a173181 135 /// check to see if the viewer is sharing no_group, visible group course.
136 /// if not , check if the viewer is in any spg group as the user
f4c85f46 137 blog_user_can_view_user_post($filterselect);
138
4a173181 139 break;
140 default:
141 break;
142}
143
8c9814f9 144// first set the start and end day equal to the day argument passed in from the get vars
4a173181 145if ($limit == 'none') {
bbbf2d40 146 $limit = get_user_preferences('blogpagesize', 10);
4a173181 147}
f99fee6c 148
4a173181 149include($CFG->dirroot .'/blog/header.php');
150
bbbf2d40 151// prints the tabs
152$currenttab = 'blogs';
153$user = $USER;
154if (!$course) {
155 $course = get_record('course', 'id', optional_param('courseid', SITEID, PARAM_INT));
156}
157require_once($CFG->dirroot .'/user/tabs.php');
158
159$blogpage = optional_param('blogpage', 0, PARAM_INT);
c2ee4e87 160
161blog_print_html_formatted_entries($userid, $postid, $limit, ($blogpage * $limit) ,$filtertype, $filterselect, $tagid, $tag, $filtertype, $filterselect);
4a173181 162
06622f92 163add_to_log($courseid, 'blog', 'view', 'index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;postid='.$postid.'&amp;tagid='.$tagid.'&amp;tag='.$tag, 'view blog entry');
92a019ac 164
4a173181 165include($CFG->dirroot .'/blog/footer.php');
166
167?>