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
*/
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' );
2006-10-03 21:07:13 +00:00
$id = optional_param ( 'id' , 0 , PARAM_INT );
$start = optional_param ( 'formstart' , 0 , PARAM_INT );
$userid = optional_param ( 'userid' , 0 , 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 );
2006-03-13 06:05:44 +00:00
$filterselect = optional_param ( 'filterselect' , 0 , PARAM_INT );
2006-10-06 10:11:52 +00:00
2006-10-03 21:07:13 +00:00
$edit = optional_param ( 'edit' , - 1 , PARAM_BOOL );
2006-10-06 10:11:52 +00:00
$courseid = optional_param ( 'courseid' , 0 , PARAM_INT ); // needed for user tabs and course tracking
2006-03-10 06:53:01 +00:00
2006-10-03 19:21:35 +00:00
if ( empty ( $CFG -> bloglevel )) {
error ( 'Blogging is disabled!' );
}
2006-08-08 05:13:06 +00:00
2006-10-03 21:07:13 +00:00
$sitecontext = get_context_instance ( CONTEXT_SYSTEM , SITEID );
// change block edit staus if not guest and logged in
if ( isloggedin () and ! isguest () and $edit != - 1 ) {
$SESSION -> blog_editing_enabled = $edit ;
}
2006-10-06 10:11:52 +00:00
if ( empty ( $filtertype )) {
if ( $userid ) { // default to user if specified
$filtertype = 'user' ;
$filterselect = $userid ;
} else if ( has_capability ( 'moodle/blog:view' , $sitecontext ) and $CFG -> bloglevel > BLOG_USER_LEVEL ) {
$filtertype = 'site' ;
$filterselect = '' ;
} else {
// user might have capability to write blogs, but not read blogs at site level
// users might enter this url manually without parameters
$filtertype = 'user' ;
$filterselect = $USER -> id ;
2006-03-10 06:53:01 +00:00
}
}
2006-10-06 10:11:52 +00:00
/// check access and prepare filters
2006-03-10 06:53:01 +00:00
switch ( $filtertype ) {
2006-10-06 10:11:52 +00:00
2006-03-10 06:53:01 +00:00
case 'site' :
2006-08-14 07:25:18 +00:00
if ( $CFG -> bloglevel < BLOG_SITE_LEVEL ) {
2006-08-08 05:13:06 +00:00
error ( 'Site blogs is not enabled' );
2006-10-06 10:11:52 +00:00
}
if ( $CFG -> bloglevel < BLOG_GLOBAL_LEVEL ) {
2006-03-10 06:53:01 +00:00
require_login ();
}
2006-10-06 10:11:52 +00:00
if ( ! has_capability ( 'moodle/blog:view' , $sitecontext )) {
error ( 'You do not have the required permissions to view all site blogs' );
}
2006-03-10 06:53:01 +00:00
break ;
2006-10-06 10:11:52 +00:00
2006-03-10 06:53:01 +00:00
case 'course' :
2006-08-14 07:25:18 +00:00
if ( $CFG -> bloglevel < BLOG_COURSE_LEVEL ) {
2006-08-08 05:13:06 +00:00
error ( 'Course blogs is not enabled' );
2006-03-10 06:53:01 +00:00
}
2006-10-06 10:11:52 +00:00
if ( ! $course = get_record ( 'course' , 'id' , $filterselect )) {
error ( 'Incorrect course id specified' );
}
$courseid = $course -> id ;
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id );
2007-10-07 09:27:13 +00:00
require_login ( $course );
2007-03-15 06:13:12 +00:00
if ( ! has_capability ( 'moodle/blog:view' , $coursecontext )) {
2006-10-06 10:11:52 +00:00
error ( 'You do not have the required permissions to view blogs in this course' );
}
2006-03-10 06:53:01 +00:00
break ;
2006-10-06 10:11:52 +00:00
2006-03-10 06:53:01 +00:00
case 'group' :
2006-08-14 07:25:18 +00:00
if ( $CFG -> bloglevel < BLOG_GROUP_LEVEL ) {
2006-10-06 10:11:52 +00:00
error ( 'Group blogs is not enabled' );
}
2007-04-10 04:26:00 +00:00
// fix for MDL-9268
if ( ! $group = groups_get_group ( $filterselect )) { //TODO:check.
2006-10-06 10:11:52 +00:00
error ( 'Incorrect group id specified' );
}
if ( ! $course = get_record ( 'course' , 'id' , $group -> courseid )) {
error ( 'Incorrect course id specified' );
2006-03-10 06:53:01 +00:00
}
2006-10-06 10:11:52 +00:00
$coursecontext = get_context_instance ( CONTEXT_COURSE , $course -> id );
$courseid = $course -> id ;
2007-10-07 09:27:13 +00:00
require_login ( $course );
2006-10-06 10:11:52 +00:00
if ( ! has_capability ( 'moodle/blog:view' , $coursecontext )) {
error ( 'You do not have the required permissions to view blogs in this course/group' );
}
2007-09-08 20:53:05 +00:00
if ( groups_get_course_groupmode ( $course ) == SEPARATEGROUPS
2006-10-06 10:11:52 +00:00
and ! has_capability ( 'moodle/site:accessallgroups' , $coursecontext )) {
2007-08-15 20:21:01 +00:00
if ( ! groups_is_member ( $filterselect )) {
2006-10-06 10:11:52 +00:00
error ( 'You are not a member of this course group' );
2006-03-10 06:53:01 +00:00
}
}
2006-10-06 10:11:52 +00:00
2006-03-10 06:53:01 +00:00
break ;
2006-10-06 10:11:52 +00:00
2006-03-10 06:53:01 +00:00
case 'user' :
2006-08-14 07:25:18 +00:00
if ( $CFG -> bloglevel < BLOG_USER_LEVEL ) {
2006-10-06 10:11:52 +00:00
error ( 'Blogs is not enabled' );
2006-03-10 06:53:01 +00:00
}
2006-10-06 10:11:52 +00:00
if ( ! $user = get_record ( 'user' , 'id' , $filterselect )) {
error ( 'Incorrect user id' );
2006-04-18 01:59:13 +00:00
}
2006-10-06 10:11:52 +00:00
if ( $USER -> id == $filterselect ) {
if ( ! has_capability ( 'moodle/blog:create' , $sitecontext )
and ! has_capability ( 'moodle/blog:view' , $sitecontext )) {
2007-03-15 06:13:12 +00:00
error ( 'You do not have your own blog, sorry.' );
2006-10-06 10:11:52 +00:00
}
} else {
$personalcontext = get_context_instance ( CONTEXT_USER , $filterselect );
if ( ! has_capability ( 'moodle/blog:view' , $sitecontext )
and ! has_capability ( 'moodle/user:readuserblogs' , $personalcontext )) {
error ( 'You do not have the required permissions to read user blogs' );
}
if ( ! blog_user_can_view_user_post ( $filterselect )) {
error ( 'You can not view blog of this user, sorry.' );
}
}
$userid = $filterselect ;
2006-04-18 01:59:13 +00:00
2007-10-07 09:27:13 +00:00
if ( ! empty ( $courseid )) {
require_login ( $courseid );
}
2006-03-10 06:53:01 +00:00
break ;
2006-10-06 10:11:52 +00:00
2006-03-10 06:53:01 +00:00
default :
2006-10-06 10:11:52 +00:00
error ( 'Incorrect blog filter type specified' );
2006-03-10 06:53:01 +00:00
break ;
}
2006-10-06 10:11:52 +00:00
if ( empty ( $courseid )) {
$courseid = SITEID ;
2006-03-10 06:53:01 +00:00
}
2006-03-15 02:02:25 +00:00
2006-03-10 06:53:01 +00:00
include ( $CFG -> dirroot . '/blog/header.php' );
2006-10-06 10:11:52 +00:00
blog_print_html_formatted_entries ( $postid , $filtertype , $filterselect , $tagid , $tag );
2006-03-10 06:53:01 +00:00
2006-07-04 06:05:25 +00:00
add_to_log ( $courseid , 'blog' , 'view' , 'index.php?filtertype=' . $filtertype . '&filterselect=' . $filterselect . '&postid=' . $postid . '&tagid=' . $tagid . '&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
2006-09-15 14:09:16 +00:00
?>