Support subscriptions to redirect URLs
[phinde.git] / src / phinde / Helper.php
index 00215fee0ca72b0cdb5d1fee5f175d8b46ad0202..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);
@@ -77,5 +91,14 @@ class Helper
         $diff = microtime(true) - static::$timer[$timer];
         echo '+timer: ' . number_format($diff, 3) . 'ms ' . $timer . "\n";
     }
+
+    public static function baseDoc($url)
+    {
+        $esDoc = new \stdClass();
+        $esDoc->status = new \stdClass();
+        $esDoc->url = $url;
+        $esDoc->schemalessUrl = Helper::noSchema($url);
+        return $esDoc;
+    }
 }
 ?>