From 70ca0267dec1fbfa0ed988846fa4bb2d0635dc53 Mon Sep 17 00:00:00 2001 From: Mark Prins <1165786+mprins@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:31:03 +0200 Subject: [PATCH] fix upload problems resolves #51 --- _test/index.test.php | 4 ++-- action.php | 17 +++++++++-------- composer.json | 2 +- helper/index.php | 30 +++++++++++++++--------------- plugin.info.txt | 2 +- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/_test/index.test.php b/_test/index.test.php index ae3f192..3d0ce95 100644 --- a/_test/index.test.php +++ b/_test/index.test.php @@ -21,7 +21,7 @@ class index_test extends DokuWikiTest * @see index_test::test_convertDMStoD * */ - final public static function convertDMStoDTestdata(): array + final public static function convertDMStoDTestdata(): array { return array( array( @@ -50,7 +50,7 @@ final public static function convertDMStoDTestdata(): array /** * @dataProvider convertDMStoDTestdata */ - final public function test_convertDMStoD(array $input, float $expected_output, string $msg): void + final public function test_convertDMStoD(array $input, float $expected_output, string $msg): void { $index = plugin_load('helper', 'spatialhelper_index'); assert($index instanceof helper_plugin_spatialhelper_index); diff --git a/action.php b/action.php index 6d8934c..ecb6013 100644 --- a/action.php +++ b/action.php @@ -1,7 +1,7 @@ + * Copyright (c) 2011-2024 Mark C. Prins * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -325,18 +325,19 @@ private function printHTML(array $searchresults, bool $showMedia = true): void */ final public function handleMediaUploaded(Event $event): void { - // data[0] temporary file name (read from $_FILES) - // data[1] file name of the file being uploaded - // data[2] future directory id of the file being uploaded - // data[3] the mime type of the file being uploaded - // data[4] true if the uploaded file exists already - // data[5] (since 2011-02-06) the PHP function used to move the file to the correct location + //data[0] path/to/new/media.file (normally read from $_FILES, potentially could come from elsewhere) + //data[1] file name of the file being uploaded + //data[2] future directory id of the file being uploaded + //data[3] the mime type of the file being uploaded + //data[4] true if the uploaded file exists already + //data[5] (since 2011-02-06) the PHP function used to move the file to the correct location Logger::debug("handleMediaUploaded::event data", $event->data); // check the list of mimetypes // if it's a supported type call appropriate index function - if (substr_compare($event->data [3], 'image/jpeg', 0)) { + if (str_contains($event->data [3], 'image/jpeg')) { + Logger::debug("handleMediaUploaded::got ".$event->data[3]." upload"); $indexer = plugin_load('helper', 'spatialhelper_index'); if ($indexer !== null) { $indexer->indexImage($event->data [2]); diff --git a/composer.json b/composer.json index 9a59a68..314dfa5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "php": ">=8.0", "ext-exif": "*", "ext-json": "*", - "mprins/dokuwiki-plugin-geophp": ">=2023-07-14" + "mprins/dokuwiki-plugin-geophp": ">=2023-11-08" }, "config": { "platform": { diff --git a/helper/index.php b/helper/index.php index 758ab6f..3c6fe88 100644 --- a/helper/index.php +++ b/helper/index.php @@ -1,7 +1,7 @@ + * Copyright (c) 2011-2024 Mark C. Prins * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -86,10 +86,10 @@ final public function generateSpatialIndex(): bool } // media $media = []; - search($media, $conf ['mediadir'], 'search_media', []); + search($media, $conf['mediadir'], 'search_media', []); foreach ($media as $medium) { - if ($medium ['isimg']) { - $this->indexImage($medium); + if ($medium['isimg']) { + $this->indexImage($medium['id']); } } return true; @@ -200,33 +200,33 @@ private function saveIndex(): bool /** * Add an index entry for this file having EXIF / IPTC data. * - * @param $img - * a Dokuwiki image - * @return bool true when image was succesfully added to the index. + * @param $imgId + * a Dokuwiki image id + * @return bool true when image was successfully added to the index. * @throws Exception * @see http://www.php.net/manual/en/function.iptcparse.php * @see http://php.net/manual/en/function.exif-read-data.php * */ - final public function indexImage(array $img): bool + final public function indexImage(string $imgId): bool { // test for supported files (jpeg only) - if ( - (!str_ends_with($img ['file'], '.jpg')) && - (!str_ends_with($img ['file'], '.jpeg')) + if ((!str_ends_with(strtolower($imgId), '.jpg')) && + (!str_ends_with(strtolower($imgId), '.jpeg')) ) { + Logger::debug("indexImage:: ".$imgId." is not a supported image file."); return false; } - $geometry = $this->getCoordsFromExif($img ['id']); + $geometry = $this->getCoordsFromExif($imgId); if (!$geometry) { return false; } $geohash = $geometry->out('geohash'); // TODO truncate the geohash to something reasonable, otherwise they are - // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too - // precise, limit at ~9 as most GPS are not submeter accurate - return $this->addToIndex($geohash, 'media__' . $img ['id']); + // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too + // precise, limit at ~9 as most GPS are not submeter accurate + return $this->addToIndex($geohash, 'media__' . $imgId); } /** diff --git a/plugin.info.txt b/plugin.info.txt index 89f3e81..934145d 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base spatialhelper author Mark C. Prins email mprins@users.sf.net -date 2023-12-22 +date 2024-04-08 name Spatial Helper plugin for DokuWiki desc Provides spatial indexing and spatial search facilities. url https://www.dokuwiki.org/plugin:spatialhelper