]> source.dussan.org Git - nextcloud-server.git/commitdiff
respect coding style guidelines
authorGeorg Ehrke <georg@ownCloud.com>
Wed, 29 May 2013 11:03:33 +0000 (13:03 +0200)
committerGeorg Ehrke <georg@ownCloud.com>
Wed, 29 May 2013 11:03:33 +0000 (13:03 +0200)
lib/preview.php
lib/preview/images.php
lib/preview/movies.php
lib/preview/mp3.php
lib/preview/pdf.php
lib/preview/provider.php
lib/preview/svg.php
lib/preview/txt.php
lib/preview/unknown.php

index 855d5a9da04a236c0d4562219344cd2d254f5de8..1150681e64ff03244964939ee8cac50aeadd25db 100755 (executable)
@@ -57,7 +57,7 @@ class Preview {
         *                                      false if thumbnail does not exist
         *                                      path to thumbnail if thumbnail exists
        */
-       public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true, $force = false){
+       public function __construct($user=null, $root='', $file='', $maxX=0, $maxY=0, $scalingup=true, $force=false) {
                //set config
                $this->max_x = \OC_Config::getValue('preview_max_x', null);
                $this->max_y = \OC_Config::getValue('preview_max_y', null);
@@ -73,46 +73,46 @@ class Preview {
                $this->fileview = new \OC\Files\View('/' . $user . '/' . $root);
                $this->userview = new \OC\Files\View('/' . $user);
 
-               if($force !== true){
-                       if(!is_null($this->max_x)){
-                               if($this->maxX > $this->max_x){
+               if($force !== true) {
+                       if(!is_null($this->max_x)) {
+                               if($this->maxX > $this->max_x) {
                                        \OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, \OC_Log::DEBUG);
                                        $this->maxX = $this->max_x;
                                }
                        }
        
-                       if(!is_null($this->max_y)){
-                               if($this->maxY > $this->max_y){
+                       if(!is_null($this->max_y)) {
+                               if($this->maxY > $this->max_y) {
                                        \OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, \OC_Log::DEBUG);
                                        $this->maxY = $this->max_y;
                                }
                        }
        
                        //init providers
-                       if(empty(self::$providers)){
+                       if(empty(self::$providers)) {
                                self::initProviders();
                        }
        
                        //check if there are any providers at all
-                       if(empty(self::$providers)){
+                       if(empty(self::$providers)) {
                                \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR);
                                throw new \Exception('No providers');
                        }
        
                        //validate parameters
-                       if($file === ''){
+                       if($file === '') {
                                \OC_Log::write('core', 'No filename passed', \OC_Log::ERROR);
                                throw new \Exception('File not found');
                        }
        
                        //check if file exists
-                       if(!$this->fileview->file_exists($file)){
+                       if(!$this->fileview->file_exists($file)) {
                                \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::ERROR);
                                throw new \Exception('File not found');
                        }
        
                        //check if given size makes sense
-                       if($maxX === 0 || $maxY === 0){
+                       if($maxX === 0 || $maxY === 0) {
                                \OC_Log::write('core', 'Can not create preview with 0px width or 0px height', \OC_Log::ERROR);
                                throw new \Exception('Height and/or width set to 0');
                        }
@@ -123,7 +123,7 @@ class Preview {
         * @brief returns the path of the file you want a thumbnail from
         * @return string
        */
-       public function getFile(){
+       public function getFile() {
                return $this->file;
        }
 
@@ -131,7 +131,7 @@ class Preview {
         * @brief returns the max width of the preview
         * @return integer
        */
-       public function getMaxX(){
+       public function getMaxX() {
                return $this->maxX;
        }
 
@@ -139,7 +139,7 @@ class Preview {
         * @brief returns the max height of the preview
         * @return integer
        */
-       public function getMaxY(){
+       public function getMaxY() {
                return $this->maxY;
        }
 
@@ -147,7 +147,7 @@ class Preview {
         * @brief returns whether or not scalingup is enabled
         * @return bool
        */
-       public function getScalingup(){
+       public function getScalingup() {
                return $this->scalingup;
        }
 
@@ -155,7 +155,7 @@ class Preview {
         * @brief returns the name of the thumbnailfolder
         * @return string
        */
-       public function getThumbnailsfolder(){
+       public function getThumbnailsfolder() {
                return self::THUMBNAILS_FOLDER;
        }
 
@@ -163,7 +163,7 @@ class Preview {
         * @brief returns the max scale factor
         * @return integer
        */
-       public function getMaxScaleFactor(){
+       public function getMaxScaleFactor() {
                return $this->max_scale_factor;
        }
 
@@ -171,7 +171,7 @@ class Preview {
         * @brief returns the max width set in ownCloud's config
         * @return integer
        */
-       public function getConfigMaxX(){
+       public function getConfigMaxX() {
                return $this->max_x;
        }
 
@@ -179,7 +179,7 @@ class Preview {
         * @brief returns the max height set in ownCloud's config
         * @return integer
        */
-       public function getConfigMaxY(){
+       public function getConfigMaxY() {
                return $this->max_y;
        }
 
@@ -187,7 +187,7 @@ class Preview {
         * @brief deletes previews of a file with specific x and y
         * @return bool
        */
-       public function deletePreview(){
+       public function deletePreview() {
                $fileinfo = $this->fileview->getFileInfo($this->file);
                $fileid = $fileinfo['fileid'];
 
@@ -199,7 +199,7 @@ class Preview {
         * @brief deletes all previews of a file
         * @return bool
        */
-       public function deleteAllPreviews(){
+       public function deleteAllPreviews() {
                $fileinfo = $this->fileview->getFileInfo($this->file);
                $fileid = $fileinfo['fileid'];
 
@@ -214,7 +214,7 @@ class Preview {
         *                              false if thumbnail does not exist
         *                              path to thumbnail if thumbnail exists
        */
-       private function isCached(){
+       private function isCached() {
                $file = $this->file;
                $maxX = $this->maxX;
                $maxY = $this->maxY;
@@ -223,12 +223,12 @@ class Preview {
                $fileinfo = $this->fileview->getFileInfo($file);
                $fileid = $fileinfo['fileid'];
 
-               if(!$this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid)){
+               if(!$this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid)) {
                        return false;
                }
 
                //does a preview with the wanted height and width already exist?
-               if($this->userview->file_exists(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')){
+               if($this->userview->file_exists(self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png')) {
                        return self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png';
                }
 
@@ -238,20 +238,20 @@ class Preview {
                $possiblethumbnails = array();
 
                $allthumbnails = $this->userview->getDirectoryContent(self::THUMBNAILS_FOLDER . '/' . $fileid);
-               foreach($allthumbnails as $thumbnail){
+               foreach($allthumbnails as $thumbnail) {
                        $size = explode('-', $thumbnail['name']);
                        $x = $size[0];
                        $y = $size[1];
 
                        $aspectratio = $x / $y;
-                       if($aspectratio != $wantedaspectratio){
+                       if($aspectratio != $wantedaspectratio) {
                                continue;
                        }
 
-                       if($x < $maxX || $y < $maxY){
-                               if($scalingup){
+                       if($x < $maxX || $y < $maxY) {
+                               if($scalingup) {
                                        $scalefactor = $maxX / $x;
-                                       if($scalefactor > $this->max_scale_factor){
+                                       if($scalefactor > $this->max_scale_factor) {
                                                continue;
                                        }
                                }else{
@@ -261,26 +261,26 @@ class Preview {
                        $possiblethumbnails[$x] = $thumbnail['path'];
                }
 
-               if(count($possiblethumbnails) === 0){
+               if(count($possiblethumbnails) === 0) {
                        return false;
                }
 
-               if(count($possiblethumbnails) === 1){
+               if(count($possiblethumbnails) === 1) {
                        return current($possiblethumbnails);
                }
 
                ksort($possiblethumbnails);
 
-               if(key(reset($possiblethumbnails)) > $maxX){
+               if(key(reset($possiblethumbnails)) > $maxX) {
                        return current(reset($possiblethumbnails));
                }
 
-               if(key(end($possiblethumbnails)) < $maxX){
+               if(key(end($possiblethumbnails)) < $maxX) {
                        return current(end($possiblethumbnails));
                }
 
-               foreach($possiblethumbnails as $width => $path){
-                       if($width < $maxX){
+               foreach($possiblethumbnails as $width => $path) {
+                       if($width < $maxX) {
                                continue;
                        }else{
                                return $path;
@@ -296,7 +296,7 @@ class Preview {
         * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly
         * @return image
        */
-       public function getPreview(){
+       public function getPreview() {
                $file = $this->file;
                $maxX = $this->maxX;
                $maxY = $this->maxY;
@@ -307,7 +307,7 @@ class Preview {
 
                $cached = self::isCached();
 
-               if($cached){
+               if($cached) {
                        $image = new \OC_Image($this->userview->file_get_contents($cached, 'r'));
                        $this->preview = $image;
                }else{
@@ -315,25 +315,25 @@ class Preview {
 
                        $preview;
 
-                       foreach(self::$providers as $supportedmimetype => $provider){
-                               if(!preg_match($supportedmimetype, $mimetype)){
+                       foreach(self::$providers as $supportedmimetype => $provider) {
+                               if(!preg_match($supportedmimetype, $mimetype)) {
                                        continue;
                                }
 
                                $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup, $this->fileview);
 
-                               if(!$preview){
+                               if(!$preview) {
                                        continue;
                                }
 
                                //are there any cached thumbnails yet
-                               if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/') === false){
+                               if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/') === false) {
                                        $this->userview->mkdir(self::THUMBNAILS_FOLDER . '/');
                                }
 
                                //cache thumbnail
                                $cachepath = self::THUMBNAILS_FOLDER . '/' . $fileid . '/' . $maxX . '-' . $maxY . '.png';
-                               if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/') === false){
+                               if($this->userview->is_dir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/') === false) {
                                        $this->userview->mkdir(self::THUMBNAILS_FOLDER . '/' . $fileid . '/');
                                }
                                $this->userview->file_put_contents($cachepath, $preview->data());
@@ -354,10 +354,10 @@ class Preview {
         * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly
         * @return void
        */
-       public function showPreview(){
+       public function showPreview() {
                \OCP\Response::enableCaching(3600 * 24); // 24 hour
                $preview = $this->getPreview();
-               if($preview){
+               if($preview) {
                        $preview->show();
                }
        }
@@ -366,7 +366,7 @@ class Preview {
         * @brief resize, crop and fix orientation
         * @return image
        */
-       public function resizeAndCrop(){
+       public function resizeAndCrop() {
                $this->preview->fixOrientation();
 
                $image = $this->preview;
@@ -374,7 +374,7 @@ class Preview {
                $y = $this->maxY;
                $scalingup = $this->scalingup;
 
-               if(!($image instanceof \OC_Image)){
+               if(!($image instanceof \OC_Image)) {
                        \OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', \OC_Log::DEBUG);
                        return;
                }
@@ -382,14 +382,14 @@ class Preview {
                $realx = (int) $image->width();
                $realy = (int) $image->height();
 
-               if($x === $realx && $y === $realy){
+               if($x === $realx && $y === $realy) {
                        return $image;
                }
 
                $factorX = $x / $realx;
                $factorY = $y / $realy;
                
-               if($factorX >= $factorY){
+               if($factorX >= $factorY) {
                        $factor = $factorX;
                }else{
                        $factor = $factorY;
@@ -399,8 +399,8 @@ class Preview {
                if($scalingup === false) {
                        if($factor>1) $factor=1;
                }
-               if(!is_null($this->max_scale_factor)){
-                       if($factor > $this->max_scale_factor){
+               if(!is_null($this->max_scale_factor)) {
+                       if($factor > $this->max_scale_factor) {
                                \OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $this->max_scale_factor, \OC_Log::DEBUG);
                                $factor = $this->max_scale_factor;
                        }
@@ -411,12 +411,12 @@ class Preview {
                // resize
                $image->preciseResize($newXsize, $newYsize);
 
-               if($newXsize === $x && $newYsize === $y){
+               if($newXsize === $x && $newYsize === $y) {
                        $this->preview = $image;
                        return;
                }
 
-               if($newXsize >= $x && $newYsize >= $y){
+               if($newXsize >= $x && $newYsize >= $y) {
                        $cropX = floor(abs($x - $newXsize) * 0.5);
                        $cropY = floor(abs($y - $newYsize) * 0.5);
 
@@ -426,13 +426,13 @@ class Preview {
                        return;
                }
 
-               if($newXsize < $x || $newYsize < $y){
-                       if($newXsize > $x){
+               if($newXsize < $x || $newYsize < $y) {
+                       if($newXsize > $x) {
                                $cropX = floor(($newXsize - $x) * 0.5);
                                $image->crop($cropX, 0, $x, $newYsize);
                        }
 
-                       if($newYsize > $y){
+                       if($newYsize > $y) {
                                $cropY = floor(($newYsize - $y) * 0.5);
                                $image->crop(0, $cropY, $newXsize, $y);
                        }
@@ -467,7 +467,7 @@ class Preview {
         * @param string $provider class name of a Preview_Provider
         * @return void
         */
-       public static function registerProvider($class, $options=array()){
+       public static function registerProvider($class, $options=array()) {
                self::$registeredProviders[]=array('class'=>$class, 'options'=>$options);
        }
 
@@ -475,7 +475,7 @@ class Preview {
         * @brief create instances of all the registered preview providers
         * @return void
         */
-       private static function initProviders(){
+       private static function initProviders() {
                if(count(self::$providers)>0) {
                        return;
                }
@@ -497,7 +497,7 @@ class Preview {
         * @brief method that handles preview requests from users that are logged in
         * @return void
        */
-       public static function previewRouter($params){
+       public static function previewRouter($params) {
                \OC_Util::checkLoggedIn();
 
                $file = '';
@@ -514,11 +514,11 @@ class Preview {
                if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y'];
                if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup'];
 
-               if($file !== '' && $maxX !== 0 && $maxY !== 0){
+               if($file !== '' && $maxX !== 0 && $maxY !== 0) {
                        try{
                                $preview = new Preview(\OC_User::getUser(), 'files', $file,  $maxX, $maxY, $scalingup);
                                $preview->showPreview();
-                       }catch(Exception $e){
+                       }catch(Exception $e) {
                                \OC_Response::setStatus(404);
                                \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
                                exit;
@@ -533,7 +533,7 @@ class Preview {
         * @brief method that handles preview requests from users that are not logged in / view shared folders that are public
         * @return void
        */
-       public static function publicPreviewRouter($params){
+       public static function publicPreviewRouter($params) {
                $file = '';
                $maxX = 0;
                $maxY = 0;
@@ -560,21 +560,21 @@ class Preview {
                
                //clean up file parameter
                $file = \OC\Files\Filesystem::normalizePath($file);
-               if(!\OC\Files\Filesystem::isValidPath($file)){
+               if(!\OC\Files\Filesystem::isValidPath($file)) {
                        \OC_Response::setStatus(403);
                        exit;
                }
 
                $path = \OC\Files\Filesystem::normalizePath($path, false);
-               if(substr($path, 0, 1) == '/'){
+               if(substr($path, 0, 1) == '/') {
                        $path = substr($path, 1);
                }
 
-               if($userid !== null && $path !== null){
+               if($userid !== null && $path !== null) {
                        try{
                                $preview = new Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup);
                                $preview->showPreview();
-                       }catch(Exception $e){
+                       }catch(Exception $e) {
                                \OC_Response::setStatus(404);
                                \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
                                exit;
@@ -585,13 +585,13 @@ class Preview {
                }
        }
 
-       public static function post_write($args){
+       public static function post_write($args) {
                self::post_delete($args);
        }
        
-       public static function post_delete($args){
+       public static function post_delete($args) {
                $path = $args['path'];
-               if(substr($path, 0, 1) == '/'){
+               if(substr($path, 0, 1) == '/') {
                        $path = substr($path, 1);
                }
                $preview = new Preview(\OC_User::getUser(), 'files/', $path, 0, 0, false, true);
index c62fc5397e523f434e02ca417eb280e17eddb4ff..933d65ec59ee3af44acf42c98b31a1630cfb2e7c 100644 (file)
@@ -10,16 +10,16 @@ namespace OC\Preview;
 
 class Image extends Provider{
 
-       public function getMimeType(){
+       public function getMimeType() {
                return '/image\/.*/';
        }
 
-       public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
+       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
                //get fileinfo
                $fileinfo = $fileview->getFileInfo($path);
 
                //check if file is encrypted
-               if($fileinfo['encrypted'] === true){
+               if($fileinfo['encrypted'] === true) {
                        $image = new \OC_Image($fileview->fopen($path, 'r'));
                }else{
                        $image = new \OC_Image();
index 14ac97b552d1a1f7318ef80135a304a98f6b83b0..aa97c3f43fce17387ab11725f7d7a70cdd2b13a5 100644 (file)
@@ -8,14 +8,14 @@
  */
 namespace OC\Preview;
 
-if(!is_null(shell_exec('ffmpeg -version'))){
+if(!is_null(shell_exec('ffmpeg -version'))) {
        class Movie extends Provider{
 
-               public function getMimeType(){
+               public function getMimeType() {
                        return '/video\/.*/';
                }
 
-               public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
+               public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
                        //get fileinfo
                        $fileinfo = $fileview->getFileInfo($path);
 
index d62c7230788cce9e6b8aa481793330a2e4e83409..cfe78f32727bac78243e7b4bebe4761b73e223f0 100644 (file)
@@ -11,7 +11,7 @@ require_once('getid3/getid3.php');
 
 class MP3 extends Provider{
 
-       public function getMimeType(){
+       public function getMimeType() {
                return '/audio\/mpeg/';
        }
 
@@ -33,7 +33,7 @@ class MP3 extends Provider{
                return $image;
        }
 
-       public function getNoCoverThumbnail($maxX, $maxY){
+       public function getNoCoverThumbnail($maxX, $maxY) {
                $image = new \OC_Image();
                return $image;
        }
index 4dd4538545cc75369d91a0b47cece8715255a66b..66570b05aa46dc037d8f168b85a3b734805c2c00 100644 (file)
@@ -7,11 +7,11 @@
  */
 namespace OC\Preview;
 
-if (extension_loaded('imagick')){
+if (extension_loaded('imagick')) {
 
        class PDF extends Provider{
 
-               public function getMimeType(){
+               public function getMimeType() {
                        return '/application\/pdf/';
                }
 
index 1e8d537adc8fc4ed10ccb6f191a7ea59526863ed..58e7ad7f453436145cfbe0fe6828276ae9554cdf 100644 (file)
@@ -18,5 +18,5 @@ abstract class Provider{
         * @param string $query
         * @return
         */
-       abstract public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview);
+       abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview);
 }
index 70be263189d7b5c92465f24e9273d16cafd58552..746315d6e6a07b5bb37c7682a16116cf495a8fe7 100644 (file)
@@ -7,11 +7,11 @@
  */
 namespace OC\Preview;
 
-if (extension_loaded('imagick')){
+if (extension_loaded('imagick')) {
 
        class SVG extends Provider{
 
-               public function getMimeType(){
+               public function getMimeType() {
                        return '/image\/svg\+xml/';
                }
 
@@ -20,7 +20,7 @@ if (extension_loaded('imagick')){
                        $svg->setResolution($maxX, $maxY);
 
                        $content = stream_get_contents($fileview->fopen($path, 'r'));
-                       if(substr($content, 0, 5) !== '<?xml'){
+                       if(substr($content, 0, 5) !== '<?xml') {
                                $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
                        }
 
index 4004ecd3fcebc44772159f63e3aa515d19eb9769..5961761aaa4c35759bbaaf76b09fb634bfe628dc 100644 (file)
@@ -9,11 +9,11 @@ namespace OC\Preview;
 
 class TXT extends Provider{
 
-       public function getMimeType(){
+       public function getMimeType() {
                return '/text\/.*/';
        }
 
-       public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
+       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
                $content = $fileview->fopen($path, 'r');
                $content = stream_get_contents($content);
 
@@ -27,7 +27,7 @@ class TXT extends Provider{
                $imagecolor = imagecolorallocate($image, 255, 255, 255);
                $textcolor = imagecolorallocate($image, 0, 0, 0);
 
-               foreach($lines as $index => $line){
+               foreach($lines as $index => $line) {
                        $index = $index + 1;
 
                        $x = (int) 1;
@@ -35,7 +35,7 @@ class TXT extends Provider{
 
                        imagestring($image, 1, $x, $y, $line, $textcolor);
 
-                       if(($index * $linesize) >= $maxY){
+                       if(($index * $linesize) >= $maxY) {
                                break;
                        }
                }
index 6a8d2fbb75c21a2e5024fa1a97a782349d5ef5f0..2977cd689230e4abe470cf7c036a21426a8f1c8b 100644 (file)
@@ -10,11 +10,11 @@ namespace OC\Preview;
 
 class Unknown extends Provider{
 
-       public function getMimeType(){
+       public function getMimeType() {
                return '/.*/';
        }
 
-       public function getThumbnail($path, $maxX, $maxY, $scalingup,$fileview) {
+       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
                /*$mimetype = $fileview->getMimeType($path);
                $info = $fileview->getFileInfo($path);
                $name = array_key_exists('name', $info) ? $info['name'] : '';