source: tmp/version-2_5-test/data/class/SC_Initial.php @ 18609

Revision 18609, 9.7 KB checked in by kajiwara, 14 years ago (diff)

正式版にナイトリービルド版をマージしてみるテスト

  • 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.2-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->defineErrorType();
59        $this->defineConstants();
60        $this->mbstringInit();
61        $this->createCacheDir();
62        $this->resetSuperglobalsRequest();
63    }
64
65    /**
66     * 初期設定ファイルを読み込む.
67     *
68     * @access protected
69     * @return void
70     */
71    function requireInitialConfig() {
72
73        require_once(realpath(dirname( __FILE__)) ."/../install.php");
74    }
75
76    /**
77     * DSN を定義する.
78     *
79     * @access protected
80     * @return void
81     */
82    function defineDSN() {
83        if(defined('DB_TYPE') && defined('DB_USER') && defined('DB_PASSWORD')
84           && defined('DB_SERVER') && defined('DB_PORT') && defined('DB_NAME')) {
85            /** サイト用DB */
86            define ("DEFAULT_DSN",
87                    DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@"
88                    . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME);
89        } else {
90            define("DEFAULT_DSN", "pgsql://nobody:password@localhost:5432/eccubedb");
91        }
92    }
93
94
95    /**
96     * エラーレベル設定を行う.
97     *
98     * ・推奨値
99     *   開発時 - E_ALL
100     *   運用時 - E_ALL & ~E_NOTICE
101     *
102     * @access protected
103     * @return void
104     */
105    function setErrorReporting() {
106        error_reporting(E_ALL & ~E_NOTICE);
107        // PHP 5.3.0対応
108        if (error_reporting() > 6143) {
109            error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
110        }
111    }
112
113    /**
114     * マルチバイト文字列設定を行う.
115     *
116     * TODO SJIS-win や, eucJP-win への対応
117     *
118     * @access protected
119     * @return void
120     */
121    function mbstringInit() {
122        ini_set("mbstring.http_input", CHAR_CODE);
123        ini_set("mbstring.http_output", CHAR_CODE);
124        ini_set("auto_detect_line_endings", 1);
125        ini_set("default_charset", CHAR_CODE);
126        ini_set("mbstring.internal_encoding", CHAR_CODE);
127        ini_set("mbstring.detect_order", "auto");
128        ini_set("mbstring.substitute_character", "none");
129       
130        mb_language('ja'); // mb_internal_encoding() より前に
131        // TODO 他に mb_language() している箇所の削除を検討
132        // TODO .htaccess の mbstring.language を削除できないか検討
133       
134        mb_internal_encoding(CHAR_CODE); // mb_language() より後で
135        // TODO 上の「ini_set("mbstring.internal_encoding", CHAR_CODE);」を削除できないか検討
136        // TODO .htaccess の mbstring.internal_encoding を削除できないか検討
137       
138        //ロケールを明示的に設定
139        setlocale(LC_ALL, LOCALE);
140    }
141
142    /**
143     * 定数 DIR_INDEX_URL を設定する.
144     *
145     * @access protected
146     * @return void
147     */
148    function defineDirectoryIndex() {
149       
150        // DirectoryIndex の実ファイル名
151        if (!defined('DIR_INDEX_FILE')) {
152            define('DIR_INDEX_FILE', 'index.php');
153        }
154       
155        // DIR_INDEX_FILE にアクセスする時の URL のファイル名部を定義する
156        if (USE_FILENAME_DIR_INDEX === true) {
157            // ファイル名を使用する
158            define('DIR_INDEX_URL', DIR_INDEX_FILE);
159        } else {
160            // ファイル名を使用しない
161            define('DIR_INDEX_URL', '');
162        }
163    }
164
165    /**
166     * 定数を設定する.
167     *
168     * mtb_constants.php を読み込んで定数を設定する.
169     * キャッシュディレクトリに存在しない場合は, 初期データからコピーする.
170     *
171     * @access protected
172     * @return void
173     */
174    function defineConstants() {
175
176        $errorMessage = "<div style='color: #F00; font-weight: bold; "
177            . "background-color: #FEB; text-align: center'>"
178            . CACHE_PATH
179            . " にユーザ書込み権限(777等)を付与して下さい。</div>";
180
181        // 定数を設定
182        if (is_file(CACHE_PATH . "mtb_constants.php")) {
183            require_once(CACHE_PATH . "mtb_constants.php");
184
185            // キャッシュが無ければ, 初期データからコピー
186        } elseif (is_file(CACHE_PATH . "../mtb_constants_init.php")) {
187
188            $mtb_constants = file_get_contents(CACHE_PATH . "../mtb_constants_init.php");
189            if (is_writable(CACHE_PATH)) {
190                $handle = fopen(CACHE_PATH . "mtb_constants.php", "w");
191                if (!$handle) {
192                    die($errorMessage);
193                }
194                if (fwrite($handle, $mtb_constants) === false) {
195                    die($errorMessage);
196                }
197                fclose($handle);
198
199                require_once(CACHE_PATH . "mtb_constants.php");
200            } else {
201                die($errorMessage);
202            }
203        } else {
204            die(CACHE_PATH . "../mtb_constants_init.php が存在しません");
205        }
206    }
207
208    /**
209     * 各種キャッシュディレクトリを生成する.
210     *
211     * Smarty キャッシュディレクトリを生成する.
212     *
213     * @access protected
214     * @return void
215     */
216    function createCacheDir() {
217        if (defined("HTML_PATH")) {
218            umask(0);
219            if (!file_exists(COMPILE_DIR)) {
220                mkdir(COMPILE_DIR);
221            }
222
223            if (!file_exists(MOBILE_COMPILE_DIR)) {
224                mkdir(MOBILE_COMPILE_DIR);
225            }
226
227            if (!file_exists(COMPILE_ADMIN_DIR)) {
228                mkdir(COMPILE_ADMIN_DIR);
229            }
230
231            if (!file_exists(COMPILE_FTP_DIR)) {
232                mkdir(COMPILE_FTP_DIR);
233            }
234        }
235    }
236
237    /**
238     * エラー種別を定数定義
239     *
240     * @access protected
241     * @return void
242     */
243    function defineErrorType() {
244        // LC_Page_Error用
245        /** 指定商品ページがない */
246        define('PRODUCT_NOT_FOUND', 1);
247        /** カート内が空 */
248        define('CART_EMPTY', 2);
249        /** ページ推移エラー */
250        define('PAGE_ERROR', 3);
251        /** 購入処理中のカート商品追加エラー */
252        define('CART_ADD_ERROR', 4);
253        /** 他にも購入手続きが行われた場合 */
254        define('CANCEL_PURCHASE', 5);
255        /** 指定カテゴリページがない */
256        define('CATEGORY_NOT_FOUND', 6);
257        /** ログインに失敗 */
258        define('SITE_LOGIN_ERROR', 7);
259        /** 会員専用ページへのアクセスエラー */
260        define('CUSTOMER_ERROR', 8);
261        /** 購入時の売り切れエラー */
262        define('SOLD_OUT', 9);
263        /** カート内商品の読込エラー */
264        define('CART_NOT_FOUND', 10);
265        /** ポイントの不足 */
266        define('LACK_POINT', 11);
267        /** 仮登録者がログインに失敗 */
268        define('TEMP_LOGIN_ERROR', 12);
269        /** URLエラー */
270        define('URL_ERROR', 13);
271        /** ファイル解凍エラー */
272        define('EXTRACT_ERROR', 14);
273        /** FTPダウンロードエラー */
274        define('FTP_DOWNLOAD_ERROR', 15);
275        /** FTPログインエラー */
276        define('FTP_LOGIN_ERROR', 16);
277        /** FTP接続エラー */
278        define('FTP_CONNECT_ERROR', 17);
279        /** DB作成エラー */
280        define('CREATE_DB_ERROR', 18);
281        /** DBインポートエラー */
282        define('DB_IMPORT_ERROR', 19);
283        /** 設定ファイル存在エラー */
284        define('FILE_NOT_FOUND', 20);
285        /** 書き込みエラー */
286        define('WRITE_FILE_ERROR', 21);
287        /** DB接続エラー */
288        define('DB_CONNECT_ERROR', 22);
289        /** フリーメッセージ */
290        define('FREE_ERROR_MSG', 999);
291
292        // LC_Page_Error_DispError用
293        /** ログイン失敗 */
294        define('LOGIN_ERROR', 1);
295        /** アクセス失敗(タイムアウト等) */
296        define('ACCESS_ERROR', 2);
297        /** アクセス権限違反 */
298        define('AUTH_ERROR', 3);
299        /** 不正な遷移エラー */
300        define('INVALID_MOVE_ERRORR', 4);
301    }
302
303    /**
304     * スーパーグローバル変数「$_REQUEST」を再セット
305     *
306     * variables_order ディレクティブによる差を吸収する。
307     *
308     * @access protected
309     * @return void
310     */
311    function resetSuperglobalsRequest() {
312        $_REQUEST = array_merge($_GET, $_POST);
313    }
314}
315?>
Note: See TracBrowser for help on using the repository browser.