Skip to content

Commit

Permalink
Initial push
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestecker committed Aug 6, 2017
0 parents commit 0e889eb
Show file tree
Hide file tree
Showing 9 changed files with 452 additions and 0 deletions.
1 change: 1 addition & 0 deletions .craftplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pluginName":"Video Embedder","pluginDescription":"Craft plugin to generate an embed URL from a YouTube or Vimeo URL.","pluginVersion":"1.0.0","pluginAuthorName":"Mike Stecker","pluginVendorName":"mikestecker","pluginAuthorUrl":"http://github.com/mikestecker","pluginAuthorGithub":"mikestecker","codeComments":"yes","pluginComponents":["variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CRAFT ENVIRONMENT
.env.php
.env.sh
.env

# COMPOSER
/vendor

# BUILD FILES
/bower_components/*
/node_modules/*
/build/*
/yarn-error.log

# MISC FILES
.cache
.DS_Store
.idea
.project
.settings
*.esproj
*.sublime-workspace
*.sublime-project
*.tmproj
*.tmproject
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
config.codekit3
prepros-6.config
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Video Embedder Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.1 - 2017-08-05
### Added
- Added `getVideoThumbnail` variable.

## 1.0.0 - 2017-08-05
### Added
- Initial release
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017 Mike Stecker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Video Embedder plugin for Craft CMS 3.x

Craft plugin to generate an embed URL from a YouTube or Vimeo URL.

Ported over from [Viget's](https://viget.com) Craft 2.x [Video Embed plugin](https://github.com/vigetlabs/craft-videoembed).

## Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.

## Installation

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

cd /path/to/project

2. Then tell Composer to load the plugin:

composer require mikestecker/video-embedder

3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Video Embedder.

## Video Embedder Overview

-Insert text here-

## Using Video Embedder

Pass a YouTube or Vimeo URL to the `getEmbedUrl` variable and an embed URL will be returned.

```
{{ craft.videoEmbed.getEmbedUrl('https://www.youtube.com/watch?v=6xWpo5Dn254') }}
```

**Example:**

```
<iframe src="{{ craft.videoEmbed.getEmbedUrl('https://www.youtube.com/watch?v=6xWpo5Dn254') }}"></iframe>
```

**Output:**

```
<iframe src="//www.youtube.com/embed/6xWpo5Dn254"></iframe>
```

Video Embedder will also pull the largest thumbnail URL from YouTube or Vimeo using the `getVideoThumbnail` variable.

```
{{ craft.videoEmbed.getVideoThumbnail('https://www.youtube.com/watch?v=6xWpo5Dn254') }}
```

**Output:**

```
//img.youtube.com/vi/6xWpo5Dn254/0.jpg
```


## Video Embedder Roadmap

Some things to do, and ideas for potential features:

* Add in the ability to actually generate the iframe HTML
* Add new Video URL field type that only allows for supported video URL's
* Add support for more video providers

Brought to you by [Mike Stecker](http://github.com/mikestecker)
47 changes: 47 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "mikestecker/craft3-videoembedder",
"description": "Craft plugin to generate an embed URL from a YouTube or Vimeo URL.",
"type": "craft-plugin",
"version": "1.0.1",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"video embedder"
],
"support": {
"docs": "https://github.com/mikestecker/craft3-videoembedder/blob/master/README.md",
"issues": "https://github.com/mikestecker/craft3-videoembedder/issues"
},
"license": "MIT",
"authors": [
{
"name": "Mike Stecker",
"homepage": "http://github.com/mikestecker"
}
],
"require": {
"craftcms/cms": "~3.0.0-beta.23"
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"autoload": {
"psr-4": {
"mikestecker\\videoembedder\\": "src/"
}
},
"extra": {
"name": "Video Embedder",
"handle": "craft3-videoembedder",
"schemaVersion": "1.0.0",
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/mikestecker/craft3-videoembedder/master/CHANGELOG.md",
"class": "mikestecker\\videoembedder\\VideoEmbedder"
}
}
123 changes: 123 additions & 0 deletions src/VideoEmbedder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/**
* Video Embedder plugin for Craft CMS 3.x
*
* Craft plugin to generate an embed URL from a YouTube or Vimeo URL.
*
* @link http://github.com/mikestecker
* @copyright Copyright (c) 2017 Mike Stecker
*/

namespace mikestecker\videoembedder;

use mikestecker\videoembedder\variables\VideoEmbedderVariable;

use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;
use craft\web\twig\variables\CraftVariable;

use yii\base\Event;

/**
* Craft plugins are very much like little applications in and of themselves. We’ve made
* it as simple as we can, but the training wheels are off. A little prior knowledge is
* going to be required to write a plugin.
*
* For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL,
* as well as some semi-advanced concepts like object-oriented programming and PHP namespaces.
*
* https://craftcms.com/docs/plugins/introduction
*
* @author Mike Stecker
* @package VideoEmbedder
* @since 1.0.0
*
*/
class VideoEmbedder extends Plugin
{
// Static Properties
// =========================================================================

/**
* Static property that is an instance of this plugin class so that it can be accessed via
* VideoEmbedder::$plugin
*
* @var VideoEmbedder
*/
public static $plugin;

// Public Methods
// =========================================================================

/**
* Set our $plugin static property to this class so that it can be accessed via
* VideoEmbedder::$plugin
*
* Called after the plugin class is instantiated; do any one-time initialization
* here such as hooks and events.
*
* If you have a '/vendor/autoload.php' file, it will be loaded for you automatically;
* you do not need to load it in your init() method.
*
*/
public function init()
{
parent::init();
self::$plugin = $this;

// Register our variables
Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function (Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('videoEmbedder', VideoEmbedderVariable::class);
}
);

// Do something after we're installed
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function (PluginEvent $event) {
if ($event->plugin === $this) {
// We were just installed
}
}
);

/**
* Logging in Craft involves using one of the following methods:
*
* Craft::trace(): record a message to trace how a piece of code runs. This is mainly for development use.
* Craft::info(): record a message that conveys some useful information.
* Craft::warning(): record a warning message that indicates something unexpected has happened.
* Craft::error(): record a fatal error that should be investigated as soon as possible.
*
* Unless `devMode` is on, only Craft::warning() & Craft::error() will log to `craft/storage/logs/web.log`
*
* It's recommended that you pass in the magic constant `__METHOD__` as the second parameter, which sets
* the category to the method (prefixed with the fully qualified class name) where the constant appears.
*
* To enable the Yii debug toolbar, go to your user account in the AdminCP and check the
* [] Show the debug toolbar on the front end & [] Show the debug toolbar on the Control Panel
*
* http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html
*/
Craft::info(
Craft::t(
'video-embedder',
'{name} plugin loaded',
['name' => $this->name]
),
__METHOD__
);
}

// Protected Methods
// =========================================================================

}
25 changes: 25 additions & 0 deletions src/translations/en/video-embedder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Video Embedder plugin for Craft CMS 3.x
*
* Craft plugin to generate an embed URL from a YouTube or Vimeo URL.
*
* @link http://github.com/mikestecker
* @copyright Copyright (c) 2017 Mike Stecker
*/

/**
* Video Embedder en Translation
*
* Returns an array with the string to be translated (as passed to `Craft::t('video-embedder', '...')`) as
* the key, and the translation as the value.
*
* http://www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html
*
* @author Mike Stecker
* @package VideoEmbedder
* @since 1.0.0
*/
return [
'Video Embedder plugin loaded' => 'Video Embedder plugin loaded',
];
Loading

0 comments on commit 0e889eb

Please sign in to comment.