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

Revision 18208, 6.9 KB checked in by AMUAMU, 15 years ago (diff)

PHP5.3対応での~E_USER_DEPRECATEDは余計だったので外した。ついでに、Revision番号を入れてみる。

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