first commit
This commit is contained in:
commit
6f75d623fe
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Neo-Inspiration
|
||||||
|
|
||||||
|
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.
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
namespace ArchiveOembed;
|
||||||
|
|
||||||
|
use Omeka\Module\AbstractModule;
|
||||||
|
use Laminas\EventManager\SharedEventManagerInterface;
|
||||||
|
use Laminas\Mvc\MvcEvent;
|
||||||
|
|
||||||
|
class Module extends AbstractModule
|
||||||
|
{
|
||||||
|
const NAMESPACE = __NAMESPACE__;
|
||||||
|
|
||||||
|
const IMAGE_WIDTH = [
|
||||||
|
'25' => '25 %',
|
||||||
|
'50' => '50 %',
|
||||||
|
'75' => '75 %',
|
||||||
|
'100' => '100 %',
|
||||||
|
];
|
||||||
|
|
||||||
|
const MEDIA_PROVIDERS_OEMBED = [
|
||||||
|
'https://vimeo.com/api/oembed.json?url=' => 'Vimeo',
|
||||||
|
'https://www.youtube.com/oembed?url=' => 'Youtube',
|
||||||
|
'https://sketchfab.com/oembed/?url=' => 'Sketchfab',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getConfig()
|
||||||
|
{
|
||||||
|
return include __DIR__ . '/config/module.config.php';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
# ArchiveOembed videos for Omeka S
|
||||||
|
|
||||||
|
[oEmmed-omeka-module] is a module for [Omeka S] that embeds media and defines height and width.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
cd ./modules
|
||||||
|
https://git.hangar.org/arcHIVE-tech/oEmbed-omeka-module/archive/main.zip
|
||||||
|
unzip main.zip
|
||||||
|
mv archiveOembed-omeka-module ArchiveOembed
|
||||||
|
rm main.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
## LISENCE
|
||||||
|
The module is released under the [MIT] License.
|
||||||
|
|
||||||
|
|
||||||
|
[arc-hive]: https://arc-hive.zone/
|
||||||
|
[oEmmed-omeka-module]: https://git.hangar.org/arcHIVE-tech/oEmbed-omeka-module
|
||||||
|
[Omeka S]: https://omeka.org/s
|
||||||
|
[MIT]: http://opensource.org/licenses/MIT
|
|
@ -0,0 +1,7 @@
|
||||||
|
/* Panaorama viewer custom */
|
||||||
|
@media screen {
|
||||||
|
.archive_org {
|
||||||
|
/* width: 600px; */
|
||||||
|
/* height: 400px; */
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
function adjust_archiveOembed_height() {
|
||||||
|
$(".archive-embeded-wrapper").each(function() {
|
||||||
|
var iframe = $(this).find('iframe')
|
||||||
|
var height = $(iframe).width() / $(iframe).attr('ratio')
|
||||||
|
$(iframe).prop("height", height)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery(document).ready(function() {
|
||||||
|
adjust_archiveOembed_height();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).resize(function() {
|
||||||
|
adjust_archiveOembed_height();
|
||||||
|
});
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
namespace ArchiveOembed;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'view_manager' => [
|
||||||
|
'template_path_stack' => [
|
||||||
|
dirname(__DIR__) . '/view',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'block_layouts' => [
|
||||||
|
'factories' => [
|
||||||
|
'archiveOembed' => Service\BlockLayout\ArchiveOembedFactory::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'form_elements' => [
|
||||||
|
'invokables' => [
|
||||||
|
Form\ArchiveOembedBlockForm::class => Form\ArchiveOembedBlockForm::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'media_ingesters' => [
|
||||||
|
'factories' => [
|
||||||
|
'ArchiveOembed_media' => Service\Media\Ingester\ArchiveOembedMediaFactory::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'media_renderers' => [
|
||||||
|
'invokables' => [
|
||||||
|
'ArchiveOembed_media' => Media\Renderer\ArchiveOembedMediaRenderer::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'DefaultSettings' => [
|
||||||
|
'ArchiveOembedBlockForm' => [
|
||||||
|
'title' => '',
|
||||||
|
'renderSourceLink' => true,
|
||||||
|
'width' => 100,
|
||||||
|
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
|
@ -0,0 +1,12 @@
|
||||||
|
[info]
|
||||||
|
name = "oEmbed a la Arc-hive"
|
||||||
|
description = "oEmbed that defines media height and width."
|
||||||
|
tags = ""
|
||||||
|
license = "MIT"
|
||||||
|
author = "Hangar.org"
|
||||||
|
author_link = "https://git.hangar.org/chris"
|
||||||
|
module_link = "https://git.hangar.org/arcHIVE-tech/ArchiveOembed-omeka-module"
|
||||||
|
support_link = "https://git.hangar.org/arcHIVE-tech/ArchiveOembed-omeka-module/issues"
|
||||||
|
configurable = false
|
||||||
|
version = "1.0.0"
|
||||||
|
omeka_version_constraint = "^3.0.1"
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
namespace ArchiveOembed\Form;
|
||||||
|
|
||||||
|
use ArchiveOembed\Module;
|
||||||
|
use Laminas\Form\Element;
|
||||||
|
use Laminas\Form\Form;
|
||||||
|
|
||||||
|
class ArchiveOembedBlockForm extends Form
|
||||||
|
{
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->add([
|
||||||
|
'name' => 'o:block[__blockIndex__][o:data][width]',
|
||||||
|
'type' => Element\Select::class,
|
||||||
|
'options' => [
|
||||||
|
'label' => 'Width',
|
||||||
|
'value_options' => Module::IMAGE_WIDTH,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->add([
|
||||||
|
'type' => Element\Checkbox::class,
|
||||||
|
'name' => 'o:block[__blockIndex__][o:data][renderSourceLink]',
|
||||||
|
'options' => [
|
||||||
|
'label' => 'Display a link to the item',
|
||||||
|
//'use_hidden_element' => true,
|
||||||
|
'checked_value' => true,
|
||||||
|
'unchecked_value' => false,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->add([
|
||||||
|
'name' => 'o:block[__blockIndex__][o:data][title]',
|
||||||
|
'type' => Element\Text::class,
|
||||||
|
'options' => [
|
||||||
|
'label' => 'Sub-title',
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
namespace ArchiveOembed\Media\Ingester;
|
||||||
|
|
||||||
|
use Omeka\Api\Request;
|
||||||
|
use Omeka\Entity\Media;
|
||||||
|
use Omeka\Media\Ingester\IngesterInterface;
|
||||||
|
use Omeka\Stdlib\ErrorStore;
|
||||||
|
use Omeka\File\Downloader;
|
||||||
|
use Zend\Form\Element\Text;
|
||||||
|
use Zend\Form\Element\Select;
|
||||||
|
use Zend\Http\Client;
|
||||||
|
use Zend\View\Renderer\PhpRenderer;
|
||||||
|
use ArchiveOembed\Module;
|
||||||
|
|
||||||
|
class ArchiveOembedMediaIngester implements IngesterInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Downloader
|
||||||
|
*/
|
||||||
|
protected $downloader;
|
||||||
|
protected $client;
|
||||||
|
|
||||||
|
public function __construct($client, Downloader $downloader)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
$this->downloader = $downloader;
|
||||||
|
}
|
||||||
|
public function getLabel()
|
||||||
|
{
|
||||||
|
return 'oEmbed a la Arc-hive'; // @translate
|
||||||
|
}
|
||||||
|
public function getRenderer()
|
||||||
|
{
|
||||||
|
return 'ArchiveOembed_media';
|
||||||
|
}
|
||||||
|
public function form(PhpRenderer $view, array $options = [])
|
||||||
|
{
|
||||||
|
$provider = new Select('o:media[__index__][o:provider]');
|
||||||
|
$provider->setLabel('Provider');
|
||||||
|
$provider->setValueOptions(Module::MEDIA_PROVIDERS_OEMBED);
|
||||||
|
$media_url = new Text('o:media[__index__][o:media_url]');
|
||||||
|
$media_url->setOptions([
|
||||||
|
'label' => 'URL of the media', // @translate
|
||||||
|
]);
|
||||||
|
$media_url->setAttributes([
|
||||||
|
'required' => true,
|
||||||
|
'placeholder' => 'https://....',
|
||||||
|
]);
|
||||||
|
return $view->formRow($provider) . $view->formRow($media_url);
|
||||||
|
|
||||||
|
}
|
||||||
|
public function ingest(Media $media, Request $request, ErrorStore $errorStore)
|
||||||
|
{
|
||||||
|
// Validate the request data.
|
||||||
|
$data = $request->getContent();
|
||||||
|
if (!isset($data['o:media_url'])) {
|
||||||
|
$errorStore->addError('o:media_url', 'No media URL specified');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$media_url = trim($data['o:media_url']);
|
||||||
|
$oembed_url = $data['o:provider'] . $media_url;
|
||||||
|
//$errorStore->addError($oembed_url, 'oembed_url');
|
||||||
|
//return;
|
||||||
|
//$url = 'https://www.youtube.com/oembed?url=' . $identifier;
|
||||||
|
$response = $this->client->setUri($oembed_url)->send();
|
||||||
|
if (!$response->isOk()) {
|
||||||
|
$errorStore->addError('o:source', sprintf(
|
||||||
|
'Cannot find media URL: ' . $media_url,
|
||||||
|
$response->getReasonPhrase(),
|
||||||
|
$response->getStatusCode()
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$response_body = json_decode($response->getBody());
|
||||||
|
$thumbnail_url = $response_body->thumbnail_url;
|
||||||
|
$tempFile = $this->downloader->download($thumbnail_url);
|
||||||
|
if ($tempFile) {
|
||||||
|
$tempFile->mediaIngestFile($media, $request, $errorStore, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the Media source and data.
|
||||||
|
$media->setSource($data['o:source']);
|
||||||
|
$media->setData(json_decode($response->getBody(), true));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
namespace ArchiveOembed\Media\Renderer;
|
||||||
|
|
||||||
|
use Omeka\Api\Representation\MediaRepresentation;
|
||||||
|
use Omeka\Media\Renderer\RendererInterface;
|
||||||
|
use Zend\View\Renderer\PhpRenderer;
|
||||||
|
|
||||||
|
class ArchiveOembedMediaRenderer implements RendererInterface
|
||||||
|
{
|
||||||
|
public function render(PhpRenderer $view,
|
||||||
|
MediaRepresentation $media,
|
||||||
|
array $options = [])
|
||||||
|
{
|
||||||
|
return $media->mediaData()['html'];
|
||||||
|
}
|
||||||
|
public function thumbnailUrl(PhpRenderer $view,
|
||||||
|
MediaRepresentation $media,
|
||||||
|
array $options = [])
|
||||||
|
{
|
||||||
|
return $media->mediaData()['thumbnail_url'];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
namespace ArchiveOembed\Service\BlockLayout;
|
||||||
|
|
||||||
|
use Interop\Container\ContainerInterface;
|
||||||
|
use ArchiveOembed\Site\BlockLayout\ArchiveOembed;
|
||||||
|
use Laminas\ServiceManager\Factory\FactoryInterface;
|
||||||
|
|
||||||
|
class ArchiveOembedFactory implements FactoryInterface
|
||||||
|
{
|
||||||
|
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
|
||||||
|
{
|
||||||
|
return new ArchiveOembed(
|
||||||
|
$services->get('FormElementManager'),
|
||||||
|
$services->get('Config')['DefaultSettings']['ArchiveOembedBlockForm']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
namespace ArchiveOembed\Service\Media\Ingester;
|
||||||
|
|
||||||
|
use ArchiveOembed\Media\Ingester\ArchiveOembedMediaIngester;
|
||||||
|
use Zend\ServiceManager\Factory\FactoryInterface;
|
||||||
|
use Interop\Container\ContainerInterface;
|
||||||
|
|
||||||
|
class ArchiveOembedMediaFactory implements FactoryInterface
|
||||||
|
{
|
||||||
|
public function __invoke(ContainerInterface $services,
|
||||||
|
$requestedName,
|
||||||
|
array $options = null)
|
||||||
|
{
|
||||||
|
return new ArchiveOembedMediaIngester(
|
||||||
|
$services->get('Omeka\HttpClient'),
|
||||||
|
$services->get('Omeka\File\Downloader')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
namespace ArchiveOembed\Site\BlockLayout;
|
||||||
|
|
||||||
|
use Omeka\Api\Representation\SiteRepresentation;
|
||||||
|
use Omeka\Api\Representation\SitePageRepresentation;
|
||||||
|
use Omeka\Api\Representation\SitePageBlockRepresentation;
|
||||||
|
use Omeka\Site\BlockLayout\AbstractBlockLayout;
|
||||||
|
use Laminas\View\Renderer\PhpRenderer;
|
||||||
|
|
||||||
|
use Laminas\Form\FormElementManager;
|
||||||
|
use ArchiveOembed\Form\ArchiveOembedBlockForm;
|
||||||
|
use DOMDocument;
|
||||||
|
|
||||||
|
class ArchiveOembed extends AbstractBlockLayout
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var FormElementManager
|
||||||
|
*/
|
||||||
|
protected $formElementManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $defaultSettings = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FormElementManager $formElementManager
|
||||||
|
* @param array $defaultSettings
|
||||||
|
*/
|
||||||
|
public function __construct(FormElementManager $formElementManager, array $defaultSettings)
|
||||||
|
{
|
||||||
|
$this->formElementManager = $formElementManager;
|
||||||
|
$this->defaultSettings = $defaultSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLabel() {
|
||||||
|
return 'oEmbed a la Arc-hive';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form(PhpRenderer $view,
|
||||||
|
SiteRepresentation $site,
|
||||||
|
SitePageRepresentation $page = null,
|
||||||
|
SitePageBlockRepresentation $block = null
|
||||||
|
) {
|
||||||
|
$form = $this->formElementManager->get(ArchiveOembedBlockForm::class);
|
||||||
|
$data = $block
|
||||||
|
? $block->data() + $this->defaultSettings
|
||||||
|
: $this->defaultSettings;
|
||||||
|
$form->setData([
|
||||||
|
'o:block[__blockIndex__][o:data][title]' => $data['title'],
|
||||||
|
'o:block[__blockIndex__][o:data][width]' => $data['width'],
|
||||||
|
'o:block[__blockIndex__][o:data][renderSourceLink]' => $data['renderSourceLink'],
|
||||||
|
]);
|
||||||
|
$form->prepare();
|
||||||
|
|
||||||
|
$html = '';
|
||||||
|
$html .= $view->blockAttachmentsForm($block);
|
||||||
|
$html .= '<a href="#" class="collapse" aria-label="collapse"><h4>';
|
||||||
|
$html .= $view->translate('Options'). '</h4></a>';
|
||||||
|
$html .= '<div class="collapsible" style="padding-top:6px;">';
|
||||||
|
$html .= $view->formCollection($form);
|
||||||
|
$html .= '</div>';
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
|
||||||
|
{
|
||||||
|
$attachments = $block->attachments();
|
||||||
|
if (!$attachments) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$media = $attachments[0]->item()->media()[0];
|
||||||
|
$ratio = $media->mediaData()['width'] / $media->mediaData()['height'];
|
||||||
|
|
||||||
|
// creates an iframe injecting our width and calculated ratio
|
||||||
|
$attribs= 'ratio="'.$ratio.'"'.PHP_EOL;
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$doc->loadHTML($media->mediaData()['html']);
|
||||||
|
$html_element= $doc->getElementsByTagName('iframe')->item(0);
|
||||||
|
if ($html_element->hasAttributes()) {
|
||||||
|
foreach ($html_element->attributes as $attr) {
|
||||||
|
$name = $attr->nodeName;
|
||||||
|
$value = $attr->nodeValue;
|
||||||
|
if ($name == 'height') {
|
||||||
|
// we will calculate height with jQuery
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($name == 'width') {
|
||||||
|
$attrib = 'width="'.$block->dataValue('width').'%"';
|
||||||
|
$attribs .= $attrib.PHP_EOL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$attrib = $name.'="'.$value.'"';
|
||||||
|
$attribs .= $attrib.PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$iframe = "<iframe ".$attribs." >".PHP_EOL."</iframe>";
|
||||||
|
|
||||||
|
return $view->partial('common/block-layout/archiveOembed', [
|
||||||
|
'title' => $block->dataValue('title'),
|
||||||
|
'renderSourceLink' => $block->dataValue('renderSourceLink'),
|
||||||
|
'item_url' => $attachments[0]->item()->url(),
|
||||||
|
'archiveOembed_iframe' => $iframe
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
$this->headScript()->appendFile($this->assetUrl('js/media_dimensions.js',
|
||||||
|
'ArchiveOembed'));
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="archive-block archive-embeded-wrapper"
|
||||||
|
style="position:relative;">
|
||||||
|
|
||||||
|
<?php if ($renderSourceLink) { ?>
|
||||||
|
<div class="source-link">
|
||||||
|
<a href="<?= $item_url ?>">Source</a>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<?= $archiveOembed_iframe ?>
|
||||||
|
|
||||||
|
<?php if ($title) { ?>
|
||||||
|
<div class="item_title">
|
||||||
|
<?= $title ?>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
</script>
|
Loading…
Reference in New Issue