dever 4 vuotta sitten
vanhempi
commit
fa1a103675
1 muutettua tiedostoa jossa 39 lisäystä ja 0 poistoa
  1. 39 0
      lib/Parse.php

+ 39 - 0
lib/Parse.php

@@ -76,6 +76,11 @@ class Parse
 				}
 			}
 
+			if ($v['local'] == 1) {
+				$this->res = $v['res_key'];
+				$value = $this->local($value, $v['type']);
+			}
+
 			$result[$v['key']] = $value;
 			if (Dever::input('test') == 1) {
 				$table[$v['name']] = $value;
@@ -89,6 +94,40 @@ class Parse
 		return $result;
 	}
 
+	private function local($content, $type = 1)
+	{
+		if ($type == 1) {
+			$rule = '<(img|video|audio).+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>';
+			$content = preg_replace_callback('/' . $rule . '/i', array($this, 'local_replace'), $content);
+		} else {
+			$content = $this->copy($content);
+		}
+		
+
+		return $content;
+	}
+
+	private function local_replace($result)
+	{
+		if (isset($result[2]) && $result[2]) {
+			$file = $this->copy($result[2]);
+			if ($file) {
+				$result[0] = str_replace($result[2], $file, $result[0]);
+				return $result[0];
+			}
+		}
+	}
+
+	private function copy($file)
+	{
+		$data = Dever::load('upload/save.copy?file=' . $file . '&key=' . $this->res . '&state=1');
+		if (isset($data['url'])) {
+			return $data['url'];
+		} else {
+			return '';
+		}
+	}
+
 	private function update($data, $project)
 	{
 		$param['option_pid'] = $project;