Skip to content

Commit

Permalink
Replace deprecated dbglog() function use with dokuwiki\Logger (#8)
Browse files Browse the repository at this point in the history
- Remove deprecated `dbglog()` function use / replace with `dokuwiki\Logger`
- Update plugin.info.txt
  • Loading branch information
mprins committed Nov 26, 2023
1 parent c23d30a commit f204b8c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 88 deletions.
27 changes: 15 additions & 12 deletions StaticMap.php
Expand Up @@ -27,6 +27,7 @@
use geoPHP\Geometry\Point;
use geoPHP\Geometry\Polygon;
use geoPHP\geoPHP;
use dokuwiki\Logger;

/**
*
Expand Down Expand Up @@ -170,7 +171,7 @@ public function getMap(): string
$this->autoZoom();
}
} catch (Exception $e) {
dbglog($e);
Logger::debug($e);
}

// use map cache, so check cache for map
Expand Down Expand Up @@ -221,7 +222,7 @@ private function autoZoom(float $paddingFactor = 1.0): void
}

if (count($geoms) <= 1) {
dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options");
Logger::debug("StaticMap::autoZoom: Skip setting autozoom options", $geoms);
return;
}

Expand All @@ -233,17 +234,17 @@ private function autoZoom(float $paddingFactor = 1.0): void
// $vy00 = log(tan(M_PI*(0.25 + $centroid->getY()/360)));
$vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360)));
$vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360)));
dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1");
Logger::debug("StaticMap::autoZoom: vertical resolution: $vy0, $vy1");
if ($vy1 - $vy0 === 0.0) {
$resolutionVertical = 0;
dbglog("StaticMap::autoZoom: using $resolutionVertical");
Logger::debug("StaticMap::autoZoom: using $resolutionVertical");
} else {
$zoomFactorPowered = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0));
$resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize);
}
// determine horizontal resolution
$resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width;
dbglog("StaticMap::autoZoom: using $resolutionHorizontal");
Logger::debug("StaticMap::autoZoom: using $resolutionHorizontal");
$resolution = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
$zoom = $this->zoom;
if ($resolution > 0) {
Expand All @@ -255,7 +256,7 @@ private function autoZoom(float $paddingFactor = 1.0): void
}
$this->lon = $centroid->getX();
$this->lat = $centroid->getY();
dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat");
Logger::debug("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat");
}

public function checkMapCache(): bool
Expand Down Expand Up @@ -298,21 +299,21 @@ public function makeMap(): void
try {
$this->drawKML();
} catch (exception $e) {
dbglog('failed to load KML file', $e);
Logger::error('failed to load KML file', $e);
}
}
if (file_exists($this->gpxFileName)) {
try {
$this->drawGPX();
} catch (exception $e) {
dbglog('failed to load GPX file', $e);
Logger::error('failed to load GPX file', $e);
}
}
if (file_exists($this->geojsonFileName)) {
try {
$this->drawGeojson();
} catch (exception $e) {
dbglog('failed to load GeoJSON file', $e);
Logger::error('failed to load GeoJSON file', $e);
}
}

Expand Down Expand Up @@ -386,7 +387,7 @@ public function createBaseMap(): void
}
$destX = ($x - $startX) * $this->tileSize + $this->offsetX;
$destY = ($y - $startY) * $this->tileSize + $this->offsetY;
dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY");
Logger::debug("imagecopy tile into image: $destX, $destY", $this->tileSize);
imagecopy(
$this->image,
$tileImage,
Expand Down Expand Up @@ -421,7 +422,7 @@ public function fetchTile(string $url)
curl_setopt($ch, CURLOPT_USERAGENT, $_UA);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL, $url . $this->apikey);
dbglog("StaticMap::fetchTile: getting: $url using curl_exec");
Logger::debug("StaticMap::fetchTile: getting: $url using curl_exec");
$tile = curl_exec($ch);
curl_close($ch);
} else {
Expand All @@ -437,7 +438,9 @@ public function fetchTile(string $url)
}

$context = stream_context_create($opts);
// dbglog("StaticMap::fetchTile: getting: $url . $this->apikey using file_get_contents and options $opts");
Logger::debug(
"StaticMap::fetchTile: getting: $url . $this->apikey using file_get_contents and options $opts"
);
$tile = file_get_contents($url . $this->apikey, false, $context);
}
if ($tile && $this->useTileCache) {
Expand Down
9 changes: 5 additions & 4 deletions admin/purge.php
@@ -1,9 +1,7 @@
<?php

use dokuwiki\Extension\AdminPlugin;

/*
* Copyright (c) 2008-2015 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2008-2023 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 All @@ -19,6 +17,9 @@
*
* @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
*/
use dokuwiki\Extension\AdminPlugin;
use dokuwiki\Logger;

/**
* DokuWiki Plugin openlayersmap (Admin Component).
* This component purges the cached tiles and maps.
Expand Down Expand Up @@ -74,7 +75,7 @@ public function handle(): void
private function rrmdir(string $sDir): bool
{
if (is_dir($sDir)) {
dbglog($sDir, 'admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: ');
Logger::debug('admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: ', $sDir);
$sDir = rtrim($sDir, '/');
$oDir = dir($sDir);
while (($sFile = $oDir->read()) !== false) {
Expand Down
9 changes: 5 additions & 4 deletions helper/staticmap.php
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2008-2022 Mark C. Prins <mprins@users.sf.net>
* Copyright (c) 2008-2023 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 All @@ -17,6 +17,7 @@
*
* @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
*/
use dokuwiki\Logger;
use dokuwiki\Extension\Plugin;
use dokuwiki\plugin\openlayersmap\StaticMap;

Expand Down Expand Up @@ -71,7 +72,7 @@ public function getMap(
string $apikey = ''
): string {
global $conf;
// dbglog($markers,'helper_plugin_openlayersmap_staticmap::getMap: markers :');
// Logger::debug('helper_plugin_openlayersmap_staticmap::getMap: markers :',$markers);

// normalize zoom
$zoom = $zoom ?: 0;
Expand All @@ -91,9 +92,9 @@ public function getMap(

// cleanup/validate gpx/kml
$kml = $this->mediaIdToPath($kml);
// dbglog($kml,'helper_plugin_openlayersmap_staticmap::getMap: kml file:');
// Logger::debug('helper_plugin_openlayersmap_staticmap::getMap: kml file:',$kml);
$gpx = $this->mediaIdToPath($gpx);
// dbglog($gpx,'helper_plugin_openlayersmap_staticmap::getMap: gpx file:');
// Logger::debug('helper_plugin_openlayersmap_staticmap::getMap: gpx file:',$gpx);
$geojson = $this->mediaIdToPath($geojson);

// create map
Expand Down
2 changes: 1 addition & 1 deletion plugin.info.txt
@@ -1,7 +1,7 @@
base openlayersmap
author Mark C. Prins
email mprins@users.sf.net
date 2023-11-15
date 2023-11-26
name OpenLayers map plugin for DokuWiki
desc Provides a syntax for rendering an OpenLayers based map in a wiki page. Uses OpenLayers 8.1.0
url https://www.dokuwiki.org/plugin:openlayersmap

0 comments on commit f204b8c

Please sign in to comment.