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

Revision 19802, 13.8 KB checked in by Seasoft, 13 years ago (diff)

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

  • 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; 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_FILE_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_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/template.tpl';
49        $this->tpl_subnavi  = 'design/subnavi.tpl';
50        $this->tpl_subno    = 'template';
51        $this->tpl_mainno   = "design";
52        $this->tpl_subtitle = 'テンプレート設定';
53        $this->arrErr  = array();
54        $this->arrForm = array();
55        $this->tpl_select = TEMPLATE_NAME;
56        ini_set("max_execution_time", 300);
57    }
58
59    /**
60     * Page のプロセス.
61     *
62     * @return void
63     */
64    function process() {
65        $this->action();
66        $this->sendResponse();
67    }
68
69    /**
70     * Page のアクション.
71     *
72     * FIXME ロジックを見直し
73     *
74     * @return void
75     */
76    function action() {
77        // 認証可否の判定
78            $objSession = new SC_Session();
79            SC_Utils::sfIsSuccess($objSession);
80
81            // uniqidをテンプレートへ埋め込み
82            $this->uniqid = $objSession->getUniqId();
83
84            $objView = new SC_AdminView();
85
86            switch($this->lfGetMode()) {
87
88            // 登録ボタン押下時
89            case 'register':
90                // 画面遷移の正当性チェック
91                if (!SC_Utils::sfIsValidTransition($objSession)) {
92                    sfDispError('');
93                }
94                // パラメータ検証
95                $objForm = $this->lfInitRegister();
96                if ($objForm->checkError()) {
97                    SC_Utils_Ex::sfDispError('');
98                }
99
100                $template_code = $objForm->getValue('template_code');
101                $this->tpl_select = $template_code;
102
103                if($template_code == "") {
104                    $template_code = "default";
105                }
106
107                // DBへ使用するテンプレートを登録
108                $this->lfRegisterTemplate($template_code);
109
110                // XXX コンパイルファイルのクリア処理を行う
111                $objView->_smarty->clear_compiled_tpl();
112
113                // common.cssの内容を更新
114                $this->lfChangeCommonCss($template_code);
115               
116                // テンプレートのコピー
117                $this->lfCopyTemplate($template_code);
118               
119                // ブロック位置を更新
120                $this->lfChangeBloc($template_code);
121
122                // 完了メッセージ
123                $this->tpl_onload="alert('登録が完了しました。');";
124                break;
125
126            // 削除ボタン押下時
127            case 'delete':
128                // 画面遷移の正当性チェック
129                if (!SC_Utils::sfIsValidTransition($objSession)) {
130                    SC_Utils::sfDispError('');
131                }
132                // パラメータ検証
133                $objForm = $this->lfInitDelete();
134                if ($objForm->checkError()) {
135                    SC_Utils::sfDispError('');
136                }
137               
138                //現在使用中のテンプレートとデフォルトのテンプレートは削除できないようにする
139                $template_code = $objForm->getValue('template_code_temp');
140                if ($template_code == TEMPLATE_NAME || $template_code == DEFAULT_TEMPLATE_NAME) {
141                    $this->tpl_onload = "alert('選択中のテンプレートは削除出来ません');";
142                    break;
143                }
144                $this->lfDeleteTemplate($template_code);
145                break;
146
147            // downloadボタン押下時
148            case 'download':
149                // 画面遷移の正当性チェック
150                if (!SC_Utils::sfIsValidTransition($objSession)) {
151                    SC_Utils::sfDispError('');
152                }
153                // パラメータ検証
154                $objForm = $this->lfInitDownload();
155                $template_code = $objForm->getValue('template_code_temp');
156                // ユーザデータの下のファイルも保存する。
157                $from_dir = USER_TEMPLATE_PATH . $template_code . "/";
158                $to_dir = SMARTY_TEMPLATES_DIR . $template_code . "/_packages/";
159                SC_Utils::sfMakeDir($to_dir);
160                SC_Utils::sfCopyDir($from_dir, $to_dir);
161                SC_Helper_FileManager::downloadArchiveFiles(SMARTY_TEMPLATES_DIR . $template_code);
162                break;
163
164            // プレビューボタン押下時
165            case 'preview':
166                break;
167
168            default:
169                break;
170            }
171
172            // defaultパラメータのセット
173            $this->templates = $this->lfGetAllTemplates();
174            $this->now_template = TEMPLATE_NAME;
175            $this->device_type_id = $device_type_id;
176    }
177
178    /**
179     * デストラクタ.
180     *
181     * @return void
182     */
183    function destroy() {
184        parent::destroy();
185    }
186
187    function lfGetMode(){
188        if (isset($_POST['mode'])) return $_POST['mode'];
189    }
190
191    function lfInitRegister() {
192        $objForm = new SC_FormParam();
193        $objForm->addParam(
194            'template_code', 'template_code', STEXT_LEN, '',
195            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
196        );
197        $objForm->setParam($_POST);
198
199        return $objForm;
200    }
201
202    function lfInitDelete() {
203        $objForm = new SC_FormParam();
204        $objForm->addParam(
205            'template_code_temp', 'template_code_temp', STEXT_LEN, '',
206            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
207        );
208        $objForm->setParam($_POST);
209
210        return $objForm;
211    }
212
213    function lfInitDownload() {
214        $objForm = new SC_FormParam();
215        $objForm->addParam(
216            'template_code_temp', 'template_code_temp', STEXT_LEN, '',
217            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
218        );
219        $objForm->setParam($_POST);
220
221        return $objForm;
222    }
223
224    /**
225     * 使用するテンプレートをDBへ登録する
226     */
227    function lfRegisterTemplate($template_code) {
228        $masterData = new SC_DB_MasterData_Ex();
229
230        $data = array('TEMPLATE_NAME' => var_export($template_code, TRUE));
231
232        // DBのデータを更新
233        $masterData->updateMasterData('mtb_constants', array(), $data);
234
235        // キャッシュを生成
236        $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks'));
237    }
238
239    /**
240     * common.cssの更新
241     */
242    function lfChangeCommonCss($template_code) {
243        $css_path = USER_PATH . "css/common.css";
244       
245        // ファイル内容取得
246        $css_data = file_get_contents($css_path);
247       
248        // ファイル内容更新
249        $pt = '/(@import url\("\.\.\/packages\/.+\/css\/import\.css"\);)/';
250        $rp = '@import url("../packages/'. $template_code. '/css/import.css");';
251        $css = preg_replace($pt, $rp, $css_data);
252       
253        // ファイル更新
254        $fp = fopen($css_path,"w");
255        fwrite($fp, $css);
256        fclose($fp);
257    }
258   
259    /**
260     * ブロック位置の更新
261     */
262    function lfChangeBloc($template_code) {
263        $objQuery = new SC_Query();
264        $filepath = USER_TEMPLATE_PATH. $template_code. "/sql/update_bloc.sql";
265       
266        // ブロック位置更新SQLファイル有
267        if(file_exists($filepath)) {
268            if($fp = fopen($filepath, "r")) {
269                $sql = fread($fp, filesize($filepath));
270                fclose($fp);
271            }
272            // 改行、タブを1スペースに変換
273            $sql = preg_replace("/[\r\n\t]/", " " ,$sql);
274            $sql_split = split(";", $sql);
275            foreach($sql_split as $key => $val){
276                if (trim($val) != "") {
277                    $objQuery->query($val);
278                }
279            }
280        }
281    }
282
283    /**
284     * テンプレートパッケージの削除
285     */
286    function lfDeleteTemplate($template_code) {
287        // DB更新
288        $objQuery = new SC_Query();
289        $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code));
290        // テンプレート削除
291        $templates_dir = SMARTY_TEMPLATES_DIR. $template_code. "/";
292        SC_Utils_Ex::sfDelFile($templates_dir);
293        // コンパイル削除
294        $templates_c_dir = DATA_FILE_PATH. "Smarty/templates_c/". $template_code. "/";
295        SC_Utils_Ex::sfDelFile($templates_c_dir);
296        // ユーザーデータ削除
297        $user_dir = USER_TEMPLATE_PATH. $template_code. "/";
298        SC_Utils_Ex::sfDelFile($user_dir);
299    }
300
301    function lfGetAllTemplates() {
302        $objQuery = new SC_Query();
303        $arrRet = $objQuery->select('*', 'dtb_templates');
304        if (empty($arrRet)) return array();
305
306        return $arrRet;
307    }
308
309   /*
310     * 関数名:lfCreateTemplate()
311     * 引数1 :ディレクトリパス
312     * 引数2 :作成ファイル名
313     * 説明 :キャンペーンの初期テンプレート作成
314     * 戻り値:無し
315     */
316    function lfCreateTemplate($dir, $file , $cart_flg) {
317        umask(0);
318        $objFileManager = new SC_Helper_FileManager_Ex();
319       
320        // 作成ファイルディレクトリ
321        $create_dir = $dir . $file;
322        $create_active_dir = $create_dir . "/" . CAMPAIGN_TEMPLATE_ACTIVE;
323        $create_end_dir = $create_dir . "/" . CAMPAIGN_TEMPLATE_END;
324        // デフォルトファイルディレクトリ
325        $default_dir = TEMPLATE_DIR . CAMPAIGN_TEMPLATE_DIR;
326        $default_active_dir = $default_dir . "/" . CAMPAIGN_TEMPLATE_ACTIVE;
327        $default_end_dir = $default_dir . "/" . CAMPAIGN_TEMPLATE_END;
328
329        $ret = $objFileManager->sfCreateFile($create_dir, 0755);
330        $ret = $objFileManager->sfCreateFile($create_active_dir, 0755);
331        $ret = $objFileManager->sfCreateFile($create_end_dir, 0755);
332
333        // キャンペーン実行PHPをコピー
334        $ret = $objFileManager->sfCreateFile(CAMPAIGN_PATH . $file);
335        copy(HTML_FILE_PATH . CAMPAIGN_TEMPLATE_DIR . "index.php", CAMPAIGN_PATH . $file . "/index.php");
336        copy(HTML_FILE_PATH . CAMPAIGN_TEMPLATE_DIR . "application.php", CAMPAIGN_PATH . $file . "/application.php");
337        copy(HTML_FILE_PATH . CAMPAIGN_TEMPLATE_DIR . "complete.php", CAMPAIGN_PATH . $file . "/complete.php");
338        copy(HTML_FILE_PATH . CAMPAIGN_TEMPLATE_DIR . "entry.php", CAMPAIGN_PATH . $file . "/entry.php");
339
340        // デフォルトテンプレート作成(キャンペーン中)
341        $header = $this->lfGetFileContents($default_active_dir."header.tpl");
342        SC_Utils_Ex::sfWriteFile($header, $create_active_dir."header.tpl", "w");
343        $contents = $this->lfGetFileContents($default_active_dir."contents.tpl");
344        if(!$cart_flg) {
345            $contents .= "\n" . '<!--{*ログインフォーム*}-->' . "\n";
346            $contents .= $this->lfGetFileContents(CAMPAIGN_BLOC_PATH . "login.tpl");
347            $contents .= '<!--{*会員登録フォーム*}-->'."\n";
348            $contents .= $this->lfGetFileContents(CAMPAIGN_BLOC_PATH . "entry.tpl");
349        }
350        SC_Utils_Ex::sfWriteFile($contents, $create_active_dir."contents.tpl", "w");
351        $footer = $this->lfGetFileContents($default_active_dir."footer.tpl");
352        SC_Utils_Ex::sfWriteFile($footer, $create_active_dir."footer.tpl", "w");
353
354        // サイトフレーム作成
355        $site_frame  = $header."\n";
356        $site_frame .= '<script type="text/javascript" src="<!--{$TPL_DIR}-->js/navi.js"></script>'."\n";
357        $site_frame .= '<script type="text/javascript" src="<!--{$TPL_DIR}-->js/site.js"></script>'."\n";
358        $site_frame .= '<!--{include file=$tpl_mainpage}-->'."\n";
359        $site_frame .= $footer."\n";
360        SC_Utils_Ex::sfWriteFile($site_frame, $create_active_dir."site_frame.tpl", "w");
361
362        /* デフォルトテンプレート作成(キャンペーン終了) */
363        $header = $this->lfGetFileContents($default_end_dir."header.tpl");
364        SC_Utils_Ex::sfWriteFile($header, $create_end_dir."header.tpl", "w");
365        $contents = $this->lfGetFileContents($default_end_dir."contents.tpl");
366        SC_Utils_Ex::sfWriteFile($contents, $create_end_dir."contents.tpl", "w");
367        $footer = $this->lfGetFileContents($default_end_dir."footer.tpl");
368        SC_Utils_Ex::sfWriteFile($footer, $create_end_dir."footer.tpl", "w");
369    }
370   
371    /*
372     * 関数名:lfGetFileContents()
373     * 引数1 :ファイルパス
374     * 説明 :ファイル読込
375     * 戻り値:無し
376     */
377    function lfGetFileContents($read_file) {
378
379        if(file_exists($read_file)) {
380            $contents = file_get_contents($read_file);
381        } else {
382            $contents = "";
383        }
384
385        return $contents;
386    }
387}
388?>
Note: See TracBrowser for help on using the repository browser.