Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Densham committed Feb 18, 2014
2 parents 50d6344 + 482dea2 commit 6ddf045
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 0 deletions.
25 changes: 25 additions & 0 deletions LICENSE
@@ -0,0 +1,25 @@
Copyright (c) 2014 Studio Bonito Ltd. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.

THIS SOFTWARE IS PROVIDED BY STUDIO BONITO LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STUDIO BONITO LTD OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Studio Bonito Ltd.
35 changes: 35 additions & 0 deletions README.md
@@ -0,0 +1,35 @@
# ShortCodes Videos Module

## Overview

ShortCodes Module is based on Daniel Hensby's post at [SSbits](http://www.ssbits.com/tutorials/2010/2-4-using-short-codes-to-embed-a-youtube-video/). It adds a shortcodes for inserting YouTube and Vimeo videos to pages, as well as adding a buttons to the TinyMCE WYSIWYG editor.

## Requirements

SilverStripe 2.4 or newer.

## Installation Instructions

### Composer

Run the following to add this module as a requirement and install it via composer.

$ composer require studiobonito/silverstripe-youtubevideos

### Manual

Copy the 'shortcodes' folder to your the root of your SilverStripe installation.

## Usage Overview

Use the following shortcode in any `HTMLTextField` to embed a YouTube video

[youtube id=4af1bFh3duo][/youtube]

or a Vimeo video

[vimeo id=29471008][/vimeo]

You can also specify a height and width which can be used by the templates that render the videos

[youtube id=4af1bFh3duo width=300 height=150][/youtube]
19 changes: 19 additions & 0 deletions _config.php
@@ -0,0 +1,19 @@
<?php

$dir = basename(dirname(__FILE__));
if ($dir === 'shortcodes') {
define('SHORTCODES_DIR', $dir);
} else {
user_error('ShortCodes: Directory name must be "shortcodes" (currently "' . $dir . '")', E_USER_ERROR);
}

ShortcodeParser::get()->register('youtube', array('ShortCodes', 'YouTubeShortCodeHandler'));
ShortcodeParser::get()->register('vimeo', array('ShortCodes', 'VimeoShortCodeHandler'));

