Skip to content

Instantly share code, notes, and snippets.

@lukasbestle
Created June 30, 2014 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukasbestle/2c82be6c3a44c61ae904 to your computer and use it in GitHub Desktop.
Save lukasbestle/2c82be6c3a44c61ae904 to your computer and use it in GitHub Desktop.
Kirbytag for HTML5 video (Kirby 1)
<?php
class kirbytextExtended extends kirbytext {
function __construct($text, $markdown=true) {
parent::__construct($text, $markdown);
$this->addTags('video');
// define custom attributes
$this->addAttributes('poster');
}
/**
* Usage: (video: filebasename poster: videoposter.jpg)
* `filebasename` gets extended to the files `filebasename.mp4` and `filebasename.ogv`
*/
function video($params) {
// Get video files
$mp4 = $this->relatedFiles()->find($params['video'] . '.mp4');
$ogv = $this->relatedFiles()->find($params['video'] . '.ogv');
// If one of the videos does not exist: error
if(!$mp4 || !$ogv) return '';
// Try to get a poster image
$poster = (isset($params['poster']))? $this->relatedFiles()->find($params['poster']) : null;
// Build the video element
return '<video controls preload="auto"' . (($poster)? ' poster="' . $poster->url() . '"' : '') . '><source src="' . $mp4->url() . '" type="video/mp4"><source src="' . $ogv->url() . '" type="video/ogg"></video>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment