Created
February 17, 2021 12:36
-
-
Save gaffling/3a1690fd5e8f55d1ec1dc0216570f3ac to your computer and use it in GitHub Desktop.
[CC LICENSES] Print CC License Image from given Parameter #php #function #cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* ---------------------------------------------------------------------------- */ | |
/* [CC LICENSES] Print CC License Image from given Parameter #php #function #cc */ | |
/* ---------------------------------------------------------------------------- */ | |
/** | |
* creativecommonsLicense() CC LICENSES INFO HTML | |
* @see https://de.wikipedia.org/wiki/Creative_Commons | |
* @param integer $adaptations [1-3] | |
* @param boolean $commercial [true or false] | |
* @param string $size ['small' or 'big'] | |
* @return string [html] | |
*/ | |
function creativecommonsLicense($adaptations=1, $commercial=true, $size='small') { | |
if (($adaptations >= 0) and ($adaptations <= 3) and ($commercial == true or $commercial == false) and ($size == 'small' or $size == 'big')) { | |
$html = '<a rel="license" href="http://creativecommons.org/licenses/REPLACE/4.0/">'; | |
$html .= '<img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/REPLACE/4.0/DIMENSIONS.png" />'; | |
$html .= '</a>'; | |
if (strtolower($size) == 'small') { | |
$dimensions = '80x15'; | |
} else { | |
$dimensions = '88x31'; | |
} | |
if ($adaptations == 1 and $commercial == true) { // Attribution (Namensnennung) | |
$license = 'by'; | |
} | |
if ($adaptations == 2 and $commercial == true) { // Attribution (Namensnennung), Sharing under same conditions (Weitergabe unter gleichen Bedingungen) | |
$license = 'by-sa'; | |
} | |
if ($adaptations == 3 and $commercial == true) { // Attribution (Namensnennung), No editing (keine Bearbeitung) | |
$license = 'by-nd'; | |
} | |
if ($adaptations == 1 and $commercial == false) { // Attribution (Namensnennung), Non commercial use (nicht kommerziell) | |
$license = 'by-nc'; | |
} | |
if ($adaptations == 2 and $commercial == false) { // Attribution (Namensnennung), Non commercial use (nicht kommerziell), Sharing under same conditions (Weitergabe unter gleichen Bedingungen) | |
$license = 'by-nc-sa'; | |
} | |
if ($adaptations == 3 and $commercial == false) { // Attribution (Namensnennung), Non commercial use (nicht kommerziell), No editing (keine Bearbeitung) | |
$license = 'by-nc-nd'; | |
} | |
} else { | |
$html = 'ERROR creativecommonsLicense()'; | |
} | |
$html = str_replace('REPLACE', $license, $html); | |
$html = str_replace('DIMENSIONS', $dimensions, $html); | |
return $html; | |
} | |
echo creativecommonsLicense(1, true, 'small').'<br />'; | |
echo creativecommonsLicense(2, true, 'small').'<br />'; | |
echo creativecommonsLicense(3, true, 'small').'<br />'; | |
echo creativecommonsLicense(1, false, 'small').'<br />'; | |
echo creativecommonsLicense(2, false, 'small').'<br />'; | |
echo creativecommonsLicense(3, false, 'small').'<br />'; | |
echo '<br />'; | |
echo creativecommonsLicense(1, true, 'big').'<br />'; | |
echo creativecommonsLicense(2, true, 'big').'<br />'; | |
echo creativecommonsLicense(3, true, 'big').'<br />'; | |
echo creativecommonsLicense(1, false, 'big').'<br />'; | |
echo creativecommonsLicense(2, false, 'big').'<br />'; | |
echo creativecommonsLicense(3, false, 'big').'<br />'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment