]> git.andy128k.dev Git - ipf.git/commitdiff
move admin views to controllers. rework file browser and routes.
authorAndrey Kutejko <andy128k@gmail.com>
Fri, 2 Jan 2015 17:31:37 +0000 (19:31 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Fri, 2 Jan 2015 17:31:37 +0000 (19:31 +0200)
17 files changed:
ipf/admin/app.php
ipf/admin/assets/css/base.css
ipf/admin/component.php
ipf/admin/controllers/components.php [new file with mode: 0644]
ipf/admin/controllers/file_browser.php [new file with mode: 0644]
ipf/admin/controllers/user.php [new file with mode: 0644]
ipf/admin/form/widgets/htmlinput.php
ipf/admin/log.php
ipf/admin/templates/admin/base.html
ipf/admin/templates/admin/change.html
ipf/admin/templates/admin/delete.html
ipf/admin/templates/admin/filebrowser.html
ipf/admin/templates/admin/index.html
ipf/admin/templates/admin/items.html
ipf/admin/templates/admin/logout.html
ipf/admin/views.php [deleted file]
ipf/auth/admin.php

index 815555ed6e383e6c59a30600e2cb6a2d57e06ef5..8d14c98fcf5a89c22feca6847444bc287f9f6583 100644 (file)
@@ -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')));
     }
 }
 
index 54d68516a017f04f9bd54cf51949359c785fef84..e9bbad69938cc7956e0cd6d388105996726356a4 100644 (file)
@@ -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%; }
index 2ada07f0ff4cebc3d1c210dffa77d2616d555d25..e9f8d58a78a43611fd3fca7c0f0c39575af31805 100644 (file)
@@ -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 (file)
index 0000000..ff705a9
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+class IPF_Admin_Controller extends IPF_Controller
+{
+    function index()
+    {
+        \PFF\Container::admin()->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 (file)
index 0000000..fa665b2
--- /dev/null
@@ -0,0 +1,190 @@
+<?php
+
+class IPF_Admin_FileBrowser_Controller extends IPF_Controller
+{
+    static function cmp($a, $b)
+    {
+        if ($a['name'] == $b['name'])
+            return 0;
+        return ($a['name'] < $b['name']) ? -1 : 1;
+    }
+
+    protected 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, $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 (file)
index 0000000..58983c4
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+class IPF_Admin_User_Controller extends IPF_Controller
+{
+    function login()
+    {
+        $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->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);
+    }
+}
+
index 87a772de7d280c3c23d8b2123331225da7d1c5d6..caf92bc09122c05260b1f96d20d62d13eff420af 100644 (file)
@@ -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);
     }
index d6c487b74363e4c84a020e7f2f26cada447655e3..510d1d2aee8d37adc76435942f3f4150a8065fd6 100644 (file)
@@ -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);
     }
 }
index 89011eb5194ad04375694099ebb2802841cd67f8..d63ba65006216f38be2c1b484ca338bb5b3958fc 100644 (file)
@@ -23,7 +23,7 @@
     </div>
     {block usertools}
       <div id="user-tools">
-        {trans 'Welcome'}, <strong>{$user}</strong>. <a href="{url 'IPF_Admin_Views_Logout'}">{trans 'Log out'}</a><br />
+        {trans 'Welcome'}, <strong>{$user}</strong>. <a href="{url array('IPF_Admin_User_Controller', 'logout')}">{trans 'Log out'}</a><br />
         <span id="ipfver">Version: {$IPF_VER}</span>
       </div>
     {/block}
@@ -42,7 +42,7 @@
             <h3>{$app.name}</h3>
             <ul>
               {foreach $app.components as $component}
-              <li><a href="{url 'IPF_Admin_Views_ListItems', array($app.path, $component->slug())}">{$component->verbose_name()}</a></li>
+              <li><a href="{url array('IPF_Admin_Controller', 'listItems'), array($app.path, $component->slug())}">{$component->verbose_name()}</a></li>
               {/foreach}
             </ul>
           </li>
index 280df59e3149fb6c99b13dbeb02e53c4f9a2920f..d884d8879471aa827d013664a9602ee91f9a0585 100644 (file)
@@ -9,8 +9,8 @@
 
 {block breadcrumbs}
 <div class="breadcrumbs">
