moodle/blog/index.php

167 lines
4.8 KiB
PHP
Raw Normal View History

2006-03-10 06:53:01 +00:00
<?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;
}
2006-04-10 07:27:03 +00:00
require_once('../config.php');
2006-03-10 06:53:01 +00:00
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);
2006-03-15 02:17:35 +00:00
$start = optional_param('formstart', 0, PARAM_INT);
2006-03-10 06:53:01 +00:00
$userid = optional_param('userid',0,PARAM_INT);
2006-04-24 03:36:02 +00:00
$courseid = optional_param('courseid',SITEID,PARAM_INT);
$tag = optional_param('tag', '', PARAM_NOTAGS);
$tagid = optional_param('tagid', 0, PARAM_INT);
2006-03-17 07:38:08 +00:00
$postid = optional_param('postid',0,PARAM_INT);
2006-03-13 06:05:44 +00:00
$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
$filterselect = optional_param('filterselect', 0, PARAM_INT);
2006-03-10 06:53:01 +00:00
if (empty($CFG->bloglevel)) {
error('Blogging is disabled!');
}
2006-03-10 06:53:01 +00:00
/// 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
2006-03-10 06:53:01 +00:00
$filtertype = 'user';
$filterselect = $userid;
} else {
$filtertype = 'site';
$filterselect = '';
}
/// Rights checking.
2006-03-10 06:53:01 +00:00
switch ($filtertype) {
case 'site':
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
2006-08-14 07:25:18 +00:00
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
error('Site blogs is not enabled');
2006-03-13 06:05:44 +00:00
} else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
2006-03-10 06:53:01 +00:00
require_login();
}
break;
case 'course':
$context = get_context_instance(CONTEXT_COURSE, $courseid);
2006-08-14 07:25:18 +00:00
if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
error('Course blogs is not enabled');
2006-03-10 06:53:01 +00:00
}
break;
case 'group':
2006-08-14 07:25:18 +00:00
$context = get_context_instance(CONTEXT_GROUP, $groupid);
if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
error ('Group blogs is not enabled');
2006-03-10 06:53:01 +00:00
}
2006-08-14 07:25:18 +00:00
if (groupmode($course) == SEPARATEGROUPS &&
!has_capability('moodle/site:accessallgroups', $context)) {
2006-03-10 06:53:01 +00:00
if (!ismember($filterselect)) {
error ('You are not a member of this group');
2006-03-10 06:53:01 +00:00
}
}
/// check if user is editting teacher, or if spg, is member
break;
case 'user':
$context = get_context_instance(CONTEXT_USER, $userid);
2006-08-14 07:25:18 +00:00
if ($CFG->bloglevel < BLOG_USER_LEVEL) {
2006-03-10 06:53:01 +00:00
error ('Blogs is not enabled');
}
2006-08-14 07:25:18 +00:00
if ($CFG->bloglevel == BLOG_USER_LEVEL && $USER->id != $filterselect) {
2006-04-18 01:59:13 +00:00
error ('Under this setting, you can only view your own blogs');
}
2006-03-17 07:38:08 +00:00
2006-03-10 06:53:01 +00:00
/// 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
2006-04-18 01:59:13 +00:00
blog_user_can_view_user_post($filterselect);
2006-03-10 06:53:01 +00:00
break;
default:
break;
}
2006-08-14 07:25:18 +00:00
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
2006-03-10 06:53:01 +00:00
if ($limit == 'none') {
$limit = get_user_preferences('blogpagesize', 10);
2006-03-10 06:53:01 +00:00
}
2006-03-10 06:53:01 +00:00
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);
2006-03-10 06:53:01 +00:00
add_to_log($courseid, 'blog', 'view', 'index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;postid='.$postid.'&amp;tagid='.$tagid.'&amp;tag='.$tag, 'view blog entry');
2006-05-02 02:44:35 +00:00
2006-03-10 06:53:01 +00:00
include($CFG->dirroot .'/blog/footer.php');
2006-08-14 07:25:18 +00:00
?>