Skip to content

Commit 639d6e3

Browse files
authored
fix upload problems (#52)
* fix upload problems resolves #51 * 🤖 Rector and PHPCS fixes * update test workflow
1 parent 038f4f4 commit 639d6e3

File tree

6 files changed

+34
-27
lines changed

6 files changed

+34
-27
lines changed

.github/workflows/CI.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
name: 'CI'
22

3-
on: [ push, pull_request, workflow_dispatch ]
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- master
8+
workflow_dispatch:
49

510
jobs:
611
action:
12+
name: "CI (${{ github.event_name }}) for ${{ matrix.php-version }} ${{ matrix.dokuwiki-branch }}"
713
strategy:
814
fail-fast: false
915
matrix:

_test/index.test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class index_test extends DokuWikiTest
2121
* @see index_test::test_convertDMStoD
2222
*
2323
*/
24-
final public static function convertDMStoDTestdata(): array
24+
final public static function convertDMStoDTestdata(): array
2525
{
2626
return array(
2727
array(
@@ -50,7 +50,7 @@ final public static function convertDMStoDTestdata(): array
5050
/**
5151
* @dataProvider convertDMStoDTestdata
5252
*/
53-
final public function test_convertDMStoD(array $input, float $expected_output, string $msg): void
53+
final public function test_convertDMStoD(array $input, float $expected_output, string $msg): void
5454
{
5555
$index = plugin_load('helper', 'spatialhelper_index');
5656
assert($index instanceof helper_plugin_spatialhelper_index);

action.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
* Copyright (c) 2011-2020 Mark C. Prins <mprins@users.sf.net>
4+
* Copyright (c) 2011-2024 Mark C. Prins <mprins@users.sf.net>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -325,18 +325,18 @@ private function printHTML(array $searchresults, bool $showMedia = true): void
325325
*/
326326
final public function handleMediaUploaded(Event $event): void
327327
{
328-
// data[0] temporary file name (read from $_FILES)
329-
// data[1] file name of the file being uploaded
330-
// data[2] future directory id of the file being uploaded
331-
// data[3] the mime type of the file being uploaded
332-
// data[4] true if the uploaded file exists already
333-
// data[5] (since 2011-02-06) the PHP function used to move the file to the correct location
328+
//data[0] path/to/new/media.file (normally read from $_FILES, potentially could come from elsewhere)
329+
//data[1] file name of the file being uploaded
330+
//data[2] future directory id of the file being uploaded
331+
//data[3] the mime type of the file being uploaded
332+
//data[4] true if the uploaded file exists already
333+
//data[5] (since 2011-02-06) the PHP function used to move the file to the correct location
334334

335335
Logger::debug("handleMediaUploaded::event data", $event->data);
336336

337337
// check the list of mimetypes
338338
// if it's a supported type call appropriate index function
339-
if (substr_compare($event->data [3], 'image/jpeg', 0)) {
339+
if (str_contains($event->data [3], 'image/jpeg')) {
340340
$indexer = plugin_load('helper', 'spatialhelper_index');
341341
if ($indexer !== null) {
342342
$indexer->indexImage($event->data [2]);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"php": ">=8.0",
1616
"ext-exif": "*",
1717
"ext-json": "*",
18-
"mprins/dokuwiki-plugin-geophp": ">=2023-07-14"
18+
"mprins/dokuwiki-plugin-geophp": ">=2023-11-08"
1919
},
2020
"config": {
2121
"platform": {

helper/index.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
* Copyright (c) 2011-2023 Mark C. Prins <mprins@users.sf.net>
4+
* Copyright (c) 2011-2024 Mark C. Prins <mprins@users.sf.net>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -86,10 +86,10 @@ final public function generateSpatialIndex(): bool
8686
}
8787
// media
8888
$media = [];
89-
search($media, $conf ['mediadir'], 'search_media', []);
89+
search($media, $conf['mediadir'], 'search_media', []);
9090
foreach ($media as $medium) {
91-
if ($medium ['isimg']) {
92-
$this->indexImage($medium);
91+
if ($medium['isimg']) {
92+
$this->indexImage($medium['id']);
9393
}
9494
}
9595
return true;
@@ -200,33 +200,34 @@ private function saveIndex(): bool
200200
/**
201201
* Add an index entry for this file having EXIF / IPTC data.
202202
*
203-
* @param $img
204-
* a Dokuwiki image
205-
* @return bool true when image was succesfully added to the index.
203+
* @param $imgId
204+
* a Dokuwiki image id
205+
* @return bool true when image was successfully added to the index.
206206
* @throws Exception
207207
* @see http://www.php.net/manual/en/function.iptcparse.php
208208
* @see http://php.net/manual/en/function.exif-read-data.php
209209
*
210210
*/
211-
final public function indexImage(array $img): bool
211+
final public function indexImage(string $imgId): bool
212212
{
213213
// test for supported files (jpeg only)
214214
if (
215-
(!str_ends_with($img ['file'], '.jpg')) &&
216-
(!str_ends_with($img ['file'], '.jpeg'))
215+
(!str_ends_with(strtolower($imgId), '.jpg')) &&
216+
(!str_ends_with(strtolower($imgId), '.jpeg'))
217217
) {
218+
Logger::debug("indexImage:: " . $imgId . " is not a supported image file.");
218219
return false;
219220
}
220221

221-
$geometry = $this->getCoordsFromExif($img ['id']);
222+
$geometry = $this->getCoordsFromExif($imgId);
222223
if (!$geometry) {
223224
return false;
224225
}
225226
$geohash = $geometry->out('geohash');
226227
// TODO truncate the geohash to something reasonable, otherwise they are
227-
// useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too
228-
// precise, limit at ~9 as most GPS are not submeter accurate
229-
return $this->addToIndex($geohash, 'media__' . $img ['id']);
228+
// useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too
229+
// precise, limit at ~9 as most GPS are not submeter accurate
230+
return $this->addToIndex($geohash, 'media__' . $imgId);
230231
}
231232

232233
/**

plugin.info.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
base spatialhelper
22
author Mark C. Prins
33
email mprins@users.sf.net
4-
date 2023-12-22
4+
date 2024-04-08
55
name Spatial Helper plugin for DokuWiki
66
desc Provides spatial indexing and spatial search facilities.
77
url https://www.dokuwiki.org/plugin:spatialhelper

0 commit comments

Comments
 (0)