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