source: branches/version-2_12-multilang/data/class/SC_Initial.php @ 22492

Revision 22492, 17.4 KB checked in by m_uehara, 11 years ago (diff)

#2084 メッセージIDの振り直し

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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-2012 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 __construct() {
38
39        /** EC-CUBEのバージョン */
40        define('ECCUBE_VERSION', '2.12.3en');
41    }
42
43    // }}}
44    // {{{ functions
45
46    /**
47     * 初期設定を行う.
48     *
49     * @access protected
50     * @return void
51     */
52    function init() {
53        $this->requireInitialConfig();
54        $this->defineDSN();                 // requireInitialConfig メソッドより後で実行
55        $this->defineDirectoryIndex();
56        $this->defineConstants();
57        $this->defineParameter();           // defineDirectoryIndex メソッドより後で実行
58        $this->complementParameter();       // defineConstants メソッドより後で実行
59        $this->phpconfigInit();             // defineConstants メソッドより後で実行
60        $this->createCacheDir();            // defineConstants メソッドより後で実行
61        $this->stripslashesDeepGpc();
62        $this->resetSuperglobalsRequest();  // stripslashesDeepGpc メソッドより後で実行
63        $this->setTimezone();               // 本当はエラーハンドラーより先に読みたい気も
64    }
65
66    /**
67     * 初期設定ファイルを読み込み, パスの設定を行う.
68     *
69     * @access protected
70     * @return void
71     */
72    function requireInitialConfig() {
73
74        define('CONFIG_REALFILE', realpath(dirname(__FILE__)) . '/../config/config.php');
75        if (file_exists(CONFIG_REALFILE)) {
76            require_once CONFIG_REALFILE;
77        }
78    }
79
80    /**
81     * DSN を定義する.
82     *
83     * @access protected
84     * @return void
85     * @deprecated 下位互換用
86     */
87    function defineDSN() {
88        if (defined('DB_TYPE') && defined('DB_USER') && defined('DB_PASSWORD')
89            && defined('DB_SERVER') && defined('DB_PORT') && defined('DB_NAME')
90        ) {
91            $dsn = DB_TYPE . '://' . DB_USER . ':' . DB_PASSWORD . '@' . DB_SERVER . ':' . DB_PORT . '/' . DB_NAME;
92            /** サイト用DB */
93            // ここで生成した DSN は使用せず, SC_Query のコンストラクタでパラメータを設定する.
94            define('DEFAULT_DSN', $dsn);
95        }
96    }
97
98    /**
99     * @deprecated
100     */
101    function setErrorReporting() {
102        error_reporting(E_ALL & ~E_NOTICE);
103        // PHP 5.3.0対応
104        if (error_reporting() > 6143) {
105            error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
106        }
107    }
108
109    /**
110     * マルチバイト文字列設定を行う.
111     *
112     * TODO SJIS-win や, eucJP-win への対応
113     *
114     * @access protected
115     * @return void
116     */
117    function phpconfigInit() {
118        ini_set('html_errors', '1');
119        ini_set('mbstring.http_input', CHAR_CODE);
120        ini_set('mbstring.http_output', CHAR_CODE);
121        ini_set('auto_detect_line_endings', 1);
122        ini_set('default_charset', CHAR_CODE);
123        ini_set('mbstring.detect_order', 'auto');
124        ini_set('mbstring.substitute_character', 'none');
125
126        mb_language('ja'); // mb_internal_encoding() より前に
127        // TODO .htaccess の mbstring.language を削除できないか検討
128
129        mb_internal_encoding(CHAR_CODE); // mb_language() より後で
130
131        ini_set('arg_separator.output', '&');
132
133        //ロケールを明示的に設定
134        $res = setlocale(LC_ALL, LOCALE);
135        if ($res === FALSE) {
136            // TODO: Windows上のロケール設定が正常に働かない場合があることに暫定的に対応
137            // ''を指定するとApache実行環境の環境変数が使われる
138            // See also: http://php.net/manual/ja/function.setlocale.php
139            setlocale(LC_ALL, '');
140        }
141
142        // #1849 (文字エンコーディングの検出を制御する)
143        mb_detect_order(array('UTF-8', 'SJIS-win', 'eucJP-win'));
144    }
145
146    /**
147     * 定数 DIR_INDEX_PATH を設定する.
148     *
149     * @access protected
150     * @return void
151     */
152    function defineDirectoryIndex() {
153
154        // DirectoryIndex の実ファイル名
155        if (!defined('DIR_INDEX_FILE')) {
156            define('DIR_INDEX_FILE', 'index.php');
157        }
158
159        $useFilenameDirIndex = is_bool(USE_FILENAME_DIR_INDEX)
160            ? USE_FILENAME_DIR_INDEX
161            : (isset($_SERVER['SERVER_SOFTWARE']) ? substr($_SERVER['SERVER_SOFTWARE'], 0, 13) == 'Microsoft-IIS' : false)
162        ;
163
164        // DIR_INDEX_FILE にアクセスする時の URL のファイル名部を定義する
165        if ($useFilenameDirIndex === true) {
166            // ファイル名を使用する
167            define('DIR_INDEX_PATH', DIR_INDEX_FILE);
168        } else {
169            // ファイル名を使用しない
170            define('DIR_INDEX_PATH', '');
171        }
172    }
173
174    /**
175     * パラメータを設定する.
176     *
177     * mtb_constants.php を読み込んで定数として定義する.
178     * キャッシュディレクトリに存在しない場合は, 初期データからコピーする.
179     *
180     * @access protected
181     * @return void
182     */
183    function defineParameter() {
184        // 定数を設定
185        if (is_file(CACHE_REALDIR . 'mtb_constants.php')) {
186            require_once CACHE_REALDIR . 'mtb_constants.php';
187
188            // キャッシュが無ければ, 初期データからコピー
189        } elseif (is_file(CACHE_REALDIR . '../mtb_constants_init.php')) {
190
191            $mtb_constants = file_get_contents(CACHE_REALDIR . '../mtb_constants_init.php');
192            $errorMessage = t('c_<div style=\"color: #F00; font-weight: bold; background-color: #FEB; text-align: center\">Please grant T_ARG1 user write access (777, etc.)</div>_01', array('T_ARG1' => CACHE_REALDIR), array('device_type_id' => FALSE));
193            if (is_writable(CACHE_REALDIR)) {
194                $handle = fopen(CACHE_REALDIR . 'mtb_constants.php', 'w');
195                if (!$handle) {
196                    die($errorMessage);
197                }
198                if (fwrite($handle, $mtb_constants) === false) {
199                    die($errorMessage);
200                }
201                fclose($handle);
202
203                require_once CACHE_REALDIR . 'mtb_constants.php';
204            } else {
205                die($errorMessage);
206            }
207        } else {
208            die(t('c_T_ARG1../mtb_constants_init.php does not exist_01', array('T_ARG1' => CACHE_REALDIR), array('device_type_id' => FALSE)));
209        }
210    }
211
212    /**
213     * パラメーターの補完
214     *
215     * ソースのみ差し替えたバージョンアップを考慮したもの。
216     * $this->defineIfNotDefined() で定義することを想定
217     *
218     * @access protected
219     * @return void
220     */
221    function complementParameter() {
222    }
223
224    /**
225     * 各種キャッシュディレクトリを生成する.
226     *
227     * Smarty キャッシュディレクトリを生成する.
228     *
229     * @access protected
230     * @return void
231     */
232    function createCacheDir() {
233        if (defined('HTML_REALDIR')) {
234            umask(0);
235            if (!file_exists(COMPILE_REALDIR)) {
236                mkdir(COMPILE_REALDIR);
237            }
238
239            if (!file_exists(MOBILE_COMPILE_REALDIR)) {
240                mkdir(MOBILE_COMPILE_REALDIR);
241            }
242
243            if (!file_exists(SMARTPHONE_COMPILE_REALDIR)) {
244                mkdir(SMARTPHONE_COMPILE_REALDIR);
245            }
246
247            if (!file_exists(COMPILE_ADMIN_REALDIR)) {
248                mkdir(COMPILE_ADMIN_REALDIR);
249            }
250        }
251    }
252
253    /**
254     * 定数定義
255     *
256     * @access protected
257     * @return void
258     */
259    function defineConstants() {
260        // LC_Page_Error用
261        /** 指定商品ページがない */
262        define('PRODUCT_NOT_FOUND', 1);
263        /** カート内が空 */
264        define('CART_EMPTY', 2);
265        /** ページ推移エラー */
266        define('PAGE_ERROR', 3);
267        /** 購入処理中のカート商品追加エラー */
268        define('CART_ADD_ERROR', 4);
269        /** 他にも購入手続きが行われた場合 */
270        define('CANCEL_PURCHASE', 5);
271        /** 指定カテゴリページがない */
272        define('CATEGORY_NOT_FOUND', 6);
273        /** ログインに失敗 */
274        define('SITE_LOGIN_ERROR', 7);
275        /** 会員専用ページへのアクセスエラー */
276        define('CUSTOMER_ERROR', 8);
277        /** 購入時の売り切れエラー */
278        define('SOLD_OUT', 9);
279        /** カート内商品の読込エラー */
280        define('CART_NOT_FOUND', 10);
281        /** ポイントの不足 */
282        define('LACK_POINT', 11);
283        /** 仮登録者がログインに失敗 */
284        define('TEMP_LOGIN_ERROR', 12);
285        /** URLエラー */
286        define('URL_ERROR', 13);
287        /** ファイル解凍エラー */
288        define('EXTRACT_ERROR', 14);
289        /** FTPダウンロードエラー */
290        define('FTP_DOWNLOAD_ERROR', 15);
291        /** FTPログインエラー */
292        define('FTP_LOGIN_ERROR', 16);
293        /** FTP接続エラー */
294        define('FTP_CONNECT_ERROR', 17);
295        /** DB作成エラー */
296        define('CREATE_DB_ERROR', 18);
297        /** DBインポートエラー */
298        define('DB_IMPORT_ERROR', 19);
299        /** 設定ファイル存在エラー */
300        define('FILE_NOT_FOUND', 20);
301        /** 書き込みエラー */
302        define('WRITE_FILE_ERROR', 21);
303        /** DB接続エラー */
304        define('DB_CONNECT_ERROR', 22);
305        /** ダウンロードファイル存在エラー */
306        define('DOWNFILE_NOT_FOUND', 22);
307        /** フリーメッセージ */
308        define('FREE_ERROR_MSG', 999);
309
310        // LC_Page_Error_DispError用
311        /** ログイン失敗 */
312        define('LOGIN_ERROR', 1);
313        /** アクセス失敗(タイムアウト等) */
314        define('ACCESS_ERROR', 2);
315        /** アクセス権限違反 */
316        define('AUTH_ERROR', 3);
317        /** 不正な遷移エラー */
318        define('INVALID_MOVE_ERRORR', 4);
319
320        // オーナーズストア通信関連
321        /** オーナーズストア通信ステータス */
322        define('OSTORE_STATUS_ERROR', 'ERROR');
323        /** オーナーズストア通信ステータス */
324        define('OSTORE_STATUS_SUCCESS', 'SUCCESS');
325        /** オーナーズストア通信エラーコード */
326        define('OSTORE_E_UNKNOWN', '1000');
327        /** オーナーズストア通信エラーコード */
328        define('OSTORE_E_INVALID_PARAM', '1001');
329        /** オーナーズストア通信エラーコード */
330        define('OSTORE_E_NO_CUSTOMER', '1002');
331        /** オーナーズストア通信エラーコード */
332        define('OSTORE_E_WRONG_URL_PASS', '1003');
333        /** オーナーズストア通信エラーコード */
334        define('OSTORE_E_NO_PRODUCTS', '1004');
335        /** オーナーズストア通信エラーコード */
336        define('OSTORE_E_NO_DL_DATA', '1005');
337        /** オーナーズストア通信エラーコード */
338        define('OSTORE_E_DL_DATA_OPEN', '1006');
339        /** オーナーズストア通信エラーコード */
340        define('OSTORE_E_DLLOG_AUTH', '1007');
341        /** オーナーズストア通信エラーコード */
342        define('OSTORE_E_C_ADMIN_AUTH', '2001');
343        /** オーナーズストア通信エラーコード */
344        define('OSTORE_E_C_HTTP_REQ', '2002');
345        /** オーナーズストア通信エラーコード */
346        define('OSTORE_E_C_HTTP_RESP', '2003');
347        /** オーナーズストア通信エラーコード */
348        define('OSTORE_E_C_FAILED_JSON_PARSE', '2004');
349        /** オーナーズストア通信エラーコード */
350        define('OSTORE_E_C_NO_KEY', '2005');
351        /** オーナーズストア通信エラーコード */
352        define('OSTORE_E_C_INVALID_ACCESS', '2006');
353        /** オーナーズストア通信エラーコード */
354        define('OSTORE_E_C_INVALID_PARAM', '2007');
355        /** オーナーズストア通信エラーコード */
356        define('OSTORE_E_C_AUTOUP_DISABLE', '2008');
357        /** オーナーズストア通信エラーコード */
358        define('OSTORE_E_C_PERMISSION', '2009');
359        /** オーナーズストア通信エラーコード */
360        define('OSTORE_E_C_BATCH_ERR', '2010');
361
362        // プラグイン関連
363        /** プラグインの状態:アップロード済み */
364        define('PLUGIN_STATUS_UPLOADED', '1');
365        /** プラグインの状態:インストール済み */
366        define('PLUGIN_STATUS_INSTALLED', '2');
367        /** プラグイン有効/無効:有効 */
368        define('PLUGIN_ENABLE_TRUE', '1');
369        /** プラグイン有効/無効:無効 */
370        define('PLUGIN_ENABLE_FALSE', '2');
371
372        // CSV入出力関連
373        /** CSV入出力列設定有効無効フラグ: 有効 */
374        define('CSV_COLUMN_STATUS_FLG_ENABLE', 1);
375        /** CSV入出力列設定有効無効フラグ: 無効 */
376        define('CSV_COLUMN_STATUS_FLG_DISABLE', 2);
377        /** CSV入出力列設定読み書きフラグ: 読み書き可能 */
378        define('CSV_COLUMN_RW_FLG_READ_WRITE', 1);
379        /** CSV入出力列設定読み書きフラグ: 読み込みのみ可能 */
380        define('CSV_COLUMN_RW_FLG_READ_ONLY', 2);
381        /** CSV入出力列設定読み書きフラグ: キー列 */
382        define('CSV_COLUMN_RW_FLG_KEY_FIELD', 3);
383
384        // 配置ID
385        /** 配置ID: 未使用 */
386        define('TARGET_ID_UNUSED', 0);
387        /** 配置ID: LeftNavi */
388        define('TARGET_ID_LEFT', 1);
389        /** 配置ID: MainHead */
390        define('TARGET_ID_MAIN_HEAD', 2);
391        /** 配置ID: RightNavi */
392        define('TARGET_ID_RIGHT', 3);
393        /** 配置ID: MainFoot */
394        define('TARGET_ID_MAIN_FOOT', 4);
395        /** 配置ID: TopNavi */
396        define('TARGET_ID_TOP', 5);
397        /** 配置ID: BottomNavi */
398        define('TARGET_ID_BOTTOM', 6);
399        /** 配置ID: HeadNavi */
400        define('TARGET_ID_HEAD', 7);
401        /** 配置ID: HeadTopNavi */
402        define('TARGET_ID_HEAD_TOP', 8);
403        /** 配置ID: FooterBottomNavi */
404        define('TARGET_ID_FOOTER_BOTTOM', 9);
405        /** 配置ID: HeaderInternalNavi */
406        define('TARGET_ID_HEADER_INTERNAL', 10);
407
408        // 他
409        /** アクセス成功 */
410        define('SUCCESS', 0);
411        /** 無制限フラグ: 無制限 */
412        define('UNLIMITED_FLG_UNLIMITED', '1');
413        /** 無制限フラグ: 制限有り */
414        define('UNLIMITED_FLG_LIMITED', '0');
415    }
416
417    /**
418     * クォートされた文字列のクォート部分を再帰的に取り除く.
419     *
420     * {@link http://jp2.php.net/manual/ja/function.get-magic-quotes-gpc.php PHP Manual} の記事を参考に実装。
421     * $_REQUEST は後続の処理で再構成されるため、本処理では外している。
422     * この関数は, PHP5以上を対象とし, PHP4 の場合は何もしない.
423     *
424     * @return void
425     */
426    function stripslashesDeepGpc() {
427        // Strip magic quotes from request data.
428        if (get_magic_quotes_gpc()
429            && version_compare(PHP_VERSION, '5.0.0', '>=')) {
430            // Create lamba style unescaping function (for portability)
431            $quotes_sybase = strtolower(ini_get('magic_quotes_sybase'));
432            $unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)';
433            $stripslashes_deep = create_function('&$value, $fn', '
434                if (is_string($value)) {
435                    $value = ' . $unescape_function . ';
436                } else if (is_array($value)) {
437                    foreach ($value as &$v) $fn($v, $fn);
438                }
439            ');
440
441            // Unescape data
442            $stripslashes_deep($_POST, $stripslashes_deep);
443            $stripslashes_deep($_GET, $stripslashes_deep);
444            $stripslashes_deep($_COOKIE, $stripslashes_deep);
445        }
446    }
447
448    /**
449     * スーパーグローバル変数「$_REQUEST」を再セット
450     *
451     * variables_order ディレクティブによる差を吸収する。
452     *
453     * @access protected
454     * @return void
455     */
456    function resetSuperglobalsRequest() {
457        $_REQUEST = array_merge($_GET, $_POST);
458    }
459
460    /**
461     * 指定された名前の定数が存在しない場合、指定された値で定義
462     *
463     * @param string $name 定数の名前。
464     * @param mixed $value 定数の値。
465     * @return void
466     */
467    function defineIfNotDefined($name, $value = null) {
468        if (!defined($name)) {
469            define($name, $value);
470        }
471    }
472
473    /**
474     * タイムゾーンを設定
475     *
476     * @return void
477     */
478    function setTimezone() {
479        date_default_timezone_set(TIMEZONE);
480    }
481}
Note: See TracBrowser for help on using the repository browser.