Drachen
19.08.2009, 17:30:09
Hallo,
ich habe mir eine Gallerie mit pagination gebaselt, nun ist das Problem dass mir nicht alle Bilder ausgegben werden sondern nur die, die durch die anzahl teilbar ist, die ich auf einer Seite, bevor man mit "weiter" weiter blättert kann. Zum Beispeil wenn ich einstelle, dass ich 10 Bilder pro SEite haben will und es gibt 42, dann werden nur 40 angezeigt. Kann mir jemand helfen?
Hier der Code:
<?php
class gallery {
var $dir;
function gallery( $dir, $thumb_file ) {
$this->dir = $dir;
$this->thumb_file = $thumb_file;
}
function gallery_resize( $file = null, $tim_w = 250, $tim_h = 14 ) {
if( $file == null and isset( $_REQUEST['file'] ) ) {
$file = $_REQUEST['file'];
}
if( $file ) {
$path = sprintf( '%s%s', $this->dir, $file );
$cache_file = sprintf( 'images/cache-new/%s', basename( $path ) );
if( file_exists( $cache_file ) ) {
header( 'Content-Type: image/jpg' );
readfile( $cache_file );
die( );
}
list( $sim_w, $sim_h, $sim_type ) = getimagesize( $path );
header( 'Expires: Mon, 26 Jul '.( date( 'Y' ) + 1 ).' 05:00:00 GMT' );
header( 'Cache-Control: store, cache' );
header( 'Pragma: cache' );
header( 'Date: '.date( 'D, j M Y H:i:s' ).' GMT' );
switch( $sim_type ) {
case IMAGETYPE_JPEG:
$sim = imagecreatefromjpeg( $path );
break;
case IMAGETYPE_GIF:
$sim = imagecreatefromgif( $path );
break;
case IMAGETYPE_PNG:
$sim = imagecreatefrompng( $path );
break;
default:
readfile( $path );
die( );
break;
}
$sim_w_orig = $sim_w;
$sim_h_orig = $sim_h;
if( $sim_w * ( $tim_h / $tim_w ) < $sim_h * ( $tim_w / $tim_h ) ) {
$sim_h = $sim_w * ( $tim_h / $tim_w );
// todo undo workaround: keine schwarzen balken
if( $sim_h > $sim_h_orig ) {
$sim_h = $sim_h_orig;
}
} else {
$sim_w = $sim_h * ( $tim_w / $tim_h );
}
$sim_x = ( $sim_w_orig - $sim_w ) / 2;
$sim_y = ( $sim_h_orig - $sim_h ) / 2;
if( $tim_h == 0 ) $tim_h = $tim_w * ( $sim_h / $sim_w );
if( $tim_w == 0 ) $tim_w = $tim_h * ( $sim_w / $sim_h );
$tim = imagecreatetruecolor( $tim_w, $tim_h );
imagecolorallocate( $tim, 255, 255, 255 );
imagecopyresampled( $tim, $sim, 0, 0, $sim_x, $sim_y, $tim_w, $tim_h, $sim_w, $sim_h );
switch( $sim_type ) {
case IMAGETYPE_JPEG:
header( 'Content-Disposition: inline; filename="image.jpg"' );
header( 'Content-Type: image/jpg' );
imagejpeg( $tim, $cache_file, 95 );
readfile( $cache_file );
break;
case IMAGETYPE_GIF:
header( 'Content-Disposition: inline; filename="image.gif"' );
header( 'Content-Type: image/gif' );
imagegif( $tim, $cache_file );
readfile( $cache_file );
break;
case IMAGETYPE_PNG:
header( 'Content-Disposition: inline; filename="image.png"' );
header( 'Content-Type: image/png' );
imagepng( $tim, $cache_file );
readfile( $cache_file );
break;
}
die( );
}
return false;
}
function gallery_list( $page = 1, $images = 14 ) {
if ($page== 0)$page=1;
$files = array( );
$d = dir( $this->dir );
while( $file = $d->read( ) ) {
if( $file != '.' and $file != '..'and $file != 'Thumbs.db' ) {
$files[$file] = filemtime( $this->dir.$file );
}
}
$file_count = count ($files);
arsort( $files );
$i = 0;
foreach( $files as $file => $file_ts ) {
$i++;
if ($i > ($page)*$images or $i <= ($page-1)*$images ) continue;
$f = basename( $file );
$x = explode( '_', substr( $f, 0, strrpos( $f, '.' ) ) );
printf(
'<div class="gal-image"><a href="%s%s" rel="lytebox[roadtrip]" title="%s"><div class="image-border"><img src="%s?file=%s" border="0"></div></a><span><b>%s</b><br />%s</span></div>',
$this->dir,
$file,
$x[0].'<br />' .$x[1],
$this->thumb_file,
$file,
$x[0],
$x[1]
);
}
print ('<div class="pagina">');
if ($page>1){
printf ('<a href="index.php?s=%s&page=%d" class="back">zurück</a>', $_REQUEST['s'],$page-1);
}
else {
printf ('<span class="back disabled">zurück</span>');
}
if ($page<floor ($file_count/$images)){
printf ('<a href="index.php?s=%s&page=%d" class="forward">weiter</a>', $_REQUEST['s'],$page+1);
}
else {
printf ('<span class="forward disabled">weiter</span>');
}
print ('<div class="pagina-pages">');
for ($p=1; $p<ceil ($file_count/$images); $p++){
printf ('<a href="index.php?s=%s&page=%d" class="%s">%d</a>', $_REQUEST['s'], $p, $page==$p?'active':'', $p);
}
print ('</div>');
print ('</div>');
print ('<script>image_zoom( ".image-border" );</script>');
}
}
?>
ich habe mir eine Gallerie mit pagination gebaselt, nun ist das Problem dass mir nicht alle Bilder ausgegben werden sondern nur die, die durch die anzahl teilbar ist, die ich auf einer Seite, bevor man mit "weiter" weiter blättert kann. Zum Beispeil wenn ich einstelle, dass ich 10 Bilder pro SEite haben will und es gibt 42, dann werden nur 40 angezeigt. Kann mir jemand helfen?
Hier der Code:
<?php
class gallery {
var $dir;
function gallery( $dir, $thumb_file ) {
$this->dir = $dir;
$this->thumb_file = $thumb_file;
}
function gallery_resize( $file = null, $tim_w = 250, $tim_h = 14 ) {
if( $file == null and isset( $_REQUEST['file'] ) ) {
$file = $_REQUEST['file'];
}
if( $file ) {
$path = sprintf( '%s%s', $this->dir, $file );
$cache_file = sprintf( 'images/cache-new/%s', basename( $path ) );
if( file_exists( $cache_file ) ) {
header( 'Content-Type: image/jpg' );
readfile( $cache_file );
die( );
}
list( $sim_w, $sim_h, $sim_type ) = getimagesize( $path );
header( 'Expires: Mon, 26 Jul '.( date( 'Y' ) + 1 ).' 05:00:00 GMT' );
header( 'Cache-Control: store, cache' );
header( 'Pragma: cache' );
header( 'Date: '.date( 'D, j M Y H:i:s' ).' GMT' );
switch( $sim_type ) {
case IMAGETYPE_JPEG:
$sim = imagecreatefromjpeg( $path );
break;
case IMAGETYPE_GIF:
$sim = imagecreatefromgif( $path );
break;
case IMAGETYPE_PNG:
$sim = imagecreatefrompng( $path );
break;
default:
readfile( $path );
die( );
break;
}
$sim_w_orig = $sim_w;
$sim_h_orig = $sim_h;
if( $sim_w * ( $tim_h / $tim_w ) < $sim_h * ( $tim_w / $tim_h ) ) {
$sim_h = $sim_w * ( $tim_h / $tim_w );
// todo undo workaround: keine schwarzen balken
if( $sim_h > $sim_h_orig ) {
$sim_h = $sim_h_orig;
}
} else {
$sim_w = $sim_h * ( $tim_w / $tim_h );
}
$sim_x = ( $sim_w_orig - $sim_w ) / 2;
$sim_y = ( $sim_h_orig - $sim_h ) / 2;
if( $tim_h == 0 ) $tim_h = $tim_w * ( $sim_h / $sim_w );
if( $tim_w == 0 ) $tim_w = $tim_h * ( $sim_w / $sim_h );
$tim = imagecreatetruecolor( $tim_w, $tim_h );
imagecolorallocate( $tim, 255, 255, 255 );
imagecopyresampled( $tim, $sim, 0, 0, $sim_x, $sim_y, $tim_w, $tim_h, $sim_w, $sim_h );
switch( $sim_type ) {
case IMAGETYPE_JPEG:
header( 'Content-Disposition: inline; filename="image.jpg"' );
header( 'Content-Type: image/jpg' );
imagejpeg( $tim, $cache_file, 95 );
readfile( $cache_file );
break;
case IMAGETYPE_GIF:
header( 'Content-Disposition: inline; filename="image.gif"' );
header( 'Content-Type: image/gif' );
imagegif( $tim, $cache_file );
readfile( $cache_file );
break;
case IMAGETYPE_PNG:
header( 'Content-Disposition: inline; filename="image.png"' );
header( 'Content-Type: image/png' );
imagepng( $tim, $cache_file );
readfile( $cache_file );
break;
}
die( );
}
return false;
}
function gallery_list( $page = 1, $images = 14 ) {
if ($page== 0)$page=1;
$files = array( );
$d = dir( $this->dir );
while( $file = $d->read( ) ) {
if( $file != '.' and $file != '..'and $file != 'Thumbs.db' ) {
$files[$file] = filemtime( $this->dir.$file );
}
}
$file_count = count ($files);
arsort( $files );
$i = 0;
foreach( $files as $file => $file_ts ) {
$i++;
if ($i > ($page)*$images or $i <= ($page-1)*$images ) continue;
$f = basename( $file );
$x = explode( '_', substr( $f, 0, strrpos( $f, '.' ) ) );
printf(
'<div class="gal-image"><a href="%s%s" rel="lytebox[roadtrip]" title="%s"><div class="image-border"><img src="%s?file=%s" border="0"></div></a><span><b>%s</b><br />%s</span></div>',
$this->dir,
$file,
$x[0].'<br />' .$x[1],
$this->thumb_file,
$file,
$x[0],
$x[1]
);
}
print ('<div class="pagina">');
if ($page>1){
printf ('<a href="index.php?s=%s&page=%d" class="back">zurück</a>', $_REQUEST['s'],$page-1);
}
else {
printf ('<span class="back disabled">zurück</span>');
}
if ($page<floor ($file_count/$images)){
printf ('<a href="index.php?s=%s&page=%d" class="forward">weiter</a>', $_REQUEST['s'],$page+1);
}
else {
printf ('<span class="forward disabled">weiter</span>');
}
print ('<div class="pagina-pages">');
for ($p=1; $p<ceil ($file_count/$images); $p++){
printf ('<a href="index.php?s=%s&page=%d" class="%s">%d</a>', $_REQUEST['s'], $p, $page==$p?'active':'', $p);
}
print ('</div>');
print ('</div>');
print ('<script>image_zoom( ".image-border" );</script>');
}
}
?>