本文整理汇总了PHP中get_home_page函数的典型用法代码示例。如果您正苦于以下问题:PHP get_home_page函数的具体用法?PHP get_home_page怎么用?PHP get_home_page使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_home_page函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialise
/**
* Initialises the navigation object.
*
* This causes the navigation object to look at the current state of the page
* that it is associated with and then load the appropriate content.
*
* This should only occur the first time that the navigation structure is utilised
* which will normally be either when the navbar is called to be displayed or
* when a block makes use of it.
*
* @return bool
*/
public function initialise()
{
global $CFG, $SITE, $USER, $DB;
// Check if it has alread been initialised
if ($this->initialised || during_initial_install()) {
return true;
}
$this->initialised = true;
// Set up the five base root nodes. These are nodes where we will put our
// content and are as follows:
// site: Navigation for the front page.
// myprofile: User profile information goes here.
// mycourses: The users courses get added here.
// courses: Additional courses are added here.
// users: Other users information loaded here.
$this->rootnodes = array();
if (get_home_page() == HOMEPAGE_SITE) {
// The home element should be my moodle because the root element is the site
if (isloggedin() && !isguestuser()) {
// Makes no sense if you aren't logged in
$this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_SETTING, null, 'home');
}
} else {
// The home element should be the site because the root node is my moodle
$this->rootnodes['home'] = $this->add(get_string('sitehome'), new moodle_url('/'), self::TYPE_SETTING, null, 'home');
if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY) {
// We need to stop automatic redirection
$this->rootnodes['home']->action->param('redirect', '0');
}
}
$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['myprofile'] = $this->add(get_string('myprofile'), null, self::TYPE_USER, null, 'myprofile');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), null, self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_ROOTNODE, null, 'courses');
$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');
// We always load the frontpage course to ensure it is available without
// JavaScript enabled.
$this->add_front_page_course_essentials($this->rootnodes['site'], $SITE);
$this->load_course_sections($SITE, $this->rootnodes['site']);
// Fetch all of the users courses.
$mycourses = enrol_get_my_courses();
// We need to show categories if we can show categories and the user isn't enrolled in any courses or we're not showing all courses
$showcategories = $this->show_categories() && (count($mycourses) == 0 || !empty($CFG->navshowallcourses));
// $issite gets set to true if the current pages course is the sites frontpage course
$issite = $this->page->course->id == $SITE->id;
// $ismycourse gets set to true if the user is enrolled in the current pages course.
$ismycourse = !$issite && array_key_exists($this->page->course->id, $mycourses);
// Check if any courses were returned.
if (count($mycourses) > 0) {
// Check if categories should be displayed within the my courses branch
if (!empty($CFG->navshowmycoursecategories)) {
// Find the category of each mycourse
$categories = array();
foreach ($mycourses as $course) {
$categories[] = $course->category;
}
// Do a single DB query to get the categories immediately associated with
// courses the user is enrolled in.
$categories = $DB->get_records_list('course_categories', 'id', array_unique($categories), 'depth ASC, sortorder ASC');
// Work out the parent categories that we need to load that we havn't
// already got.
$categoryids = array();
foreach ($categories as $category) {
$categoryids = array_merge($categoryids, explode('/', trim($category->path, '/')));
}
$categoryids = array_unique($categoryids);
$categoryids = array_diff($categoryids, array_keys($categories));
if (count($categoryids)) {
// Fetch any other categories we need.
$allcategories = $DB->get_records_list('course_categories', 'id', $categoryids, 'depth ASC, sortorder ASC');
if (is_array($allcategories) && count($allcategories) > 0) {
$categories = array_merge($categories, $allcategories);
}
}
// We ONLY want the categories, we need to get rid of the keys
$categories = array_values($categories);
$addedcategories = array();
while (($category = array_shift($categories)) !== null) {
if ($category->parent == '0') {
$categoryparent = $this->rootnodes['mycourses'];
} else {
if (array_key_exists($category->parent, $addedcategories)) {
$categoryparent = $addedcategories[$category->parent];
} else {
// Prepare to count iterations. We don't want to loop forever
// accidentally if for some reason a category can't be placed.
if (!isset($category->loopcount)) {
$category->loopcount = 0;
//.........这里部分代码省略.........
示例2: generate_user_settings
/**
* This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
* what can be shown/done
*
* @param int $courseid The current course' id
* @param int $userid The user id to load for
* @param string $gstitle The string to pass to get_string for the branch title
* @return navigation_node|false
*/
protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
{
global $DB, $CFG, $USER, $SITE;
if ($courseid != $SITE->id) {
if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
$course = $this->page->course;
} else {
$select = context_helper::get_preload_record_columns_sql('ctx');
$sql = "SELECT c.*, {$select}\n FROM {course} c\n JOIN {context} ctx ON c.id = ctx.instanceid\n WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
$params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
context_helper::preload_from_record($course);
}
} else {
$course = $SITE;
}
$coursecontext = context_course::instance($course->id);
// Course context
$systemcontext = context_system::instance();
$currentuser = $USER->id == $userid;
if ($currentuser) {
$user = $USER;
$usercontext = context_user::instance($user->id);
// User context
} else {
$select = context_helper::get_preload_record_columns_sql('ctx');
$sql = "SELECT u.*, {$select}\n FROM {user} u\n JOIN {context} ctx ON u.id = ctx.instanceid\n WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
$params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
$user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
if (!$user) {
return false;
}
context_helper::preload_from_record($user);
// Check that the user can view the profile
$usercontext = context_user::instance($user->id);
// User context
$canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
if ($course->id == $SITE->id) {
if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
// Reduce possibility of "browsing" userbase at site level
// Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
return false;
}
} else {
$canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
$userisenrolled = is_enrolled($coursecontext, $user->id, '', true);
if (!$canviewusercourse && !$canviewuser || !$userisenrolled) {
return false;
}
$canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS && !$canviewuser) {
// If groups are in use, make sure we can see that group (MDL-45874). That does not apply to parents.
if ($courseid == $this->page->course->id) {
$mygroups = get_fast_modinfo($this->page->course)->groups;
} else {
$mygroups = groups_get_user_groups($courseid);
}
$usergroups = groups_get_user_groups($courseid, $userid);
if (!array_intersect_key($mygroups[0], $usergroups[0])) {
return false;
}
}
}
}
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
$key = $gstitle;
$prefurl = new moodle_url('/user/preferences.php');
if ($gstitle != 'usercurrentsettings') {
$key .= $userid;
$prefurl->param('userid', $userid);
}
// Add a user setting branch.
if ($gstitle == 'usercurrentsettings') {
$dashboard = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_CONTAINER, null, 'dashboard');
// This should be set to false as we don't want to show this to the user. It's only for generating the correct
// breadcrumb.
$dashboard->display = false;
if (get_home_page() == HOMEPAGE_MY) {
$dashboard->mainnavonly = true;
}
$iscurrentuser = $user->id == $USER->id;
$baseargs = array('id' => $user->id);
if ($course->id != $SITE->id && !$iscurrentuser) {
$baseargs['course'] = $course->id;
$issitecourse = false;
} else {
// Load all categories and get the context for the system.
$issitecourse = true;
}
// Add the user profile to the dashboard.
$profilenode = $dashboard->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile');
//.........这里部分代码省略.........
示例3: initialise
/**
* Initialises the navigation object.
*
* This causes the navigation object to look at the current state of the page
* that it is associated with and then load the appropriate content.
*
* This should only occur the first time that the navigation structure is utilised
* which will normally be either when the navbar is called to be displayed or
* when a block makes use of it.
*
* @return bool
*/
public function initialise()
{
global $CFG, $SITE, $USER, $DB;
// Check if it has alread been initialised
if ($this->initialised || during_initial_install()) {
return true;
}
$this->initialised = true;
// Set up the five base root nodes. These are nodes where we will put our
// content and are as follows:
// site: Navigation for the front page.
// myprofile: User profile information goes here.
// mycourses: The users courses get added here.
// courses: Additional courses are added here.
// users: Other users information loaded here.
$this->rootnodes = array();
if (get_home_page() == HOMEPAGE_SITE) {
// The home element should be my moodle because the root element is the site
if (isloggedin() && !isguestuser()) {
// Makes no sense if you aren't logged in
$this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_SETTING, null, 'home');
}
} else {
// The home element should be the site because the root node is my moodle
$this->rootnodes['home'] = $this->add(get_string('sitehome'), new moodle_url('/'), self::TYPE_SETTING, null, 'home');
if ($CFG->defaulthomepage == HOMEPAGE_MY) {
// We need to stop automatic redirection
$this->rootnodes['home']->action->param('redirect', '0');
}
}
$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['myprofile'] = $this->add(get_string('myprofile'), null, self::TYPE_USER, null, 'myprofile');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), null, self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');
// Fetch all of the users courses.
$limit = 20;
if (!empty($CFG->navcourselimit)) {
$limit = $CFG->navcourselimit;
}
$mycourses = enrol_get_my_courses(NULL, 'visible DESC,sortorder ASC', $limit);
$showallcourses = count($mycourses) == 0 || !empty($CFG->navshowallcourses);
$showcategories = $showallcourses && $this->show_categories();
$issite = $this->page->course->id != SITEID;
$ismycourse = array_key_exists($this->page->course->id, $mycourses);
// Check if any courses were returned.
if (count($mycourses) > 0) {
// Add all of the users courses to the navigation
foreach ($mycourses as $course) {
$course->coursenode = $this->add_course($course, false, true);
}
}
if ($showallcourses) {
// Load all courses
$this->load_all_courses();
}
// We always load the frontpage course to ensure it is available without
// JavaScript enabled.
$frontpagecourse = $this->load_course($SITE);
$this->add_front_page_course_essentials($frontpagecourse, $SITE);
$canviewcourseprofile = true;
// Next load context specific content into the navigation
switch ($this->page->context->contextlevel) {
case CONTEXT_SYSTEM:
// This has already been loaded we just need to map the variable
$coursenode = $frontpagecourse;
$this->load_all_categories(null, $showcategories);
break;
case CONTEXT_COURSECAT:
// This has already been loaded we just need to map the variable
$coursenode = $frontpagecourse;
$this->load_all_categories($this->page->context->instanceid, $showcategories);
break;
case CONTEXT_BLOCK:
case CONTEXT_COURSE:
// Load the course associated with the page into the navigation
$course = $this->page->course;
if ($showcategories && !$issite && !$ismycourse) {
$this->load_all_categories($course->category, $showcategories);
}
$coursenode = $this->load_course($course);
// If the course wasn't added then don't try going any further.
if (!$coursenode) {
$canviewcourseprofile = false;
break;
}
// If the user is not enrolled then we only want to show the
// course node and not populate it.
//.........这里部分代码省略.........
示例4: redirect
redirect($CFG->wwwroot . '/my/');
}
/// Prepare redirection
if (user_not_fully_set_up($USER)) {
$urltogo = $CFG->wwwroot . '/user/edit.php';
// We don't delete $SESSION->wantsurl yet, so we get there later
} else {
if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0 or strpos($SESSION->wantsurl, str_replace('http://', 'https://', $CFG->wwwroot)) === 0)) {
$urltogo = $SESSION->wantsurl;
/// Because it's an address in this site
unset($SESSION->wantsurl);
} else {
// no wantsurl stored or external - go to homepage
$urltogo = $CFG->wwwroot . '/';
unset($SESSION->wantsurl);
$home_page = get_home_page();
// Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my
if ($home_page == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) {
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot . '/' or $urltogo == $CFG->wwwroot . '/index.php') {
$urltogo = $CFG->wwwroot . '/my/';
}
}
}
}
/// check if user password has expired
/// Currently supported only for ldap-authentication module
$userauth = get_auth_plugin($USER->auth);
if (!empty($userauth->config->expiration) and $userauth->config->expiration == 1) {
if ($userauth->can_change_password()) {
$passwordchangeurl = $userauth->change_password_url();
if (!$passwordchangeurl) {
示例5: user_accesstime_log
} else {
user_accesstime_log();
}
$hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
/// If the site is currently under maintenance, then print a message
if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
print_maintenance_message();
}
if ($hassiteconfig && moodle_needs_upgrading()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
}
if (get_home_page() != HOMEPAGE_SITE) {
// Redirect logged-in users to My Moodle overview if required
if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
} else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 1) {
redirect($CFG->wwwroot .'/my/');
} else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
$PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
}
}
if (isloggedin()) {
add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
}
/// If the hub plugin is installed then we let it take over the homepage here
示例6: core_login_get_return_url
/** Determine where a user should be redirected after they have been logged in.
* @return string url the user should be redirected to.
*/
function core_login_get_return_url()
{
global $CFG, $SESSION, $USER;
// Prepare redirection.
if (user_not_fully_set_up($USER)) {
$urltogo = $CFG->wwwroot . '/user/edit.php';
// We don't delete $SESSION->wantsurl yet, so we get there later.
} else {
if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0 or strpos($SESSION->wantsurl, str_replace('http://', 'https://', $CFG->wwwroot)) === 0)) {
$urltogo = $SESSION->wantsurl;
// Because it's an address in this site.
unset($SESSION->wantsurl);
} else {
// No wantsurl stored or external - go to homepage.
$urltogo = $CFG->wwwroot . '/';
unset($SESSION->wantsurl);
}
}
// If the url to go to is the same as the site page, check for default homepage.
if ($urltogo == $CFG->wwwroot . '/') {
$homepage = get_home_page();
// Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my.
if ($homepage == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) {
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot . '/' or $urltogo == $CFG->wwwroot . '/index.php') {
$urltogo = $CFG->wwwroot . '/my/';
}
}
}
return $urltogo;
}
示例7: initialise
/**
* Initialises the navigation object.
*
* This causes the navigation object to look at the current state of the page
* that it is associated with and then load the appropriate content.
*
* This should only occur the first time that the navigation structure is utilised
* which will normally be either when the navbar is called to be displayed or
* when a block makes use of it.
*
* @return bool
*/
public function initialise()
{
global $CFG, $SITE, $USER;
// Check if it has already been initialised
if ($this->initialised || during_initial_install()) {
return true;
}
$this->initialised = true;
// Set up the five base root nodes. These are nodes where we will put our
// content and are as follows:
// site: Navigation for the front page.
// myprofile: User profile information goes here.
// currentcourse: The course being currently viewed.
// mycourses: The users courses get added here.
// courses: Additional courses are added here.
// users: Other users information loaded here.
$this->rootnodes = array();
if (get_home_page() == HOMEPAGE_SITE) {
// The home element should be my moodle because the root element is the site
if (isloggedin() && !isguestuser()) {
// Makes no sense if you aren't logged in
$this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_SETTING, null, 'home');
}
} else {
// The home element should be the site because the root node is my moodle
$this->rootnodes['home'] = $this->add(get_string('sitehome'), new moodle_url('/'), self::TYPE_SETTING, null, 'home');
if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY) {
// We need to stop automatic redirection
$this->rootnodes['home']->action->param('redirect', '0');
}
}
$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['myprofile'] = $this->add(get_string('myprofile'), null, self::TYPE_USER, null, 'myprofile');
$this->rootnodes['currentcourse'] = $this->add(get_string('currentcourse'), null, self::TYPE_ROOTNODE, null, 'currentcourse');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my/'), self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_ROOTNODE, null, 'courses');
$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');
// We always load the frontpage course to ensure it is available without
// JavaScript enabled.
$this->add_front_page_course_essentials($this->rootnodes['site'], $SITE);
$this->load_course_sections($SITE, $this->rootnodes['site']);
$course = $this->page->course;
// $issite gets set to true if the current pages course is the sites frontpage course
$issite = $this->page->course->id == $SITE->id;
// Determine if the user is enrolled in any course.
$enrolledinanycourse = enrol_user_sees_own_courses();
$this->rootnodes['currentcourse']->mainnavonly = true;
if ($enrolledinanycourse) {
$this->rootnodes['mycourses']->isexpandable = true;
if ($CFG->navshowallcourses) {
// When we show all courses we need to show both the my courses and the regular courses branch.
$this->rootnodes['courses']->isexpandable = true;
}
} else {
$this->rootnodes['courses']->isexpandable = true;
}
if ($this->rootnodes['mycourses']->isactive) {
$this->load_courses_enrolled();
}
$canviewcourseprofile = true;
// Next load context specific content into the navigation
switch ($this->page->context->contextlevel) {
case CONTEXT_SYSTEM:
// Nothing left to do here I feel.
break;
case CONTEXT_COURSECAT:
// This is essential, we must load categories.
$this->load_all_categories($this->page->context->instanceid, true);
break;
case CONTEXT_BLOCK:
case CONTEXT_COURSE:
if ($issite) {
// Nothing left to do here.
break;
}
// Load the course associated with the current page into the navigation.
$coursenode = $this->add_course($course, false, self::COURSE_CURRENT);
// If the course wasn't added then don't try going any further.
if (!$coursenode) {
$canviewcourseprofile = false;
break;
}
// If the user is not enrolled then we only want to show the
// course node and not populate it.
// Not enrolled, can't view, and hasn't switched roles
if (!can_access_course($course)) {
// Very ugly hack - do not force "parents" to enrol into course their child is enrolled in,
// this hack has been propagated from user/view.php to display the navigation node. (MDL-25805)
//.........这里部分代码省略.........
示例8: array
$context = context_system::instance(); // So we even see non-sticky blocks
}
// Start setting up the page
$params = array();
$PAGE->set_context($context);
$PAGE->set_url('/dashboard/dashboardview.php', $params);
$PAGE->set_pagelayout('dashboardview');
//$PAGE->set_pagetype('my-index');
//$PAGE->blocks->add_region('content');
$PAGE->set_subpage($currentpage->id);
$PAGE->set_title($header);
$PAGE->set_heading($header);
if (!isguestuser()) { // Skip default home page for guests
if (get_home_page() != HOMEPAGE_MY) {
if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
set_user_preference('user_home_page_preference', HOMEPAGE_MY);
} else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) {
$PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/my/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
}
}
}
// Toggle the editing state and switches
if ($PAGE->user_allowed_editing()) {
if ($reset !== null) {
if (!is_null($userid)) {
require_sesskey();
if(!$currentpage = my_reset_page($userid, MY_PAGE_PRIVATE)){
print_error('reseterror', 'my');
示例9: get_site_info
//.........这里部分代码省略.........
* it was an original design error, we keep for backward compatibility.
* @return array site info
* @since Moodle 2.2
*/
public static function get_site_info($serviceshortnames = array())
{
global $USER, $SITE, $CFG, $DB, $PAGE;
$params = self::validate_parameters(self::get_site_info_parameters(), array('serviceshortnames' => $serviceshortnames));
$context = context_user::instance($USER->id);
$userpicture = new user_picture($USER);
$userpicture->size = 1;
// Size f1.
$profileimageurl = $userpicture->get_url($PAGE);
// Site information.
$siteinfo = array('sitename' => $SITE->fullname, 'siteurl' => $CFG->wwwroot, 'username' => $USER->username, 'firstname' => $USER->firstname, 'lastname' => $USER->lastname, 'fullname' => fullname($USER), 'lang' => current_language(), 'userid' => $USER->id, 'userpictureurl' => $profileimageurl->out(false));
// Retrieve the service and functions from the web service linked to the token
// If you call this function directly from external (not a web service call),
// then it will still return site info without information about a service
// Note: wsusername/wspassword ws authentication is not supported.
$functions = array();
if ($CFG->enablewebservices) {
// No need to check token if web service are disabled and not a ws call.
$token = optional_param('wstoken', '', PARAM_ALPHANUM);
if (!empty($token)) {
// No need to run if not a ws call.
// Retrieve service shortname.
$servicesql = 'SELECT s.*
FROM {external_services} s, {external_tokens} t
WHERE t.externalserviceid = s.id AND token = ? AND t.userid = ? AND s.enabled = 1';
$service = $DB->get_record_sql($servicesql, array($token, $USER->id));
$siteinfo['downloadfiles'] = $service->downloadfiles;
$siteinfo['uploadfiles'] = $service->uploadfiles;
if (!empty($service)) {
// Return the release and version number for web service users only.
$siteinfo['release'] = $CFG->release;
$siteinfo['version'] = $CFG->version;
// Retrieve the functions.
$functionssql = "SELECT f.*\n FROM {external_functions} f, {external_services_functions} sf\n WHERE f.name = sf.functionname AND sf.externalserviceid = ?";
$functions = $DB->get_records_sql($functionssql, array($service->id));
} else {
throw new coding_exception('No service found in get_site_info: something is buggy, \\
it should have fail at the ws server authentication layer.');
}
}
}
// Build up the returned values of the list of functions.
$componentversions = array();
$availablefunctions = array();
foreach ($functions as $function) {
$functioninfo = array();
$functioninfo['name'] = $function->name;
if ($function->component == 'moodle' || $function->component == 'core') {
$version = $CFG->version;
// Moodle version.
} else {
$versionpath = core_component::get_component_directory($function->component) . '/version.php';
if (is_readable($versionpath)) {
// We store the component version once retrieved (so we don't load twice the version.php).
if (!isset($componentversions[$function->component])) {
$plugin = new stdClass();
include $versionpath;
$componentversions[$function->component] = $plugin->version;
$version = $plugin->version;
} else {
$version = $componentversions[$function->component];
}
} else {
// Function component should always have a version.php,
// otherwise the function should have been described with component => 'moodle'.
throw new moodle_exception('missingversionfile', 'webservice', '', $function->component);
}
}
$functioninfo['version'] = $version;
$availablefunctions[] = $functioninfo;
}
$siteinfo['functions'] = $availablefunctions;
// Mobile CSS theme and alternative login url.
$siteinfo['mobilecssurl'] = $CFG->mobilecssurl;
// Retrieve some advanced features. Only enable/disable ones (bool).
$advancedfeatures = array("usecomments", "usetags", "enablenotes", "messaging", "enableblogs", "enablecompletion", "enablebadges");
foreach ($advancedfeatures as $feature) {
if (isset($CFG->{$feature})) {
$siteinfo['advancedfeatures'][] = array('name' => $feature, 'value' => (int) $CFG->{$feature});
}
}
// Special case mnet_dispatcher_mode.
$siteinfo['advancedfeatures'][] = array('name' => 'mnet_dispatcher_mode', 'value' => $CFG->mnet_dispatcher_mode == 'strict' ? 1 : 0);
// User can manage own files.
$siteinfo['usercanmanageownfiles'] = has_capability('moodle/user:manageownfiles', $context);
// User quota. 0 means user can ignore the quota.
$siteinfo['userquota'] = 0;
if (!has_capability('moodle/user:ignoreuserquota', $context)) {
$siteinfo['userquota'] = $CFG->userquota;
}
// User max upload file size. -1 means the user can ignore the upload file size.
$siteinfo['usermaxuploadfilesize'] = get_user_max_upload_file_size($context, $CFG->maxbytes);
// User home page.
$siteinfo['userhomepage'] = get_home_page();
return $siteinfo;
}
示例10: defined
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* My Moodle -- a user's personal dashboard
*
* @package local_my
* @category local
* @reauthor Valery Fremaux <valery.fremaux@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once $CFG->dirroot . '/local/my/lib.php';
$localmyconfig = get_config('local_my');
/*
* This hook redraws the my routing policy using local/my:overridemy switch and my force setting.
*/
if (get_home_page() != HOMEPAGE_SITE && !isguestuser($USER->id)) {
// Redirect logged-in users to My Moodle overview if required.
if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
} else {
if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY) {
if ($localmyconfig->force && !local_has_myoverride_somewhere()) {
redirect(new moodle_url('/my'));
}
if (optional_param('redirect', 1, PARAM_BOOL) === 1) {
redirect(new moodle_url('/my'));
}
} else {
if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) {
$linkurl = new moodle_url('/', array('setdefaulthome' => true));
$PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), $linkurl, navigation_node::TYPE_SETTING);