Example #1
0
 /**
  * Replaces <video> or <audio> tag with processed contents
  *
  * @param string $fulltext complete HTML snipped "<video ...>...</video>" or "<audio ...>....</audio>"
  * @return string
  */
 protected function process_media_tag($fulltext)
 {
     // Check if we ignore it.
     if (preg_match('/^<[^>]*class="[^"]*nomediaplugin/im', $fulltext)) {
         return $fulltext;
     }
     // Find all sources both as <video src=""> and as embedded <source> tags.
     $urls = [];
     if (preg_match('/^<[^>]*\\bsrc="(.*?)"/im', $fulltext, $matches)) {
         $urls[] = new moodle_url($matches[1]);
     }
     if (preg_match_all('/<source\\b[^>]*\\bsrc="(.*?)"/im', $fulltext, $matches)) {
         foreach ($matches[1] as $url) {
             $urls[] = new moodle_url($url);
         }
     }
     // Extract width/height/title attributes and call embed_alternatives to find a suitable media player.
     if ($urls) {
         $options = [core_media_manager::OPTION_ORIGINAL_TEXT => $fulltext];
         $width = core_media_player_native::get_attribute($fulltext, 'width', PARAM_INT);
         $height = core_media_player_native::get_attribute($fulltext, 'height', PARAM_INT);
         $name = core_media_player_native::get_attribute($fulltext, 'title');
         return $this->embed_alternatives($urls, $name, $width, $height, $options);
     }
     return $fulltext;
 }
Example #2
0
 public function get_embeddable_markers()
 {
     $markers = parent::get_embeddable_markers();
     if (get_config('media_videojs', 'youtube')) {
         $markers = array_merge($markers, array('youtube.com', 'youtube-nocookie.com', 'youtu.be', 'y2u.be'));
     }
     return $markers;
 }