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' );
2006-03-13 08:46:13 +00:00
$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 );
2006-09-29 20:54:15 +00:00
$tag = optional_param ( 'tag' , '' , PARAM_NOTAGS );
2006-03-13 08:46:13 +00:00
$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
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-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 ;
}
2006-08-08 05:13:06 +00:00
} else if ( $userid ) { // default to user
2006-03-10 06:53:01 +00:00
$filtertype = 'user' ;
$filterselect = $userid ;
} else {
$filtertype = 'site' ;
$filterselect = '' ;
}
2006-08-08 05:13:06 +00:00
/// Rights checking.
2006-03-10 06:53:01 +00:00
switch ( $filtertype ) {
case 'site' :
2006-08-08 05:13:06 +00:00
$context = get_context_instance ( CONTEXT_SYSTEM , SITEID );
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-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' :
2006-08-08 05:13:06 +00:00
$context = get_context_instance ( CONTEXT_COURSE , $courseid );
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
}
break ;
case 'group' :
2006-08-14 07:25:18 +00:00
$context = get_context_instance ( CONTEXT_GROUP , $groupid );
if ( $CFG -> bloglevel < BLOG_GROUP_LEVEL ) {
2006-08-08 05:13:06 +00:00
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 )) {
2006-08-08 05:13:06 +00:00
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' :
2006-09-15 14:09:16 +00:00
$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' );
}
2006-04-20 06:35:39 +00:00
// 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' ) {
2006-08-08 05:13:06 +00:00
$limit = get_user_preferences ( 'blogpagesize' , 10 );
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-08-08 05:13:06 +00:00
// 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 );
2006-04-12 02:05:46 +00:00
blog_print_html_formatted_entries ( $userid , $postid , $limit , ( $blogpage * $limit ) , $filtertype , $filterselect , $tagid , $tag , $filtertype , $filterselect );
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
?>