source: branches/version-2_5-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Up_Down.php @ 19807

Revision 19807, 9.9 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある)

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