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-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_PATH '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 = 2;
  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.     /** body タグの onload 属性 */
  67.     var $tpl_onload;
  68.  
  69.     /** 送料合計 */
  70.     var $tpl_total_deliv_fee;
  71.  
  72.     /** トランザクションID */
  73.     var $transactionid;
  74.  
  75.     // }}}
  76.     // {{{ functions
  77.  
  78.     /**
  79.      * Page を初期化する.
  80.      *
  81.      * @return void 
  82.      */
  83.     function init({}
  84.  
  85.     /**
  86.      * Page のプロセス.
  87.      *
  88.      * @return void 
  89.      */
  90.     function process({}
  91.  
  92.     /**
  93.      * デストラクタ.
  94.      *
  95.      * @return void 
  96.      */
  97.     function destroy({}
  98.  
  99.     /**
  100.      * 指定の URL へリダイレクトする.
  101.      *
  102.      * リダイレクト先 URL に SITE_URL 及び SSL_URL を含むかチェックし,
  103.      * LC_Page::getToken() の値を URLパラメータで自動的に付与する.
  104.      *
  105.      * @param string $url リダイレクト先 URL
  106.      * @param boolean $isMobile モバイル用にセッションIDを付与する場合 true
  107.      * @return void|boolean$url に SITE_URL 及び, SSL_URL を含まない場合 false,
  108.      *                        正常に遷移可能な場合は, $url の ロケーションヘッダを出力する.
  109.      * @see Net_URL
  110.      */
  111.     function sendRedirect($url$isMobile false{
  112.  
  113.         if (preg_match("/(" preg_quote(SITE_URL'/')
  114.                           . "|" preg_quote(SSL_URL'/'")/"$url)) {
  115.  
  116.             $netURL new Net_URL($url);
  117.             if (!empty($_SERVER['QUERY_STRING'])) {
  118.                 $netURL->addRawQueryString($_SERVER['QUERY_STRING']);
  119.             }
  120.  
  121.             $session SC_SessionFactory::getInstance();
  122.             if ($isMobile || $session->useCookie(== false{
  123.                 $netURL->addQueryString(session_name()session_id());
  124.             }
  125.  
  126.             $netURL->addQueryString(TRANSACTION_ID_NAME$this->getToken());
  127.             header("Location: " $netURL->getURL());
  128.             //return true;
  129.             exit();
  130.         }
  131.         return false;
  132.     }
  133.  
  134.     // }}}
  135.     // {{{ protected functions
  136.  
  137.     /**
  138.      * トランザクショントークンを生成し, 取得する.
  139.      *
  140.      * 悪意のある不正な画面遷移を防止するため, 予測困難な文字列を生成して返す.
  141.      * 同時に, この文字列をセッションに保存する.
  142.      *
  143.      * この関数を使用するためには, 生成した文字列を次画面へ渡すパラメータとして
  144.      * 出力する必要がある.
  145.      *
  146.      * 例)
  147.      * <input type="hidden" name="transactionid" value="この関数の返り値" />
  148.      *
  149.      * 遷移先のページで, LC_Page::isValidToken() の返り値をチェックすることにより,
  150.      * 画面遷移の妥当性が確認できる.
  151.      *
  152.      * @access protected
  153.      * @return string トランザクショントークンの文字列
  154.      */
  155.     function getToken({
  156.         if (empty($_SESSION[TRANSACTION_ID_NAME])) {
  157.             $_SESSION[TRANSACTION_ID_NAME$this->createToken();
  158.         }
  159.         return $_SESSION[TRANSACTION_ID_NAME];
  160.     }
  161.  
  162.     /**
  163.      * トランザクショントークンの妥当性をチェックする.
  164.      *
  165.      * 前画面で生成されたトランザクショントークンの妥当性をチェックする.
  166.      * この関数を使用するためには, 前画面のページクラスで LC_Page::getToken()
  167.      * を呼んでおく必要がある.
  168.      *
  169.      * @access protected
  170.      * @return boolean トランザクショントークンが有効な場合 true
  171.      */
  172.     function isValidToken({
  173.  
  174.         $checkToken "";
  175.  
  176.         // $_POST の値を優先する
  177.         if (isset($_POST[TRANSACTION_ID_NAME])) {
  178.  
  179.             $checkToken $_POST[TRANSACTION_ID_NAME];
  180.         elseif (isset($_GET[TRANSACTION_ID_NAME])) {
  181.  
  182.             $checkToken $_GET[TRANSACTION_ID_NAME];
  183.         }
  184.  
  185.         $ret false;
  186.         // token の妥当性チェック
  187.         if ($checkToken === $_SESSION[TRANSACTION_ID_NAME]{
  188.  
  189.             $ret true;
  190.         }
  191.  
  192.         unset($_SESSION[TRANSACTION_ID_NAME]);
  193.         return $ret;
  194.     }
  195.  
  196.     /**
  197.      * $path から URL を取得する.
  198.      *
  199.      * 以下の順序で 引数 $path から URL を取得する.
  200.      * 1. realpath($path) で $path の 絶対パスを取得
  201.      * 2. $_SERVER['DOCUMENT_ROOT'] と一致する文字列を削除
  202.      * 3. $useSSL の値に応じて, SITE_URL 又は, SSL_URL を付与する.
  203.      *
  204.      * 返り値に, QUERY_STRING を含めたい場合は, key => value 形式
  205.      * の配列を $param へ渡す.
  206.      *
  207.      * @access protected
  208.      * @param string $path 結果を取得するためのパス
  209.      * @param array $param URL に付与するパラメータの配列
  210.      * @param mixed $useSSL 結果に SSL_URL を使用する場合 true,
  211.      *                          SITE_URL を使用する場合 false,
  212.      *                          デフォルト "escape" 現在のスキーマを使用
  213.      * @return string $path の存在する http(s):// から始まる絶対パス
  214.      * @see Net_URL
  215.      */
  216.     function getLocation($path$param array()$useSSL "escape"{
  217.         $rootPath $this->getRootPath($path);
  218.  
  219.         // スキーマを定義
  220.         if ($useSSL === true{
  221.             $url SSL_URL $rootPath;
  222.         elseif ($useSSL === false){
  223.             $url SITE_URL $rootPath;
  224.         elseif ($useSSL == "escape"{
  225.             if (SC_Utils_Ex::sfIsHTTPS()) {
  226.                 $url SSL_URL $rootPath;
  227.             else {
  228.                 $url SITE_URL $rootPath;
  229.             }
  230.         else {
  231.             die("[BUG] Illegal Parametor of \$useSSL ");
  232.         }
  233.  
  234.         $netURL new Net_URL($url);
  235.         // QUERY_STRING 生成
  236.         foreach ($param as $key => $val{
  237.             $netURL->addQueryString($key$val);
  238.         }
  239.  
  240.         return $netURL->getURL();
  241.     }
  242.  
  243.     function getRootPath($path{
  244.         // $path が / で始まっている場合
  245.         if (substr($path01== "/"{
  246.             $realPath realpath(HTML_PATH substr_replace($path""0strlen(URL_DIR)));
  247.         // 相対パスの場合
  248.         else {
  249.             $realPath realpath($path);
  250.         }
  251.  
  252.         // HTML_PATH を削除した文字列を取得.
  253.         // Windowsの場合は, ディレクトリの区切り文字を\から/に変換する
  254.         $realPath str_replace("\\""/"$realPath);
  255.         $htmlPath str_replace("\\""/"HTML_PATH);
  256.  
  257.         $htmlPath rtrim($htmlPath"/");
  258.         $rootPath str_replace($htmlPath""$realPath);
  259.         $rootPath ltrim($rootPath"/");
  260.  
  261.         return $rootPath;
  262.     }
  263.  
  264.     /**
  265.      * ページをリロードする.
  266.      *
  267.      * 引数 $queryString に, $_SERVER['QUERY_STRING'] の値を使用してはならない.
  268.      * この関数は, 内部で LC_Page::sendRedirect() を使用するため,
  269.      * $_SERVER['QUERY_STRING'] の値は自動的に付与される.
  270.      *
  271.      * @param array $queryString QueryString の配列
  272.      * @param bool $removeQueryString 付与されていた QueryString を削除する場合 true
  273.      * @return void 
  274.      * @see Net_URL
  275.      */
  276.     function reload($queryString array()$removeQueryString false{
  277.  
  278.         // 現在の URL を取得
  279.         $netURL new Net_URL();
  280.  
  281.         if ($removeQueryString{
  282.             $netURL->querystring array();
  283.             $_SERVER['QUERY_STRING''';
  284.         }
  285.  
  286.         // QueryString を付与
  287.         if (!empty($queryString)) {
  288.             foreach ($queryString as $key => $val{
  289.                 $netURL->addQueryString($key$val);
  290.             }
  291.         }
  292.  
  293.         $this->sendRedirect($netURL->getURL());
  294.     }
  295.  
  296.     /**
  297.      * クライアントのキャッシュを許可する.
  298.      *
  299.      * session_start時のno-cacheヘッダーを抑制することで
  300.      * 「戻る」ボタン使用時の有効期限切れ表示を抑制する.
  301.      *
  302.      * @access protected
  303.      * @return void 
  304.      */
  305.     function allowClientCache({
  306.         session_cache_limiter('private-no-expire');
  307.     }
  308.  
  309.     /**
  310.      * デバック出力を行う.
  311.      *
  312.      * デバック用途のみに使用すること.
  313.      *
  314.      * @access protected
  315.      * @param mixed $val デバックする要素
  316.      * @return void 
  317.      */
  318.     function p($val{
  319.         SC_Utils_Ex::sfPrintR($val);
  320.     }
  321.  
  322.     // }}}
  323.     // {{{ private functions
  324.  
  325.     /**
  326.      * トランザクショントークン用の予測困難な文字列を生成して返す.
  327.      *
  328.      * @access private
  329.      * @return string トランザクショントークン用の文字列
  330.      */
  331.     function createToken({
  332.         return sha1(uniqid(rand()true));
  333.     }
  334. }
  335. ?>

Documentation generated on Fri, 24 Feb 2012 13:58:23 +0900 by Seasoft