source: branches/version-2/data/class/SC_Initial.php @ 18007

Revision 18007, 5.5 KB checked in by kajiwara, 15 years ago (diff)

2.4.0 正式版のコミット。コミット内容の詳細はこちら(http://svn.ec-cube.net/open_trac/query?status=closed&milestone=EC-CUBE2.4.0

  • 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
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 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.4.0");
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->defineConstants();
57        $this->mbstringInit();
58        $this->createCacheDir();
59    }
60
61    /**
62     * 初期設定ファイルを読み込む.
63     *
64     * @access protected
65     * @return void
66     */
67    function requireInitialConfig() {
68
69        require_once(realpath(dirname( __FILE__)) ."/../install.php");
70    }
71
72    /**
73     * DSN を定義する.
74     *
75     * @access protected
76     * @return void
77     */
78    function defineDSN() {
79        if(defined('DB_TYPE') && defined('DB_USER') && defined('DB_PASSWORD')
80           && defined('DB_SERVER') && defined('DB_PORT') && defined('DB_NAME')) {
81            /** サイト用DB */
82            define ("DEFAULT_DSN",
83                    DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@"
84                    . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME);
85        } else {
86            define("DEFAULT_DSN", "pgsql://nobody:password@localhost:5432/eccubedb");
87        }
88    }
89
90
91    /**
92     * エラーレベル設定を行う.
93     *
94     * ・推奨値
95     *   開発時 - E_ALL
96     *   運用時 - E_ALL & ~E_NOTICE
97     *
98     * @access protected
99     * @return void
100     */
101    function setErrorReporting() {
102        error_reporting(E_ALL & ~E_NOTICE);
103    }
104
105    /**
106     * マルチバイト文字列設定を行う.
107     *
108     * TODO SJIS-win や, eucJP-win への対応
109     *
110     * @access protected
111     * @return void
112     */
113    function mbstringInit() {
114        ini_set("mbstring.http_input", CHAR_CODE);
115        ini_set("mbstring.http_output", CHAR_CODE);
116        ini_set("auto_detect_line_endings", 1);
117        ini_set("default_charset", CHAR_CODE);
118        ini_set("mbstring.internal_encoding", CHAR_CODE);
119        ini_set("mbstring.detect_order", "auto");
120        ini_set("mbstring.substitute_character", "none");
121        //ロケールを明示的に設定
122        setlocale(LC_ALL, LOCALE);
123    }
124
125    /**
126     * 定数を設定する.
127     *
128     * mtb_constants.php を読み込んで定数を設定する.
129     * キャッシュディレクトリに存在しない場合は, 初期データからコピーする.
130     *
131     * @access protected
132     * @return void
133     */
134    function defineConstants() {
135
136        $errorMessage = "<div style='color: #F00; font-weight: bold; "
137            . "background-color: #FEB; text-align: center'>"
138            . CACHE_PATH
139            . " にユーザ書込み権限(777等)を付与して下さい。</div>";
140
141        // 定数を設定
142        if (is_file(CACHE_PATH . "mtb_constants.php")) {
143            require_once(CACHE_PATH . "mtb_constants.php");
144
145            // キャッシュが無ければ, 初期データからコピー
146        } elseif (is_file(CACHE_PATH . "../mtb_constants_init.php")) {
147
148            $mtb_constants = file_get_contents(CACHE_PATH . "../mtb_constants_init.php");
149            if (is_writable(CACHE_PATH)) {
150                $handle = fopen(CACHE_PATH . "mtb_constants.php", "w");
151                if (!$handle) {
152                    die($errorMessage);
153                }
154                if (fwrite($handle, $mtb_constants) === false) {
155                    die($errorMessage);
156                }
157                fclose($handle);
158
159                require_once(CACHE_PATH . "mtb_constants.php");
160            } else {
161                die($errorMessage);
162            }
163        } else {
164            die(CACHE_PATH . "../mtb_constants_init.php が存在しません");
165        }
166    }
167
168    /**
169     * 各種キャッシュディレクトリを生成する.
170     *
171     * Smarty キャッシュディレクトリを生成する.
172     *
173     * @access protected
174     * @return void
175     */
176    function createCacheDir() {
177        if (defined("HTML_PATH")) {
178            umask(0);
179            if (!file_exists(COMPILE_DIR)) {
180                mkdir(COMPILE_DIR);
181            }
182
183            if (!file_exists(MOBILE_COMPILE_DIR)) {
184                mkdir(MOBILE_COMPILE_DIR);
185            }
186
187            if (!file_exists(COMPILE_ADMIN_DIR)) {
188                mkdir(COMPILE_ADMIN_DIR);
189            }
190
191            if (!file_exists(COMPILE_FTP_DIR)) {
192                mkdir(COMPILE_FTP_DIR);
193            }
194        }
195    }
196}
197?>
Note: See TracBrowser for help on using the repository browser.