Merge branch 'MDL-65094-master' of git://github.com/rezaies/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 4 Apr 2019 20:32:52 +0000 (22:32 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 4 Apr 2019 20:32:52 +0000 (22:32 +0200)
1  2 
admin/renderer.php
lib/moodlelib.php

diff --combined admin/renderer.php
@@@ -843,8 -843,7 +843,7 @@@ class core_admin_renderer extends plugi
       */
      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'));
                      $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext label');
                  } else {
                      $row->attributes['class'] .= ' extension';
 -                    $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext label label-info');
 +                    $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info');
                  }
  
                  $coredependency = $plugin->is_core_dependency_satisfied($version);
                  $statusclass = 'statustext label ';
                  switch ($statuscode) {
                      case core_plugin_manager::PLUGIN_STATUS_NEW:
 -                        $statusclass .= $dependenciesok ? 'label-success' : 'label-warning';
 +                        $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning';
                          break;
                      case core_plugin_manager::PLUGIN_STATUS_UPGRADE:
 -                        $statusclass .= $dependenciesok ? 'label-info' : 'label-warning';
 +                        $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning';
                          break;
                      case core_plugin_manager::PLUGIN_STATUS_MISSING:
                      case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE:
                      case core_plugin_manager::PLUGIN_STATUS_DELETE:
 -                        $statusclass .= 'label-important';
 +                        $statusclass .= 'badge-danger';
                          break;
                      case core_plugin_manager::PLUGIN_STATUS_NODB:
                      case core_plugin_manager::PLUGIN_STATUS_UPTODATE:
 -                        $statusclass .= $dependenciesok ? '' : 'label-warning';
 +                        $statusclass .= $dependenciesok ? '' : 'badge-warning';
                          break;
                  }
                  $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass);
              $supportedmoodles = array();
              foreach ($plugin->version->supportedmoodles as $moodle) {
                  if ($CFG->branch == str_replace('.', '', $moodle->release)) {
 -                    $supportedmoodles[] = html_writer::span($moodle->release, 'label label-success');
 +                    $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success');
                  } else {
                      $supportedmoodles[] = html_writer::span($moodle->release, 'label');
                  }
                      $label = '';
                  } else {
                      $class = 'requires-failed';
 -                    $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
 +                    $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
                  }
                  $requires[] = html_writer::tag('li',
                      html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core').
  
                  } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) {
                      if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
 -                        $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-warning');
 -                        $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
 +                        $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning');
 +                        $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
                          $class = 'requires-failed requires-missing requires-available';
                          $actions[] = html_writer::link(
                              new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)),
                          );
  
                      } else {
 -                        $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'label label-important');
 +                        $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger');
                          $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
 -                            'label label-important');
 +                            'badge badge-danger');
                          $class = 'requires-failed requires-missing requires-unavailable';
                      }
                      $displayuploadlink = true;
  
                  } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) {
                      if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) {
 -                        $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-warning');
 -                        $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'label label-warning');
 +                        $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning');
 +                        $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning');
                          $class = 'requires-failed requires-outdated requires-available';
                          $displayupdateslink = true;
  
                      } else {
 -                        $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'label label-important');
 +                        $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger');
                          $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'),
 -                            'label label-important');
 +                            'badge badge-danger');
                          $class = 'requires-failed requires-outdated requires-unavailable';
                      }
                      $displayuploadlink = true;
                      $source = '';
                  } else {
                      $row->attributes['class'] .= ' extension';
 -                    $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source label label-info');
 +                    $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info');
                  }
  
                  if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
 -                    $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg label label-important');
 +                    $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger');
                  } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
 -                    $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg label label-success');
 +                    $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success');
                  } else {
                      $msg = '';
                  }
                  // Format error or warning line
                  if ($errorline) {
                      $messagetype = 'error';
 -                    $statusclass = 'label-important';
 +                    $statusclass = 'badge-danger';
                  } else if ($warningline) {
                      $messagetype = 'warn';
 -                    $statusclass = 'label-warning';
 +                    $statusclass = 'badge-warning';
                  } else {
                      $messagetype = 'ok';
 -                    $statusclass = 'label-success';
 +                    $statusclass = 'badge-success';
                  }
                  $status = html_writer::span($status, 'label ' . $statusclass);
                  // Here we'll store all the feedback found
diff --combined lib/moodlelib.php
@@@ -6047,7 -6047,6 +6047,7 @@@ function email_to_user($user, $from, $s
          'siteshortname' => $SITE->shortname,
          'sitewwwroot' => $CFG->wwwroot,
          'subject' => $subject,
 +        'prefix' => $CFG->emailsubjectprefix,
          'to' => $user->email,
          'toname' => fullname($user),
          'from' => $mail->From,
@@@ -9286,7 -9285,7 +9286,7 @@@ function get_performance_info() 
          // Attempt to avoid devs debugging peformance issues, when its caused by css building and so on.
          $info['html'] .= '<p><strong>Warning: Theme designer mode is enabled.</strong></p>';
      }
 -    $info['html'] .= '<ul class="list-unstyled m-l-1 row">';         // Holds userfriendly HTML representation.
 +    $info['html'] .= '<ul class="list-unstyled ml-1 row">';         // Holds userfriendly HTML representation.
  
      $info['realtime'] = microtime_diff($PERF->starttime, microtime());
  
          $info['txt']  .= 'memory_peak: '.$info['memory_peak'].'B (' . display_size($info['memory_peak']).') ';
      }
  
 -    $info['html'] .= '</ul><ul class="list-unstyled m-l-1 row">';
 +    $info['html'] .= '</ul><ul class="list-unstyled ml-1 row">';
      $inc = get_included_files();
      $info['includecount'] = count($inc);
      $info['html'] .= '<li class="included col-sm-4">Included '.$info['includecount'].' files</li> ';
  
      $info['html'] .= '</ul>';
      if ($stats = cache_helper::get_stats()) {
 -        $html = '<ul class="cachesused list-unstyled m-l-1 row">';
 +        $html = '<ul class="cachesused list-unstyled ml-1 row">';
          $html .= '<li class="cache-stats-heading font-weight-bold">Caches used (hits/misses/sets)</li>';
 -        $html .= '</ul><ul class="cachesused list-unstyled m-l-1">';
 +        $html .= '</ul><ul class="cachesused list-unstyled ml-1">';
          $text = 'Caches used (hits/misses/sets): ';
          $hits = 0;
          $misses = 0;
                      $mode = ' <span title="request cache">[r]</span>';
                      break;
              }
 -            $html .= '<ul class="cache-definition-stats list-unstyled m-l-1 m-b-1 cache-mode-'.$modeclass.' card d-inline-block">';
 +            $html .= '<ul class="cache-definition-stats list-unstyled ml-1 mb-1 cache-mode-'.$modeclass.' card d-inline-block">';
              $html .= '<li class="cache-definition-stats-heading p-t-1 card-header bg-dark bg-inverse font-weight-bold">' .
                  $definition . $mode.'</li>';
              $text .= "$definition {";
@@@ -10284,3 -10283,28 +10284,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;
+ }