From: Andrey Kutejko Date: Fri, 2 Jan 2015 17:31:37 +0000 (+0200) Subject: move admin views to controllers. rework file browser and routes. X-Git-Tag: 0.6~106 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=6e8bd5229ed3308f0289db3befadb3ed898efca5;p=ipf.git move admin views to controllers. rework file browser and routes. --- diff --git a/ipf/admin/app.php b/ipf/admin/app.php index 815555e..8d14c98 100644 --- a/ipf/admin/app.php +++ b/ipf/admin/app.php @@ -5,21 +5,31 @@ use \PFF\Placeholder as P; class IPF_Admin_App extends IPF_Application { - public static function urls() + public static function urls($prefix='admin') { - return array( - array('regex'=>'fb_rename/$#', 'func'=>'IPF_Admin_Views_FileBrowserRename'), - 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'), - array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/$#i', 'func'=>'IPF_Admin_Views_EditItem'), - array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/delete/$#i', 'func'=>'IPF_Admin_Views_DeleteItem'), - array('regex'=>'login/$#i', 'func'=>'IPF_Admin_Views_Login'), - array('regex'=>'logout/$#i', 'func'=>'IPF_Admin_Views_Logout'), - array('regex'=>'auth/user/(\d+)/impersonate/$#', 'func'=>'IPF_Admin_Views_Impersonate'), - ); + return array('prefix' => '#^/'.$prefix.'/', 'urls' => array( + array('controller' => 'IPF_Admin_FileBrowser_Controller', 'urls' => array( + array('regex' => 'filebrowser/rename/$#', 'method' => 'POST', 'func' => 'rename'), + array('regex' => 'filebrowser/move/$#', 'method' => 'POST', 'func' => 'move'), + array('regex' => 'filebrowser/mkdir/$#', 'method' => 'POST', 'func' => 'mkdir'), + array('regex' => 'filebrowser/delete/$#', 'method' => 'POST', 'func' => 'delete'), + array('regex' => 'filebrowser/upload/$#', 'method' => 'POST', 'func' => 'upload'), + array('regex' => 'filebrowser/$#'), + )), + array('controller' => 'IPF_Admin_Controller', 'urls' => array( + array('regex' => '$#', 'func' => 'index'), + array('regex' => '([\w\_\-]+)/([\w\_\-]+)/$#i', 'func' => 'listItems'), + array('regex' => '([\w\_\-]+)/([\w\_\-]+)/reorder/$#i', 'func' => 'reorder'), + array('regex' => '([\w\_\-]+)/([\w\_\-]+)/add/$#i', 'func' => 'addItem'), + array('regex' => '([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/$#i', 'func' => 'editItem'), + array('regex' => '([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/delete/$#i', 'func' => 'deleteItem'), + )), + array('controller' => 'IPF_Admin_User_Controller', 'urls' => array( + array('regex' => 'login/$#i', 'func' => 'login'), + array('regex' => 'logout/$#i', 'func' => 'logout'), + array('regex' => 'auth/user/(\d+)/impersonate/$#', 'func' => 'impersonate'), + )), + )); } public function appList($request) @@ -167,7 +177,7 @@ class IPF_Admin_LoginRequired extends IPF_Router_Shortcut { public function response($request) { - return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL::urlForView('IPF_Admin_Views_Login')); + return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL::urlForView(array('IPF_Admin_User_Controller', 'login'))); } } diff --git a/ipf/admin/assets/css/base.css b/ipf/admin/assets/css/base.css index 54d6851..e9bbad6 100644 --- a/ipf/admin/assets/css/base.css +++ b/ipf/admin/assets/css/base.css @@ -1,10 +1,14 @@ body { margin:0; padding:0; font-size:12px; font-family:"Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif; color:#333; background:#fff; } /* LINKS */ -a:link, a:visited { color:#006A95; text-decoration:none; } +a:link, a:visited { color:#006A95; text-decoration:none } a:hover { color: #036; } a img { border:none; } +input[type=submit].link-like { color:#006A95; text-decoration:none; cursor: pointer; display:inline-block;margin:0;padding:0;background:none;border:none;min-width:auto } +input[type=submit].link-like:active { color: #036; background:none;border:none; } +input[type=submit].link-like:hover { color: #036; } + /* GLOBAL DEFAULTS */ p, ol, ul, dl { margin:.2em 0 .8em 0; } p { padding:0; line-height:140%; } diff --git a/ipf/admin/component.php b/ipf/admin/component.php index 2ada07f..e9f8d58 100644 --- a/ipf/admin/component.php +++ b/ipf/admin/component.php @@ -153,7 +153,7 @@ abstract class IPF_Admin_Component $url = @$request->POST['ipf_referrer']; if (!$url) - $url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_ListItems', array($this->app->slug(), $this->slug())); + $url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'listItems'), array($this->app->slug(), $this->slug())); return new IPF_HTTP_Response_Redirect($url); } $errors = true; @@ -191,7 +191,7 @@ abstract class IPF_Admin_Component $url = @$request->POST['ipf_referrer']; if (!$url) - $url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_ListItems', array($this->app->slug(), $this->slug())); + $url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'listItems'), array($this->app->slug(), $this->slug())); return new IPF_HTTP_Response_Redirect($url); } @@ -223,7 +223,7 @@ abstract class IPF_Admin_Component $url = @$request->POST['ipf_referrer']; if (!$url) - $url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_ListItems', array($this->app->slug(), $this->slug())); + $url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'listItems'), array($this->app->slug(), $this->slug())); return new IPF_HTTP_Response_Redirect($url); } diff --git a/ipf/admin/controllers/components.php b/ipf/admin/controllers/components.php new file mode 100644 index 0000000..ff705a9 --- /dev/null +++ b/ipf/admin/controllers/components.php @@ -0,0 +1,61 @@ +ensureUserIsStaff($this->request); + + $admin_log = \PFF\Container::databaseQuery() + ->from('admin_log') + ->orderBy('created_at DESC') + ->limit(10) + ->asObject(true) + ->fetchAll(); + + $context = array( + 'page_title' => __('Site Administration'), + 'admin_log' => $admin_log, + ); + return IPF_Admin_App::RenderToResponse('admin/index.html', $context, $this->request); + } + + function listItems() + { + return $this->getComponent(array('view'))->ListItems($this->request); + } + + function addItem() + { + return $this->getComponent(array('view', 'add'))->AddItem($this->request); + } + + function editItem() + { + return $this->getComponent(array('view', 'change'))->EditItem($this->request, $this->params[3]); + } + + function deleteItem() + { + return $this->getComponent(array('view', 'delete'))->DeleteItem($this->request, $this->params[3]); + } + + function reorder() + { + $component = $this->getComponent(array('view', 'change')); + + if ($this->request->method != 'POST' || !isset($this->request->POST['ids']) || !is_array($this->request->POST['ids'])) + return new IPF_HTTP_Response_NotFound($request); + + if ($component->reorder($this->request->POST['ids'])) + return new IPF_HTTP_Response_Json("Ok"); + else + return new IPF_HTTP_Response_Json('Cannot find model'); + } + + protected function getComponent($requiredPermissions) + { + return \PFF\Container::admin()->getComponent($this->request, $requiredPermissions); + } +} + diff --git a/ipf/admin/controllers/file_browser.php b/ipf/admin/controllers/file_browser.php new file mode 100644 index 0000000..fa665b2 --- /dev/null +++ b/ipf/admin/controllers/file_browser.php @@ -0,0 +1,190 @@ +'', 'name'=>'Root Folder'); + $dd = array(); + if ($dh = @opendir($dir)) { + while (($file = readdir($dh)) !== false) { + if (($file=='.') || ($file=='..')) continue; + if (filetype($dir . $file)=='dir') + $dd[] = $file; + } + closedir($dh); + sort($dd); + foreach($dd as $file){ + $dirtree[] = array('path'=>$path.$file, 'name'=>$level.$file); + $dirtree = array_merge($dirtree, $this->dir_recursive($dir.$file.DIRECTORY_SEPARATOR, $path.$file.DIRECTORY_SEPARATOR, $level.'--')); + } + } + return $dirtree; + } + + protected function setRoot() + { + $this->root = realpath(IPF::getUploadPath()) . DIRECTORY_SEPARATOR; + } + + protected function validatePath($path) + { + $path = realpath($path) . DIRECTORY_SEPARATOR; + if (!\PFF\Str::startsWith($path, $this->root)) + throw new IPF_Admin_AccessDenied; + return $path; + } + + protected function setCurrentDir() + { + $this->setRoot(); + $this->dir = $this->validatePath(IPF::getUploadPath() . DIRECTORY_SEPARATOR . \PFF\Arr::get($this->request->REQUEST, 'dir', '')); + $this->relative = substr($this->dir, strlen($this->root)); + } + + protected function validateName($name) + { + $name = basename($name); + if (!$name || $name === '.' || $name === '..') + throw new IPF_Admin_AccessDenied; + + return $name; + } + + function index() + { + \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->setCurrentDir(); + + $request = $this->request; + $match = $this->params; + $upload_path = IPF::getUploadPath(); + $upload_url = IPF::getUploadUrl(); + + $dirs = array(); + $files = array(); + foreach (scandir($this->dir) as $file) { + if ($file === '.' || $file === '..') + continue; + + $type = filetype($this->dir . $file); + + if ($type === 'dir') { + $dirs[] = array('name'=>$file, 'type'=>'dir'); + } else { + $sx = getimagesize($this->dir . $file); + if ($sx) { + $type = 'image'; + $info = str_replace('image/','',$sx['mime']).' '.$sx[0].'x'.$sx[1]; + } else { + $info = 'binary'; + } + $files[] = array('name'=>$file, 'type'=>$type, 'info'=>$info, 'size'=>filesize($this->dir . $file)); + } + } + usort($dirs, array('IPF_Admin_FileBrowser_Controller', 'cmp')); + usort($files, array('IPF_Admin_FileBrowser_Controller', 'cmp')); + + $dirtree = $this->dir_recursive($upload_path); + + $parts = array_filter(explode(DIRECTORY_SEPARATOR, $this->relative)); + + $path = array(); + $init = array(); + foreach ($parts as $part) { + $init = array_merge($init, array($part)); + $path[] = array( + 'dir' => implode(DIRECTORY_SEPARATOR, $init), + 'name' => $part, + ); + } + + $parent_dir = implode(DIRECTORY_SEPARATOR, array_slice($parts, 0, -1)); + + $context = array( + 'page_title' => __('File Browser'), + 'dirtree' => $dirtree, + 'dirs' => $dirs, + 'files' => $files, + 'path' => $path, + 'curr_dir' => $this->relative, + 'parent_dir' => $parent_dir, + ); + return IPF_Admin_App::RenderToResponse('admin/filebrowser.html', $context, $request); + } + + protected function backToIndex() + { + return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL::urlForView(array('IPF_Admin_FileBrowser_Controller', 'index')) . '?dir=' . $this->relative); + } + + function rename() + { + \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->setCurrentDir(); + + $old_name = $this->validateName($this->request->POST['old_name']); + $new_name = $this->validateName($this->request->POST['new_name']); + rename($this->dir . $old_name, $this->dir . $new_name); + + return $this->backToIndex(); + } + + function move() + { + \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->setCurrentDir(); + + $destination = $this->validatePath(IPF::getUploadPath() . DIRECTORY_SEPARATOR . \PFF\Arr::get($this->request->POST, 'destination', '')); + $name = $this->validateName($this->request->POST['name']); + rename($this->dir . $name, $destination . $name); + + return $this->backToIndex(); + } + + function mkdir() + { + \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->setCurrentDir(); + + $name = $this->validateName($this->request->POST['name']); + mkdir($this->dir . $name); + + return $this->backToIndex(); + } + + function delete() + { + \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->setCurrentDir(); + + $name = $this->validateName($this->request->POST['name']); + IPF_Utils::removeDirectories($this->dir . $name); + + return $this->backToIndex(); + } + + function upload() + { + \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->setCurrentDir(); + + $count = count($this->request->FILES['files']['name']); + for ($i = 0; $i < $count; ++$i) { + $uploadfile = $this->dir . basename($this->request->FILES['files']['name'][$i]); + move_uploaded_file($this->request->FILES['files']['tmp_name'][$i], $uploadfile); + } + + return $this->backToIndex(); + } +} + diff --git a/ipf/admin/controllers/user.php b/ipf/admin/controllers/user.php new file mode 100644 index 0000000..58983c4 --- /dev/null +++ b/ipf/admin/controllers/user.php @@ -0,0 +1,53 @@ +request->REQUEST, 'next', '')); + if (!$success_url) + $success_url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'index')); + + if ($this->request->method == 'POST') { + $form = new IPF_Admin_Forms_Login($this->request->POST); + if ($form->isValid()) { + \PFF\Container::auth()->login($this->request, $form->user); + return new IPF_HTTP_Response_Redirect($success_url); + } + } else { + $form = new IPF_Admin_Forms_Login(array('next'=>$success_url)); + } + + $context = array( + 'page_title' => IPF::get('admin_title'), + 'form' => $form, + ); + return IPF_Admin_App::RenderToResponse('admin/login.html', $context, $this->request); + } + + function logout() + { + \PFF\Container::auth()->logout($this->request); + $context = array( + 'page_title' => IPF::get('admin_title'), + ); + return IPF_Admin_App::RenderToResponse('admin/logout.html', $context, $this->request); + } + + function impersonate() + { + $success_url = trim(\PFF\Arr::get($this->request->REQUEST, 'next', '')); + if (!$success_url) + $success_url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'index')); + + if (!$this->request->user->isAnonymous() && $this->request->user->is_superuser) { + $user = \PFF\Container::auth()->findUser($this->params[1]); + if (!$user) + return new IPF_HTTP_Response_NotFound($this->request); + \PFF\Container::auth()->login($this->request, $user); + } + + return new IPF_HTTP_Response_Redirect($success_url); + } +} + diff --git a/ipf/admin/form/widgets/htmlinput.php b/ipf/admin/form/widgets/htmlinput.php index 87a772d..caf92bc 100644 --- a/ipf/admin/form/widgets/htmlinput.php +++ b/ipf/admin/form/widgets/htmlinput.php @@ -18,7 +18,7 @@ class IPF_Admin_Form_Widget_HTMLInput extends IPF_Form_Widget $this->force_absolute_urls = \PFF\Arr::pop($attrs, 'force_absolute_urls', false); $this->editor_config = \PFF\Arr::pop($attrs, 'editor_config', array()); - $this->filebrowser_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_FileBrowser', array('/')).'/'; + $this->filebrowser_url = IPF_HTTP_URL::urlForView(array('IPF_Admin_FileBrowser_Controller', 'index'), array('/')).'/'; parent::__construct($attrs); } diff --git a/ipf/admin/log.php b/ipf/admin/log.php index d6c487b..510d1d2 100644 --- a/ipf/admin/log.php +++ b/ipf/admin/log.php @@ -19,7 +19,7 @@ class IPF_Admin_Log public static function logObject($component, $action, $object, $object_id=null) { - $url = $object_id ? IPF_HTTP_URL::urlForView('IPF_Admin_Views_EditItem', array($component->app->slug(), $component->slug(), $object_id)) : ''; + $url = $object_id ? IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'editItem'), array($component->app->slug(), $component->slug(), $object_id)) : ''; self::log($component->request->user, $action, (string)$object, $component->verbose_name(), $url); } } diff --git a/ipf/admin/templates/admin/base.html b/ipf/admin/templates/admin/base.html index 89011eb..d63ba65 100644 --- a/ipf/admin/templates/admin/base.html +++ b/ipf/admin/templates/admin/base.html @@ -23,7 +23,7 @@ {block usertools}
- {trans 'Welcome'}, {$user}. {trans 'Log out'}
+ {trans 'Welcome'}, {$user}. {trans 'Log out'}
Version: {$IPF_VER}
{/block} @@ -42,7 +42,7 @@

{$app.name}

diff --git a/ipf/admin/templates/admin/change.html b/ipf/admin/templates/admin/change.html index 280df59..d884d88 100644 --- a/ipf/admin/templates/admin/change.html +++ b/ipf/admin/templates/admin/change.html @@ -9,8 +9,8 @@ {block breadcrumbs} {/block} @@ -38,7 +38,7 @@ {/block}
- {if ($mode=='change') && $component->isAccessible(array('delete'))}

{trans 'Delete'}

{/if} + {if ($mode=='change') && $component->isAccessible(array('delete'))}

{trans 'Delete'}

{/if} {if ($mode=='change') && $component->isAccessible(array('change'))}{/if} {if ($mode=='add') && $component->isAccessible(array('add'))}{/if} diff --git a/ipf/admin/templates/admin/delete.html b/ipf/admin/templates/admin/delete.html index 0026790..d346a16 100644 --- a/ipf/admin/templates/admin/delete.html +++ b/ipf/admin/templates/admin/delete.html @@ -2,9 +2,9 @@ {block breadcrumbs} {/block} diff --git a/ipf/admin/templates/admin/filebrowser.html b/ipf/admin/templates/admin/filebrowser.html index d5fed3a..21760fa 100644 --- a/ipf/admin/templates/admin/filebrowser.html +++ b/ipf/admin/templates/admin/filebrowser.html @@ -7,124 +7,150 @@ {$page_title} - IPF Administration - - - + {assign $zero_gif = "data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="} - - - + + + + + + {/foreach} + {foreach $files as $file} + + + + + + + {/foreach} + +
- -
-

Add Folder

- -
- -
+
+ -
{$dir['name']}SUB-DIR +
+ + + +
+
{$file['name']}{$file['info']}{$file['size']} +
+ + + +
+
-

View File

- -
+
- +
- - - - -
- - - - - - - - - - - {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
-
- -
- - - - + + + diff --git a/ipf/admin/templates/admin/index.html b/ipf/admin/templates/admin/index.html index add7d14..8ad6a40 100644 --- a/ipf/admin/templates/admin/index.html +++ b/ipf/admin/templates/admin/index.html @@ -14,9 +14,9 @@ {foreach $app.components as $component} - {$component->verbose_name()} - {if $component->isAccessible(array('add'))}{trans 'Add'}{/if} - {trans 'Change'} + {$component->verbose_name()} + {if $component->isAccessible(array('add'))}{trans 'Add'}{/if} + {trans 'Change'} {/foreach} diff --git a/ipf/admin/templates/admin/items.html b/ipf/admin/templates/admin/items.html index 57627da..8d6799e 100644 --- a/ipf/admin/templates/admin/items.html +++ b/ipf/admin/templates/admin/items.html @@ -1,6 +1,6 @@ {extends "admin/base.html"} -{block breadcrumbs}{/block} +{block breadcrumbs}{/block} {block content}
diff --git a/ipf/admin/templates/admin/logout.html b/ipf/admin/templates/admin/logout.html index 35cd838..243e937 100644 --- a/ipf/admin/templates/admin/logout.html +++ b/ipf/admin/templates/admin/logout.html @@ -7,7 +7,7 @@

Logged out

Thanks for spending some quality time with the Web site today.

-

Log in again.

+

Log in again.


{/block} diff --git a/ipf/admin/views.php b/ipf/admin/views.php deleted file mode 100644 index 4e3a9dc..0000000 --- a/ipf/admin/views.php +++ /dev/null @@ -1,254 +0,0 @@ -from('admin_log') - ->orderBy('created_at DESC') - ->limit(10) - ->asObject(true) - ->fetchAll(); - - $context = array( - 'page_title' => __('Site Administration'), - 'admin_log' => $admin_log, - ); - return IPF_Admin_App::RenderToResponse('admin/index.html', $context, $request); -} - -function IPF_Admin_Views_ListItems($request, $match) -{ - $component = IPF_Admin_App::getComponent($request, array('view')); - return $component->ListItems($request); -} - -function IPF_Admin_Views_AddItem($request, $match) -{ - $component = IPF_Admin_App::getComponent($request, array('view', 'add')); - return $component->AddItem($request); -} - -function IPF_Admin_Views_EditItem($request, $match) -{ - $component = IPF_Admin_App::getComponent($request, array('view', 'change')); - return $component->EditItem($request, $request->params[3]); -} - -function IPF_Admin_Views_DeleteItem($request, $match) -{ - $component = IPF_Admin_App::getComponent($request, array('view', 'delete')); - return $component->DeleteItem($request, $request->params[3]); -} - -function IPF_Admin_Views_Reorder($request, $match) -{ - $component = IPF_Admin_App::getComponent($request, array('view', 'change')); - - if ($request->method != 'POST' || !isset($request->POST['ids']) || !is_array($request->POST['ids'])) - return new IPF_HTTP_Response_NotFound($request); - - if ($component->reorder($request->POST['ids'])) - return new IPF_HTTP_Response_Json("Ok"); - else - return new IPF_HTTP_Response_Json('Cannot find model'); -} - -function IPF_Admin_Views_Login($request, $match) -{ - $success_url = ''; - if (!empty($request->REQUEST['next'])) - $success_url = $request->REQUEST['next']; - if (trim($success_url)=='') - $success_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_Index'); - - if ($request->method == 'POST') { - $form = new IPF_Admin_Forms_Login($request->POST); - if ($form->isValid()) { - \PFF\Container::auth()->login($request, $form->user); - return new IPF_HTTP_Response_Redirect($success_url); - } - } else { - $form = new IPF_Admin_Forms_Login(array('next'=>$success_url)); - } - - $context = array( - 'page_title' => IPF::get('admin_title'), - 'form' => $form, - ); - return IPF_Admin_App::RenderToResponse('admin/login.html', $context, $request); -} - -function IPF_Admin_Views_Logout($request, $match) -{ - \PFF\Container::auth()->logout($request); - $context = array( - 'page_title' => IPF::get('admin_title'), - ); - return IPF_Admin_App::RenderToResponse('admin/logout.html', $context, $request); -} - -function IPF_Admin_Views_Impersonate($request, $match) -{ - $success_url = ''; - if (!empty($request->REQUEST['next'])) - $success_url = trim($request->REQUEST['next']); - if (!$success_url) - $success_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_Index'); - - if (!$request->user->isAnonymous() && $request->user->is_superuser) { - $user = \PFF\Container::auth()->findUser($match[1]); - if (!$user) - return new IPF_HTTP_Response_NotFound($request); - \PFF\Container::auth()->login($request, $user); - } - - return new IPF_HTTP_Response_Redirect($success_url); -} - -function cmp($a, $b) -{ - if ($a['name'] == $b['name']) - return 0; - return ($a['name'] < $b['name']) ? -1 : 1; -} - -function dir_recursive($dir, $path=DIRECTORY_SEPARATOR, $level='') -{ - $dirtree = array(); - if ($level=='') - $dirtree[] = array('path'=>'', 'name'=>'Root Folder'); - $dd = array(); - if ($dh = @opendir($dir)) { - while (($file = readdir($dh)) !== false) { - if (($file=='.') || ($file=='..')) continue; - if (filetype($dir . $file)=='dir') - $dd[] = $file; - } - closedir($dh); - sort($dd); - foreach($dd as $file){ - $dirtree[] = array('path'=>$path.$file, 'name'=>$level.$file); - $dirtree = array_merge($dirtree, dir_recursive($dir.$file.DIRECTORY_SEPARATOR, $path.$file.DIRECTORY_SEPARATOR, $level.'--')); - } - } - return $dirtree; - //print_r($dirtree); -} - -function IPF_Admin_Views_FileBrowser($request, $match) -{ - IPF_Admin_App::ensureUserIsStaff($request); - - $curr_dir = urldecode(substr($match[1],1)); - if (substr($curr_dir, -1) == '/') - $curr_dir = substr($curr_dir, 0, strlen($curr_dir)-1); - - $upload_path = IPF::getUploadPath(); - $upload_url = IPF::getUploadUrl(); - - $dir = $upload_path . $curr_dir; - $_dir = substr($dir, -1) !== DIRECTORY_SEPARATOR ? $dir.DIRECTORY_SEPARATOR : $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 (@$request->POST['new_name']!='') - @rename($_dir.$request->POST['old_name'], $_dir.$request->POST['new_name']); - - if (@$request->POST['action']=='move'){ - @rename($_dir.$request->POST['old_name'], $upload_path.$request->POST['move'].DIRECTORY_SEPARATOR.$request->POST['old_name']); - } - if (@$_FILES['files']) { - $count = count($_FILES['files']['name']); - for ($i = 0; $i < $count; ++$i) { - $uploadfile = $_dir . basename($_FILES['files']['name'][$i]); - @move_uploaded_file($_FILES['files']['tmp_name'][$i], $uploadfile); - } - } - } - - $id = 1; - $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('id'=>$id, 'name'=>$file); - $id++; - } 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; - $zh = 150; - } - $files[] = array('id'=>$id, 'name'=>$file, 'image'=>$image, 'type'=>$type, 'zw'=>$zw, 'zh'=>$zh, 'size'=>filesize($_dir . $file)); - $id++; - } - } - closedir($dh); - } - usort($dirs, 'cmp'); - usort($files, 'cmp'); - - $dirtree = dir_recursive($upload_path); - - $pth = explode('/',$curr_dir); - $path = array(); - $cd = '/admin/filebrowser/'; - foreach($pth as $p) { - $cd.=$p.'/'; - $path[] = array('cd'=>$cd, 'name'=>$p); - } - - $context = array( - 'page_title' => __('File Browser'), - 'dirtree' => $dirtree, - 'dirs' => $dirs, - 'files' => $files, - 'path' => $path, - 'upload_url' => $upload_url, - 'curr_dir' => $curr_dir, - ); - return IPF_Admin_App::RenderToResponse('admin/filebrowser.html', $context, $request); -} - -function IPF_Admin_Views_FileBrowserRename($request, $match) -{ - IPF_Admin_App::ensureUserIsStaff($request); - - $old_name = @$request->POST['old_value']; - $name = @$request->POST['value']; -// $curr_dir = @$request->POST['curr_dir']; - if ($name=='') - $name=$old_name; - return new IPF_HTTP_Response($name); -} - diff --git a/ipf/auth/admin.php b/ipf/auth/admin.php index f794f30..1d7003a 100644 --- a/ipf/auth/admin.php +++ b/ipf/auth/admin.php @@ -248,7 +248,7 @@ class AdminUser extends \IPF_Admin_Component protected function objectTools($user) { return array( - 'impersonate' => \IPF_HTTP_URL::urlForView('IPF_Admin_Views_Impersonate', array($user->id)), + 'impersonate' => \IPF_HTTP_URL::urlForView(array('IPF_Admin_User_Controller', 'impersonate'), array($user->id)), ); }