source: branches/comu-ver2/data/class/pages/admin/design/LC_Page_Admin_Design_CSS.php @ 17114

Revision 17114, 6.9 KB checked in by pineray, 16 years ago (diff)

ヘルパークラスを使用するように変更

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
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(CLASS_EX_PATH . "helper_extends/SC_Helper_FileManager_Ex.php");
27
28/**
29 * CSS設定 のページクラス.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class LC_Page_Admin_Design_CSS extends LC_Page {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46        parent::init();
47        $this->tpl_mainpage = 'design/css.tpl';
48        $this->tpl_subnavi  = 'design/subnavi.tpl';
49        $this->area_row = 30;
50        $this->tpl_subno = "css";
51        $this->tpl_mainno = "design";
52        $this->tpl_subtitle = 'CSS編集';
53    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
60    function process() {
61        $objView = new SC_AdminView();
62
63        // 認証可否の判定
64        $objSess = new SC_Session();
65        SC_Utils_Ex::sfIsSuccess($objSess);
66
67        $objFileManager = new SC_Helper_FileManager_Ex();
68
69        // CSSファイル名を取得
70        if (isset($_POST['css_name'])) {
71            $css_name = $_POST['css_name'];
72        }else if (isset($_GET['css_name'])){
73            $css_name = $_GET['css_name'];
74        }else{
75            $css_name = '';
76        }
77        $this->css_name = $css_name;
78
79        if (isset($_POST['old_css_name'])) {
80            $old_css_name = $_POST['old_css_name'];
81        }else if (isset($_GET['css_name'])) {
82            $old_css_name = $_GET['css_name'];
83        }else{
84            $old_css_name = '';
85        }
86        $this->old_css_name = $old_css_name;
87
88        $css_dir =  USER_TEMPLATE_PATH . TEMPLATE_NAME . "/css/";
89        $css_path = $css_dir . $css_name . '.css';
90
91        // CSSファイルの読み込み
92        if($css_name != ''){
93            $css_data = $objFileManager->sfReadFile($css_path);
94        }
95        // テキストエリアに表示
96        $this->css_data = $css_data;
97
98        if (!isset($_POST['mode'])) $_POST['mode'] = "";
99
100        switch($_POST['mode']) {
101            // データ更新処理
102            case 'confirm':
103                $this->lfExecuteConfirm($css_dir, $css_name, $old_css_name, $css_path);
104                break;
105            case 'delete':
106                $this->lfExecuteDelete($css_path);
107                break;
108            default:
109                if(isset($_POST['mode'])) {
110                   GC_Utils::gfPrintLog("MODEエラー:".$_POST['mode']);
111                }
112                break;
113        }
114
115        // ファイルリストを取得
116        $this->arrCSSList = $this->lfGetCSSList($css_dir);
117
118        // 画面の表示
119        $objView->assignobj($this);
120        $objView->display(MAIN_FRAME);
121    }
122
123    /**
124     * デストラクタ.
125     *
126     * @return void
127     */
128    function destroy() {
129        parent::destroy();
130    }
131
132    function lfExecuteConfirm($css_dir, $css_name, $old_css_name, $css_path) {
133        $objFileManager = new SC_Helper_FileManager_Ex();
134
135        // エラーチェック
136        $this->arrErr = $this->lfErrorCheck($_POST, $css_dir);
137
138        // エラーがなければ更新処理を行う
139        if (count($this->arrErr) == 0) {
140            // 旧ファイルの削除
141            if ($old_css_name != '' && $old_css_name != $css_name) {
142                $objFileManager->sfDeleteDir($css_dir . $old_css_name . '.css');
143            }
144            // プレビュー用テンプレートに書き込み
145            $objFileManager->sfWriteFile($css_path, $_POST['css']);
146
147            $this->tpl_onload="alert('登録が完了しました。');";
148            $this->old_css_name = $css_name;
149        }
150        $this->css_data = $_POST['css'];
151    }
152
153    function lfExecuteDelete($css_path) {
154        $objFileManager = new SC_Helper_FileManager_Ex();
155
156        // css_name が空でない場合にはdeleteを実行
157        if ($_POST['css_name'] !== '') {
158            $objFileManager->sfDeleteDir($css_path);
159        }
160        $this->sendRedirect($this->getLocation("./css.php"));
161    }
162
163    /**
164     * CSSファイルのリストを取得.
165     *
166     * @param array $css_dir CSSディレクトリ
167     * @return array ファイルリスト
168     */
169    function lfGetCSSList($css_dir) {
170        $objFileManager = new SC_Helper_FileManager_Ex();
171
172        $arrFileList = $objFileManager->sfGetFileList($css_dir);
173        foreach ($arrFileList as $key => $val) {
174            if (!$val['is_dir']) {
175                $arrCSSList[] = array(
176                    'file_name' => $val['file_name'],
177                    'css_name'  => preg_replace('/(.+)\.(.+?)$/','$1',$val['file_name']),
178                );
179            }
180        }
181        return $arrCSSList;
182    }
183
184    /**
185     * 入力項目のエラーチェックを行う.
186     *
187     * @param array $arrData 入力データ
188     * @param array $css_dir CSSディレクトリ
189     * @return array エラー情報
190     */
191    function lfErrorCheck($array, $css_dir) {
192        $objErr = new SC_CheckError($array);
193
194        $objErr->doFunc(array("CSSファイル名", "css_name", STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK"));
195
196        // 入力文字が英数字,"_","-"以外ならエラーを返す
197        if(!isset($objErr->arrErr['css_name'])){
198            if(!ereg("^[a-zA-Z0-9_\.-]+$", $array['css_name'])) {
199                $objErr->arrErr['css_name'] = '※ CSSファイル名は英数字と"_"および"-"だけを入力してください。<br />';
200            }
201        }
202
203        // 同一のファイル名が存在している場合にはエラー
204        if(!isset($objErr->arrErr['css_name'])){
205            $arrCSSList = $this->lfGetCSSList($css_dir);
206            foreach ($arrCSSList as $key => $val) {
207                if ($val['css_name'] == $array['css_name']) {
208                    if ($array['old_css_name'] == '' || $array['old_css_name'] != $array['css_name']) {
209                        $errFlg = TRUE;
210                    }
211                }
212            }
213            if ($errFlg) $objErr->arrErr['css_name'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。<br />';
214        }
215
216        return $objErr->arrErr;
217    }
218}
219?>
Note: See TracBrowser for help on using the repository browser.