Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page.php

Documentation is available at LC_Page.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 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.     /** トランザクションID */
  70.     var $transactionid;
  71.  
  72.     /** メインテンプレート名 */
  73.     var $template = SITE_FRAME;
  74.  
  75.     /** 店舗基本情報 */
  76.     var $arrSiteInfo;
  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_Ex();
  94.  
  95.         $layout new SC_Helper_PageLayout_Ex();
  96.         $layout->sfGetPageLayout($thisfalse$_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.         $this->arrSiteInfo = SC_Helper_DB_Ex::sfGetBasisData();
  105.  
  106.         // トランザクショントークンの検証と生成
  107.         $this->doValidToken();
  108.         $this->setTokenTo();
  109.     }
  110.  
  111.     /**
  112.      * Page のプロセス.
  113.      *
  114.      * @return void 
  115.      */
  116.     function process({}
  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.         // エラー画面の表示では $this->timeStart が出力されない
  159.         if (defined('PAGE_DISPLAY_TIME_LOG_MODE'&& PAGE_DISPLAY_TIME_LOG_MODE == true && isset($this->timeStart)) {
  160.             $timeEnd SC_Utils_Ex::sfMicrotimeFloat();
  161.             $timeExecTime $timeEnd $this->timeStart;
  162.             if (defined('PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME'&& $timeExecTime >= (float)PAGE_DISPLAY_TIME_LOG_MIN_EXEC_TIME{
  163.                 $logMsg sprintf("PAGE_DISPLAY_TIME_LOG [%.2fsec]"$timeExecTime);
  164.                 GC_Utils_Ex::gfPrintLog($logMsg);
  165.             }
  166.         }
  167.  
  168.     }
  169.  
  170.     /**
  171.      * テンプレート取得
  172.      *
  173.      */
  174.     function getTemplate({
  175.         return $this->template;
  176.     }
  177.  
  178.     /**
  179.      * テンプレート設定(ポップアップなどの場合)
  180.      *
  181.      */
  182.     function setTemplate($template{
  183.         $this->template = $template;
  184.     }
  185.  
  186.     /**
  187.      * $path から URL を取得する.
  188.      *
  189.      * 以下の順序で 引数 $path から URL を取得する.
  190.      * 1. realpath($path) で $path の 絶対パスを取得
  191.      * 2. $_SERVER['DOCUMENT_ROOT'] と一致する文字列を削除
  192.      * 3. $useSSL の値に応じて, HTTP_URL 又は, HTTPS_URL を付与する.
  193.      *
  194.      * 返り値に, QUERY_STRING を含めたい場合は, key => value 形式
  195.      * の配列を $param へ渡す.
  196.      *
  197.      * @access protected
  198.      * @param string $path 結果を取得するためのパス
  199.      * @param array $param URL に付与するパラメーターの配列
  200.      * @param mixed $useSSL 結果に HTTPS_URL を使用する場合 true,
  201.      *                          HTTP_URL を使用する場合 false,
  202.      *                          デフォルト 'escape' 現在のスキーマを使用
  203.      * @return string $path の存在する http(s):// から始まる絶対パス
  204.      * @see Net_URL
  205.      */
  206.     function getLocation($path$param array()$useSSL 'escape'{
  207.         $rootPath $this->getRootPath($path);
  208.  
  209.         // スキーマを定義
  210.         if ($useSSL === true{
  211.             $url HTTPS_URL $rootPath;
  212.         elseif ($useSSL === false){
  213.             $url HTTP_URL $rootPath;
  214.         elseif ($useSSL == 'escape'{
  215.             if (SC_Utils_Ex::sfIsHTTPS()) {
  216.                 $url HTTPS_URL $rootPath;
  217.             else {
  218.                 $url HTTP_URL $rootPath;
  219.             }
  220.         else {
  221.             die("[BUG] Illegal Parametor of \$useSSL ");
  222.         }
  223.  
  224.         $netURL new Net_URL($url);
  225.         // QUERY_STRING 生成
  226.         foreach ($param as $key => $val{
  227.             $netURL->addQueryString($key$val);
  228.         }
  229.  
  230.         return $netURL->getURL();
  231.     }
  232.  
  233.     /**
  234.      * EC-CUBE のWEBルート(/html/)を / としたパスを返す
  235.      *
  236.      * @param string $path 結果を取得するためのパス
  237.      * @return string EC-CUBE のWEBルート(/html/)を / としたパス
  238.      */
  239.     function getRootPath($path{
  240.         // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する
  241.         $path str_replace('\\''/'$path);
  242.         $htmlPath str_replace('\\''/'HTML_REALDIR);
  243.  
  244.         // PHP 5.1 対策 ( http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=4277&forum=9 )
  245.         if (strlen($path== 0{
  246.             $path '.';
  247.         }
  248.  
  249.         // $path が / で始まっている場合
  250.         if (substr($path01== '/'{
  251.             $realPath realpath($htmlPath substr_replace($path''0strlen(ROOT_URLPATH)));
  252.         // 相対パスの場合
  253.         else {
  254.             $realPath realpath($path);
  255.         }
  256.         $realPath str_replace('\\''/'$realPath);
  257.  
  258.         // $path が / で終わっている場合、realpath によって削られた末尾の / を復元する。
  259.         if (substr($path-11== '/' && substr($realPath-11!= '/'{
  260.             $realPath .= '/';
  261.         }
  262.  
  263.         // HTML_REALDIR を削除した文字列を取得.
  264.         $rootPath str_replace($htmlPath''$realPath);
  265.         $rootPath ltrim($rootPath'/');
  266.  
  267.         return $rootPath;
  268.     }
  269.  
  270.     /**
  271.      * 互換性確保用メソッド
  272.      *
  273.      * @access protected
  274.      * @return void 
  275.      * @deprecated 決済モジュール互換のため
  276.      */
  277.     function allowClientCache({
  278.         $this->httpCacheControl('private');
  279.     }
  280.  
  281.     /**
  282.      * クライアント・プロキシのキャッシュを制御する.
  283.      *
  284.      * @access protected
  285.      * @param string $mode (nocache/private)
  286.      * @return void 
  287.      */
  288.     function httpCacheControl($mode ''{
  289.         switch ($mode{
  290.             case 'nocache':
  291.                 header('Pragma: no-cache');
  292.                 header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
  293.                 header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
  294.                 header('Last-Modified:');
  295.                 break;
  296.  
  297.             case 'private':
  298.                 $cache_expire session_cache_expire(60;
  299.                 header('Pragma: no-cache');                                                            // anti-proxy
  300.                 header('Expires:');                                                                    // anti-mozilla
  301.                 header("Cache-Control: private, max-age={$cache_expire}, pre-check={$cache_expire}");  // HTTP/1.1 client
  302.                 header('Last-Modified:');
  303.                 break;
  304.  
  305.             default:
  306.                 break;
  307.         }
  308.     }
  309.  
  310.     /**
  311.      * リクエストパラメーター 'mode' を取得する.
  312.      *
  313.      * 1. $_GET['mode'] の値を取得する.
  314.      * 2. 1 が存在しない場合は $_POST['mode'] の値を取得する.
  315.      * 3. どちらも存在しない場合は null を返す.
  316.      *
  317.      * mode に, 半角英数字とアンダーバー(_) 以外の文字列が検出された場合は null を
  318.      * 返す.
  319.      *
  320.      * @access protected
  321.      * @return string $_GET['mode'] 又は $_POST['mode'] の文字列
  322.      */
  323.     function getMode({
  324.         $pattern '/^[a-zA-Z0-9_]+$/';
  325.         $mode null;
  326.         if (isset($_GET['mode']&& preg_match($pattern$_GET['mode'])) {
  327.             $mode =  $_GET['mode'];
  328.         elseif (isset($_POST['mode']&& preg_match($pattern$_POST['mode'])) {
  329.             $mode $_POST['mode'];
  330.         }
  331.         return $mode;
  332.     }
  333.  
  334.     /**
  335.      * POST アクセスの妥当性を検証する.
  336.      *
  337.      * 生成されたトランザクショントークンの妥当性を検証し,
  338.      * 不正な場合はエラー画面へ遷移する.
  339.      *
  340.      * この関数は, 基本的に init() 関数で呼び出され, POST アクセスの場合は自動的に
  341.      * トランザクショントークンを検証する.
  342.      * ページによって検証タイミングなどを制御する必要がある場合は, この関数を
  343.      * オーバーライドし, 個別に設定を行うこと.
  344.      *
  345.      * @access protected
  346.      * @param boolean $is_admin 管理画面でエラー表示をする場合 true
  347.      * @return void 
  348.      */
  349.     function doValidToken($is_admin false{
  350.         if ($_SERVER["REQUEST_METHOD"== 'POST'{
  351.             if (!SC_Helper_Session_Ex::isValidToken(false)) {
  352.                 if ($is_admin{
  353.                     SC_Utils_Ex::sfDispError(INVALID_MOVE_ERRORR);
  354.                 else {
  355.                     SC_Utils_Ex::sfDispSiteError(PAGE_ERROR""true);
  356.                 }
  357.                 exit;
  358.             }
  359.         }
  360.     }
  361.  
  362.     /**
  363.      * トランザクショントークンを取得し, 設定する.
  364.      *
  365.      * @access protected
  366.      * @return void 
  367.      */
  368.     function setTokenTo({
  369.         $this->transactionid = SC_Helper_Session_Ex::getToken();
  370.     }
  371.  
  372.     /**
  373.      * ログ出力を行う.
  374.      *
  375.      * ログイン中の顧客IDを含めてログ出力します.
  376.      *
  377.      * @access protected
  378.      * @param string $mess ログメッセージ
  379.      * @param string $log_level ログレベル("Info" or "Debug")
  380.      * @return void 
  381.      */
  382.     function log($mess$log_level{
  383.         $mess $mess " user=" $_SESSION['customer']['customer_id'];
  384.  
  385.         GC_Utils_Ex::gfFrontLog($mess$log_level);
  386.     }
  387.  
  388.     /**
  389.      * デバック出力を行う.
  390.      *
  391.      * デバック用途のみに使用すること.
  392.      *
  393.      * @access protected
  394.      * @param mixed $val デバックする要素
  395.      * @return void 
  396.      */
  397.     function p($val{
  398.         SC_Utils_Ex::sfPrintR($val);
  399.     }
  400. }
  401. ?>

Documentation generated on Fri, 24 Feb 2012 14:00:59 +0900 by Seasoft