Last active
February 26, 2024 07:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
} | |
} | |
?> |
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
Exactly what I was looking for. Thanks!