Merge branch 'MDL-65094-35' of git://github.com/rezaies/moodle into MOODLE_35_STABLE

This commit is contained in:
Eloy Lafuente (stronk7)
2019-04-04 22:40:10 +02:00
3 changed files with 30 additions and 9 deletions
+1 -2
View File
@@ -823,8 +823,7 @@ class core_admin_renderer extends plugin_renderer_base {
*/
protected function registration_warning($registered) {
if (!$registered) {
if (!$registered && site_is_public()) {
if (has_capability('moodle/site:config', context_system::instance())) {
$registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
get_string('register', 'admin'));
+4 -7
View File
@@ -512,13 +512,10 @@ class registration {
$markasviewed = true;
} else {
$showregistration = !empty($CFG->registrationpending);
if ($showregistration) {
$host = parse_url($CFG->wwwroot, PHP_URL_HOST);
if ($host === 'localhost' || preg_match('|^127\.\d+\.\d+\.\d+$|', $host)) {
// If it's a localhost, don't redirect to registration, it won't work anyway.
$showregistration = false;
$markasviewed = true;
}
if ($showregistration && !site_is_public()) {
// If it's not a public site, don't redirect to registration, it won't work anyway.
$showregistration = false;
$markasviewed = true;
}
}
if ($markasviewed !== null) {
+25
View File
@@ -10206,3 +10206,28 @@ function get_callable_name($callable) {
return $name;
}
}
/**
* Tries to guess if $CFG->wwwroot is publicly accessible or not.
* Never put your faith on this function and rely on its accuracy as there might be false positives.
* It just performs some simple checks, and mainly is used for places where we want to hide some options
* such as site registration when $CFG->wwwroot is not publicly accessible.
* Good thing is there is no false negative.
*
* @return bool
*/
function site_is_public() {
global $CFG;
$host = parse_url($CFG->wwwroot, PHP_URL_HOST);
if ($host === 'localhost' || preg_match('|^127\.\d+\.\d+\.\d+$|', $host)) {
$ispublic = false;
} else if (\core\ip_utils::is_ip_address($host) && !ip_is_public($host)) {
$ispublic = false;
} else {
$ispublic = true;
}
return $ispublic;
}