Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGraph committed Dec 12, 2016
2 parents 947cd0d + 4f79093 commit 8d4c6c7
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 54 deletions.
8 changes: 5 additions & 3 deletions docs/main/Credits.textile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

h2. Changelog

* *oui_player v1.2.0-beta* (2016-10-28)
* *oui_player v1.2.0* (2016-12-12)
** sets the custom field plugin pref as the defaut value of the conditional tag @play@ attribute;
** introduces a @play@ attribute value inheritance in a conditional/container tag context;
** adds support for "Vine":https://vine.co/;
** adds support for:
*** "Twitch channels":https://www.twitch.tv/,
*** "Vine":https://vine.co/;
** improves PHP classes and methods use (see _For developers_).
* *oui_player v1.1.0* (2016-10-14)
** changes Plugin/tag names;
** changes plugin/tag names;
** drops Txp 4.5 support;
** Sets closer attribute names to player parameters for consistency;
** reworks source code to be easily extendable;
Expand Down
2 changes: 1 addition & 1 deletion docs/main/Menu.textile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ notextile. <div role="group">
notextile. </div>
</section>

"(navlink)See on GitHub":https://github.com/NicolasGraph/oui_player "(navlink)Donate":https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PREHX3MZMXEUN
"(navlink)Contribute":https://github.com/NicolasGraph/oui_player "(navlink)Donate":https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PREHX3MZMXEUN "(navlink)Tweet":https://twitter.com/intent/tweet?text=I%27m%20enjoying%20video%20embedding%20in%20%23Textpattern%20%23CMS%20via%20%23oui_player!%20%40NicolasGraph%20https://github.com/NicolasGraph/oui_player

notextile. </div>
5 changes: 2 additions & 3 deletions docs/providers/Twitch.textile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ notextile. <section id="twitch" class="options_group">

h2. Twitch player config

This plugin reads Twitch videos only for now, not channels.

h3. Recognised values for the @play@ attribute

* v[*id*]
* http(s)://(www.)twitch.tv/…/v/[*id*]
* http(s)://(www.)twitch.tv/…/v/[*id*] (video)
* http(s)://(www.)twitch.tv/[*id*] (channel)

h3. Player size

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "oui_player",
"description" : "Embed customised players",
"version" : "1.2.0-beta",
"version" : "1.2.0",
"type" : 1,
"author" : "Nicolas Morand",
"author_uri" : "http://github.com/NicolasGraph",
Expand Down
10 changes: 5 additions & 5 deletions src/player/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class Admin extends Player
public function __construct()
{
if (txpinterface === 'admin') {
parent::__construct();
$this->plugin = strtolower(str_replace('\\', '_', __NAMESPACE__));
$this->providers = callback_event($this->plugin, 'plug_providers', 0, 'Provider');

$this->tags['oui_player']['provider']['valid'] = $this->providers;
$this->tags['oui_if_player']['provider']['valid'] = $this->providers;
$this->prefs['provider']['default'] = $this->providers[0];
$this->prefs['provider']['valid'] = $this->providers;
$this->prefs['provider']['default'] = $this->prefs['provider']['valid'][0];
$this->prefs['providers']['default'] = implode(', ', $this->prefs['provider']['valid']);

add_privs('plugin_prefs.' . $this->plugin, $this->privs);
add_privs('prefs.' . $this->plugin, $this->privs);
Expand Down Expand Up @@ -185,7 +185,7 @@ public function setPrefs()
$pref,
$options['default'],
$options['group'],
PREF_PLUGIN,
$pref === 'oui_player_providers' ? PREF_HIDDEN : PREF_PLUGIN,
isset($options['widget']) ? $options['widget'] : $this->prefWidget($options),
$position
);
Expand Down
8 changes: 2 additions & 6 deletions src/player/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ class Player
),
'provider' => array(
),
'providers' => array(
),
);

public function __construct()
{
$this->plugin = strtolower(str_replace('\\', '_', __NAMESPACE__));
$this->providers = callback_event($this->plugin, 'plug_providers', 0, 'Provider');
}
}
}
5 changes: 4 additions & 1 deletion src/player/Public.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Main extends Player

public function __construct()
{
parent::__construct();
$this->plugin = strtolower(str_replace('\\', '_', __NAMESPACE__));
$this->providers = explode(', ', \get_pref($this->plugin . '_providers'));
}

