CreativeCommonsLicenseDisplay

Summary: Display a compliant Creative Commons License description from a wiki page
Version: 2012-09-19
Prerequisites: v2.0+
Status: Stable
License: GPL2+
Maintainer:
Categories: Markup
Users: (view? / edit)

Questions answered by this recipe

How can I display a compliant Creative Commons License description from a wiki page?

Description

Display a compliant Creative Commons License description from a wiki page

The Creative Commons License text is more complex than a few simple links. It contains additional name space items in order for CC.org to track things. This recipe makes a simple markup to display the license.

Installation

Add the following to local/config.php:

/*  Copyright (c) 2012-2015, Tamara Temple <tamouse@gmail.com>. 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version. See pmwiki.php for full details
    and lack of warranty.
*/
// nice markup for CC licenses
//
// Usage: (:cc-license [type=(by|by-nc|by-nc-sa)] [title=<name of work>] [work=<URL of work>] [author=<name of author>] [authorurl=<link to author's contact page>] [permissions=<link to more permissions page>]:)
//
// Defaults:
//   type: by-nc-sa
//   title: $WikiTitle
//   work: $ScriptDirUrl
//   author: Anonymous
//   authorurl: blank
//   permissions: $ScriptDirUrl?n=Site.Permissions
//
Markup('creativecommonslicenses', /* unique markup identifier */
       '<links',		  /* don't want pmwiki to reprocess urls in text */
       '/\\(:cc-license\\s*?(.*?):\\)/ei', /* regex for markup recognition */
       "cc_license_markup('$1')");
function cc_license_markup($parameters='')
{
  global $WikiTitle, $ScriptUrl;
  $parameters=stripslashes($parameters);

  /* defaults */
  $license_strings = array('by' => 'Attribution',
			   'by-nc' => 'Attribution NonCommercial',
			   'by-nc-sa' => 'Attribution NonCommercial ShareAlike');
  $defaults = array('type'=>'by-nc-sa',
		    'title'=>$WikiTitle,
		    'work'=>$ScriptUrl,
		    'author'=>'Anonymous',
		    'authorurl'=>'',
		    'permissions'=>"{$ScriptUrl}?n=Site.Permissions");
  $LicenseFmt = "<a rel='license' href='\$CCL_URL'>
  <img alt='\$CCL_LogoAlt' style='border-width:0' src='\$CCL_LogoImg' />
  </a>
  <span xmlns:dct='http://purl.org/dc/terms/' href='http://purl.org/dc/dcmitype/Text' property='dct:title' rel='dct:type'><a href='\$CCL_Work'>\$CCL_Title</a></span> by <a xmlns:cc='http://creativecommons.org/ns#' href='\$CCL_AuthorUrl' property='cc:attributionName' rel='cc:attributionURL'>\$CCL_Author</a> is licensed under a <a rel='license' href='\$CCL_URL'>Creative Commons \$CCL_string 3.0 Unported License</a>. Permissions beyond the scope of this license may be available at <a xmlns:cc='http://creativecommons.org/ns#' href='\$CCL_Permissions' rel='cc:morePermissions'>Permissions</a>.";

  $args = array_merge($defaults, ParseArgs($parameters));
  $replacements = array();
  $replacements['$CCL_Title'] = $args['title'];
  $replacements['$CCL_Work'] = $args['work'];
  // NOTE: more precise replacement must preced less precise replacement
  $replacements['$CCL_AuthorUrl'] = $args['authorurl'];
  $replacements['$CCL_Author'] = $args['author'];
  $replacements['$CCL_Permissions'] = $args['permissions'];
  $replacements['$CCL_string'] = (isset($license_strings[$args['type']]) ? $license_strings[$args['type']] : 'Unknown');
  $replacements['$CCL_URL'] = "http://creativecommons.org/licenses/{$args['type']}/3.0/";
  $replacements['$CCL_LogoImg'] = "http://i.creativecommons.org/l/{$args['type']}/3.0/80x15.png";
  $replacements['$CCL_LogoAlt'] = "Creative Commons Licence";
  $return_text = str_replace(array_keys($replacements),array_values($replacements),$LicenseFmt);
  return Keep($return_text);
}

Configuration

No configuration to speak of...

Usage

To use, put the following in your wiki text:

(:cc-license type=(by|by-nc|by-nc-sa) title=<name of work> work=<URL of work> author=<name of author> authorurl=<link to author's contact page> permissions=<link to more permissions page>:)

Defaults

The following parameters have defaults:

type
by-nc-sa
title
Whatever $WikiTitle is set to
work
Whatever $ScriptUrl is set to
author
"Anonymous"
authorurl
nothing (blank)
permissions
link to {$ScriptUrl}?n=Site.Permissions

Examples

To use most of the defaults

(:cc-license author="Tamara Temple" authorurl="http://wiki.tamaratemple.com/Profiles/Tamara":)

Notes

Change log / Release notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also

Contributors

Comments

See discussion at CreativeCommonsLicenseDisplay-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.