summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2009-04-16 10:57:35 -0400
committerStephen Paul Weber <singpolyma@singpolyma.net>2009-10-23 21:22:26 -0400
commit58b9ce5946c5fea9b6f1a9f1c0c9641c5104d769 (patch)
tree91ee9e24ca828ce4a1ebf6e8788bbe865e01711c /lib
parent6d6de3c1c7b359815aa0381b4cde3fcc8258cc80 (diff)
Better license check.
Tokenise CC license parts and check for compatability. Fallback is old directly-equal test.
Diffstat (limited to 'lib')
-rw-r--r--lib/util.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/util.php b/lib/util.php
index b6e89f0bd..00696583e 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -1360,9 +1360,28 @@ function common_memcache()
}
}
+function common_license_terms($uri)
+{
+ if(preg_match('/creativecommons.org\/licenses\/([^\/]+)/', $uri, $matches)) {
+ return explode('-',$matches[1]);
+ }
+ return array($uri);
+}
+
function common_compatible_license($from, $to)
{
+ $from_terms = common_license_terms($from);
+ // public domain and cc-by are compatible with everything
+ if(count($from_terms) == 1 && ($from_terms[0] == 'publicdomain' || $from_terms[0] == 'by')) {
+ return true;
+ }
+ $to_terms = common_license_terms($to);
+ // sa is compatible across versions. IANAL
+ if(in_array('sa',$from_terms) || in_array('sa',$to_terms)) {
+ return count(array_diff($from_terms, $to_terms)) == 0;
+ }
// XXX: better compatibility check needed here!
+ // Should at least normalise URIs
return ($from == $to);
}