rabin il y a 1 mois
Parent
commit
4f7005df63
2 fichiers modifiés avec 22 ajouts et 1 suppressions
  1. 1 1
      lib/Save.php
  2. 21 0
      lib/View.php

+ 1 - 1
lib/Save.php

@@ -307,7 +307,7 @@ class Save
             $dest = DIRECTORY_SEPARATOR . substr($id, 0, 3) . DIRECTORY_SEPARATOR . substr($id, 3, 2) . DIRECTORY_SEPARATOR . substr($id, 5, 2) . DIRECTORY_SEPARATOR . $uid . '.' . $ext;
             $name = $uid;
         } else {
-            if (!strpos($name, '_')) {
+            if (!strpos($name, '_cr_')) {
                 $name = md5($name);
             }
             $path = array_slice(str_split($name, 2), 0, 3);

+ 21 - 0
lib/View.php

@@ -20,4 +20,25 @@ class View
             return $local;
         }
     }
+
+    # 从内容中解析文件
+    public function file($content, $domain, $local = false)
+    {
+        $content = preg_replace_callback('/[0-9a-zA-Z\-\\/]+(\.jpeg|\.jpg|\.png|\.gif|\.mp3|\.mp4|\.aov|\.m4a)/i', function($matches) use($domain, $local)
+        {
+            $file = $matches[0];
+            $file = ltrim($file, '/');
+            if (!strstr($file, 'http')) {
+                $file = $domain . $file;
+            }
+            if ($local) {
+                $upload = Dever::load('save', 'upload')->act($local, $file);
+                if ($upload && isset($upload['url'])) {
+                    $file = $upload['url'];
+                }
+            }
+            return $file;
+        }, $content);
+        return $content;
+    }
 }