licenses.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. define('BY1', 1);
  3. define('BY2', 2);
  4. define('BY21', 3);
  5. define('BY25', 4);
  6. define('BY3', 5);
  7. define('BYSA1', 6);
  8. define('BYSA2', 7);
  9. define('BYSA21', 8);
  10. define('BYSA25', 9);
  11. define('BYSA3', 10);
  12. define('LAL', 11);
  13. define('PD', 12);
  14. define('CC0', 13);
  15. define('BY4', 14);
  16. define('BYSA4', 15);
  17. // Arrays containing regular expressions for each license type
  18. // (so we can support multiple URL formats in the future if needed)
  19. $by1 = array('http://creativecommons.org/licenses/by/1.0/?.*');
  20. $by2 = array('http://creativecommons.org/licenses/by/2.0/?.*');
  21. $by21 = array('http://creativecommons.org/licenses/by/2.1/?.*');
  22. $by25 = array('http://creativecommons.org/licenses/by/2.5/?.*');
  23. $by3 = array('http://creativecommons.org/licenses/by/3.0/?.*');
  24. $bysa1 = array('http://creativecommons.org/licenses/by-sa/1.0/?.*');
  25. $bysa2 = array('http://creativecommons.org/licenses/by-sa/2.0/?.*');
  26. $bysa21 = array('http://creativecommons.org/licenses/by-sa/2.1/?.*');
  27. $bysa25 = array('http://creativecommons.org/licenses/by-sa/2.5/?.*');
  28. $bysa3 = array('http://creativecommons.org/licenses/by-sa/3.0/?.*');
  29. $lal = array('http://artlibre.org/licence.php/lal.html');
  30. $pd = array('http://creativecommons.org/licenses/publicdomain/?.*');
  31. $cc0 = array('http://creativecommons.org/publicdomain/zero/?.*');
  32. $by4 = array('http://creativecommons.org/licenses/by/4.0/?.*');
  33. $bysa4 = array('http://creativecommons.org/licenses/by-sa/4.0/?.*');
  34. // map licenses to ids by array position
  35. $licenses = array(array(), $by1, $by2, $by21, $by25, $by3, $bysa1, $bysa2, $bysa21, $bysa25, $bysa3, $lal, $pd, $cc0, $by4, $bysa4);
  36. function simplify_license($license) {
  37. global $licenses;
  38. foreach ($licenses as $key => $l) {
  39. foreach ($l as $urlschema) {
  40. if (preg_match("|$urlschema|", $license)) {
  41. return $key;
  42. }
  43. }
  44. }
  45. return 0;
  46. }
  47. /**
  48. * Returns true if the supplied license is one that we accept as being free
  49. *
  50. * @param $license string containing a license URL
  51. * @return bool whether this license is free or not
  52. */
  53. function is_free_license($license) {
  54. global $licenses;
  55. foreach ($licenses as $key => $l) {
  56. foreach ($l as $urlschema) {
  57. if (preg_match("|$urlschema|", $license)) {
  58. return true;
  59. }
  60. }
  61. }
  62. return false;
  63. }