Ignore:
Timestamp:
11/14/08 12:11:05 (4 years ago)
Author:
MichaelDaum
Message:

Item176:

Adding a format, header, footer set of format strings to get full
control on how galleries are rendered. This allows integration into other
slideshow tools like  http://www.twospy.com/galleriffic/ or
 http://www.airtightinteractive.com/simpleviewer/examples/small/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ImageGalleryPlugin/lib/TWiki/Plugins/ImageGalleryPlugin/Core.pm

    r424 r653  
    1 # 
    2 # TWiki WikiClone ($wikiversion has version info) 
    3 # 
    41# Copyright (C) 2002-2003 Will Norris. All Rights Reserved. (wbniv@saneasylumstudios.com) 
    52# Copyright (C) 2005-2008 Michael Daum http://michaeldaumconsulting.com 
     
    176173  $this->{minwidth} = $params->{minwidth} || 0; 
    177174  $this->{minwidth} = $this->{maxwidth} if $this->{minwidth} > $this->{maxwidth}; 
    178   $this->{format} = $params->{format} ||  
    179       '<a href="$origurl"><img src="$imageurl" title="$comment" width="$width" height="$height"/></a>'; 
     175  $this->{format} = $params->{format}; 
    180176  $this->{title} = $params->{title} || ' $comment ($imgnr/$nrimgs)&nbsp;$reddot'; 
    181177  $this->{doTitles} = ($this->{title} eq 'off')?0:1; 
     
    267263      join(', ', $this->{info}{topics}{value}) ne join(', ', @{$this->{topics}}); 
    268264 
    269   my $result = "<div class=\"igp\"><a name=\"igp$this->{id}\"></a>"; 
     265  my $result; 
    270266 
    271267  # get filename query string 
     
    273269  my $id = $this->{query}->param("id") || ''; 
    274270 
    275   if ($id eq $this->{id} && $filename) { 
    276     # picture mode 
    277     $result .= $this->renderImage($filename); 
     271  if ($this->{format}) { 
     272    $result = $this->renderFormatted(); 
    278273  } else { 
    279     # thumbnails mode 
    280     $result .= $this->renderThumbnails(); 
    281   } 
    282  
    283   $result .= "</div>\n"; 
     274    $result = "<div class=\"igp\"><a name=\"igp$this->{id}\"></a>"; 
     275    if ($id eq $this->{id} && $filename) { 
     276      # picture mode 
     277      $result .= $this->renderImage($filename); 
     278    } else { 
     279      # thumbnails mode 
     280      $result .= $this->renderThumbnails(); 
     281    } 
     282    $result .= "</div>\n"; 
     283    $result = '<noautolink>'.$result.'</noautolink>'; 
     284  } 
     285 
    284286 
    285287  $this->writeInfo(); 
    286   return '<noautolink>'.$result.'</noautolink>'; 
     288 
     289  #writeDebug("result=$result"); 
     290  return $result; 
    287291} 
    288292 
     
    368372 
    369373  # img 
     374  my $imgFormat = '<a href="$origurl"><img src="$imageurl" title="$comment" width="$width" height="$height"/></a>'; 
    370375  $result .= "<tr><td class=\"igpPicture\">"  
    371     . $this->replaceVars($this->{format}, $thisImg); 
     376    . $this->replaceVars($imgFormat, $thisImg); 
    372377 
    373378  # navi 
     
    416421 
    417422# ========================= 
    418 sub renderThumbnails { 
    419  
     423sub renderFormatted { 
    420424  my $this = shift; 
    421  
    422   #writeDebug("renderThumbnails()"); 
     425   
     426  writeDebug("renderFormatted()"); 
    423427 
    424428  if (!@{$this->{images}}) { 
     
    427431 
    428432  my $maxCols = $this->{columns}; 
    429   my $result = "<div class=\"igpThumbNails\"><table class=\"igpThumbNailsTable\"><tr>\n"; 
     433  my $header = $this->{header} || ''; 
     434  my $footer = $this->{footer} || ''; 
     435  my $format = $this->{format} || '   * $imageurl'; 
     436  my $separator = $this->{separator}; 
     437 
     438  $separator = "\n" unless defined $separator; 
     439  my @result; 
     440 
     441  my $imageNr = 0; 
     442  my @rowOfImages = (); 
     443  my $skip = $this->{skip}; 
     444  foreach my $image (@{$this->{images}}) { 
     445 
     446    $skip--; 
     447    next if $skip >= 0; 
     448    last if $this->{limit} && $imageNr >= $this->{limit}; 
     449    $imageNr++; 
     450 
     451    $this->computeImageSize($image); 
     452    if (!$this->createImg($image)) { 
     453      return renderError($this->{errorMsg}); 
     454    } 
     455    if (!$this->createImg($image, 1)) { 
     456      return renderError($this->{errorMsg}); 
     457    } 
     458 
     459 
     460    my $line = $this->replaceVars($format, $image); 
     461    $line =~ s/\$index/$imageNr/g; 
     462    push @result, $line; 
     463     
     464 
     465  } 
     466  return $header.join($separator, @result).$footer; 
     467} 
     468 
     469# ========================= 
     470sub renderThumbnails { 
     471 
     472  my $this = shift; 
     473 
     474  writeDebug("renderThumbnails()"); 
     475 
     476  if (!@{$this->{images}}) { 
     477    return renderError($this->{warn});  
     478  } 
     479 
     480  my $maxCols = $this->{columns}; 
     481  my $result = "<div class='igpThumbNails'><table class='igpThumbNailsTable'><tr>"; 
    430482  my $imageNr = 0; 
    431483  my @rowOfImages = (); 
     
    758810    $format =~ s/\$wikiusername/$image->{user}/gos; 
    759811    $format =~ s/\$username/TWiki::Func::wikiToUserName($image->{user})/geos; 
    760     $format =~ s,\$thumburl,$this->{imagesPubUrl}/thumb_$imageName,gos; 
    761     $format =~ s,\$imageurl,$this->{imagesPubUrl}/$imageName,gos; 
    762     $format =~ s,\$origurl,$image->{IGP_url},gos; 
     812    $format =~ s/\$thumburl/$this->{imagesPubUrl}\/thumb_$imageName/gos; 
     813    $format =~ s/\$imageurl/$this->{imagesPubUrl}\/$imageName/gos; 
     814    $format =~ s/\$origurl/$image->{IGP_url}/gos; 
    763815    $format =~ s/\$web/$image->{IGP_web}/gos; 
    764816    $format =~ s/\$topic/$image->{IGP_topic}/gos; 
     
    9831035} 
    9841036 
    985  
    986  
    98710371; 
Note: See TracChangeset for help on using the changeset viewer.