source: branches/version-2_12-multilang/data/class/pages/admin/design/LC_Page_Admin_Design_MainEdit.php @ 22100

Revision 22100, 14.5 KB checked in by pineray, 11 years ago (diff)

#163 (テキスト出力多言語対応)

グローバル化に伴い、不要となった SC_I18n を削除.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
RevLine 
[15682]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[21867]5 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
[15682]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15682]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[15682]26
27/**
28 * メイン編集 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[20345]34class LC_Page_Admin_Design_MainEdit extends LC_Page_Admin_Ex {
[15682]35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
[16565]46        $this->tpl_mainpage = 'design/main_edit.tpl';
47        $this->text_row     = 13;
[21481]48        $this->tpl_subno = 'main_edit';
[20538]49        $this->tpl_mainno = 'design';
[22100]50        $this->tpl_maintitle = t('TPL_MAINTITLE_003');
51        $this->tpl_subtitle = t('LC_Page_Admin_Design_MainEdit_002');
[20560]52        $masterData = new SC_DB_MasterData_Ex();
53        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
[15682]54    }
55
56    /**
57     * Page のプロセス.
58     *
59     * @return void
60     */
61    function process() {
[19661]62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
71    function action() {
[21591]72
[20847]73        $objLayout = new SC_Helper_PageLayout_Ex();
74        $objFormParam = new SC_FormParam_Ex();
75        $this->lfInitParam($objFormParam);
76        $objFormParam->setParam($_REQUEST);
77        $objFormParam->convParam();
78        $this->arrErr = $objFormParam->checkError();
79        $is_error = (!SC_Utils_Ex::isBlank($this->arrErr));
[15682]80
[20847]81        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
82        $this->page_id = $objFormParam->getValue('page_id');
[15682]83
[20041]84        switch ($this->getMode()) {
[21526]85            // 削除
86            case 'delete':
87                if (!$is_error) {
88                    if ($objLayout->isEditablePage($this->device_type_id, $this->page_id)) {
89                        $objLayout->lfDelPageData($this->page_id, $this->device_type_id);
[21591]90
[21481]91                        SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id,
92                                                     'msg' => 'on'), true);
[21743]93                        SC_Response_Ex::actionExit();
[20847]94                    }
95                }
[21526]96                break;
[20857]97
[21526]98            // 登録/編集
99            case 'confirm':
100                if (!$is_error) {
101                    $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr);
102                    if (SC_Utils_Ex::isBlank($this->arrErr)) {
103                        $result = $this->doRegister($objFormParam, $objLayout);
104                        if ($result !== false) {
[21592]105
[21526]106                            SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id,
107                                                         'page_id' => $result,
108                                                         'msg' => 'on'), true);
[21743]109                        SC_Response_Ex::actionExit();
[21526]110                        }
111                    }
112                }
113                break;
114
115            default:
116                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
[22100]117                    $this->tpl_onload = "alert('" . t('ALERT_004') . "');";
[21526]118                }
119                break;
[18344]120        }
[20847]121
122        if (!$is_error) {
123            $this->arrPageList = $objLayout->getPageProperties($this->device_type_id, null);
124            // page_id が指定されている場合にはテンプレートデータの取得
125            if (!SC_Utils_Ex::isBlank($this->page_id)) {
126                $arrPageData = $this->getTplMainpage($this->device_type_id, $this->page_id, $objLayout);
127                $objFormParam->setParam($arrPageData);
128            }
129        } else {
130            // 画面にエラー表示しないため, ログ出力
131            GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
132        }
[20911]133        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
[20847]134        $this->arrForm = $objFormParam->getFormParamList();
[21591]135
[18344]136    }
[15682]137
[18344]138    /**
139     * デストラクタ.
140     *
141     * @return void
142     */
143    function destroy() {
144        parent::destroy();
145    }
[15682]146
[18344]147    /**
[20970]148     * パラメーター情報の初期化
[20847]149     *
150     * XXX URL のフィールドは, 実際は filename なので注意
151     *
152     * @param object $objFormParam SC_FormParamインスタンス
153     * @return void
154     */
155    function lfInitParam(&$objFormParam) {
[22100]156        $objFormParam->addParam(t('PARAM_LABEL_PAGE_ID'), 'page_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
157        $objFormParam->addParam(t('PARAM_LABEL_DEVICE_TYPE_ID'), 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
158        $objFormParam->addParam(t('PARAM_LABEL_THE_NAME'), 'page_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
159        $objFormParam->addParam(t('PARAM_LABEL_URL'), 'filename', STEXT_LEN, 'a', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
160        $objFormParam->addParam(t('PARAM_LABEL_HEADER_CHK'), 'header_chk', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
161        $objFormParam->addParam(t('PARAM_LABEL_FOOTER_CHK'), 'footer_chk', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
162        $objFormParam->addParam(t('PARAM_LABEL_EDIT_FLG'), 'edit_flg', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
163        $objFormParam->addParam(t('PARAM_LABEL_TPL_DATA'), 'tpl_data');
[21527]164    }
[20847]165
166    /**
[18344]167     * ページデータを取得する.
168     *
[20847]169     * @param integer $device_type_id 端末種別ID
[18344]170     * @param integer $page_id ページID
[20847]171     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
172     * @return array ページデータの配列
[18344]173     */
[21479]174    function getTplMainpage($device_type_id, $page_id, &$objLayout) {
[20847]175        $arrPageData = $objLayout->getPageProperties($device_type_id, $page_id);
[15682]176
[20847]177        $templatePath = $objLayout->getTemplatePath($device_type_id);
[21514]178        $filename = $templatePath . $arrPageData[0]['filename'] . '.tpl';
[20847]179        if (file_exists($filename)) {
180            $arrPageData[0]['tpl_data'] = file_get_contents($filename);
[18344]181        }
[20847]182        // ファイル名を画面表示用に加工しておく
[20055]183        $arrPageData[0]['filename'] = preg_replace('|^' . preg_quote(USER_DIR) . '|', '', $arrPageData[0]['filename']);
[19722]184        return $arrPageData[0];
[18344]185    }
[15682]186
[18344]187    /**
[20847]188     * 登録を実行する.
[15682]189     *
[20847]190     * ファイルの作成に失敗した場合は, エラーメッセージを出力し,
191     * データベースをロールバックする.
192     *
193     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
194     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
195     * @return integer|boolean 登録が成功した場合, 登録したページID;
196     *                         失敗した場合 false
[15682]197     */
[20857]198    function doRegister(&$objFormParam, &$objLayout) {
[20847]199        $filename = $objFormParam->getValue('filename');
200        $arrParams['device_type_id'] = $objFormParam->getValue('device_type_id');
201        $arrParams['page_id'] = $objFormParam->getValue('page_id');
202        $arrParams['header_chk'] = intval($objFormParam->getValue('header_chk')) === 1 ? 1 : 2;
203        $arrParams['footer_chk'] = intval($objFormParam->getValue('footer_chk')) === 1 ? 1 : 2;
204        $arrParams['tpl_data'] = $objFormParam->getValue('tpl_data');
205        $arrParams['page_name'] = $objFormParam->getValue('page_name');
206        $arrParams['url'] = USER_DIR . $filename . '.php';
207        $arrParams['filename'] = USER_DIR . $filename;
[18344]208
[20847]209        $objQuery =& SC_Query_Ex::getSingletonInstance();
210        $objQuery->begin();
[18344]211
[20847]212        $page_id = $this->registerPage($arrParams, $objLayout);
[19804]213
[20847]214        /*
215         * 新規登録時
216         * or 編集可能な既存ページ編集時かつ, PHP ファイルが存在しない場合に,
217         * PHP ファイルを作成する.
218         */
219        if (SC_Utils_Ex::isBlank($arrParams['page_id'])
220            || $objLayout->isEditablePage($arrParams['device_type_id'], $arrParams['page_id'])) {
221            if (!$this->createPHPFile($filename)) {
[22100]222                $this->arrErr['err'] = t('LC_Page_Admin_Design_MainEdit_003');
[20847]223                $objQuery->rollback();
224                return false;
[18344]225            }
[20847]226            // 新規登録時のみ $page_id を代入
227            $arrParams['page_id'] = $page_id;
228        }
[18344]229
[20847]230        if ($objLayout->isEditablePage($arrParams['device_type_id'], $page_id)) {
231            $tpl_path = $objLayout->getTemplatePath($arrParams['device_type_id']) . $arrParams['filename'] . '.tpl';
[18344]232        } else {
[20847]233            $tpl_path = $objLayout->getTemplatePath($arrParams['device_type_id']) . $filename . '.tpl';
[18344]234        }
[20847]235
236        if (!SC_Helper_FileManager_Ex::sfWriteFile($tpl_path, $arrParams['tpl_data'])) {
[22100]237            $this->arrErr['err'] = t('LC_Page_Admin_Design_MainEdit_004');
[20847]238            $objQuery->rollback();
239            return false;
240        }
241
242        $objQuery->commit();
243        return $arrParams['page_id'];
[15682]244    }
245
246    /**
[20847]247     * 入力内容をデータベースに登録する.
[15682]248     *
[20970]249     * @param array $arrParams フォームパラメーターの配列
[20847]250     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
251     * @return integer ページID
[15682]252     */
[20847]253    function registerPage($arrParams, &$objLayout) {
254        $objQuery =& SC_Query_Ex::getSingletonInstance();
[15682]255
[20847]256        // ページIDが空の場合は新規登録
257        $is_new = SC_Utils_Ex::isBlank($arrParams['page_id']);
258        // 既存ページの存在チェック
259        if (!$is_new) {
260            $arrExists = $objLayout->getPageProperties($arrParams['device_type_id'], $arrParams['page_id']);
[15682]261        }
[18803]262
[20847]263        $table = 'dtb_pagelayout';
264        $arrValues = $objQuery->extractOnlyColsOf($table, $arrParams);
265        $arrValues['update_url'] = $_SERVER['HTTP_REFERER'];
[21185]266        $arrValues['update_date'] = 'CURRENT_TIMESTAMP';
[20847]267
268        // 新規登録
269        if ($is_new || SC_Utils_Ex::isBlank($arrExists)) {
270            $objQuery->setOrder('');
271            $arrValues['page_id'] = 1 + $objQuery->max('page_id', $table, 'device_type_id = ?',
272                                                       array($arrValues['device_type_id']));
[21185]273            $arrValues['create_date'] = 'CURRENT_TIMESTAMP';
[20847]274            $objQuery->insert($table, $arrValues);
[15682]275        }
[20847]276        // 更新
[18803]277        else {
[20847]278            // 編集不可ページは更新しない
279            if (!$objLayout->isEditablePage($arrValues['device_type_id'], $arrValues['page_id'])) {
280                unset($arrValues['page_name']);
281                unset($arrValues['filename']);
282                unset($arrValues['url']);
283            }
[15682]284
[20857]285            $objQuery->update($table, $arrValues, 'page_id = ? AND device_type_id = ?',
[20847]286                              array($arrValues['page_id'], $arrValues['device_type_id']));
[15682]287        }
[20847]288        return $arrValues['page_id'];
[15682]289    }
290
291    /**
[20847]292     * エラーチェックを行う.
[18344]293     *
[20847]294     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
295     * @return array エラーメッセージの配列
[18344]296     */
[20847]297    function lfCheckError(&$objFormParam, &$arrErr) {
298        $arrParams = $objFormParam->getHashArray();
299        $objErr = new SC_CheckError_Ex($arrParams);
300        $objErr->arrErr =& $arrErr;
[22100]301        $objErr->doFunc(array(t('PARAM_LABEL_THE_NAME'), 'page_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
302        $objErr->doFunc(array(t('PARAM_LABEL_URL'), 'filename', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
[19713]303
[20847]304        /*
305         * URL チェック
306         * ここでチェックするのは, パスのみなので SC_CheckError::URL_CHECK()
307         * は使用しない
308         */
309        $valid_url = true;
310        foreach (explode('/', $arrParams['filename']) as $val) {
311            if (!preg_match('/^[a-zA-Z0-9:_~\.\-]+$/', $val)) {
312                $valid_url = false;
[17416]313            }
[20847]314            if ($val == '.' || $val == '..') {
315                $valid_url = false;
[17416]316            }
[15682]317        }
[20847]318        if (!$valid_url) {
[22100]319            $objErr->arrErr['filename'] = t('LC_Page_Admin_Design_MainEdit_005');
[15682]320        }
[20847]321        // 同一URLの存在チェック
322        $where = 'page_id <> 0 AND device_type_id = ? AND filename = ?';
[21002]323        $arrValues = array($arrParams['device_type_id'], USER_DIR . $arrParams['filename']);
[20847]324        // 変更の場合は自 URL を除外
325        if (!SC_Utils_Ex::isBlank($arrParams['page_id'])) {
326            $where .= ' AND page_id <> ?';
327            $arrValues[] = $arrParams['page_id'];
[15682]328        }
[20041]329
[20830]330        $objQuery =& SC_Query_Ex::getSingletonInstance();
[21376]331        $exists = $objQuery->exists('dtb_pagelayout', $where, $arrValues);
332        if ($exists) {
[22100]333            $objErr->arrErr['filename'] = t('LC_Page_Admin_Design_MainEdit_006');
[17416]334        }
[15682]335        return $objErr->arrErr;
336    }
337
338    /**
[20847]339     * PHP ファイルを生成する.
[15682]340     *
[20847]341     * 既に同名の PHP ファイルが存在する場合は何もせず true を返す.(#831)
[15682]342     *
[20970]343     * @param string $filename フォームパラメーターの filename
[20847]344     * @return boolean 作成に成功した場合 true
[15682]345     */
[20847]346    function createPHPFile($filename) {
347        $path = USER_REALDIR . $filename . '.php';
[15682]348
[18861]349        if (file_exists($path)) {
[20847]350            return true;
[18861]351        }
352
[20847]353        if (file_exists(USER_DEF_PHP_REALFILE)) {
354            $php_contents = file_get_contents(USER_DEF_PHP_REALFILE);
355        } else {
356            return false;
[15682]357        }
358
[20847]359        // require.php の PATH を書き換える
[19777]360        $defaultStrings = "exit; // Don't rewrite. This line is rewritten by EC-CUBE.";
[20847]361        $replaceStrings = "require_once '" . str_repeat('../', substr_count($filename, '/')) . "../require.php';";
362        $php_contents = str_replace($defaultStrings, $replaceStrings, $php_contents);
[15682]363
[20847]364        return SC_Helper_FileManager_Ex::sfWriteFile($path, $php_contents);
[15682]365    }
366}
Note: See TracBrowser for help on using the repository browser.