changes module name and namespace

This commit is contained in:
buttle 2021-05-04 10:55:27 +02:00
commit 143c17a134
12 changed files with 734 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.

131
Module.php Normal file
View File

@ -0,0 +1,131 @@
<?php
namespace ArchiveSiteMeta;
use ArchiveSiteMeta\Form\ConfigForm;
use Omeka\Module\AbstractModule;
use Laminas\EventManager\Event;
use Laminas\View\Renderer\PhpRenderer;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\MvcEvent;
use Laminas\Mvc\Controller\AbstractController;
use Omeka\Mvc\Controller\Plugin\Messenger;
class Module extends AbstractModule
{
const NAMESPACE = __NAMESPACE__;
const PAGE_LAYOUT = [
'standard' => 'Standard',
'exhibition' => 'Exhibition',
];
const PAGE_TYPE = [
'' => '',
'exhibit' => 'Exhibitions',
];
/*
public function attachListeners(SharedEventManagerInterface $sharedEventManager): void
{
$sharedEventManager->attach(
\Omeka\Api\Adapter\ItemAdapter::class,
'api.create.post',
[$this, 'afterSaveItem'],
100
);
$sharedEventManager->attach(
\Omeka\Api\Adapter\ItemAdapter::class,
'api.update.post',
[$this, 'afterSaveItem'],
100
);
$sharedEventManager->attach(
\Omeka\Api\Adapter\ItemAdapter::class,
'api.delete.post',
[$this, 'afterDeleteItem'],
100
);
}
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getConfigForm(PhpRenderer $renderer)
{
$services = $this->getServiceLocator();
$config = $services->get('Config');
$settings = $services->get('Omeka\Settings');
$form = $services->get('FormElementManager')->get(ConfigForm::class);
$data = [];
$defaultSettings = $config['config']['SiteMeta'];
foreach ($defaultSettings as $name => $value) {
$data[$name] = $settings->get($name, $value);
}
$form->init();
$form->setData($data);
$html = $renderer->render('module/config', [
'form' => $form,
]);
return $html;
}
public function handleConfigForm(AbstractController $controller)
{
//return true;
//if (!parent::handleConfigForm($controller)) {
// return false;
//}
//$services = $this->getServiceLocator();
//$settings = $services->get('Omeka\Settings');
//$a=$b;
$config = $this->getConfig();
#print_r($config);
$encodedString = json_encode($config);
file_put_contents('/tmp/json_array.txt', $encodedString);
var_dump($encodedString);
$space = strtolower(static::NAMESPACE);
if (empty($config['config']['SiteMeta'])) {
return true;
}
$services = $this->getServiceLocator();
$formManager = $services->get('FormElementManager');
$formClass = static::NAMESPACE . '\Form\ConfigForm';
if (!$formManager->has($formClass)) {
return true;
}
$params = $controller->getRequest()->getPost();
$form = $formManager->get($formClass);
$form->init();
$form->setData($params);
if (!$form->isValid()) {
$controller->messenger()->addErrors($form->getMessages());
return false;
}
$params = $form->getData();
$settings = $services->get('Omeka\Settings');
$defaultSettings = $config['config']['SiteMeta'];
//$defaultSettings = $config[$space]['config'];
$params = array_intersect_key($params, $defaultSettings);
foreach ($params as $name => $value) {
$settings->set($name, $value);
}
return true;
}
}

23
README.md Normal file
View File

@ -0,0 +1,23 @@
# Meta Site data for Omeka S
This module acompanies and is required by the Archive omeka theme
## Install
```
cd ./modules
https://git.hangar.org/arcHIVE-tech/ArchiveSiteMeta/archive/main.zip
unzip main.zip
mv imageviewer/ ArchiveSiteMeta
rm main.zip
```
## LISENCE
The module is released under the [MIT] License.
[arc-hive]: https://arc-hive.zone/
[wheelzoom]: https://github.com/jackmoore/wheelzoom
[zoom]: https://github.com/jackmoore/zoom
[Omeka S]: https://omeka.org/s
[ArchiveSiteMeta]: https://git.hangar.org/arcHIVE-tech/ArchiveSiteMeta
[MIT]: http://opensource.org/licenses/MIT

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

@ -0,0 +1,46 @@
<?php
namespace ArchiveSiteMeta;
return [
'view_manager' => [
'template_path_stack' => [
dirname(__DIR__) . '/view',
],
'template_map' => [
'omeka/index/index' => __DIR__ . '/../../../themes/archive/view/omeka/site/index.phtml',
],
],
'view_helpers' => [
'invokables' => [
'archiveSiteMeta' => View\Helper\ArchiveSiteMeta::class,
'siteCollections' => View\Helper\SiteCollections::class,
],
],
'block_layouts' => [
'factories' => [
'archiveSiteMeta' => Service\BlockLayout\ArchiveSiteMetaFactory::class,
],
],
'form_elements' => [
'invokables' => [
Form\ArchiveSiteMetaBlockForm::class => Form\ArchiveSiteMetaBlockForm::class,
],
'factories' => [
Form\ConfigForm::class => Service\Form\ConfigFormFactory::class,
],
],
'config' => [
'SiteMeta' => [
'sitemeta_collections' => '',
],
],
'DefaultSettings' => [
'ArchiveSiteMetaBlockForm' => [
'page_type' => 'home',
'currator' => '',
'project_date' => '',
'collection' => '',
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',
],
]
];

13
config/module.ini Normal file
View File

@ -0,0 +1,13 @@
[info]
name = "Archove site meta"
description = "Add some meta vaule to pages"
tags = ""
license = "MIT"
author = "Hangar.org"
author_link = "https://git.hangar.org/chris"
module_link = "https://git.hangar.org/arcHIVE-tech/ArchiveSiteMeta"
support_link = "https://git.hangar.org/arcHIVE-tech/ArchiveSiteMeta/issues"
configurable = false
configurable = true
version = "1.0.0"
omeka_version_constraint = "^3.0.1"

View File

@ -0,0 +1,32 @@
<?php
namespace ArchiveSiteMeta\Form;
use ArchiveSiteMeta\Module;
use Laminas\Form\Element;
use Laminas\Form\Form;
class ArchiveSiteMetaBlockForm extends Form
{
public function init()
{
$this->add([
'name' => 'o:block[__blockIndex__][o:data][currator]',
'type' => Element\Text::class,
'options' => [
'label' => "Currator",
],
]);
$this->add([
'type' => Element\Date::class,
'name' => 'o:block[__blockIndex__][o:data][project_date]',
'options' => [
'label' => 'Project Date',
'format' => 'Y-m-d',
],
]);
}
}

195
src/Form/ConfigForm.php Normal file
View File

@ -0,0 +1,195 @@
<?php declare(strict_types=1);
namespace ArchiveSiteMeta\Form;
use ArchiveSiteMeta\Helpers;
use Laminas\Form\Element;
use Laminas\Form\Element\Text;
use Laminas\Form\Form;
use Laminas\I18n\Translator\TranslatorAwareInterface;
use Laminas\I18n\Translator\TranslatorAwareTrait;
use Omeka\Form\Element\PropertySelect;
class ConfigForm extends Form implements TranslatorAwareInterface
{
use TranslatorAwareTrait;
public function setSettings($settings): void
{
$this->settings = $settings;
}
public function getSettings()
{
return $this->siteSettings;
}
protected function getSetting($name)
{
return $this->settings->get($name);
}
public function init(): void
{
$this->add([
'name' => 'sitemeta_collections',
'type' => Element\Textarea::class,
'options' => [
'label' => "Collections",
],
]);
}
/*
$this->add([
'name' => 'archiverepertory_item_set_folder',
'type' => PropertySelect::class,
'options' => [
'label' => 'Item set folder', // @translate
'empty_option' => 'Dont add folder', // @translate
'prepend_value_options' => [
'id' => 'Internal numeric id of the resource', // @translate
],
],
'attributes' => [
'class' => 'chosen-select',
'data-placeholder' => 'Select a property', // @translate
],
]);
*/
/*
$this->add([
'name' => 'archiverepertory_item_set_prefix',
'type' => Text::class,
'options' => [
'label' => 'Prefix for item sets', // @translate
'info' => $this->translate('Choose a prefix, for example "item:", "record:" or "doc:", to select the appropriate metadata when they are multiple.') // @translate
. ' ' . $this->translate('Let empty to use simply the first one.'), // @translate
],
]);
*/
/*
$this->add(
$this->getRadioForConversion('archiverepertory_item_set_convert',
$this->translate('Convert item set names')) // @translate
);
*/
/*
$this->add([
'name' => 'archiverepertory_item_folder',
'type' => PropertySelect::class,
'options' => [
'label' => 'Item folder', // @translate
'empty_option' => 'Dont add folder', // @translate
'prepend_value_options' => [
'id' => 'Internal numeric id of the resource', // @translate
],
],
'attributes' => [
'class' => 'chosen-select',
'data-placeholder' => 'Select a property', // @translate
],
]);
*/
/*
$this->add([
'name' => 'archiverepertory_item_prefix',
'type' => Text::class,
'options' => [
'label' => 'Prefix for items',
'info' => $this->translate('Choose a prefix, for example "item:", "record:" or "doc:", to select the appropriate metadata when they are multiple.') // @translate
. ' ' . $this->translate('Let empty to use simply the first one.'), // @translate
],
]);
*/
/*
$this->add(
$this->getRadioForConversion('archiverepertory_item_convert',
$this->translate('Convert item names')) // @translate
);
*/
/*
$radios = $this->getRadioForConversion('archiverepertory_media_convert',
$this->translate('Convert file names')); // @translate
$valueOptions = $radios->getValueOptions();
$valueOptions['hash'] = $this->translate('Hash filename (default Omeka)'); // @translate
$radios->setValueOptions($valueOptions);
$this->add($radios);
*/
/*
$inputFilter = $this->getInputFilter();
$inputFilter->add([
'name' => 'archiverepertory_item_set_folder',
'required' => false,
]);
$inputFilter->add([
'name' => 'archiverepertory_item_set_prefix',
'required' => false,
]);
$inputFilter->add([
'name' => 'archiverepertory_item_set_convert',
'required' => false,
]);
$inputFilter->add([
'name' => 'archiverepertory_item_folder',
'required' => false,
]);
$inputFilter->add([
'name' => 'archiverepertory_item_prefix',
'required' => false,
]);
$inputFilter->add([
'name' => 'archiverepertory_item_convert',
'required' => false,
]);
$inputFilter->add([
'name' => 'archiverepertory_media_convert',
'required' => false,
]);
}
protected function getSetting($name)
{
return $this->settings->get($name);
}
/*
protected function translate($args)
{
$translator = $this->getTranslator();
return $translator->translate($args);
}
*/
/*
protected function getRadioForConversion($name, $label)
{
$allow_unicode = Helpers::checkUnicodeInstallation();
$info = $this->translate('Depending on your server and your needs, to avoid some potential issues, you can choose or not to rename every folder to its Ascii equivalent (or only the first letter).') // @translate
. ' ' . $this->translate('In all cases, names are sanitized: "/", "\", "|" and other special characters are removed.'); // @translate
$radio = new Element\Radio($name);
$radio->setLabel($label);
$radio->setOptions(['info' => $info]);
$radio->setValue($this->getSetting($name));
$not_recommended = isset($allow_unicode['ascii'])
? ' ' . $this->translate('(not recommended because your server is not fully compatible with Unicode)') // @translate
: '';
$recommended = (isset($allow_unicode['cli']) || isset($allow_unicode['fs']))
? ' ' . $this->translate('(recommended because your server is not fully compatible with Unicode)') // @translate
: '';
$radio->setValueOptions([
'keep' => $this->translate('Keep name as it') . $not_recommended, // @translate
'spaces' => $this->translate('Convert spaces to underscores'), // @translate
'first letter' => $this->translate('Convert first letter only'), // @translate
'first and spaces' => $this->translate('Convert first letter and spaces'), // @translate
'full' => $this->translate('Full conversion to Ascii.') . $recommended, // @translate
]);
return $radio;
}
*/
}

