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);
|
|
|
|
|
2021-11-25 23:18:39 +08:00
|
|
|
if (isset($userid) && $USER->id == $userid && !$PAGE->has_secondary_navigation()) {
|
2015-03-19 10:59:27 +08:00
|
|
|
$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.
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('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!
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('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)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('blogdisable', 'blog');
|
2014-07-10 10:57:39 +08:00
|
|
|
}
|
|
|
|
|
2018-01-16 17:16:07 +01:00
|
|
|
list($courseid, $userid) = blog_validate_access($courseid, $modid, $groupid, $entryid, $userid);
|
2009-07-01 08:49:47 +00:00
|
|
|
|
2018-01-16 17:16:07 +01:00
|
|
|
$courseid = (empty($courseid)) ? SITEID : $courseid;
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2018-01-16 17:16:07 +01:00
|
|
|
if ($courseid != SITEID) {
|
|
|
|
$course = get_course($courseid);
|
2009-07-01 08:49:47 +00:00
|
|
|
require_login($course);
|
|
|
|
}
|
|
|
|
|
2010-09-17 11:25:48 +00:00
|
|
|
if (!empty($userid)) {
|
2022-06-07 08:19:13 +01:00
|
|
|
$user = core_user::get_user($userid, '*', MUST_EXIST);
|
2018-01-16 17:16:07 +01:00
|
|
|
$PAGE->navigation->extend_for_user($user);
|
2006-03-10 06:53:01 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 03:40:01 +00:00
|
|
|
$blogheaders = blog_get_headers();
|
2009-09-04 00:36:43 +00:00
|
|
|
|
2016-11-03 09:22:04 +08:00
|
|
|
$rsscontext = null;
|
|
|
|
$filtertype = null;
|
|
|
|
$thingid = null;
|
|
|
|
$rsstitle = '';
|
2010-07-28 02:32:11 +00:00
|
|
|
if ($CFG->enablerssfeeds) {
|
|
|
|
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();
|
2021-11-25 23:18:39 +08:00
|
|
|
|
2015-04-23 18:39:41 +08:00
|
|
|
if (!empty($user)) {
|
2022-06-07 08:19:13 +01:00
|
|
|
$backurl = new moodle_url('/user/view.php', ['id' => $user->id, 'course' => $courseid]);
|
|
|
|
echo $OUTPUT->single_button($backurl, get_string('back'), 'get', ['class' => 'mb-3']);
|
|
|
|
|
2015-04-23 18:39:41 +08:00
|
|
|
$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
|
|
|
|
2016-11-03 09:22:04 +08:00
|
|
|
if ($CFG->enablerssfeeds) {
|
|
|
|
blog_rss_print_link($rsscontext, $filtertype, $thingid, $tagid, get_string('rssfeed', 'blog'));
|
|
|
|
}
|
|
|
|
|
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();
|