/**
Expand Down Expand Up @@ -90,6 +91,7 @@ public function getInfos()
'url' => '',
'provider' => \get_pref($this->plugin . '_provider'),
'id' => $this->play,
'type' => '',
);
}

Expand All @@ -105,6 +107,7 @@ public function getPlayer()
$class = __NAMESPACE__ . '\\' . $item['provider'];
$obj = new $class;
$obj->play = $item['id'];
$obj->type = $item['type'];
$obj->config = $this->config;
$out = $obj->getPlayer();
if ($out) {
Expand Down
7 changes: 6 additions & 1 deletion src/player/providers/Abcnews.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

class Abcnews extends Provider
{
protected $patterns = array('#^(http|https):\/\/(abcnews\.go\.com\/([A-Z]+\/)?video)\/[^0-9]+([0-9]+)$#i' => '4');
protected $patterns = array(
'video' => array(
'scheme' => '#^(http|https):\/\/(abcnews\.go\.com\/([A-Z]+\/)?video)\/[^0-9]+([0-9]+)$#i',
'id' => '4',
),
);
protected $src = '//abcnews.go.com/video/embed?id=';
}

Expand Down
7 changes: 6 additions & 1 deletion src/player/providers/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

class Archive extends Provider
{
protected $patterns = array('#^(http|https):\/\/(www.)?archive\.org\/(details|embed)\/([^\&\?\/]+)$#i' => '4');
protected $patterns = array(
'unknown' => array(
'scheme' => '#^(http|https):\/\/(www.)?archive\.org\/(details|embed)\/([^\&\?\/]+)$#i',
'id' => '4',
),
);
protected $src = '//archive.org/embed/';
protected $glue = array('&amp;', '&amp;');
protected $dims = array(
Expand Down
7 changes: 6 additions & 1 deletion src/player/providers/Dailymotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

class Dailymotion extends Provider
{
protected $patterns = array('#^(http|https):\/\/(www.)?(dailymotion\.com\/((embed\/video)|(video))|(dai\.ly?))\/([A-Za-z0-9]+)#i' => '8');
protected $patterns = array(
'video' => array(
'scheme' => '#^(http|https):\/\/(www.)?(dailymotion\.com\/((embed\/video)|(video))|(dai\.ly?))\/([A-Za-z0-9]+)#i',
'id' => '8',
),
);
protected $src = '//www.dailymotion.com/embed/video/';
protected $params = array(
'autoplay' => array(
Expand Down
7 changes: 6 additions & 1 deletion src/player/providers/Mixcloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

class Mixcloud extends Provider
{
protected $patterns = array('#^((http|https):\/\/(www.)?mixcloud.com\/[\S]+)$#i' => '1');
protected $patterns = array(
'audio' => array(
'scheme' => '#^((http|https):\/\/(www.)?mixcloud.com\/[\S]+)$#i',
'id' => '1',
),
);
protected $src = '//www.mixcloud.com/widget/iframe/?feed=';
protected $dims = array(
'width' => array(
Expand Down
7 changes: 6 additions & 1 deletion src/player/providers/Myspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

class Myspace extends Provider
{
protected $patterns = array('#^(http|https):\/\/myspace\.com\/[\S]+\/video\/[\S]+\/(\d+)$#i' => '2');
protected $patterns = array(
'video' => array(
'scheme' => '#^(http|https):\/\/myspace\.com\/[\S]+\/video\/[\S]+\/(\d+)$#i',
'id' => '2',
),
);
protected $src = '//media.myspace.com/play/video/';
}

Expand Down
157 changes: 157 additions & 0 deletions src/player/providers/None.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

/*
* oui_player - An extendable plugin to easily embed iframe
* customizable players in Textpattern CMS.
*
* https://github.com/NicolasGraph/oui_player
*
* Copyright (C) 2016 Nicolas Morand
*
* This file is part of oui_player.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, see https://www.gnu.org/licenses/.
*/

namespace Oui\Player {

class None extends Provider
{
protected $patterns = array(
'audio' => array(
'scheme' => '#^(\S+(.mp3)$)$#i',
'id' => '1',
),
'video' => array(
'scheme' => '#^(\S+(.mp4)$)$#i',
'id' => '1',
),
);
protected $src = '';
protected $params = array(
'autoplay' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'buffered' => array(
'default' => '',
),
'controls' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'crossorigns' => array(
'default' => '',
'valid' => array('', 'anonymous', 'use-credentials'),
),
'loop' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'muted' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'played' => array(
'default' => '0',
'valid' => array('0', '1'),
),
'preload' => array(
'default' => '',
'valid' => array('', 'none', 'metadata', 'auto'),
),
'poster' => array(
'default' => '',
'valid' => 'url',
),
);

/**
* Get player parameters in in use.
*/
public function getParams()
{
$params = array();

foreach ($this->params as $param => $infos) {
$pref = \get_pref(strtolower(str_replace('\\', '_', get_class($this))) . '_' . $param);
$default = $infos['default'];
$att = str_replace('-', '_', $param);
$value = isset($this->config[$att]) ? $this->config[$att] : '';

// Add attributes values in use or modified prefs values as player parameters.
if ($value === '' && $pref !== $default) {
// Remove # from the color pref as a color type is used for the pref input.
if ($infos['valid'] === array('0', '1')) {
$params[] = $param;
} else {
$params[] = $param . '=' . str_replace('#', '', $pref);
}
} elseif ($value !== '') {
// Remove the # in the color attribute just in case…
if ($infos['valid'] === array('0', '1')) {
$params[] = $param;
} else {
$params[] = $param . '=' . str_replace('#', '', $value);
}
}
}

return $params;
}

/**
* Get the player code
*/
public function getPlayer()
{
if (!empty($this->play)) {
$item = $this->getInfos();
$item ?: $item = array(
'id' => $this->play,
'type' => $this->type,
);
}

if ($item) {
$src = $this->src . $item['id'];
$params = $this->getParams();

$dims = $this->getSize();
extract($dims);

if (!$dims || !$height) {
// Work out the aspect ratio.
preg_match("/(\d+):(\d+)/", $ratio, $matches);
if ($matches[0] && $matches[1]!=0 && $matches[2]!=0) {
$aspect = $matches[1] / $matches[2];
} else {
$aspect = 1.778;
}

// Calcuate the new width/height.
if ($width) {
$height = $width / $aspect;
} elseif ($height) {
$width = $height * $aspect;
}
}

return '<' . $item['type'] . ' width="' . $width . '" height="' . $height . '" src="' . $src . '"' . (empty($params) ?: ' ' . implode(' ', $params)) . '></' . $item['type'] . '>' . $this->append;
}
}
}

new None;
}
Loading

0 comments on commit 8d4c6c7

Please sign in to comment.