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

Revision 19661, 6.9 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: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(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_Admin {
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        $this->action();
62        $this->sendResponse();
63    }
64
65    /**
66     * Page のアクション.
67     *
68     * @return void
69     */
70    function action() {
71        // 認証可否の判定
72        $objSess = new SC_Session();
73        SC_Utils_Ex::sfIsSuccess($objSess);
74
75        $objFileManager = new SC_Helper_FileManager_Ex();
76
77        // CSSファイル名を取得
78        if (isset($_POST['css_name'])) {
79            $css_name = $_POST['css_name'];
80        }else if (isset($_GET['css_name'])){
81            $css_name = $_GET['css_name'];
82        }else{
83            $css_name = '';
84        }
85        $this->css_name = $css_name;
86
87        if (isset($_POST['old_css_name'])) {
88            $old_css_name = $_POST['old_css_name'];
89        }else if (isset($_GET['css_name'])) {
90            $old_css_name = $_GET['css_name'];
91        }else{
92            $old_css_name = '';
93        }
94        $this->old_css_name = $old_css_name;
95
96        $css_dir =  USER_TEMPLATE_PATH . TEMPLATE_NAME . "/css/";
97        $css_path = $css_dir . $css_name . '.css';
98
99        // CSSファイルの読み込み
100        if($css_name != ''){
101            $css_data = $objFileManager->sfReadFile($css_path);
102        }
103        // テキストエリアに表示
104        $this->css_data = $css_data;
105
106        if (!isset($_POST['mode'])) $_POST['mode'] = "";
107
108        switch($_POST['mode']) {
109            // データ更新処理
110            case 'confirm':
111                $this->lfExecuteConfirm($css_dir, $css_name, $old_css_name, $css_path);
112                break;
113            case 'delete':
114                $this->lfExecuteDelete($css_path);
115                break;
116            default:
117                if(isset($_POST['mode'])) {
118                   GC_Utils::gfPrintLog("MODEエラー:".$_POST['mode']);
119                }
120                break;
121        }
122
123        // ファイルリストを取得
124        $this->arrCSSList = $this->lfGetCSSList($css_dir);
125    }
126
127    /**
128     * デストラクタ.
129     *
130     * @return void
131     */
132    function destroy() {
133        parent::destroy();
134    }
135
136    function lfExecuteConfirm($css_dir, $css_name, $old_css_name, $css_path) {
137        $objFileManager = new SC_Helper_FileManager_Ex();
138
139        // エラーチェック
140        $this->arrErr = $this->lfErrorCheck($_POST, $css_dir);
141
142        // エラーがなければ更新処理を行う
143        if (count($this->arrErr) == 0) {
144            // 旧ファイルの削除
145            if ($old_css_name != '' && $old_css_name != $css_name) {
146                $objFileManager->sfDeleteDir($css_dir . $old_css_name . '.css');
147            }
148            // プレビュー用テンプレートに書き込み
149            $objFileManager->sfWriteFile($css_path, $_POST['css']);
150
151            $this->tpl_onload="alert('登録が完了しました。');";
152            $this->old_css_name = $css_name;
153        }
154        $this->css_data = $_POST['css'];
155    }
156
157    function lfExecuteDelete($css_path) {
158        $objFileManager = new SC_Helper_FileManager_Ex();
159
160        // css_name が空でない場合にはdeleteを実行
161        if ($_POST['css_name'] !== '') {
162            $objFileManager->sfDeleteDir($css_path);
163        }
164        $this->objDisplay->redirect($this->getLocation("./css.php"));
165    }
166
167    /**
168     * CSSファイルのリストを取得.
169     *
170     * @param array $css_dir CSSディレクトリ
171     * @return array ファイルリスト
172     */
173    function lfGetCSSList($css_dir) {
174        $objFileManager = new SC_Helper_FileManager_Ex();
175
176        $arrFileList = $objFileManager->sfGetFileList($css_dir);
177        foreach ($arrFileList as $key => $val) {
178            if (!$val['is_dir']) {
179                $arrCSSList[] = array(
180                    'file_name' => $val['file_name'],
181                    'css_name'  => preg_replace('/(.+)\.(.+?)$/','$1',$val['file_name']),
182                );
183            }
184        }
185        return $arrCSSList;
186    }
187
188    /**
189     * 入力項目のエラーチェックを行う.
190     *
191     * @param array $arrData 入力データ
192     * @param array $css_dir CSSディレクトリ
193     * @return array エラー情報
194     */
195    function lfErrorCheck($array, $css_dir) {
196        $objErr = new SC_CheckError($array);
197
198        $objErr->doFunc(array("CSSファイル名", "css_name", STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK"));
199
200        // 入力文字が英数字,"_","-"以外ならエラーを返す
201        if(!isset($objErr->arrErr['css_name'])){
202            if(!ereg("^[a-zA-Z0-9_\.-]+$", $array['css_name'])) {
203                $objErr->arrErr['css_name'] = '※ CSSファイル名は英数字と"_"および"-"だけを入力してください。<br />';
204            }
205        }
206
207        // 同一のファイル名が存在している場合にはエラー
208        if(!isset($objErr->arrErr['css_name'])){
209            $arrCSSList = $this->lfGetCSSList($css_dir);
210            foreach ($arrCSSList as $key => $val) {
211                if ($val['css_name'] == $array['css_name']) {
212                    if ($array['old_css_name'] == '' || $array['old_css_name'] != $array['css_name']) {
213                        $errFlg = TRUE;
214                    }
215                }
216            }
217            if ($errFlg) $objErr->arrErr['css_name'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。<br />';
218        }
219
220        return $objErr->arrErr;
221    }
222}
223?>
Note: See TracBrowser for help on using the repository browser.