|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00009 require_once(dirname(dirname(__FILE__)).'/config.php'); 00010 require_once($CFG->dirroot .'/blog/lib.php'); 00011 require_once($CFG->dirroot .'/blog/locallib.php'); 00012 require_once($CFG->dirroot .'/course/lib.php'); 00013 require_once($CFG->dirroot .'/tag/lib.php'); 00014 require_once($CFG->dirroot .'/comment/lib.php'); 00015 00016 $id = optional_param('id', null, PARAM_INT); 00017 $start = optional_param('formstart', 0, PARAM_INT); 00018 $tag = optional_param('tag', '', PARAM_NOTAGS); 00019 $userid = optional_param('userid', null, PARAM_INT); 00020 $tagid = optional_param('tagid', null, PARAM_INT); 00021 $modid = optional_param('modid', null, PARAM_INT); 00022 $entryid = optional_param('entryid', null, PARAM_INT); 00023 $groupid = optional_param('groupid', null, PARAM_INT); 00024 $courseid = optional_param('courseid', null, PARAM_INT); 00025 $search = optional_param('search', null, PARAM_RAW); 00026 00027 comment::init(); 00028 00029 $url_params = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search'); 00030 foreach ($url_params as $var => $val) { 00031 if (empty($val)) { 00032 unset($url_params[$var]); 00033 } 00034 } 00035 $PAGE->set_url('/blog/index.php', $url_params); 00036 00037 if (empty($CFG->bloglevel)) { 00038 print_error('blogdisable', 'blog'); 00039 } 00040 00041 //correct tagid if a text tag is provided as a param 00042 if (!empty($tag)) { 00043 if ($tagrec = $DB->get_record_sql("SELECT * FROM {tag} WHERE ". $DB->sql_like('name', '?', false), array("%$tag%"))) { 00044 $tagid = $tagrec->id; 00045 } else { 00046 unset($tagid); 00047 } 00048 } 00049 00050 // add courseid if modid or groupid is specified: This is used for navigation and title 00051 if (!empty($modid) && empty($courseid)) { 00052 $courseid = $DB->get_field('course_modules', 'course', array('id'=>$modid)); 00053 } 00054 00055 if (!empty($groupid) && empty($courseid)) { 00056 $courseid = $DB->get_field('groups', 'courseid', array('id'=>$groupid)); 00057 } 00058 00059 $sitecontext = get_context_instance(CONTEXT_SYSTEM); 00060 00061 // check basic permissions 00062 if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) { 00063 // everybody can see anything - no login required unless site is locked down using forcelogin 00064 if ($CFG->forcelogin) { 00065 require_login(); 00066 } 00067 00068 } else if ($CFG->bloglevel == BLOG_SITE_LEVEL) { 00069 // users must log in and can not be guests 00070 require_login(); 00071 if (isguestuser()) { 00072 // they must have entered the url manually... 00073 print_error('blogdisable', 'blog'); 00074 } 00075 00076 } else if ($CFG->bloglevel == BLOG_USER_LEVEL) { 00077 // users can see own blogs only! with the exception of ppl with special cap 00078 require_login(); 00079 00080 } else { 00081 // weird! 00082 print_error('blogdisable', 'blog'); 00083 } 00084 00085 00086 if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) { 00087 if ($entryid) { 00088 if (!$entryobject = $DB->get_record('post', array('id'=>$entryid))) { 00089 print_error('nosuchentry', 'blog'); 00090 } 00091 $userid = $entryobject->userid; 00092 } 00093 } else if (!$userid) { 00094 $userid = $USER->id; 00095 } 00096 00097 if (!empty($modid)) { 00098 if ($CFG->bloglevel < BLOG_SITE_LEVEL) { 00099 print_error(get_string('nocourseblogs', 'blog')); 00100 } 00101 if (!$mod = $DB->get_record('course_modules', array('id' => $modid))) { 00102 print_error(get_string('invalidmodid', 'blog')); 00103 } 00104 $courseid = $mod->course; 00105 } 00106 00107 if ((empty($courseid) ? true : $courseid == SITEID) && empty($userid)) { 00108 if ($CFG->bloglevel < BLOG_SITE_LEVEL) { 00109 print_error('siteblogdisable', 'blog'); 00110 } 00111 if (!has_capability('moodle/blog:view', $sitecontext)) { 00112 print_error('cannotviewsiteblog', 'blog'); 00113 } 00114 00115 $COURSE = $DB->get_record('course', array('format'=>'site')); 00116 $courseid = $COURSE->id; 00117 } 00118 00119 if (!empty($courseid)) { 00120 if (!$course = $DB->get_record('course', array('id'=>$courseid))) { 00121 print_error('invalidcourseid'); 00122 } 00123 00124 $courseid = $course->id; 00125 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 00126 00127 require_login($course); 00128 00129 if (!has_capability('moodle/blog:view', $coursecontext)) { 00130 print_error('cannotviewcourseblog', 'blog'); 00131 } 00132 } else { 00133 $coursecontext = get_context_instance(CONTEXT_COURSE, SITEID); 00134 } 00135 00136 if (!empty($groupid)) { 00137 if ($CFG->bloglevel < BLOG_SITE_LEVEL) { 00138 print_error('groupblogdisable', 'blog'); 00139 } 00140 00141 if (! $group = groups_get_group($groupid)) { 00142 print_error(get_string('invalidgroupid', 'blog')); 00143 } 00144 00145 if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) { 00146 print_error(get_string('invalidcourseid', 'blog')); 00147 } 00148 00149 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 00150 $courseid = $course->id; 00151 require_login($course); 00152 00153 if (!has_capability('moodle/blog:view', $coursecontext)) { 00154 print_error(get_string('cannotviewcourseorgroupblog', 'blog')); 00155 } 00156 00157 if (groups_get_course_groupmode($course) == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $coursecontext)) { 00158 if (!groups_is_member($groupid)) { 00159 print_error('notmemberofgroup'); 00160 } 00161 } 00162 } 00163 00164 if (!empty($userid)) { 00165 if ($CFG->bloglevel < BLOG_USER_LEVEL) { 00166 print_error('blogdisable', 'blog'); 00167 } 00168 00169 if (!$user = $DB->get_record('user', array('id'=>$userid))) { 00170 print_error('invaliduserid'); 00171 } 00172 00173 if ($user->deleted) { 00174 echo $OUTPUT->header(); 00175 echo $OUTPUT->heading(get_string('userdeleted')); 00176 echo $OUTPUT->footer(); 00177 die; 00178 } 00179 00180 if ($USER->id == $userid) { 00181 if (!has_capability('moodle/blog:create', $sitecontext) 00182 && !has_capability('moodle/blog:view', $sitecontext)) { 00183 print_error('donothaveblog', 'blog'); 00184 } 00185 } else { 00186 $personalcontext = get_context_instance(CONTEXT_USER, $userid); 00187 00188 if (!has_capability('moodle/blog:view', $sitecontext) && !has_capability('moodle/user:readuserblogs', $personalcontext)) { 00189 print_error('cannotviewuserblog', 'blog'); 00190 } 00191 00192 if (!blog_user_can_view_user_entry($userid)) { 00193 print_error('cannotviewcourseblog', 'blog'); 00194 } 00195 } 00196 } 00197 00198 $courseid = (empty($courseid)) ? SITEID : $courseid; 00199 00200 if (empty($entryid) && empty($modid) && empty($groupid)) { 00201 $PAGE->set_context(context_user::instance($USER->id)); 00202 } else if (!empty($modid)) { 00203 $PAGE->set_context(context_module::instance($modid)); 00204 } else if (!empty($courseid)) { 00205 $PAGE->set_context(context_course::instance($courseid)); 00206 } else { 00207 $PAGE->set_context(context_system::instance()); 00208 } 00209 00210 $blogheaders = blog_get_headers(); 00211 00212 if ($CFG->enablerssfeeds) { 00213 $rsscontext = null; 00214 $filtertype = null; 00215 $thingid = null; 00216 list($thingid, $rsscontext, $filtertype) = blog_rss_get_params($blogheaders['filters']); 00217 if (empty($rsscontext)) { 00218 $rsscontext = get_system_context(); 00219 } 00220 $rsstitle = $blogheaders['heading']; 00221 00222 //check we haven't started output by outputting an error message 00223 if ($PAGE->state == moodle_page::STATE_BEFORE_HEADER) { 00224 blog_rss_add_http_header($rsscontext, $rsstitle, $filtertype, $thingid, $tagid); 00225 } 00226 00227 //this works but there isn't a great place to put the link 00228 //blog_rss_print_link($rsscontext, $filtertype, $thingid, $tagid); 00229 } 00230 00231 echo $OUTPUT->header(); 00232 00233 echo $OUTPUT->heading($blogheaders['heading'], 2); 00234 00235 $bloglisting = new blog_listing($blogheaders['filters']); 00236 $bloglisting->print_entries(); 00237 00238 echo $OUTPUT->footer(); 00239 00240 add_to_log($courseid, 'blog', 'view', 'index.php?entryid='.$entryid.'&tagid='.@$tagid.'&tag='.$tag, 'view blog entry');