From 42e0c99fd31625115bc89f7c105c7e8d167515b0 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 30 May 2017 14:12:22 +0200 Subject: [PATCH] Add version info to license HFP-1079 --- h5p.classes.php | 87 ++++++++++++++++++++----- js/h5p.js | 170 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 214 insertions(+), 43 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index d39393d..61f6be2 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -3928,6 +3928,29 @@ class H5PContentValidator { static $semantics; if ($semantics === NULL) { + $cc_versions = array( + (object) array( + 'value' => '4.0', + 'label' => '4.0 International' + ), + (object) array( + 'value' => '3.0', + 'label' => '3.0 Unported' + ), + (object) array( + 'value' => '2.5', + 'label' => '2.5 Generic' + ), + (object) array( + 'value' => '2.0', + 'label' => '2.0 Generic' + ), + (object) array( + 'value' => '1.0', + 'label' => '1.0 Generic' + ) + ); + $semantics = (object) array( 'name' => 'copyright', 'type' => 'group', @@ -3977,49 +4000,81 @@ class H5PContentValidator { ), (object) array( 'value' => 'CC BY', - 'label' => $this->h5pF->t('Attribution 4.0') + 'label' => $this->h5pF->t('Attribution'), + 'versions' => $cc_versions ), (object) array( 'value' => 'CC BY-SA', - 'label' => $this->h5pF->t('Attribution-ShareAlike 4.0') + 'label' => $this->h5pF->t('Attribution-ShareAlike'), + 'versions' => $cc_versions ), (object) array( 'value' => 'CC BY-ND', - 'label' => $this->h5pF->t('Attribution-NoDerivs 4.0') + 'label' => $this->h5pF->t('Attribution-NoDerivs'), + 'versions' => $cc_versions ), (object) array( 'value' => 'CC BY-NC', - 'label' => $this->h5pF->t('Attribution-NonCommercial 4.0') + 'label' => $this->h5pF->t('Attribution-NonCommercial'), + 'versions' => $cc_versions ), (object) array( 'value' => 'CC BY-NC-SA', - 'label' => $this->h5pF->t('Attribution-NonCommercial-ShareAlike 4.0') + 'label' => $this->h5pF->t('Attribution-NonCommercial-ShareAlike'), + 'versions' => $cc_versions ), (object) array( 'value' => 'CC BY-NC-ND', - 'label' => $this->h5pF->t('Attribution-NonCommercial-NoDerivs 4.0') + 'label' => $this->h5pF->t('Attribution-NonCommercial-NoDerivs'), + 'versions' => $cc_versions ), (object) array( 'value' => 'GNU GPL', - 'label' => $this->h5pF->t('General Public License v3') + 'label' => $this->h5pF->t('General Public License'), + 'versions' => array( + (object) array( + 'value' => 'v3', + 'label' => 'Version 3' + ), + (object) array( + 'value' => 'v2', + 'label' => 'Version 2' + ), + (object) array( + 'value' => 'v1', + 'label' => 'Version 1' + ) + ) ), (object) array( 'value' => 'PD', - 'label' => $this->h5pF->t('Public Domain') - ), - (object) array( - 'value' => 'ODC PDDL', - 'label' => $this->h5pF->t('Public Domain Dedication and Licence') - ), - (object) array( - 'value' => 'CC PDM', - 'label' => $this->h5pF->t('Public Domain Mark') + 'label' => $this->h5pF->t('Public Domain'), + 'versions' => array( + (object) array( + 'value' => '-', + 'label' => '-' + ), + (object) array( + 'value' => 'CC0 1.0', + 'label' => 'CC0 1.0 Universal' + ), + (object) array( + 'value' => 'CC PDM', + 'label' => 'Public Domain Mark' + ) + ) ), (object) array( 'value' => 'C', 'label' => $this->h5pF->t('Copyright') ) ) + ), + (object) array( + 'name' => 'version', + 'type' => 'select', + 'label' => $this->h5pF->t('License Version'), + 'options' => array() ) ) ); diff --git a/js/h5p.js b/js/h5p.js index 36e2709..25119ef 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -1245,16 +1245,68 @@ H5P.MediaCopyright = function (copyright, labels, order, extraFields) { }; /** - * Get humanized value for field. + * Get humanized value for the license field. * * @private - * @param {string} fieldName - * @param {string} value + * @param {string} license + * @param {string} [version] * @returns {string} */ - var humanizeValue = function (fieldName, value) { - if (fieldName === 'license') { - return H5P.copyrightLicenses[value]; + var humanizeLicense = function (license, version) { + var copyrightLicense = H5P.copyrightLicenses[license]; + if (copyrightLicense.label === undefined) { + return copyrightLicense; + } + + // Build license string + var value = ''; + if (!(license === 'PD' && version)) { + // Add license label + value += (copyrightLicense.label ? copyrightLicense.label : copyrightLicense); + } + + // Check for version info + var versionInfo; + if (version && copyrightLicense.versions[version]) { + versionInfo = copyrightLicense.versions[version]; + } + + if (versionInfo) { + // Add license version + if (value) { + value += ' '; + } + value += (versionInfo.label ? versionInfo.label : versionInfo); + } + + // Add link if specified + var link; + if (copyrightLicense.link) { + link = copyrightLicense.link.replace(':version', copyrightLicense.linkVersions ? copyrightLicense.linkVersions[version] : version); + } + else if (versionInfo && versionInfo.link) { + link = versionInfo.link + } + if (link) { + value = '' + value + ''; + } + + // Generate parenthesis + var parenthesis = ''; + if (license !== 'PD' && license !== 'C') { + parenthesis += license; + } + if (version && version !== 'CC0 1.0') { + if (parenthesis && license !== 'GNU GPL') { + parenthesis += ' '; + } + parenthesis += version; + } + if (parenthesis) { + value += ' (' + parenthesis + ')'; + } + if (license === 'C') { + value += ' ©'; } return value; @@ -1276,7 +1328,11 @@ H5P.MediaCopyright = function (copyright, labels, order, extraFields) { for (var i = 0; i < order.length; i++) { var fieldName = order[i]; if (copyright[fieldName] !== undefined) { - list.add(new H5P.Field(getLabel(fieldName), humanizeValue(fieldName, copyright[fieldName]))); + var humanValue = copyright[fieldName]; + if (fieldName === 'license') { + humanValue = humanizeLicense(copyright.license, copyright.version); + } + list.add(new H5P.Field(getLabel(fieldName), humanValue)); } } } @@ -1299,7 +1355,7 @@ H5P.MediaCopyright = function (copyright, labels, order, extraFields) { this.undisclosed = function () { if (list.size() === 1) { var field = list.get(0); - if (field.getLabel() === getLabel('license') && field.getValue() === humanizeValue('license', 'U')) { + if (field.getLabel() === getLabel('license') && field.getValue() === humanizeLicense('U')) { return true; } } @@ -1331,25 +1387,85 @@ H5P.MediaCopyright = function (copyright, labels, order, extraFields) { }; }; -/** - * Maps copyright license codes to their human readable counterpart. - * - * @type {Object} - */ -H5P.copyrightLicenses = { - 'U': 'Undisclosed', - 'CC BY': 'Attribution 4.0', - 'CC BY-SA': 'Attribution-ShareAlike 4.0', - 'CC BY-ND': 'Attribution-NoDerivs 4.0', - 'CC BY-NC': 'Attribution-NonCommercial 4.0', - 'CC BY-NC-SA': 'Attribution-NonCommercial-ShareAlike 4.0', - 'CC BY-NC-ND': 'Attribution-NonCommercial-NoDerivs 4.0', - 'GNU GPL': 'General Public License v3', - 'PD': 'Public Domain', - 'ODC PDDL': 'Public Domain Dedication and Licence', - 'CC PDM': 'Public Domain Mark', - 'C': 'Copyright' -}; +(function () { + var ccVersions = { + '4.0': '4.0 International', + '3.0': '3.0 Unported', + '2.5': '2.5 Generic', + '2.0': '2.0 Generic', + '1.0': '1.0 Generic' + }; + + /** + * Maps copyright license codes to their human readable counterpart. + * + * @type {Object} + */ + H5P.copyrightLicenses = { + 'U': 'Undisclosed', + 'CC BY': { + label: 'Attribution', + link: 'http://creativecommons.org/licenses/by/:version/legalcode', + versions: ccVersions + }, + 'CC BY-SA': { + label: 'Attribution-ShareAlike', + link: 'http://creativecommons.org/licenses/by-sa/:version/legalcode', + versions: ccVersions + }, + 'CC BY-ND': { + label: 'Attribution-NoDerivs', + link: 'http://creativecommons.org/licenses/by-nd/:version/legalcode', + versions: ccVersions + }, + 'CC BY-NC': { + label: 'Attribution-NonCommercial', + link: 'http://creativecommons.org/licenses/by-nc/:version/legalcode', + versions: ccVersions + }, + 'CC BY-NC-SA': { + label: 'Attribution-NonCommercial-ShareAlike', + link: 'http://creativecommons.org/licenses/by-nc-sa/:version/legalcode', + versions: ccVersions + }, + 'CC BY-NC-ND': { + label: 'Attribution-NonCommercial-NoDerivs', + link: 'http://creativecommons.org/licenses/by-nc-nd/:version/legalcode', + versions: ccVersions + }, + 'GNU GPL': { + label: 'General Public License', + link: 'http://www.gnu.org/licenses/gpl-:version-standalone.html', + linkVersions: { + 'v3': '3.0', + 'v2': '2.0', + 'v1': '1.0' + }, + versions: { + 'v3': 'Version 3', + 'v2': 'Version 2', + 'v1': 'Version 1' + } + }, + 'PD': { + label: 'Public Domain', + versions: { + 'CC0 1.0': { + label: 'CC0 1.0 Universal (CC0 1.0) Public Domain Dedication', + link: 'https://creativecommons.org/publicdomain/zero/1.0/' + }, + 'CC PDM': { + label: 'Public Domain Mark', + link: 'https://creativecommons.org/publicdomain/mark/1.0/' + } + } + }, + 'ODC PDDL': 'Public Domain Dedication and Licence', + 'CC PDM': 'Public Domain Mark', + 'C': 'Copyright' + }; + +})(); /** * A simple and elegant class for creating thumbnails of images.