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 if (!empty($THEME->customcorners
)) {
12 require_once($CFG->dirroot
.'/lib/custom_corners_lib.php');
15 $blockaction = optional_param('blockaction','', PARAM_ALPHA
);
16 $instanceid = optional_param('instanceid', 0, PARAM_INT
);
17 $blockid = optional_param('blockid', 0, PARAM_INT
);
19 /// If user has never visited this page before, install 2 blocks for him
20 blog_check_and_install_blocks();
23 if (!$course = get_record('course', 'id', $courseid)) {
24 error('The course number was incorrect ('. $courseid .')');
27 // Bounds for block widths
28 // more flexible for theme designers taken from theme config.php
29 $lmin = (empty($THEME->block_l_min_width
)) ?
160 : $THEME->block_l_min_width
;
30 $lmax = (empty($THEME->block_l_max_width
)) ?
210 : $THEME->block_l_max_width
;
31 $rmin = (empty($THEME->block_r_min_width
)) ?
160 : $THEME->block_r_min_width
;
32 $rmax = (empty($THEME->block_r_max_width
)) ?
210 : $THEME->block_r_max_width
;
34 define('BLOCK_L_MIN_WIDTH', $lmin);
35 define('BLOCK_L_MAX_WIDTH', $lmax);
36 define('BLOCK_R_MIN_WIDTH', $rmin);
37 define('BLOCK_R_MAX_WIDTH', $rmax);
39 //_____________ new page class code ________
40 $pagetype = PAGE_BLOG_VIEW
;
41 $pageclass = 'page_blog';
43 // map our page identifier to the actual name
44 // of the class which will be handling its operations.
45 page_map_class($pagetype, $pageclass);
47 // Now, create our page object.
48 if (empty($USER->id
)) {
49 $PAGE = page_create_object($pagetype);
51 $PAGE = page_create_object($pagetype, $USER->id
);
53 $PAGE->courseid
= $courseid;
54 $PAGE->filtertype
= $filtertype;
55 $PAGE->filterselect
= $filterselect;
56 $PAGE->tagid
= $tagid;
58 $PAGE->init_full(); //init the BlogInfo object and the courserecord object
61 if ($PAGE->user_allowed_editing()) {
62 $editing = $PAGE->user_is_editing();
65 // Calculate the preferred width for left, right and center (both center positions will use the same)
66 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH
, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT
]),
68 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH
, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT
]),
71 // Display the blocks and allow blocklib to handle any block action requested
72 $pageblocks = blocks_get_by_page($PAGE);
75 if (!empty($blockaction) && confirm_sesskey()) {
76 if (!empty($blockid)) {
77 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
78 } else if (!empty($instanceid)) {
79 $instance = blocks_find_instance($instanceid, $pageblocks);
80 blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
82 // This re-query could be eliminated by judicious programming in blocks_execute_action(),
83 // but I'm not sure if it's worth the complexity increase...
84 $pageblocks = blocks_get_by_page($PAGE);
86 $missingblocks = blocks_get_missing($PAGE, $pageblocks);
90 $taginstance = get_record('tag', 'id', $tagid);
94 $taginstance = tag_id($tag);
99 /// site blogs - sitefullname -> blogs -> (?tag)
100 /// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
101 /// group blogs - sitefullname -> course fullname ->group ->(?tag)
102 /// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
104 $blogstring = get_string('blogs','blog');
105 $tagstring = get_string('tag');
107 // needed also for user tabs later
108 if (!$course = get_record('course', 'id', $courseid)) {
109 error('Wrong course id');
114 /// This is very messy atm.
116 switch ($filtertype) {
118 if ($tagid ||
!empty($tag)) {
119 $navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc');
120 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
121 $navigation = build_navigation($navlinks);
122 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
124 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
125 $navigation = build_navigation($navlinks);
126 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
131 if ($tagid ||
!empty($tag)) {
132 $navlinks[] = array('name' => $blogstring,
133 'link' => "index.php?filtertype=course&filterselect=$filterselect",
135 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
136 $navigation = build_navigation($navlinks);
137 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
139 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
140 $navigation = build_navigation($navlinks);
141 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
147 if ($thisgroup = groups_get_group($filterselect, false)) { //TODO:
148 if ($tagid ||
!empty($tag)) {
149 $navlinks[] = array('name' => $thisgroup->name
,
150 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&group=$filterselect",
152 $navlinks[] = array('name' => $blogstring,
153 'link' => "index.php?filtertype=group&filterselect=$filterselect",
155 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
156 $navigation = build_navigation($navlinks);
157 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
159 $navlinks[] = array('name' => $thisgroup->name
,
160 'link' => "$CFG->wwwroot/user/index.php?id=$course->id&group=$filterselect",
162 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
163 $navigation = build_navigation($navlinks);
164 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
167 print_error('Unable to find group');
173 $participants = get_string('participants');
174 if (!$user = get_record('user', 'id', $filterselect)) {
175 error('Wrong user id');
178 if ($course->id
!= SITEID
) {
179 if ($tagid ||
!empty($tag)) {
180 $navlinks[] = array('name' => $course->shortname
,
181 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
183 $navlinks[] = array('name' => $participants,
184 'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
186 $navlinks[] = array('name' => fullname($user),
187 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&course=$course->id",
189 $navlinks[] = array('name' => $blogstring,
190 'link' => "index.php?courseid=$course->id&filtertype=user&filterselect=$filterselect",
192 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
193 $navigation = build_navigation($navlinks);
195 print_header("$course->shortname: $blogstring", $course->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
198 $navlinks[] = array('name' => $course->shortname
,
199 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
201 $navlinks[] = array('name' => $participants,
202 'link' => "$CFG->wwwroot/user/index.php?id=$course->id",
204 $navlinks[] = array('name' => fullname($user),
205 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&course=$course->id",
207 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
208 $navigation = build_navigation($navlinks);
209 print_header("$course->shortname: $blogstring", $course->fullname
,
210 '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$course->id
.'">'.$course->shortname
.'</a> ->
211 <a href="'.$CFG->wwwroot
.'/user/index.php?id='.$course->id
.'">'.$participants.'</a> ->
212 <a href="'.$CFG->wwwroot
.'/user/view.php?id='.$filterselect.'&course='.$course->id
.'">'.fullname($user).'</a> ->
213 '.$blogstring,'','',true,$PAGE->get_extra_header_string());
220 if ($tagid ||
!empty($tag)) {
221 $navlinks[] = array('name' => fullname($user),
222 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
224 $navlinks[] = array('name' => $blogstring,
225 'link' => "index.php?filtertype=user&filterselect=$filterselect",
227 $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
228 $navigation = build_navigation($navlinks);
230 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
233 $navlinks[] = array('name' => fullname($user),
234 'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
236 $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
237 $navigation = build_navigation($navlinks);
238 print_header("$SITE->shortname: $blogstring", $SITE->fullname
, $navigation,'','',true,$PAGE->get_extra_header_string());
246 error ('Error unknown filtertype');
252 if ($filtertype=='user') {
257 $currenttab = 'blogs';
259 require_once($CFG->dirroot
.'/user/tabs.php');
262 /// Layout the whole page as three big columns.
263 print '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">' . "\n";
264 print '<tr valign="top">' . "\n";
266 /// The left column ...
267 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT
) ||
$editing) {
268 print '<td style="vertical-align: top; width: '. $preferred_width_left .'px;" id="left-column">' . "\n";
269 print '<!-- Begin left side blocks -->' . "\n";
270 if (!empty($THEME->customcorners
)) print_custom_corners_start();
271 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT
);
272 if (!empty($THEME->customcorners
)) print_custom_corners_end();
273 print '<!-- End left side blocks -->' . "\n";
274 print '</td>' . "\n";
277 /// Start main column
278 print '<!-- Begin page content -->' . "\n";
280 if (!empty($THEME->customcorners
)) print_custom_corners_start();