]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix intendation and doc blocks of preview providers
authorJoas Schilling <nickvergessen@gmx.de>
Fri, 28 Nov 2014 08:16:35 +0000 (09:16 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Fri, 28 Nov 2014 08:28:28 +0000 (09:28 +0100)
lib/private/preview.php
lib/private/preview/image.php
lib/private/preview/markdown.php [new file with mode: 0644]
lib/private/preview/movie.php
lib/private/preview/mp3.php
lib/private/preview/provider.php
lib/private/preview/svg.php
lib/private/preview/txt.php

index 6547d5b3258eedcebbf0c6cbc3aa2c6222517540..f08a0ce2c2775a6d44646b92dfa581e7052fdf6c 100644 (file)
@@ -16,11 +16,6 @@ namespace OC;
 use OC\Preview\Provider;
 use OCP\Files\NotFoundException;
 
-require_once 'preview/image.php';
-require_once 'preview/movie.php';
-require_once 'preview/mp3.php';
-require_once 'preview/svg.php';
-require_once 'preview/txt.php';
 require_once 'preview/office-cl.php';
 require_once 'preview/bitmap.php';
 
index 511052caf2b5f62d1015749c634f9cd53ebd1425..986a44b48fd11c7b3cba5588a4dd0bee77aa5374 100644 (file)
@@ -9,11 +9,16 @@
 namespace OC\Preview;
 
 class Image extends Provider {
-
+       /**
+        * {@inheritDoc}
+        */
        public function getMimeType() {
                return '/image\/(?!tiff$)(?!svg.*).*/';
        }
 
+       /**
+        * {@inheritDoc}
+        */
        public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
                //get fileinfo
                $fileInfo = $fileview->getFileInfo($path);
diff --git a/lib/private/preview/markdown.php b/lib/private/preview/markdown.php
new file mode 100644 (file)
index 0000000..1be01fc
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+class MarkDown extends TXT {
+       /**
+        * {@inheritDoc}
+        */
+       public function getMimeType() {
+               return '/text\/(x-)?markdown/';
+       }
+
+}
index 850027c1a64e23d4c027dde0191d4340c0eb8507..06353ddebb7762267753f4eb3f7e16cb725e6551 100644 (file)
@@ -8,83 +8,87 @@
  */
 namespace OC\Preview;
 
-               class Movie extends Provider {
-                       public static $avconvBinary;
-                       public static $ffmpegBinary;
+class Movie extends Provider {
+       public static $avconvBinary;
+       public static $ffmpegBinary;
 
-                       public function getMimeType() {
-                               return '/video\/.*/';
-                       }
+       /**
+        * {@inheritDoc}
+        */
+       public function getMimeType() {
+               return '/video\/.*/';
+       }
 
-                       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
-                               // TODO: use proc_open() and stream the source file ?
+       /**
+        * {@inheritDoc}
+        */
+       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+               // TODO: use proc_open() and stream the source file ?
 
-                               $fileInfo = $fileview->getFileInfo($path);
-                               $useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted());
+               $fileInfo = $fileview->getFileInfo($path);
+               $useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted());
 
-                               if ($useFileDirectly) {
-                                       $absPath = $fileview->getLocalFile($path);
-                               } else {
-                                       $absPath = \OC_Helper::tmpFile();
+               if ($useFileDirectly) {
+                       $absPath = $fileview->getLocalFile($path);
+               } else {
+                       $absPath = \OC_Helper::tmpFile();
 
-                                       $handle = $fileview->fopen($path, 'rb');
+                       $handle = $fileview->fopen($path, 'rb');
 
-                                       // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB.
-                                       // in some cases 1MB was no enough to generate thumbnail
-                                       $firstmb = stream_get_contents($handle, 5242880);
-                                       file_put_contents($absPath, $firstmb);
-                               }
+                       // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB.
+                       // in some cases 1MB was no enough to generate thumbnail
+                       $firstmb = stream_get_contents($handle, 5242880);
+                       file_put_contents($absPath, $firstmb);
+               }
 
-                               $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5);
-                               if ($result === false) {
-                                       $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1);
-                                       if ($result === false) {
-                                               $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0);
-                                       }
-                               }
+               $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5);
+               if ($result === false) {
+                       $result = $this->generateThumbNail($maxX, $maxY, $absPath, 1);
+                       if ($result === false) {
+                               $result = $this->generateThumbNail($maxX, $maxY, $absPath, 0);
+                       }
+               }
 
-                               if (!$useFileDirectly) {
-                                       unlink($absPath);
-                               }
+               if (!$useFileDirectly) {
+                       unlink($absPath);
+               }
 
-                               return $result;
-                       }
+               return $result;
+       }
 
-                       /**
-                        * @param int $maxX
-                        * @param int $maxY
-                        * @param string $absPath
-                        * @param string $tmpPath
-                        * @param int $second
-                        * @return bool|\OC_Image
-                        */
-                       private function generateThumbNail($maxX, $maxY, $absPath, $second)
-                       {
-                               $tmpPath = \OC_Helper::tmpFile();
+       /**
+        * @param int $maxX
+        * @param int $maxY
+        * @param string $absPath
+        * @param int $second
+        * @return bool|\OC_Image
+        */
+       private function generateThumbNail($maxX, $maxY, $absPath, $second) {
+               $tmpPath = \OC_Helper::tmpFile();
 
-                               if (self::$avconvBinary) {
-                                       $cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) .
-                                               ' -i ' . escapeshellarg($absPath) .
-                                               ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) .
-                                               ' > /dev/null 2>&1';
-                               } else {
-                                       $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) .
-                                               ' -i ' . escapeshellarg($absPath) .
-                                               ' -f mjpeg -vframes 1' .
-                                               ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) .
-                                               ' ' . escapeshellarg($tmpPath) .
-                                               ' > /dev/null 2>&1';
-                               }
+               if (self::$avconvBinary) {
+                       $cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) .
+                               ' -i ' . escapeshellarg($absPath) .
+                               ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) .
+                               ' > /dev/null 2>&1';
+               } else {
+                       $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) .
+                               ' -i ' . escapeshellarg($absPath) .
+                               ' -f mjpeg -vframes 1' .
+                               ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) .
+                               ' ' . escapeshellarg($tmpPath) .
+                               ' > /dev/null 2>&1';
+               }
 
