initial commit

This commit is contained in:
buttle 2021-07-18 20:58:50 +02:00
commit 361f4c2917
13 changed files with 422 additions and 0 deletions

21
LICENSE Normal file
View File

@ -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.

22
Module.php Normal file
View File

@ -0,0 +1,22 @@
<?php
namespace Vimeo;
use Omeka\Module\AbstractModule;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\MvcEvent;
class Module extends AbstractModule
{
const NAMESPACE = __NAMESPACE__;
const RATIOS = [
'1.777' => '16:9',
'1.333' => '4:3',
'2' => '2:1',
];
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}

25
README.md Normal file
View File

@ -0,0 +1,25 @@
# Vimeo models for Omeka S
[Vimeo-omeka-module] is a module for [Omeka S] that integrates Vimeo
videos.
## Install
```
cd ./modules
https://git.hangar.org/arcHIVE-tech/Vimeo-omeka-module/archive/main.zip
unzip main.zip
mv vimeo-omeka-module Vimeo
rm main.zip
```
## LISENCE
The module is released under the [MIT] License.
[arc-hive]: https://arc-hive.zone/
[Vimeo-omeka-module]: https://git.hangar.org/arcHIVE-tech/Vimeo-omeka-module
[Omeka S]: https://omeka.org/s
[MIT]: http://opensource.org/licenses/MIT

7
asset/css/archiveOrg.css Normal file
View File

@ -0,0 +1,7 @@
/* Panaorama viewer custom */
@media screen {
.archive_org {
/* width: 600px; */
/* height: 400px; */
}
}

39
config/module.config.php Normal file
View File

@ -0,0 +1,39 @@
<?php
namespace Vimeo;
return [
'view_manager' => [
'template_path_stack' => [
dirname(__DIR__) . '/view',
]
],
'block_layouts' => [
'factories' => [
'vimeo' => Service\BlockLayout\VimeoFactory::class,
],
],
'form_elements' => [
'invokables' => [
Form\VimeoBlockForm::class => Form\VimeoBlockForm::class,
],
],
'media_ingesters' => [
'factories' => [
'Vimeo_media' => Service\Media\Ingester\VimeoMediaFactory::class,
],
],
'media_renderers' => [
'invokables' => [
'Vimeo_media' => Media\Renderer\VimeoMediaRenderer::class,
],
],
'DefaultSettings' => [
'VimeoBlockForm' => [
'title' => '',
'renderSourceLink' => true,
'width' => 600,
'ratio' => '2',
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',
]
]
];

12
config/module.ini Normal file
View File

@ -0,0 +1,12 @@
[info]
name = "Vimeo model viewer"
description = "Embed Vimeo videos"
tags = ""
license = "MIT"
author = "Hangar.org"
author_link = "https://git.hangar.org/chris"
module_link = "https://git.hangar.org/arcHIVE-tech/Vimeo-omeka-module"
support_link = "https://git.hangar.org/arcHIVE-tech/Vimeo-omeka-module/issues"
configurable = false
version = "1.0.0"
omeka_version_constraint = "^3.0.1"

View File

@ -0,0 +1,44 @@
<?php
namespace Vimeo\Form;
use Vimeo\Module;
use Laminas\Form\Element;
use Laminas\Form\Form;
class VimeoBlockForm extends Form
{
public function init()
{
$this->add([
'name' => 'o:block[__blockIndex__][o:data][width]',
'type' => Element\Number::class,
'options' => [
'label' => 'Width in pixels',
],
'attributes' => [
'min' => '100',
],
]);
$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',
]
]);
}
}

View File

