From 846946aab2aa88349b4deded68365e63fbb2cb98 Mon Sep 17 00:00:00 2001 From: surrim Date: Thu, 27 Feb 2020 02:15:54 +0100 Subject: [PATCH] setting for none/all categories --- serendipity_event_osm/serendipity_event_osm.php | 16 ++++++++++++---- serendipity_event_static_osm/osm.js | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/serendipity_event_osm/serendipity_event_osm.php b/serendipity_event_osm/serendipity_event_osm.php index 1508abef..4902e014 100644 --- a/serendipity_event_osm/serendipity_event_osm.php +++ b/serendipity_event_osm/serendipity_event_osm.php @@ -46,15 +46,23 @@ function event_hook($event, &$bag, &$eventData, $addData = null) { if ($event == 'entries_header') { - if ($this->get_config('category_id') === '0' || in_array($this->get_config('category_id'), $this->get_page_categories())) { - echo '
'.PHP_EOL; + $category_id = $this->get_config('category_id', 'all'); + $page_categories = $this->get_page_categories(); + if ( + $category_id === 'all' + || + ($category_id === 'none' && empty($page_categories)) + || + in_array($category_id, $page_categories) + ) { + echo '
'.PHP_EOL; } } } function get_selectable_categories() { - $categories = array(0 => ALL_CATEGORIES); + $categories = array('all' => ALL_CATEGORIES, 'none' => NO_CATEGORIES); $cats = serendipity_fetchCategories(); if (is_array($cats)) { $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED); @@ -79,7 +87,7 @@ $propbag->add('name', PLUGIN_EVENT_OSM_CATEGORY); $propbag->add('description', PLUGIN_EVENT_OSM_CATEGORY_DESCRIPTION); $propbag->add('select_values', $this->get_selectable_categories()); - $propbag->add('default', '0'); + $propbag->add('default', 'all'); break; case 'path': $propbag->add('type', 'string'); diff --git a/serendipity_event_static_osm/osm.js b/serendipity_event_static_osm/osm.js index ab6b1a13..fc5b87d9 100644 --- a/serendipity_event_static_osm/osm.js +++ b/serendipity_event_static_osm/osm.js @@ -17,7 +17,7 @@ window.onload = () => { }); const data = divMap.dataset; - const entries = geo.entries.filter(x => data.category === "0" || x.categories.includes(data.category)); + const entries = geo.entries.filter(x => ["all", "none"].includes(data.category) || x.categories.includes(data.category)); const uploads = geo.uploads.filter(x => x.url.startsWith(data.path)); const features = entries.map((entry, id) => { const feature = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(entry.pos.reverse())));