mirror of
https://github.com/jimeh/dlist.git
synced 2026-02-18 23:46:39 +00:00
dList v2.2.3 beta
- started keeping track of version numbers properly - added finnish translation - edited multiple things in simple template - added file/folder hiding by the use of regular expressions - updated most main parts of dlist git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@19 a5845835-ea0f-0410-a762-dd0bfe9bfde8
This commit is contained in:
@@ -4,18 +4,35 @@ class dirList {
|
||||
|
||||
/*
|
||||
|
||||
Class: dirList v2.0.7 beta
|
||||
Class: dirList v2.0.9 beta
|
||||
|
||||
Copyright © 2006 Jim Myhrberg. All rights reserved.
|
||||
zynode@gmail.com
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// General settings
|
||||
var $sort_by = 'name';
|
||||
var $folders_first = true;
|
||||
var $show_hidden = false;
|
||||
|
||||
|
||||
// Filtering
|
||||
|
||||
# use regular expressions to match file & folders to hide
|
||||
# intended for dynamic changes from config files and more
|
||||
var $filter_out = '';
|
||||
|
||||
# used by filtering to match whole directory structures
|
||||
# but needs to be set manually for now.
|
||||
var $dir_url = '';
|
||||
|
||||
# regular expressions used to hide the script itself,
|
||||
# same as filter_out, but not intended to be modifed by
|
||||
# plugins and other means.
|
||||
var $hide_self = false;
|
||||
|
||||
|
||||
// Sorting
|
||||
var $sort_items = true;
|
||||
@@ -25,10 +42,10 @@ class dirList {
|
||||
|
||||
// Smart date formatting
|
||||
var $use_smartdate = true;
|
||||
var $standard_date_format = '%B %e, %Y, %H:%M';
|
||||
var $smartdate = '{date}, {time}';
|
||||
var $smartdate_date = '%B %e, %Y';
|
||||
var $smartdate_time = '%H:%M';
|
||||
var $standard_date_format = '%B %e, %Y, %H:%M';
|
||||
|
||||
|
||||
// Smart date language settings
|
||||
@@ -47,10 +64,10 @@ class dirList {
|
||||
var $stats_count = 0;
|
||||
var $stats_files = 0;
|
||||
var $stats_folders = 0;
|
||||
var $stats_totalsize = 0;
|
||||
var $stats_totalsize_raw = 0;
|
||||
var $stats_totalsize;
|
||||
|
||||
// Construtor - does nothing, but is here just
|
||||
// incase it might do something in the future...
|
||||
// Construtor
|
||||
function dirlist() {
|
||||
// sorting orders
|
||||
$this->sort_order = array(
|
||||
@@ -81,13 +98,12 @@ class dirList {
|
||||
if($dh = @opendir($dir)) {
|
||||
$this->parent = $this->getDetails($dir);
|
||||
while(false !== ($item = readdir($dh))) {
|
||||
$hidden_item = ( $this->show_hidden ) ? false : preg_match("/^\./", $item) ;
|
||||
if( ($item != '.' && $item != '..') && !$hidden_item ) {
|
||||
if( $this->show_item($item) ) {
|
||||
$item_details = $this->getDetails($dir.$item);
|
||||
// stats
|
||||
$this->stats_count++;
|
||||
if ( $item_details['type'] == 'file' ) {
|
||||
$this->stats_totalsize += $item_details['size_raw'];
|
||||
$this->stats_totalsize_raw += $item_details['size_raw'];
|
||||
$this->stats_files++;
|
||||
} else {
|
||||
$this->stats_folders++;
|
||||
@@ -99,7 +115,13 @@ class dirList {
|
||||
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].'|' ;
|
||||
if ( $v == 'name' ) {
|
||||
$list_key .= $this->process_filename_for_sorting($item_details[$v]).'|';
|
||||
} elseif ( $v == 'size_raw' || $v == 'mtime' || $v == 'atime' ) {
|
||||
$list_key .= str_pad($item_details[$v], 28, '0', STR_PAD_LEFT).'|';
|
||||
} else {
|
||||
$list_key .= $item_details[$v].'|';
|
||||
}
|
||||
}
|
||||
$this->list[strtolower($list_key)] = $item_details;
|
||||
} else {
|
||||
@@ -110,6 +132,7 @@ class dirList {
|
||||
if ( $this->sort_items ) {
|
||||
( $this->reverse ) ? krsort($this->list) : ksort($this->list) ;
|
||||
}
|
||||
$this->stats_totalsize = $this->format_filesize($this->stats_totalsize_raw);
|
||||
return true;
|
||||
}else{ $this->error = true; return false; }
|
||||
closedir($dh);
|
||||
@@ -120,6 +143,26 @@ class dirList {
|
||||
// ----- [ Internal Functions ] -----------------
|
||||
// ==============================================
|
||||
|
||||
function show_item ($item) {
|
||||
$hidden_item = ( $this->show_hidden ) ? false : preg_match("/^\./", $item) ;
|
||||
$filter_out = ( empty($this->filter_out) ) ? false : preg_match($this->filter_out, $this->dir_url.$item) ;
|
||||
$hide_self = ( empty($this->hide_self) ) ? false : preg_match($this->hide_self, $this->dir_url.$item) ;
|
||||
if ( $item != '.' && $item != '..' && !$hidden_item && !$filter_out && !$hide_self ) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function process_filename_for_sorting ($input) {
|
||||
if ( preg_match_all("/(.*?)([0-9]+)/i", $input, $preg) ) {
|
||||
$foot = preg_replace("/^.*[0-9]+(\D*?)$/", "$1", $input);
|
||||
$newstring = '';
|
||||
foreach( $preg[1] as $key => $value ) {
|
||||
$newstring .= $value.str_pad($preg[2][$key], 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
return $newstring.$foot;
|
||||
}
|
||||
return $input;
|
||||
}
|
||||
|
||||
function getDetails ($item) {
|
||||
$item = str_replace("\\", '/', $item);
|
||||
$return['name'] = basename($item);
|
||||
|
||||
@@ -59,7 +59,7 @@ class imageThumb {
|
||||
}
|
||||
|
||||
function load ($file) {
|
||||
if ( is_readable($file) && preg_match("/.*\.(jpg|jpeg|png)/i", $file, $type) ) {
|
||||
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->src_file = $file;
|
||||
@@ -104,9 +104,9 @@ class imageThumb {
|
||||
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 = 'imgt_';
|
||||
$filename .= md5($string);
|
||||
$filename .= '.'.$this->type;
|
||||
if( !file_exists($filename) ) {
|
||||
@@ -121,16 +121,20 @@ class imageThumb {
|
||||
|
||||
function check_cache ($file, $target_w=null, $target_h=null) {
|
||||
if ( is_readable($file) ) {
|
||||
$ext = preg_replace("/.*\.(.*)/", "$1", $file);
|
||||
$filename = 'imgt_';
|
||||
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;
|
||||
$filename = 'imgt_';
|
||||
$filename .= md5($string);
|
||||
$filename .= '.'.$ext;
|
||||
if ( is_readable($this->cache_dir.$filename) ) {
|
||||
//TODO possibly redirect instead of loading image in script
|
||||
// header('Location: '.dirname($_SERVER['SCRIPT_URL']).'/'.$this->cache_dir.$filename);
|
||||
// return true;
|
||||
( $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);
|
||||
header('Content-disposition: image; filename="'.$file_pieces[1].'_thumb.'.$file_pieces[2].'"');
|
||||
print($this->rfile($this->cache_dir.$filename));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user