Ignore:
Timestamp:
2011/01/05 23:00:33 (15 years ago)
Author:
Seasoft
Message:

#714(パス指定によるリダイレクトの記述を簡潔にする) 共通処理実装、個別処理の一部を実装
#869(create_date, update_date 列の定義が、表やDBによるバラツキがある)

  • NOT NULL 制約により実装漏れに気づいたので修正

#893(SC_Response#reload を使うべきであろう箇所で SC_Response#sendRedirect を利用している)
#628(未使用処理・定義などの削除)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/SC_Response.php

    r19817 r19832  
    131131    } 
    132132 
    133     function sendRedirect($location) { 
    134         if (preg_match("/(" . preg_quote(HTTP_URL, '/') 
    135                           . "|" . preg_quote(HTTPS_URL, '/') . ")/", $location)) { 
    136  
    137             $netURL = new Net_URL($location); 
    138             $arrQueryString = $netURL->querystring; 
    139  
     133    /** 
     134     * @param string $location 「アプリケーションルートからの相対パス」「現在のURLからの相対パス」「URL」のいずれか 
     135     * @return void 
     136     * @static 
     137     */ 
     138    function sendRedirect($location, $arrQueryString = array(), $inheritQueryString = false, $useSsl = null) { 
     139 
     140        // アプリケーションルートからの相対パス 
     141        if ($location[0] === '/') { 
     142            if (!is_bool($useSsl)) { 
     143                $useSsl = SC_Utils_Ex::sfIsHTTPS(); 
     144            } 
     145            $url = ($useSsl ? HTTPS_URL : HTTP_URL) . substr($location, 1); 
     146        } 
     147        // URL の場合 
     148        elseif (preg_match('/^https?:/', $location)) { 
     149            $url = $location; 
     150            if (is_bool($useSsl)) { 
     151                if ($useSsl) { 
     152                    $pattern = '/^' . preg_quote(HTTP_URL, '/') . '(.*)/'; 
     153                    $replacement = HTTPS_URL . '\1'; 
     154                    $url = preg_replace($pattern, $replacement, $url); 
     155                } 
     156                else { 
     157                    $pattern = '/^' . preg_quote(HTTPS_URL, '/') . '(.*)/'; 
     158                    $replacement = HTTP_URL . '\1'; 
     159                    $url = preg_replace($pattern, $replacement, $url); 
     160                } 
     161            } 
     162        } 
     163        // 現在のURLからの相対パス 
     164        else { 
     165            if (!is_bool($useSsl)) { 
     166                $useSsl = SC_Utils_Ex::sfIsHTTPS(); 
     167            } 
     168            $netUrl = new Net_URL($useSsl ? HTTPS_URL : HTTP_URL); 
     169            $netUrl->path = dirname($_SERVER['PHP_SELF']) . '/' . $location; 
     170            $url = $netUrl->getUrl(); 
     171        } 
     172 
     173        $netUrl = new Net_URL($url); 
     174        $arrQueryString = array_merge($netUrl->querystring, $arrQueryString); 
     175 
     176        if ($inheritQueryString) { 
    140177            if (!empty($_SERVER['QUERY_STRING'])) { 
    141                 $netURL->addRawQueryString($_SERVER['QUERY_STRING']); 
    142             } 
    143  
    144             foreach ($arrQueryString as $key => $val) { 
    145                 $netURL->addQueryString($key, $val); 
    146             } 
    147  
     178                $netUrl->addRawQueryString($_SERVER['QUERY_STRING']); 
     179            } 
     180        } 
     181 
     182        foreach ($arrQueryString as $key => $val) { 
     183            $netUrl->addQueryString($key, $val); 
     184        } 
     185 
     186        $url = $netUrl->getURL(); 
     187 
     188        $pattern = '/^(' . preg_quote(HTTP_URL, '/') . '|' . preg_quote(HTTPS_URL, '/') . ')/'; 
     189        if (preg_match($pattern, $url)) { 
    148190            $session = SC_SessionFactory::getInstance(); 
    149191            if (SC_MobileUserAgent::isMobile() || $session->useCookie() == false) { 
    150                 $netURL->addQueryString(session_name(), session_id()); 
    151             } 
    152  
    153             $netURL->addQueryString(TRANSACTION_ID_NAME, SC_Helper_Session_Ex::getToken()); 
    154             header("Location: " . $netURL->getURL()); 
    155             exit; 
    156         } 
    157         return false; 
    158     } 
    159  
    160     function reload($queryString = array(), $removeQueryString = false) { 
     192                $netUrl->addQueryString(session_name(), session_id()); 
     193            } 
     194 
     195            $netUrl->addQueryString(TRANSACTION_ID_NAME, SC_Helper_Session_Ex::getToken()); 
     196            $url = $netUrl->getURL(); 
     197        } 
     198 
     199        header("Location: $url"); 
     200        exit; 
     201    } 
     202 
     203    /** 
     204     * @static 
     205     */ 
     206    function reload($arrQueryString = array(), $removeQueryString = false) { 
    161207        // 現在の URL を取得 
    162         $netURL = new Net_URL($_SERVER['REQUEST_URI']); 
    163  
    164         if ($removeQueryString) { 
    165             $netURL->querystring = array(); 
    166             $_SERVER['QUERY_STRING'] = ''; // sendRedirect() での処理用らしい 
    167         } 
    168  
    169         // QueryString を付与 
    170         if (!empty($queryString)) { 
    171             foreach ($queryString as $key => $val) { 
    172                 $netURL->addQueryString($key, $val); 
    173             } 
    174         } 
    175  
    176         $this->sendRedirect($netURL->getURL()); 
     208        $netUrl = new Net_URL($_SERVER['REQUEST_URI']); 
     209 
     210        if (!$removeQueryString) { 
     211            $arrQueryString = array_merge($netUrl->querystring, $arrQueryString); 
     212        } 
     213        $netUrl->querystring = array(); 
     214 
     215        $this->sendRedirect($netUrl->getURL(), $arrQueryString); 
    177216    } 
    178217 
Note: See TracChangeset for help on using the changeset viewer.