-  <a href="{url 'IPF_Admin_Views_Index'}">{trans 'Home'}</a> &raquo;
-  <a href="{url 'IPF_Admin_Views_ListItems', array($app->slug(), $component->slug())}">{$classname}</a> &raquo;
+  <a href="{url array('IPF_Admin_Controller', 'index')}">{trans 'Home'}</a> &raquo;
+  <a href="{url array('IPF_Admin_Controller', 'listItems'), array($app->slug(), $component->slug())}">{$classname}</a> &raquo;
   {$page_title}
 </div>
 {/block}
@@ -38,7 +38,7 @@
               {/block}
             </fieldset>
             <div class="submit-row change-form">
-                {if ($mode=='change') && $component->isAccessible(array('delete'))}<p class="float-left"><a id="id_a_delete" href="{url 'IPF_Admin_Views_DeleteItem', array($app->slug(), $component->slug(), $object_id)}" class="deletelink">{trans 'Delete'}</a></p>{/if}
+                {if ($mode=='change') && $component->isAccessible(array('delete'))}<p class="float-left"><a id="id_a_delete" href="{url array('IPF_Admin_Controller', 'deleteItem'), array($app->slug(), $component->slug(), $object_id)}" class="deletelink">{trans 'Delete'}</a></p>{/if}
                 {if ($mode=='change') && $component->isAccessible(array('change'))}<input type="submit" value="{trans 'Save'}" class="default" />{/if}
                 {if ($mode=='add') && $component->isAccessible(array('add'))}<input type="submit" value="{trans 'Add'}" class="default" />{/if}
                 <input type="button" value="{trans 'Cancel'}" onclick="javascript:history.back();" />
index 00267902b58aaa28f52a2d0e5f841826961472e3..d346a166d384432d3b772ca27bb58d68933b9cce 100644 (file)
@@ -2,9 +2,9 @@
 
 {block breadcrumbs}
 <div class="breadcrumbs">
-  <a href="{url 'IPF_Admin_Views_Index'}">{trans 'Home'}</a> &raquo;
-  <a href="{url 'IPF_Admin_Views_ListItems', array($app->slug(), $component->slug())}">{$classname}</a> &raquo;
-  <a href="{url 'IPF_Admin_Views_EditItem', array($app->slug(), $component->slug(), $object_id)}">{$object}</a> &raquo;
+  <a href="{url array('IPF_Admin_Controller', 'index')}">{trans 'Home'}</a> &raquo;
+  <a href="{url array('IPF_Admin_Controller', 'listItems'), array($app->slug(), $component->slug())}">{$classname}</a> &raquo;
+  <a href="{url array('IPF_Admin_Controller', 'editItem'), array($app->slug(), $component->slug(), $object_id)}">{$object}</a> &raquo;
   {$page_title}
 </div>
 {/block}
index d5fed3aff48d062706c05a30f271b891182b1da8..21760fad4396d4e3af65c9e9b704b6557a96b44c 100644 (file)
   <link rel="stylesheet" type="text/css" href="{$STATIC_URL}css/admin-print.css" media="print">
   <style>
   {literal}
-    .breadcrumbs {padding:10px;}
+    html, body {height: 100%;padding:0; margin:0; overflow: hidden;}
 
