| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2013 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 | * Web Page を制御する基底クラス |
|---|
| 26 | * |
|---|
| 27 | * Web Page を制御する Page クラスは必ずこのクラスを継承する. |
|---|
| 28 | * PHP4 ではこのような抽象クラスを作っても継承先で何でもできてしまうため、 |
|---|
| 29 | * あまり意味がないが、アーキテクトを統一するために作っておく. |
|---|
| 30 | * |
|---|
| 31 | * @package Page |
|---|
| 32 | * @author LOCKON CO.,LTD. |
|---|
| 33 | * @version $Id:LC_Page.php 15532 2007-08-31 14:39:46Z nanasess $ |
|---|
| 34 | */ |
|---|
| 35 | class LC_Page { |
|---|
| 36 | |
|---|
| 37 | // {{{ properties |
|---|
| 38 | |
|---|
| 39 | /** メインテンプレート */ |
|---|
| 40 | var $tpl_mainpage; |
|---|
| 41 | |
|---|
| 42 | /** テンプレートのカラム数 */ |
|---|
| 43 | var $tpl_column_num; |
|---|
| 44 | |
|---|
| 45 | /** メインナンバー */ |
|---|
| 46 | var $tpl_mainno; |
|---|
| 47 | |
|---|
| 48 | /** CSS のパス */ |
|---|
| 49 | var $tpl_css; |
|---|
| 50 | |
|---|
| 51 | /** JavaScript */ |
|---|
| 52 | var $tpl_javascript; |
|---|
| 53 | |
|---|
| 54 | /** タイトル */ |
|---|
| 55 | var $tpl_title; |
|---|
| 56 | |
|---|
| 57 | /** カテゴリ */ |
|---|
| 58 | var $tpl_page_category; |
|---|
| 59 | |
|---|
| 60 | /** ログインメールアドレス */ |
|---|
| 61 | var $tpl_login_email; |
|---|
| 62 | |
|---|
| 63 | /** HTML ロード後に実行する JavaScript コード */ |
|---|
| 64 | var $tpl_onload; |
|---|
| 65 | |
|---|
| 66 | /** トランザクションID */ |
|---|
| 67 | var $transactionid; |
|---|
| 68 | |
|---|
| 69 | /** メインテンプレート名 */ |
|---|
| 70 | var $template = SITE_FRAME; |
|---|
| 71 | |
|---|
| 72 | /** 店舗基本情報 */ |
|---|
| 73 | var $arrSiteInfo; |
|---|
| 74 | |
|---|
| 75 | /** プラグインを実行フラグ */ |
|---|
| 76 | var $plugin_activate_flg = PLUGIN_ACTIVATE_FLAG; |
|---|
| 77 | |
|---|
| 78 | // }}} |
|---|
| 79 | // {{{ functions |
|---|
| 80 | |
|---|
| 81 | /** |
|---|
| 82 | * Page を初期化する. |
|---|
| 83 | * |
|---|
| 84 | * @return void |
|---|
| 85 | */ |
|---|
| 86 | function init() { |
|---|
| 87 | // 開始時刻を設定する。 |
|---|
| 88 | $this->timeStart = microtime(true); |
|---|
| 89 | |
|---|
| 90 | $this->tpl_authority = $_SESSION['authority']; |
|---|
| 91 | |
|---|
| 92 | // ディスプレイクラス生成 |
|---|
| 93 | $this->objDisplay = new SC_Display_Ex(); |
|---|
| 94 | |
|---|
| 95 | $layout = new SC_Helper_PageLayout_Ex(); |
|---|
| 96 | $layout->sfGetPageLayout($this, false, $_SERVER['SCRIPT_NAME'], |
|---|
| 97 | $this->objDisplay->detectDevice()); |
|---|
| 98 | |
|---|
| 99 | // スーパーフックポイントを実行. |
|---|
| 100 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg); |
|---|
| 101 | $objPlugin->doAction('LC_Page_preProcess', array($this)); |
|---|
| 102 | |
|---|
| 103 | // 店舗基本情報取得 |
|---|
| 104 | $this->arrSiteInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
|---|
| 105 | |
|---|
| 106 | // トランザクショントークンの検証と生成 |
|---|
| 107 | $this->doValidToken(); |
|---|
| 108 | $this->setTokenTo(); |
|---|
| 109 | |
|---|
| 110 | // ローカルフックポイントを実行. |
|---|
| 111 | $this->doLocalHookpointBefore($objPlugin); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * Page のプロセス. |
|---|
| 116 | * |
|---|
| 117 | * @return void |
|---|
| 118 | */ |
|---|
| 119 | function process() {} |
|---|
| 120 | |
|---|
| 121 | /** |
|---|
| 122 | * Page のレスポンス送信. |
|---|
| 123 | * |
|---|
| 124 | * @return void |
|---|
| 125 | */ |
|---|
| 126 | function sendResponse() { |
|---|
| 127 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg); |
|---|
| 128 | // ローカルフックポイントを実行. |
|---|
| 129 | $this->doLocalHookpointAfter($objPlugin); |
|---|
| 130 | |
|---|
| 131 | // HeadNaviにpluginテンプレートを追加する. |
|---|
| 132 | $objPlugin->setHeadNaviBlocs($this->arrPageLayout['HeadNavi']); |
|---|
| 133 | |
|---|
| 134 | // スーパーフックポイントを実行. |
|---|
| 135 | $objPlugin->doAction('LC_Page_process', array($this)); |
|---|
| 136 | |
|---|
| 137 | // ページクラス名をテンプレートに渡す |
|---|
| 138 | $arrBacktrace = debug_backtrace(); |
|---|
| 139 | if (strlen($this->tpl_page_class_name) === 0) { |
|---|
| 140 | $this->tpl_page_class_name = $arrBacktrace[1]['class']; |
|---|
| 141 | $this->tpl_page_class_name = preg_replace('/_Ex$/', '', $this->tpl_page_class_name); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | $this->objDisplay->prepare($this); |
|---|
| 145 | $this->objDisplay->response->write(); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | /** |
|---|
| 149 | * Page のレスポンス送信(ダウンロード). |
|---|
| 150 | * |
|---|
| 151 | * @return void |
|---|
| 152 | */ |
|---|
| 153 | function sendResponseCSV($file_name, $data) { |
|---|
| 154 | $this->objDisplay->prepare($this); |
|---|
| 155 | $this->objDisplay->addHeader('Content-disposition', "attachment; filename=${file_name}"); |
|---|
| 156 | $this->objDisplay->addHeader('Content-type', "application/octet-stream; name=${file_name}"); |
|---|
| 157 | $this->objDisplay->addHeader('Cache-Control', ''); |
|---|
| 158 | $this->objDisplay->addHeader('Pragma', ''); |
|---|
| 159 | |
|---|
| 160 | $this->objDisplay->response->body = $data; |
|---|
| 161 | $this->objDisplay->response->write(); |
|---|
| 162 | SC_Response_Ex::actionExit(); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | /** |
|---|
| 166 | * デストラクタ. |
|---|
| 167 | * |
|---|
| 168 | * @return void |
|---|
| 169 | */ |
|---|
| 170 | function destroy() { |
|---|
| 171 | // 一定時間以上かかったページの場合、ログ出力する。 |
|---|
| 172 | // エラー画面の表示では $this->timeStart が出力されない |
|---|
| 173 | if (defined('PAGE_DISPLAY_TIME_LOG_MODE') && PAGE_DISPLAY_TIME_LOG_MODE == true && isset($this->timeStart)) { |
|---|
| 174 | $timeEnd = microtime(true); |
|---|
| 175 | $timeExecTime = $timeEnd - $this->timeStart; |
|---|
| 176 | if (defined('PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME') && $timeExecTime >= (float)PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME) { |
|---|
| 177 | $logMsg = sprintf('PAGE_DISPLAY_TIME_LOG [%.2fsec]', $timeExecTime); |
|---|
| 178 | GC_Utils_Ex::gfPrintLog($logMsg); |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | /** |
|---|
| 184 | * ローカルフックポイントを生成し、実行します. |
|---|
| 185 | * |
|---|
| 186 | * @param SC_Helper_Plugin_Ex $objPlugin |
|---|
| 187 | * @return void |
|---|
| 188 | */ |
|---|
| 189 | function doLocalHookpointBefore(SC_Helper_Plugin_Ex $objPlugin) { |
|---|
| 190 | // ローカルフックポイントを実行 |
|---|
| 191 | $parent_class_name = get_parent_class($this); |
|---|
| 192 | if ($parent_class_name != 'LC_Page') { |
|---|
| 193 | $objPlugin->doAction($parent_class_name . '_action_before', array($this)); |
|---|
| 194 | } |
|---|
| 195 | $class_name = get_class($this); |
|---|
| 196 | if ($parent_class_name != 'LC_Page' && $class_name != $parent_class_name) { |
|---|
| 197 | $objPlugin->doAction($class_name . '_action_before', array($this)); |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | /** |
|---|
| 202 | * ローカルフックポイントを生成し、実行します. |
|---|
| 203 | * |
|---|
| 204 | * @param SC_Helper_Plugin_Ex $objPlugin |
|---|
| 205 | * @return void |
|---|
| 206 | */ |
|---|
| 207 | function doLocalHookpointAfter(SC_Helper_Plugin_Ex $objPlugin) { |
|---|
| 208 | // ローカルフックポイントを実行 |
|---|
| 209 | $parent_class_name = get_parent_class($this); |
|---|
| 210 | if ($parent_class_name != 'LC_Page') { |
|---|
| 211 | $objPlugin->doAction($parent_class_name . '_action_after', array($this)); |
|---|
| 212 | } |
|---|
| 213 | $class_name = get_class($this); |
|---|
| 214 | if ($parent_class_name != 'LC_Page' && $class_name != $parent_class_name) { |
|---|
| 215 | $objPlugin->doAction($class_name . '_action_after', array($this)); |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | /** |
|---|
| 220 | * テンプレート取得 |
|---|
| 221 | * |
|---|
| 222 | */ |
|---|
| 223 | function getTemplate() { |
|---|
| 224 | return $this->template; |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | /** |
|---|
| 228 | * テンプレート設定(ポップアップなどの場合) |
|---|
| 229 | * |
|---|
| 230 | */ |
|---|
| 231 | function setTemplate($template) { |
|---|
| 232 | $this->template = $template; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | /** |
|---|
| 236 | * $path から URL を取得する. |
|---|
| 237 | * |
|---|
| 238 | * 以下の順序で 引数 $path から URL を取得する. |
|---|
| 239 | * 1. realpath($path) で $path の 絶対パスを取得 |
|---|
| 240 | * 2. $_SERVER['DOCUMENT_ROOT'] と一致する文字列を削除 |
|---|
| 241 | * 3. $useSSL の値に応じて, HTTP_URL 又は, HTTPS_URL を付与する. |
|---|
| 242 | * |
|---|
| 243 | * 返り値に, QUERY_STRING を含めたい場合は, key => value 形式 |
|---|
| 244 | * の配列を $param へ渡す. |
|---|
| 245 | * |
|---|
| 246 | * @access protected |
|---|
| 247 | * @param string $path 結果を取得するためのパス |
|---|
| 248 | * @param array $param URL に付与するパラメーターの配列 |
|---|
| 249 | * @param mixed $useSSL 結果に HTTPS_URL を使用する場合 true, |
|---|
| 250 | * HTTP_URL を使用する場合 false, |
|---|
| 251 | * デフォルト 'escape' 現在のスキーマを使用 |
|---|
| 252 | * @return string $path の存在する http(s):// から始まる絶対パス |
|---|
| 253 | * @see Net_URL |
|---|
| 254 | */ |
|---|
| 255 | function getLocation($path, $param = array(), $useSSL = 'escape') { |
|---|
| 256 | $rootPath = $this->getRootPath($path); |
|---|
| 257 | |
|---|
| 258 | // スキーマを定義 |
|---|
| 259 | if ($useSSL === true) { |
|---|
| 260 | $url = HTTPS_URL . $rootPath; |
|---|
| 261 | } elseif ($useSSL === false) { |
|---|
| 262 | $url = HTTP_URL . $rootPath; |
|---|
| 263 | } elseif ($useSSL == 'escape') { |
|---|
| 264 | if (SC_Utils_Ex::sfIsHTTPS()) { |
|---|
| 265 | $url = HTTPS_URL . $rootPath; |
|---|
| 266 | } else { |
|---|
| 267 | $url = HTTP_URL . $rootPath; |
|---|
| 268 | } |
|---|
| 269 | } else { |
|---|
| 270 | die("[BUG] Illegal Parametor of \$useSSL "); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | $netURL = new Net_URL($url); |
|---|
| 274 | // QUERY_STRING 生成 |
|---|
| 275 | foreach ($param as $key => $val) { |
|---|
| 276 | $netURL->addQueryString($key, $val); |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | return $netURL->getURL(); |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | /** |
|---|
| 283 | * EC-CUBE のWEBルート(/html/)を / としたパスを返す |
|---|
| 284 | * |
|---|
| 285 | * @param string $path 結果を取得するためのパス |
|---|
| 286 | * @return string EC-CUBE のWEBルート(/html/)を / としたパス |
|---|
| 287 | */ |
|---|
| 288 | function getRootPath($path) { |
|---|
| 289 | // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する |
|---|
| 290 | $path = str_replace('\\', '/', $path); |
|---|
| 291 | $htmlPath = str_replace('\\', '/', HTML_REALDIR); |
|---|
| 292 | |
|---|
| 293 | // PHP 5.1 対策 ( http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=4277&forum=9) |
|---|
| 294 | if (strlen($path) == 0) { |
|---|
| 295 | $path = '.'; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | // $path が / で始まっている場合 |
|---|
| 299 | if (substr($path, 0, 1) == '/') { |
|---|
| 300 | $realPath = realpath($htmlPath . substr_replace($path, '', 0, strlen(ROOT_URLPATH))); |
|---|
| 301 | // 相対パスの場合 |
|---|
| 302 | } else { |
|---|
| 303 | $realPath = realpath($path); |
|---|
| 304 | } |
|---|
| 305 | $realPath = str_replace('\\', '/', $realPath); |
|---|
| 306 | |
|---|
| 307 | // $path が / で終わっている場合、realpath によって削られた末尾の / を復元する。 |
|---|
| 308 | if (substr($path, -1, 1) == '/' && substr($realPath, -1, 1) != '/') { |
|---|
| 309 | $realPath .= '/'; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | // HTML_REALDIR を削除した文字列を取得. |
|---|
| 313 | $rootPath = str_replace($htmlPath, '', $realPath); |
|---|
| 314 | $rootPath = ltrim($rootPath, '/'); |
|---|
| 315 | |
|---|
| 316 | return $rootPath; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | /** |
|---|
| 320 | * 互換性確保用メソッド |
|---|
| 321 | * |
|---|
| 322 | * @access protected |
|---|
| 323 | * @return void |
|---|
| 324 | * @deprecated 決済モジュール互換のため |
|---|
| 325 | */ |
|---|
| 326 | function allowClientCache() { |
|---|
| 327 | $this->httpCacheControl('private'); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | /** |
|---|
| 331 | * クライアント・プロキシのキャッシュを制御する. |
|---|
| 332 | * |
|---|
| 333 | * @access protected |
|---|
| 334 | * @param string $mode (nocache/private) |
|---|
| 335 | * @return void |
|---|
| 336 | */ |
|---|
| 337 | function httpCacheControl($mode = '') { |
|---|
| 338 | switch ($mode) { |
|---|
| 339 | case 'nocache': |
|---|
| 340 | header('Pragma: no-cache'); |
|---|
| 341 | header('Expires: Thu, 19 Nov 1981 08:52:00 GMT'); |
|---|
| 342 | header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); |
|---|
| 343 | header('Last-Modified:'); |
|---|
| 344 | break; |
|---|
| 345 | |
|---|
| 346 | case 'private': |
|---|
| 347 | $cache_expire = session_cache_expire() * 60; |
|---|
| 348 | header('Pragma: no-cache'); // anti-proxy |
|---|
| 349 | header('Expires:'); // anti-mozilla |
|---|
| 350 | header("Cache-Control: private, max-age={$cache_expire}, pre-check={$cache_expire}"); // HTTP/1.1 client |
|---|
| 351 | header('Last-Modified:'); |
|---|
| 352 | break; |
|---|
| 353 | |
|---|
| 354 | default: |
|---|
| 355 | break; |
|---|
| 356 | } |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | /** |
|---|
| 360 | * リクエストパラメーター 'mode' を取得する. |
|---|
| 361 | * |
|---|
| 362 | * 1. $_GET['mode'] の値を取得する. |
|---|
| 363 | * 2. 1 が存在しない場合は $_POST['mode'] の値を取得する. |
|---|
| 364 | * 3. どちらも存在しない場合は null を返す. |
|---|
| 365 | * |
|---|
| 366 | * mode に, 半角英数字とアンダーバー(_) 以外の文字列が検出された場合は null を |
|---|
| 367 | * 返す. |
|---|
| 368 | * |
|---|
| 369 | * @access protected |
|---|
| 370 | * @return string $_GET['mode'] 又は $_POST['mode'] の文字列 |
|---|
| 371 | */ |
|---|
| 372 | function getMode() { |
|---|
| 373 | $pattern = '/^[a-zA-Z0-9_]+$/'; |
|---|
| 374 | $mode = null; |
|---|
| 375 | if (isset($_GET['mode']) && preg_match($pattern, $_GET['mode'])) { |
|---|
| 376 | $mode = $_GET['mode']; |
|---|
| 377 | } elseif (isset($_POST['mode']) && preg_match($pattern, $_POST['mode'])) { |
|---|
| 378 | $mode = $_POST['mode']; |
|---|
| 379 | } |
|---|
| 380 | return $mode; |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | /** |
|---|
| 384 | * POST アクセスの妥当性を検証する. |
|---|
| 385 | * |
|---|
| 386 | * 生成されたトランザクショントークンの妥当性を検証し, |
|---|
| 387 | * 不正な場合はエラー画面へ遷移する. |
|---|
| 388 | * |
|---|
| 389 | * この関数は, 基本的に init() 関数で呼び出され, POST アクセスの場合は自動的に |
|---|
| 390 | * トランザクショントークンを検証する. |
|---|
| 391 | * ページによって検証タイミングなどを制御する必要がある場合は, この関数を |
|---|
| 392 | * オーバーライドし, 個別に設定を行うこと. |
|---|
| 393 | * |
|---|
| 394 | * @access protected |
|---|
| 395 | * @param boolean $is_admin 管理画面でエラー表示をする場合 true |
|---|
| 396 | * @return void |
|---|
| 397 | */ |
|---|
| 398 | function doValidToken($is_admin = false) { |
|---|
| 399 | if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|---|
| 400 | if (!SC_Helper_Session_Ex::isValidToken(false)) { |
|---|
| 401 | if ($is_admin) { |
|---|
| 402 | SC_Utils_Ex::sfDispError(INVALID_MOVE_ERRORR); |
|---|
| 403 | } else { |
|---|
| 404 | SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true); |
|---|
| 405 | } |
|---|
| 406 | SC_Response_Ex::actionExit(); |
|---|
| 407 | } |
|---|
| 408 | } |
|---|
| 409 | } |
|---|
| 410 | |
|---|
| 411 | /** |
|---|
| 412 | * トランザクショントークンを取得し, 設定する. |
|---|
| 413 | * |
|---|
| 414 | * @access protected |
|---|
| 415 | * @return void |
|---|
| 416 | */ |
|---|
| 417 | function setTokenTo() { |
|---|
| 418 | $this->transactionid = SC_Helper_Session_Ex::getToken(); |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | /** |
|---|
| 422 | * 前方互換用 |
|---|
| 423 | * |
|---|
| 424 | * @deprecated 2.12.0 GC_Utils_Ex::gfPrintLog を使用すること |
|---|
| 425 | */ |
|---|
| 426 | function log($mess, $log_level) { |
|---|
| 427 | trigger_error('前方互換用メソッドが使用されました。', E_USER_WARNING); |
|---|
| 428 | // ログレベル=Debugの場合は、DEBUG_MODEがtrueの場合のみログ出力する |
|---|
| 429 | if ($log_level === 'Debug' && DEBUG_MODE === false) { |
|---|
| 430 | return; |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | // ログ出力 |
|---|
| 434 | GC_Utils_Ex::gfPrintLog($mess, '', true); |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | /** |
|---|
| 438 | * デバック出力を行う. |
|---|
| 439 | * |
|---|
| 440 | * デバック用途のみに使用すること. |
|---|
| 441 | * |
|---|
| 442 | * @access protected |
|---|
| 443 | * @param mixed $val デバックする要素 |
|---|
| 444 | * @return void |
|---|
| 445 | */ |
|---|
| 446 | function p($val) { |
|---|
| 447 | SC_Utils_Ex::sfPrintR($val); |
|---|
| 448 | } |
|---|
| 449 | } |
|---|