From cc7cfb8ab19a596f6ec159caa7188c645e0bf174 Mon Sep 17 00:00:00 2001 From: DBinaghi <39097246+DBinaghi@users.noreply.github.com> Date: Tue, 8 Jun 2021 10:51:56 +0200 Subject: [PATCH 001/161] Update files, add config_form --- FacetsPlugin.php | 318 ++++++++++++++++++++++++++++------------------- config_form.php | 153 +++++++++++++++++++++++ plugin.ini | 6 +- 3 files changed, 349 insertions(+), 128 deletions(-) create mode 100644 config_form.php diff --git a/FacetsPlugin.php b/FacetsPlugin.php index 9deef16..30161fe 100644 --- a/FacetsPlugin.php +++ b/FacetsPlugin.php @@ -1,125 +1,193 @@ -addHelperPath(dirname(__FILE__) . '/views/helpers', 'Facets_View_Helper_'); - } - - public function hookPublicHead($args) - { - queue_css_file('facets'); - } - - public function hookDefineRoutes($args) - { - if (is_admin_theme()) { - return; - } - - //Itemtypes browse - $router = $args['router']; - $router->addRoute( - 'facets', - new Zend_Controller_Router_Route( - "facets", - array( - 'module' => 'facets', - 'controller' => 'facets', - 'action' => 'browse' - ) - ) - ); - - } - - /** - * Deal with search terms (advanced search). - * - * Allows to get refinements when a base Dublin Core is used. - * - * @internal This hook is used twice, first to prepare select for the - * current page, second to get the total count. - * - * @internal This should be used, because the filter is not enough for - * requests with a refinable element that should contains something. - * - * @internal MySql 5.5 has a limit: group by is done before order by, and it - * is complex to skirt. - * - * @see DublinCoreExtendedPlugin::filterItemsBrowseParams() - * - * @param Omeka_Db_Select $select - * @param array $params - */ - public function hookItemsBrowseSql($args) - { - $db = $this->_db; - $select = $args['select']; - $params = $args['params']; - - } - - public function hookPublicItemsBrowse($args) - { - $view = $args['view']; - $items = $args['items']; - - // $params = $args['params']; - $itemsArray = array(); - $allItems = get_db()->getTable('Item')->findAll(); - // $allItems = $this->_helper->db->findBy($params); - foreach($allItems as $item){ - $itemsArray[] = $item->id; - } - - // echo get_view()->partial('facets/browse.php',array( - // 'itemsArray' => $itemsArray, - // 'items' => $items - // )); - - echo get_view()->partial('facets/browse.php',array( - 'itemsArray' => $itemsArray - )); - } -} + array() + ); + set_option('facets_elements', json_encode($defaults)); + set_option('facets_item_types', 1); + set_option('facets_collections', 1); + set_option('facets_tags', 0); + } + + /** + * Uninstalls the plugin. + */ + public function hookUninstall() + { + delete_option('facets_public_hook'); + delete_option('facets_description'); + delete_option('facets_hide_single_entries'); + delete_option('facets_sort_order'); + delete_option('facets_elements'); + delete_option('facets_item_types'); + delete_option('facets_collections'); + delete_option('facets_tags'); + } + + /** + * Initialize this plugin. + */ + public function hookInitialize() + { + get_view()->addHelperPath(dirname(__FILE__) . '/views/helpers', 'Facets_View_Helper_'); + + $settings = json_decode(get_option('facets_elements'), true); + $this->_settings = $settings; + } + + /** + * Shows plugin configuration page. + */ + public function hookConfigForm($args) + { + $settings = $this->_settings; + + $table = get_db()->getTable('Element'); + $select = $table->getSelect() + ->where('element_sets.name = \'Dublin Core\'') + ->order('elements.element_set_id') + ->order('ISNULL(elements.order)') + ->order('elements.order'); + $elements = $table->fetchObjects($select); + + include('config_form.php'); + } + + /** + * Handle the config form. + */ + public function hookConfig($args) + { + $post = $args['post']; + + set_option('facets_public_hook', $post['facets_public_hook']); + set_option('facets_description', $post['facets_description']); + set_option('facets_hide_single_entries', $post['facets_hide_single_entries']); + set_option('facets_sort_order', $post['facets_sort_order']); + + $settings = array( + 'item_elements' => isset($post['item_elements']) ? $post['item_elements'] : array() + ); + set_option('facets_elements', json_encode($settings)); + + set_option('facets_item_types', $post['facets_item_types']); + set_option('facets_collections', $post['facets_collections']); + set_option('facets_tags', $post['facets_tags']); + } + + public function hookPublicHead($args) + { + queue_css_file('facets'); + } + + public function hookDefineRoutes($args) + { + if (is_admin_theme()) { + return; + } + + //Itemtypes browse + $router = $args['router']; + $router->addRoute( + 'facets', + new Zend_Controller_Router_Route ( + "facets", + array( + 'module' => 'facets', + 'controller' => 'facets', + 'action' => 'browse' + ) + ) + ); + } + + public function hookPublicItemsBrowse($args) + { + if (get_option('facets_public_hook') == 'public_items_browse') { + self::showFacets($args); + } + } + + public function hookPublicItemsFacets($args) + { + if (get_option('facets_public_hook') == 'public_items_facets') { + self::showFacets($args); + } + } + + public function showFacets($args) + { + $request = Zend_Controller_Front::getInstance()->getRequest(); + $controller = $request->getControllerName(); + $action = $request->getActionName(); + + // checks whether it's one of the facet cases + if (!($controller == 'search' && $action == 'index') && !($controller == 'items' && $action == 'browse')) return; + + $itemsArray = array(); + $params = array('advanced' => $_GET['advanced'], 'collection' => $_GET['collection'], 'type' => $_GET['type'], 'tags' => $_GET['tags']); + $items = get_records('item', $params, null); + + if (count($items) > 0) { + if ($controller == 'items') { + foreach ($items as $item) { + $itemsArray[] = $item->id; + } + echo get_view()->partial('facets/browse.php', array( + 'itemsArray' => $itemsArray + )); + } elseif ($controller == 'search') { + // this would be for the site-wide simple search; + // main problem is that, differently from advanced search, + // it uses its own "search_texts" table, so results from that + // would have to be crossjoined with the "advanced" ones used + // by the facets; + // besides, advanced search works only for Items, so one might + // want to check whether the site-wide search has been performed + // just on Items. + if ($recordTypes = $_GET['record_types']) { + if (count($recordTypes) == 1 && in_array('Item', $recordTypes)) { + // site-wide search was performend just on Items + } + } + } + } + } +} \ No newline at end of file diff --git a/config_form.php b/config_form.php new file mode 100644 index 0000000..3e96e19 --- /dev/null +++ b/config_form.php @@ -0,0 +1,153 @@ + + + +
+ +
+ public_items_browse, already coded into every page (so no change is needed), normally showing up at the end of the page; or the plugin\'s own public_items_facets, that has to be coded into relevant theme pages but can be used wherever deemed right.'); ?>
+
+ +
+ formText('facets_description', get_option('facets_description')); ?> ++ +
+ formCheckbox('facets_hide_single_entries', get_option('facets_hide_single_entries'), null, array('1', '0')); ?> ++ +
+ formRadio('facets_sort_order', + get_option('facets_sort_order'), + null, + array( + 'alpha' => __('Alphabetical'), + 'count_alpha' => __('Count first, then alphabetical'), + )); + ?> ++ +
+| + | + |
|---|---|
| name); ?> | ++ formCheckbox( + "item_elements[{$element->set_name}][{$element->name}]", + '1', + array( + 'disableHidden' => true, + 'checked' => isset($settings['item_elements'][$element->set_name][$element->name]) + ) + ); ?> + | +
+ +
+ formCheckbox('facets_item_types', get_option('facets_item_types'), null, array('1', '0')); ?> ++ +
+ formCheckbox('facets_collections', get_option('facets_collections'), null, array('1', '0')); ?> ++ +
+ formCheckbox('facets_tags', get_option('facets_tags'), null, array('1', '0')); ?> ++ +
+ formCheckbox('facets_hide_popularity', get_option('facets_hide_popularity'), null, array('1', '0')); ?> +public_items_browse, already coded into every page "
+"(so no change is needed), normally showing up at the end of the page; or the plugin's own "
+"public_items_facets, that has to be coded into relevant theme pages but can be used wherever deemed right."
+msgstr ""
+"L'hook che si vuole usare: quello di default di Omeka (public_items_browse), già codificato "
+"in ogni pagina (così nessuna modifica è necessaria), solitamente mostrato alla fine della pagina; oppure, "
+"quello proprio del plugin (public_items_facets), che deve essere codificato nelle giuste "
+"pagine del tema ma può essere usato ovunque lo si ritenga opportuno."
+
+#: config_form.php:32
+msgid "Aspect"
+msgstr "Aspetto"
+
+#: config_form.php:36
+msgid "Description"
+msgstr "Descrizione"
+
+#: config_form.php:40
+msgid "Text to be used as additional description (tip: keep it short)."
+msgstr "Testo da usare come descrizione addizionale (consiglio: mantenerlo corto)."
+
+#: config_form.php:48
+msgid "Hide single entries"
+msgstr "Nascondi valori singoli"
+
+#: config_form.php:52
+msgid "If checked, values with just one entry will not be listed (unless there's less than %s entries in the list)."
+msgstr "Se selezionato, i valori singoli non verranno elencati (a meno che non ci siano meno di %s valori nella lista)."
+
+#: config_form.php:60
+msgid "Sort order"
+msgstr "Direzione ordinamento"
+
+#: config_form.php:64
+msgid "The sorting order for values in select fields."
+msgstr "La direzione di ordinamento per i valori dei campi di selezione."
+
+#: config_form.php:70
+msgid "Alphabetical"
+msgstr "Alfabetico"
+
+#: config_form.php:71
+msgid "Popularity first, then alphabetical"
+msgstr "Prima popolarità, poi alfabetico"
+
+#: config_form.php:79
+msgid "Hide popularity"
+msgstr "Nascondi popolarità"
+
+#: config_form.php:83
+msgid "If checked, values's popularity will not be displayed (sorting order will still take it into consideration, if required)."
+msgstr "Se selezionato, la popolarità dei valori non verrà mostrata (la direzione di ordinamento ne terrà comunque conto, se necessario)."
+
+#: config_form.php:89
+msgid "Elements"
+msgstr "Elementi"
+
+#: config_form.php:97
+msgid "The Dublin Core elements that can be used for search refinement."
+msgstr "Gli elementi Dublin Core che possono essere usati per il raffinamento della ricerca."
+
+#: config_form.php:102
+msgid "Element"
+msgstr "Elemento"
+
+#: config_form.php:103
+msgid "Active"
+msgstr "Attivo"
+
+#: config_form.php:133
+msgid "Item Types"
+msgstr "Tipologie documento"
+
+#: config_form.php:137
+msgid "If checked, search refinement by Item Type will be available."
+msgstr "Se selezionata, il raffinamento della ricerca per Tipologia di Documento sarà disponibile."
+
+#: config_form.php:145
+msgid "Collections"
+msgstr "Collezioni"
+
+#: config_form.php:149
+msgid "If checked, search refinement by Collection will be available."
+msgstr "Se selezionata, il raffinamento della ricerca per Collezione sarà disponibile."
+
+#: config_form.php:157
+msgid "Tags"
+msgstr "Etichette"
+
+#: config_form.php:161
+msgid "If checked, search refinement by Tag will be available."
+msgstr "Se selezionata, il raffinamento della ricerca per Etichetta sarà disponibile."
\ No newline at end of file
diff --git a/languages/template.base.pot b/languages/template.base.pot
new file mode 100644
index 0000000..09f46d6
--- /dev/null
+++ b/languages/template.base.pot
@@ -0,0 +1,17 @@
+# Translation for the Facets plugin for Omeka.
+# This file is distributed under the same license as the Omeka plugin.
+# FIRST AUTHOR public_items_browse, already coded into every page "
+"(so no change is needed), normally showing up at the end of the page; or the plugin's own "
+"public_items_facets, that has to be coded into relevant theme pages but can be used wherever deemed right."
+msgstr ""
+
+#: config_form.php:32
+msgid "Aspect"
+msgstr ""
+
+#: config_form.php:36
+msgid "Description"
+msgstr ""
+
+#: config_form.php:40
+msgid "Text to be used as additional description (tip: keep it short)."
+msgstr ""
+
+#: config_form.php:48
+msgid "Hide single entries"
+msgstr ""
+
+#: config_form.php:52
+msgid "If checked, values with just one entry will not be listed (unless there's less than %s entries in the list)."
+msgstr ""
+
+#: config_form.php:60
+msgid "Sort order"
+msgstr ""
+
+#: config_form.php:64
+msgid "The sorting order for values in select fields."
+msgstr ""
+
+#: config_form.php:70
+msgid "Alphabetical"
+msgstr ""
+
+#: config_form.php:71
+msgid "Popularity first, then alphabetical"
+msgstr ""
+
+#: config_form.php:79
+msgid "Hide popularity"
+msgstr ""
+
+#: config_form.php:83
+msgid "If checked, values's popularity will not be displayed (sorting order will still take it into consideration, if required)."
+msgstr ""
+
+#: config_form.php:89
+msgid "Elements"
+msgstr ""
+
+#: config_form.php:97
+msgid "The Dublin Core elements that can be used for search refinement."
+msgstr ""
+
+#: config_form.php:102
+msgid "Element"
+msgstr ""
+
+#: config_form.php:103
+msgid "Active"
+msgstr ""
+
+#: config_form.php:133
+msgid "Item Types"
+msgstr ""
+
+#: config_form.php:137
+msgid "If checked, search refinement by Item Type will be available."
+msgstr ""
+
+#: config_form.php:145
+msgid "Collections"
+msgstr ""
+
+#: config_form.php:149
+msgid "If checked, search refinement by Collection will be available."
+msgstr ""
+
+#: config_form.php:157
+msgid "Tags"
+msgstr ""
+
+#: config_form.php:161
+msgid "If checked, search refinement by Tag will be available."
+msgstr ""
\ No newline at end of file
From 5dd1109397f51cbd237bd2cf0a16679a6a5442fe Mon Sep 17 00:00:00 2001
From: DBinaghi <39097246+DBinaghi@users.noreply.github.com>
Date: Tue, 8 Jun 2021 15:05:06 +0200
Subject: [PATCH 016/161] Corrected typo
---
config_form.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config_form.php b/config_form.php
index 9e32408..283e8f1 100644
--- a/config_form.php
+++ b/config_form.php
@@ -158,7 +158,7 @@
- +
formCheckbox('facets_tags', get_option('facets_tags'), null, array('1', '0')); ?>
- public_items_browse, already coded into every page (so no change is needed), normally showing up at the end of the page; or the plugin\'s own public_items_facets, that has to be coded into relevant theme pages but can be used wherever deemed right.'); ?>
+ public_items_browse and public_collections_browse, already coded into every page (so no changes are needed), normally showing up at the end of the page; or the plugin\'s own public_facets, that has to be coded into relevant theme pages but can be used wherever deemed right.'); ?>