-    a {color:#2B6FB6 !important;}
-    a:hover {color:black !important;}
+    .columns {height: 100%;width:100%;padding:0; margin:0;}
+
+    .sidebar-column {width:250px; height: 100%; border-right:1px dashed #a0a0a0; padding: 0 10px;float: left}
+
+    .hr { border-top:1px dashed #a0a0a0; margin-top:5px; padding-top:5px; }
+
+    .content-column {padding: 0 10px;margin-left:270px;height:100%;}
+    .breadcrumbs {padding:10px 0;height:20px;line-height:20px}
+    .content-column .module {width:100%; height: calc(100% - 90px); overflow:auto; margin: 0;}
+
+    .submit-row {height: 30px;padding: 10px 0; text-align: right;}
 
     #pic { border:2px solid white; width:240px; text-align:center; height: 150px; line-height: 150px; background: #888; }
     #pic img { max-width: 240px; max-height: 150px; display:none; }
 
-    #prop { display:none; position:absolute; left:0; top:0; z-index:400000; border:2px solid #aaa;}
-    #prop img {width:100px}
+    #prop { display:none; position:absolute; left:0; top:0; z-index:400000; border:2px solid #aaa; background: #888; }
+    #prop img {max-width:100px;max-height:100px}
   {/literal}
   </style>
 
   <title>{$page_title} - IPF Administration</title>
 </head>
-<body style="padding:0; margin:0;overflow:hidden">
-  <div class="breadcrumbs">
-    <a href="{url 'IPF_Admin_Views_FileBrowser', array('/')}">Root</a>
-    {foreach $path as $p}
-      {if $p['name']}
-        / <a href="{$p['cd']}">{$p['name']}</a>
-      {/if}
-    {/foreach}
-  </div>
-
+<body>
   {assign $zero_gif = "data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="}
 
-  <table cellpadding="0" cellspacing="0" width="100%">
-    <tr>
-      <td valign="top" style="width:250px; background:#f0f0f0; border-right:1px dashed #a0a0a0; padding:10px;">
-        <!-- sidebar -->
-        <form method="post">
-          <h3>Add Folder</h3>
-          <input name="new_folder">
-          <div class="submit-row">
-            <input class="default" type="submit" value="Create"/>
-          </div>
+  <div class="columns">
+    <div class="sidebar-column">
+      <!-- sidebar -->
+      <form method="post" action="{url array('IPF_Admin_FileBrowser_Controller', 'mkdir')}">
+        <h3>Add Folder</h3>
+        <input type="hidden" name="dir" value="{$curr_dir}">
+        <input name="name">
+        <input type="submit" value="Create">
+      </form>
+
+      <div class="hr"></div>
+
+      <form method="post" enctype="multipart/form-data" action="{url array('IPF_Admin_FileBrowser_Controller', 'upload')}">
+        <h3>Upload File</h3>
+        <input type="file" name="files[]" multiple="multiple">
+        <input type="hidden" name="dir" value="{$curr_dir}">
+        <input type="submit" value="Upload">
+      </form>
+
+      <div id="picname" style="display:none;">
+        <div class="hr"></div>
+
+        <h3>File Option</h3>
+        <form method="post" action="{url array('IPF_Admin_FileBrowser_Controller', 'rename')}">
+          <input type="hidden" name="old_name" id="id_old_name">
+          <input type="hidden" name="dir" value="{$curr_dir}">
+          <input name="new_name" id="id_new_name">
+          <input type="submit" value="Rename">
         </form>
 
-        <form method="post" enctype="multipart/form-data">
-          <h3 style="border-top:1px dashed #a0a0a0; padding-top:5px;">Upload File</h3>
-          <input type="file" name="files[]" multiple="multiple">
-          <div class="submit-row">
-            <input class="default" type="submit" value="Upload">
-          </div>
+        <br>
+
+        <form method="post" action="{url array('IPF_Admin_FileBrowser_Controller', 'move')}">
+          <input type="hidden" name="name" id="id_old_name2">
+          <input type="hidden" name="dir" value="{$curr_dir}">
+          <select name="destination">{foreach $dirtree as $dir}<option value="{$dir['path']}">{$dir['name']}</option>{/foreach}</select>
+          <input type="submit" value="Move To">
         </form>
+      </div>
+
+      <div class="hr"></div>
+
+      <h3>View File</h3>
+
+      <div id="pic"><img src="{$zero_gif}"></div>
+      <!-- /sidebar -->
+    </div>
 
-        <div id="picname" style="display:none;">
-          <h3 style="border-top:1px dashed #a0a0a0; padding:5px 0;">File Option</h3>
-          <form method="post">
-            <input type="hidden" name="old_name" id="id_old_name">
-            <input type="hidden" name="curr_dir" id="id_curr_dir" value="{$curr_dir}">
-            <table cellpadding="0" cellspacing="0">
+    <div class="content-column">
+      <!-- content -->
+
+        <div class="breadcrumbs">
+          <a href="{url array('IPF_Admin_FileBrowser_Controller', 'index')}?dir=">Root</a>
+          {foreach $path as $p}
+            / <a href="{url array('IPF_Admin_FileBrowser_Controller', 'index')}?dir={$p['dir']}">{$p['name']}</a>
+          {/foreach}
+        </div>
+
+        <div class="module" id="changelist">
+          <table>
+            <thead>
               <tr>
-                <td><input name="new_name" id="id_new_name"></td>
-                <td><div class="submit-row" style="float:left;"><input class="default" type="submit" value="Rename"></div></td>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Size</th>
+                <th>Delete</th>
               </tr>
-            </table>
-          </form>
-
-          <form method="post">
-            <input type="hidden" name="action" value="move">
-            <input type="hidden" name="old_name" id="id_old_name2">
-            <table cellpadding="0" cellspacing="0">
+            </thead>
+            <tbody>
+            {if $curr_dir}
               <tr>
-                <td><select name="move">{foreach $dirtree as $dir}<option value="{$dir['path']}">{$dir['name']}</option>{/foreach}</select></td>
-                <td><div class="submit-row" style="float:left;"><input class="default" type="submit" value="Move To"/></div></td>
+                <td><a href="{url array('IPF_Admin_FileBrowser_Controller', 'index')}?dir={$parent_dir}">..</a></td>
+                <td>UP-DIR</td>
+                <td></td>
+                <td></td>
               </tr>
-            </table>
-          </form>
+            {/if}
+            {foreach $dirs as $dir}
+              <tr>
+                <td><a href="{url array('IPF_Admin_FileBrowser_Controller', 'index')}?dir={$curr_dir}{$dir['name']}">{$dir['name']}</a></td>
+                <td>SUB-DIR</td>
+                <td></td>
+                <td>
+                  <form method="POST" action="{url array('IPF_Admin_FileBrowser_Controller', 'delete')}">
+                    <input type="hidden" name="dir" value="{$curr_dir}">
+                    <input type="hidden" name="name" value="{$dir['name']}">
+                    <input type="submit" value="delete" class="link-like">
+                  </form>
+                </td>
+              </tr>
+            {/foreach}
+            {foreach $files as $file}
+              <tr{if $file['type'] === 'image'} class="image"{/if} data-name="{$file['name']}" data-url="{$UPLOAD_URL}{$curr_dir}{$file['name']}">
+                <td><a href="#" class="file">{$file['name']}</a></td>
+                <td>{$file['info']}</td>
+                <td>{$file['size']}</td>
+                <td>
+                  <form method="POST" action="{url array('IPF_Admin_FileBrowser_Controller', 'delete')}">
+                    <input type="hidden" name="dir" value="{$curr_dir}">
+                    <input type="hidden" name="name" value="{$file['name']}">
+                    <input type="submit" value="delete" class="link-like">
+                  </form>
+                </td>
+              </tr>
+            {/foreach}
+            </tbody>
+          </table>
         </div>
 
-        <h3 style="border-top:1px dashed #a0a0a0; padding:5px 0;">View File</h3>
-
-        <div id="pic"><img src="{$zero_gif}"></div>
+        <div id="prop"><img src="{$zero_gif}"></div>
 
         <div class="submit-row">
-          <input type="button" value="Select & Close" onclick="FileBrowserSelect()">
+          <input type="button" class="default" value="Select & Close" onclick="FileBrowserSelect()">
         </div>
-        <!-- /sidebar -->
-      </td>
-      <td valign="top" style="padding:10px;">
-        <!-- content -->
-          <div class="module" id="changelist" style="width:500px; height:550px; overflow:scroll;">
-            <table>
-              <thead>
-                <tr>
-                  <th>Filename</th>
-                  <th>Type</th>
-                  <th>Size</th>
-                  <th>delete</th>
-                </tr>
-              </thead>
-              <tbody>
-              {foreach $dirs as $dir}
-                <tr>
-                  <td><a href="{$dir['name']}/">{$dir['name']}</a></td>
-                  <td colspan="2">SUB-DIR</td>
-                  <td>{if $dir['name'] !== '..'}<a href="?delete={$dir['name']}">delete</a>{/if}</td>
-                </tr>
-              {/foreach}
-              {foreach $files as $file}
-                <tr{if $file['image']} class="image"{/if} data-name="{$file['name']}" data-url="{$UPLOAD_URL}{$curr_dir}/{$file['name']}">
-                  <td><a href="#" class="file">{$file['name']}</a></td>
-                  <td>{$file['type']}</td>
-                  <td>{$file['size']}</td>
-                  <td><a href="?delete={$file['name']}">delete</a></td>
-                </tr>
-              {/foreach}
-              </tbody>
-            </table>
-          </div>
-
-          <div id="prop"><img src="{$zero_gif}"></div>
-        <!-- /content -->
-      </td>
-    </tr>
-  </table>
+      <!-- /content -->
+    </div>
+  </div>
 
   <script src="{$STATIC_URL}js/filebrowser_popup.js"></script>
   <script src="{$STATIC_URL}admin/tinymce/tinymce.min.js"></script>
index add7d14ca32884784ce414a191f87db94e64048c..8ad6a408a8f1e3a8111254fafaf816ee0cb641f3 100644 (file)
@@ -14,9 +14,9 @@
                <tbody>
         {foreach $app.components as $component}
         <tr>
-            <th scope="row"><a href="{url 'IPF_Admin_Views_ListItems', array($app.path, $component->slug())}">{$component->verbose_name()}</a></th>
-            <td>{if $component->isAccessible(array('add'))}<a class="addlink" href="{url 'IPF_Admin_Views_AddItem', array($app.path, $component->slug())}">{trans 'Add'}</a>{/if}</td>
-            <td><a class="changelink" href="{url 'IPF_Admin_Views_ListItems', array($app.path, $component->slug())}">{trans 'Change'}</a></td>
+            <th scope="row"><a href="{url array('IPF_Admin_Controller', 'listItems'), array($app.path, $component->slug())}">{$component->verbose_name()}</a></th>
+            <td>{if $component->isAccessible(array('add'))}<a class="addlink" href="{url array('IPF_Admin_Controller', 'addItem'), array($app.path, $component->slug())}">{trans 'Add'}</a>{/if}</td>
+            <td><a class="changelink" href="{url array('IPF_Admin_Controller', 'listItems'), array($app.path, $component->slug())}">{trans 'Change'}</a></td>
         </tr>
         {/foreach}
         </tbody>
index 57627da3a9cb9085ade8825f53765ea6c3c8606e..8d6799e6935c31e196fdf3c3386bcc30bbac770b 100644 (file)
@@ -1,6 +1,6 @@
 {extends "admin/base.html"}
 
-{block breadcrumbs}<div class="breadcrumbs"><a href="{url 'IPF_Admin_Views_Index'}">{trans 'Home'}</a> &raquo; {$page_title}</div>{/block}
+{block breadcrumbs}<div class="breadcrumbs"><a href="{url array('IPF_Admin_Controller', 'index')}">{trans 'Home'}</a> &raquo; {$page_title}</div>{/block}
 
 {block content}
 <div id="content" class="flex">
index 35cd8386e3f92a404f2458d166f093bfce822b2b..243e937d903e29c1e5657d5594fba0fe7e139eea 100644 (file)
@@ -7,7 +7,7 @@
 <div id="content" class="colM">
 <h1>Logged out</h1>
 <p>Thanks for spending some quality time with the Web site today.</p>
-<p><a href="{url 'IPF_Admin_Views_Index'}">Log in</a> again.</p>
+<p><a href="{url array('IPF_Admin_Controller', 'index')}">Log in</a> again.</p>
 <br class="clear"/>
 </div>
 {/block}
diff --git a/ipf/admin/views.php b/ipf/admin/views.php
deleted file mode 100644 (file)
index 4e3a9dc..0000000
+++ /dev/null
@@ -1,254 +0,0 @@
-<?php
-
-function IPF_Admin_Views_Index($request, $match)
-{
-    IPF_Admin_App::ensureUserIsStaff($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, $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);
-}
-
index f794f30156eaf8363e2bccaa00e4f6e759f43bbb..1d7003ab0499b480eb042136033d45dc0420d67d 100644 (file)
@@ -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)),
         );
     }