From 3f5b4da066bfe6db30235c95951152cd26e6c5d9 Mon Sep 17 00:00:00 2001 From: jim Date: Mon, 17 Apr 2006 16:46:05 +0000 Subject: [PATCH] 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 --- config.php | 25 +++++-- exec/core.exec.php | 14 +++- exec/icons.exec.php | 4 +- exec/language.exec.php | 7 ++ exec/output.exec.php | 39 ++++++++++ index.php | 4 +- languages/english.lang.php | 24 +++++- languages/finnish.lang.php | 73 +++++++++++++++++++ languages/swedish.lang.php | 42 ++++++++--- libs/dirlist.lib.php | 61 +++++++++++++--- libs/imagethumb.lib.php | 16 ++-- templates/simple/_icons.phtml | 3 +- templates/simple/index.phtml | 9 +-- templates/simple/stylesheets/css.php | 7 ++ .../{screen.css.php => screen.css} | 28 ++++--- 15 files changed, 299 insertions(+), 57 deletions(-) create mode 100644 languages/finnish.lang.php create mode 100644 templates/simple/stylesheets/css.php rename templates/simple/stylesheets/{screen.css.php => screen.css} (94%) diff --git a/config.php b/config.php index 4e4f10a..b892c67 100644 --- a/config.php +++ b/config.php @@ -15,10 +15,16 @@ $config = array( # leave blank to autodetect from $_SERVER['SCRIPT_NAME'] 'dlist_url' => '', - # show debug messages, for exechandler to always re-parse all files + # if dlist is accessable from multiple urls (installed in /dev/dlist/, + # but also accessable via /dlist/ thanks to an alias) please specify + # the real path(s) here as array keys + 'alt_urls' => array('/dev/dlist'), + + # show debug messages, exechandler to always re-parse all files 'debug' => true, - # by default dList will sort by this + # by default dList will sort by this, for more details, + # check the dirlist function in libs/dirlist.lib.php 'default_sort' => 'name', @@ -27,8 +33,12 @@ $config = array( # show hidden files & folders who's names begin with . (dot) 'show_hidden' => false, + # use regular expressions to filter out specific files and folders from + # being displayed, and browseable + 'filter_out' => array(), + # what info to show for each file/folder in details view, valid values are: - # name, size, mtime, perms, chmod, owner, ownerid, group, groupid, ext + # name, size, mtime, atime, perms, chmod, owner, ownerid, group, groupid, ext # (must at least contain "name" for basic directory listing functionality) 'fields' => 'name,size,mtime,perms,owner', @@ -38,12 +48,15 @@ $config = array( # dList will default to english. 'language' => 'english', - # name of the cookie dList will check for language settings per user - 'lang_cookie' => 'dList_language', + # show thumbnails for JPEG and PNG images? + 'thumbnails' => true, # Smart Date shows relative time stamps ("Yesterday, 09:34") when applicable 'smartdate' => true, + # name of the cookie dList will check for language settings per user + 'lang_cookie' => 'dList_language', + // Template & Icon settings @@ -59,7 +72,7 @@ $config = array( 'path_plugins' => array('plugins'), 'path_cache' => 'cache', - 'req_lang_ver' => '1.0.5', + 'req_lang_ver' => '1.0.7', diff --git a/exec/core.exec.php b/exec/core.exec.php index d2f6ebe..ad11f7e 100644 --- a/exec/core.exec.php +++ b/exec/core.exec.php @@ -52,8 +52,10 @@ $do_sort_reverse = false; //>Section> do_readdir if ( $do_readdir ) { + //>Section> readdir.start $dlist = new dirList(); + //>Section> readdir.options if ( $do_sort_items ) { $dlist->sort_by = $do_sort_by; @@ -61,9 +63,20 @@ if ( $do_readdir ) { } else $dlist->sort_items = false; if ($config->show_hidden) $dlist->show_hidden = true; if ( !$config->smartdate ) $dlist->use_smartdate = false; + $dlist->dir_url = DIR_URL; + + //>Section> readdir.filter_out + if ( !empty($config->filter_out) ) $dlist->filter_out = '/'.implode('|', $config->filter_out).'/i'; + + //>Section> readdir.hide_self + $alt_string = ( empty($config->alt_urls) ) ? '' : '|^'.str_replace('/', '\/', implode('$|^', $config->alt_urls)).'$' ; + $dlist->hide_self = '/^'.str_replace('/', '\/', DLIST_URL).'$'.$alt_string.'/i'; + //>Section> readdir.read $dlist->read(DIR_PATH); + //>Section> do_readdir.end + } //========================== @@ -72,6 +85,5 @@ if ( $do_readdir ) { - //_END; ?> \ No newline at end of file diff --git a/exec/icons.exec.php b/exec/icons.exec.php index 74f899c..403a24f 100644 --- a/exec/icons.exec.php +++ b/exec/icons.exec.php @@ -34,8 +34,8 @@ class Icon { $icons_path = ICONS_PATH.$size.'/'; $icons_url = ICONS_URL.$size.'/'; if ( $type == 'file' ) { - if ( preg_match("/jpg|jpeg|png/", $ext) && $thumbnail ) { - return DLIST_URL.'thumb.php?src='.urlencode(DIR_URL.$file).'&w=48&h=48'; + if ( preg_match("/jpg|jpeg|jpe|png/i", $ext) && $thumbnail && $config->thumbnails ) { + return DLIST_URL.'thumb.php?src='.rawurlencode(DIR_URL.$file).'&w=48&h=48'; } elseif ( file_exists($icons_path.$ext.$config->icons_ext) ) { return $icons_url.$ext.$config->icons_ext; } else { diff --git a/exec/language.exec.php b/exec/language.exec.php index e9f7cd7..5a1d3f4 100644 --- a/exec/language.exec.php +++ b/exec/language.exec.php @@ -49,6 +49,7 @@ foreach( $language_files as $key => $value ) { if ( !isset($local_names[$language]) ) { execHandler::write2file($config->path_cache.'/local_names.ini', "\n".$language.'='.$lang->_language, 'at'); } +// sort($installed_languages); //>Section> warning:10 if ( $lang->_version < $config->req_lang_ver ) { @@ -79,12 +80,18 @@ define('LANG_VER', $lang->_version); //>After> core.readdir.options +//TODO add date formatting options to language files $dlist->lang_tomorrow = $lang->sd_tomorrow; $dlist->lang_today = $lang->sd_today; $dlist->lang_yesterday = $lang->sd_yesterday; $dlist->lang_2_days_ago = $lang->sd_2_days_ago; $dlist->lang_3_days_ago = $lang->sd_3_days_ago; +if ( !empty($lang->standard_date_format) ) $dlist->standard_date_format = $lang->standard_date_format; +if ( !empty($lang->sd_format) ) $dlist->smartdate = $lang->sd_format; +if ( !empty($lang->sd_date) ) $dlist->smartdate_date = $lang->sd_date; +if ( !empty($lang->sd_time) ) $dlist->smartdate_time = $lang->sd_time; + //_END; diff --git a/exec/output.exec.php b/exec/output.exec.php index 7427375..f1aa956 100644 --- a/exec/output.exec.php +++ b/exec/output.exec.php @@ -38,6 +38,45 @@ class Path { } else return false; } + //>Section> path.stats + function stats ($files=0, $folders=0, $totalsize=false) { + global $lang; + if ( !empty($folders) ) { + $r_folders = ( $folders > 1 ) ? str_replace('%n', $folders, $lang->stats_folders) : str_replace('%n', $folders, $lang->stats_folder) ; + } + if ( !empty($files) ) { + $r_files = ( $files > 1 ) ? str_replace('%n', $files, $lang->stats_files) : str_replace('%n', $files, $lang->stats_file) ; + if ( !empty($totalsize) ) { + $r_files = str_replace('%f', $r_files, $lang->stats_totalsize); + $r_files = str_replace('%s', $totalsize, $r_files); + } + } + if ( !empty($r_folders) && !empty($r_files) ) { + $return = str_replace('%d', $r_folders, $lang->stats_template); + return str_replace('%f', $r_files, $return); + } elseif ( !empty($r_folders) ) { + return $r_folders; + } elseif ( !empty($r_files) ) { + return $r_files; + } + } + + //>Section> path_wordwrap + function wordbreak ($input, $length, $break=" ") { + if (preg_match("/(.*)\.(.*)/", $input, $preg) ) { + $words = explode(' ', $preg[1]); + $ext = '.'.$preg[2]; + } else { + $words = explode(' ', $input); + $ext = ''; + } + + foreach( $words as $key => $value ) { + $words[$key] = wordwrap($value, $length, $break, 1); + } + return implode(' ', $words).$ext; + } + //>Section> path_class.end } diff --git a/index.php b/index.php index 47fd53b..7a8a6d7 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,7 @@ /* - dList v2.2.0 beta + dList v2.2.3 beta Copyright © 2006 Jim Myhrberg. All rights reserved. zynode@gmail.com @@ -51,7 +51,7 @@ $exec->addPath( ) ); foreach( $config->path_plugins as $key => $value ) { - $exec->addPath($value.'/*.exc.php'); + $exec->addPath($value.'/*.exec.php'); } $exec->cache(); include($exec->include_file); diff --git a/languages/english.lang.php b/languages/english.lang.php index 57afc46..abfa26e 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.5'; + var $_version = '1.0.7'; // Locale settings @@ -28,14 +28,32 @@ class lang { var $type = 'Type'; var $ext = 'Extension'; - var $timer_string = 'Page generated in %s seconds'; - var $icons = 'Icons'; var $details = 'Details'; + var $timer_string = 'Page generated in %s seconds'; // %s = seconds + var $powered_by = 'Powered by dList'; + // Statistics + var $stats_folder = '%n folder'; + var $stats_folders = '%n folders'; + var $stats_file = '%n file'; + var $stats_files = '%n files'; + var $stats_totalsize = '%s in %f'; // %s = size, %f = number of files + var $stats_template = '%d, %f'; // %d = folders, %f = files + + + // Date Formatting + # check the PHP Manual for strftime() for details (http://www.php.net/manual/) + var $standard_date_format = '%B %e, %Y, %H:%M'; + # Smart Date formatting + var $sd_format = '{date}, {time}'; + var $sd_date = '%B %e, %Y'; + var $sd_time = '%H:%M'; + + // Smart Date var $sd_tomorrow = 'Tomorrow'; var $sd_today = 'Today'; diff --git a/languages/finnish.lang.php b/languages/finnish.lang.php new file mode 100644 index 0000000..ac2412b --- /dev/null +++ b/languages/finnish.lang.php @@ -0,0 +1,73 @@ + \ No newline at end of file diff --git a/languages/swedish.lang.php b/languages/swedish.lang.php index af9e5b0..6921cbc 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.5'; + var $_version = '1.0.7'; // Locale settings @@ -12,30 +12,48 @@ class lang { // General - var $index_of = 'Index av'; + var $index_of = 'Index av'; var $parent_dir = 'Tidigare Mapp'; - 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'; - var $group = 'Grupp'; + 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'; + var $group = 'Grupp'; var $owner_id = 'Ägare ID'; var $group_id = 'Grupp ID'; var $type = 'Typ'; var $ext = 'Ext'; //FIXME incorrect translation - var $timer_string = 'Sidan genererades på %s sekunder'; - var $icons = 'Ikoner'; var $details = 'Detaljer'; + var $timer_string = 'Sidan genererades på %s sekunder'; // %s = seconds + var $powered_by = 'Driven av dList'; + // Statistics + var $stats_folder = '%n mapp'; + var $stats_folders = '%n mappar'; + var $stats_file = '%n fil'; + var $stats_files = '%n filer'; + var $stats_totalsize = '%s i %f'; // %s = storlek, %f = antal filer + var $stats_template = '%d, %f'; // %d = mappar, %f = filer + + + // Date Formatting + # check the PHP Manual for strftime() for details (http://www.php.net/manual/) + var $standard_date_format = '%B %e, %Y, %H:%M'; + # Smart Date formatting + var $sd_format = '{date}, {time}'; + var $sd_date = '%B %e, %Y'; + var $sd_time = '%H:%M'; + + // Smart Date var $sd_tomorrow = 'Imorgon'; var $sd_today = 'Idag'; diff --git a/libs/dirlist.lib.php b/libs/dirlist.lib.php index 7731811..efe084e 100644 --- a/libs/dirlist.lib.php +++ b/libs/dirlist.lib.php @@ -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); diff --git a/libs/imagethumb.lib.php b/libs/imagethumb.lib.php index eeeb6b2..44b3870 100644 --- a/libs/imagethumb.lib.php +++ b/libs/imagethumb.lib.php @@ -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; } } diff --git a/templates/simple/_icons.phtml b/templates/simple/_icons.phtml index 9b9d1c3..0e962c9 100644 --- a/templates/simple/_icons.phtml +++ b/templates/simple/_icons.phtml @@ -1,3 +1,4 @@ +
stats_files, $dlist->stats_folders, $dlist->stats_totalsize)?>
class="current">name?> | @@ -9,7 +10,7 @@
  • ..

    parent_dir?>

  • list as $key => $item): $info = ($item['type'] == 'file') ? $item['size'] : $item['mtime'] ;?> -
  • +
  • \ No newline at end of file diff --git a/templates/simple/index.phtml b/templates/simple/index.phtml index 6327d70..8daecf5 100644 --- a/templates/simple/index.phtml +++ b/templates/simple/index.phtml @@ -4,8 +4,9 @@ <?=$lang->index_of.' '.DIR_URL?> + - +