Skip to content

Instantly share code, notes, and snippets.

@philgruneich
Last active February 26, 2024 07:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philgruneich/8551473 to your computer and use it in GitHub Desktop.
Save philgruneich/8551473 to your computer and use it in GitHub Desktop.
This extension includes the HTML5 video tag as kirbytext and has several optional parameters. It accepts input of .ogg, .webm and custom fallback. If you don't choose width and height, it picks the one in the config.php file. It also supports class and title.
<?php
class kirbytextExtended extends kirbytext {
function __construct($text, $markdown=true) {
parent::__construct($text, $markdown);
$this->addTags('video');
$this->addAttributes('width', 'height', 'ogg', 'webm', 'class', 'title', 'fallback');
}
function video($params) {
global $site;
$page = ($this->obj) ? $this->obj : $site->pages()->active();
$video = $page->videos()->find($params['video'])->url();
$defaults = array(
'width' => c::get('kirbytext.video.width'),
'height' => c::get('kirbytext.video.height'),
'ogg' => '',
'webm' => '',
'fallback' => '',
'title' => '',
'class' => ''
);
$options = array_merge($defaults, $params);
$class = $options['class'];
$title = $options['title'];
$ogg = $options['ogg'];
$webm = $options['webm'];
// add a classname to the video
if(!empty($class)) $class = ' class="' . $class . '"';
// add a title to the video
if(!empty($title)) $title = ' title="' . $title . '"';
// add an OGG video
if(!empty($ogg)) $ogg = '<source src="' . $page->videos()->find($ogg)->url() . '" type="video/ogg">';
// add a WebM video
if(!empty($webm)) $webm = '<source src="' . $page->videos()->find($webm)->url() . '" type="video/webm">';
// return the full code
return '<video width="' . $options['width'] . '" height="' . $options['height'] . '"' . $class . $title . 'controls><source src="' . $video . '" type="video/mp4">' . $ogg . $webm . $options['fallback'] . '</video>';
}
}
?>
@hdmn
Copy link

hdmn commented May 21, 2014

Exactly what I was looking for. Thanks!

@dersven
Copy link

dersven commented Nov 12, 2014

is it for /site/plugins?! and how can i use it?! (video:movie.mp4 webm:movie.webm title: Demonstrating the video tag)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment