[16506] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[20764] | 5 | * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved. |
---|
[16506] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 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. |
---|
[16506] | 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のバージョン */ |
---|
[21179] | 40 | define('ECCUBE_VERSION', '2.11.3-dev'); |
---|
[16506] | 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(); |
---|
[21258] | 55 | $this->setErrorReporting(); |
---|
[17605] | 56 | $this->defineDirectoryIndex(); |
---|
[18287] | 57 | $this->defineErrorType(); |
---|
[16509] | 58 | $this->defineConstants(); |
---|
[20947] | 59 | $this->complementConstants(); |
---|
[19850] | 60 | $this->phpconfigInit(); |
---|
[16506] | 61 | $this->createCacheDir(); |
---|
[19760] | 62 | $this->stripslashesDeepGpc(); |
---|
[18361] | 63 | $this->resetSuperglobalsRequest(); |
---|
[16506] | 64 | } |
---|
| 65 | |
---|
| 66 | /** |
---|
[19713] | 67 | * 初期設定ファイルを読み込み, パスの設定を行う. |
---|
[16506] | 68 | * |
---|
| 69 | * @access protected |
---|
| 70 | * @return void |
---|
| 71 | */ |
---|
| 72 | function requireInitialConfig() { |
---|
| 73 | |
---|
[19937] | 74 | define('CONFIG_REALFILE', realpath(dirname(__FILE__)) . '/../config/config.php'); |
---|
| 75 | if (file_exists(CONFIG_REALFILE)) { |
---|
[20534] | 76 | require_once CONFIG_REALFILE; |
---|
[19937] | 77 | } |
---|
[16506] | 78 | } |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * DSN を定義する. |
---|
| 82 | * |
---|
| 83 | * @access protected |
---|
| 84 | * @return void |
---|
| 85 | */ |
---|
| 86 | function defineDSN() { |
---|
| 87 | if(defined('DB_TYPE') && defined('DB_USER') && defined('DB_PASSWORD') |
---|
| 88 | && defined('DB_SERVER') && defined('DB_PORT') && defined('DB_NAME')) { |
---|
| 89 | /** サイト用DB */ |
---|
| 90 | define ("DEFAULT_DSN", |
---|
| 91 | DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@" |
---|
| 92 | . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME); |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /** |
---|
[21258] | 97 | * エラーレベル設定を行う. |
---|
| 98 | * |
---|
| 99 | * ・推奨値 |
---|
| 100 | * 開発時 - E_ALL |
---|
| 101 | * 運用時 - E_ALL & ~E_NOTICE |
---|
| 102 | * |
---|
| 103 | * @access protected |
---|
| 104 | * @return void |
---|
| 105 | */ |
---|
| 106 | function setErrorReporting() { |
---|
| 107 | error_reporting(E_ALL & ~E_NOTICE); |
---|
| 108 | // PHP 5.3.0対応 |
---|
| 109 | if (error_reporting() > 6143) { |
---|
| 110 | error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
[16506] | 115 | * マルチバイト文字列設定を行う. |
---|
| 116 | * |
---|
| 117 | * TODO SJIS-win や, eucJP-win への対応 |
---|
| 118 | * |
---|
| 119 | * @access protected |
---|
| 120 | * @return void |
---|
| 121 | */ |
---|
[19850] | 122 | function phpconfigInit() { |
---|
[19937] | 123 | ini_set('display_errors', '1'); |
---|
[21264] | 124 | ini_set('html_errors', '1'); |
---|
[19937] | 125 | ini_set('mbstring.http_input', CHAR_CODE); |
---|
| 126 | ini_set('mbstring.http_output', CHAR_CODE); |
---|
| 127 | ini_set('auto_detect_line_endings', 1); |
---|
| 128 | ini_set('default_charset', CHAR_CODE); |
---|
| 129 | ini_set('mbstring.internal_encoding', CHAR_CODE); |
---|
| 130 | ini_set('mbstring.detect_order', 'auto'); |
---|
| 131 | ini_set('mbstring.substitute_character', 'none'); |
---|
[18795] | 132 | |
---|
[17347] | 133 | mb_language('ja'); // mb_internal_encoding() より前に |
---|
| 134 | // TODO 他に mb_language() している箇所の削除を検討 |
---|
| 135 | // TODO .htaccess の mbstring.language を削除できないか検討 |
---|
[18795] | 136 | |
---|
[17347] | 137 | mb_internal_encoding(CHAR_CODE); // mb_language() より後で |
---|
[19937] | 138 | // TODO 上の「ini_set('mbstring.internal_encoding', CHAR_CODE);」を削除できないか検討 |
---|
[17347] | 139 | // TODO .htaccess の mbstring.internal_encoding を削除できないか検討 |
---|
[18795] | 140 | |
---|
[19937] | 141 | ini_set('arg_separator.output', '&'); |
---|
[20540] | 142 | |
---|
[17067] | 143 | //ロケールを明示的に設定 |
---|
[20811] | 144 | $res = setlocale(LC_ALL, LOCALE); |
---|
| 145 | if($res === FALSE) { |
---|
| 146 | // TODO: Windows上のロケール設定が正常に働かない場合があることに暫定的に対応 |
---|
| 147 | // ''を指定するとApache実行環境の環境変数が使われる |
---|
| 148 | // See also: http://php.net/manual/ja/function.setlocale.php |
---|
| 149 | setlocale(LC_ALL, ''); |
---|
| 150 | } |
---|
[16506] | 151 | } |
---|
| 152 | |
---|
| 153 | /** |
---|
[19998] | 154 | * 定数 DIR_INDEX_PATH を設定する. |
---|
[17605] | 155 | * |
---|
| 156 | * @access protected |
---|
| 157 | * @return void |
---|
| 158 | */ |
---|
| 159 | function defineDirectoryIndex() { |
---|
[18795] | 160 | |
---|
[17605] | 161 | // DirectoryIndex の実ファイル名 |
---|
| 162 | if (!defined('DIR_INDEX_FILE')) { |
---|
| 163 | define('DIR_INDEX_FILE', 'index.php'); |
---|
| 164 | } |
---|
[18795] | 165 | |
---|
[19998] | 166 | $useFilenameDirIndex = is_bool(USE_FILENAME_DIR_INDEX) |
---|
| 167 | ? USE_FILENAME_DIR_INDEX |
---|
[20047] | 168 | : (isset($_SERVER['SERVER_SOFTWARE']) ? substr($_SERVER['SERVER_SOFTWARE'], 0, 13) == 'Microsoft-IIS' : false) |
---|
[19998] | 169 | ; |
---|
| 170 | |
---|
[17605] | 171 | // DIR_INDEX_FILE にアクセスする時の URL のファイル名部を定義する |
---|
[19998] | 172 | if ($useFilenameDirIndex === true) { |
---|
[17605] | 173 | // ファイル名を使用する |
---|
[19998] | 174 | define('DIR_INDEX_PATH', DIR_INDEX_FILE); |
---|
[17605] | 175 | } else { |
---|
| 176 | // ファイル名を使用しない |
---|
[19998] | 177 | define('DIR_INDEX_PATH', ''); |
---|
[17605] | 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | /** |
---|
[16506] | 182 | * 定数を設定する. |
---|
| 183 | * |
---|
| 184 | * mtb_constants.php を読み込んで定数を設定する. |
---|
| 185 | * キャッシュディレクトリに存在しない場合は, 初期データからコピーする. |
---|
| 186 | * |
---|
| 187 | * @access protected |
---|
| 188 | * @return void |
---|
| 189 | */ |
---|
| 190 | function defineConstants() { |
---|
| 191 | |
---|
[20538] | 192 | $errorMessage |
---|
| 193 | = '<div style="color: #F00; font-weight: bold; background-color: #FEB; text-align: center">' |
---|
[19805] | 194 | . CACHE_REALDIR |
---|
[20538] | 195 | . ' にユーザ書込み権限(777等)を付与して下さい。</div>'; |
---|
[16506] | 196 | |
---|
| 197 | // 定数を設定 |
---|
[19805] | 198 | if (is_file(CACHE_REALDIR . "mtb_constants.php")) { |
---|
[20534] | 199 | require_once CACHE_REALDIR . 'mtb_constants.php'; |
---|
[16506] | 200 | |
---|
| 201 | // キャッシュが無ければ, 初期データからコピー |
---|
[19805] | 202 | } elseif (is_file(CACHE_REALDIR . "../mtb_constants_init.php")) { |
---|
[16506] | 203 | |
---|
[19805] | 204 | $mtb_constants = file_get_contents(CACHE_REALDIR . "../mtb_constants_init.php"); |
---|
| 205 | if (is_writable(CACHE_REALDIR)) { |
---|
[20538] | 206 | $handle = fopen(CACHE_REALDIR . "mtb_constants.php", 'w'); |
---|
[16506] | 207 | if (!$handle) { |
---|
| 208 | die($errorMessage); |
---|
| 209 | } |
---|
| 210 | if (fwrite($handle, $mtb_constants) === false) { |
---|
| 211 | die($errorMessage); |
---|
| 212 | } |
---|
| 213 | fclose($handle); |
---|
| 214 | |
---|
[20534] | 215 | require_once CACHE_REALDIR . 'mtb_constants.php'; |
---|
[16506] | 216 | } else { |
---|
| 217 | die($errorMessage); |
---|
| 218 | } |
---|
| 219 | } else { |
---|
[19805] | 220 | die(CACHE_REALDIR . "../mtb_constants_init.php が存在しません"); |
---|
[16506] | 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | /** |
---|
[20970] | 225 | * パラメーターの補完 |
---|
[20947] | 226 | * |
---|
| 227 | * ソースのみ差し替えたバージョンアップを考慮したもの。 |
---|
| 228 | * |
---|
| 229 | * @access protected |
---|
| 230 | * @return void |
---|
| 231 | */ |
---|
| 232 | function complementConstants() { |
---|
| 233 | // 2.11.1 → 2.11.2 |
---|
| 234 | /** 郵便番号CSVのZIPアーカイブファイルの取得元 */ |
---|
| 235 | $this->defineIfNotDefined('ZIP_DOWNLOAD_URL', "http://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip"); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | /** |
---|
[16506] | 239 | * 各種キャッシュディレクトリを生成する. |
---|
| 240 | * |
---|
| 241 | * Smarty キャッシュディレクトリを生成する. |
---|
| 242 | * |
---|
| 243 | * @access protected |
---|
| 244 | * @return void |
---|
| 245 | */ |
---|
| 246 | function createCacheDir() { |
---|
[19805] | 247 | if (defined("HTML_REALDIR")) { |
---|
[17672] | 248 | umask(0); |
---|
[19987] | 249 | if (!file_exists(COMPILE_REALDIR)) { |
---|
| 250 | mkdir(COMPILE_REALDIR); |
---|
[16506] | 251 | } |
---|
| 252 | |
---|
[19805] | 253 | if (!file_exists(MOBILE_COMPILE_REALDIR)) { |
---|
| 254 | mkdir(MOBILE_COMPILE_REALDIR); |
---|
[16506] | 255 | } |
---|
| 256 | |
---|
[19805] | 257 | if (!file_exists(SMARTPHONE_COMPILE_REALDIR)) { |
---|
| 258 | mkdir(SMARTPHONE_COMPILE_REALDIR); |
---|
[19713] | 259 | } |
---|
| 260 | |
---|
[19805] | 261 | if (!file_exists(COMPILE_ADMIN_REALDIR)) { |
---|
| 262 | mkdir(COMPILE_ADMIN_REALDIR); |
---|
[16506] | 263 | } |
---|
| 264 | } |
---|
| 265 | } |
---|
[18287] | 266 | |
---|
| 267 | /** |
---|
| 268 | * エラー種別を定数定義 |
---|
| 269 | * |
---|
| 270 | * @access protected |
---|
| 271 | * @return void |
---|
| 272 | */ |
---|
| 273 | function defineErrorType() { |
---|
| 274 | // LC_Page_Error用 |
---|
| 275 | /** 指定商品ページがない */ |
---|
| 276 | define('PRODUCT_NOT_FOUND', 1); |
---|
| 277 | /** カート内が空 */ |
---|
| 278 | define('CART_EMPTY', 2); |
---|
| 279 | /** ページ推移エラー */ |
---|
| 280 | define('PAGE_ERROR', 3); |
---|
| 281 | /** 購入処理中のカート商品追加エラー */ |
---|
| 282 | define('CART_ADD_ERROR', 4); |
---|
| 283 | /** 他にも購入手続きが行われた場合 */ |
---|
| 284 | define('CANCEL_PURCHASE', 5); |
---|
| 285 | /** 指定カテゴリページがない */ |
---|
| 286 | define('CATEGORY_NOT_FOUND', 6); |
---|
| 287 | /** ログインに失敗 */ |
---|
| 288 | define('SITE_LOGIN_ERROR', 7); |
---|
| 289 | /** 会員専用ページへのアクセスエラー */ |
---|
| 290 | define('CUSTOMER_ERROR', 8); |
---|
| 291 | /** 購入時の売り切れエラー */ |
---|
| 292 | define('SOLD_OUT', 9); |
---|
| 293 | /** カート内商品の読込エラー */ |
---|
| 294 | define('CART_NOT_FOUND', 10); |
---|
| 295 | /** ポイントの不足 */ |
---|
| 296 | define('LACK_POINT', 11); |
---|
| 297 | /** 仮登録者がログインに失敗 */ |
---|
| 298 | define('TEMP_LOGIN_ERROR', 12); |
---|
| 299 | /** URLエラー */ |
---|
| 300 | define('URL_ERROR', 13); |
---|
| 301 | /** ファイル解凍エラー */ |
---|
| 302 | define('EXTRACT_ERROR', 14); |
---|
| 303 | /** FTPダウンロードエラー */ |
---|
| 304 | define('FTP_DOWNLOAD_ERROR', 15); |
---|
| 305 | /** FTPログインエラー */ |
---|
| 306 | define('FTP_LOGIN_ERROR', 16); |
---|
| 307 | /** FTP接続エラー */ |
---|
| 308 | define('FTP_CONNECT_ERROR', 17); |
---|
| 309 | /** DB作成エラー */ |
---|
| 310 | define('CREATE_DB_ERROR', 18); |
---|
| 311 | /** DBインポートエラー */ |
---|
| 312 | define('DB_IMPORT_ERROR', 19); |
---|
| 313 | /** 設定ファイル存在エラー */ |
---|
| 314 | define('FILE_NOT_FOUND', 20); |
---|
| 315 | /** 書き込みエラー */ |
---|
| 316 | define('WRITE_FILE_ERROR', 21); |
---|
| 317 | /** DB接続エラー */ |
---|
| 318 | define('DB_CONNECT_ERROR', 22); |
---|
| 319 | /** フリーメッセージ */ |
---|
| 320 | define('FREE_ERROR_MSG', 999); |
---|
| 321 | |
---|
| 322 | // LC_Page_Error_DispError用 |
---|
| 323 | /** ログイン失敗 */ |
---|
| 324 | define('LOGIN_ERROR', 1); |
---|
| 325 | /** アクセス失敗(タイムアウト等) */ |
---|
| 326 | define('ACCESS_ERROR', 2); |
---|
| 327 | /** アクセス権限違反 */ |
---|
| 328 | define('AUTH_ERROR', 3); |
---|
| 329 | /** 不正な遷移エラー */ |
---|
| 330 | define('INVALID_MOVE_ERRORR', 4); |
---|
| 331 | } |
---|
[18361] | 332 | |
---|
| 333 | /** |
---|
[20452] | 334 | * クォートされた文字列のクォート部分を再帰的に取り除く. |
---|
[19760] | 335 | * |
---|
| 336 | * {@link http://jp2.php.net/manual/ja/function.get-magic-quotes-gpc.php PHP Manual} の記事を参考に実装。 |
---|
| 337 | * $_REQUEST は後続の処理で再構成されるため、本処理では外している。 |
---|
[20452] | 338 | * この関数は, PHP5以上を対象とし, PHP4 の場合は何もしない. |
---|
| 339 | * |
---|
[19760] | 340 | * @return void |
---|
| 341 | */ |
---|
| 342 | function stripslashesDeepGpc() { |
---|
| 343 | // Strip magic quotes from request data. |
---|
[20452] | 344 | if (get_magic_quotes_gpc() |
---|
| 345 | && version_compare(PHP_VERSION, '5.0.0', '>=')) { |
---|
[19760] | 346 | // Create lamba style unescaping function (for portability) |
---|
| 347 | $quotes_sybase = strtolower(ini_get('magic_quotes_sybase')); |
---|
| 348 | $unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)'; |
---|
| 349 | $stripslashes_deep = create_function('&$value, $fn', ' |
---|
| 350 | if (is_string($value)) { |
---|
| 351 | $value = ' . $unescape_function . '; |
---|
| 352 | } else if (is_array($value)) { |
---|
| 353 | foreach ($value as &$v) $fn($v, $fn); |
---|
| 354 | } |
---|
| 355 | '); |
---|
| 356 | |
---|
| 357 | // Unescape data |
---|
| 358 | $stripslashes_deep($_POST, $stripslashes_deep); |
---|
| 359 | $stripslashes_deep($_GET, $stripslashes_deep); |
---|
| 360 | $stripslashes_deep($_COOKIE, $stripslashes_deep); |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | /** |
---|
[18361] | 365 | * スーパーグローバル変数「$_REQUEST」を再セット |
---|
| 366 | * |
---|
| 367 | * variables_order ディレクティブによる差を吸収する。 |
---|
| 368 | * |
---|
| 369 | * @access protected |
---|
| 370 | * @return void |
---|
| 371 | */ |
---|
| 372 | function resetSuperglobalsRequest() { |
---|
| 373 | $_REQUEST = array_merge($_GET, $_POST); |
---|
| 374 | } |
---|
[20947] | 375 | |
---|
| 376 | /** |
---|
| 377 | * 指定された名前の定数が存在しない場合、指定された値で定義 |
---|
| 378 | * |
---|
| 379 | * @param string $name 定数の名前。 |
---|
| 380 | * @param mixed $value 定数の値。 |
---|
[20948] | 381 | * @return void |
---|
[20947] | 382 | */ |
---|
| 383 | function defineIfNotDefined($name, $value = null) { |
---|
| 384 | if (!defined($name)) { |
---|
| 385 | define($name, $value); |
---|
| 386 | } |
---|
| 387 | } |
---|
[16506] | 388 | } |
---|
| 389 | ?> |
---|