1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2012 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 |
---|
25 | require_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 | */ |
---|
34 | class 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 = t('TPL_MAINTITLE_003'); |
---|
51 | $this->tpl_subtitle = t('LC_Page_Admin_Design_CSS_002'); |
---|
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 | $objLayout = new SC_Helper_PageLayout_Ex(); |
---|
74 | |
---|
75 | $objFormParam = new SC_FormParam_Ex(); |
---|
76 | $this->lfInitParam($objFormParam); |
---|
77 | $objFormParam->setParam($_REQUEST); |
---|
78 | $objFormParam->convParam(); |
---|
79 | $this->arrErr = $objFormParam->checkError(); |
---|
80 | $is_error = (!SC_Utils_Ex::isBlank($this->arrErr)); |
---|
81 | |
---|
82 | // CSSファイル名を取得 |
---|
83 | $this->css_name = $objFormParam->getValue('css_name'); |
---|
84 | $this->old_css_name = $objFormParam->getValue('old_css_name', $this->css_name); |
---|
85 | $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); |
---|
86 | |
---|
87 | $css_dir = $objLayout->getTemplatePath($this->device_type_id, true) . 'css/'; |
---|
88 | $css_path = $css_dir . $this->css_name . '.css'; |
---|
89 | |
---|
90 | switch ($this->getMode()) { |
---|
91 | // データ更新処理 |
---|
92 | case 'confirm': |
---|
93 | if (!$is_error) { |
---|
94 | $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr); |
---|
95 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
96 | if ($this->doRegister($css_dir, $this->css_name, $this->old_css_name, $css_path, |
---|
97 | $objFormParam->getValue('css_data'))) { |
---|
98 | $this->tpl_onload = "alert('" . t('ALERT_004') . "');"; |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | break; |
---|
103 | case 'delete': |
---|
104 | if (!$is_error) { |
---|
105 | if ($this->doDelete($css_path)) { |
---|
106 | $arrPram = array( |
---|
107 | 'device_type_id' => $this->device_type_id, |
---|
108 | 'msg' => 'on', |
---|
109 | ); |
---|
110 | |
---|
111 | SC_Response_Ex::reload($arrPram, true); |
---|
112 | } |
---|
113 | } |
---|
114 | break; |
---|
115 | default: |
---|
116 | if (isset($_GET['msg']) && $_GET['msg'] == 'on') { |
---|
117 | // 完了メッセージ |
---|
118 | $this->tpl_onload = "alert('" . t('ALERT_004') . "');"; |
---|
119 | } |
---|
120 | break; |
---|
121 | } |
---|
122 | |
---|
123 | if (!$is_error && $this->checkPath($this->css_name)) { |
---|
124 | // CSSファイルの読み込み |
---|
125 | if (!SC_Utils_Ex::isBlank($this->css_name)) { |
---|
126 | $objFormParam->setValue('css_data', file_get_contents($css_path)); |
---|
127 | } |
---|
128 | // ファイルリストを取得 |
---|
129 | $this->arrCSSList = $this->getCSSList($css_dir); |
---|
130 | } else { |
---|
131 | // 画面にエラー表示しないため, ログ出力 |
---|
132 | GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true)); |
---|
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 | * |
---|
142 | * @return void |
---|
143 | */ |
---|
144 | function destroy() { |
---|
145 | parent::destroy(); |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | * パラメーター情報の初期化 |
---|
150 | * |
---|
151 | * @param object $objFormParam SC_FormParamインスタンス |
---|
152 | * @return void |
---|
153 | */ |
---|
154 | function lfInitParam(&$objFormParam) { |
---|
155 | $objFormParam->addParam(t('PARAM_LABEL_DEVICE_TYPE_ID'), 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
156 | $objFormParam->addParam(t('PARAM_LABEL_CSS_FILE_NAME'), 'css_name', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK')); |
---|
157 | $objFormParam->addParam(t('PARAM_LABEL_CSS_OLD_FILE_NAME'), 'old_css_name', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK')); |
---|
158 | $objFormParam->addParam(t('PARAM_LABEL_CSS_DATA'), 'css_data'); |
---|
159 | |
---|
160 | } |
---|
161 | |
---|
162 | /** |
---|
163 | * 登録を実行する. |
---|
164 | * |
---|
165 | * ファイルの作成に失敗した場合は, エラーメッセージを出力する. |
---|
166 | * |
---|
167 | * @param string $css_dir CSS ディレクトリ |
---|
168 | * @param string $css_name CSSファイル名 |
---|
169 | * @param string $old_css_name 旧CSSファイル名 |
---|
170 | * @param string $css_path CSSファイルの絶対パス |
---|
171 | * @param string $css_data 書き込みを行うデータ |
---|
172 | * @return boolean 登録が成功した場合 true; 失敗した場合 false |
---|
173 | */ |
---|
174 | function doRegister($css_dir, $css_name, $old_css_name, $css_path, $css_data) { |
---|
175 | $objFileManager = new SC_Helper_FileManager_Ex(); |
---|
176 | |
---|
177 | if (!SC_Utils_Ex::isBlank($old_css_name) |
---|
178 | && $old_css_name != $css_name) { |
---|
179 | if (!unlink($css_dir . $old_css_name . '.css')) { |
---|
180 | $this->arrErr['err'] = t('LC_Page_Admin_Design_CSS_003'); |
---|
181 | return false; |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | if (!SC_Helper_FileManager_Ex::sfWriteFile($css_path, $css_data)) { |
---|
186 | $this->arrErr['err'] = t('LC_Page_Admin_Design_CSS_004'); |
---|
187 | return false; |
---|
188 | } |
---|
189 | return true; |
---|
190 | } |
---|
191 | |
---|
192 | /** |
---|
193 | * 削除を実行する. |
---|
194 | * |
---|
195 | * @param string $css_path CSSファイルの絶対パス |
---|
196 | * @return boolean 削除が成功した場合 true; 失敗した場合 false |
---|
197 | */ |
---|
198 | function doDelete($css_path) { |
---|
199 | if (!unlink($css_path)) { |
---|
200 | $this->arrErr['err'] = t('LC_Page_Admin_Design_CSS_005'); |
---|
201 | return false; |
---|
202 | } |
---|
203 | return true; |
---|
204 | } |
---|
205 | |
---|
206 | /** |
---|
207 | * CSSファイルのリストを取得. |
---|
208 | * |
---|
209 | * @param array $css_dir CSSディレクトリ |
---|
210 | * @return array ファイルリスト |
---|
211 | */ |
---|
212 | function getCSSList($css_dir) { |
---|
213 | $objFileManager = new SC_Helper_FileManager_Ex(); |
---|
214 | |
---|
215 | $arrFileList = $objFileManager->sfGetFileList($css_dir); |
---|
216 | foreach ($arrFileList as $val) { |
---|
217 | if (!$val['is_dir']) { |
---|
218 | $arrCSSList[] = array( |
---|
219 | 'file_name' => $val['file_name'], |
---|
220 | 'css_name' => preg_replace('/(.+)\.(.+?)$/','$1',$val['file_name']), |
---|
221 | ); |
---|
222 | } |
---|
223 | } |
---|
224 | return $arrCSSList; |
---|
225 | } |
---|
226 | |
---|
227 | /** |
---|
228 | * エラーチェックを行う. |
---|
229 | * |
---|
230 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
231 | * @return array エラーメッセージの配列 |
---|
232 | */ |
---|
233 | function lfCheckError(&$objFormParam, &$arrErr) { |
---|
234 | $arrParams = $objFormParam->getHashArray(); |
---|
235 | $objErr = new SC_CheckError_Ex($arrParams); |
---|
236 | $objErr->arrErr =& $arrErr; |
---|
237 | $objErr->doFunc(array(t('PARAM_LABEL_CSS_FILE_NAME'), 'css_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK','FILE_NAME_CHECK_BY_NOUPLOAD')); |
---|
238 | |
---|
239 | $device_type_id = $objFormParam->getValue('device_type_id'); |
---|
240 | $css_name = $objFormParam->getValue('css_name'); |
---|
241 | $old_css_name = $objFormParam->getValue('old_css_name', $css_name); |
---|
242 | |
---|
243 | $is_error = false; |
---|
244 | // 重複チェック |
---|
245 | if (!SC_Utils_Ex::isBlank(($objErr->arrErr['css_name']))) { |
---|
246 | $arrCSSList = $this->getCSSList($this->getCSSDir()); |
---|
247 | foreach ($arrCSSList as $val) { |
---|
248 | if ($val['css_name'] == $css_name) { |
---|
249 | if (SC_Utils_Ex::isBlank($old_css_name) |
---|
250 | || $old_css_name != $css_name) { |
---|
251 | $is_error = true; |
---|
252 | } |
---|
253 | } |
---|
254 | } |
---|
255 | if ($is_error) { |
---|
256 | $objErr->arrErr['css_name'] = t('LC_Page_Admin_Design_CSS_006'); |
---|
257 | } |
---|
258 | } |
---|
259 | return $objErr->arrErr; |
---|
260 | } |
---|
261 | |
---|
262 | /** |
---|
263 | * CSSディレクトリを取得する. |
---|
264 | * |
---|
265 | * @param integer $device_type_id 端末種別ID |
---|
266 | * @return string CSSディレクトリ |
---|
267 | */ |
---|
268 | function getCSSDir($device_type_id) { |
---|
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 | function checkPath($str) { |
---|
278 | // 含む場合はfalse |
---|
279 | if (preg_match('|\./|', $str)) { |
---|
280 | return false; |
---|
281 | } |
---|
282 | return true; |
---|
283 | } |
---|
284 | } |
---|