source: branches/comu-ver2/data/class/SC_Initial.php @ 18219

Revision 18219, 6.9 KB checked in by Seasoft, 15 years ago (diff)

r18208 の不適切な部分(Revision番号を定数セットしようとした試み)を逆マージ。

  • その方法では /data/class/SC_Initial.php を更新したときのみ更新される。(同様の試みを r17651 で行い、既に失敗しています。)
  • 文字列定数として「ドルマーク + 英数字」のパターンが存在する場合、ダブルクォートで囲ってはいけない。シングルクォートで囲うべきである。
  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • 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/**
25 * アプリケーションの初期設定クラス.
26 *
27 * @author LOCKON CO.,LTD.
28 * @version $Id$
29 */
30class SC_Initial {
31
32    // {{{ cunstructor
33
34    /**
35     * コンストラクタ.
36     */
37    function SC_Initial() {
38
39        /** EC-CUBEのバージョン */
40        // XXX SVNのリビジョンを付加できたら良いと思う。(方法が分からない。)
41        define('ECCUBE_VERSION', "2.4.0-comu");
42    }
43
44    // }}}
45    // {{{ functions
46
47    /**
48     * 初期設定を行う.
49     *
50     * @access protected
51     * @return void
52     */
53    function init() {
54        $this->requireInitialConfig();
55        $this->defineDSN();
56        $this->setErrorReporting();
57        $this->defineDirectoryIndex();
58        $this->defineConstants();
59        $this->mbstringInit();
60        $this->createCacheDir();
61    }
62
63    /**
64     * 初期設定ファイルを読み込む.
65     *
66     * @access protected
67     * @return void
68     */
69    function requireInitialConfig() {
70
71        require_once(realpath(dirname( __FILE__)) ."/../install.php");
72    }
73
74    /**
75     * DSN を定義する.
76     *
77     * @access protected
78     * @return void
79     */
80    function defineDSN() {
81        if(defined('DB_TYPE') && defined('DB_USER') && defined('DB_PASSWORD')
82           && defined('DB_SERVER') && defined('DB_PORT') && defined('DB_NAME')) {
83            /** サイト用DB */
84            define ("DEFAULT_DSN",
85                    DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@"
86                    . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME);
87        } else {
88            define("DEFAULT_DSN", "pgsql://nobody:password@localhost:5432/eccubedb");
89        }
90    }
91
92
93    /**
94     * エラーレベル設定を行う.
95     *
96     * ・推奨値
97     *   開発時 - E_ALL
98     *   運用時 - E_ALL & ~E_NOTICE
99     *
100     * @access protected
101     * @return void
102     */
103    function setErrorReporting() {
104        error_reporting(E_ALL & ~E_NOTICE);
105        // PHP 5.3.0対応
106        if (error_reporting() > 6143) {
107            error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
108        }
109    }
110
111    /**
112     * マルチバイト文字列設定を行う.
113     *
114     * TODO SJIS-win や, eucJP-win への対応
115     *
116     * @access protected
117     * @return void
118     */
119    function mbstringInit() {
120        ini_set("mbstring.http_input", CHAR_CODE);
121        ini_set("mbstring.http_output", CHAR_CODE);
122        ini_set("auto_detect_line_endings", 1);
123        ini_set("default_charset", CHAR_CODE);
124        ini_set("mbstring.internal_encoding", CHAR_CODE);
125        ini_set("mbstring.detect_order", "auto");
126        ini_set("mbstring.substitute_character", "none");
127       
128        mb_language('ja'); // mb_internal_encoding() より前に
129        // TODO 他に mb_language() している箇所の削除を検討
130        // TODO .htaccess の mbstring.language を削除できないか検討
131       
132        mb_internal_encoding(CHAR_CODE); // mb_language() より後で
133        // TODO 上の「ini_set("mbstring.internal_encoding", CHAR_CODE);」を削除できないか検討
134        // TODO .htaccess の mbstring.internal_encoding を削除できないか検討
135       
136        //ロケールを明示的に設定
137        setlocale(LC_ALL, LOCALE);
138    }
139
140    /**
141     * 定数 DIR_INDEX_URL を設定する.
142     *
143     * @access protected
144     * @return void
145     */
146    function defineDirectoryIndex() {
147       
148        // DirectoryIndex の実ファイル名
149        if (!defined('DIR_INDEX_FILE')) {
150            define('DIR_INDEX_FILE', 'index.php');
151        }
152       
153        // DIR_INDEX_FILE にアクセスする時の URL のファイル名部を定義する
154        if (USE_FILENAME_DIR_INDEX === true) {
155            // ファイル名を使用する
156            define('DIR_INDEX_URL', DIR_INDEX_FILE);
157        } else {
158            // ファイル名を使用しない
159            define('DIR_INDEX_URL', '');
160        }
161    }
162
163    /**
164     * 定数を設定する.
165     *
166     * mtb_constants.php を読み込んで定数を設定する.
167     * キャッシュディレクトリに存在しない場合は, 初期データからコピーする.
168     *
169     * @access protected
170     * @return void
171     */
172    function defineConstants() {
173
174        $errorMessage = "<div style='color: #F00; font-weight: bold; "
175            . "background-color: #FEB; text-align: center'>"
176            . CACHE_PATH
177            . " にユーザ書込み権限(777等)を付与して下さい。</div>";
178
179        // 定数を設定
180        if (is_file(CACHE_PATH . "mtb_constants.php")) {
181            require_once(CACHE_PATH . "mtb_constants.php");
182
183            // キャッシュが無ければ, 初期データからコピー
184        } elseif (is_file(CACHE_PATH . "../mtb_constants_init.php")) {
185
186            $mtb_constants = file_get_contents(CACHE_PATH . "../mtb_constants_init.php");
187            if (is_writable(CACHE_PATH)) {
188                $handle = fopen(CACHE_PATH . "mtb_constants.php", "w");
189                if (!$handle) {
190                    die($errorMessage);
191                }
192                if (fwrite($handle, $mtb_constants) === false) {
193                    die($errorMessage);
194                }
195                fclose($handle);
196
197                require_once(CACHE_PATH . "mtb_constants.php");
198            } else {
199                die($errorMessage);
200            }
201        } else {
202            die(CACHE_PATH . "../mtb_constants_init.php が存在しません");
203        }
204    }
205
206    /**
207     * 各種キャッシュディレクトリを生成する.
208     *
209     * Smarty キャッシュディレクトリを生成する.
210     *
211     * @access protected
212     * @return void
213     */
214    function createCacheDir() {
215        if (defined("HTML_PATH")) {
216            umask(0);
217            if (!file_exists(COMPILE_DIR)) {
218                mkdir(COMPILE_DIR);
219            }
220
221            if (!file_exists(MOBILE_COMPILE_DIR)) {
222                mkdir(MOBILE_COMPILE_DIR);
223            }
224
225            if (!file_exists(COMPILE_ADMIN_DIR)) {
226                mkdir(COMPILE_ADMIN_DIR);
227            }
228
229            if (!file_exists(COMPILE_FTP_DIR)) {
230                mkdir(COMPILE_FTP_DIR);
231            }
232        }
233    }
234}
235?>
Note: See TracBrowser for help on using the repository browser.