Skip to content

Commit

Permalink
fix upload problems (#52)
Browse files Browse the repository at this point in the history
* fix upload problems

resolves #51

* 🤖 Rector and PHPCS fixes

* update test workflow
  • Loading branch information
mprins authored Apr 8, 2024
1 parent 038f4f4 commit 639d6e3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: 'CI'

on: [ push, pull_request, workflow_dispatch ]
on:
push:
pull_request:
branches:
- master
workflow_dispatch:

jobs:
action:
name: "CI (${{ github.event_name }}) for ${{ matrix.php-version }} ${{ matrix.dokuwiki-branch }}"
strategy:
fail-fast: false
matrix:
Expand Down
4 changes: 2 additions & 2 deletions _test/index.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions action.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2011-2020 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011-2024 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -325,18 +325,18 @@ 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')) {
$indexer = plugin_load('helper', 'spatialhelper_index');
if ($indexer !== null) {
$indexer->indexImage($event->data [2]);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
29 changes: 15 additions & 14 deletions helper/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2011-2023 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2011-2024 Mark C. Prins <mprins@users.sf.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -200,33 +200,34 @@ 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'))
(!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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugin.info.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 639d6e3

Please sign in to comment.