Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 3.3.x ended 17 May 2018 (12 months).
  • Bug fixes for security issues in 3.3.x ended 12 November 2018 (18 months).
  • minimum PHP 5.6.5. Note: minimum PHP version has increased since Moodle 3.1. PHP 7.0.x and 7.1.x are supported but have some engine limitations.
  • / -> index.php (source)

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

       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  $hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance());
      52  
      53  // If the site is currently under maintenance, then print a message.
      54  if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
      55      print_maintenance_message();
      56  }
      57  
      58  $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
      59  
      60  if ($hassiteconfig && moodle_needs_upgrading()) {
      61      redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
      62  }
      63  
      64  if (get_home_page() != HOMEPAGE_SITE) {
      65      // Redirect logged-in users to My Moodle overview if required.
      66      $redirect = optional_param('redirect', 1, PARAM_BOOL);
      67      if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
      68          set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
      69      } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
      70          redirect($CFG->wwwroot .'/my/');
      71      } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
      72          $frontpagenode = $PAGE->settingsnav->find('frontpage', null);
      73          if ($frontpagenode) {
      74              $frontpagenode->add(
      75                  get_string('makethismyhome'),
      76                  new moodle_url('/', array('setdefaulthome' => true)),
      77                  navigation_node::TYPE_SETTING);
      78          } else {
      79              $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);
      80              $frontpagenode->force_open();
      81              $frontpagenode->add(get_string('makethismyhome'),
      82                  new moodle_url('/', array('setdefaulthome' => true)),
      83                  navigation_node::TYPE_SETTING);
      84          }
      85      }
      86  }
      87  
      88  // Trigger event.
      89  course_view(context_course::instance(SITEID));
      90  
      91  // If the hub plugin is installed then we let it take over the homepage here.
      92  if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {
      93      require_once($CFG->dirroot.'/local/hub/lib.php');
      94      $hub = new local_hub();
      95      $continue = $hub->display_homepage();
      96      // Function display_homepage() returns true if the hub home page is not displayed
      97      // ...mostly when search form is not displayed for not logged users.
      98      if (empty($continue)) {
      99          exit;
     100      }
     101  }
     102  
     103  $PAGE->set_pagetype('site-index');
     104  $PAGE->set_docs_path('');
     105  $editing = $PAGE->user_is_editing();
     106  $PAGE->set_title($SITE->fullname);
     107  $PAGE->set_heading($SITE->fullname);
     108  $courserenderer = $PAGE->get_renderer('core', 'course');
     109  echo $OUTPUT->header();
     110  
     111  // Print Section or custom info.
     112  $siteformatoptions = course_get_format($SITE)->get_format_options();
     113  $modinfo = get_fast_modinfo($SITE);
     114  $modnames = get_module_types_names();
     115  $modnamesplural = get_module_types_names(true);
     116  $modnamesused = $modinfo->get_used_module_names();
     117  $mods = $modinfo->get_cms();
     118  
     119  if (!empty($CFG->customfrontpageinclude)) {
     120      include($CFG->customfrontpageinclude);
     121  
     122  } else if ($siteformatoptions['numsections'] > 0) {
     123      if ($editing) {
     124          // Make sure section with number 1 exists.
     125          course_create_sections_if_missing($SITE, 1);
     126          // Re-request modinfo in case section was created.
     127          $modinfo = get_fast_modinfo($SITE);
     128      }
     129      $section = $modinfo->get_section_info(1);
     130      if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
     131          echo $OUTPUT->box_start('generalbox sitetopic');
     132  
     133          // If currently moving a file then show the current clipboard.
     134          if (ismoving($SITE->id)) {
     135              $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
     136              echo '<p><font size="2">';
     137              echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">";
     138              echo get_string('cancel') . '</a>)';
     139              echo '</font></p>';
     140          }
     141  
     142          $context = context_course::instance(SITEID);
     143  
     144          // If the section name is set we show it.
     145          if (trim($section->name) !== '') {
     146              echo $OUTPUT->heading(
     147                  format_string($section->name, true, array('context' => $context)),
     148                  2,
     149                  'sectionname'
     150              );
     151          }
     152  
     153          $summarytext = file_rewrite_pluginfile_urls($section->summary,
     154              'pluginfile.php',
     155              $context->id,
     156              'course',
     157              'section',
     158              $section->id);
     159          $summaryformatoptions = new stdClass();
     160          $summaryformatoptions->noclean = true;
     161          $summaryformatoptions->overflowdiv = true;
     162  
     163          echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
     164  
     165          if ($editing && has_capability('moodle/course:update', $context)) {
     166              $streditsummary = get_string('editsummary');
     167              echo "<a title=\"$streditsummary\" " .
     168                   " href=\"course/editsection.php?id=$section->id\">" . $OUTPUT->pix_icon('t/edit', $streditsummary) .
     169                   "</a><br /><br />";
     170          }
     171  
     172          $courserenderer = $PAGE->get_renderer('core', 'course');
     173          echo $courserenderer->course_section_cm_list($SITE, $section);
     174  
     175          echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
     176          echo $OUTPUT->box_end();
     177      }
     178  }
     179  // Include course AJAX.
     180  include_course_ajax($SITE, $modnamesused);
     181  
     182  if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
     183      $frontpagelayout = $CFG->frontpageloggedin;
     184  } else {
     185      $frontpagelayout = $CFG->frontpage;
     186  }
     187  
     188  foreach (explode(',', $frontpagelayout) as $v) {
     189      switch ($v) {
     190          // Display the main part of the front page.
     191          case FRONTPAGENEWS:
     192              if ($SITE->newsitems) {
     193                  // Print forums only when needed.
     194                  require_once($CFG->dirroot .'/mod/forum/lib.php');
     195  
     196                  if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
     197                      print_error('cannotfindorcreateforum', 'forum');
     198                  }
     199  
     200                  // Fetch news forum context for proper filtering to happen.
     201                  $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
     202                  $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);
     203  
     204                  $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
     205                  echo html_writer::link('#skipsitenews',
     206                      get_string('skipa', 'access', core_text::strtolower(strip_tags($forumname))),
     207                      array('class' => 'skip-block skip'));
     208  
     209                  // Wraps site news forum in div container.
     210                  echo html_writer::start_tag('div', array('id' => 'site-news-forum'));
     211  
     212                  if (isloggedin()) {
     213                      $SESSION->fromdiscussion = $CFG->wwwroot;
     214                      $subtext = '';
     215                      if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
     216                          if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
     217                              $subtext = get_string('unsubscribe', 'forum');
     218                          }
     219                      } else {
     220                          $subtext = get_string('subscribe', 'forum');
     221                      }
     222                      echo $OUTPUT->heading($forumname);
     223                      $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
     224                      echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
     225                  } else {
     226                      echo $OUTPUT->heading($forumname);
     227                  }
     228  
     229                  forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
     230  
     231                  // End site news forum div container.
     232                  echo html_writer::end_tag('div');
     233  
     234                  echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews'));
     235              }
     236          break;
     237  
     238          case FRONTPAGEENROLLEDCOURSELIST:
     239              $mycourseshtml = $courserenderer->frontpage_my_courses();
     240              if (!empty($mycourseshtml)) {
     241                  echo html_writer::link('#skipmycourses',
     242                      get_string('skipa', 'access', core_text::strtolower(get_string('mycourses'))),
     243                      array('class' => 'skip skip-block'));
     244  
     245                  // Wrap frontpage course list in div container.
     246                  echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
     247  
     248                  echo $OUTPUT->heading(get_string('mycourses'));
     249                  echo $mycourseshtml;
     250  
     251                  // End frontpage course list div container.
     252                  echo html_writer::end_tag('div');
     253  
     254                  echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipmycourses'));
     255                  break;
     256              }
     257              // No "break" here. If there are no enrolled courses - continue to 'Available courses'.
     258  
     259          case FRONTPAGEALLCOURSELIST:
     260              $availablecourseshtml = $courserenderer->frontpage_available_courses();
     261              if (!empty($availablecourseshtml)) {
     262                  echo html_writer::link('#skipavailablecourses',
     263                      get_string('skipa', 'access', core_text::strtolower(get_string('availablecourses'))),
     264                      array('class' => 'skip skip-block'));
     265  
     266                  // Wrap frontpage course list in div container.
     267                  echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
     268  
     269                  echo $OUTPUT->heading(get_string('availablecourses'));
     270                  echo $availablecourseshtml;
     271  
     272                  // End frontpage course list div container.
     273                  echo html_writer::end_tag('div');
     274  
     275                  echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipavailablecourses'));
     276              }
     277          break;
     278  
     279          case FRONTPAGECATEGORYNAMES:
     280              echo html_writer::link('#skipcategories',
     281                  get_string('skipa', 'access', core_text::strtolower(get_string('categories'))),
     282                  array('class' => 'skip skip-block'));
     283  
     284              // Wrap frontpage category names in div container.
     285              echo html_writer::start_tag('div', array('id' => 'frontpage-category-names'));
     286  
     287              echo $OUTPUT->heading(get_string('categories'));
     288              echo $courserenderer->frontpage_categories_list();
     289  
     290              // End frontpage category names div container.
     291              echo html_writer::end_tag('div');
     292  
     293              echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcategories'));
     294          break;
     295  
     296          case FRONTPAGECATEGORYCOMBO:
     297              echo html_writer::link('#skipcourses',
     298                  get_string('skipa', 'access', core_text::strtolower(get_string('courses'))),
     299                  array('class' => 'skip skip-block'));
     300  
     301              // Wrap frontpage category combo in div container.
     302              echo html_writer::start_tag('div', array('id' => 'frontpage-category-combo'));
     303  
     304              echo $OUTPUT->heading(get_string('courses'));
     305              echo $courserenderer->frontpage_combo_list();
     306  
     307              // End frontpage category combo div container.
     308              echo html_writer::end_tag('div');
     309  
     310              echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcourses'));
     311          break;
     312  
     313          case FRONTPAGECOURSESEARCH:
     314              echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');
     315          break;
     316  
     317      }
     318      echo '<br />';
     319  }
     320  if ($editing && has_capability('moodle/course:create', context_system::instance())) {
     321      echo $courserenderer->add_new_course_button();
     322  }
     323  echo $OUTPUT->footer();
    

    Search This Site: