source: branches/version-2_5-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileManager.php @ 19909

Revision 19909, 10.4 KB checked in by uemoto, 13 years ago (diff)

#382(管理画面XHTMLに変更)

  • デザインを刷新
  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.php");
26require_once(CLASS_EX_REALDIR . "helper_extends/SC_Helper_FileManager_Ex.php");
27
28/**
29 * ファイル管理 のページクラス.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class LC_Page_Admin_Contents_FileManager extends LC_Page_Admin {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46        parent::init();
47        $this->tpl_mainpage = 'contents/file_manager.tpl';
48        $this->tpl_mainno = 'contents';
49        $this->tpl_subnavi = 'contents/subnavi.tpl';
50        $this->tpl_subno = "file";
51        $this->tpl_subtitle = 'ファイル管理';
52
53    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
60    function process() {
61        $this->action();
62        $this->sendResponse();
63    }
64
65    /**
66     * Page のアクション.
67     *
68     * @return void
69     */
70    function action() {
71        //---- 認証可否の判定
72        $objSess = new SC_Session();
73        SC_Utils_Ex::sfIsSuccess($objSess);
74
75        // ルートディレクトリ
76        $top_dir = USER_REALDIR;
77
78        $objView = new SC_AdminView();
79        $objQuery = new SC_Query();
80        $objFileManager = new SC_Helper_FileManager_Ex();
81
82        if (!isset($_POST['mode'])) $_POST['mode'] = "";
83       
84        // 現在の階層を取得
85        if($_POST['mode'] != "") {
86            $now_dir = $_POST['now_file'];
87        } else {
88            // 初期表示はルートディレクトリ(user_data/)を表示
89            $now_dir = $top_dir;
90        }
91
92        // ファイル管理クラス
93        $objUpFile = new SC_UploadFile($now_dir, $now_dir);
94        // ファイル情報の初期化
95        $this->lfInitFile($objUpFile);
96
97        switch($_POST['mode']) {
98
99            // ファイル表示
100
101        case 'view':
102            // エラーチェック
103
104            $arrErr = $this->lfErrorCheck();
105
106            if (empty($arrErr)) {
107                // 選択されたファイルがディレクトリなら移動
108                if(is_dir($_POST['select_file'])) {
109                    $now_dir = $this->lfCheckSelectDir($_POST['select_file']);
110                } else {
111                    // javascriptで別窓表示(テンプレート側に渡す)
112                    // FIXME XSS対策すること
113                    $file_url = ereg_replace(USER_REALDIR, "", $_POST['select_file']);
114                    $this->tpl_onload = "win02('./file_view.php?file=". $file_url ."', 'user_data', '600', '400');";
115                    $now_dir = $this->lfCheckSelectDir(dirname($_POST['select_file']));
116                }
117            }
118
119            break;
120           
121            // ファイルダウンロード
122        case 'download':
123
124            // エラーチェック
125            $arrErr = $this->lfErrorCheck();
126            if (empty($arrErr)) {
127                if(is_dir($_POST['select_file'])) {
128                    // ディレクトリの場合はjavascriptエラー
129                    $arrErr['select_file'] = "※ ディレクトリをダウンロードすることは出来ません。<br/>";
130                } else {
131                    // ファイルダウンロード
132                    $objFileManager->sfDownloadFile($_POST['select_file']);
133                    exit;
134                }
135            }
136            break;
137            // ファイル削除
138        case 'delete':
139            // エラーチェック
140            $arrErr = $this->lfErrorCheck();
141            if (empty($arrErr)) {
142                $objFileManager->sfDeleteDir($_POST['select_file']);
143            }
144            break;
145            // ファイル作成
146        case 'create':
147            // エラーチェック
148            $arrErr = $this->lfCreateErrorCheck();
149            if (empty($arrErr)) {
150                $create_dir = ereg_replace("/$", "", $now_dir);
151                // ファイル作成
152                if(!$objFileManager->sfCreateFile($create_dir."/".$_POST['create_file'], 0755)) {
153                    // 作成エラー
154                    $arrErr['create_file'] = "※ ".$_POST['create_file']."の作成に失敗しました。<br/>";
155                } else {
156                    $this->tpl_onload .= "alert('フォルダを作成しました。');";
157                }
158            }
159            break;
160            // ファイルアップロード
161        case 'upload':
162            // 画像保存処理
163            $ret = $objUpFile->makeTempFile('upload_file', false);
164            if($ret != "") {
165                $arrErr['upload_file'] = $ret;
166            } else {
167                $this->tpl_onload .= "alert('ファイルをアップロードしました。');";
168            }
169            break;
170            // フォルダ移動
171        case 'move':
172            $now_dir = $this->lfCheckSelectDir($_POST['tree_select_file']);
173            break;
174            // 初期表示
175        default :
176            break;
177        }
178        // トップディレクトリか調査
179        $is_top_dir = false;
180        // 末尾の/をとる
181        $top_dir_check = ereg_replace("/$", "", $top_dir);
182        $now_dir_check = ereg_replace("/$", "", $now_dir);
183        if($top_dir_check == $now_dir_check) $is_top_dir = true;
184
185        // 現在の階層より一つ上の階層を取得
186        $parent_dir = $this->lfGetParentDir($now_dir);
187
188        // 現在のディレクトリ配下のファイル一覧を取得
189        $this->arrFileList = $objFileManager->sfGetFileList($now_dir);
190        $this->tpl_is_top_dir = $is_top_dir;
191        $this->tpl_parent_dir = $parent_dir;
192        // TODO JSON で投げて, フロント側で処理した方が良い?
193        $this->tpl_now_dir = "";
194        $arrNowDir = preg_split('/\//', str_replace(HTML_REALDIR, '', $now_dir));
195        for ($i = 0; $i < count($arrNowDir); $i++) {
196            if (!empty($arrNowDir)) {
197                $this->tpl_now_dir .= $arrNowDir[$i];
198                if ($i < count($arrNowDir) - 1) {
199                     // フロント側で &gt; へエスケープするため, ここでは > を使用
200                    $this->tpl_now_dir .= ' > ';
201                }
202            }
203        }
204        $this->tpl_now_file = basename($now_dir);
205        $this->arrErr = isset($arrErr) ? $arrErr : "";
206        $this->arrParam = $_POST;
207
208        // ツリーを表示する divタグid, ツリー配列変数名, 現在ディレクトリ, 選択ツリーhidden名, ツリー状態hidden名, mode hidden名
209        $treeView = "fnTreeView('tree', arrTree, '$now_dir', 'tree_select_file', 'tree_status', 'move');";
210        if (!empty($this->tpl_onload)) {
211            $this->tpl_onload .= $treeView;
212        } else {
213            $this->tpl_onload = $treeView;
214        }
215
216        // ツリー配列作成用 javascript
217        if (!isset($_POST['tree_status'])) $_POST['tree_status'] = "";
218        $arrTree = $objFileManager->sfGetFileTree($top_dir, $_POST['tree_status']);
219        $this->tpl_javascript .= "arrTree = new Array();\n";
220        foreach($arrTree as $arrVal) {
221            $this->tpl_javascript .= "arrTree[".$arrVal['count']."] = new Array(".$arrVal['count'].", '".$arrVal['type']."', '".$arrVal['path']."', ".$arrVal['rank'].",";
222            if ($arrVal['open']) {
223                $this->tpl_javascript .= "true);\n";
224            } else {
225                $this->tpl_javascript .= "false);\n";
226            }
227        }
228    }
229
230    /**
231     * デストラクタ.
232     *
233     * @return void
234     */
235    function destroy() {
236        parent::destroy();
237    }
238
239    /*
240     * 関数名:lfErrorCheck()
241     * 説明 :エラーチェック
242     */
243    function lfErrorCheck() {
244        $objErr = new SC_CheckError($_POST);
245        $objErr->doFunc(array("ファイル", "select_file"), array("SELECT_CHECK"));
246
247        return $objErr->arrErr;
248    }
249
250    /*
251     * 関数名:lfCreateErrorCheck()
252     * 説明 :ファイル作成処理エラーチェック
253     */
254    function lfCreateErrorCheck() {
255        $objErr = new SC_CheckError($_POST);
256        $objErr->doFunc(array("作成ファイル名", "create_file"), array("EXIST_CHECK", "FILE_NAME_CHECK_BY_NOUPLOAD"));
257
258        return $objErr->arrErr;
259    }
260
261    /*
262     * 関数名:lfInitFile()
263     * 説明 :ファイル情報の初期化
264     */
265    function lfInitFile(&$objUpFile) {
266        $objUpFile->addFile("ファイル", 'upload_file', array(), FILE_SIZE, true, 0, 0, false);
267    }
268
269    /*
270     * 関数名:lfCheckSelectDir()
271     * 引数1:ディレクトリ
272     * 説明:選択ディレクトリがUSER_REALDIR以下かチェック
273     */
274    function lfCheckSelectDir($dir) {
275        $top_dir = USER_REALDIR;
276        // USER_REALDIR以下の場合
277            if (preg_match("@^\Q". $top_dir. "\E@", $dir) > 0) {
278            // 相対パスがある場合、USER_REALDIRを返す.
279            if (preg_match("@\Q..\E@", $dir) > 0) {
280                return $top_dir;
281            // 相対パスがない場合、そのままディレクトリパスを返す.
282            } else {
283                return $dir;
284            }
285        // USER_REALDIR以下でない場合、USER_REALDIRを返す.
286        } else {
287            return $top_dir;
288        }
289    }
290
291    /*
292     * 関数名:lfGetParentDir()
293     * 引数1 :ディレクトリ
294     * 説明 :親ディレクトリ取得
295     */
296    function lfGetParentDir($dir) {
297        $dir = ereg_replace("/$", "", $dir);
298        $arrDir = split('/', $dir);
299        array_pop($arrDir);
300        $parent_dir = "";
301        foreach($arrDir as $val) {
302            $parent_dir .= "$val/";
303        }
304        $parent_dir = ereg_replace("/$", "", $parent_dir);
305
306        return $parent_dir;
307    }
308}
309?>
Note: See TracBrowser for help on using the repository browser.