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

Revision 19803, 10.0 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある)

  • 一斉置換前の現状記録のためのコミット

#628(未使用処理・定義などの削除)

  • 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_FILE_PATH . "pages/admin/LC_Page_Admin.php");
26require_once(CLASS_EX_FILE_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_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_FILE_PATH;
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        case 'view':
101            // エラーチェック
102            $arrErr = $this->lfErrorCheck();
103
104            if (empty($arrErr)) {
105                // 選択されたファイルがディレクトリなら移動
106                if(is_dir($_POST['select_file'])) {
107                    ///$now_dir = $_POST['select_file'];
108                    // ツリー遷移用のjavascriptを埋め込む
109                    $arrErr['select_file'] = "※ ディレクトリを表示することは出来ません。<br/>";
110
111                } else {
112                    // javascriptで別窓表示(テンプレート側に渡す)
113                    // FIXME XSS対策すること
114                    $file_url = ereg_replace(USER_FILE_PATH, "", $_POST['select_file']);
115                    $this->tpl_onload = "win02('./file_view.php?file=". $file_url ."', 'user_data', '600', '400');";
116                }
117            }
118            break;
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        $this->tpl_now_dir = $now_dir;
191        $this->tpl_now_file = basename($now_dir);
192        $this->arrErr = isset($arrErr) ? $arrErr : "";
193        $this->arrParam = $_POST;
194
195        // ツリーを表示する divタグid, ツリー配列変数名, 現在ディレクトリ, 選択ツリーhidden名, ツリー状態hidden名, mode hidden名
196        $treeView = "fnTreeView('tree', arrTree, '$now_dir', 'tree_select_file', 'tree_status', 'move');";
197        if (!empty($this->tpl_onload)) {
198            $this->tpl_onload .= $treeView;
199        } else {
200            $this->tpl_onload = $treeView;
201        }
202
203        // ツリー配列作成用 javascript
204        if (!isset($_POST['tree_status'])) $_POST['tree_status'] = "";
205        $arrTree = $objFileManager->sfGetFileTree($top_dir, $_POST['tree_status']);
206        $this->tpl_javascript .= "arrTree = new Array();\n";
207        foreach($arrTree as $arrVal) {
208            $this->tpl_javascript .= "arrTree[".$arrVal['count']."] = new Array(".$arrVal['count'].", '".$arrVal['type']."', '".$arrVal['path']."', ".$arrVal['rank'].",";
209            if ($arrVal['open']) {
210                $this->tpl_javascript .= "true);\n";
211            } else {
212                $this->tpl_javascript .= "false);\n";
213            }
214        }
215    }
216
217    /**
218     * デストラクタ.
219     *
220     * @return void
221     */
222    function destroy() {
223        parent::destroy();
224    }
225
226    /*
227     * 関数名:lfErrorCheck()
228     * 説明 :エラーチェック
229     */
230    function lfErrorCheck() {
231        $objErr = new SC_CheckError($_POST);
232        $objErr->doFunc(array("ファイル", "select_file"), array("SELECT_CHECK"));
233
234        return $objErr->arrErr;
235    }
236
237    /*
238     * 関数名:lfCreateErrorCheck()
239     * 説明 :ファイル作成処理エラーチェック
240     */
241    function lfCreateErrorCheck() {
242        $objErr = new SC_CheckError($_POST);
243        $objErr->doFunc(array("作成ファイル名", "create_file"), array("EXIST_CHECK", "FILE_NAME_CHECK_BY_NOUPLOAD"));
244
245        return $objErr->arrErr;
246    }
247
248    /*
249     * 関数名:lfInitFile()
250     * 説明 :ファイル情報の初期化
251     */
252    function lfInitFile(&$objUpFile) {
253        $objUpFile->addFile("ファイル", 'upload_file', array(), FILE_SIZE, true, 0, 0, false);
254    }
255
256    /*
257     * 関数名:lfCheckSelectDir()
258     * 引数1:ディレクトリ
259     * 説明:選択ディレクトリがUSER_FILE_PATH以下かチェック
260     */
261    function lfCheckSelectDir($dir) {
262        $top_dir = USER_FILE_PATH;
263        // USER_FILE_PATH以下の場合
264            if (preg_match("@^\Q". $top_dir. "\E@", $dir) > 0) {
265            // 相対パスがある場合、USER_FILE_PATHを返す.
266            if (preg_match("@\Q..\E@", $dir) > 0) {
267                return $top_dir;
268            // 相対パスがない場合、そのままディレクトリパスを返す.
269            } else {
270                return $dir;
271            }
272        // USER_FILE_PATH以下でない場合、USER_FILE_PATHを返す.
273        } else {
274            return $top_dir;
275        }
276    }
277
278    /*
279     * 関数名:lfGetParentDir()
280     * 引数1 :ディレクトリ
281     * 説明 :親ディレクトリ取得
282     */
283    function lfGetParentDir($dir) {
284        $dir = ereg_replace("/$", "", $dir);
285        $arrDir = split('/', $dir);
286        array_pop($arrDir);
287        $parent_dir = "";
288        foreach($arrDir as $val) {
289            $parent_dir .= "$val/";
290        }
291        $parent_dir = ereg_replace("/$", "", $parent_dir);
292
293        return $parent_dir;
294    }
295}
296?>
Note: See TracBrowser for help on using the repository browser.