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

Revision 19724, 10.3 KB checked in by Seasoft, 13 years ago (diff)

#787(スマートフォン対応)

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