]> _ Git - cubist_util.git/commitdiff
wip #6014 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Jun 2023 09:42:52 +0000 (11:42 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Jun 2023 09:42:52 +0000 (11:42 +0200)
src/Files/VirtualDirectory.php
src/Url.php

index 3d2d4c944f2588e89da6c425c8f0d557b2d24f2a..607a2fc5ce2009f29278f63692b95920504dd94d 100644 (file)
@@ -26,7 +26,7 @@ class VirtualDirectory
     public function copy($from, $to, $prepend = false)
     {
         if (!file_exists($from)) {
-            throw new \Exception(sprintf('File %s doesn\'t exist (to %s)', $from, $to));
+            throw new \Exception(sprintf('File "%s" doesn\'t exist (to %s)', $from, $to));
         }
         $realto = $this->path($to);
         if (!$realto) {
index 1a83c0ffc7ddbce831fe528a0e87ed69cf30cfd5..d273c6e088fd0a481a704459377b75f51660febd 100644 (file)
@@ -4,74 +4,82 @@ namespace Cubist\Util;
 class Url
 {
 
-       public static function isLocal($url, $site_url=null)
-       {
-               if (null!==$site_url && strpos($url, $site_url) === 0) {
-                       return true;
-               }
+    public static function isLocal($url, $site_url = null)
+    {
+        if (null !== $site_url && strpos($url, $site_url) === 0) {
+            return true;
+        }
 
-               if (strpos($url, "//") === 0) {
-                       return false;
-               }
-               $u = parse_url($url);
+        if (strpos($url, "//") === 0) {
+            return false;
+        }
+        $u = parse_url($url);
         return !(isset($u['scheme']) && $u['scheme'] != '');
     }
 
-       public static function extractPathComponents($path)
-       {
-               $path = urldecode($path);
-               $path = trim($path, '/');
-               if ($path == '') {
-                       return [];
-               }
+    public static function extractPathComponents($path)
+    {
+        $path = urldecode($path);
+        $path = trim($path, '/');
+        if ($path == '') {
+            return [];
+        }
 
         return explode('/', $path);
     }
 
-       public static function isDistant($url, $site_url=null)
-       {
-               return !self::isLocal($url, $site_url);
-       }
+    public static function isDistant($url, $site_url = null)
+    {
+        return !self::isLocal($url, $site_url);
+    }
 
-       public static function toAbsolute($url, $site_url=null)
-       {
-               if (strpos($url, '/') === 0) {
-                       $url = $site_url . $url;
-               }
-               return $url;
-       }
+    public static function toAbsolute($url, $site_url = null)
+    {
+        if (strpos($url, '/') === 0) {
+            $url = $site_url . $url;
+        }
+        return $url;
+    }
 
-       public static function createGetUrl($url, $options)
-       {
-               $res = $url;
-               $o = array();
-               foreach ($options as $k => $v) {
-                       $o[] = $k . '=' . rawurlencode($v);
-               }
-               if (count($o)) {
-                       $res .= '?' . implode('&', $o);
-               }
-               return $res;
-       }
+    public static function createGetUrl($url, $options)
+    {
+        $res = $url;
+        $o = array();
+        foreach ($options as $k => $v) {
+            $o[] = $k . '=' . rawurlencode($v);
+        }
+        if (count($o)) {
+            $res .= '?' . implode('&', $o);
+        }
+        return $res;
+    }
 
-       public static function sameDomain($url, $domain, $site_url, $acceptSubdomain = false)
-       {
-               if (self::isLocal($url, $site_url)) {
-                       return true;
-               }
+    public static function sameDomain($url, $domain, $site_url, $acceptSubdomain = false)
+    {
+        if (self::isLocal($url, $site_url)) {
+            return true;
+        }
 
-               $host = parse_url($url, PHP_URL_HOST);
-               if (!$acceptSubdomain) {
-                       return $host === $domain;
-               }
-               return preg_match("/" . $domain . "$/", $host);
-       }
+        $host = parse_url($url, PHP_URL_HOST);
+        if (!$acceptSubdomain) {
+            return $host === $domain;
+        }
+        return preg_match("/" . $domain . "$/", $host);
+    }
 
-       public static function getFilePath($url, $site_url, $public_path)
-       {
-               if (self::isLocal($url, $site_url)) {
-                       return $public_path . $url;
-               }
-       }
+    public static function getFilePath($url, $site_url, $public_path)
+    {
+        if (self::isLocal($url, $site_url)) {
+            return $public_path . $url;
+        }
+    }
+
+    public static function linkIfisURL($str, $target = "_self", $rel = "noopenner")
+    {
+        if (self::isDistant($str)) {
+            return '<a href="' . e($str) . '" target="' . $target . '" rel="' . $rel . '">' . e($str) . '</a>';
+        }
+        return $str;
+    }
 
 }