diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c61c8c6 --- /dev/null +++ b/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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..35010ef --- /dev/null +++ b/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] \ No newline at end of file diff --git a/_config.php b/_config.php new file mode 100644 index 0000000..7347c88 --- /dev/null +++ b/_config.php @@ -0,0 +1,19 @@ +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'); \ No newline at end of file diff --git a/code/ShortCodes.php b/code/ShortCodes.php new file mode 100644 index 0000000..e4250ca --- /dev/null +++ b/code/ShortCodes.php @@ -0,0 +1,67 @@ +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)); + } +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..568d75a --- /dev/null +++ b/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" + } +} \ No newline at end of file diff --git a/images/vimeo.png b/images/vimeo.png new file mode 100644 index 0000000..725d217 Binary files /dev/null and b/images/vimeo.png differ diff --git a/images/youtube.png b/images/youtube.png new file mode 100644 index 0000000..dde0cd2 Binary files /dev/null and b/images/youtube.png differ diff --git a/javascript/vimeo.js b/javascript/vimeo.js new file mode 100644 index 0000000..ad5d5dc --- /dev/null +++ b/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)); \ No newline at end of file diff --git a/javascript/vimeo.min.js b/javascript/vimeo.min.js new file mode 100644 index 0000000..3f8c869 --- /dev/null +++ b/javascript/vimeo.min.js @@ -0,0 +1 @@ +(function(o){"use strict";o.tinymce.create("tinymce.plugins.VimeoShortCodePlugin",{init:function(o){var t=this;t.editor=o,o.addCommand("insertVimeoShortCode",function(){var t="[vimeo id=][/vimeo]";o.execCommand("mceInsertContent",!1,t)}),o.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"}}}),o.tinymce.PluginManager.add("vimeo",o.tinymce.plugins.VimeoShortCodePlugin)})(window); \ No newline at end of file diff --git a/javascript/youtube.js b/javascript/youtube.js new file mode 100644 index 0000000..c2b6258 --- /dev/null +++ b/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)); \ No newline at end of file diff --git a/javascript/youtube.min.js b/javascript/youtube.min.js new file mode 100644 index 0000000..c09761d --- /dev/null +++ b/javascript/youtube.min.js @@ -0,0 +1 @@ +(function(o){"use strict";o.tinymce.create("tinymce.plugins.YouTubeShortCodePlugin",{init:function(o){var t=this;t.editor=o,o.addCommand("insertYouTubeShortCode",function(){var t="[youtube id=][/youtube]";o.execCommand("mceInsertContent",!1,t)}),o.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"}}}),o.tinymce.PluginManager.add("youtube",o.tinymce.plugins.YouTubeShortCodePlugin)})(window); \ No newline at end of file diff --git a/templates/Vimeo.ss b/templates/Vimeo.ss new file mode 100644 index 0000000..e0fdd43 --- /dev/null +++ b/templates/Vimeo.ss @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/templates/YouTube.ss b/templates/YouTube.ss new file mode 100644 index 0000000..abbaf14 --- /dev/null +++ b/templates/YouTube.ss @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file