source: trunk/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileManager.php @ 18758

Revision 18758, 9.8 KB checked in by kajiwara, 14 years ago (diff)

EC-CUBE Ver2.4.4 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=223

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