First commit

This commit is contained in:
buttle 2021-06-22 10:19:26 +02:00
commit d9292e49a9
13 changed files with 413 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.

28
Module.php Normal file
View File

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

29
README.md Normal file
View File

@ -0,0 +1,29 @@
# Archive.org media for Omeka S
[Sketchfab] is a module for [Omeka S] that integrates Sketchfab
3D models.
## Install
```
cd ./modules
https://git.hangar.org/arcHIVE-tech/Sketchfab/archive/main.zip
unzip main.zip
mv archiveorg/ Sketchfab
rm main.zip
```
## LISENCE
The module is released under the [MIT] License.
[arc-hive]: https://arc-hive.zone/
[Archive.org media ]: https://git.hangar.org/arcHIVE-tech/Sketchfab
[Omeka S]: https://omeka.org/s
[Archive.org]: https://archive.org
[MIT]: http://opensource.org/licenses/MIT
## Notes
https://sketchfab.com/developers/oembed

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

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

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

@ -0,0 +1,40 @@
<?php
namespace Sketchfab;
return [
'view_manager' => [
'template_path_stack' => [
dirname(__DIR__) . '/view',
]
],
'block_layouts' => [
'factories' => [
'sketchfab' => Service\BlockLayout\SketchfabFactory::class,
],
],
'form_elements' => [
'invokables' => [
Form\SketchfabBlockForm::class => Form\SketchfabBlockForm::class,
],
],
'media_ingesters' => [
'factories' => [
'Sketchfab_media' => Service\Media\Ingester\SketchfabMediaFactory::class,
],
],
'media_renderers' => [
'invokables' => [
'Sketchfab_media' => Media\Renderer\SketchfabMediaRenderer::class,
],
],
'DefaultSettings' => [
'SketchfabBlockForm' => [
'media_type' => 'video',
'title' => '',
'width' => 600,
'ratio' => '2',
'autoLoad' => false,
'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 = "Archive.org media viewer"
description = "Embed Archive.org media"
tags = ""
license = "MIT"
author = "Hangar.org"
author_link = "https://git.hangar.org/chris"
module_link = "https://git.hangar.org/arcHIVE-tech/Sketchfab"
support_link = "https://git.hangar.org/arcHIVE-tech/Sketchfab/issues"
configurable = false
version = "1.0.0"
omeka_version_constraint = "^3.0.1"

View File

@ -0,0 +1,51 @@
<?php
namespace Sketchfab\Form;
use Sketchfab\Module;
use Laminas\Form\Element;
use Laminas\Form\Form;
class SketchfabBlockForm extends Form
{
public function init()
{
$this->add([
'name' => 'o:block[__blockIndex__][o:data][title]',
'type' => Element\Text::class,
'options' => [
'label' => 'Title (option)',
]
]);
$this->add([
'name' => 'o:block[__blockIndex__][o:data][media_type]',
'type' => Element\Select::class,
'options' => [
'label' => 'Media type',
'value_options' => Module::MEDIA_TYPE,
],
]);
$this->add([
'name' => 'o:block[__blockIndex__][o:data][width]',
'type' => Element\Number::class,
'options' => [
'label' => 'Width in pixels',
],
'attributes' => [
'min' => '100',
],
]);
$this->add([
'name' => 'o:block[__blockIndex__][o:data][ratio]',
'type' => Element\Select::class,
'options' => [
'label' => 'Ratio',
'value_options' => Module::RATIOS,
],
]);
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Sketchfab\Media\Ingester;
use Omeka\Api\Request;
use Omeka\Entity\Media;
use Omeka\Media\Ingester\IngesterInterface;
use Omeka\Stdlib\ErrorStore;
use Zend\Form\Element\Text;
use Zend\Http\Client;
use Zend\View\Renderer\PhpRenderer;
class SketchfabMediaIngester implements IngesterInterface
{
protected $client;
public function __construct($client)
{
$this->client = $client;
}
public function getLabel()
{
return 'Archive.org media'; // @translate
}
public function getRenderer()
{
return 'Sketchfab_media';
}
public function form(PhpRenderer $view, array $options = [])
{
$input = new Text('o:media[__index__][o:identifier]');
$input->setOptions([
'label' => 'Indentifier', // @translate
]);
$input->setAttributes([
'required' => true,
]);
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;
}
$url = 'https://archive.org/embed/' . $data['o:identifier'];
$media->setSource($url);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Sketchfab\Media\Renderer;
use Omeka\Api\Representation\MediaRepresentation;
use Omeka\Media\Renderer\RendererInterface;
use Zend\View\Renderer\PhpRenderer;
class SketchfabMediaRenderer implements RendererInterface
{
public function render(PhpRenderer $view,
MediaRepresentation $media,
array $options = [])
{
$url = $media->source();
$html = '<iframe ';
$html .= 'src="' . $url . '" ';
$html .= 'frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen>';
$html .= '</iframe>';
return $html;
//return $media->mediaData()['html'];
}
}

View File

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

View File

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

View File

@ -0,0 +1,90 @@
<?php
namespace Sketchfab\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 Sketchfab\Form\SketchfabBlockForm;
class Sketchfab 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 'Archive.org media';
}
public function form(PhpRenderer $view,
SiteRepresentation $site,
SitePageRepresentation $page = null,
SitePageBlockRepresentation $block = null
) {
$form = $this->formElementManager->get(SketchfabBlockForm::class);
$data = $block
? $block->data() + $this->defaultSettings
: $this->defaultSettings;
$form->setData([
'o:block[__blockIndex__][o:data][media_type]' => $data['media_type'],
'o:block[__blockIndex__][o:data][title]' => $data['title'],
'o:block[__blockIndex__][o:data][width]' => $data['width'],
'o:block[__blockIndex__][o:data][ratio]' => $data['ratio'],
]);
$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 = $block->dataValue('width');
$height = $width / $block->dataValue('ratio');
return $view->partial('common/block-layout/archiveOrg', [
'media_type' => $block->dataValue('media_type'),
'title' => $block->dataValue('title'),
'width' => $width,
'height' => $height,
'url' => $media->source(),
'id' => 'achive_org-' . ++$id,
'thumbnails' => $thumbnails,
]);
}
}

View File

@ -0,0 +1,29 @@
<div class="archive_org-wrap" style="position:relative;">
<?php
if ($title !== false && $title !== "") {
$title = sprintf('<p id="achive_org_media-title">%s</p>', $title);
} else {
$title = false;
}
?>
<?php if ($media_type != "audio") { ?>
<style>
#<?= $id ?> {
height: <?= $height ?>px;
width: <?= $width ?>px;
}
</style>
<?php } ?>
<iframe
id="<?= $id ?>"
src="<?= $url ?>"
frameborder="0"
webkitallowfullscreen="true"
mozallowfullscreen="true"
allowfullscreen >
</iframe>
</div>