From edf251dbece667e993196b000b9ce606f22c423d Mon Sep 17 00:00:00 2001 From: jim Date: Sun, 9 Apr 2006 18:00:39 +0000 Subject: [PATCH] - thumbnail support is fully functional with custom imageThumb class which supports caching and so on, the class is still considered beta (specially the clean_cache() function) - updated simple template - added Last Access (atime) to dirlist.lib.php - updated and fixed loads of other things git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@18 a5845835-ea0f-0410-a762-dd0bfe9bfde8 --- config.php | 6 +- exec/core.exec.php | 2 +- exec/icons.exec.php | 18 +- icons/osx/config.ini | 4 + index.php | 2 +- languages/english.lang.php | 3 +- languages/swedish.lang.php | 5 +- libs/dirlist.lib.php | 7 +- libs/exechandler.lib.php | 2 +- libs/imagethumb.lib.php | 203 ++++++++++++++++++ resources/init.php | 8 +- templates/simple/_details.phtml | 2 +- templates/simple/_icons.phtml | 4 +- templates/simple/index.phtml | 6 +- .../{screen.css => screen.css.php} | 16 +- thumb.php | 26 +++ 16 files changed, 289 insertions(+), 25 deletions(-) create mode 100644 libs/imagethumb.lib.php rename templates/simple/stylesheets/{screen.css => screen.css.php} (90%) create mode 100644 thumb.php diff --git a/config.php b/config.php index 3f1f65a..4e4f10a 100644 --- a/config.php +++ b/config.php @@ -27,9 +27,9 @@ $config = array( # show hidden files & folders who's names begin with . (dot) 'show_hidden' => false, - # what info to show for each file/folder, valid values are: + # what info to show for each file/folder in details view, valid values are: # name, size, mtime, perms, chmod, owner, ownerid, group, groupid, ext - # (must contain "name", for basic directory listing functionality) + # (must at least contain "name" for basic directory listing functionality) 'fields' => 'name,size,mtime,perms,owner', // Display settings @@ -59,7 +59,7 @@ $config = array( 'path_plugins' => array('plugins'), 'path_cache' => 'cache', - 'req_lang_ver' => '1.0.2', + 'req_lang_ver' => '1.0.5', diff --git a/exec/core.exec.php b/exec/core.exec.php index 715eeb5..d2f6ebe 100644 --- a/exec/core.exec.php +++ b/exec/core.exec.php @@ -12,7 +12,7 @@ Name: core Priority: 40 Author: Jim Myhrberg -Include: output.exc.php, language.exc.php +Include: language.exc.php, output.exc.php */ //_SCRIPT; diff --git a/exec/icons.exec.php b/exec/icons.exec.php index 77ab0c8..74f899c 100644 --- a/exec/icons.exec.php +++ b/exec/icons.exec.php @@ -23,18 +23,20 @@ Author: Jim Myhrberg class Icon { //>Section> get_url - function get_url ($ext, $size, $type) { - //TODO enable thumbnail support using phpThumbs + function get_url ($file, $size, $type, $thumbnail=false) { global $config; if ( $size == 'large' || $size == 'big' ) { $size = $config->icons_large; } else { $size = $config->icons_small; } + $ext = ( preg_match("/.*\.(.*)/", $file, $ext) ) ? $ext[1] : '' ; $icons_path = ICONS_PATH.$size.'/'; $icons_url = ICONS_URL.$size.'/'; if ( $type == 'file' ) { - if ( file_exists($icons_path.$ext.$config->icons_ext) ) { + if ( preg_match("/jpg|jpeg|png/", $ext) && $thumbnail ) { + return DLIST_URL.'thumb.php?src='.urlencode(DIR_URL.$file).'&w=48&h=48'; + } elseif ( file_exists($icons_path.$ext.$config->icons_ext) ) { return $icons_url.$ext.$config->icons_ext; } else { return $icons_url.'_file'.$config->icons_ext; @@ -58,6 +60,16 @@ class Icon { } return ICONS_URL.$size.'/_parent'.$config->icons_ext; } + +//>Section> is_image + function is_image ($file) { + if ( preg_match("/.*\.(jpg|jpeg|png|gif|bmp)/", $file) ) { + return true; + } elseif ( preg_match("/jpg|jpeg|png|gif|bmp/", $file) ) { + return true; + } + return false; + } //> class.end } diff --git a/icons/osx/config.ini b/icons/osx/config.ini index 3638de6..8addc79 100644 --- a/icons/osx/config.ini +++ b/icons/osx/config.ini @@ -9,5 +9,9 @@ small = 16x16 ; Large icons... large = 48x48 +; Large icon sizes, used to deterim thumbnails sizes to match icons +large_w = 48 +large_h = 48 + ; File extension of icon files ext = .gif \ No newline at end of file diff --git a/index.php b/index.php index 903833e..47fd53b 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,7 @@ /* - dList v2.1.4 beta + dList v2.2.0 beta Copyright © 2006 Jim Myhrberg. All rights reserved. zynode@gmail.com diff --git a/languages/english.lang.php b/languages/english.lang.php index 155ca57..57afc46 100644 --- a/languages/english.lang.php +++ b/languages/english.lang.php @@ -4,7 +4,7 @@ class lang { // Language settings var $_language = 'english'; // local language name ("svenska" for swedish)... - var $_version = '1.0.4'; + var $_version = '1.0.5'; // Locale settings @@ -18,6 +18,7 @@ class lang { var $name = 'Name'; var $size = 'Size'; var $mtime = 'Date Modified'; + var $atime = 'Last Accessed'; var $perms = 'Permissions'; var $chmod = 'CHMOD'; var $owner = 'Owner'; diff --git a/languages/swedish.lang.php b/languages/swedish.lang.php index c5d1555..af9e5b0 100644 --- a/languages/swedish.lang.php +++ b/languages/swedish.lang.php @@ -4,7 +4,7 @@ class lang { // Language settings var $_language = 'svenska'; // local language name ("svenska" for swedish)... - var $_version = '1.0.4'; + var $_version = '1.0.5'; // Locale settings @@ -18,6 +18,7 @@ class lang { var $name = 'Namn'; var $size = 'Storlek'; var $mtime = 'Datum Ändrad'; + var $atime = 'Sisst Öppnad'; //FIXME possibly incorrect var $perms = 'Rättigheter'; var $chmod = 'CHMOD'; var $owner = 'Ägare'; @@ -25,7 +26,7 @@ class lang { var $owner_id = 'Ägare ID'; var $group_id = 'Grupp ID'; var $type = 'Typ'; - var $ext = 'Ext'; // incorrect translation + var $ext = 'Ext'; //FIXME incorrect translation var $timer_string = 'Sidan genererades på %s sekunder'; diff --git a/libs/dirlist.lib.php b/libs/dirlist.lib.php index 5c98778..7731811 100644 --- a/libs/dirlist.lib.php +++ b/libs/dirlist.lib.php @@ -4,7 +4,7 @@ class dirList { /* - Class: dirList v2.0.6 beta + Class: dirList v2.0.7 beta Copyright © 2006 Jim Myhrberg. All rights reserved. zynode@gmail.com @@ -57,6 +57,7 @@ class dirList { 'name' => 'name,mtime,size', 'size' => 'size,name,mtime', 'mtime' => 'mtime,name,size', + 'atime' => 'atime,name,size', 'type' => 'type,name,size,mtime', 'ext' => 'ext,name,size,mtime', 'group' => 'group,name,size,mtime', @@ -97,6 +98,7 @@ class dirList { foreach( $sort_by as $v ) { if ( $v == 'size' ) $v = 'size_raw'; if ( $v == 'mtime' ) $v = 'mtime_raw'; + if ( $v == 'atime' ) $v = 'atime_raw'; $list_key .= ( $v == 'size_raw' || $v == 'mtime' ) ? str_pad($item_details[$v], 28, '0', STR_PAD_LEFT).'|' : $item_details[$v].'|' ; } $this->list[strtolower($list_key)] = $item_details; @@ -128,10 +130,13 @@ class dirList { // Last Modified $return['mtime_raw'] = filemtime($item); + $return['atime_raw'] = fileatime($item); if ( $this->use_smartdate ) { $return['mtime'] = $this->smartDate($return['mtime_raw'], $this->smartdate_date, $this->smartdate_time, $this->smartdate); + $return['atime'] = $this->smartDate($return['atime_raw'], $this->smartdate_date, $this->smartdate_time, $this->smartdate); } else { $return['mtime'] = date($this->standard_date_format, $return['mtime_raw']); + $return['atime'] = date($this->standard_date_format, $return['atime_raw']); } // Permissions and CHMOD value diff --git a/libs/exechandler.lib.php b/libs/exechandler.lib.php index c524747..b806684 100644 --- a/libs/exechandler.lib.php +++ b/libs/exechandler.lib.php @@ -391,7 +391,7 @@ class execHandler { return $file_data; } - function write2file($file, $string, $mode="wb", $lock=2){ + function write2file($file, $string, $mode="wt", $lock=2){ if ( !isset($file) ) return false; $fp = fopen($file, $mode); if ($fp != false) { diff --git a/libs/imagethumb.lib.php b/libs/imagethumb.lib.php new file mode 100644 index 0000000..eeeb6b2 --- /dev/null +++ b/libs/imagethumb.lib.php @@ -0,0 +1,203 @@ +load($src); + } + + +// ============================================== +// ----- [ Public Functions ] ------------------- +// ============================================== + + + function quick ($file, $width, $height, $quality=false) { + if ( !$this->check_cache($file, $width, $height) ) { + $this->load($file); + if ( $this->error == false) { + $this->resize($width, $height); + if ( !empty($quality) ) $this->jpg_quality = $quality; + $this->output(); + $this->save_to_cache(); + $this->destroy(); + } + } + $this->clean_cache(); + } + + function load ($file) { + if ( is_readable($file) && preg_match("/.*\.(jpg|jpeg|png)/i", $file, $type) ) { + $this->type = $type = $type[1]; + $this->image = ( $type == 'png' ) ? imagecreatefrompng($file) : imagecreatefromjpeg($file) ; + $this->src_file = $file; + $this->last_modified = filemtime($file); + } else { $this->error = true; return false; } + } + + function resize ($width=null, $height=null, $onlydown=true, $keepratio=true) { + if ( $width != null || $height != null ) { + $src_w = imageSX($this->image); + $src_h = imageSY($this->image); + if ( $width == null ) $width = 5000; + if ( $height == null ) $height = 5000; + $size = $this->resize_dimensions($src_w, $src_h, $width, $height, $onlydown, $keepratio); + $image = imagecreatetruecolor($size['w'], $size['h']); + imagecopyresampled($image, $this->image, 0, 0, 0, 0, $size['w'], $size['h'], $src_w, $src_h); + $this->image = $image; + $this->target_w = $width; + $this->target_h = $height; + } + } + + function output ($file=null) { + $type = ( empty($this->output_format) ) ? $this->type : $this->output_format ; + if ( $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) ; + } else { + header('Content-type: image/jpeg'); + header('Content-disposition: image; filename="'.basename($this->src_file).'"'); + imagejpeg($this->image, $file, $this->jpg_quality); + } + } + + function destroy () { + imagedestroy($this->image); + } + +// Caching Functions + + function save_to_cache () { + if ( !preg_match("/\/$/", $this->cache_dir) ) $this->cache_dir .= '/'; + if ( is_writable($this->cache_dir) ) { + $filename = 'imgt_'; + $string = $this->src_file.$this->last_modified; + if ( !empty($this->target_w) && !empty($this->target_h)) $string .= $this->target_w.$this->target_h; + $filename .= md5($string); + $filename .= '.'.$this->type; + if( !file_exists($filename) ) { + if ( $this->type == 'png' ) { + imagepng($this->image, $this->cache_dir.$filename); + } else { + imagejpeg($this->image, $this->cache_dir.$filename); + } + } + } + } + + function check_cache ($file, $target_w=null, $target_h=null) { + if ( is_readable($file) ) { + $ext = preg_replace("/.*\.(.*)/", "$1", $file); + $filename = 'imgt_'; + $string = $file.filemtime($file); + if ( !empty($target_w) && !empty($target_h) ) $string .= $target_w.$target_h; + $filename .= md5($string); + $filename .= '.'.$ext; + if ( is_readable($this->cache_dir.$filename) ) { + ( $ext == 'png' ) ? header('Content-type: image/png') : header('Content-type: image/jpeg'); + header('Content-disposition: image; filename="'.basename($this->src_file).'"'); + echo $this->rfile($this->cache_dir.$filename); + return true; + } + } + return false; + } + + function clean_cache () { + if ( is_readable($this->cache_dir.$this->last_clean_file) ) { + $last_clean = $this->rfile($this->cache_dir.$this->last_clean_file); + } else { $last_clean = 0; } + + $clean_cache = $this->clean_cache * 3600; + $cache_validity = $this->cache_validity * 86400; + if ( time() > ($last_clean + $clean_cache) ) { + $this->write2file($this->cache_dir.$this->last_clean_file, time()); + $glob = glob($this->cache_dir.'*'); + foreach( $glob as $key => $value ) { + if ( preg_match("/(?:.*\/|)(imgt_.*?\.(jpg|jpeg|png))/i", $value) && (fileatime($value) + $cache_validity) < time() ) { + unlink($value); + } + } + } + } + + +// ============================================== +// ----- [ Internal Functions ] ----------------- +// ============================================== + + + function rfile ($file){ + if (!isset($file)) return false; + if (is_file($file)) { + if (!($fh = fopen($file,'r'))) return false; + $file_data = fread($fh, filesize($file)); + fclose($fh); + } else { return false; } + return $file_data; + } + + function write2file($file, $string, $mode="wt", $lock=2){ + if ( !isset($file) ) return false; + $fp = fopen($file, $mode); + if ($fp != false) { + flock($fp,$lock); + $re = fwrite($fp,$string); + $re2 = fclose($fp); + if ($re != false && $re2 != false) return true; + } + return false; + } + + function resize_dimensions ($src_w, $src_h, $w, $h, $onlydown=true, $keepratio=true) { + $img_w = ( $w >= $src_w && $onlydown ) ? $src_w : $w ; + $img_h = ( $h >= $src_h && $onlydown ) ? $src_h : $h ; + + if ( $keepratio ) { + $ratio = $src_w / $src_h; + if ( $ratio > ($img_w / $img_h) ) { + $img_h = $src_h / ($src_w / $img_w); + } elseif ( $ratio < ($img_w / $img_h) ) { + $img_w = $src_w / ($src_h / $img_h); + } + } + return array('w'=>$img_w, 'h'=>$img_h); + } + +} + +?> \ No newline at end of file diff --git a/resources/init.php b/resources/init.php index e8177d9..314bb76 100644 --- a/resources/init.php +++ b/resources/init.php @@ -31,8 +31,12 @@ if(!preg_match("/\/$/", $dir_url)) $redirect = '/'; if ( empty($redirect) ) { // path lookup - $dir_path = apache_lookup_uri($dir_url); - $dir_path = ( is_array($dir_path) ) ? $dir_path['filename'] : $dir_path->filename ; + if ( function_exists('apache_lookup_uri') ) { + $dir_path = apache_lookup_uri($dir_url); + $dir_path = ( is_array($dir_path) ) ? $dir_path['filename'] : $dir_path->filename ; + } else { + $dir_path = $_SERVER['DOCUMENT_ROOT'].$dir_url; + } if(!preg_match("/\/$/", $dir_path)) $dir_path .= '/'; // check for index files and redirect if found diff --git a/templates/simple/_details.phtml b/templates/simple/_details.phtml index 1678ff4..e9685ae 100644 --- a/templates/simple/_details.phtml +++ b/templates/simple/_details.phtml @@ -13,7 +13,7 @@ list as $key => $item): ?> - icon + icon $value): if ($key == 'name'):?> diff --git a/templates/simple/_icons.phtml b/templates/simple/_icons.phtml index ce3172b..9b9d1c3 100644 --- a/templates/simple/_icons.phtml +++ b/templates/simple/_icons.phtml @@ -6,10 +6,10 @@ \ No newline at end of file diff --git a/templates/simple/index.phtml b/templates/simple/index.phtml index c93c4e6..6327d70 100644 --- a/templates/simple/index.phtml +++ b/templates/simple/index.phtml @@ -5,11 +5,7 @@ <?=$lang->index_of.' '.DIR_URL?> - +