Convert the text cache to use a blob, so that there are no character set
[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);
516194d0 27$postid = optional_param('postid',0,PARAM_INT);
9154b440 28
29$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
30$filterselect = optional_param('filterselect', 0, PARAM_INT);
4a173181 31
32/// overwrite filter code here
33/// the the following code does the rights checkings?
34
35if ($filtertype) {
36 switch ($filtertype) {
37
38 case 'site':
39 if ($filterselect) {
40 $userid = $filterselect;
41 } else {
42 $userid = 0;
43 }
44 $course = get_site();
45 $courseid = SITEID;
46 break;
47
48 case 'course':
49 if ($filterselect) {
50 $courseid = $filterselect;
51 $course = get_record('course','id',$courseid);
52 }
53 $userid =0;
54 $groupid = 0;
55
56 break;
57
58 case 'group':
59 if ($filterselect) {
60 $groupid = $filterselect;
61 $group = get_record('groups','id',$groupid);
62 $course = get_record('course','id',$group->courseid);
63 $courseid = $course->id;
64 } else {
65 $groupid = 0;
66 }
67 $userid = 0;
68
69 break;
70
71 case 'user':
72 if ($filterselect) {
73 $userid = $filterselect;
74 }
75 $groupid = 0;
76
77 break;
78 default:
79 break;
80 }
81
82} else if ($userid) { //default to user
83 $filtertype = 'user';
84 $filterselect = $userid;
85} else {
86 $filtertype = 'site';
87 $filterselect = '';
88}
89
90
91/// rights checking
92
93switch ($filtertype) {
94 case 'site':
9154b440 95 if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
4a173181 96 error ('site blogs is not enabled');
9154b440 97 } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
4a173181 98 require_login();
99 }
100 break;
101 case 'course':
9154b440 102 if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
4a173181 103 error ('course blogs is not enabled');
104 }
105
106 if (!isstudent($filterselect) && !isteacher($filterselect)) {
107 error ('you must be a student in this course to view course blogs');
108 }
109 /// check if viewer is student
110 break;
111 case 'group':
9154b440 112 if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
4a173181 113 error ('group blogs is not enabled');
114 }
115 if (!isteacheredit($course) and (groupmode($course) == SEPARATEGROUPS)) {
116 if (!ismember($filterselect)) {
117 error ('you are not in this group');
118 }
119 }
120 /// check if user is editting teacher, or if spg, is member
121 break;
122 case 'user':
9154b440 123 if ($CFG->bloglevel < BLOG_USER_LEVEL) {
4a173181 124 error ('Blogs is not enabled');
125 }
516194d0 126
127 blog_user_can_view_user_post($filterselect);
128
4a173181 129 /// check to see if the viewer is sharing no_group, visible group course.
130 /// if not , check if the viewer is in any spg group as the user
131 break;
132 default:
133 break;
134}
135
4a173181 136//first set the start and end day equal to the day argument passed in from the get vars
4a173181 137if ($limit == 'none') {
138 $limit = get_user_preferences('blogpagesize',8);
139}
f99fee6c 140
516194d0 141$blogFilter =& new BlogFilter($userid, $postid, $limit, $start,$filtertype, $filterselect, $tagid, $tag);
4a173181 142
4a173181 143include($CFG->dirroot .'/blog/header.php');
144
145//prints the tabs
146$currenttab = 'blogs';
147$user = $USER;
148if (!$course) {
149 $course = get_record('course','id',optional_param('courseid', SITEID, PARAM_INT));
150}
151require_once($CFG->dirroot .'/user/tabs.php');
152
153blog_print_html_formatted_entries($blogFilter, $filtertype, $filterselect);
154
155include($CFG->dirroot .'/blog/footer.php');
156
157?>