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

Revision 22567, 9.7 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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