dever 4 年之前
父節點
當前提交
cfde69cd47
共有 4 個文件被更改,包括 59 次插入35 次删除
  1. 5 0
      lib/Store/Core.php
  2. 3 1
      lib/Store/Oss.php
  3. 1 1
      lib/Store/Qiniu.php
  4. 50 33
      src/View.php

+ 5 - 0
lib/Store/Core.php

@@ -48,6 +48,11 @@ class Core
 		$this->data = $data;
 	}
 
+	public function getData()
+	{
+		return $this->data;
+	}
+
 	/**
 	 * 获取根目录
 	 * 

+ 3 - 1
lib/Store/Oss.php

@@ -89,7 +89,7 @@ class Oss extends Core implements Config
 
         $this->output['file'] = $this->file;
         $this->output['url'] = $this->host . $this->file;
-        $this->output['url'] = '{uploadYun}['.$this->config['yun'].']' . $this->file;
+        //$this->output['url'] = '{uploadYun}' . $this->file;
         return $this->output['file'];
     }
     
@@ -196,6 +196,8 @@ class Oss extends Core implements Config
             if (isset($config['compress']) && $config['compress'] > 0) {
                 $dest .= ',q_' . $config['compress'];
             }
+        } else {
+            $dest = $this->data['host'] . $source;
         }
         return $dest;
     }

+ 1 - 1
lib/Store/Qiniu.php

@@ -85,7 +85,7 @@ class Qiniu extends Core implements Config
 
         $this->output['file'] = $this->file;
         $this->output['url'] = $this->host . $this->file;
-        $this->output['url'] = '{uploadYun}['.$this->config['yun'].']' . $this->file;
+        //$this->output['url'] = '{uploadYun}' . $this->file;
         return $this->output['file'];
     }
     

+ 50 - 33
src/View.php

@@ -298,6 +298,18 @@ class View
         }
     }
 
+    # 获取云端配置
+    public function getYun($key)
+    {
+        $key = Dever::input('key', $key);
+        $config = Dever::db('upload/upload')->one($key);
+        if ($config && $key && $config['save_type'] >= 2 && $config['yun'] > 0) {
+            $yun = Dever::db('upload/yun')->one($config['yun']);
+            return $yun['host'];
+        }
+        return false;
+    }
+
 	# 根据配置生成缩略图 暂时支持缩略图
 	public function get($file = '')
 	{
@@ -307,46 +319,51 @@ class View
         $type = $array[1];
         $id = $array[2];
 
-        if ($id > 0) {
-            $host = Dever::config('host')->uploadRes;
-            $dest = $file;
-            $path = '';
-            $handle = true;
-            if (strstr($file, '{uploadRes}') || strstr($file, $host)) {
-                # 本地的
-                $root = Dever::data() . 'upload/';
-                $source = Dever::pic($source);
-                $dest = str_replace(array('{uploadRes}', $host), $root, $file);
-                $path = str_replace($root, '', $dest);
-                if (strstr($source, $host)) {
-                    
-                    $source = $root . str_replace($host, '', $source);
-
-                    if (!is_file($source)) {
-                        $source = $array[0];
-                    }
-                }
+        $host = Dever::config('host')->uploadRes;
+        $dest = $file;
+        $path = '';
+        $handle = true;
+        $local = false;
+        if (strstr($file, '{uploadRes}') || strstr($file, $host)) {
+            # 本地的
+            $local = true;
+            $root = Dever::data() . 'upload/';
+            $source = Dever::pic($source);
+            $dest = str_replace(array('{uploadRes}', $host), $root, $file);
+            $path = str_replace($root, '', $dest);
+            if (strstr($source, $host)) {
+                
+                $source = $root . str_replace($host, '', $source);
 
-                if ($type == 'wp') {
-                    $temp = explode('.', $dest);
-                    $dest = $temp[0] . '.webp';
-                    $file = str_replace($root, $host, $dest);
+                if (!is_file($source)) {
+                    $source = $array[0];
                 }
+            }
 
-                if (is_file($dest)) {
-                    $file = $dest;
-                    $handle = false;
-                }
+            if ($type == 'wp') {
+                $temp = explode('.', $dest);
+                $dest = $temp[0] . '.webp';
+                $file = str_replace($root, $host, $dest);
             }
 
-            if ($handle) {
-                $temp = explode('/', $path);
-                $key = $temp[0];
-                $image['file']  = false;
-                $image['key']   = $key;
-                $handle = new Handle($image);
+            if (is_file($dest)) {
+                $file = $dest;
+                $handle = false;
+            }
+        }
+
+        if ($handle) {
+            $temp = explode('/', $path);
+            $key = $temp[0];
+            $image['file']  = false;
+            $image['key']   = $key;
+            $handle = new Handle($image);
+            if ($type) {
                 $method = 'handle_' . $type;
                 $file = $handle->$method($id, $source, $dest, $path);
+            } elseif (!$local) {
+                $yun = $handle->yun->getData();
+                $file = $yun['host'] . $source;
             }
         }