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.
<?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