From 143c17a134241c436fcf2e0c6b24a296960f28eb Mon Sep 17 00:00:00 2001 From: buttle Date: Tue, 4 May 2021 10:55:27 +0200 Subject: [PATCH] changes module name and namespace --- LICENSE | 21 ++ Module.php | 131 ++++++++++++ README.md | 23 +++ config/module.config.php | 46 +++++ config/module.ini | 13 ++ src/Form/ArchiveSiteMetaBlockForm.php | 32 +++ src/Form/ConfigForm.php | 195 ++++++++++++++++++ .../BlockLayout/ArchiveSiteMetaFactory.php | 24 +++ src/Service/Form/ConfigFormFactory.php | 28 +++ src/Site/BlockLayout/ArchiveSiteMeta.php | 100 +++++++++ src/View/Helper/ArchiveSiteMeta.php | 93 +++++++++ view/module/config.phtml | 28 +++ 12 files changed, 734 insertions(+) create mode 100644 LICENSE create mode 100644 Module.php create mode 100644 README.md create mode 100644 config/module.config.php create mode 100644 config/module.ini create mode 100644 src/Form/ArchiveSiteMetaBlockForm.php create mode 100644 src/Form/ConfigForm.php create mode 100644 src/Service/BlockLayout/ArchiveSiteMetaFactory.php create mode 100644 src/Service/Form/ConfigFormFactory.php create mode 100644 src/Site/BlockLayout/ArchiveSiteMeta.php create mode 100644 src/View/Helper/ArchiveSiteMeta.php create mode 100644 view/module/config.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..d562d31 --- /dev/null +++ b/Module.php @@ -0,0 +1,131 @@ + '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; + } + +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ff6219 --- /dev/null +++ b/README.md @@ -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 diff --git a/config/module.config.php b/config/module.config.php new file mode 100644 index 0000000..d55cbf4 --- /dev/null +++ b/config/module.config.php @@ -0,0 +1,46 @@ + [ + '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;', + ], + ] +]; diff --git a/config/module.ini b/config/module.ini new file mode 100644 index 0000000..6a9e855 --- /dev/null +++ b/config/module.ini @@ -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" diff --git a/src/Form/ArchiveSiteMetaBlockForm.php b/src/Form/ArchiveSiteMetaBlockForm.php new file mode 100644 index 0000000..8c468b5 --- /dev/null +++ b/src/Form/ArchiveSiteMetaBlockForm.php @@ -0,0 +1,32 @@ +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', + ], + ]); + + } +} diff --git a/src/Form/ConfigForm.php b/src/Form/ConfigForm.php new file mode 100644 index 0000000..2a01550 --- /dev/null +++ b/src/Form/ConfigForm.php @@ -0,0 +1,195 @@ +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' => 'Don’t 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' => 'Don’t 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; + + } + */ +} diff --git a/src/Service/BlockLayout/ArchiveSiteMetaFactory.php b/src/Service/BlockLayout/ArchiveSiteMetaFactory.php new file mode 100644 index 0000000..c385465 --- /dev/null +++ b/src/Service/BlockLayout/ArchiveSiteMetaFactory.php @@ -0,0 +1,24 @@ +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') + ); + } +} +?> diff --git a/src/Service/Form/ConfigFormFactory.php b/src/Service/Form/ConfigFormFactory.php new file mode 100644 index 0000000..bcc780d --- /dev/null +++ b/src/Service/Form/ConfigFormFactory.php @@ -0,0 +1,28 @@ +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; + } +} diff --git a/src/Site/BlockLayout/ArchiveSiteMeta.php b/src/Site/BlockLayout/ArchiveSiteMeta.php new file mode 100644 index 0000000..e4db9af --- /dev/null +++ b/src/Site/BlockLayout/ArchiveSiteMeta.php @@ -0,0 +1,100 @@ +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 .= '

'; + $html .= $view->translate('Options'). '

'; + $html .= '
'; + $html .= $view->formCollection($form); + $html .= '
'; + return $html; + } + + public function render(PhpRenderer $view, SitePageBlockRepresentation $block) + { + /* + $controller->layout()->setVariable( + 'content', + $this->viewRenderer->render('my/email/view_script.phtml'); + ); + */ + return ""; + } +} diff --git a/src/View/Helper/ArchiveSiteMeta.php b/src/View/Helper/ArchiveSiteMeta.php new file mode 100644 index 0000000..2a484dd --- /dev/null +++ b/src/View/Helper/ArchiveSiteMeta.php @@ -0,0 +1,93 @@ +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'); + } +} diff --git a/view/module/config.phtml b/view/module/config.phtml new file mode 100644 index 0000000..c5d9feb --- /dev/null +++ b/view/module/config.phtml @@ -0,0 +1,28 @@ +plugin('translate'); +?> +headStyle()->appendStyle('.inputs label { display: block; }'); ?> + +prepare(); ?> + + +
+ + +formRow($form->get('sitemeta_collections')); ?> + +
+ +
+ +
+ +
+ +
+ +formRow($form->get('csrf')); ?>