[pmwiki-users] Page Variables help - how to take one and split into two

Hans design5 at softflow.co.uk
Mon Nov 2 17:11:33 CST 2009


Monday, November 2, 2009, 10:22:09 PM, stevecrisp at gmail.com wrote:

> The ParseArgs() function is icing on the cake.  I'm integrating that
> in also.  I might be in danger of understanding this stuff soon ;-)

ParseArgs() does  not work too well, as it creats separate arrays for
single parameters starting with - and with +, and it gets tricky to
deconstruct these into the actual values.

So I tried this instead, which adds parameters lat=... and long=...

$FmtPV['$Latitude'] = '@$page["latitude"]';
SaveProperties[] = 'latitude';
$FmtPV['$Longitude'] = '@$page["longitude"]';
SaveProperties[] = 'longitude';

Markup('coord', 'directives',
  "/\\(:coord\\s+(.*?)\\s+(.*?)\\s*:\\)/ei",
  "PZZ(SetCoord(\$pagename, PSS('$1'), PSS('$2')))");
 
function SetCoord($pagename, $lat, $long) {
  foreach (array($lat,$long) as $k => $v) {
    if (strstr($v,'=')) {
      $arg = explode('=', $v);
      if ($arg[0]=='lat') $latitude = $arg[1];
      elseif ($arg[0]=='long') $longitude = $arg[1];
    } else {
      $latitude = $lat;
      $longitude = $long;
    }
  }
  SetProperty($pagename, 'latitude', $latitude, ', ');
  SetProperty($pagename, 'longitude', $longitude, ', ');
}


  ~Hans




More information about the pmwiki-users mailing list