true,
"icofolder" => "ico/",
"JS" =>true);
var $icons = array(
"png" => "picture.png",
"jpg" => "picture.png",
"jpeg" => "picture.png",
"gif" => "gif.png",
"bmp" => "bmp.png",
"zip" => "zip.png",
"rar" => "rar.png",
"7z" => "rar.png",
"gz" => "rar.png",
"bz" => "rar.png",
"ace" => "rar.png",
"uha" => "rar.png",
"bat" => "cmd.png",
"com" => "cmd.png",
"exe" => "exe.png",
"setup" => "setup.png",
"msi" => "setup.png",
"iso" => "cd.png",
"bin" => "cd.png",
"txt" => "text.png",
"js" => "js.png",
"htm" => "html.png",
"html" => "html.png",
"shtml" => "html.png",
"php" => "php.png",
"xml" => "js.png",
"css" => "js.png",
"ico" => "picture.png",
"ebc" => "easy-joomla-favicon.ico",
"ini" => "sig.png",
"sql" => "html.png",
"tpl" => "tpl.png",
"cfg" => "cfg.png",
"fla" => "fla.png",
"swf" => "swf.png",
"pps" => "pps.png",
"xls" => "excel.png",
"doc" => "doc.png",
"sig" => "sig.png",
"asc" => "sig.png",
"fh10" => "fh10.png",
"pdf" => "pdf.png",
"psd" => "psd.png",
"rm" => "real.png",
"ram" => "real.png",
"mpg" => "video.png",
"mpeg" => "video.png",
"mov" => "video.png",
"avi" => "video.png",
"wmv" => "video.png",
"eps" => "eps.gif",
"pls" => "m3u.png",
"m3u" => "m3u.png",
"mp3" => "music.png",
"wma" => "music.png");
//-->> save setting
function set($setting, $value){
if(!empty($setting)){
$this->settings[$setting] = $value;
return true;
}else{
return false;
}
}
function addExclude($type, $name)
{
jimport('joomla.filesystem.file');
switch( $type )
{
case 'directory':
$this->exclude_dirs[] = $name;
break;
case 'file':
$this->exclude_files[] = $name;
break;
}
}//function
//-->> JavaScript (perform function in
)
function javascript()
{
$js = '';
$vars = array('ebc_project', 'task', 'controller', 'view');
$vs = array();
foreach ($vars as $var)
{
$vs[] = $var.'='.JRequest::getVar($var, '', 'post');
}//foreach
$postVars = implode('&', $vs);
$js .= "";
return $js;
}//function
//-->> read the directory
function read($folder){
/**
* Define the OS directory separator
*/
if( ! defined('DS') ) define('DS', DIRECTORY_SEPARATOR);
$tree = array();
$tmpdirs = array();
$tmpfiles = array();
if(is_dir($folder)){
$handle = opendir($folder);
while($file = readdir($handle))
{
if($this->allowed_dir($folder.DS.$file))
{
$tmpdirs[] = $file;
}
elseif($this->allowed_file($folder.DS.$file))
{
$tmpfiles[] = $file;
}
}//while
sort($tmpdirs);
sort($tmpfiles);
foreach($tmpdirs as $tmpdir)
{
$tree[$tmpdir] = $this->read($folder.DS.$tmpdir);
}
$tree = array_merge($tree, $tmpfiles);
return array( '>PATH' =>$folder,
'>TREE' =>$tree);
} else
{
echo ''.JText::_('Invalid path').'
';
return false;
}
}
//-->> build the html-tree
function build($structure, $path = '', $offset = 0, $depth = 0, $allOpened = false, $excludeFiles = array())
{
$offset = ($offset > 0) ? 16 : 0;
if(array_key_exists('>PATH', $structure))
{
$path = $structure['>PATH'];
}
if($path != "")
$path = $path.DS;
if(array_key_exists('>TREE', $structure))
{
$tree = $structure['>TREE'];
}
if(is_array($tree)){
$result = "\n";
$result .= str_repeat("\t", $depth);
$result .= "\n";
$i = 1;
foreach($tree as $key =>$value)
{
if($i < count($tree))
{
$spacer = 'nl.gif';
$background = " background: url(".$this->settings['icofolder']."/d.gif); background-repeat: repeat-y;";
}else
{
$spacer = 'l.gif';
$background = '';
}
$i++;
if(is_array($value))
{
if($this->settings['JS'])
{
$rand = rand(10000000, 99999999);
$js = " style=\"cursor: pointer;\" onclick=\"openclose('".$rand."');\"";
$ico = " id=\"".$rand."_ico\"";
$display =( $allOpened ) ? 'block' : 'none';
$div = " style=\"display: ".$display.";\" id=\"".$rand."\"";
}else
{
$rand = $js = $ico = $div = '';
}
$result .= str_repeat("\t", $depth);
$result .= "\n";
$result .= str_repeat("\t", $depth);
$result .= "\n";
$result .= str_repeat("\t", $depth+1);
$result .= "
\n";
$result .= str_repeat("\t", $depth+2);
$result .= "

settings['icofolder']."/".$spacer."\" align=\"absmiddle\" alt=\"\" width=\"20\" />";
$result .= "
";
$result .= "
settings['icofolder']."/folder_closed.png\" align=\"absmiddle\" border=\"0\"".$ico." />";
$result .= "".htmlentities($key, ENT_QUOTES)."";
$result .= "\n";
$result .= str_repeat("\t", $depth+1);
$result .= "
\n";
$result .= str_repeat("\t", $depth+1);
$result .= "
";
$result .= $this->build($value, $path.$key, 1, $depth+2, $allOpened);
$result .= str_repeat("\t", $depth+1);
$result .= "
\n";
$result .= str_repeat("\t", $depth);
$result .= "
\n";
$result .= str_repeat("\t", $depth);
$result .= "\n";
}else
{
$result .= str_repeat("\t", $depth);
$result .= "\n";
$result .= str_repeat("\t", $depth);
$result .= "\n";
$result .= str_repeat("\t", $depth+1);
$result .= "

settings['icofolder']."/".$spacer."\" align=\"top\" alt=\"\" width=\"20\" />\n";
$result .= $this->displayLink( $path, $value );
$result .= str_repeat("\t", $depth);
$result .= "
\n";
$result .= str_repeat("\t", $depth);
$result .= "\n";
}
}
$result .= str_repeat("\t", $depth);
$result .= "\n";
return $result;
}
}
function displayLink( $path, $value )
{
if($this->settings['ico'])
{
$extension = $this->get_extension($value);
if(array_key_exists($extension, $this->icons))
{
$icon = "
settings['icofolder'].'/'.$this->icons[$extension]."\" alt=\"".$extension."\" border=\"0\" />";
}else
{
$icon = "
settings['icofolder']."/unknown.png\" alt=\"".$extension."\" border=\"0\" />";
}
}
else
{
$icon = "";
}
$pathtodir = substr( $path, strlen(JPATH_ROOT) + 1);
$the_path = JRequest::getVar('file_path', '');
$the_file = JRequest::getVar('file_name', NULL);
$style = '';
$selected = '';
if( $the_path
&& $the_path == $pathtodir
&& $value == $the_file )
{
$style = 'style="color: red; font-weight: bold;"';
$selected = ' selected';
}
$task = JRequest::getCmd('task');
// $js = "ecr_load_X('".addslashes($pathtodir)."', '$value');";
// $s_link = ''.$icon.' '.$value.'
'.NL;
// $s_link = ''.$icon.' '.$value.'
';
// $s_link = ''.$icon.' '.$value.'
';
$s_link = ''.$icon.' '.$value.'
';
return $s_link;
}// function
//-->> read the directory and cache it in an array for further use
function cache_array($path = "", $key = ""){
if($path == "." || $path == ".."){
$path .= DS;
}
if($this->allowed_dir($path)){
if(!empty($key)){
$this->cached_array[$key] = $this->read($path);
}else{
$this->cached_array[$path] = $this->read($path);
}
}else{
return false;
}
}
//-->> read the directory, build the html-tree and cache it in an array for further use
function cache_output($path = '', $key = ''){
if($path == '.' || $path == '..'){
$path .= DS;
}
if($this->allowed_dir($path)){
if(!empty($key))
$this->cached_output[$key] = $this->build($this->read($path));
else
$this->cached_output[$path] = $this->build($this->read($path));
}else{
return false;
}
}
function allowed_dir($path = ''){
$dir = $this->get_dir($path);
if(@is_dir($path) && $dir != "." && $dir != ".." && $dir != '.svn' && ! $this->in_array_regex($path, $this->exclude_dirs))
return true;
else
return false;
}
function allowed_file($path = ''){
if(@is_file($path) && ! $this->in_array_regex($path, $this->exclude_files))
return true;
else
return false;
}
function get_dir($path){
$array = explode(DS, $path);
$retval = strtolower(array_pop($array));
return $retval;
}
function get_extension($file){
$array = explode(".", $file);
$retval = strtolower(array_pop($array));
return $retval;
}
function in_array_regex($string, $array){
reset($array);
foreach($array as $value){
if((strpos($value, '*') === 0) || (strpos($value, '?') === 0))
$value = ".".$value;
if(preg_match("/".$value."/i", $string))
return true;
}
return false;
}
}//class