View File

@ -0,0 +1,24 @@
<?php
namespace ArchiveSiteMeta\Service\BlockLayout;
use Interop\Container\ContainerInterface;
use ArchiveSiteMeta\Site\BlockLayout\ArchiveSiteMeta;
use Laminas\ServiceManager\Factory\FactoryInterface;
class ArchiveSiteMetaFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
$settings = $services->get('Omeka\Settings');
//$defaultSettings['collections'] = $settings->get('sitemeta_collections');
return new ArchiveSiteMeta(
$services->get('FormElementManager'),
$services->get('Config')['DefaultSettings']['ArchiveSiteMetaBlockForm'],
$settings->get('sitemeta_collections'),
//$services->get('Config')['DefaultSettings']['ArchiveSiteMetaBlockForm'],
//$settings->get('sitemeta_collections')
);
}
}
?>

View File

@ -0,0 +1,28 @@
<?php declare(strict_types=1);
namespace ArchiveSiteMeta\Service\Form;
use ArchiveSiteMeta\Form\ConfigForm;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
class ConfigFormFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
//$basePath = $services->get('Config')['file_store']['local']['base_path'] ?: (OMEKA_PATH . '/files');
$settings = $services->get('Omeka\Settings');
//$a = $settings["sitemeta_collections"];
//array_push($options, $a);
//$translator = $services->get('MvcTranslator');
$form = new ConfigForm(null, $options);
//$form->setLocalStorage($basePath);
$form->setSettings($settings);
//$form->setTranslator($translator);
return $form;
}
}

