Completed
Push — master ( 39d391...be0e46 )
by John
22:18 queued 17s
created
lib/private/Preview/ProviderV2.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
 	/**
44 44
 	 * @return string Regex with the mimetypes that are supported by this provider
45 45
 	 */
46
-	abstract public function getMimeType(): string ;
46
+	abstract public function getMimeType(): string;
47 47
 
48 48
 	/**
49 49
 	 * Check if a preview can be generated for $path
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -14,92 +14,92 @@
 block discarded – undo
14 14
 use OCP\Preview\IProviderV2;
15 15
 
16 16
 abstract class ProviderV2 implements IProviderV2 {
17
-	/** @var array */
18
-	protected $options;
19
-
20
-	/** @var array */
21
-	protected $tmpFiles = [];
22
-
23
-	/**
24
-	 * Constructor
25
-	 *
26
-	 * @param array $options
27
-	 */
28
-	public function __construct(array $options = []) {
29
-		$this->options = $options;
30
-	}
31
-
32
-	/**
33
-	 * @return string Regex with the mimetypes that are supported by this provider
34
-	 */
35
-	abstract public function getMimeType(): string ;
36
-
37
-	/**
38
-	 * Check if a preview can be generated for $path
39
-	 *
40
-	 * @param FileInfo $file
41
-	 * @return bool
42
-	 */
43
-	public function isAvailable(FileInfo $file): bool {
44
-		return true;
45
-	}
46
-
47
-	/**
48
-	 * get thumbnail for file at path $path
49
-	 *
50
-	 * @param File $file
51
-	 * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
52
-	 * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
53
-	 * @return null|\OCP\IImage false if no preview was generated
54
-	 * @since 17.0.0
55
-	 */
56
-	abstract public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage;
57
-
58
-	protected function useTempFile(File $file): bool {
59
-		return $file->isEncrypted() || !$file->getStorage()->isLocal();
60
-	}
61
-
62
-	/**
63
-	 * Get a path to either the local file or temporary file
64
-	 *
65
-	 * @param File $file
66
-	 * @param int $maxSize maximum size for temporary files
67
-	 * @return string|false
68
-	 */
69
-	protected function getLocalFile(File $file, ?int $maxSize = null) {
70
-		if ($this->useTempFile($file)) {
71
-			$absPath = \OC::$server->getTempManager()->getTemporaryFile();
72
-
73
-			$content = $file->fopen('r');
74
-			if ($content === false) {
75
-				return false;
76
-			}
77
-
78
-			if ($maxSize) {
79
-				$content = stream_get_contents($content, $maxSize);
80
-			}
81
-
82
-			file_put_contents($absPath, $content);
83
-			$this->tmpFiles[] = $absPath;
84
-			return $absPath;
85
-		} else {
86
-			$path = $file->getStorage()->getLocalFile($file->getInternalPath());
87
-			if (is_string($path)) {
88
-				return $path;
89
-			} else {
90
-				return false;
91
-			}
92
-		}
93
-	}
94
-
95
-	/**
96
-	 * Clean any generated temporary files
97
-	 */
98
-	protected function cleanTmpFiles(): void {
99
-		foreach ($this->tmpFiles as $tmpFile) {
100
-			unlink($tmpFile);
101
-		}
102
-
103
-		$this->tmpFiles = [];
104
-	}
17
+    /** @var array */
18
+    protected $options;
19
+
20
+    /** @var array */
21
+    protected $tmpFiles = [];
22
+
23
+    /**
24
+     * Constructor
25
+     *
26
+     * @param array $options
27
+     */
28
+    public function __construct(array $options = []) {
29
+        $this->options = $options;
30
+    }
31
+
32
+    /**
33
+     * @return string Regex with the mimetypes that are supported by this provider
34
+     */
35
+    abstract public function getMimeType(): string ;
36
+
37
+    /**
38
+     * Check if a preview can be generated for $path
39
+     *
40
+     * @param FileInfo $file
41
+     * @return bool
42
+     */
43
+    public function isAvailable(FileInfo $file): bool {
44
+        return true;
45
+    }
46
+
47
+    /**
48
+     * get thumbnail for file at path $path
49
+     *
50
+     * @param File $file
51
+     * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
52
+     * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
53
+     * @return null|\OCP\IImage false if no preview was generated
54
+     * @since 17.0.0
55
+     */
56
+    abstract public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage;
57
+
58
+    protected function useTempFile(File $file): bool {
59
+        return $file->isEncrypted() || !$file->getStorage()->isLocal();
60
+    }
61
+
62
+    /**
63
+     * Get a path to either the local file or temporary file
64
+     *
65
+     * @param File $file
66
+     * @param int $maxSize maximum size for temporary files
67
+     * @return string|false
68
+     */
69
+    protected function getLocalFile(File $file, ?int $maxSize = null) {
70
+        if ($this->useTempFile($file)) {
71
+            $absPath = \OC::$server->getTempManager()->getTemporaryFile();
72
+
73
+            $content = $file->fopen('r');
74
+            if ($content === false) {
75
+                return false;
76
+            }
77
+
78
+            if ($maxSize) {
79
+                $content = stream_get_contents($content, $maxSize);
80
+            }
81
+
82
+            file_put_contents($absPath, $content);
83
+            $this->tmpFiles[] = $absPath;
84
+            return $absPath;
85
+        } else {
86
+            $path = $file->getStorage()->getLocalFile($file->getInternalPath());
87
+            if (is_string($path)) {
88
+                return $path;
89
+            } else {
90
+                return false;
91
+            }
92
+        }
93
+    }
94
+
95
+    /**
96
+     * Clean any generated temporary files
97
+     */
98
+    protected function cleanTmpFiles(): void {
99
+        foreach ($this->tmpFiles as $tmpFile) {
100
+            unlink($tmpFile);
101
+        }
102
+
103
+        $this->tmpFiles = [];
104
+    }
105 105
 }
Please login to merge, or discard this patch.
lib/private/Preview/StarOffice.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 
24 24
 //.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
25 25
 class StarOffice extends Office {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/application\/vnd.sun.xml.*/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/application\/vnd.sun.xml.*/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/MSOffice2007.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 
24 24
 //.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
25 25
 class MSOffice2007 extends Office {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/application\/vnd.openxmlformats-officedocument.*/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/application\/vnd.openxmlformats-officedocument.*/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/BMP.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 namespace OC\Preview;
24 24
 
25 25
 class BMP extends Image {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/image\/bmp/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/image\/bmp/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/GIF.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 namespace OC\Preview;
24 24
 
25 25
 class GIF extends Image {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/image\/gif/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/image\/gif/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/XBitmap.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 namespace OC\Preview;
24 24
 
25 25
 class XBitmap extends Image {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/image\/x-xbitmap/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/image\/x-xbitmap/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/PNG.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 namespace OC\Preview;
24 24
 
25 25
 class PNG extends Image {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/image\/png/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/image\/png/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/MSOffice2003.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 
24 24
 //.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m)
25 25
 class MSOffice2003 extends Office {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/application\/vnd.ms-.*/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/application\/vnd.ms-.*/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/JPEG.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 namespace OC\Preview;
24 24
 
25 25
 class JPEG extends Image {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/image\/jpeg/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/image\/jpeg/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.