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.

Differences Between: [Versions 400 and 401]

   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;
  18  
  19  /**
  20   * Class plugin.
  21   *
  22   * @package mod_bigbluebuttonbn
  23   * @copyright 2019 onwards, Blindside Networks Inc
  24   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   * @author    Darko Miletic  (darko.miletic [at] gmail [dt] com)
  26   */
  27  abstract class plugin {
  28  
  29      /**
  30       * Component name.
  31       */
  32      const COMPONENT = 'mod_bigbluebuttonbn';
  33  
  34      /**
  35       * Helper function to convert an html string to plain text.
  36       *
  37       * @param string $html
  38       * @param int $len
  39       *
  40       * @return string
  41       */
  42      public static function html2text($html, $len = 0) {
  43          $text = strip_tags($html);
  44          $text = str_replace('&nbsp;', ' ', $text);
  45          $textlen = strlen($text);
  46          $text = mb_substr($text, 0, $len);
  47          if ($textlen > $len) {
  48              $text .= '...';
  49          }
  50          return $text;
  51      }
  52  
  53      /**
  54       * Helper generates a random password.
  55       *
  56       * @param int $length
  57       * @param string $unique
  58       *
  59       * @return string
  60       */
  61      public static function random_password($length = 8, $unique = "") {
  62          $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  63          do {
  64              $password = substr(str_shuffle($chars), 0, $length);
  65          } while ($unique == $password);
  66          return $password;
  67      }
  68  
  69      /**
  70       * Generate random credentials for guest access
  71       *
  72       * @return array
  73       */
  74      public static function generate_guest_meeting_credentials(): array {
  75          $password = self::random_password();
  76          $guestlinkuid = sha1(self::random_password(1024));
  77          return [$guestlinkuid, $password];
  78      }
  79  }