, implement caption
# 2021-06-18 Fix incorrect placement of "-" in regex for PHP 7.4
# 2021-04-21 Caption, inline-block
# 2018-07-10 Don't generate zoom parameter when llbs or nzbs
# 2018-05-14 Call topomap with https
# 2018-05-12 PHP 7.2
# 2015-07-01 Attachments corrected (gpx, kml requires extra processing)
# 2014-08-09 Markup_e PHP 5.5 compatible, add mapref parameter
# 2013-07-15 Initial version
*/
# Version date
$RecipeInfo[NZTOPONAME]['Version'] = '2022-02-22' . NZTOPONEW;
$FmtPV['$NZTopoVersion'] = "'" . NZTOPONAME . " version {$RecipeInfo[NZTOPONAME]['Version']}'"; // return version as a custom page variable
\SDV($NZTopoZoom, 13); # set default zoom factor
\SDV($NZTopoNewwin, 1); # set default new window setting
\SDV($NZTopoDebug, false); # set default debug setting
\SDV($HTMLStylesFmt[NZTOPONAME], # set default styles
'.nztopo figcaption {font-size:smaller;}'
. '.nztopodebug {font-size:smaller;}');
# declare $NZTopo for (:if enabled NZTopo:) recipe installation check
$NZTopo = true; # enabled
# set debug flag
$nztopo_debugon = boolval ($NZTopoDebug); # if on writes input and output to web page
if ($nztopo_debugon) tpmsg ('
' . __FILE__, $RecipeInfo[NZTOPONAME]['Version']);
// Initialise constants
DEFINE ('NL', "\n");
DEFINE ('BR', '
' . NL);
DEFINE ('SRC_URL', 'https://www.topomap.co.nz/NZTopoMap'); # URL for browser service
DEFINE ('SRC_URLEMB', 'https://www.topomap.co.nz/NZTopoMapEmbedded'); # URL for embedded service
DEFINE ('SRC_PROXY', 'https://www.topomap.co.nz/proxy.ashx?'); # URL for gpx proxy
DEFINE ('APV_VERSION', 'v=2'); # fixed version of nztopomap interface
## Add a PmWiki custom markup
// This markup ensures the user is syntactically correct when entering the parameters
# (:nztopo ll=-41.293722,174.871482 :)
# (:nztopo topo50=BP33912708,BP33876687 height=300 width=400 pin=1 label='destination' float=right clear=both zoom=12:)
# (:nztopo mapref=BN33991890:)
## the following builds the regex to parse the NZTopo PmWiki directive input parameters
# directive arguments are
# ll= -- decimal latitude,longitude
# llbs = -- -- decimal latitude,longitude;latitude,longitude
$vlat = '[-+]?\d{1,2}[.]\d+'; # latitude -90 .. 90
$vlong = '[-+]?[1]?\d{1,2}[.]\d+'; # longitude -180 .. 180
$vlatlong = $vlat . '[,]' . $vlong; # latitude,longitude
$pll = 'll=' . $vlatlong;
$pllbs = 'llbs=' . $vlatlong . '(?:[;]' . $vlatlong . ')+'; # two or more pairs of lat long co-ordinates separated by semicolons
# nztm
$vnztm = '\d{7}(?:[.]\d{0,3})?'; # single NZTM co-ordinate e.g. 1234567(.123)
$vnztm2 = $vnztm . '[,]' . $vnztm; # pair of NZTM co-ordinates: easting; northing, separated by comma
# mapref
$mapref ='[ABC][A-Z][0-4]\d[ ]?\d{6}'; # topo50 map reference e.g. BN33991890, BN33 991890
## parameters
$pnzne = 'nzne=' . $vnztm2;
$pnzbs = 'nzbs=' . $vnztm2 . '(?:[;]' . $vnztm2 . ')+'; # two or more pairs of NZTM co-ordinates separated by semicolons
# topo50= -- topo50 grid coordinate, or two grid coordinates (not currently implemented in nztopomap)
$ptopo50 = 'topo50=' . $mapref . '(?:[,]' . $mapref .')?'; # separated by comma
## -- only one of topo50, ll, llbs, nzne, nzbs,, kml or gpx can be supplied
# Use PmWiki PageNameChars and UploadNameChars sets to define group, name, and filename syntax
# see https://regex101.com/r/dc2mho/1
$vnamepagefile = "(?:[$PageNameChars]+(?:\.|\/)){0,2}" # optional group/page name and separator (/ or .) repeated
. "[$UploadNameChars]+\."; # file name and dot, extension is added later
//if ($nztopo_debugon) tpmsg ('vpagenum', qt ($vnamepagefile . 'gpx', true) . ' PN:"' . $PageNameChars . '" Up:"' . $UploadNameChars . '"');
$vscheme = 'https?:\/\/'; #
# see https://regex101.com/r/Nrtqlt/1
$vurl = $vscheme . '.*'; #
$vurlunqt = $vscheme . '[^\s]*'; #
# kml= -- URL or wiki page to kml file
$pkml = 'kml=(?:' . qt ($vurl) . '|' . qt ($vnamepagefile . 'kml', true) . '|' . $vurlunqt . ')';
if ($nztopo_debugon) { # add extra test parameters
$pkml2 = 'kml2=(?:' . qt ($vurl) . '|' . $vurlunqt . ')'; # added for debug and testing
$pkml3 = 'kml3=(?:' . qt ($vurl) . '|' . $vurlunqt . ')'; # added for debug and testing
$pkml4 = 'kml4=(?:' . qt ($vurl) . '|' . $vurlunqt . ')'; # added for debug and testing
} # debugon
# gpx= -- URL or wiki page to gpx file, see https://regex101.com/r/dc2mho/7
$pgpx = 'gpx=(?:' . qt ($vnamepagefile . 'gpx', true) . '|' . qt ($vurl) . '|' . $vurlunqt . ')';
//if ($nztopo_debugon) tpmsg ('pgpx', $pgpx);
# map reference
$pmapref = 'mapref=' . qt ($mapref, true);
DEFINE ('LENUNITS', '\d{1,5}(?:px)?'); # units can only be pixels
# height= -- image height in pixels
$pheight = 'height=' . LENUNITS;
# width= -- image width in pixels
$pwidth = 'width=' . LENUNITS;
# pin= -- show pin
$ppin = 'pin=[01]';
# label -- tool tip label for pin
$qtstr = '.+?';
$plabel = 'label=' . qt($qtstr); # provide for single and double quoted strings
# zoom= -- scale factor for map
$pzoom = 'zoom=\d{1,2}';
# float= -- left or right
$pfloat = 'float=(?:left|right)';
# clear= -- left, right, both
$pclear = 'clear=(?:left|right|both)';
# caption = string
$pcaption = 'caption=' . qt($qtstr); # provide for single and double quoted strings
## only one location can be supplied
$qlocale = '(?:' . $pll . ')|(?:' . $pllbs . ')|(?:' . $pkml . ')|(?:' . $pgpx . ')|(?:' . $pnzne . ')|(?:' . $pnzbs . ')|(?:' . $pmapref . ')';
if ($nztopo_debugon) { # add extra test parameters
$qlocale .= '|(?:' . $pkml2 . ')|(?:' . $pkml3 . ')|(?:' . $pkml4 . ')';
} # debugon
# display modifications
$qmods = "(" . $pheight . ")\s*|(" . $pwidth . ")\s*|(" . $ppin . ")\s*|(" . $plabel . ")\s*|(" . $pzoom . ")\s*|(" . $pfloat . ")\s*|(" . $pclear . ")\s*";
# captions
$qdesc = "(" . $pcaption . ")\s*";
##
$MarkupParam = "/\\(:" . mb_strtolower(NZTOPONAME) . '\s+?(' . $qlocale . ")\s*?(?:" . $qmods . "){0,7}\s*?(?:" . $qdesc . "){0,1}\s*?:\\)/i"; #
# see https://regex101.com/r/hUTcCN/3
# s = dot matches all chars including newline
# i = case insensitive
if ($nztopo_debugon) tpmsg ('markup', $MarkupParam);
\Markup(NZTOPOID, # an internal PmWiki function that defines the custom markup for the wiki (see https://www.pmwiki.org/wiki/PmWiki/CustomMarkup)
'directives',
$MarkupParam,
__NAMESPACE__ . '\NZTopo_Parse' );
#
return; # NZTopo processing complete
# Keep prevents PmWiki markup being applied
#
/** Main NZTopo parser
* /param arguments as documented above
* /return The HTML-formatted NZTopo markup wrapped in a