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

Revision 23605, 9.6 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 * CSS設定 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Design_CSS extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'design/css.tpl';
44        $this->area_row = 30;
45        $this->tpl_subno = 'css';
46        $this->tpl_mainno = 'design';
47        $this->tpl_maintitle = 'デザイン管理';
48        $this->tpl_subtitle = 'CSS設定';
49        $masterData = new SC_DB_MasterData_Ex();
50        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    public function process()
59    {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    public function action()
70    {
71        $objLayout = new SC_Helper_PageLayout_Ex();
72
73        $objFormParam = new SC_FormParam_Ex();
74        $this->lfInitParam($objFormParam);
75        $objFormParam->setParam($_REQUEST);
76        $objFormParam->convParam();
77        $this->arrErr = $objFormParam->checkError();
78        $is_error = !SC_Utils_Ex::isBlank($this->arrErr);
79
80        // CSSファイル名を取得
81        $this->css_name = $objFormParam->getValue('css_name');
82        $this->old_css_name = $objFormParam->getValue('old_css_name', $this->css_name);
83        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
84
85        $css_dir = $objLayout->getTemplatePath($this->device_type_id, true) . 'css/';
86        $css_path = $css_dir . $this->css_name . '.css';
87
88        switch ($this->getMode()) {
89            // データ更新処理
90            case 'confirm':
91                if (!$is_error) {
92                    $this->arrErr = array_merge($this->arrErr, $this->lfCheckError($objFormParam, $this->arrErr));
93                    if (SC_Utils_Ex::isBlank($this->arrErr)) {
94                        if ($this->doRegister($css_dir, $this->css_name, $this->old_css_name, $css_path,
95                                              $objFormParam->getValue('css_data'))) {
96                            $this->tpl_onload = "alert('登録が完了しました。');";
97                        }
98                    }
99                }
100                break;
101            case 'delete':
102                if (!$is_error) {
103                    if ($this->doDelete($css_path)) {
104                        $arrPram = array(
105                            'device_type_id' => $this->device_type_id,
106                            'msg' => 'on',
107                        );
108
109                        SC_Response_Ex::reload($arrPram, true);
110                    }
111                }
112                break;
113            default:
114                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
115                    // 完了メッセージ
116                    $this->tpl_onload = "alert('登録が完了しました。');";
117                }
118                break;
119        }
120
121        if (SC_Utils_Ex::isBlank($this->arrErr) && $this->checkPath($this->css_name)) {
122            // CSSファイルの読み込み
123            if (!SC_Utils_Ex::isBlank($this->css_name)) {
124                $objFormParam->setValue('css_data', file_get_contents($css_path));
125            }
126        } else {
127            // 画面にエラー表示しないため, ログ出力
128            GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
129        }
130
131        // ファイルリストを取得
132        $this->arrCSSList = $this->getCSSList($css_dir);
133
134        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
135        $this->arrForm = $objFormParam->getFormParamList();
136    }
137
138    /**
139     * パラメーター情報の初期化
140     *
141     * @param  SC_FormParam_Ex $objFormParam SC_FormParamインスタンス
142     * @return void
143     */
144    public function lfInitParam(&$objFormParam)
145    {
146        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
147        $objFormParam->addParam('CSSファイル名', 'css_name', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK'));
148        $objFormParam->addParam('旧CSSファイル名', 'old_css_name', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK'));
149        $objFormParam->addParam('CSSデータ', 'css_data');
150    }
151
152    /**
153     * 登録を実行する.
154     *
155     * ファイルの作成に失敗した場合は, エラーメッセージを出力する.
156     *
157     * @param  string  $css_dir      CSS ディレクトリ
158     * @param  string  $css_name     CSSファイル名
159     * @param  string  $old_css_name 旧CSSファイル名
160     * @param  string  $css_path     CSSファイルの絶対パス
161     * @param  string  $css_data     書き込みを行うデータ
162     * @return boolean 登録が成功した場合 true; 失敗した場合 false
163     */
164    public function doRegister($css_dir, $css_name, $old_css_name, $css_path, $css_data)
165    {
166        if (!SC_Utils_Ex::isBlank($old_css_name)
167            && $old_css_name != $css_name) {
168            if (!unlink($css_dir . $old_css_name . '.css')) {
169                $this->arrErr['err'] = '※ 旧ファイルの削除に失敗しました<br />';
170
171                return false;
172            }
173        }
174
175        if (!SC_Helper_FileManager_Ex::sfWriteFile($css_path, $css_data)) {
176            $this->arrErr['err'] = '※ CSSの書き込みに失敗しました<br />';
177
178            return false;
179        }
180
181        return true;
182    }
183
184    /**
185     * 削除を実行する.
186     *
187     * @param  string  $css_path CSSファイルの絶対パス
188     * @return boolean 削除が成功した場合 true; 失敗した場合 false
189     */
190    public function doDelete($css_path)
191    {
192        if (!unlink($css_path)) {
193            $this->arrErr['err'] = '※ CSSの削除に失敗しました<br />';
194
195            return false;
196        }
197
198        return true;
199    }
200
201    /**
202     * CSSファイルのリストを取得.
203     *
204     * @param  string $css_dir CSSディレクトリ
205     * @return array ファイルリスト
206     */
207    public function getCSSList($css_dir)
208    {
209        $objFileManager = new SC_Helper_FileManager_Ex();
210
211        $arrFileList = $objFileManager->sfGetFileList($css_dir);
212        foreach ($arrFileList as $val) {
213            if (!$val['is_dir']) {
214                $arrCSSList[] = array(
215                    'file_name' => $val['file_name'],
216                    'css_name'  => preg_replace('/(.+)\.(.+?)$/', '$1', $val['file_name']),
217                );
218            }
219        }
220
221        return $arrCSSList;
222    }
223
224    /**
225     * エラーチェックを行う.
226     *
227     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
228     * @return array        エラーメッセージの配列
229     */
230    public function lfCheckError(&$objFormParam, &$arrErr)
231    {
232        $arrParams = $objFormParam->getHashArray();
233        $objErr = new SC_CheckError_Ex($arrParams);
234        $objErr->arrErr =& $arrErr;
235        $objErr->doFunc(array('CSSファイル名', 'css_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'FILE_NAME_CHECK_BY_NOUPLOAD'));
236
237        $css_name = $objFormParam->getValue('css_name');
238        $old_css_name = $objFormParam->getValue('old_css_name');
239        $device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
240
241        $is_error = false;
242        // 重複チェック
243        if (SC_Utils_Ex::isBlank($objErr->arrErr['css_name'])) {
244            $arrCSSList = $this->getCSSList($this->getCSSDir($device_type_id));
245            foreach ($arrCSSList as $val) {
246                if ($val['css_name'] == $css_name) {
247                    if (SC_Utils_Ex::isBlank($old_css_name)
248                        || $old_css_name != $css_name) {
249                        $is_error = true;
250                    }
251                }
252            }
253            if ($is_error) {
254                $objErr->arrErr['css_name'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。<br />';
255            }
256        }
257
258        return $objErr->arrErr;
259    }
260
261    /**
262     * CSSディレクトリを取得する.
263     *
264     * @param  integer $device_type_id 端末種別ID
265     * @return string  CSSディレクトリ
266     */
267    public function getCSSDir($device_type_id)
268    {
269        return SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id, true) . 'css/';
270    }
271
272    /**
273     * 文字列に[./]表記がないかをチェックします
274     * @param  string  $str
275     * @return boolean
276     */
277    public function checkPath($str)
278    {
279        // 含む場合はfalse
280        if (preg_match('|\./|', $str)) {
281            return false;
282        }
283
284        return true;
285    }
286}
Note: See TracBrowser for help on using the repository browser.