Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Hunziker
committed
Aug 12, 2016
1 parent
89f2902
commit f95f97d
Showing
6 changed files
with
361 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
plg_sermonspeaker_vimeo/language/en-GB/en-GB.plg_sermonspeaker_vimeo.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_SERMONSPEAKER_VIMEO="SermonSpeaker - Vimeo" | ||
PLG_SERMONSPEAKER_VIMEO_XML_DESCRIPTION="Creates a player using Vimeo." | ||
|
||
; Fields | ||
PLG_SERMONSPEAKER_VIMEO_FIELD_GA_LABEL="Google Analytics" | ||
PLG_SERMONSPEAKER_VIMEO_FIELD_GA_DESC="Activates the support for Google Analytics." | ||
|
||
; Common strings across plugins. Hopefully shared with Transifex translation memory | ||
PLG_SERMONSPEAKER_COMMON_FIELD_AUTOSTART_LABEL="Autostart " | ||
PLG_SERMONSPEAKER_COMMON_FIELD_AUTOSTART_DESC="If enabled audio/video will start automatically" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_AWIDTH_LABEL="Audio Width" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_AWIDTH_DESC="Set width of player when playing audio files" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_AHEIGHT_LABEL="Audio Height" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_AHEIGHT_DESC="Set height of player when playing audio files" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_VWIDTH_LABEL="Video Width" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_VWIDTH_DESC="Set width of player when playing video files" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_VHEIGHT_LABEL="Video Height" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_VHEIGHT_DESC="Set height of player when playing video files" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_FILEPRIO_LABEL="Priority" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_FILEPRIO_DESC="Select the priority which file should be shown if both (video and audio) are present" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_FILETOGGLE_LABEL="Audio/Video toggle" | ||
PLG_SERMONSPEAKER_COMMON_FIELD_FILETOGGLE_DESC="Allows to toggle between audio- and videofiles" | ||
PLG_SERMONSPEAKER_COMMON_SPEAKER="Speaker" | ||
PLG_SERMONSPEAKER_COMMON_AUDIO="Audio" | ||
PLG_SERMONSPEAKER_COMMON_VIDEO="Video" |
4 changes: 4 additions & 0 deletions
4
plg_sermonspeaker_vimeo/language/en-GB/en-GB.plg_sermonspeaker_vimeo.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_SERMONSPEAKER_VIMEO="SermonSpeaker - Vimeo" | ||
PLG_SERMONSPEAKER_VIMEO_XML_DESCRIPTION="Creates a player using Vimeo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/** | ||
* GA Code Samples | ||
* | ||
* Vimeo Video Tracking Plugin | ||
* | ||
* Copyright 2011, Cardinal Path | ||
* Licensed under the MIT license. | ||
* | ||
* @author Eduardo Cereto <eduardocereto@gmail.com> | ||
*/ | ||
|
||
(function(){ | ||
|
||
//Shortcuts, these speed up and compress the code | ||
var sindexOf = String.prototype.indexOf; | ||
|
||
|
||
/** | ||
* Helper function to post messages to a vimeo player | ||
* | ||
* @param {string} method The method from the vimeo API. | ||
* @param {string} params to be passed as the value of the method. | ||
* @param {object} target Iframe DOM Element for the Vimeo player. | ||
* @return {boolean} true if it worked or false otherwise. | ||
*/ | ||
function _vimeoPostMessage(method, params, target) { | ||
if (!target.contentWindow || !target.contentWindow.postMessage) { | ||
return false; | ||
} | ||
var url = target.getAttribute('src').split('?')[0], | ||
data = JSON.stringify({ | ||
method: method, | ||
value: params | ||
}); | ||
target.contentWindow.postMessage(data, url); | ||
return true; | ||
} | ||
|
||
/** | ||
* Cached urls for vimeo players on the page. | ||
* | ||
* @type {object} | ||
*/ | ||
var _vimeo_urls = {}; | ||
|
||
/** | ||
* Flag that indicates if the global listener has been bind to the window | ||
* @type {boolean} | ||
*/ | ||
var _has_vimeo_window_event = false; | ||
|
||
/** | ||
* Triggers the Vimeo Tracking on the page | ||
* | ||
* Only works for the Universal Tag from Vimeo (iframe). The video must have | ||
* the parameter api=1 on the url in order to make the tracking work. | ||
* | ||
* @this {GasHelper} GA Helper object. | ||
* @param {(string|boolean)} force evaluates to true if we should force the | ||
* api=1 parameter on the url to activate the api. May cause the player to | ||
* reload. | ||
*/ | ||
function _trackVimeo(force) { | ||
var iframes = document.getElementsByTagName('iframe'); | ||
var vimeo_videos = 0; | ||
var player_id; | ||
var player_src; | ||
var separator; | ||
for (var i = 0; i < iframes.length; i++) { | ||
if (sindexOf.call(iframes[i].src, '//player.vimeo.com') > -1) { | ||
player_id = 'gas_vimeo_' + i; | ||
player_src = iframes[i].src; | ||
separator = '?'; | ||
if (sindexOf.call(player_src, '?') > -1) { | ||
separator = '&'; | ||
} | ||
if (sindexOf.call(player_src, 'api=1') < 0) { | ||
if (force) { | ||
// Reload the video enabling the api | ||
player_src += separator + 'api=1&player_id=' + player_id; | ||
}else { | ||
// We won't track players that don't have api enabled. | ||
break; | ||
} | ||
}else { | ||
if (sindexOf.call(player_src, 'player_id=') < -1) { | ||
player_src += separator + 'player_id=' + player_id; | ||
} | ||
} | ||
vimeo_videos++; | ||
iframes[i].id = player_id; | ||
if (iframes[i].src !== player_src) { | ||
iframes[i].src = player_src; | ||
break; // break to wait until it is ready since we reloaded it. | ||
} | ||
// We need to cache the video url since vimeo won't provide it | ||
// in the event | ||
_vimeoPostMessage('getVideoUrl', '', iframes[i]); | ||
_vimeoPostMessage('addEventListener', 'play', iframes[i]); | ||
_vimeoPostMessage('addEventListener', 'pause', iframes[i]); | ||
_vimeoPostMessage('addEventListener', 'finish', iframes[i]); | ||
} | ||
} | ||
if (vimeo_videos > 0 && _has_vimeo_window_event === false) { | ||
var WindowEvent = function(callback){ | ||
if (window.addEventListener) { | ||
window.addEventListener('message', callback, false); | ||
} | ||
// IE | ||
else { | ||
window.attachEvent('onmessage', callback, false); | ||
} | ||
}; | ||
|
||
|
||
WindowEvent(function(event) { | ||
if (sindexOf.call(event.origin, '//player.vimeo.com') > -1) { | ||
var data = JSON.parse(event.data); | ||
if (data.event === 'ready') { | ||
_trackVimeo(); // Force rerun since a player is ready | ||
}else if (data.method) { | ||
if (data.method == 'getVideoUrl') { | ||
_vimeo_urls[data.player_id] = data.value; | ||
} | ||
} else { | ||
ga('send', 'event', 'Vimeo Video', | ||
data.event, _vimeo_urls[data.player_id]); | ||
} | ||
} | ||
|
||
}); | ||
_has_vimeo_window_event = true; | ||
} | ||
} | ||
|
||
window['_trackVimeo'] = _trackVimeo; | ||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
/** | ||
* @package SermonSpeaker | ||
* @subpackage Plugin.SermonSpeaker | ||
* @author Thomas Hunziker <admin@sermonspeaker.net> | ||
* @copyright © 2016 - Thomas Hunziker | ||
* @license http://www.gnu.org/licenses/gpl.html | ||
**/ | ||
|
||
defined('_JEXEC') or die(); | ||
|
||
JLoader::register('SermonspeakerPluginPlayer', JPATH_SITE . '/components/com_sermonspeaker/plugin/player.php'); | ||
JLoader::register('SermonspeakerHelperSermonspeaker', JPATH_SITE . '/components/com_sermonspeaker/helpers/sermonspeaker.php'); | ||
|
||
/** | ||
* Plug-in to show the Vimeo videos | ||
* | ||
* @since 5.5.0 | ||
*/ | ||
class PlgSermonspeakerVimeo extends SermonspeakerPluginPlayer | ||
{ | ||
/** | ||
* @var object Holds the player object | ||
*/ | ||
protected $player; | ||
|
||
/** | ||
* @var boolean True if scripts are loaded already | ||
*/ | ||
private static $script_loaded = false; | ||
|
||
/** | ||
* @var string player mode. Either 'audio' or 'video'. | ||
*/ | ||
private $mode; | ||
|
||
/** | ||
* @var string filetype mode. Either 'audio', 'video' or 'auto' (default). | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @var int which file to prioritise. Either 0 (audio) or 1 (video). | ||
*/ | ||
private $fileprio; | ||
|
||
/** | ||
* @var array Player options | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* Creates the player | ||
* | ||
* @param string $context The context from where it's triggered | ||
* @param object &$player Player object | ||
* @param array|object $items An array of sermnon objects or a single sermon object | ||
* @param Joomla\Registry\Registry $config A config object. Special properties: | ||
* - count (id of the player) | ||
* - type (may be audio, video or auto) | ||
* - prio (may be 0 for audio or 1 for video) | ||
* - autostart (overwrites the backend setting) | ||
* - alt_player (overwrites the backend setting) | ||
* - awidth, aheight (width and height for audio) | ||
* - vwidth, vheight (width and height for video) | ||
* | ||
* @return void | ||
*/ | ||
public function onGetPlayer($context, &$player, $items, $config) | ||
{ | ||
$this->player = $player; | ||
|
||
// There is already a player loaded | ||
if ($this->player->mspace) | ||
{ | ||
return; | ||
} | ||
|
||
// Config asks for a specific player | ||
if ($config->get('alt_player', $this->_name) != $this->_name) | ||
{ | ||
return; | ||
} | ||
|
||
if (is_array($items)) | ||
{ | ||
return; | ||
} | ||
|
||
// Merge $config into plugin params. $config takes priority. | ||
$this->params->merge($config); | ||
|
||
$count = $this->params->get('count', 1); | ||
|
||
$supported = $this->isSupported($items); | ||
|
||
if (!$supported) | ||
{ | ||
return; | ||
} | ||
|
||
$this->setDimensions(50, '100%'); | ||
$this->setPopup('v'); | ||
$id = trim(strrchr($items->videofile, '/'), '/ '); | ||
$start = $this->params->get('autostart') ? 1 : 0; | ||
|
||
$this->player->player = $this->_name; | ||
$this->player->toggle = false; | ||
$this->player->mspace = '<iframe id="mediaspace' . $count . '" width="' . $this->config['vwidth'] . '" height="' . $this->config['vheight'] | ||
. '" src="https://player.vimeo.com/video/' . $id . '?title=0&byline=0&portrait=0&border=0&autoplay=' . $start . '&player_id=vimeo' | ||
. $count . '&api=1"></iframe>'; | ||
|
||
// Loading needed Javascript only once | ||
if (!self::$script_loaded) | ||
{ | ||
if ($this->params->get('ga', '')) | ||
{ | ||
JHtml::Script('media/plg_sermonspeaker_vimeo/js/ganalytics.js', true); | ||
$doc = JFactory::getDocument(); | ||
$doc->addScriptDeclaration("window.addEvent('domready', _trackVimeo);"); | ||
} | ||
|
||
self::$script_loaded = 1; | ||
} | ||
|
||
return; | ||
} | ||
|
||
/** | ||
* Checks if either audio or videofile is supported | ||
* | ||
* @param object $item Sermon object | ||
* | ||
* @return array supported files | ||
*/ | ||
private function isSupported($item) | ||
{ | ||
$supported = array(); | ||
|
||
if (parse_url($item->videofile, PHP_URL_HOST) == 'vimeo.com' | ||
|| parse_url($item->videofile, PHP_URL_HOST) == 'player.vimeo.com' | ||
) | ||
{ | ||
$supported[] = 'video'; | ||
} | ||
|
||
return $supported; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<extension version="3.6.0" type="plugin" group="sermonspeaker" method="upgrade"> | ||
<name>plg_sermonspeaker_vimeo</name> | ||
<author>Thomas Hunziker</author> | ||
<creationDate>2016-08-12</creationDate> | ||
<copyright>© 2016</copyright> | ||
<license>http://www.gnu.org/licenses/gpl.html</license> | ||
<authorEmail>admin@sermonspeaker.net</authorEmail> | ||
<authorUrl>http://www.sermonspeaker.net</authorUrl> | ||
<version>5.5.0</version> | ||
<description>PLG_SERMONSPEAKER_VIMEO_XML_DESCRIPTION</description> | ||
<files> | ||
<filename plugin="vimeo">vimeo.php</filename> | ||
<folder>language</folder> | ||
</files> | ||
<media destination="plg_sermonspeaker_vimeo" folder="media"> | ||
<folder>js</folder> | ||
</media> | ||
<updateservers> | ||
<server type="extension" priority="1" name="SermonSpeaker.net">http://www.sermonspeaker.net/update/plg_sermonspeaker_vimeo.xml</server> | ||
</updateservers> | ||
<config> | ||
<fields name="params"> | ||
<fieldset name="basic"> | ||
<field | ||
name="ga" | ||
type="radio" | ||
label="PLG_SERMONSPEAKER_VIMEO_FIELD_GA_LABEL" | ||
description="PLG_SERMONSPEAKER_VIMEO_FIELD_GA_DESC" | ||
class="btn-group btn-group-yesno" | ||
default="0" | ||
> | ||
<option value="1">JYES</option> | ||
<option value="0">JNO</option> | ||
</field> | ||
</fieldset> | ||
</fields> | ||
</config> | ||
</extension> |