1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2007 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_PATH . "pages/LC_Page.php"); |
---|
26 | require_once(DATA_PATH. "module/Tar.php"); |
---|
27 | require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_FileManager_Ex.php");
|
---|
28 | |
---|
29 | /** |
---|
30 | * テンプレートアップロード のページクラス. |
---|
31 | * |
---|
32 | * @package Page |
---|
33 | * @author LOCKON CO.,LTD. |
---|
34 | * @version $Id: LC_Page_Admin_Design_Up_Down.php 16582 2007-10-29 03:06:29Z nanasess $ |
---|
35 | */ |
---|
36 | class LC_Page_Admin_Design_Up_Down extends LC_Page { |
---|
37 | |
---|
38 | // }}} |
---|
39 | // {{{ functions |
---|
40 | |
---|
41 | /** |
---|
42 | * Page を初期化する. |
---|
43 | * |
---|
44 | * @return void |
---|
45 | */ |
---|
46 | function init() { |
---|
47 | parent::init(); |
---|
48 | $this->tpl_mainpage = 'design/up_down.tpl';
|
---|
49 | $this->tpl_subnavi = 'design/subnavi.tpl';
|
---|
50 | $this->tpl_subno = 'up_down';
|
---|
51 | $this->tpl_mainno = "design";
|
---|
52 | $this->tpl_subtitle = 'アップロード/ダウンロード';
|
---|
53 | $this->arrErr = array();
|
---|
54 | $this->arrForm = array();
|
---|
55 | ini_set("max_execution_time", 300); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * Page のプロセス. |
---|
60 | * |
---|
61 | * @return void |
---|
62 | */ |
---|
63 | function process() {
|
---|
64 | // ログインチェック
|
---|
65 | $objSession = new SC_Session();
|
---|
66 | SC_Utils::sfIsSuccess($objSession);
|
---|
67 | $this->now_template = $this->lfGetNowTemplate();
|
---|
68 |
|
---|
69 | // uniqidをテンプレートへ埋め込み
|
---|
70 | $this->uniqid = $objSession->getUniqId();
|
---|
71 |
|
---|
72 | switch($this->lfGetMode()) {
|
---|
73 |
|
---|
74 | // ダウンロードボタン押下時の処理
|
---|
75 | case 'download':
|
---|
76 | break;
|
---|
77 | // アップロードボタン押下時の処理
|
---|
78 | case 'upload':
|
---|
79 | // 画面遷移の正当性チェック
|
---|
80 | if (!SC_Utils::sfIsValidTransition($objSession)) {
|
---|
81 | SC_Utils::sfDispError('');
|
---|
82 | }
|
---|
83 | // フォームパラメータ初期化
|
---|
84 | $objForm = $this->lfInitUpload();
|
---|
85 | // エラーチェック
|
---|
86 | if ($arrErr = $this->lfValidateUpload($objForm)) {
|
---|
87 | $this->arrErr = $arrErr;
|
---|
88 | $this->arrForm = $objForm->getFormParamList();
|
---|
89 | break;
|
---|
90 | }
|
---|
91 | // アップロードファイル初期化
|
---|
92 | $objUpFile = $this->lfInitUploadFile($objForm);
|
---|
93 | // 一時ファイルへ保存
|
---|
94 | $errMsg = $objUpFile->makeTempFile('template_file', false);
|
---|
95 | // 書き込みエラーチェック
|
---|
96 | if(isset($errMsg)) {
|
---|
97 | $this->arrErr['template_file'] = $errMsg;
|
---|
98 | $this->arrForm = $objForm->getFormParamList();
|
---|
99 | break;
|
---|
100 | }
|
---|
101 | $this->lfAddTemplates($objForm, $objUpFile);
|
---|
102 | $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');";
|
---|
103 | break;
|
---|
104 |
|
---|
105 | // 初回表示
|
---|
106 | default:
|
---|
107 | break;
|
---|
108 | }
|
---|
109 |
|
---|
110 | // 画面の表示
|
---|
111 | $objView = new SC_AdminView();
|
---|
112 | $objView->assignobj($this);
|
---|
113 | $objView->display(MAIN_FRAME); |
---|
114 | } |
---|
115 | |
---|
116 | /** |
---|
117 | * デストラクタ. |
---|
118 | * |
---|
119 | * @return void |
---|
120 | */ |
---|
121 | function destroy() { |
---|
122 | parent::destroy(); |
---|
123 | } |
---|
124 | |
---|
125 | /**
|
---|
126 | * POSTされるmodeパラメータを取得する.
|
---|
127 | *
|
---|
128 | * @param void
|
---|
129 | * @return string modeパラメータ, 無ければnull
|
---|
130 | */
|
---|
131 | function lfGetMode(){
|
---|
132 | if (isset($_POST['mode'])) return $_POST['mode'];
|
---|
133 | }
|
---|
134 | /**
|
---|
135 | * SC_UploadFileクラスの初期化.
|
---|
136 | *
|
---|
137 | * @param object $objForm SC_FormParamのインスタンス
|
---|
138 | * @return object SC_UploadFileのインスタンス
|
---|
139 | */
|
---|
140 | function lfInitUploadFile($objForm) {
|
---|
141 | $pkg_dir = SMARTY_TEMPLATES_DIR . $objForm->getValue('template_code');
|
---|
142 | $objUpFile = new SC_UploadFile(TEMPLATE_TEMP_DIR, $pkg_dir);
|
---|
143 | $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
|
---|
144 |
|
---|
145 | return $objUpFile;
|
---|
146 | }
|
---|
147 | /**
|
---|
148 | * SC_FormParamクラスの初期化.
|
---|
149 | *
|
---|
150 | * @param void
|
---|
151 | * @retrun object SC_FormParamのインスタンス
|
---|
152 | */
|
---|
153 | function lfInitUpload() {
|
---|
154 | $objForm = new SC_FormParam;
|
---|
155 |
|
---|
156 | $objForm->addParam("テンプレートコード", "template_code", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK"));
|
---|
157 | $objForm->addParam("テンプレート名", "template_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
|
---|
158 | $objForm->setParam($_POST);
|
---|
159 |
|
---|
160 | return $objForm;
|
---|
161 | }
|
---|
162 | /**
|
---|
163 | * uploadモードのパラメータ検証を行う.
|
---|
164 | *
|
---|
165 | * @param object $objForm SC_FormParamのインスタンス
|
---|
166 | * @return array エラー情報を格納した連想配列, エラーが無ければ(多分)nullを返す
|
---|
167 | */
|
---|
168 | function lfValidateUpload($objForm) {
|
---|
169 | $arrErr = $objForm->checkError();
|
---|
170 | if (!empty($arrErr)) {
|
---|
171 | return $arrErr;
|
---|
172 | }
|
---|
173 |
|
---|
174 | $arrForm = $objForm->getHashArray();
|
---|
175 |
|
---|
176 | // 同名のフォルダが存在する場合はエラー
|
---|
177 | if(file_exists(USER_TEMPLATE_PATH . $arrForm['template_code'])) {
|
---|
178 | $arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
|
---|
179 | }
|
---|
180 |
|
---|
181 | // 登録不可の文字列チェック
|
---|
182 | $arrIgnoreCode = array(
|
---|
183 | 'admin', 'mobile', 'default'
|
---|
184 | );
|
---|
185 | if(in_array($arrForm['template_code'], $arrIgnoreCode)) {
|
---|
186 | $arrErr['template_code'] = "※ このテンプレートコードは使用できません。<br/>";
|
---|
187 | }
|
---|
188 |
|
---|
189 | // DBにすでに登録されていないかチェック
|
---|
190 | $objQuery = new SC_Query();
|
---|
191 | $ret = $objQuery->count("dtb_templates", "template_code = ?", array($arrForm['template_code']));
|
---|
192 | if(!empty($ret)) {
|
---|
193 | $arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
|
---|
194 | }
|
---|
195 |
|
---|
196 | // ファイルの拡張子チェック(.tar/tar.gzのみ許可)
|
---|
197 | $errFlag = true;
|
---|
198 | $array_ext = explode(".", $_FILES['template_file']['name']);
|
---|
199 | $ext = $array_ext[ count ( $array_ext ) - 1 ];
|
---|
200 | $ext = strtolower($ext);
|
---|
201 | // .tarチェック
|
---|
202 | if ($ext == 'tar') {
|
---|
203 | $errFlag = false;
|
---|
204 | }
|
---|
205 | $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
|
---|
206 | $ext = strtolower($ext);
|
---|
207 | // .tar.gzチェック
|
---|
208 | if ($ext== 'tar.gz') {
|
---|
209 | $errFlag = false;
|
---|
210 | }
|
---|
211 |
|
---|
212 | if($errFlag) {
|
---|
213 | $arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";
|
---|
214 | }
|
---|
215 |
|
---|
216 | return $arrErr;
|
---|
217 | }
|
---|
218 | /**
|
---|
219 | * DBおよびTPL_PKG_PATHにテンプレートパッケージを追加する.
|
---|
220 | *
|
---|
221 | * @param object $objForm SC_FormParamのインスタンス
|
---|
222 | * @param object $objUpFile SC_UploadFileのインスタンス
|
---|
223 | * @return void
|
---|
224 | */
|
---|
225 | function lfAddTemplates($objForm, $objUpFile) {
|
---|
226 | $template_code = $objForm->getValue('template_code');
|
---|
227 | $template_dir = SMARTY_TEMPLATES_DIR . $template_code;
|
---|
228 | $compile_dir = DATA_PATH . "Smarty/templates_c/" . $template_code;
|
---|
229 | // フォルダ作成
|
---|
230 | if(!file_exists($template_dir)) {
|
---|
231 | mkdir($template_dir);
|
---|
232 | }
|
---|
233 | if(!file_exists($compile_dir)) {
|
---|
234 | mkdir($compile_dir);
|
---|
235 | }
|
---|
236 |
|
---|
237 | // 一時フォルダから保存ディレクトリへ移動
|
---|
238 | $objUpFile->moveTempFile();
|
---|
239 |
|
---|
240 | // 解凍
|
---|
241 | SC_Helper_FileManager::unpackFile($template_dir . "/" . $_FILES['template_file']['name']);
|
---|
242 | // ユーザデータの下のファイルをコピーする
|
---|
243 | $from_dir = SMARTY_TEMPLATES_DIR . $template_code . "/_packages/";
|
---|
244 | $to_dir = USER_PATH . "packages/" . $template_code . "/";
|
---|
245 | SC_Utils::sfMakeDir($to_dir);
|
---|
246 | SC_Utils::sfCopyDir($from_dir, $to_dir);
|
---|
247 |
|
---|
248 | // DBにテンプレート情報を保存
|
---|
249 | $this->lfRegisterTemplates($objForm->getHashArray());
|
---|
250 | }
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * dtb_templatesへ入力内容を登録する.
|
---|
254 | *
|
---|
255 | * @param array $arrForm POSTされたパラメータ
|
---|
256 | * @return void
|
---|
257 | */
|
---|
258 | function lfRegisterTemplates($arrForm) {
|
---|
259 | $objQuery = new SC_Query();
|
---|
260 | $sqlval = $arrForm;
|
---|
261 | $sqlval['create_date'] = "now()";
|
---|
262 | $sqlval['update_date'] = "now()";
|
---|
263 | $objQuery->insert('dtb_templates', $sqlval);
|
---|
264 | }
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * デザイン管理で作成されたファイルをupload/temp_template/以下にコピーする
|
---|
268 | *
|
---|
269 | * @param string $to
|
---|
270 | * @return void
|
---|
271 | */
|
---|
272 | function lfCopyUserEdit($to) {
|
---|
273 | $arrDirs = array(
|
---|
274 | 'css',
|
---|
275 | 'include',
|
---|
276 | 'templates'
|
---|
277 | );
|
---|
278 |
|
---|
279 | foreach ($arrDirs as $dir) {
|
---|
280 | $from = USER_PATH . $dir;
|
---|
281 | SC_Utils::sfCopyDir($from, $to, '', true);
|
---|
282 | }
|
---|
283 | }
|
---|
284 | /**
|
---|
285 | * 現在選択しているテンプレートパッケージをupload/temp_template/以下にコピーする
|
---|
286 | *
|
---|
287 | * @param string $to 保存先パス
|
---|
288 | * @return void
|
---|
289 | */
|
---|
290 | function lfCopyTplPackage($to) {
|
---|
291 | $nowTpl = $this->lfGetNowTemplate();
|
---|
292 | if (!$nowTpl) return;
|
---|
293 |
|
---|
294 | $from = TPL_PKG_PATH . $nowTpl . '/';
|
---|
295 | SC_Utils::sfCopyDir($from, $to, '');
|
---|
296 | }
|
---|
297 | /**
|
---|
298 | * 現在適用しているテンプレートパッケージ名を取得する.
|
---|
299 | *
|
---|
300 | * @param void
|
---|
301 | * @return string テンプレートパッケージ名
|
---|
302 | */
|
---|
303 | function lfGetNowTemplate() {
|
---|
304 | $objQuery = new SC_Query();
|
---|
305 | $arrRet = $objQuery->select('top_tpl', 'dtb_baseinfo');
|
---|
306 | if (isset($arrRet[0]['top_tpl'])) {
|
---|
307 | return $arrRet[0]['top_tpl'];
|
---|
308 | }
|
---|
309 | return null;
|
---|
310 | } |
---|
311 | } |
---|
312 | ?> |
---|