Skip to content

Instantly share code, notes, and snippets.

@plfstr
Forked from ClementRoy/kirbytext.extended.php
Last active October 21, 2015 10:14
Show Gist options
  • Save plfstr/9d768b655e73e083c74f to your computer and use it in GitHub Desktop.
Save plfstr/9d768b655e73e083c74f to your computer and use it in GitHub Desktop.
Kirby 2 Kirbytag extension for simple CodePen embeds.

Codepen extension for Kirbytext

This extension for Kirbytext will make it possible to use

(: http://codepen.io/CBeghin/pen/HeuiF)

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('codepen');
$this->addAttributes('type');
}
function codepen($params) {
// http://codepen.io/CBeghin/pen/BJrmq
$source = $params['codepen'];
if( !preg_match('!codepen.io\/([a-z0-9A-Z_-]+)\/pen\/([a-z0-9_-]+)!i', $source, $array ) ) {
return false;
}
// define default values for attributes
$defaults = array(
'height' => '300',
'type' => 'result'
);
// merge the given parameters with the default values
$options = array_merge($defaults, $params);
$availableTypes = array('result', 'html', 'css', 'js');
$defaultType = 'result';
if( !in_array($options['type'], $availableTypes) ){
$options['type'] = $defaultType;
}
return '<div class="code-container"><pre class="codepen" data-height="'.$options['height'].'" data-type="'.$options['type'].'" data-href="'.$array[2].'" data-user="'.$array[1].'" data-safe="false"><code></code></pre><script async src="http://codepen.io/assets/embed/ei.js"></script></div>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment