source: branches/version-2_5-dev/data/class/SC_Initial.php @ 19998

Revision 19998, 11.9 KB checked in by Seasoft, 13 years ago (diff)

#640(URL の index.php ハードコーディングを解消し省略・変更を考慮)

  • IIS動作未確認

#834(パスに関わるパラメータ名が不適切)

  • DIR_INDEX_URL -> DIR_INDEX_PATH
  • 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; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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.5.0-dev");
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();
55        $this->setErrorReporting();
56        $this->defineDirectoryIndex();
57        $this->defineErrorType();
58        $this->defineConstants();
59        $this->phpconfigInit();
60        $this->createCacheDir();
61        $this->stripslashesDeepGpc();
62        $this->resetSuperglobalsRequest();
63    }
64
65    /**
66     * 初期設定ファイルを読み込み, パスの設定を行う.
67     *
68     * @access protected
69     * @return void
70     */
71    function requireInitialConfig() {
72
73        define('CONFIG_REALFILE', realpath(dirname(__FILE__)) . '/../config/config.php');
74        if (file_exists(CONFIG_REALFILE)) {
75            require_once(CONFIG_REALFILE);
76        }
77
78        if (defined('ECCUBE_INSTALL')) {
79            define('MOBILE_DIR', '');
80            define('MOBILE_HTML_REALDIR', HTML_REALDIR . MOBILE_DIR);
81            define('MOBILE_HTTP_URL', HTTP_URL . MOBILE_DIR);
82            define('MOBILE_HTTPS_URL', HTTPS_URL . MOBILE_DIR);
83            define('MOBILE_URLPATH', ROOT_URLPATH . MOBILE_DIR);
84
85            define('SMARTPHONE_DIR', '');
86            define('SMARTPHONE_HTML_REALDIR', HTML_REALDIR . SMARTPHONE_DIR);
87            define('SMARTPHONE_HTTP_URL', HTTP_URL . SMARTPHONE_DIR);
88            define('SMARTPHONE_HTTPS_URL', HTTPS_URL . SMARTPHONE_DIR);
89            define('SMARTPHONE_URLPATH', ROOT_URLPATH . SMARTPHONE_DIR);
90        }
91    }
92
93    /**
94     * DSN を定義する.
95     *
96     * @access protected
97     * @return void
98     */
99    function defineDSN() {
100        if(defined('DB_TYPE') && defined('DB_USER') && defined('DB_PASSWORD')
101           && defined('DB_SERVER') && defined('DB_PORT') && defined('DB_NAME')) {
102            /** サイト用DB */
103            define ("DEFAULT_DSN",
104                    DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@"
105                    . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME);
106        }
107    }
108
109
110    /**
111     * エラーレベル設定を行う.
112     *
113     * ・推奨値
114     *   開発時 - E_ALL
115     *   運用時 - E_ALL & ~E_NOTICE
116     *
117     * @access protected
118     * @return void
119     */
120    function setErrorReporting() {
121        error_reporting(E_ALL & ~E_NOTICE);
122        // PHP 5.3.0対応
123        if (error_reporting() > 6143) {
124            error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
125        }
126    }
127
128    /**
129     * マルチバイト文字列設定を行う.
130     *
131     * TODO SJIS-win や, eucJP-win への対応
132     *
133     * @access protected
134     * @return void
135     */
136    function phpconfigInit() {
137        ini_set('display_errors', '1');
138        ini_set('mbstring.http_input', CHAR_CODE);
139        ini_set('mbstring.http_output', CHAR_CODE);
140        ini_set('auto_detect_line_endings', 1);
141        ini_set('default_charset', CHAR_CODE);
142        ini_set('mbstring.internal_encoding', CHAR_CODE);
143        ini_set('mbstring.detect_order', 'auto');
144        ini_set('mbstring.substitute_character', 'none');
145
146        mb_language('ja'); // mb_internal_encoding() より前に
147        // TODO 他に mb_language() している箇所の削除を検討
148        // TODO .htaccess の mbstring.language を削除できないか検討
149
150        mb_internal_encoding(CHAR_CODE); // mb_language() より後で
151        // TODO 上の「ini_set('mbstring.internal_encoding', CHAR_CODE);」を削除できないか検討
152        // TODO .htaccess の mbstring.internal_encoding を削除できないか検討
153
154        ini_set('arg_separator.output', '&');
155       
156        //ロケールを明示的に設定
157        setlocale(LC_ALL, LOCALE);
158    }
159
160    /**
161     * 定数 DIR_INDEX_PATH を設定する.
162     *
163     * @access protected
164     * @return void
165     */
166    function defineDirectoryIndex() {
167
168        // DirectoryIndex の実ファイル名
169        if (!defined('DIR_INDEX_FILE')) {
170            define('DIR_INDEX_FILE', 'index.php');
171        }
172
173        $useFilenameDirIndex = is_bool(USE_FILENAME_DIR_INDEX)
174            ? USE_FILENAME_DIR_INDEX
175            : (empty($_SERVER['SERVER_SOFTWARE']) ? false : substr($_SERVER['SERVER_SOFTWARE'], 0, 13) == 'Microsoft-IIS')
176        ;
177
178        // DIR_INDEX_FILE にアクセスする時の URL のファイル名部を定義する
179        if ($useFilenameDirIndex === true) {
180            // ファイル名を使用する
181            define('DIR_INDEX_PATH', DIR_INDEX_FILE);
182        } else {
183            // ファイル名を使用しない
184            define('DIR_INDEX_PATH', '');
185        }
186    }
187
188    /**
189     * 定数を設定する.
190     *
191     * mtb_constants.php を読み込んで定数を設定する.
192     * キャッシュディレクトリに存在しない場合は, 初期データからコピーする.
193     *
194     * @access protected
195     * @return void
196     */
197    function defineConstants() {
198
199        $errorMessage = "<div style='color: #F00; font-weight: bold; "
200            . "background-color: #FEB; text-align: center'>"
201            . CACHE_REALDIR
202            . " にユーザ書込み権限(777等)を付与して下さい。</div>";
203
204        // 定数を設定
205        if (is_file(CACHE_REALDIR . "mtb_constants.php")) {
206            require_once(CACHE_REALDIR . "mtb_constants.php");
207
208            // キャッシュが無ければ, 初期データからコピー
209        } elseif (is_file(CACHE_REALDIR . "../mtb_constants_init.php")) {
210
211            $mtb_constants = file_get_contents(CACHE_REALDIR . "../mtb_constants_init.php");
212            if (is_writable(CACHE_REALDIR)) {
213                $handle = fopen(CACHE_REALDIR . "mtb_constants.php", "w");
214                if (!$handle) {
215                    die($errorMessage);
216                }
217                if (fwrite($handle, $mtb_constants) === false) {
218                    die($errorMessage);
219                }
220                fclose($handle);
221
222                require_once(CACHE_REALDIR . "mtb_constants.php");
223            } else {
224                die($errorMessage);
225            }
226        } else {
227            die(CACHE_REALDIR . "../mtb_constants_init.php が存在しません");
228        }
229    }
230
231    /**
232     * 各種キャッシュディレクトリを生成する.
233     *
234     * Smarty キャッシュディレクトリを生成する.
235     *
236     * @access protected
237     * @return void
238     */
239    function createCacheDir() {
240        if (defined("HTML_REALDIR")) {
241            umask(0);
242            if (!file_exists(COMPILE_REALDIR)) {
243                mkdir(COMPILE_REALDIR);
244            }
245
246            if (!file_exists(MOBILE_COMPILE_REALDIR)) {
247                mkdir(MOBILE_COMPILE_REALDIR);
248            }
249
250            if (!file_exists(SMARTPHONE_COMPILE_REALDIR)) {
251                mkdir(SMARTPHONE_COMPILE_REALDIR);
252            }
253
254            if (!file_exists(COMPILE_ADMIN_REALDIR)) {
255                mkdir(COMPILE_ADMIN_REALDIR);
256            }
257        }
258    }
259
260    /**
261     * エラー種別を定数定義
262     *
263     * @access protected
264     * @return void
265     */
266    function defineErrorType() {
267        // LC_Page_Error用
268        /** 指定商品ページがない */
269        define('PRODUCT_NOT_FOUND', 1);
270        /** カート内が空 */
271        define('CART_EMPTY', 2);
272        /** ページ推移エラー */
273        define('PAGE_ERROR', 3);
274        /** 購入処理中のカート商品追加エラー */
275        define('CART_ADD_ERROR', 4);
276        /** 他にも購入手続きが行われた場合 */
277        define('CANCEL_PURCHASE', 5);
278        /** 指定カテゴリページがない */
279        define('CATEGORY_NOT_FOUND', 6);
280        /** ログインに失敗 */
281        define('SITE_LOGIN_ERROR', 7);
282        /** 会員専用ページへのアクセスエラー */
283        define('CUSTOMER_ERROR', 8);
284        /** 購入時の売り切れエラー */
285        define('SOLD_OUT', 9);
286        /** カート内商品の読込エラー */
287        define('CART_NOT_FOUND', 10);
288        /** ポイントの不足 */
289        define('LACK_POINT', 11);
290        /** 仮登録者がログインに失敗 */
291        define('TEMP_LOGIN_ERROR', 12);
292        /** URLエラー */
293        define('URL_ERROR', 13);
294        /** ファイル解凍エラー */
295        define('EXTRACT_ERROR', 14);
296        /** FTPダウンロードエラー */
297        define('FTP_DOWNLOAD_ERROR', 15);
298        /** FTPログインエラー */
299        define('FTP_LOGIN_ERROR', 16);
300        /** FTP接続エラー */
301        define('FTP_CONNECT_ERROR', 17);
302        /** DB作成エラー */
303        define('CREATE_DB_ERROR', 18);
304        /** DBインポートエラー */
305        define('DB_IMPORT_ERROR', 19);
306        /** 設定ファイル存在エラー */
307        define('FILE_NOT_FOUND', 20);
308        /** 書き込みエラー */
309        define('WRITE_FILE_ERROR', 21);
310        /** DB接続エラー */
311        define('DB_CONNECT_ERROR', 22);
312        /** フリーメッセージ */
313        define('FREE_ERROR_MSG', 999);
314
315        // LC_Page_Error_DispError用
316        /** ログイン失敗 */
317        define('LOGIN_ERROR', 1);
318        /** アクセス失敗(タイムアウト等) */
319        define('ACCESS_ERROR', 2);
320        /** アクセス権限違反 */
321        define('AUTH_ERROR', 3);
322        /** 不正な遷移エラー */
323        define('INVALID_MOVE_ERRORR', 4);
324    }
325
326    /**
327     * クォートされた文字列のクォート部分を再帰的に取り除く
328     *
329     * {@link http://jp2.php.net/manual/ja/function.get-magic-quotes-gpc.php PHP Manual} の記事を参考に実装。
330     * $_REQUEST は後続の処理で再構成されるため、本処理では外している。
331     * @return void
332     */
333    function stripslashesDeepGpc() {
334        // Strip magic quotes from request data.
335        if (get_magic_quotes_gpc()) {
336            // Create lamba style unescaping function (for portability)
337            $quotes_sybase = strtolower(ini_get('magic_quotes_sybase'));
338            $unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)';
339            $stripslashes_deep = create_function('&$value, $fn', '
340                if (is_string($value)) {
341                    $value = ' . $unescape_function . ';
342                } else if (is_array($value)) {
343                    foreach ($value as &$v) $fn($v, $fn);
344                }
345            ');
346
347            // Unescape data
348            $stripslashes_deep($_POST, $stripslashes_deep);
349            $stripslashes_deep($_GET, $stripslashes_deep);
350            $stripslashes_deep($_COOKIE, $stripslashes_deep);
351        }
352    }
353
354    /**
355     * スーパーグローバル変数「$_REQUEST」を再セット
356     *
357     * variables_order ディレクティブによる差を吸収する。
358     *
359     * @access protected
360     * @return void
361     */
362    function resetSuperglobalsRequest() {
363        $_REQUEST = array_merge($_GET, $_POST);
364    }
365}
366?>
Note: See TracBrowser for help on using the repository browser.