From 1b47d3e97f4d64ce1ee026def3437d6ac0e9aa46 Mon Sep 17 00:00:00 2001 From: avl Date: Fri, 17 Jul 2009 17:53:41 +0300 Subject: [PATCH] new file manager --- ipf/admin/app.php | 3 +- .../templates/admin/base_filebrowser.html | 20 +++ ipf/admin/templates/admin/filebrowser.html | 126 ++++++++++++++++++ ipf/admin/views.php | 81 +++++++++++ ipf/form/widget/htmlinput.php | 28 ++-- ipf/utils.php | 2 +- 6 files changed, 247 insertions(+), 13 deletions(-) create mode 100644 ipf/admin/templates/admin/base_filebrowser.html create mode 100644 ipf/admin/templates/admin/filebrowser.html diff --git a/ipf/admin/app.php b/ipf/admin/app.php index 7b8da86..221ae33 100644 --- a/ipf/admin/app.php +++ b/ipf/admin/app.php @@ -8,7 +8,8 @@ class IPF_Admin_App extends IPF_Application{ } public static function urls(){ return array( - array('regex'=>'$#', 'func'=>'IPF_Admin_Views_Index'), + array('regex'=>'filebrowser(.+)#', 'func'=>'IPF_Admin_Views_FileBrowser'), + array('regex'=>'$#', 'func'=>'IPF_Admin_Views_Index'), array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/$#i', 'func'=>'IPF_Admin_Views_ListItems'), array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/reorder/$#i', 'func'=>'IPF_Admin_Views_Reorder'), array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/add/$#i', 'func'=>'IPF_Admin_Views_AddItem'), diff --git a/ipf/admin/templates/admin/base_filebrowser.html b/ipf/admin/templates/admin/base_filebrowser.html new file mode 100644 index 0000000..8381ba8 --- /dev/null +++ b/ipf/admin/templates/admin/base_filebrowser.html @@ -0,0 +1,20 @@ + + + + + {block css} + + {/block} + + {$page_title} - IPF Administration + + + + +{block breadcrumb}{/block} + + + +
{block sidebar}{/block}{block content}{/block}
+ + diff --git a/ipf/admin/templates/admin/filebrowser.html b/ipf/admin/templates/admin/filebrowser.html new file mode 100644 index 0000000..f240a69 --- /dev/null +++ b/ipf/admin/templates/admin/filebrowser.html @@ -0,0 +1,126 @@ +{extends "admin/base_filebrowser.html"} + +{block breadcrumb} + + + + + + + + +{/block} + +{block sidebar} +
+

Add Folder

+ +
+ +
+
+ +
+

Upload File

+ +
+ +
+
+ +

View File

+ +
+
+
+
+ +
+ +{/block} + +{block content} + +
+ + + + + + + + + + +{foreach $dirs as $dir} + + + + + +{/foreach} +{foreach $files as $file} + + + + + + +{/foreach} + +
FilenameTypeSizedelete
{$dir['name']}SUB-DIR{if $dir['name']!='..'}delete{/if}
{$file['name']}{$file['type']}{$file['size']}delete
+ +
+{/block} + diff --git a/ipf/admin/views.php b/ipf/admin/views.php index db7f5ff..2ce7974 100644 --- a/ipf/admin/views.php +++ b/ipf/admin/views.php @@ -258,3 +258,84 @@ function IPF_Admin_Views_Logout($request, $match){ ); return IPF_Shortcuts::RenderToResponse('admin/logout.html', $context, $request); } + +function IPF_Admin_Views_FileBrowser($request, $match){ + $ca = IPF_Admin_App::checkAdminAuth($request); + if ($ca!==true) return $ca; + + $curr_dir = urldecode(substr($match[1],1)); + $dir = IPF::get('upload_path').$curr_dir; + + if ($request->method=="GET"){ + if (@$request->GET['delete']){ + $del = $dir.$request->GET['delete']; + @IPF_Utils::removeDirectories($del); + } + } + + + if ($request->method=="POST"){ + if (@$request->POST['new_folder']!='') + @mkdir($dir.$request->POST['new_folder']); + + if (@$_FILES['file']){ + $uploadfile = $dir . basename($_FILES['file']['name']); + @move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile); + } + } + + $dirs = array(); + $files = array(); + if ($dh = @opendir($dir)) { + while (($file = readdir($dh)) !== false) { + if ($file=='.') + continue; + if (($curr_dir=='') && ($file=='..')) + continue; + if (filetype($dir . $file)=='dir') + $dirs[] = array('name'=>$file); + else{ + + $sx = getimagesize($dir.$file); + if ($sx){ + $image = '1'; + $type = str_replace('image/','',$sx['mime']).' '.$sx[0].'x'.$sx[1]; + if ($sx[0]<=200){ + $zw = $sx[0]; + $zh = $sx[1]; + } + else { + $zw = 200; + $prop = (float)$sx[1] / (float)$sx[0]; + $zh = (int)(200.0 * $prop); + } + } + else { + $image = '0'; + $type = 'binary'; + $zw = 200; + $zw = 150; + } + $files[] = array('name'=>$file, 'image'=>$image, 'type'=>$type, 'zw'=>$zw, 'zh'=>$zh, 'size'=>filesize($dir . $file)); + } + } + closedir($dh); + } + + $pth = split(DIRECTORY_SEPARATOR,$curr_dir); + $path = array(); + $cd = '/admin/filebrowser/'; + foreach($pth as $p){ + $cd.=$p.DIRECTORY_SEPARATOR; + $path[] = array('cd'=>$cd, 'name'=>$p); + } + + $context = array( + 'page_title' => __('File Browser'), + 'dirs' => $dirs, + 'files' => $files, + 'path' => $path, + 'curr_dir' => $curr_dir, + ); + return IPF_Shortcuts::RenderToResponse('admin/filebrowser.html', $context, $request); +} diff --git a/ipf/form/widget/htmlinput.php b/ipf/form/widget/htmlinput.php index 12da8a7..bda46c4 100644 --- a/ipf/form/widget/htmlinput.php +++ b/ipf/form/widget/htmlinput.php @@ -51,16 +51,22 @@ class IPF_Form_Widget_HTMLInput extends IPF_Form_Widget IPF_Form_Widget_HTMLInput::$js_include = true; $out .= ''."\n"; $out .=''; } diff --git a/ipf/utils.php b/ipf/utils.php index 0a25f10..f114f19 100644 --- a/ipf/utils.php +++ b/ipf/utils.php @@ -161,7 +161,7 @@ class IPF_Utils { } return rmdir($folderPath); } else { - return false; + unlink($folderPath); } } -- 2.49.0