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