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 39 and 401] [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  
  18  /**
  19   * A script to embed vimeo videos via the site (so vimeo privacy restrictions by domain will work in the mobile app).
  20   *
  21   * The site is doing a double frame embedding:
  22   *  - First, the media player replaces the vimeo link with an iframe pointing to vimeo.
  23   *  - Second, the app replaces the previous iframe link with a link to this file that includes again the iframe to vimeo.
  24   *  Thanks to these changes, the video is embedded in a page in the site server so the privacy restrictions will work.
  25   *
  26   *  Note 1: Vimeo privacy restrictions seems to be based on the Referer HTTP header.
  27   *  Note 2: This script works even if the plugin is disabled (some users could be using the vimeo embedding code).
  28   *
  29   * @package    media_vimeo
  30   * @copyright  2017 Juan Leyva
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  
  34  define('NO_MOODLE_COOKIES', true);
  35  
  36  require_once(__DIR__ . '/../../../config.php');
  37  require_once($CFG->dirroot . '/webservice/lib.php');
  38  
  39  $token = required_param('token', PARAM_ALPHANUM);
  40  $video = required_param('video', PARAM_ALPHANUM);   // Video ids are numeric, but it's more solid to expect things like 00001.
  41  $width = optional_param('width', 0, PARAM_INT);
  42  $height = optional_param('height', 0, PARAM_INT);
  43  $h = optional_param('h', '', PARAM_ALPHANUM); // Security hash for restricted videos.
  44  
  45  // Authenticate the user.
  46  $webservicelib = new webservice();
  47  $webservicelib->authenticate_user($token);
  48  
  49  if (empty($width) && empty($height)) {
  50      // Use the full page. The video will keep the ratio.
  51      $display = 'style="position:absolute; top:0; left:0; width:100%; height:100%;"';
  52  } else {
  53      $display = "width=\"$width\" height=\"$height\"";
  54  }
  55  
  56  if (!empty($h)) {
  57      $video .= '?h=' . $h;
  58  }
  59  
  60  $output = <<<OET
  61  <html>
  62      <head>
  63          <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  64      </head>
  65      <body style="margin:0; padding:0">
  66          <iframe src="https://player.vimeo.com/video/$video"
  67              $display frameborder="0"
  68              webkitallowfullscreen mozallowfullscreen allowfullscreen>
  69          </iframe>
  70      </body>
  71  </html>
  72  OET;
  73  echo $output;