Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="video"> | ||
<iframe src="http://player.vimeo.com/video/{$VimeoID}?title=0&byline=0&portrait=0&<% if $Autoplay %>&autoplay=1<% end_if %>&loop=1" width="{$Width}" height="{$Height}" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe> | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |