mirror of
https://github.com/jimeh/dlist.git
synced 2026-02-18 23:46:39 +00:00
modified thumbnail url pattern to make it shorter, and save some bandwidth when displaying very long file lists (and it also looks prettier :D)
git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@37 a5845835-ea0f-0410-a762-dd0bfe9bfde8
This commit is contained in:
10
.htaccess
Normal file
10
.htaccess
Normal file
@@ -0,0 +1,10 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
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
|
||||
|
||||
</IfModule>
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -7,14 +7,25 @@
|
||||
<p class="n">..</p>
|
||||
<p class="i"><?=$lang->parent_dir?></p>
|
||||
</a>
|
||||
</li><? $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)."'" : '' ; ?>
|
||||
</li><?
|
||||
$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 = '';
|
||||
?>
|
||||
<li>
|
||||
<a href="<?=rawurlencode($item['name'])?><? if($item['type'] == 'dir') echo '/'; ?>" onmouseover="iP(<?=$n.$thumbnail?>)" onmouseout="o()">
|
||||
<p class="p"><img src="<?=Icon::get_url($item['name'], 'large', $item['type'], true)?>" alt="" /></p>
|
||||
<p class="n"><?=Path::breakFilename($item['name'], $config->tpl_file_maxlength, $config->tpl_wordbreak)?></p>
|
||||
<p class="i"><?=$info?></p>
|
||||
<span id="p<?=$n?>"><div class="name"><?=$item['name']?></div>
|
||||
<?
|
||||
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 '<br />';
|
||||
}
|
||||
if ( !empty($fields['mtime']) && $item['type'] == 'file' ) echo $lang->mtime.': '.$item['mtime'].'<br />';
|
||||
@@ -27,9 +38,6 @@
|
||||
if ( !empty($fields['group_id']) ) echo $lang->group_id.': '.$item['group_id'].'<br />';
|
||||
?>
|
||||
</span>
|
||||
<p class="p"><img src="<?=Icon::get_url($item['name'], 'large', $item['type'], true)?>" alt="" /></p>
|
||||
<p class="n"><?=Path::breakFilename($item['name'], $config->tpl_file_maxlength, $config->tpl_wordbreak)?></p>
|
||||
<p class="i"><?=$info?></p>
|
||||
</a>
|
||||
</li><? $n++; endforeach; ?>
|
||||
</ul>
|
||||
|
||||
@@ -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...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user