first commit

This commit is contained in:
Chris 2021-08-10 13:32:24 +02:00
commit 5b1f1a0239
9 changed files with 335 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.

29
Module.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace PDFLink;
use Omeka\Module\AbstractModule;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\MvcEvent;
class Module extends AbstractModule
{
const NAMESPACE = __NAMESPACE__;
const IMAGE_WIDTH = [
'25' => '25 %',
'50' => '50 %',
'75' => '75 %',
'100' => '100 %',
];
const ZOOM_TYPE = [
'' => '',
'zoom' => 'Touch / grab',
'wheelzoom' => 'Deep zooming',
];
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}

20
README.md Normal file
View File

@ -0,0 +1,20 @@
# PDFLink media for Omeka S
[PDFLink] is a module for [Omeka S] that adds PDF links with description text.
## Install
```
cd ./modules
https://git.hangar.org/arcHIVE-tech/PDFLink/archive/main.zip
unzip main.zip
mv pdflink-omeka-module/ PDFLink
rm main.zip
```
## LISENCE
The module is released under the [MIT] License.
[Omeka S]: https://omeka.org/s
[PDFLink]: https://git.hangar.org/arcHIVE-tech/PDFLink
[MIT]: http://opensource.org/licenses/MIT

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

@ -0,0 +1,29 @@
<?php
namespace PDFLink;
return [
'view_manager' => [
'template_path_stack' => [
dirname(__DIR__) . '/view',
]
],
'block_layouts' => [
'factories' => [
'pDFLink' => Service\BlockLayout\PDFLinkFactory::class,
],
],
'form_elements' => [
'invokables' => [
Form\PDFLinkBlockForm::class => Form\PDFLinkBlockForm::class,
],
],
'DefaultSettings' => [
'PDFLinkBlockForm' => [
'title' => '',
'renderSourceLink' => true,
'width' => 600,
'zoom_type' => '',
'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 = "Image viewer"
description = "View and optionally zoom images"
tags = ""
license = "MIT"
author = "Hangar.org"
author_link = "https://git.hangar.org/chris"
module_link = "https://git.hangar.org/arcHIVE-tech/PDFLink"
support_link = "https://git.hangar.org/arcHIVE-tech/PDFLink/issues"
configurable = false
version = "1.0.0"
omeka_version_constraint = "^3.0.1"

View File

@ -0,0 +1,50 @@
<?php
namespace PDFLink\Form;
use PDFLink\Module;
use Laminas\Form\Element;
use Laminas\Form\Form;
class PDFLinkBlockForm extends Form
{
public function init()
{
$this->add([
'name' => 'o:block[__blockIndex__][o:data][width]',
'type' => Element\Select::class,
'options' => [
'label' => 'Width',
'value_options' => Module::IMAGE_WIDTH,
],
]);
$this->add([
'name' => 'o:block[__blockIndex__][o:data][zoom_type]',
'type' => Element\Select::class,
'options' => [
'label' => 'Zooming',
'value_options' => Module::ZOOM_TYPE,
],
]);
$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,18 @@
<?php
namespace PDFLink\Service\BlockLayout;
use Interop\Container\ContainerInterface;
use PDFLink\Site\BlockLayout\PDFLink;
use Laminas\ServiceManager\Factory\FactoryInterface;
class PDFLinkFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
return new PDFLink(
$services->get('FormElementManager'),
$services->get('Config')['DefaultSettings']['PDFLinkBlockForm']
);
}
}
?>

View File

@ -0,0 +1,88 @@
<?php
namespace PDFLink\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 PDFLink\Form\PDFLinkBlockForm;
class PDFLink 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 'Image viewer';
}
public function form(PhpRenderer $view,
SiteRepresentation $site,
SitePageRepresentation $page = null,
SitePageBlockRepresentation $block = null
) {
$form = $this->formElementManager->get(PDFLinkBlockForm::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][zoom_type]' => $data['zoom_type'],
'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];
return $view->partial('common/block-layout/pDFLink', [
'zoom_type' => $block->dataValue('zoom_type'),
'title' => $block->dataValue('title'),
'item_url' => $attachments[0]->item()->url(),
'renderSourceLink' => $block->dataValue('renderSourceLink'),
'width' => $block->dataValue('width'),
'image' => $media->primaryMedia()->thumbnailUrl('large'),
'id' => 'iv-' . ++$id,
]);
}
}

View File

@ -0,0 +1,68 @@
<?php
if ($zoom_type == "wheelzoom") {
$this->headScript()->appendFile($this->assetUrl('vendor/wheelzoom/wheelzoom.js',
'PDFLink'));
}
if ($zoom_type == "zoom") {
$this->headScript()->appendFile($this->assetUrl('vendor/zoom/jquery.zoom.min.js',
'PDFLink'));
}
if ($zoom_type == "zoom" || $zoom_type == "wheelzoom") {
$this->headLink()->appendStylesheet($this->assetUrl('css/zoom.css',
'PDFLink'));
}
?>
<?php if ($renderSourceLink) { ?>
<div class="source-link">
<a href="<?= $item_url ?>">Source</a>
</div>
<?php } ?>
<?php if ($zoom_type == "zoom") { ?>
<div id='<?= $id ?>' class='zoom' style='width:<?= $width ?>%; cursor:grab'>
<img src='<?= $image ?>' alt='<?= $title ?>'/>
</div>
<?php } ?>
<?php if ($zoom_type == "wheelzoom") { ?>
<div class='zoom' style='display:block; width:<?= $width ?>%; cursor:crosshair'>
<img id="<?= $id ?>" src="<?= $image ?>" />
</div>
<?php } ?>
<?php if ($zoom_type == "") { ?>
<div class="archive-img">
<img id="<?= $id ?>"
style="width: <?= $width ?>%;"
src="<?= $image ?>"
/>
</div>
<?php } ?>
<?php if ($title) { ?>
<div class="item_title">
<?= $title ?>
</div>
<?php } ?>
<?php if ($zoom_type == "zoom") { ?>
<script>
$(document).ready(function(){
$('#<?= $id ?>').zoom({on:'grab', 'duration': 200, 'magnify': 1.5});
});
</script>
<?php } ?>
<?php if ($zoom_type == "wheelzoom") { ?>
<script>
$(document).ready(function(){
wheelzoom(document.querySelector('#<?= $id ?>'));
});
</script>
<?php } ?>