]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19676 Removed course and group visibility settings for blog
authornicolasconnault <nicolasconnault>
Wed, 1 Jul 2009 08:49:47 +0000 (08:49 +0000)
committernicolasconnault <nicolasconnault>
Wed, 1 Jul 2009 08:49:47 +0000 (08:49 +0000)
blocks/blog_menu/block_blog_menu.php
blocks/blog_tags/block_blog_tags.php
blog/index.php
lib/db/upgrade.php

index 2967304084f67b2a1acf625122492149073e413a..6bd9415530ccfdf46144859ab677716a0d533a16 100755 (executable)
@@ -1,6 +1,7 @@
 <?php //$Id$
 
 require_once($CFG->dirroot .'/blog/lib.php');
+require_once($CFG->dirroot .'/course/lib.php');
 
 class block_blog_menu extends block_base {
 
@@ -11,7 +12,7 @@ class block_blog_menu extends block_base {
     }
 
     function get_content() {
-        global $CFG, $USER;
+        global $CFG, $USER, $COURSE, $DB, $PAGE;
 
         if (empty($CFG->bloglevel)) {
             $this->content->text = '';
@@ -40,77 +41,249 @@ class block_blog_menu extends block_base {
         $this->content = new stdClass;
         $this->content->footer = '';
 
-        //if ( blog_isLoggedIn() && !isguest() ) {
-            $courseviewlink = '';
+        if (empty($this->instance)) {
+            // Either we're being asked for content without
+            // an associated instance of the Blog module has never been installed.
+            $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 = '';
-            $coursearg = '';
+        $blogprefslink = '';
+        $myviewlink = '';
+        $siteviewlink = '';
+        $courseviewlink = '';
+        $modviewlink = '';
+        $groupviewlink = '';
+        $userviewlink = '';
+        $tagviewlink = '';
+        $coursepopuplink = '';
+        $modpopuplink = '';
+        $grouppopuplink = '';
+        $userspopuplink = '';
 
+        //create basic blog preference links
+        $coursearg = '';
             $sitecontext = get_context_instance(CONTEXT_SYSTEM);
 
             if ($this->page->course->id != SITEID) {
-
                 $incoursecontext = true;
                 $curcontext = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
             } else {
                 $incoursecontext = false;
                 $curcontext = $sitecontext;
             }
-
             $canviewblogs = has_capability('moodle/blog:view', $curcontext);
-
-            /// Accessibility: markup as a list.
-
             if ( (isloggedin() && !isguest()) && $incoursecontext
-                    && $CFG->bloglevel >= BLOG_COURSE_LEVEL && $canviewblogs) {
+                    && $CFG->bloglevel >= BLOG_SITE_LEVEL && $canviewblogs) {
 
                 $coursearg = '&amp;courseid='.$this->page->course->id;
+                if(!empty($modid)) $coursearg .= '&amp;modid='.$modid;
+
                 // a course is specified
 
                 $courseviewlink = '<li><a href="'. $CFG->wwwroot .'/blog/index.php?filtertype=course&amp;filterselect='. $this->page->course->id .'">';
                 $courseviewlink .= get_string('viewcourseentries', 'blog') ."</a></li>\n";
             }
-
             $blogmodon = false;
-
             if ( (isloggedin() && !isguest())
                         && (!$blogmodon || ($blogmodon && $coursearg != ''))
                         && $CFG->bloglevel >= BLOG_USER_LEVEL ) {
-
-                // show Add entry link
+            // create the Add entry link
                 if (has_capability('moodle/blog:create', $sitecontext)) {
                     $addentrylink = '<li><a href="'. $CFG->wwwroot. '/blog/edit.php?action=add'
                                    .$coursearg.'">'.get_string('addnewentry', 'blog') ."</a></li>\n";
                 }
-                // show View my entries link
-                $addentrylink .= '<li><a href="'. $CFG->wwwroot .'/blog/index.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='.
+            // create the link to manage blog prefs
+            $blogprefslink = '<li><a href="'. $CFG->wwwroot. '/blog/preferences.php?userid='.
                                  $userBlog->userid . $coursearg .'">'.
                                  get_string('blogpreferences', 'blog')."</a></li>\n";
-
-                $output = $addentrylink;
-                $output .= $courseviewlink;
+            // create the View my entries link
+            $myviewlink = '<li><a href="'.blog_get_blogs_url(array('user'=>$USER->id)).'">'.
+                          //'<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) {
-                $output .= '<li><a href="'. $CFG->wwwroot .'/blog/index.php?filtertype=site&amp;">';
-                $output .= get_string('viewsiteentries', 'blog')."</a></li>\n";
+            $siteviewlink .= '<li><a href="'.blog_get_blogs_url(array()).'">'.
+                             get_string('viewsiteentries', 'blog').
+                             //$DB->get_field('course', 'shortname', array('format'=>'site')).
+                             "</a></li>\n";
+            }
+
+        //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";
+        }
+
+        //create 'view blogs for user' link
+        if(!empty($userid) and $userid != $USER->id and (!empty($modid) or !empty($courseid) or !empty($tagid) or !empty($groupid))
+           and  $canviewblogs) {
+            $userviewlink = '<li><a href="'. blog_get_blogs_url(array('user'=>$userid)) .'">'.
+                            '<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />'.
+                            $DB->get_field('user', 'username', array('id'=>$userid)).
+                            "</a></li>\n";
             }
 
-            // took out tag management interface/link, should use tag/manage.php
+        //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";
+        }
 
-            // show Help with blogging link
-            //$output .= '<li><a href="'. $CFG->wwwroot .'/help.php?module=blog&amp;file=user.html">';
-            //$output .= get_string('helpblogging', 'blog') ."</a></li>\n";
-        //} else {
-        //    $output = ''; //guest users and users who are not logged in do not get menus
-        //}
+        //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;
     }
 }
index 77e42b891decca12e6f73f44f38187dc50f51d41..3a1286e9f26dd9854253e4d42e1d912e09d43929 100644 (file)
@@ -128,16 +128,6 @@ class block_blog_tags extends block_base {
                         $filterselect = $USER->id;
                     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:
                         if ($this->page->course->id != SITEID) {
                             $filtertype = 'course';
@@ -149,7 +139,7 @@ class block_blog_tags extends block_base {
                     break;
                 }
 
-                $link = $CFG->wwwroot.'/blog/index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;tagid='.$tag->id;
+                $link = blog_get_blogs_url(array($filtertype => $filterselect, 'tag'=>$tag->id));
                 $this->content->text .= '<li><a href="'.$link.'" '.
                                         'class="'.$tag->class.'" '.
                                         'title="'.get_string('numberofentries','blog',$tag->ct).'">'.
index a9f8b3a81c75ade80c01b2c7c1dba49370c3815f..4d9a47d02d04a93e7dee54706e09306943accfde 100755 (executable)
@@ -8,6 +8,7 @@
 
 require_once('../config.php');
 require_once($CFG->dirroot .'/blog/lib.php');
+require_once($CFG->dirroot .'/blog/newlib.php');
 
 $id           = optional_param('id', 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);
 $tagid        = optional_param('tagid', 0, PARAM_INT);
 $postid       = optional_param('postid', 0, PARAM_INT);
-$filtertype   = optional_param('filtertype', '', PARAM_ALPHA);
-$filterselect = optional_param('filterselect', 0, PARAM_INT);
-
+$listing_type = optional_param('listing_type', '', PARAM_ALPHA);
+$listing_id   = optional_param('listing_id', null, PARAM_INT);
 $edit         = optional_param('edit', -1, PARAM_BOOL);
 $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)) {
     print_error('blogdisable', 'blog');
@@ -33,132 +50,154 @@ if (isloggedin() and !isguest() and $edit != -1) {
     $USER->editing = $edit;
 }
 
-if (empty($filtertype)) {
-    if ($userid) {    // default to user if specified
-        $filtertype = 'user';
-        $filterselect = $userid;
-    } 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 = '';
+if (!$userid and has_capability('moodle/blog:view', $sitecontext) and $CFG->bloglevel > BLOG_USER_LEVEL) {
+    if ($postid) {
+        if (!$postobject = $DB->get_record('post', array('module'=>'blog', 'id'=>$postid))) {
+            print_error('nosuchentry', 'blog');
         }
-    } else {
-        // 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;
+        $userid = $postobject->userid;
     }
+} 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
 
-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 ($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');
-        }
-    break;
+if ((empty($courseid) ? true : $courseid == SITEID) and empty($userid)) {  //check site access
+    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');
+    }
 
-    case 'course':
-        if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
-            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;
+    $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');
+    }
 
-    case 'group':
-        if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
-            print_error('groupblogdisable', 'blog');
-        }
-        
         // fix for MDL-9268
-        if (! $group = groups_get_group($filterselect)) { //TODO:check.
-            print_error('invalidgroupid');
-        }
-        if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
-            print_error('invalidcourseid');
-        }
-        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-        $courseid = $course->id;
-        require_login($course);
-        if (!has_capability('moodle/blog:view', $coursecontext)) {
-            print_error('cannotviewcourseorgroupblog', 'blog');
-        }
-        if (groups_get_course_groupmode($course) == SEPARATEGROUPS
-          and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
-            if (!groups_is_member($filterselect)) {
-                print_error('notmemberofgroup');
-            }
-        }
+    if (! $group = groups_get_group($groupid)) { //TODO:check.
+        print_error(get_string('invalidgroupid', 'blog'));
+    }
 
