Commit f7406158 authored by Robert Lyon's avatar Robert Lyon

Bug 1826284: External media block renders different for PDF export

It renders the video as a link to the external video

If the video is also a vimeo / youtube video it fetches the thumbnail
for the video to display that as well

behatnotneeded

Change-Id: Ib727325dc5909bd38e740071b83f5fcdf28587cd
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent d5c331d5
......@@ -390,3 +390,4 @@ $string['notrendertopdffiles'] = array(
'The file has been added to: ',
'The files have been added to: ',
);
$string['notrendertopdflink'] = 'The file can be accessed at: ';
......@@ -122,6 +122,49 @@ class PluginBlocktypeExternalvideo extends MaharaCoreBlocktype {
return array('externalvideo' => array('media'));
}
public static function render_instance_export(BlockInstance $instance, $editing=false, $versioning=false, $exporting=null) {
if ($exporting != 'pdf') {
return self::render_instance($instance, $editing, $versioning);
}
$configdata = $instance->get('configdata');
// The exporting for pdf
$sources = self::load_media_sources();
$vidurl = preg_match('/"(https?:.*?)"/', $configdata['videoid'], $matches);
if (empty($matches[1])) {
// Can't work out what the url is
return self::render_instance($instance, $editing, $versioning);
}
$video = array();
$vidurl = $matches[1];
foreach ($sources as $name => $source) {
if ($video = $source->validate_url($vidurl)) {
break;
}
}
$html = '';
if (isset($video['vimeo'])) {
// Fetch the metadata for the video
$res = mahara_http_request(array(CURLOPT_URL => 'http://vimeo.com/api/v2/video/' . $video['vimeo'] . '.json'));
if ($res->info['http_code'] == '200') {
$json = json_decode($res->data);
if (isset($json[0]->thumbnail_large)) {
$html .= '<div class="image"><img src="' . $json[0]->thumbnail_large . '"></div>';
}
}
}
else if (isset($video['youtube'])) {
// We can fetch the thumbnail of the video and display that
$html .= '<div class="image"><img src="https://img.youtube.com/vi/' . $video['youtube'] . '/0.jpg"></div>';
}
$html .= '<div class="text-midtone">' . get_string('notrendertopdf', 'artefact.file');
$html .= '<br>' . get_string('notrendertopdflink', 'artefact.file');
// We need to add an <a> link so that the HTML export() sub-task makes a copy of the artefct for the export 'files/' directory
// We then override the link in the PDF pdf_view_export_data() function.
$html .= '<a class="" href="' . $vidurl . '">' . $instance->get('title') . '</a>';
$html .= '</div>';
return $html;
}
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
global $THEME;
......
......@@ -18,8 +18,8 @@ class Media_vimeo implements MediaBase {
self::$iframe_sources = array(
array(
'match' => '#^http://player\.vimeo\.com/video/([0-9]+).*#',
'url' => $this->httpstr . '://player.vimeo.com/video/$1'
'match' => '#^https?://(player)\.vimeo\.com/video/([0-9]+).*#', // we do a dummy capture on 'player' so both this and the other one match ID at position $2
'url' => $this->httpstr . '://player.vimeo.com/video/$2'
),
array(
'match' => '#^https?://(www\.|secure\.)?vimeo\.com/([0-9]+)#',
......@@ -57,8 +57,8 @@ class Media_vimeo implements MediaBase {
public function validate_url($input) {
foreach (self::$iframe_sources as $source) {
if (preg_match($source['match'], $input)) {
return true;
if (preg_match($source['match'], $input, $matches)) {
return array('vimeo' => $matches[2]); // the type/id of the video
}
}
return false;
......
......@@ -64,8 +64,8 @@ class Media_youtube implements MediaBase {
public function validate_url($input) {
foreach (self::$iframe_sources as $source) {
if (preg_match($source['match'], $input)) {
return true;
if (preg_match($source['match'], $input, $matches)) {
return array('youtube' => $matches[2]); // the type/id of the video
}
}
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment