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
|
|
|
|
*/
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
require_once(dirname(dirname(__FILE__)).'/config.php');
|
2006-03-10 06:53:01 +00:00
|
|
|
require_once($CFG->dirroot .'/blog/lib.php');
|
2009-09-04 00:36:43 +00:00
|
|
|
require_once($CFG->dirroot .'/blog/locallib.php');
|
|
|
|
require_once($CFG->dirroot .'/course/lib.php');
|
|
|
|
require_once($CFG->dirroot .'/tag/lib.php');
|
2006-03-10 06:53:01 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
$id = optional_param('id', null, PARAM_INT);
|
2006-10-03 21:07:13 +00:00
|
|
|
$start = optional_param('formstart', 0, PARAM_INT);
|
|
|
|
$tag = optional_param('tag', '', PARAM_NOTAGS);
|
2009-09-04 00:36:43 +00:00
|
|
|
$userid = optional_param('userid', null, PARAM_INT);
|
|
|
|
$tagid = optional_param('tagid', null, PARAM_INT);
|
|
|
|
$modid = optional_param('modid', null, PARAM_INT);
|
|
|
|
$entryid = optional_param('entryid', null, PARAM_INT);
|
|
|
|
$groupid = optional_param('groupid', null, PARAM_INT);
|
|
|
|
$courseid = optional_param('courseid', null, PARAM_INT); // needed for user tabs and course tracking
|
|
|
|
$search = optional_param('search', null, PARAM_RAW);
|
|
|
|
|
|
|
|
$url_params = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search');
|
|
|
|
foreach ($url_params as $var => $val) {
|
|
|
|
if (empty($val)) {
|
|
|
|
unset($url_params[$var]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$PAGE->set_url('blog/index.php', $url_params);
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2009-07-01 08:49:47 +00:00
|
|
|
//correct tagid if a text tag is provided as a param
|
|
|
|
if (!empty($tag)) { //text tag parameter takes precedence
|
|
|
|
if ($tagrec = $DB->get_record_sql("SELECT * FROM {tag} WHERE name LIKE ?", array($tag))) {
|
|
|
|
$tagid = $tagrec->id;
|
|
|
|
} else {
|
|
|
|
unset($tagid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
// add courseid if modid or groupid is specified: This is used for navigation and title
|
|
|
|
if (!empty($modid) && empty($courseid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
$courseid = $DB->get_field('course_modules', 'course', array('id'=>$modid));
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!empty($groupid) && empty($courseid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
$courseid = $DB->get_field('groups', 'courseid', array('id'=>$groupid));
|
|
|
|
}
|
2006-03-10 06:53:01 +00:00
|
|
|
|
2006-10-03 19:21:35 +00:00
|
|
|
if (empty($CFG->bloglevel)) {
|
2008-04-23 08:00:05 +00:00
|
|
|
print_error('blogdisable', 'blog');
|
2006-10-03 19:21:35 +00:00
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2008-04-30 04:46:46 +00:00
|
|
|
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
2009-09-04 00:36:43 +00:00
|
|
|
$tabsfile = null;
|
2006-10-03 21:07:13 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) {
|
|
|
|
if ($entryid) {
|
|
|
|
if (!$entryobject = $DB->get_record('post', array('module'=>'blog', 'id'=>$entryid))) {
|
2009-07-01 08:49:47 +00:00
|
|
|
print_error('nosuchentry', 'blog');
|
2008-04-22 05:56:21 +00:00
|
|
|
}
|
2009-09-04 00:36:43 +00:00
|
|
|
$userid = $entryobject->userid;
|
2006-03-10 06:53:01 +00:00
|
|
|
}
|
2009-07-01 08:49:47 +00:00
|
|
|
} else if (!$userid) {
|
|
|
|
// user might have capability to write blogs, but not read blogs at site level
|
|
|
|
// users might enter this url manually without parameters
|
|
|
|
$userid = $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
|
|
|
|
2009-07-01 08:49:47 +00:00
|
|
|
if (!empty($modid)) { //check mod access
|
|
|
|
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
|
|
|
|
print_error(get_string('nocourseblogs', 'blog'));
|
|
|
|
}
|
|
|
|
if (!$mod = $DB->get_record('course_modules', array('id' => $modid))) {
|
|
|
|
print_error(get_string('invalidmodid', 'blog'));
|
|
|
|
}
|
|
|
|
$courseid = $mod->course;
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if ((empty($courseid) ? true : $courseid == SITEID) && empty($userid)) { //check site access
|
2009-07-01 08:49:47 +00:00
|
|
|
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
|
|
|
|
print_error('siteblogdisable', 'blog');
|
|
|
|
}
|
|
|
|
if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
|
|
|
|
require_login();
|
|
|
|
}
|
|
|
|
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
|
|
|
print_error('cannotviewsiteblog', 'blog');
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2009-07-01 08:49:47 +00:00
|
|
|
$COURSE = $DB->get_record('course', array('format'=>'site'));
|
|
|
|
$courseid = $COURSE->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($courseid)) {
|
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
|
|
|
|
print_error('invalidcourseid');
|
|
|
|
}
|
|
|
|
|
|
|
|
$courseid = $course->id;
|
|
|
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
|
|
|
|
require_login($course);
|
|
|
|
|
|
|
|
if (!has_capability('moodle/blog:view', $coursecontext)) {
|
|
|
|
print_error('cannotviewcourseblog', 'blog');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$coursecontext = get_context_instance(CONTEXT_COURSE, SITEID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($groupid)) {
|
|
|
|
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
|
|
|
|
print_error('groupblogdisable', 'blog');
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2007-04-10 04:26:00 +00:00
|
|
|
// fix for MDL-9268
|
2009-07-01 08:49:47 +00:00
|
|
|
if (! $group = groups_get_group($groupid)) { //TODO:check.
|
|
|
|
print_error(get_string('invalidgroupid', 'blog'));
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2009-07-01 08:49:47 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
|
|
|
|
print_error(get_string('invalidcourseid', 'blog'));
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2009-07-01 08:49:47 +00:00
|
|
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
$courseid = $course->id;
|
|
|
|
require_login($course);
|
|
|
|
|
|
|
|
if (!has_capability('moodle/blog:view', $coursecontext)) {
|
|
|
|
print_error(get_string('cannotviewcourseorgroupblog', 'blog'));
|
|
|
|
}
|
2008-07-05 14:52:39 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (groups_get_course_groupmode($course) == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $coursecontext)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
if (!groups_is_member($groupid)) {
|
|
|
|
print_error('notmemberofgroup');
|
2006-10-06 10:11:52 +00:00
|
|
|
}
|
2009-07-01 08:49:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($user)) {
|
|
|
|
if ($CFG->bloglevel < BLOG_USER_LEVEL) {
|
|
|
|
print_error('blogdisable', 'blog');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
|
|
|
|
print_error('invaliduserid');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user->deleted) {
|
2009-09-04 00:36:43 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-08-06 08:26:20 +00:00
|
|
|
echo $OUTPUT->heading(get_string('userdeleted'));
|
2009-08-06 14:22:50 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-07-01 08:49:47 +00:00
|
|
|
die;
|
|
|
|
}
|
2006-04-18 01:59:13 +00:00
|
|
|
|
2009-07-01 08:49:47 +00:00
|
|
|
if ($USER->id == $userid) {
|
|
|
|
if (!has_capability('moodle/blog:create', $sitecontext)
|
2009-09-04 00:36:43 +00:00
|
|
|
&& !has_capability('moodle/blog:view', $sitecontext)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
print_error('donothaveblog', 'blog');
|
2007-10-07 09:27:13 +00:00
|
|
|
}
|
2009-07-01 08:49:47 +00:00
|
|
|
} else {
|
|
|
|
$personalcontext = get_context_instance(CONTEXT_USER, $userid);
|
2007-10-07 09:27:13 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!has_capability('moodle/blog:view', $sitecontext) && !has_capability('moodle/user:readuserblogs', $personalcontext)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
print_error('cannotviewuserblog', 'blog');
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!blog_user_can_view_user_entry($userid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
print_error('cannotviewcourseblog', 'blog');
|
|
|
|
}
|
|
|
|
}
|
2009-09-04 00:36:43 +00:00
|
|
|
$tabsfile = $CFG->dirroot . '/user/tabs.php';
|
2006-03-10 06:53:01 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
$courseid = (empty($courseid)) ? SITEID : $courseid;
|
2006-03-15 02:02:25 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!empty($courseid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
$filters['course'] = $courseid;
|
2009-09-04 00:36:43 +00:00
|
|
|
$PAGE->set_context(get_context_instance(CONTEXT_COURSE, $courseid));
|
2009-07-01 08:49:47 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!empty($modid)) {
|
|
|
|
$filters['module'] = $modid;
|
|
|
|
$PAGE->set_context(get_context_instance(CONTEXT_MODULE, $modid));
|
2009-07-01 08:49:47 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!empty($groupid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
$filters['group'] = $groupid;
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!empty($userid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
$filters['user'] = $userid;
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!empty($tagid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
$filters['tag'] = $tagid;
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!empty($search)) {
|
|
|
|
$filters['search'] = $search;
|
|
|
|
}
|
2006-03-10 06:53:01 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
if (!empty($entryid)) {
|
|
|
|
$filters['entry'] = $entryid;
|
|
|
|
}
|
2009-09-04 03:40:01 +00:00
|
|
|
$blogheaders = blog_get_headers();
|
2009-09-15 07:57:54 +00:00
|
|
|
blog_extend_settings_navigation($PAGE->settingsnav);
|
2009-09-04 00:36:43 +00:00
|
|
|
|
|
|
|
// prints the tabs
|
|
|
|
$showroles = !empty($userid);
|
|
|
|
$currenttab = 'blogs';
|
|
|
|
|
|
|
|
$user = $USER;
|
|
|
|
$userid = $USER->id;
|
|
|
|
|
|
|
|
// Unless this is a user's blog listing, the context is system
|
|
|
|
if (empty($entryid) && empty($modid) && empty($groupid)) {
|
|
|
|
$PAGE->set_context(get_context_instance(CONTEXT_USER, $userid));
|
|
|
|
}
|
|
|
|
|
2009-09-04 03:40:01 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-09-04 00:36:43 +00:00
|
|
|
|
|
|
|
if (!empty($tabsfile)) {
|
|
|
|
require_once($tabsfile);
|
|
|
|
}
|
2006-03-10 06:53:01 +00:00
|
|
|
|
2009-09-04 03:40:01 +00:00
|
|
|
echo $OUTPUT->heading($blogheaders['heading'], 2);
|
2006-05-02 02:44:35 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
$blog_listing = new blog_listing($filters);
|
|
|
|
$blog_listing->print_entries();
|
2006-03-10 06:53:01 +00:00
|
|
|
|
2009-08-06 14:22:50 +00:00
|
|
|
echo $OUTPUT->footer();
|
2006-08-14 07:25:18 +00:00
|
|
|
|
2009-09-04 00:36:43 +00:00
|
|
|
add_to_log($courseid, 'blog', 'view', 'index.php?entryid='.$entryid.'&tagid='.@$tagid.'&tag='.$tag, 'view blog entry');
|