Created
June 30, 2014 14:44
-
-
Save lukasbestle/2c82be6c3a44c61ae904 to your computer and use it in GitHub Desktop.
Kirbytag for HTML5 video (Kirby 1)
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'); | |
// 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