Search moodle.org's
Developer Documentation


Long Term Support Release

  • Bug fixes for general core bugs in 3.1.x ended 8 May 2017 (12 months).
  • Bug fixes for security issues in 3.1.x ended 13 May 2019 (36 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x , 5.5.x or 5.6.x on Windows - http://windows.php.net/download/). PHP 7.0.x is supported but has some engine limitations. PHP 7.1.x is not supported.
  • / -> index.php (source)

    Differences Between: [Versions 29 and 31] [Versions 30 and 31] [Versions 31 and 32] [Versions 31 and 33] [Versions 31 and 34] [Versions 31 and 35] [Versions 31 and 36] [Versions 31 and 37] [Versions 31 and 38]

       1  <?php
       2  // This file is part of Moodle - http://moodle.org/
       3  //
       4  // Moodle is free software: you can redistribute it and/or modify
       5  // it under the terms of the GNU General Public License as published by
       6  // the Free Software Foundation, either version 3 of the License, or
       7  // (at your option) any later version.
       8  //
       9  // Moodle is distributed in the hope that it will be useful,
      10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12  // GNU General Public License for more details.
      13  //
      14  // You should have received a copy of the GNU General Public License
      15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
      16  
      17  /**
      18   * Moodle frontpage.
      19   *
      20   * @package    core
      21   * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
      22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      23   */
      24  
      25  if (!file_exists('./config.php')) {
      26      header('Location: install.php');
      27      die;
      28  }
      29  
      30  require_once('config.php');
      31  require_once($CFG->dirroot .'/course/lib.php');
      32  require_once($CFG->libdir .'/filelib.php');
      33  
      34  redirect_if_major_upgrade_required();
      35  
      36  $urlparams = array();
      37  if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 0) {
      38      $urlparams['redirect'] = 0;
      39  }
      40  $PAGE->set_url('/', $urlparams);
      41  $PAGE->set_pagelayout('frontpage');
      42  $PAGE->set_other_editing_capability('moodle/course:update');
      43  $PAGE->set_other_editing_capability('moodle/course:manageactivities');
      44  $PAGE->set_other_editing_capability('moodle/course:activityvisibility');
      45  
      46  // Prevent caching of this page to stop confusion when changing page after making AJAX changes.
      47  $PAGE->set_cacheable(false);
      48  
      49  require_course_login($SITE);
      50  
      51  $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
      52  
      53  // If the site is currently under maintenance, then print a message.
      54  if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
      55      print_maintenance_message();
      56  }
      57  
      58  if ($hassiteconfig && moodle_needs_upgrading()) {
      59      redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
      60  }
      61  
      62  if (get_home_page() != HOMEPAGE_SITE) {
      63      // Redirect logged-in users to My Moodle overview if required.
      64      $redirect = optional_param('redirect', 1, PARAM_BOOL);
      65      if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
      66          set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
      67      } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
      68          redirect($CFG->wwwroot .'/my/');
      69      } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
      70          $frontpagenode = $PAGE->settingsnav->find('frontpage', null);
      71          if ($frontpagenode) {
      72              $frontpagenode->add(
      73                  get_string('makethismyhome'),
      74                  new moodle_url('/', array('setdefaulthome' => true)),
      75                  navigation_node::TYPE_SETTING);
      76          } else {
      77              $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);
      78              $frontpagenode->force_open();
      79              $frontpagenode->add(get_string('makethismyhome'),
      80                  new moodle_url('/', array('setdefaulthome' => true)),
      81                  navigation_node::TYPE_SETTING);
      82          }
      83      }
      84  }
      85  
      86  // Trigger event.
      87  course_view(context_course::instance(SITEID));
      88  
      89  // If the hub plugin is installed then we let it take over the homepage here.
      90  if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {
      91      require_once($CFG->dirroot.'/local/hub/lib.php');
      92      $hub = new local_hub();
      93      $continue = $hub->display_homepage();
      94      // Function display_homepage() returns true if the hub home page is not displayed
      95      // ...mostly when search form is not displayed for not logged users.
      96      if (empty($continue)) {
      97          exit;
      98      }
      99  }
     100  
     101  $PAGE->set_pagetype('site-index');
     102  $PAGE->set_docs_path('');
     103  $editing = $PAGE->user_is_editing();
     104  $PAGE->set_title($SITE->fullname);
     105  $PAGE->set_heading($SITE->fullname);
     106  $courserenderer = $PAGE->get_renderer('core', 'course');
     107  echo $OUTPUT->header();
     108  
     109  // Print Section or custom info.
     110  $siteformatoptions = course_get_format($SITE)->get_format_options();
     111  $modinfo = get_fast_modinfo($SITE);
     112  $modnames = get_module_types_names();
     113  $modnamesplural = get_module_types_names(true);
     114  $modnamesused = $modinfo->get_used_module_names();
     115  $mods = $modinfo->get_cms();
     116  
     117  if (!empty($CFG->customfrontpageinclude)) {
     118      include($CFG->customfrontpageinclude);
     119  
     120  } else if ($siteformatoptions['numsections'] > 0) {
     121      if ($editing) {
     122          // Make sure section with number 1 exists.
     123          course_create_sections_if_missing($SITE, 1);
     124          // Re-request modinfo in case section was created.
     125          $modinfo = get_fast_modinfo($SITE);
     126      }
     127      $section = $modinfo->get_section_info(1);
     128      if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
     129          echo $OUTPUT->box_start('generalbox sitetopic');
     130  
     131          // If currently moving a file then show the current clipboard.
     132          if (ismoving($SITE->id)) {
     133              $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
     134              echo '<p><font size="2">';
     135              echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">";
     136              echo get_string('cancel') . '</a>)';
     137              echo '</font></p>';
     138          }
     139  
     140          $context = context_course::instance(SITEID);
     141  
     142          // If the section name is set we show it.
     143          if (trim($section->name) !== '') {
     144              echo $OUTPUT->heading(
     145                  format_string($section->name, true, array('context' => $context)),
     146                  2,
     147                  'sectionname'
     148              );
     149          }
     150  
     151          $summarytext = file_rewrite_pluginfile_urls($section->summary,
     152              'pluginfile.php',
     153              $context->id,
     154              'course',
     155              'section',
     156              $section->id);
     157          $summaryformatoptions = new stdClass();
     158          $summaryformatoptions->noclean = true;
     159          $summaryformatoptions->overflowdiv = true;
     160  
     161          echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
     162  
     163          if ($editing && has_capability('moodle/course:update', $context)) {
     164              $streditsummary = get_string('editsummary');
     165              echo "<a title=\"$streditsummary\" ".
     166                   " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
     167                   " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
     168          }
     169  
     170          $courserenderer = $PAGE->get_renderer('core', 'course');
     171          echo $courserenderer->course_section_cm_list($SITE, $section);
     172  
     173          echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
     174          echo $OUTPUT->box_end();
     175      }
     176  }
     177  // Include course AJAX.
     178  include_course_ajax($SITE, $modnamesused);
     179  
     180  if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
     181      $frontpagelayout = $CFG->frontpageloggedin;
     182  } else {
     183      $frontpagelayout = $CFG->frontpage;
     184  }
     185  
     186  foreach (explode(',', $frontpagelayout) as $v) {
     187      switch ($v) {
     188          // Display the main part of the front page.
     189          case FRONTPAGENEWS:
     190              if ($SITE->newsitems) {
     191                  // Print forums only when needed.
     192                  require_once($CFG->dirroot .'/mod/forum/lib.php');
     193  
     194                  if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
     195                      print_error('cannotfindorcreateforum', 'forum');
     196                  }
     197  
     198                  // Fetch news forum context for proper filtering to happen.
     199                  $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
     200                  $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);
     201  
     202                  $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
     203                  echo html_writer::link('#skipsitenews',
     204                      get_string('skipa', 'access', core_text::strtolower(strip_tags($forumname))),
     205                      array('class' => 'skip-block skip'));
     206  
     207                  // Wraps site news forum in div container.
     208                  echo html_writer::start_tag('div', array('id' => 'site-news-forum'));
     209  
     210                  if (isloggedin()) {
     211                      $SESSION->fromdiscussion = $CFG->wwwroot;
     212                      $subtext = '';
     213                      if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
     214                          if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
     215                              $subtext = get_string('unsubscribe', 'forum');
     216                          }
     217                      } else {
     218                          $subtext = get_string('subscribe', 'forum');
     219                      }
     220                      echo $OUTPUT->heading($forumname);
     221                      $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
     222                      echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
     223                  } else {
     224                      echo $OUTPUT->heading($forumname);
     225                  }
     226  
     227                  forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
     228  
     229                  // End site news forum div container.
     230                  echo html_writer::end_tag('div');
     231  
     232                  echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews'));
     233              }
     234          break;
     235  
     236          case FRONTPAGEENROLLEDCOURSELIST:
     237              $mycourseshtml = $courserenderer->frontpage_my_courses();
     238              if (!empty($mycourseshtml)) {
     239                  echo html_writer::link('#skipmycourses',
     240                      get_string('skipa', 'access', core_text::strtolower(get_string('mycourses'))),
     241                      array('class' => 'skip skip-block'));
     242  
     243                  // Wrap frontpage course list in div container.
     244                  echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
     245  
     246                  echo $OUTPUT->heading(get_string('mycourses'));
     247                  echo $mycourseshtml;
     248  
     249                  // End frontpage course list div container.
     250                  echo html_writer::end_tag('div');
     251  
     252                  echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipmycourses'));
     253                  break;
     254              }
     255              // No "break" here. If there are no enrolled courses - continue to 'Available courses'.
     256  
     257          case FRONTPAGEALLCOURSELIST:
     258              $availablecourseshtml = $courserenderer->frontpage_available_courses();
     259              if (!empty($availablecourseshtml)) {
     260                  echo html_writer::link('#skipavailablecourses',
     261                      get_string('skipa', 'access', core_text::strtolower(get_string('availablecourses'))),
     262                      array('class' => 'skip skip-block'));
     263  
     264                  // Wrap frontpage course list in div container.
     265                  echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
     266  
     267                  echo $OUTPUT->heading(get_string('availablecourses'));
     268                  echo $availablecourseshtml;
     269  
     270                  // End frontpage course list div container.
     271                  echo html_writer::end_tag('div');
     272  
     273                  echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipavailablecourses'));
     274              }
     275          break;
     276  
     277          case FRONTPAGECATEGORYNAMES:
     278              echo html_writer::link('#skipcategories',
     279                  get_string('skipa', 'access', core_text::strtolower(get_string('categories'))),
     280                  array('class' => 'skip skip-block'));
     281  
     282              // Wrap frontpage category names in div container.
     283              echo html_writer::start_tag('div', array('id' => 'frontpage-category-names'));
     284  
     285              echo $OUTPUT->heading(get_string('categories'));
     286              echo $courserenderer->frontpage_categories_list();
     287  
     288              // End frontpage category names div container.
     289              echo html_writer::end_tag('div');
     290  
     291              echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcategories'));
     292          break;
     293  
     294          case FRONTPAGECATEGORYCOMBO:
     295              echo html_writer::link('#skipcourses',
     296                  get_string('skipa', 'access', core_text::strtolower(get_string('courses'))),
     297                  array('class' => 'skip skip-block'));
     298  
     299              // Wrap frontpage category combo in div container.
     300              echo html_writer::start_tag('div', array('id' => 'frontpage-category-combo'));
     301  
     302              echo $OUTPUT->heading(get_string('courses'));
     303              echo $courserenderer->frontpage_combo_list();
     304  
     305              // End frontpage category combo div container.
     306              echo html_writer::end_tag('div');
     307  
     308              echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcourses'));
     309          break;
     310  
     311          case FRONTPAGECOURSESEARCH:
     312              echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');
     313          break;
     314  
     315      }
     316      echo '<br />';
     317  }
     318  if ($editing && has_capability('moodle/course:create', context_system::instance())) {
     319      echo $courserenderer->add_new_course_button();
     320  }
     321  echo $OUTPUT->footer();
    

    Search This Site: