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

Revision 21693, 10.0 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 フックポイント名を変更

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