1<?php 2 3/** 4 * @author Stefan Jahn 5 * @copyright Copyright (C) 2005 Stefan Jahn 6 * @link http://www.stefanjahn.de 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @version 20060731 9 * 10 * Datei dwgallery.php 11 * Erstellt am 20.12.2005 12 * 13 * Plugin für DokuWiki. Erstellt aus den Bildern eines Namensraums eine 14 * Galerie. Auf Wunsch werden die Thumbnails permanent abgespeichert. 15 * 16 * This program is free software; you can redistribute it and/or 17 * modify it under the terms of the GNU General Public License 18 * as published by the Free Software Foundation; either version 2 19 * of the License, or (at your option) any later version. 20 * 21 * This program is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * You should have received a copy of the GNU General Public License 27 * along with this program; if not, write to the Free Software 28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 29 */ 30 31 32/** 33 * Einstellungen vornehmen 34 * 35 * @return array 36 */ 37function gallery_init() { 38 global $conf; 39 40 // Namensraum der für Galerien vorbehalten ist 41 $gallery['namespace'] = 'Fotos'; 42 43 // Diverse Meldungen 44 $gallery['nopicture'] = 'Es sind noch keine Bilder vorhanden.'; 45 $gallery['picturename'] = 'Bild #'; 46 $gallery['of'] = 'von'; 47 $gallery['content'] = 'Übersicht'; 48 $gallery['city'] = 'Ort'; 49 $gallery['country'] = 'Land'; 50 $gallery['count'] = 'Anzahl der Bilder:'; 51 52 // HTML-Codes 53 $gallery['titlestart'] = '<h2>'; // Überschrift Start 54 $gallery['titleend'] = '</h2>'; // Überschrift Ende 55 $gallery['displaystart'] = '<div class="level2">'; // Start der Ausgabe 56 $gallery['displayend'] = '</div>'; // Ende der Ausgabe 57 58 $gallery['exif'] = TRUE; // EXIF-Unterstützung 59 $gallery['iptc'] = TRUE; // IPTC-Unterstützung 60 61 $gallery['savethumbs'] = FALSE; // Thumbnails erstellen und abspeichern 62 $gallery['thumbwidth'] = 100; // Breite der Thumbnails 63 64 $gallery['randomwidth'] = 150; // Breiter der Thumbails der Zufallbilder 65 $gallery['index'] = 'index.txt'; // Liste mit den Zufallsbildern 66 67 // Eigene Einstellungen vornehmen 68 @require_once('config.php'); 69 70 // Pfad zum Datenverzeichnis 71 $dir = trim($conf['savedir']); 72 if ($dir{0} == '.') $dir = substr($dir, 1); 73 if ($dir{0} == '/') $dir = substr($dir, 1); 74 if ($dir{strlen($dir)-1} == '/') $dir = substr($dir, 0, strlen($dir)-1); 75 $gallery['datadir'] = $dir; 76 77 return $gallery; 78} 79 80 81/** 82 * Hauptroutine - Galerie starten 83 * 84 * Funktion wird im Template "main.php" aufgerufen 85 */ 86function tpl_gallery() { 87 global $ID; 88 global $ACT; 89 global $conf; 90 global $INFO; 91 92 // Werte einstellen 93 $gallery = gallery_init(); 94 95 // Galerie nur anzeigen wenn Seite nicht bearbeitet wird und Seite vorhanden ist 96 if ($ACT != 'show' or $INFO['exists'] != 1) return; 97 98 // Galerie nur anzeigen wenn man sich im korrekten Namespace befindet 99 $array_id = split(':', $ID); 100 if (strtolower($array_id[0]) != strtolower($gallery['namespace'])) return; 101 102 // Parameter einlesen 103 $gallery['pic'] = $_GET['pic']; 104 105 // Name der Seite ermitteln 106 $gallery['name'] = $array_id[count($array_id)-1]; 107 108 // Galerie nicht anzeigen wenn eine "Startseite" aktiv ist 109 if (strtolower($gallery['name']) == strtolower($conf['start'])) return; 110 111 // Namespaces ermitteln 112 $gallery['space'] = str_replace(':', '/', str_replace(':'.$gallery['name'], '', $ID)); 113 114 // Suffix für Dateinamen der Bilder erstellen 115 $gallery['suffix'] = strtolower($gallery['name']).'_'; 116 117 // Pfad zu den Bildern 118 $gallery['dir'] = $gallery['datadir'].'/media/'.$gallery['space']; 119 $gallery['media'] = 'media/'.$gallery['space']; 120 121 // Prüfen ob Verzeichnis vorhanden ist 122 if (!is_dir($gallery['dir'])) { 123 echo '<p>'.$gallery['nopicture']."</p>\n"; 124 return; 125 } 126 127 // Verzeichnis einlesen 128 $array = gallery_readdir($gallery); 129 $gallery['image'] = $array[1]; 130 $gallery['thumbnail'] = $array[2]; 131 $gallery['imagename'] = $array[3]; 132 $gallery['thumbname'] = $array[4]; 133 134 // Anzahl der Bilder ermitteln 135 $gallery['max'] = count($gallery['image']); 136 137 // Prüfen ob Bilder vorhanden sind 138 if ($gallery['max'] == 0) { 139 echo '<p>'.$gallery['nopicture']."</p>\n"; 140 return; 141 } 142 143 // Parameter prüfen 144 if (isset($gallery['pic'])) { 145 if ($gallery['pic'] > $gallery['max']) $gallery['pic'] = $gallery['max']; 146 if ($gallery['pic'] < 1) $gallery['pic'] = 1; 147 } 148 149 // Gallerie oder einzelnes Bild anzeigen 150 if (!isset($gallery['pic'])) gallery_displaythumbnails($gallery); 151 else gallery_displayimage($gallery); 152 153 return; 154} 155 156 157/** 158 * Zufallsbild anzeigen 159 */ 160function tpl_gallery_random() { 161 global $conf; 162 global $ACT; 163 global $INFO; 164 global $ID; 165 166 // Werte einstellen 167 $gallery = gallery_init(); 168 $namespace = strtolower($gallery['namespace']); 169 170 // Galerie nur anzeigen wenn Seite nicht bearbeitet wird und Seite vorhanden ist 171 if ($ACT != 'show' or $INFO['exists'] != 1) return; 172 173 // Galerie nur anzeigen wenn "Startseite" aktiv ist 174 if (strtolower($ID) != strtolower($conf['start'])) return; 175 176 // Pfad+Dateiname der Index-Datei 177 $file = $gallery['datadir'].'/media/'.$namespace.'/'.$gallery['index']; 178 179 // Inhalt der Index-Datei einlesen 180 if (file_exists($file)) { 181 $index = file($file); 182 $max = count($index); 183 184 // Einträge in der Index-Datei sind vorhanden 185 if ($max > 0) { 186 $nr = rand(0, $max); // Zufallsbild auswählen 187 $picture = $namespace.'/'.trim($index[$nr]); // Dateiname des Bildes 188 $sizeimage = getimagesize($gallery['datadir'].'/media/'.$picture, $info); 189 $height = $sizeimage[1]/($sizeimage[0]/$gallery['randomwidth']); 190 $media = ml(str_replace('/', ':', $picture), 'w='.$gallery['randomwidth'].'&h='.$height.'&cache=cache', TRUE); 191 if (isset($info["APP13"]) and $gallery['iptc']) { 192 $iptc = iptcparse ($info['APP13']); 193 194 $alt = htmlentities($iptc['2#120'][0]); 195 $iptc_caption = str_ireplace("\r\n", '<br />', $alt); 196 $iptc_caption = str_ireplace("\r", '<br />', $iptc_caption); 197 $iptc_caption = str_ireplace("\n", '<br />', $iptc_caption); 198 199 $alt = htmlentities($iptc['2#090'][0]); 200 $iptc_city = str_ireplace("\r\n", '<br />', $alt); 201 $iptc_city = str_ireplace("\r", '<br />', $iptc_city); 202 $iptc_city = str_ireplace("\n", '<br />', $iptc_city); 203 } else { 204 unset($iptc_caption); 205 unset($iptc_city); 206 } 207 208 // Bild anzeigen 209 $script = wl($gallery['namespace'].':'.$conf['start']); 210 echo '<div class="randompicture" style="width:'.$gallery['randomwidth'].'px">'."\n"; 211 echo '<a href="'.$script.'"><img src="'.$media.'" alt="'.$alt.'" width="'.$gallery['randomwidth'].'" height="'.$height.'" /></a>'."\n"; 212 echo "<br />\n$iptc_caption\n"; 213 if ($iptc_city != '') echo "<br />\n($iptc_city)\n"; 214 echo '</div>'."\n"; 215 } 216 217 } 218} 219 220 221/** 222 * Thumbnails anzeigen 223 * 224 * @param array $gallery Daten-Array 225 */ 226function gallery_displaythumbnails($gallery) { 227 global $ID; 228 229 $script = wl($ID); 230 231 // Trenner für Parameter in URL 232 $trenner = '?'; 233 if (stristr($script, '?')) { 234 $trenner = '&'; 235 } 236 237 echo $gallery['titlestart'].$gallery['content'].$gallery['titleend']."\n"; 238 echo $gallery['displaystart']."\n"; 239 echo $gallery['count'].' '.$gallery['max']."\n"; 240 241 echo '<div style="text-align:center">'."\n"; 242 for ($i = 0; $i < $gallery['max']; $i++): 243 // Thumbnail erzeugen falls nicht vorhanden ist 244 if ($gallery['savethumbs']) { 245 if (!file_exists($gallery['thumbnail'][$i])) gallery_createthumbnail($gallery, $i); 246 $sizethumb = getimagesize($gallery['thumbnail'][$i]); 247 } 248 249 $sizeimage = getimagesize($gallery['image'][$i], $info); 250 251 // IPTC-Daten ermitteln 252 if ($gallery['iptc'] and isset($info["APP13"])) { 253 $iptc = iptcparse($info['APP13']); 254 $iptc_caption = htmlentities($iptc['2#120'][0]); 255 if ($iptc_caption != '') $iptc_caption = ' - '.$iptc_caption; 256 } else unset($iptc_caption); 257 258 // Thumbnail anzeigen 259 if ($gallery['savethumbs']) { 260 $media = ml(getNS($ID).':'.$gallery['thumbname'][$i], 'w=&h=&cache=cache', TRUE); 261 echo '<a href="'.$script.$trenner.'pic='.($i+1).'" title="'.$gallery['picturename'].($i+1).$iptc_caption.'"><img class="thumb" src="'.$media.'" alt="'.$gallery['picturename'].($i+1).$iptc_caption.'" '.$sizethumb[3].' /></a>'."\n"; 262 } else { 263 $media = ml(getNS($ID).':'.$gallery['imagename'][$i], 'w='.$gallery['thumbwidth'].'&h=&cache=cache', TRUE); 264 $height = $sizeimage[1]/($sizeimage[0]/$gallery['thumbwidth']); 265 echo '<a href="'.$script.$trenner.'pic='.($i+1).'" title="'.$gallery['picturename'].($i+1).$iptc_caption.'"><img class="thumb" src="'.$media.'" alt="'.$gallery['picturename'].($i+1).$iptc_caption.'" width="'.$gallery['thumbwidth'].'" height="'.$height.'" /></a>'."\n"; 266 } 267 flush(); 268 endfor; 269 echo '</div>'."\n"; 270 271 echo $gallery['displayend']."\n"; 272 273 flush(); 274} 275 276 277/** 278 * Bild anzeigen 279 * 280 * @param array $gallery Daten-Array 281 */ 282function gallery_displayimage($gallery) { 283 global $ID; 284 285 $size = getimagesize($gallery['image'][$gallery['pic']-1], $info); 286 287 // EXIF-Daten ermitteln 288 if ($gallery['exif']) { 289 $exif = exif_read_data($gallery['image'][$gallery['pic']-1],'',true,false); 290 $exif_date = htmlentities($exif['DateTime']); 291 $exif_make = htmlentities($exif['Make']); 292 $exif_camera = htmlentities($exif['Model']); 293 } 294 295 // IPTC-Daten ermitteln 296 if (isset($info["APP13"]) and $gallery['iptc']) { 297 $iptc = iptcparse ($info['APP13']); 298 $iptc_program = htmlentities($iptc['2#065'][0]); 299 $iptc_jobid = htmlentities($iptc['2#022'][0]); 300 $iptc_status = htmlentities($iptc['2#007'][0]); 301 $iptc_copyright = htmlentities($iptc['2#116'][0]); 302 $iptc_specialinstructions = htmlentities($iptc['2#040'][0]); 303 $iptc_headline = htmlentities($iptc['2#105'][0]); 304 $iptc_captionwriter = htmlentities($iptc['2#122'][0]); 305 $iptc_caption = htmlentities($iptc['2#120'][0]); 306 $iptc_caption = str_ireplace("\r\n", '<br />', $iptc_caption); 307 $iptc_caption = str_ireplace("\r", '<br />', $iptc_caption); 308 $iptc_caption = str_ireplace("\n", '<br />', $iptc_caption); 309 $iptc_originaltransmissionreference = htmlentities($iptc['2#103'][0]); 310 $iptc_countrycode = htmlentities($iptc['2#100'][0]); 311 $iptc_country = htmlentities($iptc['2#101'][0]); 312 $iptc_state = htmlentities($iptc['2#095'][0]); 313 $iptc_sublocation = htmlentities($iptc['2#092'][0]); 314 $iptc_city = htmlentities($iptc['2#090'][0]); 315 $iptc_objectname = htmlentities($iptc['2#005'][0]); 316 $iptc_source = htmlentities($iptc['2#115'][0]); 317 $iptc_credit = htmlentities($iptc['2#110'][0]); 318 $iptc_bylinetitle = htmlentities($iptc['2#085'][0]); 319 $iptc_byline = htmlentities($iptc['2#080'][0]); 320 } else { 321 unset($iptc_program); 322 unset($iptc_jobid); 323 unset($iptc_status); 324 unset($iptc_copyright); 325 unset($iptc_specialinstructions); 326 unset($iptc_headline); 327 unset($iptc_captionwriter); 328 unset($iptc_caption); 329 unset($iptc_originaltransmissionreference); 330 unset($iptc_countrycode); 331 unset($iptc_country); 332 unset($iptc_state); 333 unset($iptc_sublocation); 334 unset($iptc_city); 335 unset($iptc_objectname); 336 unset($iptc_source); 337 unset($iptc_credit); 338 unset($iptc_bylinetitle); 339 unset($iptc_byline); 340 } 341 342 echo $gallery['titlestart'].$gallery['picturename'].$gallery['pic'].' '.$gallery['of'].' '.$gallery['max'].$gallery['titleend']."\n"; 343 echo $gallery['displaystart']."\n"; 344 345 // Bild anzeigen 346 $detail = ml(getNS($ID).':'.$gallery['imagename'][$gallery['pic']-1], 'id='.$ID.'&cache=cache', FALSE); 347 $media = ml(getNS($ID).':'.$gallery['imagename'][$gallery['pic']-1], 'w=&h=&cache=cache', TRUE); 348 $alt = getNS($ID).':'.$gallery['imagename'][$gallery['pic']-1]; 349 echo '<div style="text-align:center">'."\n"; 350 echo '<a href="'.$detail.'" title="'.$alt.'" onclick="return svchk()" onkeypress="return svchk()">'; 351 echo '<img class="photo" src="'.$media.'" alt="'.$gallery['picturename'].$gallery['pic'].' '.$gallery['of'].' '.$gallery['max'].'" '.$size[3].' />'; 352 echo '</a>'."\n"; 353 echo '<br />'."\n"; 354 355 // Beschreibung anzeigen 356 if ($exif_date != '' and $gallery['exif']) { 357 echo $exif_date."\n"; 358 echo '<br />'."\n"; 359 } 360 361 if ($gallery['iptc']) { 362 if ($iptc_caption != '') { 363 echo $iptc_caption."\n"; 364 echo '<br />'."\n"; 365 } 366 if ($iptc_city != '') { 367 echo $gallery['city'].': '.$iptc_city; 368 if ($iptc_country != '') echo ', '.$iptc_country; 369 echo '<br />'."\n"; 370 } elseif ($iptc_country != '') { 371 echo $gallery['country'].': '.$iptc_country."\n"; 372 echo '<br />'."\n"; 373 } 374 if ($iptc_sublocation != '') { 375 echo $iptc_sublocation."\n"; 376 echo '<br />'."\n"; 377 } 378 } 379 380 echo '<br />'."\n"; 381 382 // Navigation anzeigen 383 gallery_navigation($gallery); 384 385 echo '</div>'."\n"; 386 387 echo $gallery['displayend']."\n"; 388 389 flush(); 390} 391 392 393/** 394 * Verzeichnis einlesen 395 * 396 * @param array $gallery Daten-Array 397 * @return array 398 */ 399function gallery_readdir($gallery) { 400 $path = $gallery['dir'].'/'; 401 $suffix = strtolower($gallery['suffix']); 402 $len = strlen($suffix); 403 $dir = dir($path); 404 405 while ($file = $dir->read()) { 406 $filename = strtolower($file); 407 if (substr($filename,0,6) != 'thumb_' and substr($filename,0,$len) == $suffix) { 408 if (stristr($filename, '.jpg')) { 409 $image[] = $path.$filename; 410 $thumbnail[] = $path.'thumb_'.$filename; 411 $imagename[] = $filename; 412 $thumbname[] = 'thumb_'.$filename; 413 } 414 if (stristr($filename, '.jpeg')) { 415 $image[] = $path.$filename; 416 $thumbnail[] = $path.'thumb_'.$filename; 417 $imagename[] = $filename; 418 $thumbname[] = 'thumb_'.$filename; 419 } 420 if (stristr($filename, '.png')) { 421 $image[] = $path.$filename; 422 $thumbnail[] = $path.'thumb_'.$filename; 423 $imagename[] = $filename; 424 $thumbname[] = 'thumb_'.$filename; 425 } 426 if (stristr($filename, '.gif')) { 427 $image[] = $path.$filename; 428 $thumbnail[] = $path.'thumb_'.$filename; 429 $imagename[] = $filename; 430 $thumbname[] = 'thumb_'.$filename; 431 } 432 } 433 } 434 $dir->close(); 435 436 // Inhaltsverzeichnis sortieren 437 if (count($image) > 0) { 438 sort($image); 439 sort($thumbnail); 440 sort($imagename); 441 sort($thumbname); 442 } 443 444 $array[1] = $image; 445 $array[2] = $thumbnail; 446 $array[3] = $imagename; 447 $array[4] = $thumbname; 448 449 return $array; 450} 451 452 453/** 454 * Thumbnail erzeugen 455 * 456 * @param array $gallery Daten-Array 457 * @param integer $nr Nummer des Bildes 458 */ 459function gallery_createthumbnail($gallery, $nr) { 460 $image = $gallery['image'][$nr]; 461 $thumbnail = $gallery['thumbnail'][$nr]; 462 463 // Infos über Bild holen 464 $info = getimagesize($image); 465 $width = $info[0]; 466 $height = $info[1]; 467 $type = $info[2]; 468 469 // Thumbnail erstellen 470 if ($type == 1) $new = imagecreatefromgif($image); 471 elseif ($type == 2) $new = imagecreatefromjpeg($image); 472 elseif ($type == 3) $new = imagecreatefrompng($image); 473 474 $newwidth = $gallery['thumbwidth']; 475 $newheight = $height/($width/$newwidth); 476 $newimage = imagecreatetruecolor($newwidth, $newheight); 477 imagecopyresampled($newimage, $new, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 478 479 // Thumbnail speichern 480 if ($type == 1) imagegif($newimage, $thumbnail); 481 elseif ($type == 2) imagejpeg($newimage, $thumbnail); 482 elseif ($type == 3) imagepng($newimage, $thumbnail); 483} 484 485 486/** 487 * Navigation anzeigen 488 * 489 * @param array $gallery Daten-Array 490 */ 491function gallery_navigation($gallery) { 492 global $ID; 493 494 $script = wl($ID); 495 496 // Trenner für Parameter in URL 497 $trenner = '?'; 498 if (stristr($script, '?')) { 499 $trenner = '&'; 500 } 501 502 echo "<p>\n"; 503 504 // Thumbnails 505 $start = $gallery['pic']-2; 506 if ($start < 1) $start = 1; 507 508 $ende = $start+5; 509 if ($ende > $gallery['max']+1) { 510 $ende = $gallery['max']+1; 511 512 if ($ende-5 < $start) $start = $ende-5; 513 if ($start < 1) $start = 1; 514 } 515 516 for ($i = $start-1; $i < $ende-1; $i++) { 517 if ($gallery['savethumbs']) $sizethumb = getimagesize($gallery['thumbnail'][$i]); 518 $sizeimage = getimagesize($gallery['image'][$i], $info); 519 520 // IPTC-Daten ermitteln 521 if (isset($info["APP13"]) and $gallery['iptc']) { 522 $iptc = iptcparse($info['APP13']); 523 $iptc_caption = htmlentities($iptc['2#120'][0]); 524 if ($iptc_caption != '') $iptc_caption = ' - '.$iptc_caption; 525 } else unset($iptc_caption); 526 527 // Thumbnail anzeigen 528 if ($gallery['savethumbs']) { 529 $media = ml(getNS($ID).':'.$gallery['thumbname'][$i], 'w=&h=&cache=cache', TRUE); 530 } else { 531 $media = ml(getNS($ID).':'.$gallery['imagename'][$i], 'w='.$gallery['thumbwidth'].'&h=&cache=cache', TRUE); 532 $height = $sizeimage[1]/($sizeimage[0]/$gallery['thumbwidth']); 533 } 534 $thumb = str_replace('/', '%3A', $thumb); 535 536 if ($i+1 == $gallery['pic']) { 537 if ($gallery['savethumbs']) echo '<img class="thumbactiv" src="'.$media.'" alt="'.$gallery['picturename'].($i+1).$iptc_caption.'" '.$sizethumb[3].' />'."\n"; 538 else echo '<img class="thumbactiv" src="'.$media.'" alt="'.$gallery['picturename'].($i+1).$iptc_caption.'" width="'.$gallery['thumbwidth'].'" height="'.$height.'" />'."\n"; 539 } else { 540 if ($gallery['savethumbs']) echo '<a href="'.$script.$trenner.'pic='.($i+1).'" title="'.$gallery['picturename'].($i+1).$iptc_caption.'"><img class="thumb" src="'.$media.'" alt="'.$gallery['picturename'].($i+1).$iptc_caption.'" '.$sizethumb[3].' /></a>'."\n"; 541 else echo '<a href="'.$script.$trenner.'pic='.($i+1).'" title="'.$gallery['picturename'].($i+1).$iptc_caption.'"><img class="thumb" src="'.$media.'" alt="'.$gallery['picturename'].($i+1).$iptc_caption.'" width="'.$gallery['thumbwidth'].'" height="'.$height.'" /></a>'."\n"; 542 } 543 flush(); 544 } 545 546 flush(); 547 548 echo "<br />\n"; 549 550 // Textlinks 551 if ($gallery['pic'] > 1) { 552 echo '<a href="'.$script.$trenner.'pic=1" title="'.$gallery['picturename'].'1"><<</a> '."\n"; 553 echo '<a href="'.$script.$trenner.'pic='.($gallery['pic']-1).'" title="'.$gallery['picturename'].($gallery['pic']-1).'"><</a> '."\n"; 554 } else { 555 echo '<< '."\n"; 556 echo '< '."\n"; 557 } 558 559 echo '<a href="'.$script.'" title="'.$gallery['content'].'">'.$gallery['content'].'</a> '."\n"; 560 561 if ($gallery['pic'] < $gallery['max']) { 562 echo '<a href="'.$script.$trenner.'pic='.($gallery['pic']+1).'" title="'.$gallery['picturename'].($gallery['pic']+1).'">></a> '."\n"; 563 echo '<a href="'.$script.$trenner.'pic='.$gallery['max'].'" title="'.$gallery['picturename'].$gallery['max'].'">>></a>'."\n"; 564 } else { 565 echo '> '."\n"; 566 echo '>>'."\n"; 567 } 568 569 echo "</p>\n"; 570 571 flush(); 572 573 return; 574} 575 576?>