source: branches/comu-ver2/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php @ 17575

Revision 17575, 9.3 KB checked in by Seasoft, 16 years ago (diff)

merge 17337,17338,17339,17343,17344,17346,17370,17371

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php
Line 
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
25require_once(CLASS_PATH . "pages/LC_Page.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$
35 */
36class LC_Page_Admin_Design_Template extends LC_Page {
37
38    // }}}
39    // {{{ functions
40
41    /** テンプレートデータ種別 */
42    var $arrSubnavi = array(
43                     'title' => array(
44                                1 => 'top',
45                                2 => 'product',
46                                3 => 'detail',
47                                4 => 'mypage'
48                                             ),
49                     'name' =>array(
50                                1 => 'TOPページ',
51                                2 => '商品一覧ページ',
52                                3 => '商品詳細ページ',
53                                4 => 'MYページ'
54                              )
55                     );
56
57    /**
58     * Page を初期化する.
59     *
60     * @return void
61     */
62    function init() {
63        parent::init();
64        $this->tpl_mainpage = 'design/template.tpl';
65        $this->tpl_subnavi  = 'design/subnavi.tpl';
66        $this->tpl_subno    = 'template';
67        $this->tpl_mainno   = "design";
68        $this->tpl_subtitle = 'テンプレート設定';
69        $this->arrErr  = array();
70        $this->arrForm = array();
71        $this->tpl_select = DEFAULT_TEMPLATE_NAME;
72        ini_set("max_execution_time", 300);
73    }
74
75    /**
76     * Page のプロセス.
77     *
78     * @return void
79     */
80    function process() {
81        // 認証可否の判定
82        $objSession = new SC_Session();
83        SC_Utils::sfIsSuccess($objSession);
84
85        // uniqidをテンプレートへ埋め込み
86        $this->uniqid = $objSession->getUniqId();
87
88        $objView = new SC_AdminView();
89
90        switch($this->lfGetMode()) {
91
92        // 登録ボタン押下時
93        case 'register':
94            // 画面遷移の正当性チェック
95            if (!SC_Utils::sfIsValidTransition($objSession)) {
96                sfDispError('');
97            }
98            // パラメータ検証
99            $objForm = $this->lfInitRegister();
100            if ($objForm->checkError()) {
101                SC_Utils_Ex::sfDispError('');
102            }
103
104            $template_code = $objForm->getValue('template_code');
105            $this->tpl_select = $template_code;
106
107            if($template_code == "") {
108                $template_code = "default";
109            }
110
111            // DBへ使用するテンプレートを登録
112            $this->lfRegisterTemplate($template_code);
113
114            // XXX コンパイルファイルのクリア処理を行う
115            $objView->_smarty->clear_compiled_tpl();
116
117            // common.cssの内容を更新
118            $this->lfChangeCommonCss($template_code);
119
120            // ブロック位置を更新
121            $this->lfChangeBloc($template_code);
122
123            // 完了メッセージ
124            $this->tpl_onload="alert('登録が完了しました。');";
125            break;
126
127        // 削除ボタン押下時
128        case 'delete':
129            // 画面遷移の正当性チェック
130            if (!SC_Utils::sfIsValidTransition($objSession)) {
131                SC_Utils::sfDispError('');
132            }
133            // パラメータ検証
134            $objForm = $this->lfInitDelete();
135            if ($objForm->checkError()) {
136                SC_Utils::sfDispError('');
137            }
138
139            $template_code = $objForm->getValue('template_code_temp');
140            if ($template_code == DEFAULT_TEMPLATE_NAME) {
141                $this->tpl_onload = "alert('選択中のテンプレートは削除出来ません');";
142                break;
143            }
144
145            $this->lfDeleteTemplate($template_code);
146            break;
147
148        // downloadボタン押下時
149        case 'download':
150            // 画面遷移の正当性チェック
151            if (!SC_Utils::sfIsValidTransition($objSession)) {
152                SC_Utils::sfDispError('');
153            }
154            // パラメータ検証
155            $objForm = $this->lfInitDownload();
156            $template_code = $objForm->getValue('template_code_temp');
157            // ユーザデータの下のファイルも保存する。
158            $from_dir = USER_TEMPLATE_PATH . $template_code . "/";
159            $to_dir = SMARTY_TEMPLATES_DIR . $template_code . "/_packages/";
160            SC_Utils::sfMakeDir($to_dir);
161            SC_Utils::sfCopyDir($from_dir, $to_dir);
162            SC_Helper_FileManager::downloadArchiveFiles(SMARTY_TEMPLATES_DIR . $template_code);
163            break;
164
165        // プレビューボタン押下時
166        case 'preview':
167            break;
168
169        default:
170            break;
171        }
172
173        // defaultパラメータのセット
174        $this->templates = $this->lfGetAllTemplates();
175        $this->now_template = DEFAULT_TEMPLATE_NAME;
176
177        // 画面の表示
178        $objView->assignobj($this);
179        $objView->display(MAIN_FRAME);
180    }
181
182    /**
183     * デストラクタ.
184     *
185     * @return void
186     */
187    function destroy() {
188        parent::destroy();
189    }
190
191    function lfGetMode(){
192        if (isset($_POST['mode'])) return $_POST['mode'];
193    }
194
195    function lfInitRegister() {
196        $objForm = new SC_FormParam();
197        $objForm->addParam(
198            'template_code', 'template_code', STEXT_LEN, '',
199            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
200        );
201        $objForm->setParam($_POST);
202
203        return $objForm;
204    }
205
206    function lfInitDelete() {
207        $objForm = new SC_FormParam();
208        $objForm->addParam(
209            'template_code_temp', 'template_code_temp', STEXT_LEN, '',
210            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
211        );
212        $objForm->setParam($_POST);
213
214        return $objForm;
215    }
216
217    function lfInitDownload() {
218        $objForm = new SC_FormParam();
219        $objForm->addParam(
220            'template_code_temp', 'template_code_temp', STEXT_LEN, '',
221            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
222        );
223        $objForm->setParam($_POST);
224
225        return $objForm;
226    }
227
228    /**
229     * 使用するテンプレートをDBへ登録する
230     */
231    function lfRegisterTemplate($template_code) {
232        $objQuery = new SC_Query();
233        $sqlval['name'] = "\"" . $template_code . "\"";
234        $objQuery->update("mtb_constants", $sqlval, "id = ?", array('DEFAULT_TEMPLATE_NAME'));
235        // キャッシュを生成
236        $masterData = new SC_DB_MasterData_Ex();
237        // 更新したデータを取得
238        $mtb_constants = $masterData->getDBMasterData("mtb_constants");
239        $masterData->clearCache("mtb_constants");
240        $masterData->createCache("mtb_constants", $mtb_constants, true,
241                                 array("id", "remarks", "rank"));
242    }
243
244    /**
245     * common.cssの更新
246     */
247    function lfChangeCommonCss($template_code) {
248        $css_path = USER_PATH . "css/common.css";
249       
250        // ファイル内容取得
251        $css_data = file_get_contents($css_path);
252       
253        // ファイル内容更新
254        $pt = '/(@import url\("\.\.\/packages\/.+\/css\/import\.css"\);)/';
255        $rp = '@import url("../packages/'. $template_code. '/css/import.css");';
256        $css = preg_replace($pt, $rp, $css_data);
257       
258        // ファイル更新
259        $fp = fopen($css_path,"w");
260        fwrite($fp, $css);
261        fclose($fp);
262    }
263   
264    /**
265     * ブロック位置の更新
266     */
267    function lfChangeBloc($template_code) {
268        $objQuery = new SC_Query();
269        $filepath = USER_TEMPLATE_PATH. $template_code. "/sql/update_bloc.sql";
270       
271        // ブロック位置更新SQLファイル有
272        if(file_exists($filepath)) {
273            if($fp = fopen($filepath, "r")) {
274                $sql = fread($fp, filesize($filepath));
275                fclose($fp);
276            }
277            // 改行、タブを1スペースに変換
278            $sql = preg_replace("/[\r\n\t]/", " " ,$sql);
279            $sql_split = split(";", $sql);
280            foreach($sql_split as $key => $val){
281                if (trim($val) != "") {
282                    $objQuery->query($val);
283                }
284            }
285        }
286    }
287
288    /**
289     * テンプレートパッケージの削除
290     */
291    function lfDeleteTemplate($template_code) {
292        // DB更新
293        $objQuery = new SC_Query();
294        $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code));
295        // テンプレート削除
296        $templates_dir = SMARTY_TEMPLATES_DIR. $template_code. "/";
297        SC_Utils_Ex::sfDelFile($templates_dir);
298        // コンパイル削除
299        $templates_c_dir = DATA_PATH. "Smarty/templates_c/". $template_code. "/";
300        SC_Utils_Ex::sfDelFile($templates_c_dir);
301        // ユーザーデータ削除
302        $user_dir = USER_TEMPLATE_PATH. $template_code. "/";
303        SC_Utils_Ex::sfDelFile($user_dir);
304    }
305
306    function lfGetAllTemplates() {
307        $objQuery = new SC_Query();
308        $arrRet = $objQuery->select('*', 'dtb_templates');
309        if (empty($arrRet)) return array();
310
311        return $arrRet;
312    }
313}
314?>
Note: See TracBrowser for help on using the repository browser.