From 361f4c29172291749201634bc5e5c9662fbbe70b Mon Sep 17 00:00:00 2001 From: buttle Date: Sun, 18 Jul 2021 20:58:50 +0200 Subject: [PATCH] initial commit --- LICENSE | 21 +++++ Module.php | 22 +++++ README.md | 25 ++++++ asset/css/archiveOrg.css | 7 ++ config/module.config.php | 39 ++++++++ config/module.ini | 12 +++ src/Form/VimeoBlockForm.php | 44 +++++++++ src/Media/Ingester/VimeoMediaIngester.php | 77 ++++++++++++++++ src/Media/Renderer/VimeoMediaRenderer.php | 22 +++++ src/Service/BlockLayout/VimeoFactory.php | 18 ++++ .../Media/Ingester/VimeoMediaFactory.php | 19 ++++ src/Site/BlockLayout/Vimeo.php | 90 +++++++++++++++++++ view/common/block-layout/vimeo.phtml | 26 ++++++ 13 files changed, 422 insertions(+) create mode 100644 LICENSE create mode 100644 Module.php create mode 100644 README.md create mode 100644 asset/css/archiveOrg.css create mode 100644 config/module.config.php create mode 100644 config/module.ini create mode 100644 src/Form/VimeoBlockForm.php create mode 100644 src/Media/Ingester/VimeoMediaIngester.php create mode 100644 src/Media/Renderer/VimeoMediaRenderer.php create mode 100644 src/Service/BlockLayout/VimeoFactory.php create mode 100644 src/Service/Media/Ingester/VimeoMediaFactory.php create mode 100644 src/Site/BlockLayout/Vimeo.php create mode 100644 view/common/block-layout/vimeo.phtml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9bd6b00 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/Module.php b/Module.php new file mode 100644 index 0000000..fdc8b84 --- /dev/null +++ b/Module.php @@ -0,0 +1,22 @@ + '16:9', + '1.333' => '4:3', + '2' => '2:1', + ]; + + public function getConfig() + { + return include __DIR__ . '/config/module.config.php'; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..2c0445d --- /dev/null +++ b/README.md @@ -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 + + diff --git a/asset/css/archiveOrg.css b/asset/css/archiveOrg.css new file mode 100644 index 0000000..59c4481 --- /dev/null +++ b/asset/css/archiveOrg.css @@ -0,0 +1,7 @@ +/* Panaorama viewer custom */ +@media screen { + .archive_org { + /* width: 600px; */ + /* height: 400px; */ + } +} diff --git a/config/module.config.php b/config/module.config.php new file mode 100644 index 0000000..bcbfe61 --- /dev/null +++ b/config/module.config.php @@ -0,0 +1,39 @@ + [ + '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;', + ] + ] +]; diff --git a/config/module.ini b/config/module.ini new file mode 100644 index 0000000..e9c76b6 --- /dev/null +++ b/config/module.ini @@ -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" diff --git a/src/Form/VimeoBlockForm.php b/src/Form/VimeoBlockForm.php new file mode 100644 index 0000000..939d878 --- /dev/null +++ b/src/Form/VimeoBlockForm.php @@ -0,0 +1,44 @@ +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', + ] + ]); + + } +} diff --git a/src/Media/Ingester/VimeoMediaIngester.php b/src/Media/Ingester/VimeoMediaIngester.php new file mode 100644 index 0000000..80a7b14 --- /dev/null +++ b/src/Media/Ingester/VimeoMediaIngester.php @@ -0,0 +1,77 @@ +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)); + } +} diff --git a/src/Media/Renderer/VimeoMediaRenderer.php b/src/Media/Renderer/VimeoMediaRenderer.php new file mode 100644 index 0000000..017b08e --- /dev/null +++ b/src/Media/Renderer/VimeoMediaRenderer.php @@ -0,0 +1,22 @@ +mediaData()['html']; + } + public function thumbnailUrl(PhpRenderer $view, + MediaRepresentation $media, + array $options = []) + { + return $media->mediaData()['thumbnail_url']; + } +} diff --git a/src/Service/BlockLayout/VimeoFactory.php b/src/Service/BlockLayout/VimeoFactory.php new file mode 100644 index 0000000..2c425f6 --- /dev/null +++ b/src/Service/BlockLayout/VimeoFactory.php @@ -0,0 +1,18 @@ +get('FormElementManager'), + $services->get('Config')['DefaultSettings']['VimeoBlockForm'] + ); + } +} +?> \ No newline at end of file diff --git a/src/Service/Media/Ingester/VimeoMediaFactory.php b/src/Service/Media/Ingester/VimeoMediaFactory.php new file mode 100644 index 0000000..81da823 --- /dev/null +++ b/src/Service/Media/Ingester/VimeoMediaFactory.php @@ -0,0 +1,19 @@ +get('Omeka\HttpClient'), + $services->get('Omeka\File\Downloader') + ); + } +} diff --git a/src/Site/BlockLayout/Vimeo.php b/src/Site/BlockLayout/Vimeo.php new file mode 100644 index 0000000..70f9477 --- /dev/null +++ b/src/Site/BlockLayout/Vimeo.php @@ -0,0 +1,90 @@ +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 .= '

'; + $html .= $view->translate('Options'). '

'; + $html .= '
'; + $html .= $view->formCollection($form); + $html .= '
'; + 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'], + ]); + } +} diff --git a/view/common/block-layout/vimeo.phtml b/view/common/block-layout/vimeo.phtml new file mode 100644 index 0000000..9c11fa4 --- /dev/null +++ b/view/common/block-layout/vimeo.phtml @@ -0,0 +1,26 @@ +
+ + + + + + + + +
+ +
+ + +
+ + +