<?php if (!defined('PmWiki')) exit();
/*
  Copyright 2004-2023 Patrick R. Michaud (pmichaud@pobox.com)
  This file is licenses.php; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 
  as published by the Free Software Foundation.
  
  See documentation for this recipe at:
    https://www.pmwiki.org/wiki/Cookbook/Licenses 

  Script maintained by Petko Yotov www.pmwiki.org/petko
*/

SDV($RecipeInfo['Licenses']['Version'], '20231127');

SDV($LicenseVersion, '4.0');

SDVA($LicenseTypeFmt, array(
  'by' => 1,
  'by-nd' => 1,
  'by-nc-nd' => 1,
  'by-nc' => 1,
  'by-nc-sa' => 1,
  'by-sa' => 1,
  'pd' => 1,
));

SDVA($LicenseFmt, array(
  'cc' => '[[https://creativecommons.org/licenses/%s/%s/ | https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/%s.svg"$[Creative Commons License]"]]',
  'pd' => '[[https://creativecommons.org/publicdomain/zero/1.0/ | https://mirrors.creativecommons.org/presskit/buttons/88x31/svg/pd.svg"$[Public Domain Dedication]"]]',
));
  
SDV($LicenseDefault, 'by-nc-nd');


Markup('license', 'directives',
  '/\\(:license(\\s.*?)?:\\)/',
  "FmtLicense");

function FmtLicense($m) {
  extract($GLOBALS['MarkupToHTML']);
  global $LicenseFmt, $LicenseTypeFmt, $LicenseVersion, $LicenseDefault;
  $args = ParseArgs(@$m[1]);
  $cc = strtolower(strval(@$args[''][0]));
  if (! $cc) $cc = $LicenseDefault;
  $fmt = @$LicenseTypeFmt[$cc];
  if (!$fmt) return "unrecognized license $cc";
  
  if ($fmt === 1) { # new formats
    $fmt = isset($LicenseFmt[$cc])? $LicenseFmt[$cc] : $LicenseFmt['cc'];
    $fmt = sprintf($fmt, $cc, $LicenseVersion, $cc);
  }
  #else old formats, customized at some point
  
  return FmtPageName($fmt, $pagename);
}