Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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 tiny_recordrtc;
  18  
  19  use context;
  20  use editor_tiny\editor;
  21  use editor_tiny\plugin;
  22  use editor_tiny\plugin_with_buttons;
  23  use editor_tiny\plugin_with_configuration;
  24  use editor_tiny\plugin_with_menuitems;
  25  
  26  /**
  27   * Tiny RecordRTC plugin.
  28   *
  29   * @package    tiny_recordrtc
  30   * @copyright  2022 Stevani Andolo <stevani@hotmail.com.au>
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class plugininfo extends plugin implements plugin_with_buttons, plugin_with_menuitems, plugin_with_configuration {
  34      /**
  35       * Whether the plugin is enabled
  36       *
  37       * @param context $context The context that the editor is used within
  38       * @param array $options The options passed in when requesting the editor
  39       * @param array $fpoptions The filepicker options passed in when requesting the editor
  40       * @param editor $editor The editor instance in which the plugin is initialised
  41       * @return boolean
  42       */
  43      public static function is_enabled(
  44          context $context,
  45          array $options,
  46          array $fpoptions,
  47          ?editor $editor = null
  48      ): bool {
  49          // Disabled if:
  50          // - Not logged in or guest.
  51          // - Files are not allowed.
  52          $canhavefiles = !empty($options['maxfiles']);
  53          return isloggedin() && !isguestuser() && $canhavefiles;
  54      }
  55  
  56      public static function get_available_buttons(): array {
  57          return [
  58              'tiny_recordrtc/tiny_recordrtc_image',
  59          ];
  60      }
  61  
  62      public static function get_available_menuitems(): array {
  63          return [
  64              'tiny_recordrtc/tiny_recordrtc_image',
  65          ];
  66      }
  67  
  68      public static function get_plugin_configuration_for_context(
  69          context $context,
  70          array $options,
  71          array $fpoptions,
  72          ?editor $editor = null
  73      ): array {
  74          $sesskey = sesskey();
  75          $allowedtypes = get_config('tiny_recordrtc', 'allowedtypes');
  76          $audiobitrate = get_config('tiny_recordrtc', 'audiobitrate');
  77          $videobitrate = get_config('tiny_recordrtc', 'videobitrate');
  78          $audiotimelimit = get_config('tiny_recordrtc', 'audiotimelimit');
  79          $videotimelimit = get_config('tiny_recordrtc', 'videotimelimit');
  80  
  81          // Update $allowedtypes to account for capabilities.
  82          $audioallowed = $allowedtypes === 'audio' || $allowedtypes === 'both';
  83          $videoallowed = $allowedtypes === 'video' || $allowedtypes === 'both';
  84          $audioallowed = $audioallowed && has_capability('tiny/recordrtc:recordaudio', $context);
  85          $videoallowed = $videoallowed && has_capability('tiny/recordrtc:recordvideo', $context);
  86          if ($audioallowed && $videoallowed) {
  87              $allowedtypes = 'both';
  88          } else if ($audioallowed) {
  89              $allowedtypes = 'audio';
  90          } else if ($videoallowed) {
  91              $allowedtypes = 'video';
  92          } else {
  93              $allowedtypes = '';
  94          }
  95  
  96          $maxrecsize = get_max_upload_file_size();
  97          if (!empty($options['maxbytes'])) {
  98              $maxrecsize = min($maxrecsize, $options['maxbytes']);
  99          }
 100          $params = [
 101              'contextid' => $context->id,
 102              'sesskey' => $sesskey,
 103              'allowedtypes' => $allowedtypes,
 104              'audiobitrate' => $audiobitrate,
 105              'videobitrate' => $videobitrate,
 106              'audiotimelimit' => $audiotimelimit,
 107              'videotimelimit' => $videotimelimit,
 108              'maxrecsize' => $maxrecsize
 109          ];
 110  
 111          $data = [
 112              'params' => $params,
 113              'fpoptions' => $fpoptions
 114          ];
 115  
 116          return [
 117              'data' => $data,
 118              'videoAllowed' => $videoallowed,
 119              'audioAllowed' => $audioallowed,
 120          ];
 121      }
 122  }