update for short url validation
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 10 Feb 2010 21:51:41 +0000 (21:51 +0000)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 10 Feb 2010 21:51:41 +0000 (21:51 +0000)
Toolkit/ShortURL.php

index 7189021..14c622a 100755 (executable)
@@ -123,5 +123,38 @@ class Toolkit_ShortURL
     }
 
     // }}}
+    // {{{ isValidUrlName()
+    /**
+     * check the short url nam eto make sure it doesn't match any file names in the root
+     * 
+     * @param mixed $url requested short url name
+     * 
+     * @access public
+     * @return string
+     */
+    public function isValidUrlName($url)
+    {
+        if (is_dir(BASE)) {
+            if (file_exists(BASE . $url)) {
+                return false;
+            }
+            if (file_exists(BASE . $url.'.php')) {
+                return false;
+            }
+            if (file_exists(BASE . $url.'.css')) {
+                return false;
+            }
+            if (file_exists(BASE . $url.'.html')) {
+                return false;
+            }
+            if (file_exists(BASE . $url.'.js')) {
+                return false;
+            }
+            return true;
+        } else {
+            throw new Exception('Main Web root dir define BASE not set');
+        }
+    }
+    // }}}
 }
 ?>