| 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 | /**
 | 
        
           |  |  | 18 |  *
 | 
        
           |  |  | 19 |  * @package     theme_universe
 | 
        
           |  |  | 20 |  * @copyright   2023 Marcin Czaja (https://rosea.io)
 | 
        
           |  |  | 21 |  * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 22 |  */
 | 
        
           |  |  | 23 |   | 
        
           |  |  | 24 | /**
 | 
        
           |  |  | 25 |  * Class theme_universe_core_h5p_renderer.
 | 
        
           |  |  | 26 |  *
 | 
        
           |  |  | 27 |  * See: https://tracker.moodle.org/browse/MDL-69087 and
 | 
        
           |  |  | 28 |  *      https://github.com/sarjona/h5pmods-moodle-plugin.
 | 
        
           |  |  | 29 |  *
 | 
        
           |  |  | 30 |  * @package     theme_universe
 | 
        
           |  |  | 31 |  * @copyright   2023 Marcin Czaja (https://rosea.io)
 | 
        
           |  |  | 32 |  * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 33 |  */
 | 
        
           |  |  | 34 | class theme_universe_core_h5p_renderer extends \core_h5p\output\renderer {
 | 
        
           |  |  | 35 |     /**
 | 
        
           |  |  | 36 |      * Add styles when an H5P is displayed.
 | 
        
           |  |  | 37 |      *
 | 
        
           |  |  | 38 |      * @param array $styles Styles that will be applied.
 | 
        
           |  |  | 39 |      * @param array $libraries Libraries that will be shown.
 | 
        
           |  |  | 40 |      * @param string $embedtype How the H5P is displayed.
 | 
        
           |  |  | 41 |      */
 | 
        
           |  |  | 42 |     public function h5p_alter_styles(&$styles, array $libraries, string $embedtype) {
 | 
        
           |  |  | 43 |         $theme = theme_config::load('universe');
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 |         $content = $theme->settings->hvpcss;
 | 
        
           |  |  | 46 |   | 
        
           |  |  | 47 |         if (!empty($content)) {
 | 
        
           |  |  | 48 |             $styles[] = (object) array(
 | 
        
           |  |  | 49 |                 'path' => $this->get_style_url($content),
 | 
        
           |  |  | 50 |                 'version' => ''
 | 
        
           |  |  | 51 |             );
 | 
        
           |  |  | 52 |         }
 | 
        
           |  |  | 53 |     }
 | 
        
           |  |  | 54 |   | 
        
           |  |  | 55 |     /**
 | 
        
           |  |  | 56 |      * Get style URL when an H5P is displayed.
 | 
        
           |  |  | 57 |      *
 | 
        
           |  |  | 58 |      * @param string $content Content.
 | 
        
           |  |  | 59 |      *
 | 
        
           |  |  | 60 |      * @return moodle_url the URL.
 | 
        
           |  |  | 61 |      */
 | 
        
           |  |  | 62 |     protected function get_style_url($content) {
 | 
        
           |  |  | 63 |         global $CFG;
 | 
        
           |  |  | 64 |   | 
        
           |  |  | 65 |         $syscontext = \context_system::instance();
 | 
        
           |  |  | 66 |   | 
        
           |  |  | 67 |         $itemid = md5($content);
 | 
        
           |  |  | 68 |   | 
        
           |  |  | 69 |         return \moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
 | 
        
           |  |  | 70 |             "/$syscontext->id/theme_universe/hvp/$itemid/themehvp.css");
 | 
        
           |  |  | 71 |     }
 | 
        
           |  |  | 72 | }
 |