source: branches/feature-module-update/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileManager.php @ 16996

Revision 16996, 9.9 KB checked in by satou, 16 years ago (diff)

#227 『管理画面:コンテンツ管理:ファイル管理』でuser_dataディレクトリ以外のディレクトリが表示されてしまうバグを改修。

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