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 | */ |
---|
30 | class 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 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * マルチバイト文字列設定を行う. |
---|
109 | * |
---|
110 | * TODO SJIS-win や, eucJP-win への対応 |
---|
111 | * |
---|
112 | * @access protected |
---|
113 | * @return void |
---|
114 | */ |
---|
115 | function mbstringInit() { |
---|
116 | ini_set("mbstring.http_input", CHAR_CODE); |
---|
117 | ini_set("mbstring.http_output", CHAR_CODE); |
---|
118 | ini_set("auto_detect_line_endings", 1); |
---|
119 | ini_set("default_charset", CHAR_CODE); |
---|
120 | ini_set("mbstring.internal_encoding", CHAR_CODE); |
---|
121 | ini_set("mbstring.detect_order", "auto"); |
---|
122 | ini_set("mbstring.substitute_character", "none"); |
---|
123 | |
---|
124 | mb_language('ja'); // mb_internal_encoding() より前に |
---|
125 | // TODO 他に mb_language() している箇所の削除を検討 |
---|
126 | // TODO .htaccess の mbstring.language を削除できないか検討 |
---|
127 | |
---|
128 | mb_internal_encoding(CHAR_CODE); // mb_language() より後で |
---|
129 | // TODO 上の「ini_set("mbstring.internal_encoding", CHAR_CODE);」を削除できないか検討 |
---|
130 | // TODO .htaccess の mbstring.internal_encoding を削除できないか検討 |
---|
131 | |
---|
132 | //ロケールを明示的に設定 |
---|
133 | setlocale(LC_ALL, LOCALE); |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * 定数 DIR_INDEX_URL を設定する. |
---|
138 | * |
---|
139 | * @access protected |
---|
140 | * @return void |
---|
141 | */ |
---|
142 | function defineDirectoryIndex() { |
---|
143 | |
---|
144 | // DirectoryIndex の実ファイル名 |
---|
145 | if (!defined('DIR_INDEX_FILE')) { |
---|
146 | define('DIR_INDEX_FILE', 'index.php'); |
---|
147 | } |
---|
148 | |
---|
149 | // DIR_INDEX_FILE にアクセスする時の URL のファイル名部を定義する |
---|
150 | if (USE_FILENAME_DIR_INDEX === true) { |
---|
151 | // ファイル名を使用する |
---|
152 | define('DIR_INDEX_URL', DIR_INDEX_FILE); |
---|
153 | } else { |
---|
154 | // ファイル名を使用しない |
---|
155 | define('DIR_INDEX_URL', ''); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * 定数を設定する. |
---|
161 | * |
---|
162 | * mtb_constants.php を読み込んで定数を設定する. |
---|
163 | * キャッシュディレクトリに存在しない場合は, 初期データからコピーする. |
---|
164 | * |
---|
165 | * @access protected |
---|
166 | * @return void |
---|
167 | */ |
---|
168 | function defineConstants() { |
---|
169 | |
---|
170 | $errorMessage = "<div style='color: #F00; font-weight: bold; " |
---|
171 | . "background-color: #FEB; text-align: center'>" |
---|
172 | . CACHE_PATH |
---|
173 | . " にユーザ書込み権限(777等)を付与して下さい。</div>"; |
---|
174 | |
---|
175 | // 定数を設定 |
---|
176 | if (is_file(CACHE_PATH . "mtb_constants.php")) { |
---|
177 | require_once(CACHE_PATH . "mtb_constants.php"); |
---|
178 | |
---|
179 | // キャッシュが無ければ, 初期データからコピー |
---|
180 | } elseif (is_file(CACHE_PATH . "../mtb_constants_init.php")) { |
---|
181 | |
---|
182 | $mtb_constants = file_get_contents(CACHE_PATH . "../mtb_constants_init.php"); |
---|
183 | if (is_writable(CACHE_PATH)) { |
---|
184 | $handle = fopen(CACHE_PATH . "mtb_constants.php", "w"); |
---|
185 | if (!$handle) { |
---|
186 | die($errorMessage); |
---|
187 | } |
---|
188 | if (fwrite($handle, $mtb_constants) === false) { |
---|
189 | die($errorMessage); |
---|
190 | } |
---|
191 | fclose($handle); |
---|
192 | |
---|
193 | require_once(CACHE_PATH . "mtb_constants.php"); |
---|
194 | } else { |
---|
195 | die($errorMessage); |
---|
196 | } |
---|
197 | } else { |
---|
198 | die(CACHE_PATH . "../mtb_constants_init.php が存在しません"); |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | /** |
---|
203 | * 各種キャッシュディレクトリを生成する. |
---|
204 | * |
---|
205 | * Smarty キャッシュディレクトリを生成する. |
---|
206 | * |
---|
207 | * @access protected |
---|
208 | * @return void |
---|
209 | */ |
---|
210 | function createCacheDir() { |
---|
211 | if (defined("HTML_PATH")) { |
---|
212 | umask(0); |
---|
213 | if (!file_exists(COMPILE_DIR)) { |
---|
214 | mkdir(COMPILE_DIR); |
---|
215 | } |
---|
216 | |
---|
217 | if (!file_exists(MOBILE_COMPILE_DIR)) { |
---|
218 | mkdir(MOBILE_COMPILE_DIR); |
---|
219 | } |
---|
220 | |
---|
221 | if (!file_exists(COMPILE_ADMIN_DIR)) { |
---|
222 | mkdir(COMPILE_ADMIN_DIR); |
---|
223 | } |
---|
224 | |
---|
225 | if (!file_exists(COMPILE_FTP_DIR)) { |
---|
226 | mkdir(COMPILE_FTP_DIR); |
---|
227 | } |
---|
228 | } |
---|
229 | } |
---|
230 | } |
---|
231 | ?> |
---|