From 98f7f6919ef0aa0fd6a1a7625e7c51660dee171a Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Thu, 2 Jul 2009 06:43:43 +0000 Subject: [PATCH] MDL-19677 Reverting prematurely committed blog patch --- blocks/blog_menu/block_blog_menu.php | 243 ++++----------------------- 1 file changed, 35 insertions(+), 208 deletions(-) diff --git a/blocks/blog_menu/block_blog_menu.php b/blocks/blog_menu/block_blog_menu.php index 6bd9415530..2967304084 100755 --- a/blocks/blog_menu/block_blog_menu.php +++ b/blocks/blog_menu/block_blog_menu.php @@ -1,7 +1,6 @@ dirroot .'/blog/lib.php'); -require_once($CFG->dirroot .'/course/lib.php'); class block_blog_menu extends block_base { @@ -12,7 +11,7 @@ class block_blog_menu extends block_base { } function get_content() { - global $CFG, $USER, $COURSE, $DB, $PAGE; + global $CFG, $USER; if (empty($CFG->bloglevel)) { $this->content->text = ''; @@ -41,249 +40,77 @@ class block_blog_menu extends block_base { $this->content = new stdClass; $this->content->footer = ''; - 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; - } - + //if ( blog_isLoggedIn() && !isguest() ) { + $courseviewlink = ''; $addentrylink = ''; - $blogprefslink = ''; - $myviewlink = ''; - $siteviewlink = ''; - $courseviewlink = ''; - $modviewlink = ''; - $groupviewlink = ''; - $userviewlink = ''; - $tagviewlink = ''; - $coursepopuplink = ''; - $modpopuplink = ''; - $grouppopuplink = ''; - $userspopuplink = ''; + $coursearg = ''; - //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_SITE_LEVEL && $canviewblogs) { + && $CFG->bloglevel >= BLOG_COURSE_LEVEL && $canviewblogs) { $coursearg = '&courseid='.$this->page->course->id; - if(!empty($modid)) $coursearg .= '&modid='.$modid; - // a course is specified $courseviewlink = '
  • '; $courseviewlink .= get_string('viewcourseentries', 'blog') ."
  • \n"; } + $blogmodon = false; + if ( (isloggedin() && !isguest()) && (!$blogmodon || ($blogmodon && $coursearg != '')) && $CFG->bloglevel >= BLOG_USER_LEVEL ) { - // create the Add entry link + + // show Add entry link if (has_capability('moodle/blog:create', $sitecontext)) { $addentrylink = '
  • '.get_string('addnewentry', 'blog') ."
  • \n"; } - // create the link to manage blog prefs - $blogprefslink = '
  • wwwroot .'/blog/index.php?userid='. + $userBlog->userid.'">'.get_string('viewmyentries', 'blog'). + "
  • \n"; + + // show link to manage blog prefs + $addentrylink .= '
  • '. get_string('blogpreferences', 'blog')."
  • \n"; - // create the View my entries link - $myviewlink = '
  • '. - //''.fullname($USER). - get_string('viewmyentries', 'blog'). - "
  • \n"; - } - - // create the View site entries link - if ($CFG->bloglevel >= BLOG_SITE_LEVEL && $canviewblogs) { - $siteviewlink .= '
  • '. - get_string('viewsiteentries', 'blog'). - //$DB->get_field('course', 'shortname', array('format'=>'site')). - "
  • \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 = '
  • ' - .''. - $DB->get_field('course', 'shortname', array('id'=>$courseid)) ."
  • \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 = '
  • '. - ''. - $DB->get_field('user', 'username', array('id'=>$userid)). - "
  • \n"; + $output = $addentrylink; + $output .= $courseviewlink; } - //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 = '
  • '. - ''. - $DB->get_field($modname, 'name', array('id' => $modinfo->instance)). - "
  • \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 = '
  • '. - ''. - $DB->get_field('groups', 'name', array('id'=>$groupid)) ."
  • \n"; - } - - //create 'view blogs for tag' link - if(!empty($tagid) && (!empty($modid) or !empty($userid) or !empty($courseid) or !empty($groupid)) and $canviewblogs) { - $tagviewlink = '
  • '.get_string('tag', 'tag').': '. - $DB->get_field('tag', 'name', array('id'=>$tagid))."
  • \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 = '
  • '.popup_form('', $courseoptions, 'view_course_blogs', blog_get_blogs_url($basefilters), - get_string('course'),'', '', true) . "
  • \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 = '
  • '.popup_form('', $modoptions, 'view_mod_blogs', blog_get_blogs_url($basefilters), - get_string('resource').'/'.get_string('activity'), - '', '', true)."
  • \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 = '
  • '.popup_form('', $groupoptions, 'view_group_blogs', blog_get_blogs_url($basefilters), - get_string('group'),'', '', true)."
  • \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 = '
  • '.popup_form('', $useroptions, 'view_user_blogs', blog_get_blogs_url($basefilters), - get_string('user'),'', '', true)."
  • \n"; - + // show View site entries link + if ($CFG->bloglevel >= BLOG_SITE_LEVEL && $canviewblogs) { + $output .= '
  • '; + $output .= get_string('viewsiteentries', 'blog')."
  • \n"; } + // took out tag management interface/link, should use tag/manage.php - $this->content->text = '\n"; + // show Help with blogging link + //$output .= '
  • '; + //$output .= get_string('helpblogging', 'blog') ."
  • \n"; + //} else { + // $output = ''; //guest users and users who are not logged in do not get menus + //} + $this->content->text = '\n"; return $this->content; } } -- 2.39.5