3 defined('MOODLE_INTERNAL') ||
die();
5 /// Sets up blocks and navigation for index.php
7 require_once($CFG->dirroot
.'/blog/lib.php');
8 require_once($CFG->libdir
.'/pagelib.php');
9 require_once($CFG->dirroot
.'/blog/blogpage.php');
10 require_once($CFG->libdir
.'/blocklib.php');
11 require_once($CFG->dirroot
.'/course/lib.php');
13 $blockaction = optional_param('blockaction','', PARAM_ALPHA
);
14 $instanceid = optional_param('instanceid', 0, PARAM_INT
);
15 $blockid = optional_param('blockid', 0, PARAM_INT
);
17 /// If user has never visited this page before, install 2 blocks for him
18 blog_check_and_install_blocks();
21 if (!$course = get_record('course', 'id', $courseid)) {
22 error('The course number was incorrect ('. $courseid .')');
25 // Bounds for block widths
26 // more flexible for theme designers taken from theme config.php
27 $lmin = (empty($THEME->block_l_min_width
)) ?
160 : $THEME->block_l_min_width
;
28 $lmax = (empty($THEME->block_l_max_width
)) ?
210 : $THEME->block_l_max_width
;
29 $rmin = (empty($THEME->block_r_min_width
)) ?
160 : $THEME->block_r_min_width
;
30 $rmax = (empty($THEME->block_r_max_width
)) ?
210 : $THEME->block_r_max_width
;
32 define('BLOCK_L_MIN_WIDTH', $lmin);
33 define('BLOCK_L_MAX_WIDTH', $lmax);
34 define('BLOCK_R_MIN_WIDTH', $rmin);
35 define('BLOCK_R_MAX_WIDTH', $rmax);
37 //_____________ new page class code ________
38 $pagetype = PAGE_BLOG_VIEW
;
39 $pageclass = 'page_blog';
41 // map our page identifier to the actual name
42 // of the class which will be handling its operations.
43 page_map_class($pagetype, $pageclass);
45 // Now, create our page object.
46 if (empty($USER->id
)) {
47 $PAGE = page_create_object($pagetype);
49 $PAGE = page_create_object($pagetype, $USER->id
);
51 $PAGE->courseid
= $courseid;
52 $PAGE->filtertype
= $filtertype;
53 $PAGE->filterselect
= $filterselect;
54 $PAGE->tagid
= $tagid;
56 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
59 if ($PAGE->user_allowed_editing()) {
60 $editing = $PAGE->user_is_editing();
63 // Calculate the preferred width for left, right and center (both center positions will use the same)
64 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH
, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT
]),
66 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH
, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT
]),
69 // Display the blocks and allow blocklib to handle any block action requested
70 $pageblocks = blocks_get_by_page($PAGE);
73 if (!empty($blockaction) && confirm_sesskey()) {
74 if (!empty($blockid)) {
75 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
76 } else if (!empty($instanceid)) {
77 $instance = blocks_find_instance($instanceid, $pageblocks);
78 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
80 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
81 // but I'm not sure if it's worth the complexity increase...
82 $pageblocks = blocks_get_by_page($PAGE);
84 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
88 $taginstance = get_record('tag', 'id', $tagid);
89 } elseif (!empty($tag)) {
90 $taginstance = tag_id($tag);
94 /// site blogs - sitefullname -> blogs -> (?tag)
95 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
96 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
97 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
99 $blogstring = get_string('blogs','blog');
100 $tagstring = get_string('tag');
102 // needed also for user tabs later
103 if (!$course = get_record('course', 'id', $courseid)) {
104 error('Wrong course id');
109 /// This is very messy atm.
111 switch ($filtertype) {
113 if ($tagid ||
!empty($tag)) {
114 $navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc');
115 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
116 $navigation = build_navigation($navlinks);
117 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
119 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
120 $navigation = build_navigation($navlinks);
121 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
126 if ($tagid ||
!empty($tag)) {
127 $navlinks[] = array('name' => $blogstring,
128 'link' => "index.php?filtertype=course&filterselect=$filterselect",
130 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
131 $navigation = build_navigation($navlinks);
132 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
134 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
135 $navigation = build_navigation($navlinks);
136 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
142 if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
143 if ($tagid ||
!empty($tag)) {
144 $navlinks[] = array('name' => $thisgroup->name
,
145 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&group=$filterselect",
147 $navlinks[] = array('name' => $blogstring,
148 'link' => "index.php?filtertype=group&filterselect=$filterselect",
150 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
151 $navigation = build_navigation($navlinks);
152 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
154 $navlinks[] = array('name' => $thisgroup->name
,
155 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&group=$filterselect",
157 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
158 $navigation = build_navigation($navlinks);
159 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
162 print_error('Unable to find group');
168 $participants = get_string('participants');
169 if (!$user = get_record('user', 'id', $filterselect)) {
170 error('Wrong user id');
173 if ($course->id
!= SITEID
) {
174 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
); // Course context
175 $systemcontext = get_context_instance(CONTEXT_SYSTEM
); // SYSTEM context
177 if (has_capability('moodle/course:viewparticipants', $coursecontext) ||
has_capability('moodle/site:viewparticipants', $systemcontext)) {
178 $navlinks[] = array('name' => $participants,
179 'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
182 $navlinks[] = array('name' => fullname($user),
183 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&course=$course->id",
186 if ($tagid ||
!empty($tag)) {
187 $navlinks[] = array('name' => $blogstring,
188 'link' => "index.php?courseid=$course->id&filtertype=user&filterselect=$filterselect",
190 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
191 $navigation = build_navigation($navlinks);
194 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
195 $navigation = build_navigation($navlinks);
197 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
204 $navlinks[] = array('name' => fullname($user),
205 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
207 $navlinks[] = array('name' => $blogstring,
208 'link' => "index.php?filtertype=user&filterselect=$filterselect",
210 $navlinks[] = array('name' => format_string($postobject->subject
), 'link' => null, 'type' => 'misc');
211 $navigation = build_navigation($navlinks);
213 } else if ($tagid ||
!empty($tag)) {
214 $navlinks[] = array('name' => fullname($user),
215 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
217 $navlinks[] = array('name' => $blogstring,
218 'link' => "index.php?filtertype=user&filterselect=$filterselect",
220 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
221 $navigation = build_navigation($navlinks);
224 $navlinks[] = array('name' => fullname($user),
225 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
227 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
228 $navigation = build_navigation($navlinks);
230 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
236 error ('Error unknown filtertype');
242 if ($filtertype=='user') {
247 $currenttab = 'blogs';
249 require_once($CFG->dirroot
.'/user/tabs.php');
252 /// Layout the whole page as three big columns.
253 print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
254 print '<tr valign="top">' . "\n";
256 /// The left column ...
257 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT
) ||
$editing) {
258 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
259 print '<!-- Begin left side blocks -->' . "\n";
260 print_container_start();
261 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT
);
262 print_container_end();
263 print '<!-- End left side blocks -->' . "\n";
264 print '</td>' . "\n";
267 /// Start main column
268 print '<!-- Begin page content -->' . "\n";
270 print_container_start();