Add URL rewrites/replacements
[phinde.git] / src / phinde / Helper.php
index aeb8ba5d4e8c08874963fc5cf2b28843677d753f..d22b9c89f16a46e6597bd8586ed1b4189a140190 100644 (file)
@@ -3,6 +3,20 @@ namespace phinde;
 
 class Helper
 {
+    public static function rewriteUrl($url)
+    {
+        if (!isset($GLOBALS['phinde']['urlRewrites'])
+            || count($GLOBALS['phinde']['urlRewrites']) == 0
+        ) {
+            return $url;
+        }
+
+        foreach ($GLOBALS['phinde']['urlRewrites'] as $pattern => $replacement) {
+            $url = preg_replace('#' . $pattern . '#', $replacement, $url);
+        }
+        return $url;
+    }
+
     public static function isUrlAllowed($url)
     {
         $urlDomain = parse_url($url, PHP_URL_HOST);