Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sommerregen committed Feb 5, 2017
2 parents 5f74db0 + 5f9790d commit 555aad3
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
assets/logo.svg
*.xcf
.idea
22 changes: 17 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# v1.3.0
## 02/05/2017

1. [](#new)
* Added support image or link for not embed media (Thanks to [@magikcypres](https://github.com/magikcypress))
* Added support for **Twitter.com** (Thanks to [@magikcypres](https://github.com/magikcypress))
2. [](#bugfix)
* Fixed support for **Github** (Thanks to [@magikcypres](https://github.com/magikcypress))
* Fixed partial bug [#9](https://github.com/Sommerregen/grav-plugin-mediaembed/issues/9) (Mediaembed converts images into images)
* Fixed [#15](https://github.com/Sommerregen/grav-plugin-mediaembed/pull/15) (Fixed `media.responsive`)
* Fixed [#25](https://github.com/Sommerregen/grav-plugin-mediaembed/pull/25) (Fix Admin Panel issues [#13](https://github.com/Sommerregen/grav-plugin-mediaembed/issues/13), [#17](https://github.com/Sommerregen/grav-plugin-mediaembed/issues/17), and [#24](https://github.com/Sommerregen/grav-plugin-mediaembed/issues/24))

# v1.2.0
## 08/08/2015

Expand All @@ -18,18 +30,18 @@
## 05/10/2015

1. [](#new)
* Added plugin roadmap
* Added support for modular pages
* Added plugin roadmap
* Added support for modular pages
2. [](#improved)
* Prevent potential division by zero error [#2](https://github.com/Sommerregen/grav-plugin-mediaembed/pull/2)
* Prevent potential division by zero error [#2](https://github.com/Sommerregen/grav-plugin-mediaembed/pull/2)
3. [](#bugfix)
* Fixed link generation in case no MediaEmbed service is found
* Fixed link generation in case no MediaEmbed service is found

# v1.0.1
## 04/28/2015

3. [](#bugfix)
* Fixed issue [#1](https://github.com/Sommerregen/grav-plugin-mediaembed/issues/1) with broken MediaEmbed functionality (i.e. removed test code)
* Fixed issue [#1](https://github.com/Sommerregen/grav-plugin-mediaembed/issues/1) with broken MediaEmbed functionality (i.e. removed test code)

# v1.0.0
## 04/26/2015
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using Grav MediaEmbed Plugin in any way.
MIT LICENSE
-----------

Copyright (c) 2015 Benjamin Regler, https://github.com/sommerregen/grav-plugin-mediaembed
Copyright (c) 2017 Benjamin Regler, https://github.com/sommerregen/grav-plugin-mediaembed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Grav MediaEmbed plugin is the official successor of [Grav VideoEmbed plugin](htt
- Imgur
- Instagram
- GitHub
- Twitter

but more services are coming soon! In principle it supports any service, which provides the [oEmbed format](http://www.oembed.com/). Media are embedded using the Markdown syntax for images (`![Alt](URL "Title")`), e.g. the below screenshot was created with the following code:

Expand Down Expand Up @@ -123,7 +124,7 @@ Thanks!

## License

Copyright (c) 2015 [Benjamin Regler][github]. See also the list of [contributors] who participated in this project.
Copyright (c) 2017 [Benjamin Regler][github]. See also the list of [contributors] who participated in this project.

[Dual-licensed](LICENSE) for use under the terms of the [MIT][mit-license] or [GPLv3][gpl-license] licenses.

Expand Down
34 changes: 22 additions & 12 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: MediaEmbed
version: 1.2.0
version: 1.3.0
description: "This plugin embeds several media sites (e.g. YouTube, Vimeo, Soundcloud) by only providing the URL to the medium."
icon: spinner
author:
Expand Down Expand Up @@ -106,7 +106,7 @@ form:
validate:
type: bool

media.preview:
media.responsive:
type: toggle
label: "Responsive media"
help: "Allow media to be responsive"
Expand All @@ -130,7 +130,7 @@ form:
title: "Services"

fields:
services.SoundCloud:
services.SoundCloud.enabled:
type: toggle
label: "Embed SoundCloud"
default: 1
Expand All @@ -140,7 +140,7 @@ form:
validate:
type: bool

services.Spotify:
services.Spotify.enabled:
type: toggle
label: "Embed Spotify"
default: 1
Expand All @@ -150,7 +150,7 @@ form:
validate:
type: bool

services.Flickr:
services.Flickr.enabled:
type: toggle
label: "Embed Flickr"
default: 1
Expand All @@ -160,7 +160,7 @@ form:
validate:
type: bool

services.Imgur:
services.Imgur.enabled:
type: toggle
label: "Embed Imgur"
default: 1
Expand All @@ -171,7 +171,7 @@ form:
type: bool


services.Instagram:
services.Instagram.enabled:
type: toggle
label: "Embed Instagram"
default: 1
Expand All @@ -181,7 +181,7 @@ form:
validate:
type: bool

services.Dailymotion:
services.Dailymotion.enabled:
type: toggle
label: "Embed Dailymotion"
default: 1
Expand All @@ -191,7 +191,7 @@ form:
validate:
type: bool

services.YouTube:
services.YouTube.enabled:
type: toggle
label: "Embed YouTube"
default: 1
Expand All @@ -201,7 +201,7 @@ form:
validate:
type: bool

services.Vimeo:
services.Vimeo.enabled:
type: toggle
label: "Embed Vimeo"
default: 1
Expand All @@ -211,7 +211,7 @@ form:
validate:
type: bool

services.GitHub:
services.GitHub.enabled:
type: toggle
label: "Embed GitHub"
default: 1
Expand All @@ -221,7 +221,7 @@ form:
validate:
type: bool

services.Slides:
services.Slides.enabled:
type: toggle
label: "Embed Slides"
default: 1
Expand All @@ -230,3 +230,13 @@ form:
0: "No"
validate:
type: bool

services.Twitter.enabled:
type: toggle
label: "Embed Twitter"
default: 1
options:
1: "Yes"
0: "No"
validate:
type: bool
31 changes: 25 additions & 6 deletions classes/MediaEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,28 @@ function($match) use ($twig, &$uid, $config) {
$embed = $twig->processTemplate($template, $vars);
} else {
$text = (strlen($data['alt']) > 0) ? $data['alt'] : $data['src'];
$attributes = [
'href' => $data['src'],
'title' => $data['title'],
];

// If display link or img
$link = $config->get('link');
if($link == true) {
$attributes = [
'href' => $data['src'],
'title' => $data['title'],
];

$format = '<a%s>%s</a>';

} else {
$attributes = [
'src' => $data['src'],
'title' => $data['title'],
'alt' => $data['alt'],
];

$format = '<img%s>';

}

foreach ($attributes as $key => $value) {
if (strlen($value) == 0) {
unset($attributes[$key]);
Expand All @@ -249,8 +267,9 @@ function($match) use ($twig, &$uid, $config) {

$attributes = $attributes ? ' ' . implode(' ', $attributes) : '';

// Transform embed media to link for compatibility
$embed = sprintf('<a%s>%s</a>', $attributes, $text);
// Transform embed media to link or img for compatibility
$embed = sprintf($format, $attributes, $text);

}

return $embed;
Expand Down
10 changes: 6 additions & 4 deletions classes/Services/Github.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Grav\Plugin\MediaEmbed\Services;

use Grav\Common\Debugger;
use Grav\Plugin\MediaEmbed\OEmbed\OEmbedRich;

/**
Expand All @@ -25,6 +26,7 @@ public function getOEmbed()
}

$endpoint = $this->format($this->config->get('endpoint', ''));

if (!$endpoint) {
return [];
}
Expand All @@ -38,13 +40,13 @@ public function getOEmbed()

$this->oembed = [
'type' => 'rich',
'title' => reset($json['files']),
'title' => $json['files'],
'description' => $json['description'],
'author_name' => $json['owner'],
'author_url' => 'http://github.com/' . $json['owner'],
'author_url' => 'https://github.com/' . $json['owner'],
'provider' => 'GitHub',
'provider_url' => 'http://gist.github.com/',
'url' => 'http://www.gist.github.com/' . $this->embedCode,
'provider_url' => 'https://gist.github.com/',
'url' => 'https://gist.github.com/' . $this->embedCode,
'html' => $json['div'],
];

Expand Down
51 changes: 51 additions & 0 deletions classes/Services/Twitter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Twitter
*
* This file is part of Grav MediaEmbed plugin.
*
* Dual licensed under the MIT or GPL Version 3 licenses, see LICENSE.
* http://benjamin-regler.de/license/
*/

namespace Grav\Plugin\MediaEmbed\Services;

use Grav\Plugin\MediaEmbed\OEmbed\OEmbedRich;

/**
* Twitter
*/
class Twitter extends OEmbedRich
{

public function getOEmbed()
{
if ($this->oembed) {
return $this->oembed;
}

$endpoint = $this->format($this->config->get('endpoint', ''));
if (!$endpoint) {
return [];
}

$response = \Requests::get($endpoint);
if (!$response->success) {
$response->throw_for_status();
}

$json = json_decode($response->body, true);

$this->oembed = [
'type' => 'rich',
'author_name' => $json['author_name'],
'author_url' => 'https://twitter.com/' . $json['author_name'],
'provider_name' => 'Twitter',
'provider_url' => 'https://twitter.com/',
'url' => 'https://www.twitter.com/' . $this->embedCode,
'html' => $json['html'],
];

return $this->oembed;
}
}
6 changes: 3 additions & 3 deletions mediaembed.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* MediaEmbed v1.2.0
* MediaEmbed v1.3.0
*
* This plugin embeds several media sites (e.g. YouTube, Vimeo,
* Soundcloud) by only providing the URL to the medium.
Expand All @@ -9,10 +9,10 @@
* http://benjamin-regler.de/license/
*
* @package MediaEmbed
* @version 1.2.0
* @version 1.3.0
* @link <https://github.com/sommerregen/grav-plugin-archive-plus>
* @author Benjamin Regler <[email protected]>
* @copyright 2015, Benjamin Regler
* @copyright 2017, Benjamin Regler
* @license <http://opensource.org/licenses/MIT> MIT
* @license <http://opensource.org/licenses/GPL-3.0> GPLv3
*/
Expand Down
22 changes: 19 additions & 3 deletions mediaembed.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Global plugin configurations

enabled: true # Set to false to disable this plugin completely
link: false # Set if display link or img, if false display img tag for not mediaembed
built_in_css: true # Use built-in CSS of the plugin
built_in_js: true # Use built-in JS of the plugin

Expand Down Expand Up @@ -187,15 +188,15 @@ services:
autoplay: 0

## Others ##
GitHub:
Github:
enabled: true # Set to false to disable this service completely
type: "rich" # Type of the media service

# Canonical URL of media service (used in endpoint calls)
canonical: "http://www.gist.github.com/{:id}"
canonical: "https://gist.github.com/{:id}"

# Endpoint to grab media informations
endpoint: "http://gist.github.com/{:id}.json"
endpoint: "https://gist.github.com/{:id}.json"

# Schemes to grab media id
schemes:
Expand Down Expand Up @@ -223,3 +224,18 @@ services:
style: "light" # Footer style: dark, light, hidden
width: 1920
height: 1400

Twitter:
enabled: true # Set to false to disable this service completely
type: "rich" # Type of the media service

# Canonical URL of media service (used in endpoint calls)
canonical: "https://twitter.com/{:id}"

# Endpoint to grab media informations
endpoint: "https://api.twitter.com/1/statuses/oembed.json?url={:canonical}"

# Schemes to grab media id
schemes:
- "twitter.com/*"
- "twitter.com/*/*"

0 comments on commit 555aad3

Please sign in to comment.