From 6f75d623fee958d0b8ae7944d39354ba1496d25a Mon Sep 17 00:00:00 2001 From: buttle Date: Thu, 2 Sep 2021 13:38:14 +0200 Subject: [PATCH] first commit --- LICENSE | 21 ++++ Module.php | 29 +++++ README.md | 22 ++++ asset/css/archiveOrg.css | 7 ++ asset/js/media_dimensions.js | 15 +++ config/module.config.php | 38 +++++++ config/module.ini | 12 ++ src/Form/ArchiveOembedBlockForm.php | 42 +++++++ .../Ingester/ArchiveOembedMediaIngester.php | 86 ++++++++++++++ .../Renderer/ArchiveOembedMediaRenderer.php | 22 ++++ .../BlockLayout/ArchiveOembedFactory.php | 18 +++ .../Ingester/ArchiveOembedMediaFactory.php | 19 ++++ src/Site/BlockLayout/ArchiveOembed.php | 106 ++++++++++++++++++ view/common/block-layout/archiveOembed.phtml | 27 +++++ 14 files changed, 464 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 asset/js/media_dimensions.js create mode 100644 config/module.config.php create mode 100644 config/module.ini create mode 100644 src/Form/ArchiveOembedBlockForm.php create mode 100644 src/Media/Ingester/ArchiveOembedMediaIngester.php create mode 100644 src/Media/Renderer/ArchiveOembedMediaRenderer.php create mode 100644 src/Service/BlockLayout/ArchiveOembedFactory.php create mode 100644 src/Service/Media/Ingester/ArchiveOembedMediaFactory.php create mode 100644 src/Site/BlockLayout/ArchiveOembed.php create mode 100644 view/common/block-layout/archiveOembed.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..15451a8 --- /dev/null +++ b/Module.php @@ -0,0 +1,29 @@ + '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'; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..070ffd7 --- /dev/null +++ b/README.md @@ -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 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/asset/js/media_dimensions.js b/asset/js/media_dimensions.js new file mode 100644 index 0000000..777143e --- /dev/null +++ b/asset/js/media_dimensions.js @@ -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(); +}); diff --git a/config/module.config.php b/config/module.config.php new file mode 100644 index 0000000..908c4c8 --- /dev/null +++ b/config/module.config.php @@ -0,0 +1,38 @@ + [ + '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;', + ] + ] +]; diff --git a/config/module.ini b/config/module.ini new file mode 100644 index 0000000..33b8fec --- /dev/null +++ b/config/module.ini @@ -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" diff --git a/src/Form/ArchiveOembedBlockForm.php b/src/Form/ArchiveOembedBlockForm.php new file mode 100644 index 0000000..5b1b9a7 --- /dev/null +++ b/src/Form/ArchiveOembedBlockForm.php @@ -0,0 +1,42 @@ +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', + ] + ]); + + } +} diff --git a/src/Media/Ingester/ArchiveOembedMediaIngester.php b/src/Media/Ingester/ArchiveOembedMediaIngester.php new file mode 100644 index 0000000..b3442f2 --- /dev/null +++ b/src/Media/Ingester/ArchiveOembedMediaIngester.php @@ -0,0 +1,86 @@ +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)); + } +} diff --git a/src/Media/Renderer/ArchiveOembedMediaRenderer.php b/src/Media/Renderer/ArchiveOembedMediaRenderer.php new file mode 100644 index 0000000..64de7fe --- /dev/null +++ b/src/Media/Renderer/ArchiveOembedMediaRenderer.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/ArchiveOembedFactory.php b/src/Service/BlockLayout/ArchiveOembedFactory.php new file mode 100644 index 0000000..6a9ec27 --- /dev/null +++ b/src/Service/BlockLayout/ArchiveOembedFactory.php @@ -0,0 +1,18 @@ +get('FormElementManager'), + $services->get('Config')['DefaultSettings']['ArchiveOembedBlockForm'] + ); + } +} +?> \ No newline at end of file diff --git a/src/Service/Media/Ingester/ArchiveOembedMediaFactory.php b/src/Service/Media/Ingester/ArchiveOembedMediaFactory.php new file mode 100644 index 0000000..6cf64ba --- /dev/null +++ b/src/Service/Media/Ingester/ArchiveOembedMediaFactory.php @@ -0,0 +1,19 @@ +get('Omeka\HttpClient'), + $services->get('Omeka\File\Downloader') + ); + } +} diff --git a/src/Site/BlockLayout/ArchiveOembed.php b/src/Site/BlockLayout/ArchiveOembed.php new file mode 100644 index 0000000..2750f19 --- /dev/null +++ b/src/Site/BlockLayout/ArchiveOembed.php @@ -0,0 +1,106 @@ +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 .= '

'; + $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 ''; + } + $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 = ""; + + return $view->partial('common/block-layout/archiveOembed', [ + 'title' => $block->dataValue('title'), + 'renderSourceLink' => $block->dataValue('renderSourceLink'), + 'item_url' => $attachments[0]->item()->url(), + 'archiveOembed_iframe' => $iframe + ]); + } + } diff --git a/view/common/block-layout/archiveOembed.phtml b/view/common/block-layout/archiveOembed.phtml new file mode 100644 index 0000000..cc87114 --- /dev/null +++ b/view/common/block-layout/archiveOembed.phtml @@ -0,0 +1,27 @@ +headScript()->appendFile($this->assetUrl('js/media_dimensions.js', + 'ArchiveOembed')); +?> + +
+ + + + + + + + +
+ +
+ + +
+ +