Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [Versions 401 and 403]

   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  namespace mod_bigbluebuttonbn\local;
  18  
  19  use mod_bigbluebuttonbn\instance;
  20  use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
  21  use mod_bigbluebuttonbn\recording;
  22  
  23  /**
  24   * Handles the global configuration based on config.php.
  25   *
  26   * @package   mod_bigbluebuttonbn
  27   * @copyright 2010 onwards, Blindside Networks Inc
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
  30   */
  31  class config {
  32  
  33      /** @var string Default bigbluebutton server url */
  34      public const DEFAULT_SERVER_URL = 'https://test-moodle.blindsidenetworks.com/bigbluebutton/';
  35  
  36      /** @var string Default bigbluebutton server shared secret */
  37      public const DEFAULT_SHARED_SECRET = '0b21fcaf34673a8c3ec8ed877d76ae34';
  38  
  39      /** @var string Default bigbluebutton data processing agreement url */
  40      public const DEFAULT_DPA_URL = 'https://blindsidenetworks.com/dpa-moodle-free-tier';
  41  
  42      /** @var string the default bigbluebutton checksum algorithm */
  43      public const DEFAULT_CHECKSUM_ALGORITHM = 'SHA1';
  44  
  45      /** @var array list of supported bigbluebutton checksum algorithm */
  46      const CHECKSUM_ALGORITHMS = [
  47          self::DEFAULT_CHECKSUM_ALGORITHM,
  48          'SHA256',
  49          'SHA512'
  50      ];
  51  
  52      /**
  53       * Returns moodle version.
  54       *
  55       * @return string
  56       */
  57      protected static function get_moodle_version_major(): string {
  58          global $CFG;
  59          $versionarray = explode('.', $CFG->version);
  60          return $versionarray[0];
  61      }
  62  
  63      /**
  64       * Returns configuration default values.
  65       *
  66       * @return array
  67       */
  68      protected static function defaultvalues(): array {
  69          return [
  70              'server_url' => self::DEFAULT_SERVER_URL,
  71              'shared_secret' => self::DEFAULT_SHARED_SECRET,
  72              'voicebridge_editable' => false,
  73              'importrecordings_enabled' => false,
  74              'importrecordings_from_deleted_enabled' => false,
  75              'waitformoderator_default' => false,
  76              'waitformoderator_editable' => true,
  77              'waitformoderator_ping_interval' => '10',
  78              'waitformoderator_cache_ttl' => '60',
  79              'userlimit_default' => '0',
  80              'userlimit_editable' => false,
  81              'preuploadpresentation_editable' => false,
  82              'recordingready_enabled' => false,
  83              'recordingstatus_enabled' => false,
  84              'meetingevents_enabled' => false,
  85              'participant_moderator_default' => '0',
  86              'profile_picture_enabled' => false,
  87              'scheduled_pre_opening' => '10',
  88              'recordings_enabled' => true,
  89              'recordings_deleted_default' => false,
  90              'recordings_deleted_editable' => false,
  91              'recordings_imported_default' => false,
  92              'recordings_imported_editable' => false,
  93              'recordings_preview_default' => true,
  94              'recordings_preview_editable' => false,
  95              'recording_default' => true,
  96              'recording_editable' => true,
  97              'recording_refresh_period' => recording::RECORDING_REFRESH_DEFAULT_PERIOD,
  98              'recording_all_from_start_default' => false,
  99              'recording_all_from_start_editable' => false,
 100              'recording_hide_button_default' => false,
 101              'recording_hide_button_editable' => false,
 102              'recording_protect_editable' => true,
 103              'general_warning_message' => '',
 104              'general_warning_roles' => 'editingteacher,teacher',
 105              'general_warning_box_type' => 'info',
 106              'general_warning_button_text' => '',
 107              'general_warning_button_href' => '',
 108              'general_warning_button_class' => '',
 109              'muteonstart_default' => false,
 110              'muteonstart_editable' => false,
 111              'disablecam_default' => false,
 112              'disablecam_editable' => true,
 113              'disablemic_default' => false,
 114              'disablemic_editable' => true,
 115              'disableprivatechat_default' => false,
 116              'disableprivatechat_editable' => true,
 117              'disablepublicchat_default' => false,
 118              'disablepublicchat_editable' => true,
 119              'disablenote_default' => false,
 120              'disablenote_editable' => true,
 121              'hideuserlist_default' => false,
 122              'hideuserlist_editable' => true,
 123              'welcome_default' => '',
 124              'welcome_editable' => true,
 125              'default_dpa_accepted' => false,
 126              'poll_interval' => bigbluebutton_proxy::DEFAULT_POLL_INTERVAL,
 127              'checksum_algorithm' => self::DEFAULT_CHECKSUM_ALGORITHM,
 128          ];
 129      }
 130  
 131      /**
 132       * Returns default value for an specific setting.
 133       *
 134       * @param string $setting
 135       * @return string|null
 136       */
 137      public static function defaultvalue(string $setting): ?string {
 138          $defaultvalues = self::defaultvalues();
 139          if (!array_key_exists($setting, $defaultvalues)) {
 140              return null;
 141          }
 142          return $defaultvalues[$setting];
 143      }
 144  
 145      /**
 146       * Returns value for an specific setting.
 147       *
 148       * @param string $setting
 149       * @return string
 150       */
 151      public static function get(string $setting): string {
 152          global $CFG;
 153          if (isset($CFG->bigbluebuttonbn[$setting])) {
 154              return (string) $CFG->bigbluebuttonbn[$setting];
 155          }
 156          if (isset($CFG->{'bigbluebuttonbn_' . $setting})) {
 157              return (string) $CFG->{'bigbluebuttonbn_' . $setting};
 158          }
 159          return (string) self::defaultvalue($setting);
 160      }
 161  
 162      /**
 163       * Validates if recording settings are enabled.
 164       *
 165       * @return bool
 166       */
 167      public static function recordings_enabled(): bool {
 168          return (boolean) self::get('recordings_enabled');
 169      }
 170  
 171      /**
 172       * Validates if imported recording settings are enabled.
 173       *
 174       * @return bool
 175       */
 176      public static function importrecordings_enabled(): bool {
 177          return (boolean) self::get('importrecordings_enabled');
 178      }
 179  
 180      /**
 181       * Wraps current settings in an array.
 182       *
 183       * @return array
 184       */
 185      public static function get_options(): array {
 186          return [
 187              'version_major' => self::get_moodle_version_major(),
 188              'voicebridge_editable' => self::get('voicebridge_editable'),
 189              'importrecordings_enabled' => self::get('importrecordings_enabled'),
 190              'importrecordings_from_deleted_enabled' => self::get('importrecordings_from_deleted_enabled'),
 191              'waitformoderator_default' => self::get('waitformoderator_default'),
 192              'waitformoderator_editable' => self::get('waitformoderator_editable'),
 193              'userlimit_default' => self::get('userlimit_default'),
 194              'userlimit_editable' => self::get('userlimit_editable'),
 195              'preuploadpresentation_editable' => self::get('preuploadpresentation_editable'),
 196              'recordings_enabled' => self::get('recordings_enabled'),
 197              'meetingevents_enabled' => self::get('meetingevents_enabled'),
 198              'recordings_deleted_default' => self::get('recordings_deleted_default'),
 199              'recordings_deleted_editable' => self::get('recordings_deleted_editable'),
 200              'recordings_imported_default' => self::get('recordings_imported_default'),
 201              'recordings_imported_editable' => self::get('recordings_imported_editable'),
 202              'recordings_preview_default' => self::get('recordings_preview_default'),
 203              'recordings_preview_editable' => self::get('recordings_preview_editable'),
 204              'recording_default' => self::get('recording_default'),
 205              'recording_editable' => self::get('recording_editable'),
 206              'recording_refresh_period' => self::get('recording_refresh_period'),
 207              'recording_all_from_start_default' => self::get('recording_all_from_start_default'),
 208              'recording_all_from_start_editable' => self::get('recording_all_from_start_editable'),
 209              'recording_hide_button_default' => self::get('recording_hide_button_default'),
 210              'recording_hide_button_editable' => self::get('recording_hide_button_editable'),
 211              'recording_protect_editable' => self::get('recording_protect_editable'),
 212              'general_warning_message' => self::get('general_warning_message'),
 213              'general_warning_box_type' => self::get('general_warning_box_type'),
 214              'general_warning_button_text' => self::get('general_warning_button_text'),
 215              'general_warning_button_href' => self::get('general_warning_button_href'),
 216              'general_warning_button_class' => self::get('general_warning_button_class'),
 217              'muteonstart_editable' => self::get('muteonstart_editable'),
 218              'muteonstart_default' => self::get('muteonstart_default'),
 219              'disablecam_editable' => self::get('disablecam_editable'),
 220              'disablecam_default' => self::get('disablecam_default'),
 221              'disablemic_editable' => self::get('disablemic_editable'),
 222              'disablemic_default' => self::get('disablemic_default'),
 223              'disableprivatechat_editable' => self::get('disableprivatechat_editable'),
 224              'disableprivatechat_default' => self::get('disableprivatechat_default'),
 225              'disablepublicchat_editable' => self::get('disablepublicchat_editable'),
 226              'disablepublicchat_default' => self::get('disablepublicchat_default'),
 227              'disablenote_editable' => self::get('disablenote_editable'),
 228              'disablenote_default' => self::get('disablenote_default'),
 229              'hideuserlist_editable' => self::get('hideuserlist_editable'),
 230              'hideuserlist_default' => self::get('hideuserlist_default'),
 231              'welcome_default' => self::get('welcome_default'),
 232              'welcome_editable' => self::get('welcome_editable'),
 233              'poll_interval' => self::get('poll_interval'),
 234              'guestaccess_enabled' => self::get('guestaccess_enabled'),
 235          ];
 236      }
 237  
 238      /**
 239       * Helper function returns an array with enabled features for an specific profile type.
 240       *
 241       * @param array $typeprofiles
 242       * @param string|null $type
 243       *
 244       * @return array
 245       */
 246      public static function get_enabled_features(array $typeprofiles, ?string $type = null): array {
 247          $enabledfeatures = [];
 248          $features = $typeprofiles[instance::TYPE_ALL]['features'];
 249          if (!is_null($type) && key_exists($type, $typeprofiles)) {
 250              $features = $typeprofiles[$type]['features'];
 251          }
 252          $enabledfeatures['showroom'] = (in_array('all', $features) || in_array('showroom', $features));
 253          // Evaluates if recordings are enabled for the Moodle site.
 254          $enabledfeatures['showrecordings'] = false;
 255          if (self::recordings_enabled()) {
 256              $enabledfeatures['showrecordings'] = (in_array('all', $features) || in_array('showrecordings', $features));
 257          }
 258          $enabledfeatures['importrecordings'] = false;
 259          if (self::importrecordings_enabled()) {
 260              $enabledfeatures['importrecordings'] = (in_array('all', $features) || in_array('importrecordings', $features));
 261          }
 262          return $enabledfeatures;
 263      }
 264  }