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