-                               exec($cmd, $output, $returnCode);
+               exec($cmd, $output, $returnCode);
 
-                               if ($returnCode === 0) {
-                                       $image = new \OC_Image();
-                                       $image->loadFromFile($tmpPath);
-                                       unlink($tmpPath);
-                                       return $image->valid() ? $image : false;
-                               }
-                               unlink($tmpPath);
-                               return false;
-                       }
+               if ($returnCode === 0) {
+                       $image = new \OC_Image();
+                       $image->loadFromFile($tmpPath);
+                       unlink($tmpPath);
+                       return $image->valid() ? $image : false;
                }
+               unlink($tmpPath);
+               return false;
+       }
+}
index 661cb92bf624ac6beb0e49eea4175aef1b9a2316..f1a50d99e1383a90bc056284d19013ccf9fe62cb 100644 (file)
@@ -8,11 +8,16 @@
 namespace OC\Preview;
 
 class MP3 extends Provider {
-
+       /**
+        * {@inheritDoc}
+        */
        public function getMimeType() {
                return '/audio\/mpeg/';
        }
 
+       /**
+        * {@inheritDoc}
+        */
        public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
                $getID3 = new \getID3();
 
@@ -31,6 +36,12 @@ class MP3 extends Provider {
                return $this->getNoCoverThumbnail();
        }
 
+       /**
+        * Generates a default image when the file has no cover
+        *
+        * @return false|\OC_Image      False if the default image is missing or invalid,
+        *                                                      otherwise the image is returned as \OC_Image
+        */
        private function getNoCoverThumbnail() {
                $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png';
 
index 10e23efa20ab73cbe61cd3bcd5fa6bdced061818..ead67eaeef7c729f3fd752c9d6d168f1bbc10b31 100644 (file)
@@ -29,7 +29,7 @@ abstract class Provider {
         * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
         * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
         * @param bool $scalingup Disable/Enable upscaling of previews
-        * @param object $fileview fileview object of user folder
+        * @param \OC\Files\View $fileview fileview object of user folder
         * @return mixed
         *              false if no preview was generated
         *              OC_Image object of the preview
index 6ddf893966937f941c0501fc6190da775b30b835..561e87a65005d26ba5afe7d8bd12a101be2e1e4d 100644 (file)
@@ -7,41 +7,43 @@
  */
 namespace OC\Preview;
 
-use Imagick;
-
-               class SVG extends Provider {
-
-                       public function getMimeType() {
-                               return '/image\/svg\+xml/';
+class SVG extends Provider {
+       /**
+        * {@inheritDoc}
+        */
+       public function getMimeType() {
+               return '/image\/svg\+xml/';
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+               try{
+                       $svg = new \Imagick();
+                       $svg->setBackgroundColor(new \ImagickPixel('transparent'));
+
+                       $content = stream_get_contents($fileview->fopen($path, 'r'));
+                       if(substr($content, 0, 5) !== '<?xml') {
+                               $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
                        }
 
-                       public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
-                               try{
-                                       $svg = new Imagick();
-                                       $svg->setBackgroundColor(new \ImagickPixel('transparent'));
-
-                                       $content = stream_get_contents($fileview->fopen($path, 'r'));
-                                       if(substr($content, 0, 5) !== '<?xml') {
-                                               $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
-                                       }
-
-                                       // Do not parse SVG files with references
-                                       if(stripos($content, 'xlink:href') !== false) {
-                                               return false;
-                                       }
-
-                                       $svg->readImageBlob($content);
-                                       $svg->setImageFormat('png32');
-                               } catch (\Exception $e) {
-                                       \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
-                                       return false;
-                               }
-
-
-                               //new image object
-                               $image = new \OC_Image();
-                               $image->loadFromData($svg);
-                               //check if image object is valid
-                               return $image->valid() ? $image : false;
+                       // Do not parse SVG files with references
+                       if(stripos($content, 'xlink:href') !== false) {
+                               return false;
                        }
+
+                       $svg->readImageBlob($content);
+                       $svg->setImageFormat('png32');
+               } catch (\Exception $e) {
+                       \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
+                       return false;
                }
+
+               //new image object
+               $image = new \OC_Image();
+               $image->loadFromData($svg);
+               //check if image object is valid
+               return $image->valid() ? $image : false;
+       }
+}
index ff612e2509a1323f546f068d6526ac869d490f34..8b414dc5726f8f00ac7cab6732e52ceeadc604bd 100644 (file)
@@ -26,7 +26,6 @@ class TXT extends Provider {
         * {@inheritDoc}
         */
        public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
-
                $content = $fileview->fopen($path, 'r');
                $content = stream_get_contents($content,3000);
 
@@ -73,10 +72,3 @@ class TXT extends Provider {
                return $image->valid() ? $image : false;
        }
 }
-
-class MarkDown extends TXT {
-       public function getMimeType() {
-               return '/text\/(x-)?markdown/';
-       }
-
-}