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

Revision 19937, 11.7 KB checked in by Seasoft, 13 years ago (diff)

#903(install.php の取り扱い事故を防ぐ)
#628(未使用処理・定義などの削除)
#627(ソース整形・ソースコメントの改善)

  • 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_URL_PATH', URL_PATH . 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_URL_PATH', URL_PATH . 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_URL を設定する.
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        // DIR_INDEX_FILE にアクセスする時の URL のファイル名部を定義する
174        if (USE_FILENAME_DIR_INDEX === true) {
175            // ファイル名を使用する
176            define('DIR_INDEX_URL', DIR_INDEX_FILE);
177        } else {
178            // ファイル名を使用しない
179            define('DIR_INDEX_URL', '');
180        }
181    }
182
183    /**
184     * 定数を設定する.
185     *
186     * mtb_constants.php を読み込んで定数を設定する.
187     * キャッシュディレクトリに存在しない場合は, 初期データからコピーする.
188     *
189     * @access protected
190     * @return void
191     */
192    function defineConstants() {
193
194        $errorMessage = "<div style='color: #F00; font-weight: bold; "
195            . "background-color: #FEB; text-align: center'>"
196            . CACHE_REALDIR
197            . " にユーザ書込み権限(777等)を付与して下さい。</div>";
198
199        // 定数を設定
200        if (is_file(CACHE_REALDIR . "mtb_constants.php")) {
201            require_once(CACHE_REALDIR . "mtb_constants.php");
202
203            // キャッシュが無ければ, 初期データからコピー
204        } elseif (is_file(CACHE_REALDIR . "../mtb_constants_init.php")) {
205
206            $mtb_constants = file_get_contents(CACHE_REALDIR . "../mtb_constants_init.php");
207            if (is_writable(CACHE_REALDIR)) {
208                $handle = fopen(CACHE_REALDIR . "mtb_constants.php", "w");
209                if (!$handle) {
210                    die($errorMessage);
211                }
212                if (fwrite($handle, $mtb_constants) === false) {
213                    die($errorMessage);
214                }
215                fclose($handle);
216
217                require_once(CACHE_REALDIR . "mtb_constants.php");
218            } else {
219                die($errorMessage);
220            }
221        } else {
222            die(CACHE_REALDIR . "../mtb_constants_init.php が存在しません");
223        }
224    }
225
226    /**
227     * 各種キャッシュディレクトリを生成する.
228     *
229     * Smarty キャッシュディレクトリを生成する.
230     *
231     * @access protected
232     * @return void
233     */
234    function createCacheDir() {
235        if (defined("HTML_REALDIR")) {
236            umask(0);
237            if (!file_exists(COMPILE_DIR)) {
238                mkdir(COMPILE_DIR);
239            }
240
241            if (!file_exists(MOBILE_COMPILE_REALDIR)) {
242                mkdir(MOBILE_COMPILE_REALDIR);
243            }
244
245            if (!file_exists(SMARTPHONE_COMPILE_REALDIR)) {
246                mkdir(SMARTPHONE_COMPILE_REALDIR);
247            }
248
249            if (!file_exists(COMPILE_ADMIN_REALDIR)) {
250                mkdir(COMPILE_ADMIN_REALDIR);
251            }
252        }
253    }
254
255    /**
256     * エラー種別を定数定義
257     *
258     * @access protected
259     * @return void
260     */
261    function defineErrorType() {
262        // LC_Page_Error用
263        /** 指定商品ページがない */
264        define('PRODUCT_NOT_FOUND', 1);
265        /** カート内が空 */
266        define('CART_EMPTY', 2);
267        /** ページ推移エラー */
268        define('PAGE_ERROR', 3);
269        /** 購入処理中のカート商品追加エラー */
270        define('CART_ADD_ERROR', 4);
271        /** 他にも購入手続きが行われた場合 */
272        define('CANCEL_PURCHASE', 5);
273        /** 指定カテゴリページがない */
274        define('CATEGORY_NOT_FOUND', 6);
275        /** ログインに失敗 */
276        define('SITE_LOGIN_ERROR', 7);
277        /** 会員専用ページへのアクセスエラー */
278        define('CUSTOMER_ERROR', 8);
279        /** 購入時の売り切れエラー */
280        define('SOLD_OUT', 9);
281        /** カート内商品の読込エラー */
282        define('CART_NOT_FOUND', 10);
283        /** ポイントの不足 */
284        define('LACK_POINT', 11);
285        /** 仮登録者がログインに失敗 */
286        define('TEMP_LOGIN_ERROR', 12);
287        /** URLエラー */
288        define('URL_ERROR', 13);
289        /** ファイル解凍エラー */
290        define('EXTRACT_ERROR', 14);
291        /** FTPダウンロードエラー */
292        define('FTP_DOWNLOAD_ERROR', 15);
293        /** FTPログインエラー */
294        define('FTP_LOGIN_ERROR', 16);
295        /** FTP接続エラー */
296        define('FTP_CONNECT_ERROR', 17);
297        /** DB作成エラー */
298        define('CREATE_DB_ERROR', 18);
299        /** DBインポートエラー */
300        define('DB_IMPORT_ERROR', 19);
301        /** 設定ファイル存在エラー */
302        define('FILE_NOT_FOUND', 20);
303        /** 書き込みエラー */
304        define('WRITE_FILE_ERROR', 21);
305        /** DB接続エラー */
306        define('DB_CONNECT_ERROR', 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     * クォートされた文字列のクォート部分を再帰的に取り除く
323     *
324     * {@link http://jp2.php.net/manual/ja/function.get-magic-quotes-gpc.php PHP Manual} の記事を参考に実装。
325     * $_REQUEST は後続の処理で再構成されるため、本処理では外している。
326     * @return void
327     */
328    function stripslashesDeepGpc() {
329        // Strip magic quotes from request data.
330        if (get_magic_quotes_gpc()) {
331            // Create lamba style unescaping function (for portability)
332            $quotes_sybase = strtolower(ini_get('magic_quotes_sybase'));
333            $unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)';
334            $stripslashes_deep = create_function('&$value, $fn', '
335                if (is_string($value)) {
336                    $value = ' . $unescape_function . ';
337                } else if (is_array($value)) {
338                    foreach ($value as &$v) $fn($v, $fn);
339                }
340            ');
341
342            // Unescape data
343            $stripslashes_deep($_POST, $stripslashes_deep);
344            $stripslashes_deep($_GET, $stripslashes_deep);
345            $stripslashes_deep($_COOKIE, $stripslashes_deep);
346        }
347    }
348
349    /**
350     * スーパーグローバル変数「$_REQUEST」を再セット
351     *
352     * variables_order ディレクティブによる差を吸収する。
353     *
354     * @access protected
355     * @return void
356     */
357    function resetSuperglobalsRequest() {
358        $_REQUEST = array_merge($_GET, $_POST);
359    }
360}
361?>
Note: See TracBrowser for help on using the repository browser.