-    break;
+    if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
+        print_error(get_string('invalidcourseid', '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;
-        }
+    $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 ($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');
-            }
+    if (groups_get_course_groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
+        if (!groups_is_member($groupid)) {
+            print_error('notmemberofgroup');
         }
-        $userid = $filterselect;
+    }
+}
+
+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 (!empty($courseid)) {
-            require_login($courseid);
+    if ($USER->id == $userid) {
+        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, $userid);
 
-    break;
+        if (!has_capability('moodle/blog:view', $sitecontext) and !has_capability('moodle/user:readuserblogs', $personalcontext)) {
+            print_error('cannotviewuserblog', 'blog');
+        }
 
-    default:
-        print_error('incorrectblogfilter', 'blog');
-    break;
+        if (!blog_user_can_view_user_post($userid)) {
+            print_error('cannotviewcourseblog', 'blog');
+        }
+    }
 }
 
 if (empty($courseid)) {
     $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');
 
 blog_print_html_formatted_entries($postid, $filtertype, $filterselect, $tagid, $tag);
@@ -167,5 +206,6 @@ add_to_log($courseid, 'blog', 'view', 'index.php?filtertype='.$filtertype.'&amp;
 
 include($CFG->dirroot .'/blog/footer.php');
 
+print_footer();
 
 ?>
index 13f7b90dae208e4d9180332dc7be7ada90baa0db..c6434f33a1bde13bd9bcf8d0952cd868d9eba0ca 100644 (file)
@@ -593,6 +593,40 @@ function xmldb_main_upgrade($oldversion) {
         $dbman->change_field_type($table, $field);
         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) {
         $table = new xmldb_table('question');
@@ -2265,6 +2299,15 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
         } 
         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;
 }