<?php if (!defined('PmWiki')) exit();

/*
Creative Commons Licenses
licenses.php
Adam Overton, August 2009
the following code adpated from Patrick Michaud's code in the original licenses.php

VARIABLES
this allows the following setup variables in config.php:
* $LicenseDefault - i.e. 'by-nc-nd'
* $LicenseLoc - not required - otherwise enter one of the two-letter country codes: at, cz, de, ec, es, gr, gt, hk, hr, lu, nl, no, nz, ph, pl, pr, ro, rs, sg, th, us
* $LicenseSizeDefault - 'large' or 'small' - determines which size license to post
* $LicenseSizeArray - defaults currently in use on the creativecommons site are 'large'=>'88x31', or 'small'=>'80x15'
* $LicenseVersion - easily update the version your using - default is 3.0
* $LicenseBaseLinkURL - base link for most (not all) of the urls for the CC-deed links - default is http://creativecommons.org/licenses
* $LicenseBaseImgURL - base link for most (not all) of the urls for the CC-images - default is  http://i.creativecommons.org/l

ARGUMENTS
users can now indicate the license-type, location and size of their license in the format:
(:license type=by-nc-nd size=large loc=us :)
  or
(:license by-nc-nd size=large loc=us :)

ADDITIONAL LICENSE CONDITION ICONS
this version of license also now incorporates the individual license condition icons for each aspect of a CC license, i.e. Share Alike, No Derivatives, etc. these are accessed the same as above, but without any size or location arguments, and for type argument using one of the following - by-icon, sa-icon, nc-icon, nd-icon, pd-icon - as in:
(:license by-icon:)
  or 
(:license type=by-icon:)

*/

SDV($RecipeInfo['Licenses']['Version'], '2008-08-04');

SDV($LicenseDefault, 'by-nc-nd');
SDV($LicenseLoc, ''); # not required - otherwise enter one of the two-letter country codes: at, cz, de, ec, es, gr, gt, hk, hr, lu, nl, no, nz, ph, pl, pr, ro, rs, sg, th, us
SDV($LicenseSizeDefault, 'large');  # smaller
SDVA($LicenseSizeArray, array('large'=>'88x31', 'small'=>'80x15'));
SDV($LicenseVersion, '3.0');   # change or update the version

SDV($LicenseBaseLinkURL, 'http://creativecommons.org/licenses');   # change or update the version
SDV($LicenseBaseImgURL, 'http://i.creativecommons.org/l');   # change or update the version

Markup('license', 'directives',
  '/\\(:license(\\s.*?)?:\\)/e',
  "License(\$pagename, PSS('$1'))");

function License($pagename, $args) {
	global $LicenseDefault, $LicenseSizeDefault, $LicenseSizeArray, $LicenseBaseLinkURL, $LicenseBaseImgURL, $LicenseVersion;
	$args = ParseArgs($args);
	
	$License = isset($args['type']) ? $args['type'] : $args[''][0];
	if ($License == '') $License = $LicenseDefault;
	$License = strtolower($License);
	
	$size = $args['size'];
	if(isset($args['size'])) { $LicenseSize = $LicenseSizeArray[$args['size']]; }
		else { $LicenseSize = $LicenseSizeArray[$LicenseSizeDefault]; }

	if(isset($args['loc'])) $LicenseLoc = "/".$args['loc'];
	
	# these licenseTypes have a different link format
	$licenseTypes_main = array('by','by-nd','by-nc-nd','by-nc','by-nc-sa','by-sa');
	$iconArray = array(
		'by-icon' => array('attrib','Attribution'),
		'sa-icon' => array('sharealike','Share Alike'),
		'nc-icon' => array('noncomm','Noncommercial'),
		'nd-icon' => array('nomod','No Derivative Works'),
		'pd-icon' => array('pd','Public Domain')
	);

	if(strstr($License,"-icon")) {
		# link for individual icons
		$fmt = '[[http://creativecommons.org/about/licenses | http://creativecommons.org/images/icons/'.$iconArray[$License][0].'.gif"Creative Commons - '.$iconArray[$License][1].'"]]';
	} elseif ($License=='pd') {
		# link for public domain rectangle
		$fmt = "[[$LicenseBaseLinkURL/$License/$LicenseVersion/ | $LicenseBaseImgURL/publicdomain/$LicenseSize.png\"Public Domain Dedication\"]]";
	} else {
		# link for regular rectangular licenses
		$fmt = "[[$LicenseBaseLinkURL/$License/$LicenseVersion/ | $LicenseBaseImgURL/$License/$LicenseVersion$LicenseLoc/$LicenseSize.png\"Creative Commons License\"]]";
	}
	
	return FmtPageName($fmt, $pagename);
}