source: branches/version-2_13-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_FileView.php @ 23605

Revision 23605, 4.0 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • 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-2014 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
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * ファイル表示 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Contents_FileView extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43    }
44
45    /**
46     * Page のプロセス.
47     *
48     * @return void
49     */
50    public function process()
51    {
52        $this->action();
53        $this->sendResponse();
54    }
55
56    /**
57     * Page のアクション.
58     *
59     * @return void
60     */
61    public function action()
62    {
63        switch ($this->getMode()) {
64            default:
65                // フォーム操作クラス
66                $objFormParam = new SC_FormParam_Ex();
67                // パラメーター情報の初期化
68                $this->lfInitParam($objFormParam);
69                $objFormParam->setParam($_GET);
70                $objFormParam->convParam();
71
72                // 表示するファイルにエラーチェックを行う
73                if ($this->checkErrorDispFile($objFormParam)) {
74                    $this->execFileView($objFormParam);
75                } else {
76                    SC_Utils_Ex::sfDispError('');
77                }
78
79                SC_Response_Ex::actionExit();
80                break;
81        }
82    }
83
84    /**
85     * 初期化を行う.
86     *
87     * @param  SC_FormParam $objFormParam SC_FormParamインスタンス
88     * @return void
89     */
90    public function lfInitParam(&$objFormParam)
91    {
92        $objFormParam->addParam('ファイル名', 'file', MTEXT_LEN, 'a', array('EXIST_CHECK'));
93    }
94
95    /**
96     * 表示するファイルにエラーチェックを行う
97     *
98     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
99     * @return boolean       $file_check_flg エラーチェックの結果
100     */
101    public function checkErrorDispFile($objFormParam)
102    {
103        $file_check_flg = false;
104        // FIXME パスのチェック関数が必要
105        $file = $objFormParam->getValue('file');
106        $path_exists = SC_Utils::checkFileExistsWithInBasePath($file, USER_REALDIR);
107        if ($path_exists) {
108            $file_check_flg = true;
109        }
110        return $file_check_flg;
111    }
112
113    /**
114     * ファイル内容を表示する
115     *
116     * @return void
117     */
118    public function execFileView($objFormParam)
119    {
120        $file = $objFormParam->getValue('file');
121
122        // ソースとして表示するファイルを定義(直接実行しないファイル)
123        $arrViewFile = array(
124            'html',
125            'htm',
126            'tpl',
127            'php',
128            'css',
129            'js',
130        );
131
132        $extension = pathinfo($file, PATHINFO_EXTENSION);
133
134        if (in_array($extension, $arrViewFile)) {
135            $objFileManager = new SC_Helper_FileManager_Ex();
136            // ファイルを読み込んで表示
137            header("Content-type: text/plain\n\n");
138            echo $objFileManager->sfReadFile(USER_REALDIR . $file);
139        } else {
140            SC_Response_Ex::sendRedirect(USER_URL . $file);
141        }
142    }
143}
Note: See TracBrowser for help on using the repository browser.