mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-19676 Removed course and group visibility settings for blog
This commit is contained in:
parent
6e155d1c00
commit
856b6fe6d2
4 changed files with 405 additions and 159 deletions
|
@ -1,6 +1,7 @@
|
||||||
<?php //$Id$
|
<?php //$Id$
|
||||||
|
|
||||||
require_once($CFG->dirroot .'/blog/lib.php');
|
require_once($CFG->dirroot .'/blog/lib.php');
|
||||||
|
require_once($CFG->dirroot .'/course/lib.php');
|
||||||
|
|
||||||
class block_blog_menu extends block_base {
|
class block_blog_menu extends block_base {
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ class block_blog_menu extends block_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_content() {
|
function get_content() {
|
||||||
global $CFG, $USER;
|
global $CFG, $USER, $COURSE, $DB, $PAGE;
|
||||||
|
|
||||||
if (empty($CFG->bloglevel)) {
|
if (empty($CFG->bloglevel)) {
|
||||||
$this->content->text = '';
|
$this->content->text = '';
|
||||||
|
@ -40,77 +41,249 @@ class block_blog_menu extends block_base {
|
||||||
$this->content = new stdClass;
|
$this->content = new stdClass;
|
||||||
$this->content->footer = '';
|
$this->content->footer = '';
|
||||||
|
|
||||||
//if ( blog_isLoggedIn() && !isguest() ) {
|
if (empty($this->instance)) {
|
||||||
$courseviewlink = '';
|
// Either we're being asked for content without
|
||||||
$addentrylink = '';
|
// an associated instance of the Blog module has never been installed.
|
||||||
$coursearg = '';
|
$this->content->text = $output;
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
//discover context for pre-loaded associations
|
||||||
|
$basefilters = array();
|
||||||
|
if(!empty($COURSE)) $courseid = $COURSE->id;
|
||||||
|
switch($PAGE->pagetype) {
|
||||||
|
case PAGE_COURSE_VIEW:
|
||||||
|
$courseid = $PAGE->courserecord->id;
|
||||||
|
$basefilters['courseid'] = $courseid;
|
||||||
|
break;
|
||||||
|
case PAGE_BLOG_VIEW:
|
||||||
|
$basefilters = $PAGE->filters;
|
||||||
|
if(!empty($PAGE->filters['course']))
|
||||||
|
$courseid = $PAGE->filters['course'];
|
||||||
|
if(!empty($PAGE->filters['mod']))
|
||||||
|
$modid = $PAGE->filters['mod'];
|
||||||
|
if(!empty($PAGE->filters['user']))
|
||||||
|
$userid = $PAGE->filters['user'];
|
||||||
|
if(!empty($PAGE->filters['group']))
|
||||||
|
$groupid = $PAGE->filters['group'];
|
||||||
|
if(!empty($PAGE->filters['tag']))
|
||||||
|
$tagid = $PAGE->filters['tag'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$addentrylink = '';
|
||||||
|
$blogprefslink = '';
|
||||||
|
$myviewlink = '';
|
||||||
|
$siteviewlink = '';
|
||||||
|
$courseviewlink = '';
|
||||||
|
$modviewlink = '';
|
||||||
|
$groupviewlink = '';
|
||||||
|
$userviewlink = '';
|
||||||
|
$tagviewlink = '';
|
||||||
|
$coursepopuplink = '';
|
||||||
|
$modpopuplink = '';
|
||||||
|
$grouppopuplink = '';
|
||||||
|
$userspopuplink = '';
|
||||||
|
|
||||||
|
//create basic blog preference links
|
||||||
|
$coursearg = '';
|
||||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||||
|
|
||||||
if ($this->page->course->id != SITEID) {
|
if ($this->page->course->id != SITEID) {
|
||||||
|
|
||||||
$incoursecontext = true;
|
$incoursecontext = true;
|
||||||
$curcontext = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
|
$curcontext = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
|
||||||
} else {
|
} else {
|
||||||
$incoursecontext = false;
|
$incoursecontext = false;
|
||||||
$curcontext = $sitecontext;
|
$curcontext = $sitecontext;
|
||||||
}
|
}
|
||||||
|
|
||||||
$canviewblogs = has_capability('moodle/blog:view', $curcontext);
|
$canviewblogs = has_capability('moodle/blog:view', $curcontext);
|
||||||
|
|
||||||
/// Accessibility: markup as a list.
|
|
||||||
|
|
||||||
if ( (isloggedin() && !isguest()) && $incoursecontext
|
if ( (isloggedin() && !isguest()) && $incoursecontext
|
||||||
&& $CFG->bloglevel >= BLOG_COURSE_LEVEL && $canviewblogs) {
|
&& $CFG->bloglevel >= BLOG_SITE_LEVEL && $canviewblogs) {
|
||||||
|
|
||||||
$coursearg = '&courseid='.$this->page->course->id;
|
$coursearg = '&courseid='.$this->page->course->id;
|
||||||
|
if(!empty($modid)) $coursearg .= '&modid='.$modid;
|
||||||
|
|
||||||
// a course is specified
|
// a course is specified
|
||||||
|
|
||||||
$courseviewlink = '<li><a href="'. $CFG->wwwroot .'/blog/index.php?filtertype=course&filterselect='. $this->page->course->id .'">';
|
$courseviewlink = '<li><a href="'. $CFG->wwwroot .'/blog/index.php?filtertype=course&filterselect='. $this->page->course->id .'">';
|
||||||
$courseviewlink .= get_string('viewcourseentries', 'blog') ."</a></li>\n";
|
$courseviewlink .= get_string('viewcourseentries', 'blog') ."</a></li>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$blogmodon = false;
|
$blogmodon = false;
|
||||||
|
|
||||||
if ( (isloggedin() && !isguest())
|
if ( (isloggedin() && !isguest())
|
||||||
&& (!$blogmodon || ($blogmodon && $coursearg != ''))
|
&& (!$blogmodon || ($blogmodon && $coursearg != ''))
|
||||||
&& $CFG->bloglevel >= BLOG_USER_LEVEL ) {
|
&& $CFG->bloglevel >= BLOG_USER_LEVEL ) {
|
||||||
|
// create the Add entry link
|
||||||
// show Add entry link
|
|
||||||
if (has_capability('moodle/blog:create', $sitecontext)) {
|
if (has_capability('moodle/blog:create', $sitecontext)) {
|
||||||
$addentrylink = '<li><a href="'. $CFG->wwwroot. '/blog/edit.php?action=add'
|
$addentrylink = '<li><a href="'. $CFG->wwwroot. '/blog/edit.php?action=add'
|
||||||
.$coursearg.'">'.get_string('addnewentry', 'blog') ."</a></li>\n";
|
.$coursearg.'">'.get_string('addnewentry', 'blog') ."</a></li>\n";
|
||||||
}
|
}
|
||||||
// show View my entries link
|
// create the link to manage blog prefs
|
||||||
$addentrylink .= '<li><a href="'. $CFG->wwwroot .'/blog/index.php?userid='.
|
$blogprefslink = '<li><a href="'. $CFG->wwwroot. '/blog/preferences.php?userid='.
|
||||||
$userBlog->userid.'">'.get_string('viewmyentries', 'blog').
|
|
||||||
"</a></li>\n";
|
|
||||||
|
|
||||||
// show link to manage blog prefs
|
|
||||||
$addentrylink .= '<li><a href="'. $CFG->wwwroot. '/blog/preferences.php?userid='.
|
|
||||||
$userBlog->userid . $coursearg .'">'.
|
$userBlog->userid . $coursearg .'">'.
|
||||||
get_string('blogpreferences', 'blog')."</a></li>\n";
|
get_string('blogpreferences', 'blog')."</a></li>\n";
|
||||||
|
// create the View my entries link
|
||||||
$output = $addentrylink;
|
$myviewlink = '<li><a href="'.blog_get_blogs_url(array('user'=>$USER->id)).'">'.
|
||||||
$output .= $courseviewlink;
|
//'<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />'.fullname($USER).
|
||||||
|
get_string('viewmyentries', 'blog').
|
||||||
|
"</a></li>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// show View site entries link
|
// create the View site entries link
|
||||||
if ($CFG->bloglevel >= BLOG_SITE_LEVEL && $canviewblogs) {
|
if ($CFG->bloglevel >= BLOG_SITE_LEVEL && $canviewblogs) {
|
||||||
$output .= '<li><a href="'. $CFG->wwwroot .'/blog/index.php?filtertype=site&">';
|
$siteviewlink .= '<li><a href="'.blog_get_blogs_url(array()).'">'.
|
||||||
$output .= get_string('viewsiteentries', 'blog')."</a></li>\n";
|
get_string('viewsiteentries', 'blog').
|
||||||
|
//$DB->get_field('course', 'shortname', array('format'=>'site')).
|
||||||
|
"</a></li>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// took out tag management interface/link, should use tag/manage.php
|
//create 'view blogs for course' link
|
||||||
|
if($incoursecontext and (!empty($modid) or !empty($userid) or !empty($tagid) or !empty($groupid) or
|
||||||
|
$PAGE->pagetype == PAGE_COURSE_VIEW)
|
||||||
|
and $CFG->bloglevel >= BLOG_SITE_LEVEL and $canviewblogs) {
|
||||||
|
$courseviewlink = '<li><a href="'. blog_get_blogs_url(array('course'=>$courseid)) .'">'
|
||||||
|
.'<img src="'.$CFG->pixpath.'/i/course.gif" class="icon" alt="" />'.
|
||||||
|
$DB->get_field('course', 'shortname', array('id'=>$courseid)) ."</a></li>\n";
|
||||||
|
}
|
||||||
|
|
||||||
// show Help with blogging link
|
//create 'view blogs for user' link
|
||||||
//$output .= '<li><a href="'. $CFG->wwwroot .'/help.php?module=blog&file=user.html">';
|
if(!empty($userid) and $userid != $USER->id and (!empty($modid) or !empty($courseid) or !empty($tagid) or !empty($groupid))
|
||||||
//$output .= get_string('helpblogging', 'blog') ."</a></li>\n";
|
and $canviewblogs) {
|
||||||
//} else {
|
$userviewlink = '<li><a href="'. blog_get_blogs_url(array('user'=>$userid)) .'">'.
|
||||||
// $output = ''; //guest users and users who are not logged in do not get menus
|
'<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />'.
|
||||||
//}
|
$DB->get_field('user', 'username', array('id'=>$userid)).
|
||||||
|
"</a></li>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//create 'view blogs for mod' link
|
||||||
|
if(!empty($modid) and (!empty($groupid) or !empty($userid) or !empty($tagid))
|
||||||
|
and $CFG->bloglevel >= BLOG_SITE_LEVEL and $canviewblogs) {
|
||||||
|
$filtercontext = get_context_instance(CONTEXT_MODULE, $modid);
|
||||||
|
$modinfo = $DB->get_record('course_modules', array('id' => $filtercontext->instanceid));
|
||||||
|
$modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module));
|
||||||
|
$modviewlink = '<li><a href="'. blog_get_blogs_url(array('mod'=>$modid)) .'">'.
|
||||||
|
'<img src="'.$CFG->wwwroot.'/mod/'.$modname.'/icon.gif" border=0 alt="">'.
|
||||||
|
$DB->get_field($modname, 'name', array('id' => $modinfo->instance)).
|
||||||
|
"</a></li>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//create 'view blogs for group' link
|
||||||
|
if(!empty($groupid) and (!empty($modid) or !empty($tagid) or !empty($userid))
|
||||||
|
and $CFG->bloglevel >= BLOG_SITE_LEVEL and $canviewblogs) {
|
||||||
|
$groupviewlink = '<li><a href="'. blog_get_blogs_url(array('group'=>$groupid)) .'">'.
|
||||||
|
'<img src="'.$CFG->pixpath.'/i/group.gif" class="icon" alt="" />'.
|
||||||
|
$DB->get_field('groups', 'name', array('id'=>$groupid)) ."</a></li>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//create 'view blogs for tag' link
|
||||||
|
if(!empty($tagid) && (!empty($modid) or !empty($userid) or !empty($courseid) or !empty($groupid)) and $canviewblogs) {
|
||||||
|
$tagviewlink = '<li>'.get_string('tag', 'tag').': <a href="'. blog_get_blogs_url(array('tag'=>$tagid)) .'">'.
|
||||||
|
$DB->get_field('tag', 'name', array('id'=>$tagid))."</a></li>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//create 'view blogs for this site's courses' link
|
||||||
|
if($canviewblogs and $CFG->bloglevel >= BLOG_SITE_LEVEL) {
|
||||||
|
$courseoptions = array();
|
||||||
|
if(!empty($courseid)) {
|
||||||
|
if($courseid != SITEID) {
|
||||||
|
$newfilters = $basefilters;
|
||||||
|
unset($newfilters['course']);
|
||||||
|
unset($newfilters['mod']);
|
||||||
|
unset($newfilters['group']);
|
||||||
|
$courseoptions = array(blog_get_blogs_url($newfilters) => 'none');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($DB->get_records('course', array()) as $course) {
|
||||||
|
if($course->id != SITEID) {
|
||||||
|
$newfilters = $basefilters;
|
||||||
|
if(!empty($courseid)) {
|
||||||
|
if($course->id != $courseid) {
|
||||||
|
unset($newfilters['mod']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$newfilters['course'] = $course->id;
|
||||||
|
$courseoptions[blog_get_blogs_url($newfilters)] = $course->shortname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$coursepopuplink = '<li>'.popup_form('', $courseoptions, 'view_course_blogs', blog_get_blogs_url($basefilters),
|
||||||
|
get_string('course'),'', '', true) . "</li>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//create 'view blogs for this course's mods' link
|
||||||
|
if(!empty($courseid) and $canviewblogs and $CFG->bloglevel >= BLOG_SITE_LEVEL) {
|
||||||
|
$modnames = array();
|
||||||
|
$modnamesplural = array();
|
||||||
|
$modnamesused = array();
|
||||||
|
$modoptions = array();
|
||||||
|
if(!empty($modid)) {
|
||||||
|
$newfilters = $basefilters;
|
||||||
|
unset($newfilters['mod']);
|
||||||
|
$modoptions = array(blog_get_blogs_url($newfilters) => 'none');
|
||||||
|
}
|
||||||
|
get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
|
||||||
|
foreach($mods as $i => $mod) {
|
||||||
|
$newfilters = $basefilters;
|
||||||
|
$newfilters['mod'] = $mod->id;
|
||||||
|
$modoptions[blog_get_blogs_url($newfilters)] = $DB->get_field($mod->modname, 'name', array('id' => $mod->instance));
|
||||||
|
}
|
||||||
|
$modpopuplink = '<li>'.popup_form('', $modoptions, 'view_mod_blogs', blog_get_blogs_url($basefilters),
|
||||||
|
get_string('resource').'/'.get_string('activity'),
|
||||||
|
'', '', true)."</li>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//create 'view blogs for this course's groups link
|
||||||
|
if($incoursecontext and $canviewblogs and $CFG->bloglevel >= BLOG_SITE_LEVEL) {
|
||||||
|
$groupoptions = array();
|
||||||
|
if(!empty($groupid)) {
|
||||||
|
$newfilters = $basefilters;
|
||||||
|
unset($newfilters['group']);
|
||||||
|
$groupoptions = array(blog_get_blogs_url($newfilters) => 'none');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($DB->get_records('groups', array('courseid'=>$courseid)) as $group) {
|
||||||
|
$newfilters = $basefilters;
|
||||||
|
$newfilters['group'] = $group->id;
|
||||||
|
$groupoptions[blog_get_blogs_url($newfilters)] = $group->name;
|
||||||
|
}
|
||||||
|
$grouppopuplink = '<li>'.popup_form('', $groupoptions, 'view_group_blogs', blog_get_blogs_url($basefilters),
|
||||||
|
get_string('group'),'', '', true)."</li>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//create 'view blogs for this course/group's users link
|
||||||
|
if(!empty($courseid) and $canviewblogs and $CFG->bloglevel >= BLOG_SITE_LEVEL) {
|
||||||
|
$useroptions = array();
|
||||||
|
if(!empty($userid)) {
|
||||||
|
$newfilters = $basefilters;
|
||||||
|
unset($newfilters['user']);
|
||||||
|
$useroptions = array(blog_get_blogs_url($newfilters) => 'none');
|
||||||
|
}
|
||||||
|
if(!empty($groupid)) {
|
||||||
|
$members = $DB->get_records('groups_members', array('groupid'=>$groupid));
|
||||||
|
} else {
|
||||||
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||||
|
$members = $DB->get_records('role_assignments', array('contextid'=>$coursecontext->id));
|
||||||
|
}
|
||||||
|
foreach($members as $member) {
|
||||||
|
$newfilters = $basefilters;
|
||||||
|
$newfilters['user'] = $member->userid;
|
||||||
|
$useroptions[blog_get_blogs_url($newfilters)] = $DB->get_field('user', 'username', array('id'=>$member->userid));
|
||||||
|
}
|
||||||
|
$userspopuplink = '<li>'.popup_form('', $useroptions, 'view_user_blogs', blog_get_blogs_url($basefilters),
|
||||||
|
get_string('user'),'', '', true)."</li>\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->content->text = '<ul class="list">' . $addentrylink.$blogprefslink.$myviewlink.$siteviewlink;
|
||||||
|
if($courseviewlink or $modviewlink or $groupviewlink or $userviewlink or $tagviewlink) {
|
||||||
|
$this->content->text .= '<ul class="list">'.get_string('viewblogsfor', 'blog') .
|
||||||
|
$courseviewlink.$modviewlink.$groupviewlink.$userviewlink.$tagviewlink.'</ul>';
|
||||||
|
}
|
||||||
|
if($PAGE->pagetype != PAGE_COURSE_VIEW and ($coursepopuplink or $modpopuplink or $grouppopuplink or $userspopuplink)) {
|
||||||
|
$this->content->text .= '<ul class="list">'.get_string('filterblogsby', 'blog') .
|
||||||
|
$coursepopuplink.$modpopuplink.$grouppopuplink.$userspopuplink.'</ul>';
|
||||||
|
}
|
||||||
|
$this->content->text .= "</ul>\n";
|
||||||
|
|
||||||
$this->content->text = '<ul class="list">'. $output ."</ul>\n";
|
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,16 +128,6 @@ class block_blog_tags extends block_base {
|
||||||
$filterselect = $USER->id;
|
$filterselect = $USER->id;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BLOG_GROUP_LEVEL:
|
|
||||||
$filtertype = 'group';
|
|
||||||
$filterselect = groups_get_course_group($this->page->course);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BLOG_COURSE_LEVEL:
|
|
||||||
$filtertype = 'course';
|
|
||||||
$filterselect = $this->page->course->id;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ($this->page->course->id != SITEID) {
|
if ($this->page->course->id != SITEID) {
|
||||||
$filtertype = 'course';
|
$filtertype = 'course';
|
||||||
|
@ -149,7 +139,7 @@ class block_blog_tags extends block_base {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = $CFG->wwwroot.'/blog/index.php?filtertype='.$filtertype.'&filterselect='.$filterselect.'&tagid='.$tag->id;
|
$link = blog_get_blogs_url(array($filtertype => $filterselect, 'tag'=>$tag->id));
|
||||||
$this->content->text .= '<li><a href="'.$link.'" '.
|
$this->content->text .= '<li><a href="'.$link.'" '.
|
||||||
'class="'.$tag->class.'" '.
|
'class="'.$tag->class.'" '.
|
||||||
'title="'.get_string('numberofentries','blog',$tag->ct).'">'.
|
'title="'.get_string('numberofentries','blog',$tag->ct).'">'.
|
||||||
|
|
256
blog/index.php
256
blog/index.php
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
require_once('../config.php');
|
require_once('../config.php');
|
||||||
require_once($CFG->dirroot .'/blog/lib.php');
|
require_once($CFG->dirroot .'/blog/lib.php');
|
||||||
|
require_once($CFG->dirroot .'/blog/newlib.php');
|
||||||
|
|
||||||
$id = optional_param('id', 0, PARAM_INT);
|
$id = optional_param('id', 0, PARAM_INT);
|
||||||
$start = optional_param('formstart', 0, PARAM_INT);
|
$start = optional_param('formstart', 0, PARAM_INT);
|
||||||
|
@ -15,12 +16,28 @@ $userid = optional_param('userid', 0, PARAM_INT);
|
||||||
$tag = optional_param('tag', '', PARAM_NOTAGS);
|
$tag = optional_param('tag', '', PARAM_NOTAGS);
|
||||||
$tagid = optional_param('tagid', 0, PARAM_INT);
|
$tagid = optional_param('tagid', 0, PARAM_INT);
|
||||||
$postid = optional_param('postid', 0, PARAM_INT);
|
$postid = optional_param('postid', 0, PARAM_INT);
|
||||||
$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
|
$listing_type = optional_param('listing_type', '', PARAM_ALPHA);
|
||||||
$filterselect = optional_param('filterselect', 0, PARAM_INT);
|
$listing_id = optional_param('listing_id', null, PARAM_INT);
|
||||||
|
|
||||||
$edit = optional_param('edit', -1, PARAM_BOOL);
|
$edit = optional_param('edit', -1, PARAM_BOOL);
|
||||||
$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs and course tracking
|
$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs and course tracking
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//add courseid if modid or groupid is specified
|
||||||
|
if (!empty($modid) and empty($courseid)) {
|
||||||
|
$courseid = $DB->get_field('course_modules', 'course', array('id'=>$modid));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($groupid) and empty($courseid)) {
|
||||||
|
$courseid = $DB->get_field('groups', 'courseid', array('id'=>$groupid));
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($CFG->bloglevel)) {
|
if (empty($CFG->bloglevel)) {
|
||||||
print_error('blogdisable', 'blog');
|
print_error('blogdisable', 'blog');
|
||||||
|
@ -33,132 +50,154 @@ if (isloggedin() and !isguest() and $edit != -1) {
|
||||||
$USER->editing = $edit;
|
$USER->editing = $edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($filtertype)) {
|
if (!$userid and has_capability('moodle/blog:view', $sitecontext) and $CFG->bloglevel > BLOG_USER_LEVEL) {
|
||||||
if ($userid) { // default to user if specified
|
if ($postid) {
|
||||||
$filtertype = 'user';
|
if (!$postobject = $DB->get_record('post', array('module'=>'blog', 'id'=>$postid))) {
|
||||||
$filterselect = $userid;
|
print_error('nosuchentry', 'blog');
|
||||||
} else if (has_capability('moodle/blog:view', $sitecontext) and $CFG->bloglevel > BLOG_USER_LEVEL) {
|
|
||||||
if ($postid) {
|
|
||||||
$filtertype = 'user';
|
|
||||||
if (!$postobject = $DB->get_record('post', array('module'=>'blog', 'id'=>$postid))) {
|
|
||||||
print_error('nosuchentry', 'blog');
|
|
||||||
}
|
|
||||||
$filterselect = $postobject->userid;
|
|
||||||
} else {
|
|
||||||
$filtertype = 'site';
|
|
||||||
$filterselect = '';
|
|
||||||
}
|
}
|
||||||
} else {
|
$userid = $postobject->userid;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
/// check access and prepare filters
|
/// check access and prepare filters
|
||||||
|
|
||||||
switch ($filtertype) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
case 'site':
|
if ((empty($courseid) ? true : $courseid == SITEID) and empty($userid)) { //check site access
|
||||||
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
|
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
|
||||||
print_error('siteblogdisable', 'blog');
|
print_error('siteblogdisable', 'blog');
|
||||||
}
|
}
|
||||||
if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
|
if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
|
||||||
require_login();
|
require_login();
|
||||||
}
|
}
|
||||||
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
||||||
print_error('cannotviewsiteblog', 'blog');
|
print_error('cannotviewsiteblog', 'blog');
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case 'course':
|
$COURSE = $DB->get_record('course', array('format'=>'site'));
|
||||||
if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
|
$courseid = $COURSE->id;
|
||||||
print_error('courseblogdisable', 'blog');
|
}
|
||||||
}
|
|
||||||
if (!$course = $DB->get_record('course', array('id'=>$filterselect))) {
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'group':
|
if (!empty($courseid)) {
|
||||||
if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
|
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
|
||||||
print_error('groupblogdisable', 'blog');
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
// fix for MDL-9268
|
// fix for MDL-9268
|
||||||
if (! $group = groups_get_group($filterselect)) { //TODO:check.
|
if (! $group = groups_get_group($groupid)) { //TODO:check.
|
||||||
print_error('invalidgroupid');
|
print_error(get_string('invalidgroupid', 'blog'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
|
||||||
|
print_error(get_string('invalidcourseid', 'blog'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$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'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groups_get_course_groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
|
||||||
|
if (!groups_is_member($groupid)) {
|
||||||
|
print_error('notmemberofgroup');
|
||||||
}
|
}
|
||||||
if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
|
}
|
||||||
print_error('invalidcourseid');
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
print_header();
|
||||||
|
print_heading(get_string('userdeleted'));
|
||||||
|
print_footer();
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($USER->id == $userid) {
|
||||||
|
if (!has_capability('moodle/blog:create', $sitecontext)
|
||||||
|
and !has_capability('moodle/blog:view', $sitecontext)) {
|
||||||
|
print_error('donothaveblog', 'blog');
|
||||||
}
|
}
|
||||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
} else {
|
||||||
$courseid = $course->id;
|
$personalcontext = get_context_instance(CONTEXT_USER, $userid);
|
||||||
require_login($course);
|
|
||||||
if (!has_capability('moodle/blog:view', $coursecontext)) {
|
if (!has_capability('moodle/blog:view', $sitecontext) and !has_capability('moodle/user:readuserblogs', $personalcontext)) {
|
||||||
print_error('cannotviewcourseorgroupblog', 'blog');
|
print_error('cannotviewuserblog', 'blog');
|
||||||
}
|
|
||||||
if (groups_get_course_groupmode($course) == SEPARATEGROUPS
|
|
||||||
and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
|
|
||||||
if (!groups_is_member($filterselect)) {
|
|
||||||
print_error('notmemberofgroup');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
if (!blog_user_can_view_user_post($userid)) {
|
||||||
|
print_error('cannotviewcourseblog', 'blog');
|
||||||
case 'user':
|
|
||||||
if ($CFG->bloglevel < BLOG_USER_LEVEL) {
|
|
||||||
print_error('blogdisable', 'blog');
|
|
||||||
}
|
}
|
||||||
if (!$user = $DB->get_record('user', array('id'=>$filterselect))) {
|
}
|
||||||
print_error('invaliduserid');
|
|
||||||
}
|
|
||||||
if ($user->deleted) {
|
|
||||||
print_header();
|
|
||||||
print_heading(get_string('userdeleted'));
|
|
||||||
print_footer();
|
|
||||||
die;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($USER->id == $filterselect) {
|
|
||||||
if (!has_capability('moodle/blog:create', $sitecontext)
|
|
||||||
and !has_capability('moodle/blog:view', $sitecontext)) {
|
|
||||||
print_error('donothaveblog', 'blog');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$personalcontext = get_context_instance(CONTEXT_USER, $filterselect);
|
|
||||||
if (!has_capability('moodle/blog:view', $sitecontext)
|
|
||||||
and !has_capability('moodle/user:readuserblogs', $personalcontext)) {
|
|
||||||
print_error('cannotviewuserblog', 'blog');
|
|
||||||
}
|
|
||||||
if (!blog_user_can_view_user_post($filterselect)) {
|
|
||||||
print_error('cannotviewcourseblog', 'blog');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$userid = $filterselect;
|
|
||||||
|
|
||||||
if (!empty($courseid)) {
|
|
||||||
require_login($courseid);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
print_error('incorrectblogfilter', 'blog');
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($courseid)) {
|
if (empty($courseid)) {
|
||||||
$courseid = SITEID;
|
$courseid = SITEID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!empty($postid)) {
|
||||||
|
$filters['post'] = $postid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($courseid)) {
|
||||||
|
$filters['course'] = $courseid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($modid)) {
|
||||||
|
$filters['mod'] = $modid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($groupid)) {
|
||||||
|
$filters['group'] = $groupid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($userid)) {
|
||||||
|
$filters['user'] = $userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($tagid)) {
|
||||||
|
$filters['tag'] = $tagid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$PAGE->title = get_string('blog');
|
||||||
include($CFG->dirroot .'/blog/header.php');
|
include($CFG->dirroot .'/blog/header.php');
|
||||||
|
|
||||||
blog_print_html_formatted_entries($postid, $filtertype, $filterselect, $tagid, $tag);
|
blog_print_html_formatted_entries($postid, $filtertype, $filterselect, $tagid, $tag);
|
||||||
|
@ -167,5 +206,6 @@ add_to_log($courseid, 'blog', 'view', 'index.php?filtertype='.$filtertype.'&
|
||||||
|
|
||||||
include($CFG->dirroot .'/blog/footer.php');
|
include($CFG->dirroot .'/blog/footer.php');
|
||||||
|
|
||||||
|
print_footer();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -593,6 +593,40 @@ function xmldb_main_upgrade($oldversion) {
|
||||||
$dbman->change_field_type($table, $field);
|
$dbman->change_field_type($table, $field);
|
||||||
upgrade_main_savepoint($result, 2008081500);
|
upgrade_main_savepoint($result, 2008081500);
|
||||||
}
|
}
|
||||||
|
if ($result && $oldversion < 2008081300) {
|
||||||
|
/// Define table blog_association to be created
|
||||||
|
$table = new xmldb_table('blog_association');
|
||||||
|
|
||||||
|
/// Adding fields to table blog_association
|
||||||
|
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
|
||||||
|
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
|
||||||
|
$table->add_field('blogid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
|
||||||
|
/// Adding keys to table blog_association
|
||||||
|
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||||
|
$table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
|
||||||
|
$table->add_key('blogid', XMLDB_KEY_FOREIGN, array('blogid'), 'post', array('id'));
|
||||||
|
|
||||||
|
if (!$dbman->table_exists($table)) {
|
||||||
|
/// Launch create table for blog_association
|
||||||
|
$dbman->create_table($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Main savepoint reached
|
||||||
|
upgrade_main_savepoint($result, 2008081300);
|
||||||
|
}
|
||||||
|
if ($result && $oldversion < 2008081301) {
|
||||||
|
|
||||||
|
/// Changing list of values (enum) of field publishstate on table post to 'draft', 'site', 'public', 'group', 'course'
|
||||||
|
$table = new xmldb_table('post');
|
||||||
|
$field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('draft', 'site', 'public', 'group', 'course'), 'draft', 'attachment');
|
||||||
|
|
||||||
|
/// Launch change of list of values for field publishstate
|
||||||
|
$dbman->change_field_enum($table, $field);
|
||||||
|
|
||||||
|
/// Main savepoint reached
|
||||||
|
upgrade_main_savepoint($result, 2008081301);
|
||||||
|
}
|
||||||
|
|
||||||
if ($result && $oldversion < 2008081501) {
|
if ($result && $oldversion < 2008081501) {
|
||||||
$table = new xmldb_table('question');
|
$table = new xmldb_table('question');
|
||||||
|
@ -2266,6 +2300,15 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
|
||||||
upgrade_main_savepoint($result, 2009063000);
|
upgrade_main_savepoint($result, 2009063000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($result && $oldversion < 2009070100) {
|
||||||
|
// MDL-19677 Change $CFG->bloglevel to BLOG_SITE_LEVEL if BLOG_COURSE_LEVEL or BLOG_GROUP_LEVEL
|
||||||
|
$current_bloglevel = get_config(null, 'bloglevel');
|
||||||
|
|
||||||
|
if ($current_bloglevel == BLOG_GROUP_LEVEL || $current_bloglevel == BLOG_COURSE_LEVEL) {
|
||||||
|
set_config('bloglevel', BLOG_SITE_LEVEL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue