source: branches/feature-module-update/data/class/SC_Initial.php @ 16889

Revision 16889, 5.4 KB checked in by naka, 16 years ago (diff)

EC-CUBEバージョンアップ

  • 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.0.1");
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
123    /**
124     * 定数を設定する.
125     *
126     * mtb_constants.php を読み込んで定数を設定する.
127     * キャッシュディレクトリに存在しない場合は, 初期データからコピーする.
128     *
129     * @access protected
130     * @return void
131     */
132    function defineConstants() {
133
134        $errorMessage = "<div style='color: #F00; font-weight: bold; "
135            . "background-color: #FEB; text-align: center'>"
136            . CACHE_PATH
137            . " にユーザ書込み権限(777等)を付与して下さい。</div>";
138
139        // 定数を設定
140        if (is_file(CACHE_PATH . "mtb_constants.php")) {
141            require_once(CACHE_PATH . "mtb_constants.php");
142
143            // キャッシュが無ければ, 初期データからコピー
144        } elseif (is_file(CACHE_PATH . "../mtb_constants_init.php")) {
145
146            $mtb_constants = file_get_contents(CACHE_PATH . "../mtb_constants_init.php");
147            if (is_writable(CACHE_PATH)) {
148                $handle = fopen(CACHE_PATH . "mtb_constants.php", "w");
149                if (!$handle) {
150                    die($errorMessage);
151                }
152                if (fwrite($handle, $mtb_constants) === false) {
153                    die($errorMessage);
154                }
155                fclose($handle);
156
157                require_once(CACHE_PATH . "mtb_constants.php");
158            } else {
159                die($errorMessage);
160            }
161        } else {
162            die(CACHE_PATH . "../mtb_constants_init.php が存在しません");
163        }
164    }
165
166    /**
167     * 各種キャッシュディレクトリを生成する.
168     *
169     * Smarty キャッシュディレクトリを生成する.
170     *
171     * @access protected
172     * @return void
173     */
174    function createCacheDir() {
175        if (defined("HTML_PATH")) {
176            if (!file_exists(COMPILE_DIR)) {
177                mkdir(COMPILE_DIR);
178            }
179
180            if (!file_exists(MOBILE_COMPILE_DIR)) {
181                mkdir(MOBILE_COMPILE_DIR);
182            }
183
184            if (!file_exists(COMPILE_ADMIN_DIR)) {
185                mkdir(COMPILE_ADMIN_DIR);
186            }
187
188            if (!file_exists(COMPILE_FTP_DIR)) {
189                mkdir(COMPILE_FTP_DIR);
190            }
191        }
192    }
193}
194?>
Note: See TracBrowser for help on using the repository browser.