@ -0,0 +1,77 @@
<?php
namespace Vimeo\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\Http\Client;
use Zend\View\Renderer\PhpRenderer;
class VimeoMediaIngester implements IngesterInterface
{
/**
* @var Downloader
*/
protected $downloader;
protected $client;
public function __construct($client, Downloader $downloader)
{
$this->client = $client;
$this->downloader = $downloader;
}
public function getLabel()
{
return 'Vimeo model'; // @translate
}
public function getRenderer()
{
return 'Vimeo_media';
}
public function form(PhpRenderer $view, array $options = [])
{
$input = new Text('o:media[__index__][o:identifier]');
$input->setOptions([
'label' => 'URL of the video', // @translate
]);
$input->setAttributes([
'required' => true,
'placeholder' => 'https://vimeo.com/....',
]);
return $view->formRow($input);
}
public function ingest(Media $media, Request $request, ErrorStore $errorStore)
{
// Validate the request data.
$data = $request->getContent();
if (!isset($data['o:identifier'])) {
$errorStore->addError('o:identifier', 'No identifier specified');
return;
}
$identifier = trim($data['o:identifier']);
$url = 'https://vimeo.com/api/oembed.json?url=' . $identifier;
$response = $this->client->setUri($url)->send();
if (!$response->isOk()) {
$errorStore->addError('o:source', sprintf(
'Cannot find video URL: ' . $identifier,
$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));
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Vimeo\Media\Renderer;
use Omeka\Api\Representation\MediaRepresentation;
use Omeka\Media\Renderer\RendererInterface;
use Zend\View\Renderer\PhpRenderer;
class VimeoMediaRenderer 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'];
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Vimeo\Service\BlockLayout;
use Interop\Container\ContainerInterface;
use Vimeo\Site\BlockLayout\Vimeo;
use Laminas\ServiceManager\Factory\FactoryInterface;
class VimeoFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
return new Vimeo(
$services->get('FormElementManager'),
$services->get('Config')['DefaultSettings']['VimeoBlockForm']
);
}
}
?>

View File

@ -0,0 +1,19 @@
<?php
namespace Vimeo\Service\Media\Ingester;
use Vimeo\Media\Ingester\VimeoMediaIngester;
use Zend\ServiceManager\Factory\FactoryInterface;
use Interop\Container\ContainerInterface;
class VimeoMediaFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $services,
$requestedName,
array $options = null)
{
return new VimeoMediaIngester(
$services->get('Omeka\HttpClient'),
$services->get('Omeka\File\Downloader')
);
}
}

View File

@ -0,0 +1,90 @@
<?php
namespace Vimeo\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 Vimeo\Form\VimeoBlockForm;
class Vimeo 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 'Vimeo model';
}
public function form(PhpRenderer $view,
SiteRepresentation $site,
SitePageRepresentation $page = null,
SitePageBlockRepresentation $block = null
) {
$form = $this->formElementManager->get(VimeoBlockForm::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][ratio]' => $data['ratio'],
'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 '';
}
$thumbnails = [];
static $id = 0;
$media = $attachments[0]->item()->media()[0];
$width = 900;
//$height = $width / $block->dataValue('ratio');
$height = $width / 1.333;
return $view->partial('common/block-layout/vimeo', [
'title' => $block->dataValue('title'),
'renderSourceLink' => $block->dataValue('renderSourceLink'),
'item_url' => $attachments[0]->item()->url(),
'width' => $width,
'height' => $height,
'vimeo_iframe' => $media->mediaData()['html'],
]);
}
}

View File

@ -0,0 +1,26 @@
<div class="vimeo-wrap" style="position:relative;">
<?php if ($renderSourceLink) { ?>
<div class="source-link">
<a href="<?= $item_url ?>">Source</a>
</div>
<?php } ?>
<?= $vimeo_iframe ?>
<?php if ($title) { ?>
<div class="item_title">
<?= $title ?>
</div>
<?php } ?>
</div>
<script>
jQuery(document).ready(function() {
var vimeo = $(".vimeo-wrap").find('iframe');
//$(vimeo).prop('width', <?= $width ?>);
//$(vimeo).prop('height', <?= $height ?>);
});
</script>