[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/blog/ -> header.php (source)

   1  <?php //$Id: header.php,v 1.41.2.8 2008/04/22 05:55:34 moodler Exp $
   2  
   3  /// Sets up blocks and navigation for index.php
   4  
   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');
  10  
  11  $blockaction = optional_param('blockaction','', PARAM_ALPHA);
  12  $instanceid  = optional_param('instanceid', 0, PARAM_INT);
  13  $blockid     = optional_param('blockid',    0, PARAM_INT);
  14  
  15  /// If user has never visited this page before, install 2 blocks for him
  16  blog_check_and_install_blocks();
  17  
  18  
  19  if (!$course = get_record('course', 'id', $courseid)) {
  20      error('The course number was incorrect ('. $courseid .')');
  21  }
  22  
  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;
  29  
  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);
  34  
  35  //_____________ new page class code ________
  36  $pagetype = PAGE_BLOG_VIEW;
  37  $pageclass = 'page_blog';
  38  
  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);
  42  
  43  // Now, create our page object.
  44  if (empty($USER->id)) {
  45      $PAGE = page_create_object($pagetype);
  46  } else {
  47      $PAGE = page_create_object($pagetype, $USER->id);
  48  }
  49  $PAGE->courseid     = $courseid;
  50  $PAGE->filtertype   = $filtertype;
  51  $PAGE->filterselect = $filterselect;
  52  $PAGE->tagid        = $tagid;
  53  
  54  $PAGE->init_full(); //init the BlogInfo object and the courserecord object
  55  
  56  $editing = false;
  57  if ($PAGE->user_allowed_editing()) {
  58      $editing = $PAGE->user_is_editing();
  59  }
  60  
  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]),
  63                                          BLOCK_L_MAX_WIDTH);
  64  $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
  65                                          BLOCK_R_MAX_WIDTH);
  66  
  67  // Display the blocks and allow blocklib to handle any block action requested
  68  $pageblocks = blocks_get_by_page($PAGE);
  69  
  70  if ($editing) {
  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);
  77          }
  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);
  81      }
  82      $missingblocks = blocks_get_missing($PAGE, $pageblocks);
  83  }
  84  
  85  if (!empty($tagid)) {
  86      $taginstance = get_record('tag', 'id', $tagid);
  87  } elseif (!empty($tag)) {
  88      $taginstance = tag_id($tag);
  89  }
  90  
  91  /// navigations
  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)
  96  
  97  $blogstring = get_string('blogs','blog');
  98  $tagstring = get_string('tag');
  99  
 100  // needed also for user tabs later
 101  if (!$course = get_record('course', 'id', $courseid)) {
 102      error('Wrong course id');
 103  }
 104  
 105  $navlinks = array();
 106  
 107  /// This is very messy atm.
 108  
 109      switch ($filtertype) {
 110          case 'site':
 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());
 116              } else {
 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());
 120              }
 121          break;
 122  
 123          case 'course':
 124              if ($tagid || !empty($tag)) {
 125                  $navlinks[] = array('name' => $blogstring,
 126                                      'link' => "index.php?filtertype=course&amp;filterselect=$filterselect",
 127                                      'type' => 'misc');
 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());
 131              } else {
 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());
 135              }
 136          break;
 137  
 138          case 'group':
 139  
 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&amp;group=$filterselect",
 144                                          'type' => 'misc');
 145                      $navlinks[] = array('name' => $blogstring,
 146                                          'link' => "index.php?filtertype=group&amp;filterselect=$filterselect",
 147                                          'type' => 'misc');
 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());
 151                  } else {
 152                      $navlinks[] = array('name' => $thisgroup->name,
 153                                          'link' => "$CFG->wwwroot/user/index.php?id=$course->id&amp;group=$filterselect",
 154                                          'type' => 'misc');
 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());
 158                  }
 159              } else {
 160                  print_error('Unable to find group');
 161              }
 162  
 163          break;
 164  
 165          case 'user':
 166              $participants = get_string('participants');
 167              if (!$user = get_record('user', 'id', $filterselect)) {
 168                 error('Wrong user id');
 169              }
 170  
 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
 174  
 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",
 178                                          'type' => 'misc');
 179                  }
 180                  $navlinks[] = array('name' => fullname($user),
 181                                      'link' => "$CFG->wwwroot/user/view.php?id=$filterselect&amp;course=$course->id",
 182                                      'type' => 'misc');
 183  
 184                  if ($tagid || !empty($tag)) {
 185                      $navlinks[] = array('name' => $blogstring,
 186                                          'link' => "index.php?courseid=$course->id&amp;filtertype=user&amp;filterselect=$filterselect",
 187                                          'type' => 'misc');
 188                      $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
 189                      $navigation = build_navigation($navlinks);
 190  
 191                  } else {
 192                      $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
 193                      $navigation = build_navigation($navlinks);
 194                  }
 195                  print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
 196  
 197              } else {
 198  
 199              //in top view
 200  
 201                  if ($postid) {
 202                      $navlinks[] = array('name' => fullname($user),
 203                                          'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
 204                                          'type' => 'misc');
 205                      $navlinks[] = array('name' => $blogstring,
 206                                          'link' => "index.php?filtertype=user&amp;filterselect=$filterselect",
 207                                          'type' => 'misc');
 208                      $navlinks[] = array('name' => format_string($postobject->subject), 'link' => null, 'type' => 'misc');
 209                      $navigation = build_navigation($navlinks);
 210  
 211                  } else if ($tagid || !empty($tag)) {
 212                      $navlinks[] = array('name' => fullname($user),
 213                                          'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
 214                                          'type' => 'misc');
 215                      $navlinks[] = array('name' => $blogstring,
 216                                          'link' => "index.php?filtertype=user&amp;filterselect=$filterselect",
 217                                          'type' => 'misc');
 218                      $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
 219                      $navigation = build_navigation($navlinks);
 220  
 221                  } else {
 222                      $navlinks[] = array('name' => fullname($user),
 223                                          'link' => "$CFG->wwwroot/user/view.php?id=$filterselect",
 224                                          'type' => 'misc');
 225                      $navlinks[] = array('name' => $blogstring, 'link' => null, 'type' => 'misc');
 226                      $navigation = build_navigation($navlinks);
 227                  }
 228                  print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
 229  
 230              }
 231          break;
 232  
 233          default:
 234              error ('Error unknown filtertype');
 235          break;
 236      }
 237  
 238  
 239  // prints the tabs
 240  if ($filtertype=='user') {
 241      $showroles = true;
 242  } else {
 243      $showroles = false;
 244  }
 245  $currenttab = 'blogs';
 246  
 247  require_once($CFG->dirroot .'/user/tabs.php');
 248  
 249  
 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";
 253  
 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";
 263  }
 264  
 265  /// Start main column
 266  print '<!-- Begin page content -->' . "\n";
 267  print '<td>';
 268  print_container_start();
 269  ?>
 270  <table width="100%">
 271  <tr>
 272  <td valign="top">


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7