2009-11-01 13:10:07 +00:00
|
|
|
<?php
|
2014-07-13 18:43:09 +08:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2006-03-10 06:53:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2016-02-26 17:47:58 +11:00
|
|
|
require_once(__DIR__ . '/../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');
|
2010-03-15 07:59:28 +00:00
|
|
|
require_once($CFG->dirroot .'/comment/lib.php');
|
2006-03-10 06:53:01 +00:00
|
|
|
|
2009-10-30 07:25:50 +00:00
|
|
|
$id = optional_param('id', null, PARAM_INT);
|
|
|
|
$start = optional_param('formstart', 0, PARAM_INT);
|
|
|
|
$tag = optional_param('tag', '', PARAM_NOTAGS);
|
|
|
|
$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);
|
|
|
|
$search = optional_param('search', null, PARAM_RAW);
|
2009-09-04 00:36:43 +00:00
|
|
|
|
2010-03-15 07:59:28 +00:00
|
|
|
comment::init();
|
2009-09-16 10:05:34 +00:00
|
|
|
|
2015-08-28 16:13:26 +08:00
|
|
|
$urlparams = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search');
|
|
|
|
foreach ($urlparams as $var => $val) {
|
2009-09-04 00:36:43 +00:00
|
|
|
if (empty($val)) {
|
2015-08-28 16:13:26 +08:00
|
|
|
unset($urlparams[$var]);
|
2009-09-04 00:36:43 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-28 16:13:26 +08:00
|
|
|
$PAGE->set_url('/blog/index.php', $urlparams);
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2014-07-13 18:43:09 +08:00
|
|
|
// Correct tagid if a text tag is provided as a param.
|
2009-10-30 07:25:50 +00:00
|
|
|
if (!empty($tag)) {
|
2013-11-21 13:36:48 +08:00
|
|
|
if ($tagrec = $DB->get_record('tag', array('name' => $tag))) {
|
2009-07-01 08:49:47 +00:00
|
|
|
$tagid = $tagrec->id;
|
|
|
|
} else {
|
|
|
|
unset($tagid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 16:17:30 +08:00
|
|
|
// Set the userid to the entry author if we have the entry ID.
|
|
|
|
if ($entryid and !isset($userid)) {
|
|
|
|
$entry = new blog_entry($entryid);
|
|
|
|
$userid = $entry->userid;
|
|
|
|
}
|
|
|
|
|
2016-04-12 11:53:34 +08:00
|
|
|
if (isset($userid) && empty($courseid) && empty($modid)) {
|
2015-03-16 13:13:07 +08:00
|
|
|
$context = context_user::instance($userid);
|
2015-10-30 14:14:24 +00:00
|
|
|
} else if (!empty($courseid) && $courseid != SITEID) {
|
2015-04-23 18:39:41 +08:00
|
|
|
$context = context_course::instance($courseid);
|
2015-03-16 13:13:07 +08:00
|
|
|
} else {
|
|
|
|
$context = context_system::instance();
|
|
|
|
}
|
|
|
|
$PAGE->set_context($context);
|
|
|
|
|
2012-07-24 09:52:41 +08:00
|
|
|
$sitecontext = context_system::instance();
|
2011-03-20 13:34:51 +01:00
|
|
|
|
2015-03-19 10:59:27 +08:00
|
|
|
if (isset($userid) && $USER->id == $userid) {
|
|
|
|
$blognode = $PAGE->navigation->find('siteblog', null);
|
2015-05-22 15:34:09 +08:00
|
|
|
if ($blognode) {
|
|
|
|
$blognode->make_inactive();
|
|
|
|
}
|
2015-03-19 10:59:27 +08:00
|
|
|
}
|
|
|
|
|
2014-07-13 18:43:09 +08:00
|
|
|
// Check basic permissions.
|
2011-03-20 13:34:51 +01:00
|
|
|
if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) {
|
2014-07-13 18:43:09 +08:00
|
|
|
// Everybody can see anything - no login required unless site is locked down using forcelogin.
|
2011-03-20 13:34:51 +01:00
|
|
|
if ($CFG->forcelogin) {
|
|
|
|
require_login();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ($CFG->bloglevel == BLOG_SITE_LEVEL) {
|
2014-07-13 18:43:09 +08:00
|
|
|
// Users must log in and can not be guests.
|
2011-03-20 13:34:51 +01:00
|
|
|
require_login();
|
|
|
|
if (isguestuser()) {
|
2014-07-13 18:43:09 +08:00
|
|
|
// They must have entered the url manually.
|
2016-08-15 21:46:48 -04:00
|
|
|
print_error('noguest');
|
2011-03-20 13:34:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if ($CFG->bloglevel == BLOG_USER_LEVEL) {
|
2014-07-13 18:43:09 +08:00
|
|
|
// Users can see own blogs only! with the exception of people with special cap.
|
2011-03-20 13:34:51 +01:00
|
|
|
require_login();
|
|
|
|
|
|
|
|
} else {
|
2014-07-13 18:43:09 +08:00
|
|
|
// Weird!
|
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
|
|
|
|
2014-07-10 10:57:39 +08:00
|
|
|
if (empty($CFG->enableblogs)) {
|
|
|
|
print_error('blogdisable', 'blog');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add courseid if modid or groupid is specified: This is used for navigation and title.
|
|
|
|
if (!empty($modid) && empty($courseid)) {
|
|
|
|
$courseid = $DB->get_field('course_modules', 'course', array('id' => $modid));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($groupid) && empty($courseid)) {
|
|
|
|
$courseid = $DB->get_field('groups', 'courseid', array('id' => $groupid));
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-08-28 16:13:26 +08:00
|
|
|
if (!$entryobject = $DB->get_record('post', array('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) {
|
|
|
|
$userid = $USER->id;
|
2006-03-10 06:53:01 +00:00
|
|
|
}
|
|
|
|
|
2009-10-30 07:25:50 +00:00
|
|
|
if (!empty($modid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
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-10-30 07:25:50 +00:00
|
|
|
if ((empty($courseid) ? true : $courseid == SITEID) && empty($userid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
|
|
|
|
print_error('siteblogdisable', 'blog');
|
|
|
|
}
|
|
|
|
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
|
|
|
print_error('cannotviewsiteblog', 'blog');
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2015-08-28 16:13:26 +08:00
|
|
|
$COURSE = $DB->get_record('course', array('format' => 'site'));
|
2009-07-01 08:49:47 +00:00
|
|
|
$courseid = $COURSE->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($courseid)) {
|
2015-08-28 16:13:26 +08:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
2009-07-01 08:49:47 +00:00
|
|
|
print_error('invalidcourseid');
|
|
|
|
}
|
|
|
|
|
|
|
|
$courseid = $course->id;
|
|
|
|
require_login($course);
|
|
|
|
|
2013-04-04 16:27:34 +08:00
|
|
|
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
print_error('cannotviewcourseblog', 'blog');
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-24 09:52:41 +08:00
|
|
|
$coursecontext = context_course::instance(SITEID);
|
2009-07-01 08:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($groupid)) {
|
|
|
|
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
|
|
|
|
print_error('groupblogdisable', 'blog');
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2009-10-30 07:25:50 +00:00
|
|
|
if (! $group = groups_get_group($groupid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
print_error(get_string('invalidgroupid', 'blog'));
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2015-08-28 16:13:26 +08:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $group->courseid))) {
|
2012-06-27 13:29:51 +08:00
|
|
|
print_error('invalidcourseid');
|
2009-07-01 08:49:47 +00:00
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2012-07-24 09:52:41 +08:00
|
|
|
$coursecontext = context_course::instance($course->id);
|
2009-07-01 08:49:47 +00:00
|
|
|
$courseid = $course->id;
|
|
|
|
require_login($course);
|
|
|
|
|
2013-04-04 16:27:34 +08:00
|
|
|
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 11:25:48 +00:00
|
|
|
if (!empty($userid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
if ($CFG->bloglevel < BLOG_USER_LEVEL) {
|
|
|
|
print_error('blogdisable', 'blog');
|
|
|
|
}
|
|
|
|
|
2015-08-28 16:13:26 +08:00
|
|
|
if (!$user = $DB->get_record('user', array('id' => $userid))) {
|
2009-07-01 08:49:47 +00:00
|
|
|
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 {
|
2013-03-08 09:37:21 +08:00
|
|
|
if (!has_capability('moodle/blog:view', $sitecontext) || !blog_user_can_view_user_entry($userid)) {
|
2009-07-01 08:49:47 +00:00
|
|
|
print_error('cannotviewcourseblog', 'blog');
|
|
|
|
}
|
2012-05-24 09:40:59 +07:00
|
|
|
|
|
|
|
$PAGE->navigation->extend_for_user($user);
|
2009-07-01 08:49:47 +00:00
|
|
|
}
|
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-07-01 08:49:47 +00:00
|
|
|
|
2009-09-04 03:40:01 +00:00
|
|
|
$blogheaders = blog_get_headers();
|
2009-09-04 00:36:43 +00:00
|
|
|
|
2010-07-28 02:32:11 +00:00
|
|
|
if ($CFG->enablerssfeeds) {
|
2011-12-09 12:01:02 +08:00
|
|
|
$rsscontext = null;
|
|
|
|
$filtertype = null;
|
|
|
|
$thingid = null;
|
2010-07-28 02:32:11 +00:00
|
|
|
list($thingid, $rsscontext, $filtertype) = blog_rss_get_params($blogheaders['filters']);
|
2011-12-09 12:01:02 +08:00
|
|
|
if (empty($rsscontext)) {
|
2013-04-04 16:27:34 +08:00
|
|
|
$rsscontext = context_system::instance();
|
2011-12-09 12:01:02 +08:00
|
|
|
}
|
2010-07-28 02:32:11 +00:00
|
|
|
$rsstitle = $blogheaders['heading'];
|
|
|
|
|
2014-07-13 18:43:09 +08:00
|
|
|
// Check we haven't started output by outputting an error message.
|
2010-07-28 02:32:11 +00:00
|
|
|
if ($PAGE->state == moodle_page::STATE_BEFORE_HEADER) {
|
|
|
|
blog_rss_add_http_header($rsscontext, $rsstitle, $filtertype, $thingid, $tagid);
|
|
|
|
}
|
|
|
|
}
|
2015-04-23 18:39:41 +08:00
|
|
|
|
|
|
|
$usernode = $PAGE->navigation->find('user'.$userid, null);
|
|
|
|
if ($usernode && $courseid != SITEID) {
|
|
|
|
$courseblogsnode = $PAGE->navigation->find('courseblogs', null);
|
|
|
|
if ($courseblogsnode) {
|
|
|
|
$courseblogsnode->remove();
|
|
|
|
}
|
|
|
|
$blogurl = new moodle_url($PAGE->url);
|
|
|
|
$blognode = $usernode->add(get_string('blogscourse', 'blog'), $blogurl);
|
|
|
|
$blognode->make_active();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($courseid != SITEID) {
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
if (!empty($user)) {
|
|
|
|
$headerinfo = array('heading' => fullname($user), 'user' => $user);
|
|
|
|
echo $OUTPUT->context_header($headerinfo, 2);
|
|
|
|
}
|
|
|
|
} else if (isset($userid)) {
|
2015-03-16 13:13:07 +08:00
|
|
|
$PAGE->set_heading(fullname($user));
|
2015-04-23 18:39:41 +08:00
|
|
|
echo $OUTPUT->header();
|
|
|
|
} else if ($courseid == SITEID) {
|
|
|
|
echo $OUTPUT->header();
|
2015-03-16 13:13:07 +08:00
|
|
|
}
|
2010-07-28 02:32:11 +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-10-30 07:25:50 +00:00
|
|
|
$bloglisting = new blog_listing($blogheaders['filters']);
|
|
|
|
$bloglisting->print_entries();
|
2006-03-10 06:53:01 +00:00
|
|
|
|
2009-08-06 14:22:50 +00:00
|
|
|
echo $OUTPUT->footer();
|
2013-11-21 15:36:35 +08:00
|
|
|
$eventparams = array(
|
|
|
|
'other' => array('entryid' => $entryid, 'tagid' => $tagid, 'userid' => $userid, 'modid' => $modid, 'groupid' => $groupid,
|
|
|
|
'search' => $search, 'fromstart' => $start)
|
|
|
|
);
|
|
|
|
if (!empty($userid)) {
|
|
|
|
$eventparams['relateduserid'] = $userid;
|
|
|
|
}
|
|
|
|
$eventparams['other']['courseid'] = ($courseid === SITEID) ? 0 : $courseid;
|
|
|
|
$event = \core\event\blog_entries_viewed::create($eventparams);
|
|
|
|
$event->trigger();
|