View File

@ -0,0 +1,100 @@
<?php
namespace ArchiveSiteMeta\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\Element;
use Laminas\Form\FormElementManager;
use ArchiveSiteMeta\Form\ArchiveSiteMetaBlockForm;
class ArchiveSiteMeta extends AbstractBlockLayout
{
/**
* @var FormElementManager
*/
protected $formElementManager;
/**
* @var array
*/
protected $defaultSettings = [];
protected $sitemeta_collections = "ff";
/**
* @param FormElementManager $formElementManager
* @param array $defaultSettings
*/
public function __construct(FormElementManager $formElementManager,
array $defaultSettings,
string $sitemeta_collections)
{
$this->formElementManager = $formElementManager;
$this->defaultSettings = $defaultSettings;
$this->sitemeta_collections = $sitemeta_collections;
}
public function getLabel() {
return 'Archive site meta';
}
public function form(PhpRenderer $view,
SiteRepresentation $site,
SitePageRepresentation $page = null,
SitePageBlockRepresentation $block = null
) {
$form = $this->formElementManager->get(ArchiveSiteMetaBlockForm::class);
$collection_options = [];
foreach ( explode("\n", $this->sitemeta_collections) as $value ) {
$key_value = explode("=", $value);
$collection_options[$key_value[1]] = $key_value[0];
}
$form->add([
'name' => 'o:block[__blockIndex__][o:data][collection]',
'type' => Element\Select::class,
'options' => [
'label' => "Collections",
'value_options' => $collection_options,
],
]);
$data = $block
? $block->data() + $this->defaultSettings
: $this->defaultSettings;
$form->setData([
'o:block[__blockIndex__][o:data][currator]' => $data['currator'],
'o:block[__blockIndex__][o:data][project_date]' => $data['project_date'],
'o:block[__blockIndex__][o:data][collection]' => $data['collection'],
]);
$form->prepare();
//$form->collections = $this->sitemeta_collections;
$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)
{
/*
$controller->layout()->setVariable(
'content',
$this->viewRenderer->render('my/email/view_script.phtml');
);
*/
return "";
}
}

