diff --git a/.htaccess b/.htaccess
new file mode 100644
index 0000000..1b40eba
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,10 @@
+
+Options +FollowSymlinks
+RewriteEngine On
+
+# RewriteCond %{REQUEST_FILENAME} !-f [NC]
+# RewriteCond %{REQUEST_FILENAME} !-d [NC]
+RewriteRule ^([0-9]{1,4})x([0-9]{1,4})x([0-9]{1,3})(.*)$ thumb.php?src=$4&w=$1&h=$2&q=$3
+RewriteRule ^([0-9]{1,4})x([0-9]{1,4})(.*)$ thumb.php?src=$3&w=$1&h=$2
+
+
\ No newline at end of file
diff --git a/config.php b/config.php
index 2567f02..2cd7471 100644
--- a/config.php
+++ b/config.php
@@ -52,6 +52,11 @@ $config = array(
'thumbnails' => true,
'thumb_pattern' => '/jpg|jpeg|jpe|png$/i',
+ # thumbnail request url
+ 'thumb_url' => '%width%x%height%%url%',
+ // 'thumb_url' => 'thumb.php?src=%url%&w=%width%&h=%height%',
+
+
# Smart Date shows relative time stamps ("Yesterday, 09:34") when applicable
'smartdate' => true,
diff --git a/exec/icons.exec.php b/exec/icons.exec.php
index a77e65a..335c88e 100644
--- a/exec/icons.exec.php
+++ b/exec/icons.exec.php
@@ -57,7 +57,10 @@ class Icon {
$icons_url = ICONS_URL.$size.'/';
if ( $type == 'file' ) {
if ( preg_match($config->thumb_pattern, $ext) && $thumbnail && $config->thumbnails ) {
- return DLIST_URL.'thumb.php?src='.rawurlencode(DIR_URL.$file).'&w='.$sizew.'&h='.$sizeh;
+ $thumb_url = (!preg_match('/^\//i', $config->thumb_url)) ? DLIST_URL.$config->thumb_url : $config->thumb_url ;
+ $thumb_url = str_replace('%width%', $sizew, $thumb_url);
+ $thumb_url = str_replace('%height%', $sizeh, $thumb_url);
+ return str_replace('%url%', DIR_URL.$file, $thumb_url);
} elseif ( file_exists($icons_path.$ext.$config->icons_ext) ) {
return $icons_url.$ext.$config->icons_ext;
} else {
@@ -74,7 +77,11 @@ class Icon {
//>Section> get_thumbnail
function get_thumbnail_url ($file, $sizew, $sizeh) {
- return DLIST_URL.'thumb.php?src='.rawurlencode(DIR_URL.$file).'&w='.$sizew.'&h='.$sizeh;
+ global $config;
+ $thumb_url = (!preg_match('/^\//i', $config->thumb_url)) ? DLIST_URL.$config->thumb_url : $config->thumb_url ;
+ $thumb_url = str_replace('%width%', $sizew, $thumb_url);
+ $thumb_url = str_replace('%height%', $sizeh, $thumb_url);
+ return str_replace('%url%', DIR_URL.$file, $thumb_url);
}
//>Section> get_parent
diff --git a/libs/imagethumb.lib.php b/libs/imagethumb.lib.php
index e4b05df..2105ff3 100644
--- a/libs/imagethumb.lib.php
+++ b/libs/imagethumb.lib.php
@@ -31,7 +31,7 @@ class imageThumb {
// ----- [ Configuration ] ----------------------
// ==============================================
- var $jpg_quality = 85;
+ var $jpg_quality = 85; // default jpg quality
var $cache_dir = 'cache/images/';
var $cache_validity = 60; // days
@@ -60,12 +60,12 @@ class imageThumb {
// ==============================================
- function quick ($file, $width, $height, $quality=false) {
- if ( !$this->check_cache($file, $width, $height) ) {
+ function quick ($file, $width, $height, $quality=null) {
+ if ( !$this->check_cache($file, $width, $height, $quality) ) {
$this->load($file);
if ( $this->error == false) {
- $this->resize($width, $height);
if ( !empty($quality) ) $this->jpg_quality = $quality;
+ $this->resize($width, $height);
$this->output();
$this->save_to_cache();
$this->destroy();
@@ -76,8 +76,8 @@ class imageThumb {
function load ($file) {
if ( is_readable($file) && preg_match("/.*\.(jpg|jpeg|jpe|png)/i", $file, $type) ) {
- $this->type = $type = $type[1];
- $this->image = ( $type == 'png' ) ? imagecreatefrompng($file) : imagecreatefromjpeg($file) ;
+ $this->type = ( $type[1] == 'jpeg' || $type[1] == 'jpe' ) ? 'jpg' : $type[1] ;
+ $this->image = ( $this->type == 'png' ) ? imagecreatefrompng($file) : imagecreatefromjpeg($file) ;
$this->src_file = $file;
$this->last_modified = filemtime($file);
} else { $this->error = true; return false; }
@@ -99,8 +99,7 @@ class imageThumb {
}
function output ($file=null) {
- $type = ( empty($this->output_format) ) ? $this->type : $this->output_format ;
- if ( $type == 'png' ) {
+ if ( $this->get_type() == 'png' ) {
header('Content-type: image/png');
header('Content-disposition: image; filename="'.basename($this->src_file).'"');
( empty($file) ) ? imagepng($this->image) : imagepng($this->image, $file) ;
@@ -121,7 +120,9 @@ class imageThumb {
if ( !preg_match("/\/$/", $this->cache_dir) ) $this->cache_dir .= '/';
if ( is_writable($this->cache_dir) ) {
$string = $this->src_file.$this->last_modified;
- if ( !empty($this->target_w) && !empty($this->target_h)) $string .= $this->target_w.$this->target_h;
+ if ( !empty($this->target_w) ) $string .= $this->target_w;
+ if ( !empty($this->target_h) ) $string .= $this->target_h;
+ if ( $this->get_type() == 'jpg' ) $string .= $this->jpg_quality;
$filename = 'imgt_';
$filename .= md5($string);
$filename .= '.'.$this->type;
@@ -129,18 +130,20 @@ class imageThumb {
if ( $this->type == 'png' ) {
imagepng($this->image, $this->cache_dir.$filename);
} else {
- imagejpeg($this->image, $this->cache_dir.$filename);
+ imagejpeg($this->image, $this->cache_dir.$filename, $this->jpg_quality);
}
}
}
}
- function check_cache ($file, $target_w=null, $target_h=null) {
+ function check_cache ($file, $target_w=null, $target_h=null, $quality=null) {
if ( is_readable($file) ) {
preg_match("/(?:.*\/|)(.*?)\.(.*)/i", $file, $file_pieces);
$ext = $file_pieces[2];
$string = $file.filemtime($file);
- if ( !empty($target_w) && !empty($target_h) ) $string .= $target_w.$target_h;
+ if ( !empty($target_w) ) $string .= $target_w;
+ if ( !empty($target_h) ) $string .= $target_h;
+ if ( $ext == 'jpg' || $ext == 'jpeg' || $ext == 'jpe' ) $string .= $quality;
$filename = 'imgt_';
$filename .= md5($string);
$filename .= '.'.$ext;
@@ -181,6 +184,10 @@ class imageThumb {
// ==============================================
+ function get_type () {
+ return ( empty($this->output_format) ) ? $this->type : $this->output_format ;
+ }
+
function rfile ($file){
if (!isset($file)) return false;
if (is_file($file)) {
diff --git a/templates/slik/_icons.phtml b/templates/slik/_icons.phtml
index 4e1e1a5..81cb9f8 100644
--- a/templates/slik/_icons.phtml
+++ b/templates/slik/_icons.phtml
@@ -7,14 +7,25 @@
..
=$lang->parent_dir?>
- $n = 1; foreach ($dlist->list as $key => $item): $info = ($item['type'] == 'file') ? $item[$config->tpl_file_info] : $item[$config->tpl_folder_info] ; $thumbnail = (Icon::is_image($item['ext']) && $config->thumbnails) ? ", '".Icon::get_thumbnail_url($item['name'], $config->tpl_preview_width, $config->tpl_preview_height)."'" : '' ; ?>
+
+ $n = 1;
+ foreach ($dlist->list as $key => $item):
+ $info = ($item['type'] == 'file') ? $item[$config->tpl_file_info] : $item[$config->tpl_folder_info] ;
+ if ( Icon::is_image($item['ext']) && $config->thumbnails ) {
+ $thumbnail = ", '".Icon::get_thumbnail_url($item['name'], $config->tpl_preview_width, $config->tpl_preview_height)."'";
+ } else $thumbnail = '';
+ ?>
+ ?>)
+ =Path::breakFilename($item['name'], $config->tpl_file_maxlength, $config->tpl_wordbreak)?>
+ =$info?>
=$item['name']?>
if ( !empty($fields['size']) && $item['type'] == 'file' ) {
echo $lang->size.': '.$item['size'];
- if (!preg_match('/bytes/i', $item['size'])) echo ' ('.number_format($item['size_raw']).' bytes)';
+ if (strpos($item['size'], 'bytes') === false)
+ echo ' ('.number_format($item['size_raw']).' bytes)';
echo '
';
}
if ( !empty($fields['mtime']) && $item['type'] == 'file' ) echo $lang->mtime.': '.$item['mtime'].'
';
@@ -27,9 +38,6 @@
if ( !empty($fields['group_id']) ) echo $lang->group_id.': '.$item['group_id'].'
';
?>
- ?>)
- =Path::breakFilename($item['name'], $config->tpl_file_maxlength, $config->tpl_wordbreak)?>
- =$info?>
$n++; endforeach; ?>
diff --git a/thumb.php b/thumb.php
index d259718..6c7f600 100644
--- a/thumb.php
+++ b/thumb.php
@@ -30,7 +30,7 @@ require_once('libs/imagethumb.lib.php');
$src = ( !empty($_GET['src']) ) ? $_GET['src'] : false ;
$w = ( !empty($_GET['w']) && preg_match("/[0-9]{1,4}/", $_GET['w']) ) ? $_GET['w'] : null ;
$h = ( !empty($_GET['h']) && preg_match("/[0-9]{1,4}/", $_GET['w']) ) ? $_GET['h'] : null ;
-$q = ( !empty($_GET['q']) ) ? $_GET['q'] : false ;
+$q = ( !empty($_GET['q']) && $_GET['q'] >= 0 && $_GET['q'] <= 100) ? $_GET['q'] : false ;
//TODO load sizes from config instead of from $_GET vars for security reasons...