Compare commits

..

2 Commits

Author SHA1 Message Date
buttle f633eeb529 adds item source link and item subtitile 2021-06-27 12:38:19 +02:00
buttle 191087a1e4 adds media thumbnail 2021-06-27 12:25:47 +02:00
6 changed files with 55 additions and 11 deletions

View File

@ -30,6 +30,7 @@ return [
'DefaultSettings' => [ 'DefaultSettings' => [
'SketchfabBlockForm' => [ 'SketchfabBlockForm' => [
'title' => '', 'title' => '',
'renderSourceLink' => true,
'width' => 600, 'width' => 600,
'ratio' => '2', 'ratio' => '2',
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;', 'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',

View File

@ -29,5 +29,24 @@ class SketchfabBlockForm extends Form
], ],
]); ]);
$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

@ -5,16 +5,24 @@ use Omeka\Api\Request;
use Omeka\Entity\Media; use Omeka\Entity\Media;
use Omeka\Media\Ingester\IngesterInterface; use Omeka\Media\Ingester\IngesterInterface;
use Omeka\Stdlib\ErrorStore; use Omeka\Stdlib\ErrorStore;
use Omeka\File\Downloader;
use Zend\Form\Element\Text; use Zend\Form\Element\Text;
use Zend\Http\Client; use Zend\Http\Client;
use Zend\View\Renderer\PhpRenderer; use Zend\View\Renderer\PhpRenderer;
class SketchfabMediaIngester implements IngesterInterface class SketchfabMediaIngester implements IngesterInterface
{ {
/**
* @var Downloader
*/
protected $downloader;
protected $client; protected $client;
public function __construct($client)
public function __construct($client, Downloader $downloader)
{ {
$this->client = $client; $this->client = $client;
$this->downloader = $downloader;
} }
public function getLabel() public function getLabel()
{ {
@ -54,8 +62,14 @@ class SketchfabMediaIngester implements IngesterInterface
)); ));
return false; 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. // Set the Media source and data.
$media->setSource($data['o:source']); $media->setSource($data['o:source']);
$media->setData(json_decode($response->getBody(), true));; $media->setData($response_body, true));
} }
} }

View File

@ -11,6 +11,9 @@ class SketchfabMediaFactory implements FactoryInterface
$requestedName, $requestedName,
array $options = null) array $options = null)
{ {
return new SketchfabMediaIngester($services->get('Omeka\HttpClient')); return new SketchfabMediaIngester(
$services->get('Omeka\HttpClient'),
$services->get('Omeka\File\Downloader')
);
} }
} }

View File

@ -50,6 +50,7 @@ class Sketchfab extends AbstractBlockLayout
'o:block[__blockIndex__][o:data][title]' => $data['title'], 'o:block[__blockIndex__][o:data][title]' => $data['title'],
'o:block[__blockIndex__][o:data][width]' => $data['width'], 'o:block[__blockIndex__][o:data][width]' => $data['width'],
'o:block[__blockIndex__][o:data][ratio]' => $data['ratio'], 'o:block[__blockIndex__][o:data][ratio]' => $data['ratio'],
'o:block[__blockIndex__][o:data][renderSourceLink]' => $data['renderSourceLink'],
]); ]);
$form->prepare(); $form->prepare();
@ -78,7 +79,9 @@ class Sketchfab extends AbstractBlockLayout
//$height = $width / $block->dataValue('ratio'); //$height = $width / $block->dataValue('ratio');
$height = $width / 1.333; $height = $width / 1.333;
return $view->partial('common/block-layout/sketchfab', [ return $view->partial('common/block-layout/sketchfab', [
'title' => false, 'title' => $block->dataValue('title'),
'renderSourceLink' => $block->dataValue('renderSourceLink'),
'item_url' => $attachments[0]->item()->url(),
'width' => $width, 'width' => $width,
'height' => $height, 'height' => $height,
'sketchfab_iframe' => $media->mediaData()['html'], 'sketchfab_iframe' => $media->mediaData()['html'],

View File

@ -1,15 +1,19 @@
<div class="sketchfab-wrap" style="position:relative;"> <div class="sketchfab-wrap" style="position:relative;">
<?php <?php if ($renderSourceLink) { ?>
if ($title !== false && $title !== "") { <div class="source-link">
$title = sprintf('<p id="sketchfab-title">%s</p>', $title); <a href="<?= $item_url ?>">Source</a>
} else { </div>
$title = false; <?php } ?>
}
?>
<?= $sketchfab_iframe ?> <?= $sketchfab_iframe ?>
<?php if ($title) { ?>
<div class="item_title">
<?= $title ?>
</div>
<?php } ?>
</div> </div>