View File

@ -0,0 +1,93 @@
<?php declare(strict_types=1);
namespace ArchiveSiteMeta\View\Helper;
use Laminas\View\Helper\AbstractHelper;
#use ArchiveSiteMeta\Service\Form\ConfigFormFactory;
/**
* View helper to get metadata for all pages of the specified type.
*/
class ArchiveSiteMeta extends AbstractHelper
{
/**
* Get data for all pages of the specified type in the current site.
*
* @param string|array $pageType
* @return \Omeka\Api\Representation\SitePageBlockRepresentation[]
*/
//public function __invoke($pageType)
public function getSiteMetaValues($site)
{
// Check if the site page has the specified block.
//$site = $this->currentSite();
$pages = $site->pages();
foreach ($pages as $page) {
foreach ($page->blocks() as $block) {
// A page can belong to multiple types…
if ($block->layout() === 'archiveSiteMeta') {
$url = null;
$attachments = $block->attachments();
if ($attachments) {
$media = $attachments[0]->item()->media()[0];
$url = $media->primaryMedia()->thumbnailUrl('large');
}
return array(
"currator" => $block->dataValue('currator'),
"thumbnail" => $url,
'project_date' => $block->dataValue('project_date'),
'collection' => $block->dataValue('collection'),
);
}
}
}
return null;
}
public function getCollections($sites){
$collections = [];
foreach ($sites as $site) {
$settings = $this->getSiteMetaValues($site);
if ($settings && !in_array($settings['collection'], $collections)) {
array_push($collections, $settings['collection']);
}
}
return $collections;
}
public function getPages()
{
return [];
}
/**
* Get the page's meta image url.
*
* @param SitePageRepresentation
* @return string media url
*/
public function getPageImage($page)
{
foreach ($page->blocks() as $block) {
if ($block->layout() === 'archiveSiteMeta') {
$attachments = $block->attachments();
if (!$attachments) {
return null;
}
$media = $attachments[0]->item()->media()[0];
return $media->primaryMedia()->thumbnailUrl('large');
}
}
return null;
}
/**
* @return \Omeka\Api\Representation\SiteRepresentation
*/
protected function currentSite()
{
$view = $this->getView();
return isset($view->site)
? $view->site
: $view->getHelperPluginManager()->get('Laminas\View\Helper\ViewModel')->getRoot()->getVariable('site');
}
}

28
view/module/config.phtml Normal file
View File

@ -0,0 +1,28 @@
<?php declare(strict_types=1);
/**
* @var \Laminas\View\Renderer\PhpRenderer $this
* @var \ArchiveRepertory\Form\ConfigForm $form
*/
$translate = $this->plugin('translate');
?>
<?php $this->headStyle()->appendStyle('.inputs label { display: block; }'); ?>
<?php $form->prepare(); ?>
<fieldset id="fieldset-item-sets">
<?php echo $this->formRow($form->get('sitemeta_collections')); ?>
</fieldset>
<fieldset id="fieldset-items">
</fieldset>
<fieldset id="fieldset-files">
</fieldset>
<?php echo $this->formRow($form->get('csrf')); ?>