| 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 | // {{{ requires |
|---|
| 25 | require_once(DATA_REALDIR . 'module/Net/URL.php'); |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * Web Page を制御する基底クラス |
|---|
| 29 | * |
|---|
| 30 | * Web Page を制御する Page クラスは必ずこのクラスを継承する. |
|---|
| 31 | * PHP4 ではこのような抽象クラスを作っても継承先で何でもできてしまうため、 |
|---|
| 32 | * あまり意味がないが、アーキテクトを統一するために作っておく. |
|---|
| 33 | * |
|---|
| 34 | * @package Page |
|---|
| 35 | * @author LOCKON CO.,LTD. |
|---|
| 36 | * @version $Id:LC_Page.php 15532 2007-08-31 14:39:46Z nanasess $ |
|---|
| 37 | */ |
|---|
| 38 | class LC_Page { |
|---|
| 39 | |
|---|
| 40 | // {{{ properties |
|---|
| 41 | |
|---|
| 42 | /** メインテンプレート */ |
|---|
| 43 | var $tpl_mainpage; |
|---|
| 44 | |
|---|
| 45 | /** テンプレートのカラム数 */ |
|---|
| 46 | var $tpl_column_num; |
|---|
| 47 | |
|---|
| 48 | /** メインナンバー */ |
|---|
| 49 | var $tpl_mainno; |
|---|
| 50 | |
|---|
| 51 | /** CSS のパス */ |
|---|
| 52 | var $tpl_css; |
|---|
| 53 | |
|---|
| 54 | /** JavaScript */ |
|---|
| 55 | var $tpl_javascript; |
|---|
| 56 | |
|---|
| 57 | /** タイトル */ |
|---|
| 58 | var $tpl_title; |
|---|
| 59 | |
|---|
| 60 | /** カテゴリ */ |
|---|
| 61 | var $tpl_page_category; |
|---|
| 62 | |
|---|
| 63 | /** ログインメールアドレス */ |
|---|
| 64 | var $tpl_login_email; |
|---|
| 65 | |
|---|
| 66 | /** HTML ロード後に実行する JavaScript コード */ |
|---|
| 67 | var $tpl_onload; |
|---|
| 68 | |
|---|
| 69 | /** 送料合計 */ |
|---|
| 70 | var $tpl_total_deliv_fee; |
|---|
| 71 | |
|---|
| 72 | /** トランザクションID */ |
|---|
| 73 | var $transactionid; |
|---|
| 74 | |
|---|
| 75 | /** メインテンプレート名 */ |
|---|
| 76 | var $template = SITE_FRAME; |
|---|
| 77 | |
|---|
| 78 | // }}} |
|---|
| 79 | // {{{ functions |
|---|
| 80 | |
|---|
| 81 | /** |
|---|
| 82 | * Page を初期化する. |
|---|
| 83 | * |
|---|
| 84 | * @return void |
|---|
| 85 | */ |
|---|
| 86 | function init() { |
|---|
| 87 | // 開始時刻を設定する。 |
|---|
| 88 | $this->timeStart = SC_Utils_Ex::sfMicrotimeFloat(); |
|---|
| 89 | |
|---|
| 90 | $this->tpl_authority = $_SESSION['authority']; |
|---|
| 91 | |
|---|
| 92 | // ディスプレイクラス生成 |
|---|
| 93 | $this->objDisplay = new SC_Display(); |
|---|
| 94 | |
|---|
| 95 | $layout = new SC_Helper_PageLayout_Ex(); |
|---|
| 96 | $layout->sfGetPageLayout($this, false, $_SERVER['PHP_SELF'], |
|---|
| 97 | $this->objDisplay->detectDevice()); |
|---|
| 98 | |
|---|
| 99 | // プラグインクラス生成 |
|---|
| 100 | $this->objPlugin = new SC_Helper_Plugin_Ex(); |
|---|
| 101 | $this->objPlugin->preProcess($this); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | /** |
|---|
| 105 | * Page のプロセス. |
|---|
| 106 | * |
|---|
| 107 | * @return void |
|---|
| 108 | */ |
|---|
| 109 | function process() {} |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Page のプロセス.(モバイル) |
|---|
| 113 | * |
|---|
| 114 | * @return void |
|---|
| 115 | */ |
|---|
| 116 | function mobileProcess() {} |
|---|
| 117 | |
|---|
| 118 | /** |
|---|
| 119 | * Page のレスポンス送信. |
|---|
| 120 | * |
|---|
| 121 | * @return void |
|---|
| 122 | */ |
|---|
| 123 | function sendResponse() { |
|---|
| 124 | |
|---|
| 125 | if (isset($this->objPlugin)) { // FIXME モバイルエラー応急対応 |
|---|
| 126 | // post-prosess処理(暫定的) |
|---|
| 127 | $this->objPlugin->process($this); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | $this->objDisplay->prepare($this); |
|---|
| 131 | $this->objDisplay->response->write(); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | * Page のレスポンス送信(ダウンロード). |
|---|
| 136 | * |
|---|
| 137 | * @return void |
|---|
| 138 | */ |
|---|
| 139 | function sendResponseCSV($file_name, $data) { |
|---|
| 140 | $this->objDisplay->prepare($this); |
|---|
| 141 | $this->objDisplay->addHeader("Content-disposition", "attachment; filename=${file_name}"); |
|---|
| 142 | $this->objDisplay->addHeader("Content-type", "application/octet-stream; name=${file_name}"); |
|---|
| 143 | $this->objDisplay->addHeader("Cache-Control", ""); |
|---|
| 144 | $this->objDisplay->addHeader("Pragma", ""); |
|---|
| 145 | |
|---|
| 146 | $this->objDisplay->response->body = $data; |
|---|
| 147 | $this->objDisplay->response->write(); |
|---|
| 148 | exit; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | /** |
|---|
| 152 | * デストラクタ. |
|---|
| 153 | * |
|---|
| 154 | * @return void |
|---|
| 155 | */ |
|---|
| 156 | function destroy() { |
|---|
| 157 | // 一定時間以上かかったページの場合、ログ出力する。 |
|---|
| 158 | if(defined('PAGE_DISPLAY_TIME_LOG_MODE') && PAGE_DISPLAY_TIME_LOG_MODE == true) { |
|---|
| 159 | $timeEnd = SC_Utils_Ex::sfMicrotimeFloat();; |
|---|
| 160 | $timeExecTime = $timeEnd - $this->timeStart; |
|---|
| 161 | if(defined('PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME') && $timeExecTime >= (float)PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME) { |
|---|
| 162 | $logMsg = sprintf("PAGE_DISPLAY_TIME_LOG [%.2fsec]", $timeExecTime); |
|---|
| 163 | GC_Utils_Ex::gfPrintLog($logMsg); |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | /** |
|---|
| 170 | * テンプレート取得 |
|---|
| 171 | * |
|---|
| 172 | */ |
|---|
| 173 | function getTemplate() { |
|---|
| 174 | return $this->template; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | /** |
|---|
| 178 | * テンプレート設定(ポップアップなどの場合) |
|---|
| 179 | * |
|---|
| 180 | */ |
|---|
| 181 | function setTemplate($template) { |
|---|
| 182 | $this->template = $template; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | /** |
|---|
| 186 | * $path から URL を取得する. |
|---|
| 187 | * |
|---|
| 188 | * 以下の順序で 引数 $path から URL を取得する. |
|---|
| 189 | * 1. realpath($path) で $path の 絶対パスを取得 |
|---|
| 190 | * 2. $_SERVER['DOCUMENT_ROOT'] と一致する文字列を削除 |
|---|
| 191 | * 3. $useSSL の値に応じて, HTTP_URL 又は, HTTPS_URL を付与する. |
|---|
| 192 | * |
|---|
| 193 | * 返り値に, QUERY_STRING を含めたい場合は, key => value 形式 |
|---|
| 194 | * の配列を $param へ渡す. |
|---|
| 195 | * |
|---|
| 196 | * @access protected |
|---|
| 197 | * @param string $path 結果を取得するためのパス |
|---|
| 198 | * @param array $param URL に付与するパラメータの配列 |
|---|
| 199 | * @param mixed $useSSL 結果に HTTPS_URL を使用する場合 true, |
|---|
| 200 | * HTTP_URL を使用する場合 false, |
|---|
| 201 | * デフォルト "escape" 現在のスキーマを使用 |
|---|
| 202 | * @return string $path の存在する http(s):// から始まる絶対パス |
|---|
| 203 | * @see Net_URL |
|---|
| 204 | */ |
|---|
| 205 | function getLocation($path, $param = array(), $useSSL = "escape") { |
|---|
| 206 | $rootPath = $this->getRootPath($path); |
|---|
| 207 | |
|---|
| 208 | // スキーマを定義 |
|---|
| 209 | if ($useSSL === true) { |
|---|
| 210 | $url = HTTPS_URL . $rootPath; |
|---|
| 211 | } elseif ($useSSL === false){ |
|---|
| 212 | $url = HTTP_URL . $rootPath; |
|---|
| 213 | } elseif ($useSSL == "escape") { |
|---|
| 214 | if (SC_Utils_Ex::sfIsHTTPS()) { |
|---|
| 215 | $url = HTTPS_URL . $rootPath; |
|---|
| 216 | } else { |
|---|
| 217 | $url = HTTP_URL . $rootPath; |
|---|
| 218 | } |
|---|
| 219 | } else { |
|---|
| 220 | die("[BUG] Illegal Parametor of \$useSSL "); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | $netURL = new Net_URL($url); |
|---|
| 224 | // QUERY_STRING 生成 |
|---|
| 225 | foreach ($param as $key => $val) { |
|---|
| 226 | $netURL->addQueryString($key, $val); |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | return $netURL->getURL(); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | /** |
|---|
| 233 | * EC-CUBE のWEBルート(/html/)を / としたパスを返す |
|---|
| 234 | * |
|---|
| 235 | * @param string $path 結果を取得するためのパス |
|---|
| 236 | * @return string EC-CUBE のWEBルート(/html/)を / としたパス |
|---|
| 237 | */ |
|---|
| 238 | function getRootPath($path) { |
|---|
| 239 | // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する |
|---|
| 240 | $path = str_replace('\\', '/', $path); |
|---|
| 241 | $htmlPath = str_replace('\\', '/', HTML_REALDIR); |
|---|
| 242 | |
|---|
| 243 | // PHP 5.1 対策 ( http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=4277&forum=9 ) |
|---|
| 244 | if (strlen($path) == 0) { |
|---|
| 245 | $path = '.'; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | // $path が / で始まっている場合 |
|---|
| 249 | if (substr($path, 0, 1) == '/') { |
|---|
| 250 | $realPath = realpath($htmlPath . substr_replace($path, '', 0, strlen(ROOT_URLPATH))); |
|---|
| 251 | // 相対パスの場合 |
|---|
| 252 | } else { |
|---|
| 253 | $realPath = realpath($path); |
|---|
| 254 | } |
|---|
| 255 | $realPath = str_replace('\\', '/', $realPath); |
|---|
| 256 | |
|---|
| 257 | // $path が / で終わっている場合、realpath によって削られた末尾の / を復元する。 |
|---|
| 258 | if (substr($path, -1, 1) == '/' && substr($realPath, -1, 1) != '/') { |
|---|
| 259 | $realPath .= '/'; |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | // HTML_REALDIR を削除した文字列を取得. |
|---|
| 263 | $rootPath = str_replace($htmlPath, '', $realPath); |
|---|
| 264 | $rootPath = ltrim($rootPath, '/'); |
|---|
| 265 | |
|---|
| 266 | return $rootPath; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | /** |
|---|
| 270 | * 互換性確保用メソッド |
|---|
| 271 | * |
|---|
| 272 | * @access protected |
|---|
| 273 | * @return void |
|---|
| 274 | * @deprecated 決済モジュール互換のため |
|---|
| 275 | */ |
|---|
| 276 | function allowClientCache() { |
|---|
| 277 | LC_Page::httpCacheControl('private'); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | /** |
|---|
| 281 | * クライアント・プロキシのキャッシュを制御する. |
|---|
| 282 | * |
|---|
| 283 | * @access protected |
|---|
| 284 | * @param string $mode (nocache/private) |
|---|
| 285 | * @return void |
|---|
| 286 | */ |
|---|
| 287 | function httpCacheControl($mode = '') { |
|---|
| 288 | switch ($mode) { |
|---|
| 289 | case 'nocache': |
|---|
| 290 | header('Pragma: no-cache'); |
|---|
| 291 | header('Expires: Thu, 19 Nov 1981 08:52:00 GMT'); |
|---|
| 292 | header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); |
|---|
| 293 | header('Last-Modified:'); |
|---|
| 294 | break; |
|---|
| 295 | |
|---|
| 296 | case 'private': |
|---|
| 297 | $cache_expire = session_cache_expire() * 60; |
|---|
| 298 | header('Pragma: no-cache'); // anti-proxy |
|---|
| 299 | header('Expires:'); // anti-mozilla |
|---|
| 300 | header("Cache-Control: private, max-age={$cache_expire}, pre-check={$cache_expire}"); // HTTP/1.1 client |
|---|
| 301 | header('Last-Modified:'); |
|---|
| 302 | break; |
|---|
| 303 | |
|---|
| 304 | default: |
|---|
| 305 | break; |
|---|
| 306 | } |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | /** |
|---|
| 310 | * リクエストパラメータ "mode" を取得する. |
|---|
| 311 | * |
|---|
| 312 | * 1. $_GET['mode'] の値を取得する. |
|---|
| 313 | * 2. 1 が存在しない場合は $_POST['mode'] の値を取得する. |
|---|
| 314 | * 3. どちらも存在しない場合は null を返す. |
|---|
| 315 | * |
|---|
| 316 | * mode に, 半角英数字とアンダーバー(_) 以外の文字列が検出された場合は null を |
|---|
| 317 | * 返す. |
|---|
| 318 | * |
|---|
| 319 | * @access protected |
|---|
| 320 | * @return string $_GET['mode'] 又は $_POST['mode'] の文字列 |
|---|
| 321 | */ |
|---|
| 322 | function getMode() { |
|---|
| 323 | $pattern = '/^[a-zA-Z0-9_]+$/'; |
|---|
| 324 | $mode = null; |
|---|
| 325 | if (isset($_GET['mode']) && preg_match($pattern, $_GET['mode'])) { |
|---|
| 326 | $mode = $_GET['mode']; |
|---|
| 327 | } elseif (isset($_POST['mode']) && preg_match($pattern, $_POST['mode'])) { |
|---|
| 328 | $mode = $_POST['mode']; |
|---|
| 329 | } |
|---|
| 330 | return $mode; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | /** |
|---|
| 334 | * デバック出力を行う. |
|---|
| 335 | * |
|---|
| 336 | * デバック用途のみに使用すること. |
|---|
| 337 | * |
|---|
| 338 | * @access protected |
|---|
| 339 | * @param mixed $val デバックする要素 |
|---|
| 340 | * @return void |
|---|
| 341 | */ |
|---|
| 342 | function p($val) { |
|---|
| 343 | SC_Utils_Ex::sfPrintR($val); |
|---|
| 344 | } |
|---|
| 345 | } |
|---|
| 346 | ?> |
|---|