[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: serendipity_event_creativecommons.php 1637 2007-03-01 11:06:56Z garvinhicking $ 2 3 4 if (IN_serendipity !== true) { 5 die ("Don't hack!"); 6 } 7 8 // Probe for a language include with constants. Still include defines later on, if some constants were missing 9 $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php'; 10 if (file_exists($probelang)) { 11 include $probelang; 12 } 13 14 include dirname(__FILE__) . '/lang_en.inc.php'; 15 16 class serendipity_event_creativecommons extends serendipity_event { 17 var $title = PLUGIN_CREATIVECOMMONS_NAME; 18 19 function introspect(&$propbag) 20 { 21 22 $propbag->add('name', PLUGIN_CREATIVECOMMONS_NAME); 23 $propbag->add('description', PLUGIN_CREATIVECOMMONS_DESC); 24 $propbag->add('stackable', false); 25 $propbag->add('author', 'Evan Nemerson'); 26 $propbag->add('version', '1.3'); 27 $propbag->add('requirements', array( 28 'serendipity' => '0.8', 29 'smarty' => '2.6.7', 30 'php' => '4.1.0' 31 )); 32 $propbag->add('configuration', array('nc', 'nd', 'txt', 'cc_v2')); 33 $propbag->add('event_hooks', 34 array('frontend_display:rss-1.0:per_entry' => true, 35 'frontend_display:rss-1.0:once' => true, 36 'frontend_display:rss-1.0:namespace' => true, 37 'frontend_display:rss-2.0:per_entry' => true, 38 'frontend_display:rss-2.0:namespace' => true, 39 'frontend_display:html:per_entry' => true, 40 'frontend_display:html_layout' => true)); 41 $propbag->add('groups', array('FRONTEND_EXTERNAL_SERVICES')); 42 } 43 44 function introspect_config_item($name, &$propbag) 45 { 46 switch($name) { 47 /* 48 case 'by': 49 $propbag->add('type', 'boolean'); 50 $propbag->add('name', PLUGIN_CREATIVECOMMONS_BY); 51 $propbag->add('description', PLUGIN_CREATIVECOMMONS_BY_DESC); 52 break; 53 */ 54 55 case 'cc_v2': 56 $propbag->add('type', 'hidden'); 57 $propbag->add('value', 'true'); 58 break; 59 60 case 'nc': 61 $propbag->add('type', 'boolean'); 62 $propbag->add('name', PLUGIN_CREATIVECOMMONS_NC); 63 $propbag->add('description', PLUGIN_CREATIVECOMMONS_NC_DESC); 64 $propbag->add('default', 'true'); 65 break; 66 67 case 'nd': 68 $propbag->add('type', 'radio'); 69 $propbag->add('name', PLUGIN_CREATIVECOMMONS_ND); 70 $propbag->add('description', PLUGIN_CREATIVECOMMONS_ND_DESC); 71 $propbag->add('radio', array( 72 'value' => array('yes', 'sa', 'no'), 73 'desc' => array(YES, PLUGIN_CREATIVECOMMONS_SA_DESC, NO) 74 )); 75 $propbag->add('radio_per_row', '1'); 76 $propbag->add('default', 'yes'); 77 78 break; 79 80 case 'txt': 81 $propbag->add('type', 'boolean'); 82 $propbag->add('name', PLUGIN_CREATIVECOMMONS_TXT); 83 $propbag->add('description', PLUGIN_CREATIVECOMMONS_TXT_DESC); 84 $propbag->add('default', 'true'); 85 break; 86 87 default: 88 return false; 89 break; 90 } 91 return true; 92 } 93 94 function generate_content(&$title) { 95 $title = $this->title; 96 } 97 98 function event_hook($event, &$bag, &$eventData) { 99 global $serendipity; 100 101 $license_data = $this->get_license_data(); 102 $license_version = $this->get_config('cc_version', '1.0'); 103 $license_type = $license_data['type']; 104 $license_string = $license_data['string']; 105 $rdf = $license_data['rdf']; 106 107 if ($license_string == '') { 108 $license_uri = 'http://web.resource.org/cc/PublicDomain'; 109 } else { 110 $license_uri = 'http://creativecommons.org/licenses/'.$license_string.'/'.$license_version.'/'; 111 switch ($serendipity['lang']){ 112 case 'ja': 113 $license_uri .= 'jp/'; 114 break; 115 case 'de': 116 $license_uri .= 'deed.de'; 117 break; 118 } 119 } 120 121 $cc_visibility = 'invisible'; 122 123 switch ($event) { 124 case 'frontend_display:html_layout': 125 $cc_visibility = 'visible'; 126 case 'frontend_display:html:per_entry': 127 $eventData['display_dat'] .= '<div style="text-align: center;">'; 128 if ($license_string == '') { 129 if ($cc_visibility == 'visible') { 130 $eventData['display_dat'] .= '<a href="http://creativecommons.org/licenses/publicdomain">'; 131 $eventData['display_dat'] .= '<img style="border: 0px" alt="No Rights Reserved" src="' . serendipity_getTemplateFile('img/norights.png') .'" />'; 132 $eventData['display_dat'] .= '</a>'; 133 if (serendipity_db_bool($this->get_config('txt', true))) { 134 $eventData['display_dat'] .= '<br />' . str_replace('#license_uri#', $license_uri, PLUGIN_CREATIVECOMMONS_CAP_PD); 135 } 136 } 137 } elseif ($cc_visibility == 'visible') { 138 $eventData['display_dat'] .= '<a href="'.$license_uri.'">'; 139 $eventData['display_dat'] .= '<img style="border: 0px" alt="Creative Commons License - Some Rights Reserved" src="' . serendipity_getTemplateFile('img/somerights20.gif') .'" />'; 140 $eventData['display_dat'] .= '</a>'; 141 if (serendipity_db_bool($this->get_config('txt', true))) { 142 $eventData['display_dat'] .= '<br />' . str_replace('#license_uri#', $license_uri, PLUGIN_CREATIVECOMMONS_CAP); 143 } 144 } 145 146 $eventData['display_dat'] .= '<!-- <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><Work rdf:about=""><license rdf:resource="'.$license_uri.'"/></Work><License rdf:about="'.$license_uri.'">'; 147 if (is_array($rdf)) { 148 foreach ($rdf as $rdf_t => $rdf_v) { 149 $eventData['display_dat'] .= ' <'.$rdf_v.' rdf:resource="http://web.resource.org/cc/'.$rdf_t.'" />'; 150 } 151 } 152 153 $eventData['display_dat'] .= '</License></rdf:RDF> -->'; 154 $eventData['display_dat'] .= '</div>'; 155 return true; 156 break; 157 158 case 'frontend_display:rss-2.0:per_entry': 159 $eventData['display_dat'] .= '<creativeCommons:license>'.$license_uri.'</creativeCommons:license>'; 160 return true; 161 break; 162 163 case 'frontend_display:rss-1.0:per_entry': 164 $eventData['display_dat'] .= '<cc:license rdf:resource="'.$license_uri.'" />'; 165 return true; 166 break; 167 168 case 'frontend_display:rss-1.0:once': 169 $eventData['display_dat'] .= '<cc:License rdf:about="'.$license_uri.'">'; 170 if (is_array($rdf)) { 171 foreach ($rdf as $rdf_t => $rdf_v) { 172 $eventData['display_dat'] .= '<cc:'.$rdf_v.' rdf:resource="http://web.resource.org/cc/'.$rdf_t.'" />'; 173 } 174 } 175 $eventData['display_dat'] .= '</cc:License>'; 176 return true; 177 break; 178 179 case 'frontend_display:rss-2.0:namespace': 180 $eventData['display_dat'] .= 'xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"'; 181 return true; 182 break; 183 184 case 'frontend_display:rss-1.0:namespace': 185 $eventData['display_dat'] .= 'xmlns:cc="http://web.resource.org/cc/"'; 186 return true; 187 break; 188 189 default: 190 return true; 191 break; 192 } 193 } 194 195 function get_license_data() { 196 $license_type = array(); 197 $license_version = $this->get_config('cc_version', '1.0'); 198 199 if ( ($license_version < 2.5) && ($this->get_config('cc_v2', 'false') == 'true') ) { 200 $this->set_config('cc_version', '2.5'); 201 $license_version = '2.5'; 202 } 203 204 if (($license_version >= 2.5) || serendipity_db_bool($this->get_config('by', true))) { 205 $license_type[] = 'by'; 206 } 207 208 if (!serendipity_db_bool($this->get_config('nc', true))) { 209 $license_type[] = 'nc'; 210 } 211 212 if ($this->get_config('nd') == 'no') { 213 $license_type[] = 'nd'; 214 } 215 216 217 if ($this->get_config('nd') == 'sa') { 218 $license_type[] = 'sa'; 219 } 220 221 $license_string = implode('-', $license_type); 222 223 switch ($license_string) { 224 case 'by': 225 $rdf = array( 226 'Attribution' => 'requires', 227 'Reproduction' => 'permits', 228 'Distribution' => 'permits', 229 'DerivativeWorks' => 'permits', 230 'Notice' => 'requires' 231 ); 232 break; 233 234 case 'by-nd': 235 $rdf = array( 236 'Attribution' => 'requires', 237 'Reproduction' => 'permits', 238 'Distribution' => 'permits', 239 'Notice' => 'requires' 240 ); 241 break; 242 243 case 'by-nd-nc': 244 $rdf = array( 245 'Attribution' => 'requires', 246 'Reproduction' => 'permits', 247 'Distribution' => 'permits', 248 'CommercialUse' => 'prohibits', 249 'Notice' => 'requires' 250 ); 251 break; 252 253 case 'by-nc': 254 $rdf = array( 255 'Attribution' => 'requires', 256 'Reproduction' => 'permits', 257 'Distribution' => 'permits', 258 'DerivativeWorks' => 'permits', 259 'CommercialUse' => 'prohibits', 260 'Notice' => 'requires' 261 ); 262 break; 263 264 case 'by-nc-sa': 265 $rdf = array( 266 'Attribution' => 'requires', 267 'Reproduction' => 'permits', 268 'Distribution' => 'permits', 269 'DerivativeWorks' => 'permits', 270 'ShareAlike' => 'requires', 271 'CommercialUse' => 'prohibits', 272 'Notice' => 'requires' 273 ); 274 break; 275 276 case 'by-sa': 277 $rdf = array( 278 'Attribution' => 'requires', 279 'Reproduction' => 'permits', 280 'Distribution' => 'permits', 281 'DerivativeWorks' => 'permits', 282 'ShareAlike' => 'requires', 283 'Notice' => 'requires' 284 ); 285 break; 286 287 case 'nd': 288 $rdf = array( 289 'Reproduction' => 'permits', 290 'Distribution' => 'permits', 291 'Notice' => 'requires' 292 ); 293 break; 294 295 case 'nd-nc': 296 $rdf = array( 297 'Reproduction' => 'permits', 298 'Distribution' => 'permits', 299 'CommercialUse' => 'prohibits', 300 'Notice' => 'requires' 301 ); 302 break; 303 304 case 'nc': 305 $rdf = array( 306 'Reproduction' => 'permits', 307 'Distribution' => 'permits', 308 'DerivativeWorks' => 'permits', 309 'CommercialUse' => 'prohibits', 310 'Notice' => 'requires' 311 ); 312 break; 313 314 case 'nc-sa': 315 $rdf = array( 316 'Reproduction' => 'permits', 317 'Distribution' => 'permits', 318 'DerivativeWorks' => 'permits', 319 'ShareAlike' => 'requires', 320 'CommercialUse' => 'prohibits', 321 'Notice' => 'requires' 322 ); 323 break; 324 325 case 'sa': 326 $rdf = array( 327 'Reproduction' => 'permits', 328 'Distribution' => 'permits', 329 'DerivativeWorks' => 'permits', 330 'ShareAlike' => 'requires', 331 'Notice' => 'requires' 332 ); 333 break; 334 335 case '': 336 $rdf = array( 337 'Reproduction' => 'permits', 338 'Distribution' => 'permits', 339 'DerivativeWorks' => 'permits' 340 ); 341 break; 342 } 343 344 return array( 345 'type' => $license_type, 346 'string' => $license_string, 347 'rdf' => $rdf 348 ); 349 } 350 } 351 352 /* vim: set sts=4 ts=4 expandtab : */ 353 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |