| 1 | 
           efrain | 
           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 core_h5p\output;
  | 
        
        
            | 
            | 
           18 | 
              | 
        
        
            | 
            | 
           19 | 
           use plugin_renderer_base;
  | 
        
        
            | 
            | 
           20 | 
              | 
        
        
            | 
            | 
           21 | 
           /**
  | 
        
        
            | 
            | 
           22 | 
            * Renderer class.
  | 
        
        
            | 
            | 
           23 | 
            *
  | 
        
        
            | 
            | 
           24 | 
            * @package    core_h5p
  | 
        
        
            | 
            | 
           25 | 
            * @copyright  2020 Victor Deniz {victor@moodle.com}
  | 
        
        
            | 
            | 
           26 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           27 | 
            */
  | 
        
        
            | 
            | 
           28 | 
           class renderer extends plugin_renderer_base {
  | 
        
        
            | 
            | 
           29 | 
              | 
        
        
            | 
            | 
           30 | 
               /**
  | 
        
        
            | 
            | 
           31 | 
                * Alter which stylesheets are loaded for H5P.
  | 
        
        
            | 
            | 
           32 | 
                * This is useful for adding custom styles or replacing existing ones.
  | 
        
        
            | 
            | 
           33 | 
                *
  | 
        
        
            | 
            | 
           34 | 
                * This method can be overridden by other themes if the styles must be loaded from
  | 
        
        
            | 
            | 
           35 | 
                * a different place than the "Raw initial SCSS" and "Raw SCSS" theme settings.
  | 
        
        
            | 
            | 
           36 | 
                *
  | 
        
        
            | 
            | 
           37 | 
                * @param \stdClass[] $styles List of stylesheets that will be loaded
  | 
        
        
            | 
            | 
           38 | 
                * @param array $libraries Array of libraries indexed by the library's machineName
  | 
        
        
            | 
            | 
           39 | 
                * @param string $embedtype Possible values: div, iframe, external, editor
  | 
        
        
            | 
            | 
           40 | 
                */
  | 
        
        
            | 
            | 
           41 | 
               public function h5p_alter_styles(&$styles, array $libraries, string $embedtype) {
  | 
        
        
            | 
            | 
           42 | 
                   $customcss = \core_h5p\file_storage::get_custom_styles();
  | 
        
        
            | 
            | 
           43 | 
                   if (!empty($customcss)) {
  | 
        
        
            | 
            | 
           44 | 
                       // Add the CSS file to the styles array, to load it from the H5P player.
  | 
        
        
            | 
            | 
           45 | 
                       $styles[] = (object) [
  | 
        
        
            | 
            | 
           46 | 
                           'path' => $customcss['cssurl']->out(),
  | 
        
        
            | 
            | 
           47 | 
                           'version' => '?ver='.$customcss['cssversion'],
  | 
        
        
            | 
            | 
           48 | 
                       ];
  | 
        
        
            | 
            | 
           49 | 
                   }
  | 
        
        
            | 
            | 
           50 | 
               }
  | 
        
        
            | 
            | 
           51 | 
              | 
        
        
            | 
            | 
           52 | 
               /**
  | 
        
        
            | 
            | 
           53 | 
                * Alter which scripts are loaded for H5P.
  | 
        
        
            | 
            | 
           54 | 
                * This is useful for adding custom scripts or replacing existing ones.
  | 
        
        
            | 
            | 
           55 | 
                *
  | 
        
        
            | 
            | 
           56 | 
                * @param array|object $scripts List of JavaScripts that will be loaded
  | 
        
        
            | 
            | 
           57 | 
                * @param array $libraries Array of libraries indexed by the library's machineName
  | 
        
        
            | 
            | 
           58 | 
                * @param string $embedtype Possible values: div, iframe, external, editor
  | 
        
        
            | 
            | 
           59 | 
                */
  | 
        
        
            | 
            | 
           60 | 
               public function h5p_alter_scripts(&$scripts, array $libraries, string $embedtype) {
  | 
        
        
            | 
            | 
           61 | 
               }
  | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
               /**
  | 
        
        
            | 
            | 
           64 | 
                * Alter semantics before they are processed. This is useful for changing
  | 
        
        
            | 
            | 
           65 | 
                * how the editor looks and how content parameters are filtered.
  | 
        
        
            | 
            | 
           66 | 
                *
  | 
        
        
            | 
            | 
           67 | 
                * @param object|object $semantics Semantics as object
  | 
        
        
            | 
            | 
           68 | 
                * @param string $name Machine name of library
  | 
        
        
            | 
            | 
           69 | 
                * @param int $majorversion Major version of library
  | 
        
        
            | 
            | 
           70 | 
                * @param int $minorversion Minor version of library
  | 
        
        
            | 
            | 
           71 | 
                */
  | 
        
        
            | 
            | 
           72 | 
               public function h5p_alter_semantics(&$semantics, $name, $majorversion, $minorversion) {
  | 
        
        
            | 
            | 
           73 | 
               }
  | 
        
        
            | 
            | 
           74 | 
              | 
        
        
            | 
            | 
           75 | 
               /**
  | 
        
        
            | 
            | 
           76 | 
                * Alter parameters of H5P content after it has been filtered through semantics.
  | 
        
        
            | 
            | 
           77 | 
                * This is useful for adapting the content to the current context.
  | 
        
        
            | 
            | 
           78 | 
                *
  | 
        
        
            | 
            | 
           79 | 
                * @param array|object $parameters The content parameters for the library
  | 
        
        
            | 
            | 
           80 | 
                * @param string $name The machine readable name of the library
  | 
        
        
            | 
            | 
           81 | 
                * @param int $majorversion Major version of the library
  | 
        
        
            | 
            | 
           82 | 
                * @param int $minorversion Minor version of the library
  | 
        
        
            | 
            | 
           83 | 
                */
  | 
        
        
            | 
            | 
           84 | 
               public function h5p_alter_filtered_parameters(&$parameters, string $name, int $majorversion, int $minorversion) {
  | 
        
        
            | 
            | 
           85 | 
               }
  | 
        
        
            | 
            | 
           86 | 
           }
  |