OSDN Git Service

modify behavior of Ethna_View_Redirect::preforward
authorSotaro Karasawa <sotaro.k@gmail.com>
Thu, 13 Aug 2009 17:23:07 +0000 (02:23 +0900)
committerSotaro Karasawa <sotaro.k@gmail.com>
Thu, 13 Aug 2009 17:23:07 +0000 (02:23 +0900)
CHANGES
class/View/Ethna_View_Redirect.php

diff --git a/CHANGES b/CHANGES
index f2478d2..e67e44d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
 -- Plugin に設定を受け渡す方法を変更したため,etcのskelを変更
 --- それに伴い,Ethna_Plugin_Cachemanager_Memcacheの設定方法を変更
 - Ethna_Plugin_Cachemanager に config からデフォルト の namespace を指定可能とした
+- Ethna_View_Redirect の挙動変更
+-- URLが指定されなかった場合,アプリのURLのトップにリダイレクトする
+-- 相対URLが指定された場合は,自分のアプリのURLに結合する
+-- 絶対URLが指定された場合,そのURLにリダイレクトする
 
 *** bug fix
 
index e0a6668..ad6fa12 100644 (file)
@@ -34,11 +34,40 @@ class Ethna_View_Redirect extends Ethna_ViewClass
     function preforward($url = NULL)
     {
         if (is_null($url)) {
-            Ethna::raiseWarning(
-                "URL is not set! use array('redirect', $url); on ActionClass."
-            );
+            $this->redirect($this->config->get('url'));
+        }
+        else {
+            if ($this->isAbsoluteUrl($url)) {
+                $this->redirect($url);
+            }
+            else {
+                if (substr($this->config->get('url'), -1) === '/') {
+                    $base = $this->config->get('url');
+                }
+                else {
+                    $base = $this->config->get('url') . '/';
+                }
+
+                if (substr($url, 0) === '/') {
+                    $suff = substr($url, 1);
+                }
+                else {
+                    $suff = $url;
+                }
+
+                $this->redirect($base . $suff);
+            }
+        }
+    }
+
+    function isAbsoluteUrl($url)
+    {
+        if (preg_match("@^(https?|ftp)://.+@", $url)) {
+            return true;
+        }
+        else {
+            return false;
         }
-        $this->redirect($url);
     }
 
     /**