HtmlEditorConfig::get('cms')->enablePlugins(
array(
'youtube' => '../../../shortcodes/javascript/youtube.min.js',
'vimeo' => '../../../shortcodes/javascript/vimeo.min.js'
)
);
HtmlEditorConfig::get('cms')->insertButtonsAfter('anchor', 'youtube', 'vimeo');
67 changes: 67 additions & 0 deletions code/ShortCodes.php
@@ -0,0 +1,67 @@
<?php
class ShortCodes
{

public static function YouTubeShortCodeHandler($arguments, $caption = null, $parser = null)
{
if (empty($arguments['id'])) {
return false;
}

$customise = array();
/*** SET DEFAULTS ***/
$customise['YouTubeID'] = $arguments['id'];
//play the video on page load
$customise['Autoplay'] = false;
//set the caption
$customise['Caption'] = $caption ? Convert::raw2xml($caption) : false;
//set dimensions
$customise['Width'] = 640;
$customise['Height'] = 385;

//overide the defaults with the arguments supplied
$customise = array_merge($customise, $arguments);

//get our YouTube template
$template = new SSViewer(
array(
'YouTube',
SHORTCODES_DIR . '/templates/YouTube.ss'
)
);

//return the customised template
return $template->process(new ArrayData($customise));
}

public static function VimeoShortCodeHandler($arguments, $caption = null, $parser = null)
{
if (empty($arguments['id'])) {
return false;
}

$customise = array();
/*** SET DEFAULTS ***/
$customise['VimeoID'] = $arguments['id'];
//play the video on page load
$customise['Autoplay'] = false;
//set the caption
$customise['Caption'] = $caption ? Convert::raw2xml($caption) : false;
//set dimensions
$customise['Width'] = 480;
$customise['Height'] = 320;

//overide the defaults with the arguments supplied
$customise = array_merge($customise, $arguments);

//get our YouTube template
$template = new SSViewer(
array(
'Vimeo',
SHORTCODES_DIR . '/templates/Vimeo.ss'
)
);

return $template->process(new ArrayData($customise));
}
}
22 changes: 22 additions & 0 deletions composer.json
@@ -0,0 +1,22 @@
{
"name": "studiobonito/silverstripe-shortcodes",
"description": "Shortcodes Module is based on Daniel Hensby's post at SSbits. It adds a shortcode for inserting YouTube videos to pages, as well as adding a button to the TinyMCE WYSIWYG editor.",
"type": "silverstripe-module",
"keywords": ["silverstripe", "shortcodes", "vimeo", "youtube", "video", "shortcode", "wysiwyg", "tinymce", "cms"],
"license": "BSD-2-Clause",
"authors": [
{
"name": "Tom Densham",
"email": "tom.densham@studiobonito.co.uk"
}
],
"require": {
"silverstripe/framework": ">=2.4"
},
"support": {
"issues": "https://github.com/studiobonito/silverstripe-shortcodes/issues"
},
"extra": {
"installer-name": "shortcodes"
}
}
Binary file added images/vimeo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/youtube.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions javascript/vimeo.js
@@ -0,0 +1,38 @@
/*global window */
(function (window) {
'use strict';

window.tinymce.create('tinymce.plugins.VimeoShortCodePlugin', {
init: function (ed, url) {
var t = this;

t.editor = ed;

ed.addCommand('insertVimeoShortCode', function () {
var str = '[vimeo id=][/vimeo]';

ed.execCommand('mceInsertContent', false, str);
});

// Register button
ed.addButton('vimeo', {
title: 'Insert Vimeo ShortCode',
image: 'shortcodes/images/vimeo.png',
cmd: 'insertVimeoShortCode'
});
},

getInfo: function () {
return {
longname: 'ShortCodes Module - Vimeo',
author: 'Studio Bonito Ltd',
authorurl: 'http://www.studiobonito.co.uk',
infourl: 'http://www.studiobonito.co.uk',
version: '1.0.0'
};
}
});

// Register plugin
window.tinymce.PluginManager.add('vimeo', window.tinymce.plugins.VimeoShortCodePlugin);
}(window));
1 change: 1 addition & 0 deletions javascript/vimeo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions javascript/youtube.js
@@ -0,0 +1,38 @@
/*global window */
(function (window) {
'use strict';

window.tinymce.create('tinymce.plugins.YouTubeShortCodePlugin', {
init: function (ed, url) {
var t = this;

t.editor = ed;

ed.addCommand('insertYouTubeShortCode', function () {
var str = '[youtube id=][/youtube]';

ed.execCommand('mceInsertContent', false, str);
});

// Register button
ed.addButton('youtube', {
title: 'Insert YouTube ShortCode',
image: 'shortcodes/images/youtube.png',
cmd: 'insertYouTubeShortCode'
});
},

getInfo: function () {
return {
longname: 'ShortCodes Module - YouTube',
author: 'Studio Bonito Ltd',
authorurl: 'http://www.studiobonito.co.uk',
infourl: 'http://www.studiobonito.co.uk',
version: '1.0.0'
};
}
});

// Register plugins
window.tinymce.PluginManager.add('youtube', window.tinymce.plugins.YouTubeShortCodePlugin);
}(window));
1 change: 1 addition & 0 deletions javascript/youtube.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions templates/Vimeo.ss
@@ -0,0 +1,3 @@
<div class="video">
<iframe src="http://player.vimeo.com/video/{$VimeoID}?title=0&amp;byline=0&amp;portrait=0&amp;<% if $Autoplay %>&autoplay=1<% end_if %>&amp;loop=1" width="{$Width}" height="{$Height}" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>
</div>
5 changes: 5 additions & 0 deletions templates/YouTube.ss
@@ -0,0 +1,5 @@
<div class="video">
<object type="application/x-shockwave-flash" data="http://www.youtube-nocookie.com/v/{$YouTubeID}<% if $Autoplay %>&autoplay=1<% end_if %>" width="{$Width" height="{$Height}">
<embed name="movie" value="http://www.youtube-nocookie.com/v/{$YouTubeID}<% if $Autoplay %>&autoplay=1<% end_if %>" />
</object>
</div>

0 comments on commit 6ddf045

Please sign in to comment.