modif comtabilite
This commit is contained in:
@@ -1,3 +1,15 @@
|
||||
# v3.0.1
|
||||
## 08/20/2018
|
||||
|
||||
1. [](#improved)
|
||||
* Refactor to remove GravTrait
|
||||
|
||||
# v3.0.0
|
||||
## 08/02/2018
|
||||
|
||||
1. [](#new)
|
||||
* Added shortcode support
|
||||
|
||||
# v2.0.4
|
||||
## 09/28/2017
|
||||
|
||||
|
||||
@@ -55,13 +55,15 @@ You can also set any of these settings on a per-page basis by adding them under
|
||||
title: YouTube Video
|
||||
youtube:
|
||||
player_parameters:
|
||||
autoplay: true
|
||||
autoplay: 1
|
||||
---
|
||||
|
||||
[plugin:youtube](https://www.youtube.com/watch?v=BK8guP9ov2U)
|
||||
|
||||
This will display a video and auto-play it.
|
||||
|
||||
For more details on the `player_parameters`, please check out the [YouTube official documentation](https://developers.google.com/youtube/player_parameters)
|
||||
|
||||
# Usage
|
||||
|
||||
To use this plugin you simply need to include a youtube URL in markdown link such as:
|
||||
@@ -78,4 +80,12 @@ Will be converted into the following embeded HTML:
|
||||
|
||||
CSS is also loaded to provide the appropriate responsive layout.
|
||||
|
||||
# Shortcode Syntax
|
||||
|
||||
As of version `3.0` you can now use an alternative _shortcode_ syntax that supports passing in the player parameter values inline
|
||||
|
||||
```
|
||||
[youtube color=white autoplay=1]https://www.youtube.com/watch?v=BK8guP9ov2U[/youtube]
|
||||
```
|
||||
|
||||
[grav]: http://github.com/getgrav/grav
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: YouTube
|
||||
version: 2.0.4
|
||||
description: "**YouTube** is a simple plugin that converts markdown links into responsive embeds."
|
||||
version: 3.0.1
|
||||
description: "**YouTube** is a simple plugin that converts markdown links or shortcodes into responsive embeds."
|
||||
icon: youtube
|
||||
author:
|
||||
name: Team Grav
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace Grav\Plugin\Youtube\Twig;
|
||||
|
||||
use Grav\Common\GravTrait;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
|
||||
class YoutubeTwigExtension extends \Twig_Extension
|
||||
{
|
||||
use GravTrait;
|
||||
|
||||
/**
|
||||
* Returns extension name.
|
||||
*
|
||||
@@ -38,7 +37,7 @@ class YoutubeTwigExtension extends \Twig_Extension
|
||||
*/
|
||||
public function embedUrl($video_id, array $player_parameters = array(), $privacy_enhanced_mode = FALSE)
|
||||
{
|
||||
$grav = static::getGrav();
|
||||
$grav = Grav::instance();
|
||||
|
||||
// build base video embed URL (while respecting privacy enhanced mode setting)
|
||||
$url = 'https://www.youtube' . ($privacy_enhanced_mode ? '-nocookie' : '') . '.com/embed/' . $video_id;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace Grav\Plugin\Shortcodes;
|
||||
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
|
||||
class YoutubeShortcode extends Shortcode
|
||||
{
|
||||
const YOUTUBE_REGEX = '/(?:https?:\/{2}(?:(?:www.youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=))|(?:youtu\.be\/)))([a-zA-Z0-9_-]{11})/';
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->shortcode->getHandlers()->add('youtube', function(ShortcodeInterface $sc) {
|
||||
|
||||
// Get shortcode content and parameters
|
||||
$url = $sc->getContent();
|
||||
$params = $sc->getParameters();
|
||||
$privacy_mode = $sc->getParameter('privacy_enhanced_mode');
|
||||
|
||||
if ($url) {
|
||||
preg_match($this::YOUTUBE_REGEX, $url, $matches);
|
||||
$search = $matches[0];
|
||||
|
||||
// double check to make sure we found a valid YouTube video ID
|
||||
if (!isset($matches[1])) {
|
||||
return $search;
|
||||
}
|
||||
|
||||
/** @var Twig $twig */
|
||||
$twig = $this->grav['twig'];
|
||||
|
||||
// build the replacement embed HTML string
|
||||
$replace = $twig->processTemplate('partials/youtube.html.twig', array(
|
||||
'player_parameters' => $params,
|
||||
'privacy_enhanced_mode' => $privacy_mode,
|
||||
'video_id' => $matches[1],
|
||||
));
|
||||
|
||||
// do the replacement
|
||||
return str_replace($search, $replace, $search);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ class YoutubePlugin extends Plugin
|
||||
'onTwigExtensions' => ['onTwigExtensions', 0],
|
||||
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
|
||||
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
||||
'onShortcodeHandlers' => ['onShortcodeHandlers', 0],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -126,4 +127,12 @@ class YoutubePlugin extends Plugin
|
||||
{
|
||||
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize shortcodes
|
||||
*/
|
||||
public function onShortcodeHandlers()
|
||||
{
|
||||
$this->grav['shortcode']->registerAllShortcodes(__DIR__.'/shortcodes');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user