| 1 | # CCLicense Plugin for version-conscious CCLicense tags |
|---|
| 2 | # |
|---|
| 3 | # Release 0.02 (Jun 13, 2005) |
|---|
| 4 | # |
|---|
| 5 | # This software is provided as-is. You may use it for commercial or |
|---|
| 6 | # personal use. If you distribute it, please keep this notice intact. |
|---|
| 7 | # |
|---|
| 8 | # Copyright (c) 2005 Hirotaka Ogawa |
|---|
| 9 | |
|---|
| 10 | package MT::Plugin::CCLicense; |
|---|
| 11 | use strict; |
|---|
| 12 | |
|---|
| 13 | my $CCL_VERSION = '2.5'; |
|---|
| 14 | my $CCL_LANG = ''; |
|---|
| 15 | my $USE_CCL2_IMG = 0; # If you want to use CCL2 image, set this to "1" |
|---|
| 16 | |
|---|
| 17 | eval { |
|---|
| 18 | require MT::Plugin; |
|---|
| 19 | my $plugin = new MT::Plugin(); |
|---|
| 20 | $plugin->name("CCLicense Plugin 0.02"); |
|---|
| 21 | $plugin->description("CCLicense tags for CCL version $CCL_VERSION" . |
|---|
| 22 | ($CCL_LANG ? "/$CCL_LANG" : "")); |
|---|
| 23 | MT->add_plugin($plugin); |
|---|
| 24 | }; |
|---|
| 25 | |
|---|
| 26 | use MT::Util; |
|---|
| 27 | use MT::Template::Context; |
|---|
| 28 | { |
|---|
| 29 | local $SIG{__WARN__} = sub { }; |
|---|
| 30 | *MT::Util::cc_url = \&_cc_url; |
|---|
| 31 | *MT::Template::Context::_hdlr_blog_cc_license_image = \&_cc_img_url; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | sub _cc_url { |
|---|
| 35 | my $cc = $_[0] or return; |
|---|
| 36 | my ($code, $cc_url, $cc_img_url) = $cc =~ /(\S+) (\S+) (\S+)/; |
|---|
| 37 | $cc = $code || $cc; |
|---|
| 38 | $cc eq 'pd' ? |
|---|
| 39 | "http://web.resource.org/cc/PublicDomain" : |
|---|
| 40 | "http://creativecommons.org/licenses/$cc/$CCL_VERSION/" . |
|---|
| 41 | ($CCL_LANG ? "$CCL_LANG/" : ""); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | sub _cc_img_url { |
|---|
| 45 | require MT::Blog; |
|---|
| 46 | my $cc = $_[0]->stash('blog')->cc_license or return; |
|---|
| 47 | my ($code, $cc_url, $cc_img_url) = $cc =~ /(\S+) (\S+) (\S+)/; |
|---|
| 48 | $cc = $code || $cc; |
|---|
| 49 | "http://creativecommons.org/images/public/" . |
|---|
| 50 | ($cc eq 'pd' ? 'norights.gif' : |
|---|
| 51 | ($USE_CCL2_IMG ? 'somerights20.gif' : 'somerights.gif')); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | 1; |
|---|