3 /// Sets up blocks and navigation for index.php
5 require_once($CFG->dirroot
.'/blog/lib.php');
6 require_once($CFG->libdir
.'/pagelib.php');
7 require_once($CFG->dirroot
.'/blog/blogpage.php');
8 require_once($CFG->libdir
.'/blocklib.php');
9 require_once($CFG->dirroot
.'/course/lib.php');
11 $blockaction = optional_param('blockaction','', PARAM_ALPHA
);
12 $instanceid = optional_param('instanceid', 0, PARAM_INT
);
13 $blockid = optional_param('blockid', 0, PARAM_INT
);
15 /// If user has never visited this page before, install 2 blocks for him
16 blog_check_and_install_blocks();
19 if (!$course = get_record('course', 'id', $courseid)) {
20 error('The course number was incorrect ('. $courseid .')');
23 // Bounds for block widths
24 // more flexible for theme designers taken from theme config.php
25 $lmin = (empty($THEME->block_l_min_width
)) ?
160 : $THEME->block_l_min_width
;
26 $lmax = (empty($THEME->block_l_max_width
)) ?
210 : $THEME->block_l_max_width
;
27 $rmin = (empty($THEME->block_r_min_width
)) ?
160 : $THEME->block_r_min_width
;
28 $rmax = (empty($THEME->block_r_max_width
)) ?
210 : $THEME->block_r_max_width
;
30 define('BLOCK_L_MIN_WIDTH', $lmin);
31 define('BLOCK_L_MAX_WIDTH', $lmax);
32 define('BLOCK_R_MIN_WIDTH', $rmin);
33 define('BLOCK_R_MAX_WIDTH', $rmax);
35 //_____________ new page class code ________
36 $pagetype = PAGE_BLOG_VIEW
;
37 $pageclass = 'page_blog';
39 // map our page identifier to the actual name
40 // of the class which will be handling its operations.
41 page_map_class($pagetype, $pageclass);
43 // Now, create our page object.
44 if (empty($USER->id
)) {
45 $PAGE = page_create_object($pagetype);
47 $PAGE = page_create_object($pagetype, $USER->id
);
49 $PAGE->courseid
= $courseid;
50 $PAGE->filtertype
= $filtertype;
51 $PAGE->filterselect
= $filterselect;
52 $PAGE->tagid
= $tagid;
54 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
57 if ($PAGE->user_allowed_editing()) {
58 $editing = $PAGE->user_is_editing();
61 // Calculate the preferred width for left, right and center (both center positions will use the same)
62 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH
, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT
]),
64 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH
, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT
]),
67 // Display the blocks and allow blocklib to handle any block action requested
68 $pageblocks = blocks_get_by_page($PAGE);
71 if (!empty($blockaction) && confirm_sesskey()) {
72 if (!empty($blockid)) {
73 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
74 } else if (!empty($instanceid)) {
75 $instance = blocks_find_instance($instanceid, $pageblocks);
76 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
78 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
79 // but I'm not sure if it's worth the complexity increase...
80 $pageblocks = blocks_get_by_page($PAGE);
82 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
86 $taginstance = get_record('tag', 'id', $tagid);
87 } elseif (!empty($tag)) {
88 $taginstance = tag_id($tag);
92 /// site blogs - sitefullname -> blogs -> (?tag)
93 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
94 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
95 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
97 $blogstring = get_string('blogs','blog');
98 $tagstring = get_string('tag');
100 // needed also for user tabs later
101 if (!$course = get_record('course', 'id', $courseid)) {
102 error('Wrong course id');
107 /// This is very messy atm.
109 switch ($filtertype) {
111 if ($tagid ||
!empty($tag)) {
112 $navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc');
113 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
114 $navigation = build_navigation($navlinks);
115 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
117 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
118 $navigation = build_navigation($navlinks);
119 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
124 if ($tagid ||
!empty($tag)) {
125 $navlinks[] = array('name' => $blogstring,
126 'link' => "index.php?filtertype=course&filterselect=$filterselect",
128 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
129 $navigation = build_navigation($navlinks);
130 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
132 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
133 $navigation = build_navigation($navlinks);
134 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
140 if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
141 if ($tagid ||
!empty($tag)) {
142 $navlinks[] = array('name' => $thisgroup->name
,
143 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&group=$filterselect",
145 $navlinks[] = array('name' => $blogstring,
146 'link' => "index.php?filtertype=group&filterselect=$filterselect",
148 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
149 $navigation = build_navigation($navlinks);
150 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
152 $navlinks[] = array('name' => $thisgroup->name
,
153 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&group=$filterselect",
155 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
156 $navigation = build_navigation($navlinks);
157 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
160 print_error('Unable to find group');
166 $participants = get_string('participants');
167 if (!$user = get_record('user', 'id', $filterselect)) {
168 error('Wrong user id');
171 if ($course->id
!= SITEID
) {
172 $coursecontext = get_context_instance(CONTEXT_COURSE
, $course->id
); // Course context
173 $systemcontext = get_context_instance(CONTEXT_SYSTEM
); // SYSTEM context
175 if (has_capability('moodle/course:viewparticipants', $coursecontext) ||
has_capability('moodle/site:viewparticipants', $systemcontext)) {
176 $navlinks[] = array('name' => $participants,
177 'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
180 $navlinks[] = array('name' => fullname($user),
181 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&course=$course->id",
184 if ($tagid ||
!empty($tag)) {
185 $navlinks[] = array('name' => $blogstring,
186 'link' => "index.php?courseid=$course->id&filtertype=user&filterselect=$filterselect",
188 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
189 $navigation = build_navigation($navlinks);
192 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
193 $navigation = build_navigation($navlinks);
195 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
202 $navlinks[] = array('name' => fullname($user),
203 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
205 $navlinks[] = array('name' => $blogstring,
206 'link' => "index.php?filtertype=user&filterselect=$filterselect",
208 $navlinks[] = array('name' => format_string($postobject->subject
), 'link' => null, 'type' => 'misc');
209 $navigation = build_navigation($navlinks);
211 } else if ($tagid ||
!empty($tag)) {
212 $navlinks[] = array('name' => fullname($user),
213 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
215 $navlinks[] = array('name' => $blogstring,
216 'link' => "index.php?filtertype=user&filterselect=$filterselect",
218 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
219 $navigation = build_navigation($navlinks);
222 $navlinks[] = array('name' => fullname($user),
223 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
225 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
226 $navigation = build_navigation($navlinks);
228 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
234 error ('Error unknown filtertype');
240 if ($filtertype=='user') {
245 $currenttab = 'blogs';
247 require_once($CFG->dirroot
.'/user/tabs.php');
250 /// Layout the whole page as three big columns.
251 print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
252 print '<tr valign="top">' . "\n";
254 /// The left column ...
255 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT
) ||
$editing) {
256 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
257 print '<!-- Begin left side blocks -->' . "\n";
258 print_container_start();
259 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT
);
260 print_container_end();
261 print '<!-- End left side blocks -->' . "\n";
262 print '</td>' . "\n";
265 /// Start main column
266 print '<!-- Begin page content -->' . "\n";
268 print_container_start();