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

Revision 20116, 10.4 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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        // 現在の階層を取得 TODO 要リファクタリング(MODE if利用)
83        if($this->getMode() != null) {
84            $now_dir = $_POST['now_file'];
85        } else {
86            // 初期表示はルートディレクトリ(user_data/)を表示
87            $now_dir = $top_dir;
88        }
89
90        // ファイル管理クラス
91        $objUpFile = new SC_UploadFile($now_dir, $now_dir);
92        // ファイル情報の初期化
93        $this->lfInitFile($objUpFile);
94
95        switch($this->getMode()) {
96
97            // ファイル表示
98
99        case 'view':
100            // エラーチェック
101
102            $arrErr = $this->lfErrorCheck();
103
104            if (empty($arrErr)) {
105                // 選択されたファイルがディレクトリなら移動
106                if(is_dir($_POST['select_file'])) {
107                    $now_dir = $this->lfCheckSelectDir($_POST['select_file']);
108                } else {
109                    // javascriptで別窓表示(テンプレート側に渡す)
110                    // FIXME XSS対策すること
111                    $file_url = ereg_replace(USER_REALDIR, "", $_POST['select_file']);
112                    $this->tpl_onload = "win02('./file_view.php?file=". $file_url ."', 'user_data', '600', '400');";
113                    $now_dir = $this->lfCheckSelectDir(dirname($_POST['select_file']));
114                }
115            }
116
117            break;
118
119            // ファイルダウンロード
120        case 'download':
121
122            // エラーチェック
123            $arrErr = $this->lfErrorCheck();
124            if (empty($arrErr)) {
125                if(is_dir($_POST['select_file'])) {
126                    // ディレクトリの場合はjavascriptエラー
127                    $arrErr['select_file'] = "※ ディレクトリをダウンロードすることは出来ません。<br/>";
128                } else {
129                    // ファイルダウンロード
130                    $objFileManager->sfDownloadFile($_POST['select_file']);
131                    exit;
132                }
133            }
134            break;
135            // ファイル削除
136        case 'delete':
137            // エラーチェック
138            $arrErr = $this->lfErrorCheck();
139            if (empty($arrErr)) {
140                $objFileManager->sfDeleteDir($_POST['select_file']);
141            }
142            break;
143            // ファイル作成
144        case 'create':
145            // エラーチェック
146            $arrErr = $this->lfCreateErrorCheck();
147            if (empty($arrErr)) {
148                $create_dir = ereg_replace("/$", "", $now_dir);
149                // ファイル作成
150                if(!$objFileManager->sfCreateFile($create_dir."/".$_POST['create_file'], 0755)) {
151                    // 作成エラー
152                    $arrErr['create_file'] = "※ ".$_POST['create_file']."の作成に失敗しました。<br/>";
153                } else {
154                    $this->tpl_onload .= "alert('フォルダを作成しました。');";
155                }
156            }
157            break;
158            // ファイルアップロード
159        case 'upload':
160            // 画像保存処理
161            $ret = $objUpFile->makeTempFile('upload_file', false);
162            if($ret != "") {
163                $arrErr['upload_file'] = $ret;
164            } else {
165                $this->tpl_onload .= "alert('ファイルをアップロードしました。');";
166            }
167            break;
168            // フォルダ移動
169        case 'move':
170            $now_dir = $this->lfCheckSelectDir($_POST['tree_select_file']);
171            break;
172            // 初期表示
173        default :
174            break;
175        }
176        // トップディレクトリか調査
177        $is_top_dir = false;
178        // 末尾の/をとる
179        $top_dir_check = ereg_replace("/$", "", $top_dir);
180        $now_dir_check = ereg_replace("/$", "", $now_dir);
181        if($top_dir_check == $now_dir_check) $is_top_dir = true;
182
183        // 現在の階層より一つ上の階層を取得
184        $parent_dir = $this->lfGetParentDir($now_dir);
185
186        // 現在のディレクトリ配下のファイル一覧を取得
187        $this->arrFileList = $objFileManager->sfGetFileList($now_dir);
188        $this->tpl_is_top_dir = $is_top_dir;
189        $this->tpl_parent_dir = $parent_dir;
190        // TODO JSON で投げて, フロント側で処理した方が良い?
191        $this->tpl_now_dir = "";
192        $arrNowDir = preg_split('/\//', str_replace(HTML_REALDIR, '', $now_dir));
193        for ($i = 0; $i < count($arrNowDir); $i++) {
194            if (!empty($arrNowDir)) {
195                $this->tpl_now_dir .= $arrNowDir[$i];
196                if ($i < count($arrNowDir) - 1) {
197                     // フロント側で &gt; へエスケープするため, ここでは > を使用
198                    $this->tpl_now_dir .= ' > ';
199                }
200            }
201        }
202        $this->tpl_now_file = basename($now_dir);
203        $this->arrErr = isset($arrErr) ? $arrErr : "";
204        $this->arrParam = $_POST;
205
206        // ツリーを表示する divタグid, ツリー配列変数名, 現在ディレクトリ, 選択ツリーhidden名, ツリー状態hidden名, mode hidden名
207        $treeView = "fnTreeView('tree', arrTree, '$now_dir', 'tree_select_file', 'tree_status', 'move');";
208        if (!empty($this->tpl_onload)) {
209            $this->tpl_onload .= $treeView;
210        } else {
211            $this->tpl_onload = $treeView;
212        }
213
214        // ツリー配列作成用 javascript
215        if (!isset($_POST['tree_status'])) $_POST['tree_status'] = "";
216        $arrTree = $objFileManager->sfGetFileTree($top_dir, $_POST['tree_status']);
217        $this->tpl_javascript .= "arrTree = new Array();\n";
218        foreach($arrTree as $arrVal) {
219            $this->tpl_javascript .= "arrTree[".$arrVal['count']."] = new Array(".$arrVal['count'].", '".$arrVal['type']."', '".$arrVal['path']."', ".$arrVal['rank'].",";
220            if ($arrVal['open']) {
221                $this->tpl_javascript .= "true);\n";
222            } else {
223                $this->tpl_javascript .= "false);\n";
224            }
225        }
226    }
227
228    /**
229     * デストラクタ.
230     *
231     * @return void
232     */
233    function destroy() {
234        parent::destroy();
235    }
236
237    /*
238     * 関数名:lfErrorCheck()
239     * 説明 :エラーチェック
240     */
241    function lfErrorCheck() {
242        $objErr = new SC_CheckError($_POST);
243        $objErr->doFunc(array("ファイル", "select_file"), array("SELECT_CHECK"));
244
245        return $objErr->arrErr;
246    }
247
248    /*
249     * 関数名:lfCreateErrorCheck()
250     * 説明 :ファイル作成処理エラーチェック
251     */
252    function lfCreateErrorCheck() {
253        $objErr = new SC_CheckError($_POST);
254        $objErr->doFunc(array("作成ファイル名", "create_file"), array("EXIST_CHECK", "FILE_NAME_CHECK_BY_NOUPLOAD"));
255
256        return $objErr->arrErr;
257    }
258
259    /*
260     * 関数名:lfInitFile()
261     * 説明 :ファイル情報の初期化
262     */
263    function lfInitFile(&$objUpFile) {
264        $objUpFile->addFile("ファイル", 'upload_file', array(), FILE_SIZE, true, 0, 0, false);
265    }
266
267    /*
268     * 関数名:lfCheckSelectDir()
269     * 引数1:ディレクトリ
270     * 説明:選択ディレクトリがUSER_REALDIR以下かチェック
271     */
272    function lfCheckSelectDir($dir) {
273        $top_dir = USER_REALDIR;
274        // USER_REALDIR以下の場合
275            if (preg_match("@^\Q". $top_dir. "\E@", $dir) > 0) {
276            // 相対パスがある場合、USER_REALDIRを返す.
277            if (preg_match("@\Q..\E@", $dir) > 0) {
278                return $top_dir;
279            // 相対パスがない場合、そのままディレクトリパスを返す.
280            } else {
281                return $dir;
282            }
283        // USER_REALDIR以下でない場合、USER_REALDIRを返す.
284        } else {
285            return $top_dir;
286        }
287    }
288
289    /*
290     * 関数名:lfGetParentDir()
291     * 引数1 :ディレクトリ
292     * 説明 :親ディレクトリ取得
293     */
294    function lfGetParentDir($dir) {
295        $dir = ereg_replace("/$", "", $dir);
296        $arrDir = split('/', $dir);
297        array_pop($arrDir);
298        $parent_dir = "";
299        foreach($arrDir as $val) {
300            $parent_dir .= "$val/";
301        }
302        $parent_dir = ereg_replace("/$", "", $parent_dir);
303
304        return $parent_dir;
305    }
306}
307?>
Note: See TracBrowser for help on using the repository browser.