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

Revision 19661, 9.8 KB checked in by nanasess, 13 years ago (diff)

source:branches/camp/camp-2_5-E のマージ

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