Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions syntax/video.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler)
[$vid, $pstr] = sexplode('?', $vid, 2, '');
parse_str($pstr, $userparams);
[$width, $height] = $this->parseSize($userparams);
[$aspect_w, $aspect_h] = $this->parseAspect($userparams);

// get URL
$url = $this->insertPlaceholders($this->sites[$site]['url'], $vid, $width, $height);
Expand All @@ -103,7 +104,9 @@ public function handle($match, $state, $pos, Doku_Handler $handler)
'align' => $this->alignments[$align],
'width' => $width,
'height' => $height,
'title' => $title
'title' => $title,
'aspect_w' => $aspect_w,
'aspect_h' => $aspect_h
];
}

Expand Down Expand Up @@ -133,7 +136,7 @@ public function iframe($data, $element = 'iframe')
'src' => $data['url'],
'width' => $data['width'],
'height' => $data['height'],
'style' => $this->sizeToStyle($data['width'], $data['height']),
'style' => $this->sizeToStyle($data['width'], $data['height']) . $this->aspectToStyle($data['aspect_w'], $data['aspect_h']),
'class' => 'vshare vshare__' . $data['align'],
'allowfullscreen' => '',
'frameborder' => 0,
Expand All @@ -160,11 +163,11 @@ public function iframe($data, $element = 'iframe')
public function sizeToStyle($width, $height)
{
// no unit? use px
if ($width && $width == (int)$width) {
if ($width && $width == (int)$width . '') {
$width .= 'px';
}
// no unit? use px
if ($height && $height == (int)$height) {
if ($height && $height == (int)$height . '') {
$height .= 'px';
}

Expand All @@ -174,6 +177,24 @@ public function sizeToStyle($width, $height)
return $style;
}

/**
* Create a style attribute for the given size
*
* @param int|string $width
* @param int|string $height
* @return string
*/
public function aspectToStyle($w, $h)
{
$style = '';
if ($w > 0 && $h > 0) {
$style .= 'aspect-ratio:' . $w . '/' . $h . '; height: unset';
}
return $style;
}



/**
* Prepare the HTML for output in PDF exports
*
Expand Down Expand Up @@ -246,6 +267,27 @@ public function parseSize(&$params)
return $this->sizes['medium'];
}

/**
* Extract the wanted aspect from the parameter list
*
* @param array $params
* @return int[]
*/
public function parseAspect(&$params)
{
foreach (array_keys($params) as $key) {
if (preg_match("/^((\d+):(\d+))\$/i", $key, $m)) {
unset($params[$key]);
if (isset($m[2]) && isset($m[3])) {
return [$m[2], $m[3]];
} else {
return [];
}
}
}
return [];
}

/**
* Get additional attributes to set on the iframe to harden
*
Expand Down