source: branches/version-2_11-dev/data/class/SC_Initial.php @ 21258

Revision 21258, 12.6 KB checked in by nanasess, 13 years ago (diff)

#1433 (PHP Notice が発生する)

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