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

Revision 20540, 11.4 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)

  • 半SP
  • 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-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.11.0-beta");
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
79    /**
80     * DSN を定義する.
81     *
82     * @access protected
83     * @return void
84     */
85    function defineDSN() {
86        if(defined('DB_TYPE') && defined('DB_USER') && defined('DB_PASSWORD')
87           && defined('DB_SERVER') && defined('DB_PORT') && defined('DB_NAME')) {
88            /** サイト用DB */
89            define ("DEFAULT_DSN",
90                    DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@"
91                    . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME);
92        }
93    }
94
95
96    /**
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    /**
115     * マルチバイト文字列設定を行う.
116     *
117     * TODO SJIS-win や, eucJP-win への対応
118     *
119     * @access protected
120     * @return void
121     */
122    function phpconfigInit() {
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');
131
132        mb_language('ja'); // mb_internal_encoding() より前に
133        // TODO 他に mb_language() している箇所の削除を検討
134        // TODO .htaccess の mbstring.language を削除できないか検討
135
136        mb_internal_encoding(CHAR_CODE); // mb_language() より後で
137        // TODO 上の「ini_set('mbstring.internal_encoding', CHAR_CODE);」を削除できないか検討
138        // TODO .htaccess の mbstring.internal_encoding を削除できないか検討
139
140        ini_set('arg_separator.output', '&');
141
142        //ロケールを明示的に設定
143        setlocale(LC_ALL, LOCALE);
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 defineConstants() {
184
185        $errorMessage
186            = '<div style="color: #F00; font-weight: bold; background-color: #FEB; text-align: center">'
187            . CACHE_REALDIR
188            . ' にユーザ書込み権限(777等)を付与して下さい。</div>';
189
190        // 定数を設定
191        if (is_file(CACHE_REALDIR . "mtb_constants.php")) {
192            require_once CACHE_REALDIR . 'mtb_constants.php';
193
194            // キャッシュが無ければ, 初期データからコピー
195        } elseif (is_file(CACHE_REALDIR . "../mtb_constants_init.php")) {
196
197            $mtb_constants = file_get_contents(CACHE_REALDIR . "../mtb_constants_init.php");
198            if (is_writable(CACHE_REALDIR)) {
199                $handle = fopen(CACHE_REALDIR . "mtb_constants.php", 'w');
200                if (!$handle) {
201                    die($errorMessage);
202                }
203                if (fwrite($handle, $mtb_constants) === false) {
204                    die($errorMessage);
205                }
206                fclose($handle);
207
208                require_once CACHE_REALDIR . 'mtb_constants.php';
209            } else {
210                die($errorMessage);
211            }
212        } else {
213            die(CACHE_REALDIR . "../mtb_constants_init.php が存在しません");
214        }
215    }
216
217    /**
218     * 各種キャッシュディレクトリを生成する.
219     *
220     * Smarty キャッシュディレクトリを生成する.
221     *
222     * @access protected
223     * @return void
224     */
225    function createCacheDir() {
226        if (defined("HTML_REALDIR")) {
227            umask(0);
228            if (!file_exists(COMPILE_REALDIR)) {
229                mkdir(COMPILE_REALDIR);
230            }
231
232            if (!file_exists(MOBILE_COMPILE_REALDIR)) {
233                mkdir(MOBILE_COMPILE_REALDIR);
234            }
235
236            if (!file_exists(SMARTPHONE_COMPILE_REALDIR)) {
237                mkdir(SMARTPHONE_COMPILE_REALDIR);
238            }
239
240            if (!file_exists(COMPILE_ADMIN_REALDIR)) {
241                mkdir(COMPILE_ADMIN_REALDIR);
242            }
243        }
244    }
245
246    /**
247     * エラー種別を定数定義
248     *
249     * @access protected
250     * @return void
251     */
252    function defineErrorType() {
253        // LC_Page_Error用
254        /** 指定商品ページがない */
255        define('PRODUCT_NOT_FOUND', 1);
256        /** カート内が空 */
257        define('CART_EMPTY', 2);
258        /** ページ推移エラー */
259        define('PAGE_ERROR', 3);
260        /** 購入処理中のカート商品追加エラー */
261        define('CART_ADD_ERROR', 4);
262        /** 他にも購入手続きが行われた場合 */
263        define('CANCEL_PURCHASE', 5);
264        /** 指定カテゴリページがない */
265        define('CATEGORY_NOT_FOUND', 6);
266        /** ログインに失敗 */
267        define('SITE_LOGIN_ERROR', 7);
268        /** 会員専用ページへのアクセスエラー */
269        define('CUSTOMER_ERROR', 8);
270        /** 購入時の売り切れエラー */
271        define('SOLD_OUT', 9);
272        /** カート内商品の読込エラー */
273        define('CART_NOT_FOUND', 10);
274        /** ポイントの不足 */
275        define('LACK_POINT', 11);
276        /** 仮登録者がログインに失敗 */
277        define('TEMP_LOGIN_ERROR', 12);
278        /** URLエラー */
279        define('URL_ERROR', 13);
280        /** ファイル解凍エラー */
281        define('EXTRACT_ERROR', 14);
282        /** FTPダウンロードエラー */
283        define('FTP_DOWNLOAD_ERROR', 15);
284        /** FTPログインエラー */
285        define('FTP_LOGIN_ERROR', 16);
286        /** FTP接続エラー */
287        define('FTP_CONNECT_ERROR', 17);
288        /** DB作成エラー */
289        define('CREATE_DB_ERROR', 18);
290        /** DBインポートエラー */
291        define('DB_IMPORT_ERROR', 19);
292        /** 設定ファイル存在エラー */
293        define('FILE_NOT_FOUND', 20);
294        /** 書き込みエラー */
295        define('WRITE_FILE_ERROR', 21);
296        /** DB接続エラー */
297        define('DB_CONNECT_ERROR', 22);
298        /** フリーメッセージ */
299        define('FREE_ERROR_MSG', 999);
300
301        // LC_Page_Error_DispError用
302        /** ログイン失敗 */
303        define('LOGIN_ERROR', 1);
304        /** アクセス失敗(タイムアウト等) */
305        define('ACCESS_ERROR', 2);
306        /** アクセス権限違反 */
307        define('AUTH_ERROR', 3);
308        /** 不正な遷移エラー */
309        define('INVALID_MOVE_ERRORR', 4);
310    }
311
312    /**
313     * クォートされた文字列のクォート部分を再帰的に取り除く.
314     *
315     * {@link http://jp2.php.net/manual/ja/function.get-magic-quotes-gpc.php PHP Manual} の記事を参考に実装。
316     * $_REQUEST は後続の処理で再構成されるため、本処理では外している。
317     * この関数は, PHP5以上を対象とし, PHP4 の場合は何もしない.
318     *
319     * @return void
320     */
321    function stripslashesDeepGpc() {
322        // Strip magic quotes from request data.
323        if (get_magic_quotes_gpc()
324            && version_compare(PHP_VERSION, '5.0.0', '>=')) {
325            // Create lamba style unescaping function (for portability)
326            $quotes_sybase = strtolower(ini_get('magic_quotes_sybase'));
327            $unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)';
328            $stripslashes_deep = create_function('&$value, $fn', '
329                if (is_string($value)) {
330                    $value = ' . $unescape_function . ';
331                } else if (is_array($value)) {
332                    foreach ($value as &$v) $fn($v, $fn);
333                }
334            ');
335
336            // Unescape data
337            $stripslashes_deep($_POST, $stripslashes_deep);
338            $stripslashes_deep($_GET, $stripslashes_deep);
339            $stripslashes_deep($_COOKIE, $stripslashes_deep);
340        }
341    }
342
343    /**
344     * スーパーグローバル変数「$_REQUEST」を再セット
345     *
346     * variables_order ディレクティブによる差を吸収する。
347     *
348     * @access protected
349     * @return void
350     */
351    function resetSuperglobalsRequest() {
352        $_REQUEST = array_merge($_GET, $_POST);
353    }
354}
355?>
Note: See TracBrowser for help on using the repository browser.