mirror of
https://github.com/jimeh/dlist.git
synced 2026-02-18 23:46:39 +00:00
- added full icon support (still needs tweaking)
- very simple but powerful template system working (also needs tweaking, a fair amount of it) - other fixes to both dirlist.lib.php, exechandler.lib.php, config.lib.php and more... git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@9 a5845835-ea0f-0410-a762-dd0bfe9bfde8
This commit is contained in:
@@ -4,7 +4,7 @@ class config {
|
||||
|
||||
/*
|
||||
|
||||
Class: config v0.1 beta
|
||||
Class: config v0.2 beta
|
||||
|
||||
Copyright © 2006 Jim Myhrberg. All rights reserved.
|
||||
zynode@gmail.com
|
||||
@@ -17,7 +17,8 @@ class config {
|
||||
}
|
||||
|
||||
// Main function
|
||||
function parse ($input, $overwrite=true) {
|
||||
function parse ($input, $overwrite=true, $pad=false) {
|
||||
if ( !empty($pad) ) $this->_config_pad = $pad;
|
||||
if ( is_array($input) ) {
|
||||
$this->parse_array($input, $overwrite);
|
||||
} elseif ( is_string($input) ) {
|
||||
@@ -27,6 +28,7 @@ class config {
|
||||
$this->parse_ini_file($input);
|
||||
}
|
||||
}
|
||||
unset($this->_config_pad);
|
||||
}
|
||||
|
||||
// Parse settings from an array
|
||||
@@ -36,10 +38,12 @@ class config {
|
||||
if ( is_array($value) ) {
|
||||
foreach( $value as $k => $v ) {
|
||||
if ( ($empty = empty($this->$key)) || $overwrite ) {
|
||||
if ( !empty($this->_config_pad) ) $k = $this->_config_pad.$k;
|
||||
$this->$key = ( $empty ) ? array($k=>$v) : array_merge($this->$key, array($k=>$v)) ;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
if ( !empty($this->_config_pad) ) $key = $this->_config_pad.$key;
|
||||
if ( $overwrite || empty($this->$key) ) $this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ class dirList {
|
||||
|
||||
/*
|
||||
|
||||
Class: dirList v2.0 beta
|
||||
Class: dirList v2.0.2 beta
|
||||
|
||||
Copyright © 2006 Jim Myhrberg. All rights reserved.
|
||||
zynode@gmail.com
|
||||
@@ -21,14 +21,16 @@ class dirList {
|
||||
var $reverse = false;
|
||||
|
||||
// Smart date formatting
|
||||
var $use_smartdate = true;
|
||||
var $smartdate = '{date}, {time}';
|
||||
var $smartdate_date = 'F d, Y';
|
||||
var $smartdate_time = 'H:i';
|
||||
var $standard_date_format = 'F d, Y, H:i';
|
||||
|
||||
|
||||
// Internals
|
||||
var $error = false;
|
||||
var $this_dir;
|
||||
var $parent;
|
||||
var $list = array();
|
||||
var $sort_by = array();
|
||||
|
||||
@@ -37,7 +39,8 @@ class dirList {
|
||||
var $stats_folders = 0;
|
||||
var $stats_totalsize = 0;
|
||||
|
||||
// Construtor
|
||||
// Construtor - does nothing, but is here just
|
||||
// incase it might do something in the future...
|
||||
function dirlist() {
|
||||
|
||||
}
|
||||
@@ -50,7 +53,7 @@ class dirList {
|
||||
if(!preg_match("/\/$/", $dir)) $dir .= '/';
|
||||
$this->sort_by = explode(',', $this->default_sort);
|
||||
if($dh = @opendir($dir)) {
|
||||
$this->this_dir = $this->getDetails($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 ) {
|
||||
@@ -64,12 +67,17 @@ class dirList {
|
||||
$this->stats_folders++;
|
||||
}
|
||||
// sorting
|
||||
$list_key = ( $this->folders_first ) ? $item_details['type'].'|' : '' ;
|
||||
foreach( $this->sort_by as $v ) {
|
||||
if ( $v == 'size' ) $v = 'size_raw';
|
||||
$list_key .= ( $v == 'size_raw' || $v == 'mtime' ) ? str_pad($item_details[$v], 28, '0', STR_PAD_LEFT).'|' : $item_details[$v].'|' ;
|
||||
if ( $this->sort_items ) {
|
||||
$list_key = ( $this->folders_first ) ? $item_details['type'].'|' : '' ;
|
||||
foreach( $this->sort_by as $v ) {
|
||||
if ( $v == 'size' ) $v = 'size_raw';
|
||||
if ( $v == 'mtime' ) $v = 'mtime_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;
|
||||
} else {
|
||||
$this->list[] = $item_details;
|
||||
}
|
||||
$this->list[$list_key] = $this->getDetails($dir.$item);
|
||||
}
|
||||
}
|
||||
if ( $this->sort_items ) {
|
||||
@@ -80,43 +88,64 @@ class dirList {
|
||||
closedir($dh);
|
||||
}
|
||||
|
||||
function getDetails ($item) {
|
||||
$item = str_replace("\\", '/', $item);
|
||||
$return['name'] = ( preg_match("/^.*\/(.*)/", $item, $name) ) ? $name[1] : $item ;
|
||||
|
||||
// Owner and Group
|
||||
if ( ($group = $this->getGroup($item)) != false ) $return = array_merge($return, $group);
|
||||
if ( ($owner = $this->getOwner($item)) != false ) $return = array_merge($return, $owner);
|
||||
|
||||
// Last Modified
|
||||
$return['mtime'] = filemtime($item);
|
||||
$return['mtimef'] = $this->smartDate($return['mtime'], $this->smartdate_date, $this->smartdate_time, $this->smartdate);
|
||||
|
||||
// Permissions and CHMOD value
|
||||
$return['perms'] = $this->format_perms(fileperms($item));
|
||||
$return['chmod'] = substr(sprintf('%o', fileperms($item)), -4);
|
||||
|
||||
$return['type_raw'] = filetype($item);
|
||||
|
||||
if ( is_file($item) ) {
|
||||
$return['type'] = 'file';
|
||||
$return['ext'] = ( preg_match("/^.*\.(.*)/", $return['name'], $ext) ) ? $ext[1] : '' ;
|
||||
$return['size_raw'] = filesize($item);
|
||||
$return['size'] = $this->format_filesize($return['size_raw']);
|
||||
} elseif ( is_dir($item) ) {
|
||||
$return['type'] = 'dir';
|
||||
$return['ext'] = '';
|
||||
$return['size_raw'] = '';
|
||||
$return['size'] = '-';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
// ==============================================
|
||||
// ----- [ Internal Functions ] -----------------
|
||||
// ==============================================
|
||||
|
||||
function getDetails ($item) {
|
||||
$item = str_replace("\\", '/', $item);
|
||||
$return['name'] = basename($item);
|
||||
|
||||
// Owner and Group
|
||||
if ( ($group = $this->getGroup($item)) != false ) $return = array_merge($return, $group);
|
||||
if ( ($owner = $this->getOwner($item)) != false ) $return = array_merge($return, $owner);
|
||||
|
||||
// Last Modified
|
||||
$return['mtime_raw'] = filemtime($item);
|
||||
if ( $this->use_smartdate ) {
|
||||
$return['mtime'] = $this->smartDate($return['mtime_raw'], $this->smartdate_date, $this->smartdate_time, $this->smartdate);
|
||||
} else {
|
||||
$return['mtime'] = date($this->standard_date_format, $return['mtime_raw']);
|
||||
}
|
||||
|
||||
// Permissions and CHMOD value
|
||||
$return['perms'] = $this->format_perms(fileperms($item));
|
||||
$return['chmod'] = substr(sprintf('%o', fileperms($item)), -4);
|
||||
|
||||
$return['type_raw'] = filetype($item);
|
||||
|
||||
$return['ext'] = ( preg_match("/^.*\.(.*)/", $return['name'], $ext) ) ? $ext[1] : '' ;
|
||||
|
||||
if ( is_file($item) ) {
|
||||
$return['type'] = 'file';
|
||||
$return['size_raw'] = filesize($item);
|
||||
$return['size'] = $this->format_filesize($return['size_raw']);
|
||||
} elseif ( is_dir($item) ) {
|
||||
$return['type'] = 'dir';
|
||||
$return['size_raw'] = '';
|
||||
$return['size'] = '-';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function getOwner ($item) {
|
||||
if ( function_exists('posix_getpwuid') ) {
|
||||
$id = fileowner($item);
|
||||
$name = posix_getpwuid($id);
|
||||
return array('ownerid'=>$id, 'owner'=>$name['name']);
|
||||
} else { return false; }
|
||||
}
|
||||
|
||||
function getGroup ($item) {
|
||||
if ( function_exists('posix_getgrgid') ) {
|
||||
$id = filegroup($item);
|
||||
$name = posix_getgrgid($id);
|
||||
return array('groupid'=>$id, 'group'=>$name['name']);
|
||||
} else { return false; }
|
||||
}
|
||||
|
||||
function format_filesize($bytes) {
|
||||
$types = array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
||||
for($n = 0; $bytes >= 1024; $n++) $bytes = $bytes / 1024;
|
||||
@@ -171,22 +200,6 @@ class dirList {
|
||||
return $info;
|
||||
}
|
||||
|
||||
function getOwner ($item) {
|
||||
if ( function_exists('posix_getpwuid') ) {
|
||||
$id = fileowner($item);
|
||||
$name = posix_getpwuid($id);
|
||||
return array('ownerid'=>$id, 'owner'=>$name['name']);
|
||||
} else { return false; }
|
||||
}
|
||||
|
||||
function getGroup ($item) {
|
||||
if ( function_exists('posix_getgrgid') ) {
|
||||
$id = filegroup($item);
|
||||
$name = posix_getgrgid($id);
|
||||
return array('groupid'=>$id, 'group'=>$name['name']);
|
||||
} else { return false; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -4,7 +4,7 @@ class execHandler {
|
||||
|
||||
/*
|
||||
|
||||
Class: execHandler v0.7 beta
|
||||
Class: execHandler v0.7.3 beta
|
||||
|
||||
Copyright © 2006 Jim Myhrberg. All rights reserved.
|
||||
zynode@gmail.com
|
||||
@@ -88,6 +88,7 @@ class execHandler {
|
||||
var $compiled_code = false;
|
||||
var $include_file = false;
|
||||
var $stages = array();
|
||||
var $parsing_order = array();
|
||||
|
||||
|
||||
// Construct Function
|
||||
@@ -109,7 +110,7 @@ class execHandler {
|
||||
|
||||
function cache ($force=false) {
|
||||
if ( $force || $this->debug || !$this->check_cache() ) {
|
||||
echo "reloading\n";
|
||||
if ( $this->debug ) echo "reloading\n";
|
||||
$this->loadFile($this->files_to_load);
|
||||
$this->compile();
|
||||
$this->save_cache();
|
||||
@@ -129,14 +130,16 @@ class execHandler {
|
||||
}
|
||||
|
||||
function loadFile ($input) {
|
||||
$return = true;
|
||||
if ( is_array($input) ) {
|
||||
foreach( $input as $file ) {
|
||||
$result = $this->load_file($file);
|
||||
if ( $result == false ) return false;
|
||||
if ( $result == false ) $return = false;
|
||||
}
|
||||
} elseif ( is_string($input) ) {
|
||||
return $this->load_file($input);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function compile () {
|
||||
@@ -153,8 +156,7 @@ class execHandler {
|
||||
$pr = explode('|', $key, 2);
|
||||
$pr = $pr[0];
|
||||
$this->compiled_code
|
||||
.= ( $new_stage ) ? "\n// Code Piece: ".$code.":".$pr."\n" : "\n\n// Code Piece: ".$code.":".$pr."\n" ;
|
||||
//$this->compiled_code .= "\n// Code Piece: ".$code."\n";
|
||||
.= ( $new_stage ) ? "\n// Section: ".$code.":".$pr."\n" : "\n\n// Section: ".$code.":".$pr."\n" ;
|
||||
$this->compiled_code .= $this->clean_up_code($this->code[$stage][$code]);
|
||||
$new_stage = false;
|
||||
} else {
|
||||
@@ -184,9 +186,9 @@ class execHandler {
|
||||
$content['file'] = $file;
|
||||
if ( $included ) $content['included'] = true;
|
||||
$this->files[$file] = $content;
|
||||
return true;
|
||||
}else return false;
|
||||
}
|
||||
} else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function sort_stage_list () {
|
||||
@@ -199,6 +201,10 @@ class execHandler {
|
||||
}
|
||||
|
||||
function parse ($string, $file) {
|
||||
|
||||
// parse order statistics
|
||||
$this->parsing_order[] = $file;
|
||||
|
||||
// Filter Out Main Content
|
||||
$file_start = $this->addslashes($this->file_start);
|
||||
$code_delim = $this->addslashes($this->code_delim);
|
||||
@@ -215,6 +221,7 @@ class execHandler {
|
||||
// Stage Loop
|
||||
$n = '001';
|
||||
foreach ( $code as $value ) {
|
||||
$sort_name = str_pad($settings['name'], 24, '_', STR_PAD_RIGHT);
|
||||
preg_match("/^(.*?)$(?s)(.*)/im", $value, $stage_code);
|
||||
if ( preg_match("/(.*)".$this->priority_delim."([0-9]{1,2})/i", trim($stage_code[1]), $stage) ) {
|
||||
$stage_priority = $stage[2];
|
||||
@@ -231,14 +238,15 @@ class execHandler {
|
||||
$stage_code[0] = $this->clean_up_code($stage_code[0]);
|
||||
if ( !empty($stage_code[0]) ) {
|
||||
$this->code[$stage][$settings['name'].'.'.$this->default_stage_code] = "\n".$stage_code[0];
|
||||
$this->execution_order[$stage][$this->default_priority.'|'.$settings['name'].':'.$n.':'.$this->default_stage_code.'__main']
|
||||
$this->execution_order[$stage][$this->default_priority.'|'.$sort_name.':'.$n.':'.$this->default_stage_code.'__main']
|
||||
= $settings['name'].'.'.$this->default_stage_code;
|
||||
$this->order_id[$stage][$settings['name'].'.'.$this->default_stage_code]
|
||||
= $this->default_priority.'|'.$settings['name'].':'.$n.':'.'.'.$this->default_stage_code.'__main';
|
||||
= $this->default_priority.'|'.$sort_name.':'.$n.':'.'.'.$this->default_stage_code.'__main';
|
||||
$n = str_pad($n+1, 3, '0', STR_PAD_LEFT);
|
||||
}
|
||||
array_shift($stage_code);
|
||||
|
||||
|
||||
// Section Loop
|
||||
foreach( $stage_code as $value ) {
|
||||
preg_match("/^(.*?)$(?s)(.*)/im", $value, $section_code);
|
||||
@@ -259,6 +267,8 @@ class execHandler {
|
||||
}
|
||||
|
||||
$section_code = $this->clean_up_code($section_code[2]);
|
||||
$priority = str_pad($priority, 2, '0', STR_PAD_LEFT);
|
||||
$section_sort_name = str_pad($section, 24, '_', STR_PAD_RIGHT);
|
||||
|
||||
if ( !empty($section_code) ) {
|
||||
|
||||
@@ -270,15 +280,15 @@ class execHandler {
|
||||
elseif ( $handler == $this->insert_before || $handler == $this->insert_after ) {
|
||||
$placement = ( $handler == $this->insert_before ) ? '___before' : '_zafter' ;
|
||||
$this->code[$stage][$settings['name'].'.'.$section] = "\n".$section_code;
|
||||
$this->execution_order[$stage][$this->order_id[$stage][$section].$placement.'|'.$priority.'|'.$settings['name'].':'.$n]
|
||||
$this->execution_order[$stage][$this->order_id[$stage][$section].$placement.'|'.$priority.'|'.$sort_name.':'.$n]
|
||||
= $settings['name'].'.'.$section;
|
||||
}
|
||||
// section
|
||||
elseif ( $handler == $this->section_delim || $handler == '' ) {
|
||||
$this->code[$stage][$settings['name'].'.'.$section] = "\n".$section_code;
|
||||
$this->execution_order[$stage][$priority.'|'.$settings['name'].':'.$n.':'.$section.'__main']
|
||||
$this->execution_order[$stage][$priority.'|'.$sort_name.':'.$n.':'.$section_sort_name.'__main']
|
||||
= $settings['name'].'.'.$section;
|
||||
$this->order_id[$stage][$settings['name'].'.'.$section] = $priority.'|'.$settings['name'].':'.$n.':'.$section;
|
||||
$this->order_id[$stage][$settings['name'].'.'.$section] = $priority.'|'.$sort_name.':'.$n.':'.$section_sort_name;
|
||||
}
|
||||
}
|
||||
$n = str_pad($n+1, 3, '0', STR_PAD_LEFT);
|
||||
@@ -329,6 +339,9 @@ class execHandler {
|
||||
function save_cache ($force_compile=false) {
|
||||
if(!preg_match("/\/$/", $this->cache_dir)) $this->cache_dir .= '/';
|
||||
if ( is_writeable($this->cache_dir) ) {
|
||||
if ( !file_exists($this->cache_dir.'.htaccess') ) {
|
||||
$this->write2file($this->cache_dir.'.htaccess', 'Deny from all');
|
||||
}
|
||||
$cache_details = '';
|
||||
foreach( $this->files as $key => $value ) {
|
||||
$cache_details .= $value['file'].'='.$value['md5'];
|
||||
@@ -411,6 +424,7 @@ class execHandler {
|
||||
function include_files ($input, $dirname='.') {
|
||||
$include_files = explode($this->include_seperator, $input);
|
||||
foreach( $include_files as $key => $value ) {
|
||||
$value = trim($value);
|
||||
if ( $dirname == '.' && is_readable($value) ) {
|
||||
$this->load_file($value, true);
|
||||
} elseif ( is_readable($dirname.'/'.$value) ) {
|
||||
@@ -425,7 +439,7 @@ class execHandler {
|
||||
function clean_up_code ($string, $comments=true, $emptylines=true, $indents=false) {
|
||||
if ( $comments ) $string = $this->remove_comments($string);
|
||||
if ( $emptylines ) $string = $this->remove_empty_lines($string);
|
||||
if ( $indents ) $string = $this->remove_indents($string);
|
||||
if ( $indents && $this->debug != true) $string = $this->remove_indents($string);
|
||||
return trim($string);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user