Skip to content

Instantly share code, notes, and snippets.

@ClementRoy
Last active December 14, 2015 03:49
Show Gist options
  • Save ClementRoy/5024129 to your computer and use it in GitHub Desktop.
Save ClementRoy/5024129 to your computer and use it in GitHub Desktop.
Kirbytext Dailymotion tag

Dailymotion extension for Kirbytext

This extension for Kirbytext will make it possible to use

(dailymotion: http://www.dailymotion.com/video/xnhtlb_somebody-that-i-used-to-know-walk-off-the-earth-gotye-cover_music width: 200 height: 100 class: dailymotion-video)

in your content files, in order to embed video from french video plateform Dailymotion http://www.dailymotion.com/

Installation

Put kirbytext.extended.php in your site/plugins folder (or edit it)

Usage

In your content text files you can now use the new dailymotion tag:

(dailymotion: http://www.dailymotion.com/video/xnhtlb_somebody-that-i-used-to-know-walk-off-the-earth-gotye-cover_music)

http://www.dailymotion.com/video/xnhtlb_somebody-that-i-used-to-know-walk-off-the-earth-gotye-cover_music is just the url of the video, you can use the embed url direclty too http://www.dailymotion.com/embed/video/xnhtlb

Parameters

You can pass all parameters, which are also available for the dailymotion plugin:

(dailymotion: video_path width: xxx height: xxx class: xxx)

Feel free to change the $defaults array in kirbytext.extended.php to add the values which fit best to your project.


// customize this:

$defaults = array(
	'width'		=> c::get('kirbytext.video.width'),
	'height'	=> c::get('kirbytext.video.height'),
	'class' 	=> ''
);

Those defaults will make it possible to use the dailymotion tag without specifying all the attributes.

<?php
class kirbytextExtended extends kirbytext {
function __construct($text, $markdown=true) {
parent::__construct($text, $markdown);
$this->addTags('dailymotion');
}
function dailymotion($params) {
// given dailymotion video url
$source = $params['dailymotion'];
// define default values for attributes
$defaults = array(
'width' => c::get('kirbytext.video.width'),
'height' => c::get('kirbytext.video.height'),
'class' => ''
);
// merge the given parameters with the default values
$options = array_merge($defaults, $params);
// http://www.dailymotion.com/embed/video/xnhtlb
if( preg_match('!dailymotion.com\/embed\/video\/([a-z0-9]+)!i', $source, $array) ){
$id = $array[1];
}
// http://www.dailymotion.com/video/xnhtlb_somebody-that-i-used-to-know-walk-off-the-earth-gotye-cover_music
elseif( preg_match('!dailymotion.com\/video\/([a-z0-9]+)!i', $source, $array) ) {
$id = $array[1];
}
// no id no result!
if(empty($id)) return false;
// build the final url
$url = 'http://www.dailymotion.com/embed/video/' . $id;
// add a classname to the iframe
$class = $options['class'];
if(!empty($class)) $class = ' class="' . $class . '"';
return '<div class="video-container"><iframe' . $class . ' width="' . $options['width'] . '" height="' . $options['height'] . '" src="' . $url . '" frameborder="0" allowfullscreen></iframe></div>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment