| 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 | */ |
|---|
| 30 | class SC_Initial { |
|---|
| 31 | |
|---|
| 32 | // {{{ cunstructor |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * コンストラクタ. |
|---|
| 36 | */ |
|---|
| 37 | function SC_Initial() { |
|---|
| 38 | |
|---|
| 39 | /** EC-CUBEのバージョン */ |
|---|
| 40 | define('ECCUBE_VERSION', "2.4.4"); |
|---|
| 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->checkConvertEncodingAll(); |
|---|
| 59 | $this->createCacheDir(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | * 初期設定ファイルを読み込む. |
|---|
| 64 | * |
|---|
| 65 | * @access protected |
|---|
| 66 | * @return void |
|---|
| 67 | */ |
|---|
| 68 | function requireInitialConfig() { |
|---|
| 69 | |
|---|
| 70 | require_once(realpath(dirname( __FILE__)) ."/../install.php"); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * DSN を定義する. |
|---|
| 75 | * |
|---|
| 76 | * @access protected |
|---|
| 77 | * @return void |
|---|
| 78 | */ |
|---|
| 79 | function defineDSN() { |
|---|
| 80 | if(defined('DB_TYPE') && defined('DB_USER') && defined('DB_PASSWORD') |
|---|
| 81 | && defined('DB_SERVER') && defined('DB_PORT') && defined('DB_NAME')) { |
|---|
| 82 | /** サイト用DB */ |
|---|
| 83 | define ("DEFAULT_DSN", |
|---|
| 84 | DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@" |
|---|
| 85 | . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME); |
|---|
| 86 | } else { |
|---|
| 87 | define("DEFAULT_DSN", "pgsql://nobody:password@localhost:5432/eccubedb"); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | * エラーレベル設定を行う. |
|---|
| 94 | * |
|---|
| 95 | * ・推奨値 |
|---|
| 96 | * 開発時 - E_ALL |
|---|
| 97 | * 運用時 - E_ALL & ~E_NOTICE |
|---|
| 98 | * |
|---|
| 99 | * @access protected |
|---|
| 100 | * @return void |
|---|
| 101 | */ |
|---|
| 102 | function setErrorReporting() { |
|---|
| 103 | error_reporting(E_ALL & ~E_NOTICE); |
|---|
| 104 | // PHP 5.3.0対応 |
|---|
| 105 | if (error_reporting() > 6143) { |
|---|
| 106 | error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | * マルチバイト文字列設定を行う. |
|---|
| 112 | * |
|---|
| 113 | * TODO SJIS-win や, eucJP-win への対応 |
|---|
| 114 | * |
|---|
| 115 | * @access protected |
|---|
| 116 | * @return void |
|---|
| 117 | */ |
|---|
| 118 | function mbstringInit() { |
|---|
| 119 | ini_set("mbstring.http_input", CHAR_CODE); |
|---|
| 120 | ini_set("mbstring.http_output", CHAR_CODE); |
|---|
| 121 | ini_set("auto_detect_line_endings", 1); |
|---|
| 122 | ini_set("default_charset", CHAR_CODE); |
|---|
| 123 | ini_set("mbstring.internal_encoding", CHAR_CODE); |
|---|
| 124 | ini_set("mbstring.detect_order", "auto"); |
|---|
| 125 | ini_set("mbstring.substitute_character", "none"); |
|---|
| 126 | //ロケールを明示的に設定 |
|---|
| 127 | setlocale(LC_ALL, LOCALE); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | /** |
|---|
| 131 | * 文字エンコーディングをチェックし, CHAR_CODE に変換する. |
|---|
| 132 | * |
|---|
| 133 | * $_GET, $_POST, $_REQUEST の文字エンコーディングをチェックし, CHAR_CODE と |
|---|
| 134 | * 一致しない場合は, CHAR_CODE へ変換する. |
|---|
| 135 | * |
|---|
| 136 | * @access protected |
|---|
| 137 | * @return void |
|---|
| 138 | * @see $this->checkConvertEncoding() |
|---|
| 139 | */ |
|---|
| 140 | function checkConvertEncodingAll() { |
|---|
| 141 | $_GET = $this->checkConvertEncoding($_GET); |
|---|
| 142 | $_POST = $this->checkConvertEncoding($_POST); |
|---|
| 143 | $_REQUEST = $this->checkConvertEncoding($_REQUEST); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | /** |
|---|
| 147 | * 配列の要素の文字エンコーディングをチェックし, CHAR_CODE に変換して返す. |
|---|
| 148 | * |
|---|
| 149 | * 引数の配列の要素の文字エンコーディングをチェックし, CHAR_CODE と一致しない |
|---|
| 150 | * 場合は, CHAR_CODE へ変換して返す. |
|---|
| 151 | * |
|---|
| 152 | * 文字エンコーディングの判別は, mb_detect_encoding に依存します. |
|---|
| 153 | * |
|---|
| 154 | * @access private |
|---|
| 155 | * @param array $arrMethod チェック対象の配列 |
|---|
| 156 | * @return array 変換後の配列 |
|---|
| 157 | * @see mb_detect_encoding() |
|---|
| 158 | * @see mb_convert_encoding() |
|---|
| 159 | */ |
|---|
| 160 | function checkConvertEncoding($arrMethod) { |
|---|
| 161 | $arrResult = array(); |
|---|
| 162 | foreach ($arrMethod as $key => $val) { |
|---|
| 163 | if (is_array($val)) { |
|---|
| 164 | $arrResult[$key] = $this->checkConvertEncoding($val); |
|---|
| 165 | } else { |
|---|
| 166 | $encoding = mb_detect_encoding($val); |
|---|
| 167 | if ($encoding !== false && $encoding != CHAR_CODE) { |
|---|
| 168 | $arrResult[$key] = mb_convert_encoding($val, CHAR_CODE, $encoding); |
|---|
| 169 | } else { |
|---|
| 170 | $arrResult[$key] = $val; |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | return $arrResult; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | /** |
|---|
| 178 | * 定数を設定する. |
|---|
| 179 | * |
|---|
| 180 | * mtb_constants.php を読み込んで定数を設定する. |
|---|
| 181 | * キャッシュディレクトリに存在しない場合は, 初期データからコピーする. |
|---|
| 182 | * |
|---|
| 183 | * @access protected |
|---|
| 184 | * @return void |
|---|
| 185 | */ |
|---|
| 186 | function defineConstants() { |
|---|
| 187 | |
|---|
| 188 | $errorMessage = "<div style='color: #F00; font-weight: bold; " |
|---|
| 189 | . "background-color: #FEB; text-align: center'>" |
|---|
| 190 | . CACHE_PATH |
|---|
| 191 | . " にユーザ書込み権限(777等)を付与して下さい。</div>"; |
|---|
| 192 | |
|---|
| 193 | // 定数を設定 |
|---|
| 194 | if (is_file(CACHE_PATH . "mtb_constants.php")) { |
|---|
| 195 | require_once(CACHE_PATH . "mtb_constants.php"); |
|---|
| 196 | |
|---|
| 197 | // キャッシュが無ければ, 初期データからコピー |
|---|
| 198 | } elseif (is_file(CACHE_PATH . "../mtb_constants_init.php")) { |
|---|
| 199 | |
|---|
| 200 | $mtb_constants = file_get_contents(CACHE_PATH . "../mtb_constants_init.php"); |
|---|
| 201 | if (is_writable(CACHE_PATH)) { |
|---|
| 202 | $handle = fopen(CACHE_PATH . "mtb_constants.php", "w"); |
|---|
| 203 | if (!$handle) { |
|---|
| 204 | die($errorMessage); |
|---|
| 205 | } |
|---|
| 206 | if (fwrite($handle, $mtb_constants) === false) { |
|---|
| 207 | die($errorMessage); |
|---|
| 208 | } |
|---|
| 209 | fclose($handle); |
|---|
| 210 | |
|---|
| 211 | require_once(CACHE_PATH . "mtb_constants.php"); |
|---|
| 212 | } else { |
|---|
| 213 | die($errorMessage); |
|---|
| 214 | } |
|---|
| 215 | } else { |
|---|
| 216 | die(CACHE_PATH . "../mtb_constants_init.php が存在しません"); |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | /** |
|---|
| 221 | * 各種キャッシュディレクトリを生成する. |
|---|
| 222 | * |
|---|
| 223 | * Smarty キャッシュディレクトリを生成する. |
|---|
| 224 | * |
|---|
| 225 | * @access protected |
|---|
| 226 | * @return void |
|---|
| 227 | */ |
|---|
| 228 | function createCacheDir() { |
|---|
| 229 | if (defined("HTML_PATH")) { |
|---|
| 230 | umask(0); |
|---|
| 231 | if (!file_exists(COMPILE_DIR)) { |
|---|
| 232 | mkdir(COMPILE_DIR); |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | if (!file_exists(MOBILE_COMPILE_DIR)) { |
|---|
| 236 | mkdir(MOBILE_COMPILE_DIR); |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | if (!file_exists(COMPILE_ADMIN_DIR)) { |
|---|
| 240 | mkdir(COMPILE_ADMIN_DIR); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | if (!file_exists(COMPILE_FTP_DIR)) { |
|---|
| 244 | mkdir(COMPILE_FTP_DIR); |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | ?> |
|---|