had to change this a bit because blogs use different location to store rss, as it...
[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}
13require_once('../config.php');
14
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
22$userid = optional_param('userid',0,PARAM_INT);
23$groupid = optional_param('groupid',0,PARAM_INT);
24$courseid = optional_param('courseid',0,PARAM_INT);
61ca5f8d 25$tag = s(urldecode(optional_param('tag', '', PARAM_NOTAGS)));
5c625033 26$tagid = optional_param('tagid', 0, PARAM_INT);
9154b440 27
28$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
29$filterselect = optional_param('filterselect', 0, PARAM_INT);
4a173181 30
31/// overwrite filter code here
32/// the the following code does the rights checkings?
33
34if ($filtertype) {
35 switch ($filtertype) {
36
37 case 'site':
38 if ($filterselect) {
39 $userid = $filterselect;
40 } else {
41 $userid = 0;
42 }
43 $course = get_site();
44 $courseid = SITEID;
45 break;
46
47 case 'course':
48 if ($filterselect) {
49 $courseid = $filterselect;
50 $course = get_record('course','id',$courseid);
51 }
52 $userid =0;
53 $groupid = 0;
54
55 break;
56
57 case 'group':
58 if ($filterselect) {
59 $groupid = $filterselect;
60 $group = get_record('groups','id',$groupid);
61 $course = get_record('course','id',$group->courseid);
62 $courseid = $course->id;
63 } else {
64 $groupid = 0;
65 }
66 $userid = 0;
67
68 break;
69
70 case 'user':
71 if ($filterselect) {
72 $userid = $filterselect;
73 }
74 $groupid = 0;
75
76 break;
77 default:
78 break;
79 }
80
81} else if ($userid) { //default to user
82 $filtertype = 'user';
83 $filterselect = $userid;
84} else {
85 $filtertype = 'site';
86 $filterselect = '';
87}
88
89
90/// rights checking
91
92switch ($filtertype) {
93 case 'site':
9154b440 94 if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
4a173181 95 error ('site blogs is not enabled');
9154b440 96 } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
4a173181 97 require_login();
98 }
99 break;
100 case 'course':
9154b440 101 if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
4a173181 102 error ('course blogs is not enabled');
103 }
104
105 if (!isstudent($filterselect) && !isteacher($filterselect)) {
106 error ('you must be a student in this course to view course blogs');
107 }
108 /// check if viewer is student
109 break;
110 case 'group':
9154b440 111 if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
4a173181 112 error ('group blogs is not enabled');
113 }
114 if (!isteacheredit($course) and (groupmode($course) == SEPARATEGROUPS)) {
115 if (!ismember($filterselect)) {
116 error ('you are not in this group');
117 }
118 }
119 /// check if user is editting teacher, or if spg, is member
120 break;
121 case 'user':
9154b440 122 if ($CFG->bloglevel < BLOG_USER_LEVEL) {
4a173181 123 error ('Blogs is not enabled');
124 }
125 $canview = 0; //bad start
126
127 $usercourses = get_my_courses($filterselect);
128 foreach ($usercourses as $usercourse) {
129 /// if viewer and user sharing same non-spg course, then grant permission
130 if (groupmode($usercourse)!= SEPARATEGROUPS){
131 if (isstudent($usercourse->id) || isteacher($usercourse->id)) {
132 $canview = 1;
133 }
134 } else {
135 /// now we need every group the user is in, and check to see if view is a member
136 if ($usergroups = user_group($usercourse->id, $filterselect)) {
137 foreach ($usergroups as $usergroup) {
138 if (ismember($usergroup->id)) {
139 $canview = 1;
140 }
141 }
142 }
143 }
144 }
9154b440 145 if (!$canview && $CFG->bloglevel < BLOG_SITE_LEVEL) {
4a173181 146 error ('you can not view this user\'s blogs');
147 }
148 /// check to see if the viewer is sharing no_group, visible group course.
149 /// if not , check if the viewer is in any spg group as the user
150 break;
151 default:
152 break;
153}
154
4a173181 155//first set the start and end day equal to the day argument passed in from the get vars
4a173181 156if ($limit == 'none') {
157 $limit = get_user_preferences('blogpagesize',8);
158}
f99fee6c 159
f99fee6c 160$blogFilter =& new BlogFilter($userid, '', $limit, $start,$filtertype, $filterselect, $tagid, $tag);
4a173181 161//print_object($blogFilter); //debug
162
4a173181 163include($CFG->dirroot .'/blog/header.php');
164
165//prints the tabs
166$currenttab = 'blogs';
167$user = $USER;
168if (!$course) {
169 $course = get_record('course','id',optional_param('courseid', SITEID, PARAM_INT));
170}
171require_once($CFG->dirroot .'/user/tabs.php');
172
173blog_print_html_formatted_entries($blogFilter, $filtertype, $filterselect);
174
175include($CFG->dirroot .'/blog/footer.php');
176
177?>