]> source.dussan.org Git - nextcloud-server.git/commitdiff
any preview requiring the which command will not be used on Windows
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 14 Oct 2013 22:15:45 +0000 (00:15 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 14 Oct 2013 22:15:45 +0000 (00:15 +0200)
lib/private/preview/movies.php
lib/private/preview/office-cl.php
lib/private/preview/office.php

index c318137ff0e06b9ca24836b60455114938003954..dc50d1603469a6d68ec9596d0e4fac77b5e2ea49 100644 (file)
@@ -8,40 +8,44 @@
  */
 namespace OC\Preview;
 
-$isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions')));
-$whichAVCONV = shell_exec('which avconv');
-$isAVCONVAvailable = !empty($whichAVCONV);
+// movie preview is currently not supported on Windows
+if (!\OC_Util::runningOnWindows()) {
+       $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions')));
+       $whichAVCONV = shell_exec('which avconv');
+       $isAVCONVAvailable = !empty($whichAVCONV);
 
-if($isShellExecEnabled && $isAVCONVAvailable) {
+       if($isShellExecEnabled && $isAVCONVAvailable) {
 
-       class Movie extends Provider {
+               class Movie extends Provider {
 
-               public function getMimeType() {
-                       return '/video\/.*/';
-               }
+                       public function getMimeType() {
+                               return '/video\/.*/';
+                       }
+
+                       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+                               $absPath = \OC_Helper::tmpFile();
+                               $tmpPath = \OC_Helper::tmpFile();
 
-               public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
-                       $absPath = \OC_Helper::tmpFile();
-                       $tmpPath = \OC_Helper::tmpFile();
+                               $handle = $fileview->fopen($path, 'rb');
 
-                       $handle = $fileview->fopen($path, 'rb');
+                               $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576
+                               file_put_contents($absPath, $firstmb);
 
-                       $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576
-                       file_put_contents($absPath, $firstmb);
+                               //$cmd = 'ffmpeg -y  -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath;
+                               $cmd = 'avconv -an -y -ss 1 -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 ' . escapeshellarg($tmpPath);
 
-                       //$cmd = 'ffmpeg -y  -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath;
-                       $cmd = 'avconv -an -y -ss 1 -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 ' . escapeshellarg($tmpPath);
-                       
-                       shell_exec($cmd);
+                               shell_exec($cmd);
 
-                       $image = new \OC_Image($tmpPath);
+                               $image = new \OC_Image($tmpPath);
 
-                       unlink($absPath);
-                       unlink($tmpPath);
+                               unlink($absPath);
+                               unlink($tmpPath);
 
-                       return $image->valid() ? $image : false;
+                               return $image->valid() ? $image : false;
+                       }
                }
+
+               \OC\Preview::registerProvider('OC\Preview\Movie');
        }
+}
 
-       \OC\Preview::registerProvider('OC\Preview\Movie');
-}
\ No newline at end of file
index 112909d652352c9d806a0fd98adeee4e8b806d93..8f2e06c050be1a00b5278632f0ad30dfca11e4b3 100644 (file)
  */
 namespace OC\Preview;
 
-//we need imagick to convert
-class Office extends Provider {
+// office preview is currently not supported on Windows
+if (!\OC_Util::runningOnWindows()) {
 
-       private $cmd;
+       //we need imagick to convert
+       class Office extends Provider {
 
-       public function getMimeType() {
-               return null;
-       }
+               private $cmd;
 
-       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
-               $this->initCmd();
-               if(is_null($this->cmd)) {
-                       return false;
+               public function getMimeType() {
+                       return null;
                }
 
-               $absPath = $fileview->toTmpFile($path);
+               public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+                       $this->initCmd();
+                       if(is_null($this->cmd)) {
+                               return false;
+                       }
+
+                       $absPath = $fileview->toTmpFile($path);
+
+                       $tmpDir = get_temp_dir();
 
-               $tmpDir = get_temp_dir();
+                       $defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ';
+                       $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
 
-               $defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ';
-               $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
+                       $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
+                       $export = 'export HOME=/' . $tmpDir;
 
-               $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
-               $export = 'export HOME=/' . $tmpDir;
+                       shell_exec($export . "\n" . $exec);
 
-               shell_exec($export . "\n" . $exec);
+                       //create imagick object from pdf
+                       try{
+                               $pdf = new \imagick($absPath . '.pdf' . '[0]');
+                               $pdf->setImageFormat('jpg');
+                       } catch (\Exception $e) {
+                               unlink($absPath);
+                               unlink($absPath . '.pdf');
+                               \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
+                               return false;
+                       }
+
+                       $image = new \OC_Image($pdf);
 
-               //create imagick object from pdf
-               try{
-                       $pdf = new \imagick($absPath . '.pdf' . '[0]');
-                       $pdf->setImageFormat('jpg');
-               } catch (\Exception $e) {
                        unlink($absPath);
                        unlink($absPath . '.pdf');
-                       \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
-                       return false;
+
+                       return $image->valid() ? $image : false;
                }
 
-               $image = new \OC_Image($pdf);
+               private function initCmd() {
+                       $cmd = '';
 
-               unlink($absPath);
-               unlink($absPath . '.pdf');
+                       if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) {
+                               $cmd = \OC_Config::getValue('preview_libreoffice_path', null);
+                       }
 
-               return $image->valid() ? $image : false;
-       }
+                       $whichLibreOffice = shell_exec('which libreoffice');
+                       if($cmd === '' && !empty($whichLibreOffice)) {
+                               $cmd = 'libreoffice';
+                       }
 
-       private function initCmd() {
-               $cmd = '';
+                       $whichOpenOffice = shell_exec('which openoffice');
+                       if($cmd === '' && !empty($whichOpenOffice)) {
+                               $cmd = 'openoffice';
+                       }
 
-               if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) {
-                       $cmd = \OC_Config::getValue('preview_libreoffice_path', null);
-               }
+                       if($cmd === '') {
+                               $cmd = null;
+                       }
 
-               $whichLibreOffice = shell_exec('which libreoffice');
-               if($cmd === '' && !empty($whichLibreOffice)) {
-                       $cmd = 'libreoffice';
+                       $this->cmd = $cmd;
                }
+       }
 
-               $whichOpenOffice = shell_exec('which openoffice');
-               if($cmd === '' && !empty($whichOpenOffice)) {
-                       $cmd = 'openoffice';
-               }
+       //.doc, .dot
+       class MSOfficeDoc extends Office {
 
-               if($cmd === '') {
-                       $cmd = null;
+               public function getMimeType() {
+                       return '/application\/msword/';
                }
 
-               $this->cmd = $cmd;
-       }
-}
-
-//.doc, .dot
-class MSOfficeDoc extends Office {
-
-       public function getMimeType() {
-               return '/application\/msword/';
        }
 
-}
+       \OC\Preview::registerProvider('OC\Preview\MSOfficeDoc');
 
-\OC\Preview::registerProvider('OC\Preview\MSOfficeDoc');
+       //.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m)
+       class MSOffice2003 extends Office {
 
-//.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m)
-class MSOffice2003 extends Office {
+               public function getMimeType() {
+                       return '/application\/vnd.ms-.*/';
+               }
 
-       public function getMimeType() {
-               return '/application\/vnd.ms-.*/';
        }
 
-}
+       \OC\Preview::registerProvider('OC\Preview\MSOffice2003');
 
-\OC\Preview::registerProvider('OC\Preview\MSOffice2003');
+       //.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
+       class MSOffice2007 extends Office {
 
-//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
-class MSOffice2007 extends Office {
+               public function getMimeType() {
+                       return '/application\/vnd.openxmlformats-officedocument.*/';
+               }
 
-       public function getMimeType() {
-               return '/application\/vnd.openxmlformats-officedocument.*/';
        }
 
-}
+       \OC\Preview::registerProvider('OC\Preview\MSOffice2007');
 
-\OC\Preview::registerProvider('OC\Preview\MSOffice2007');
+       //.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
+       class OpenDocument extends Office {
 
-//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
-class OpenDocument extends Office {
+               public function getMimeType() {
+                       return '/application\/vnd.oasis.opendocument.*/';
+               }
 
-       public function getMimeType() {
-               return '/application\/vnd.oasis.opendocument.*/';
        }
 
-}
+       \OC\Preview::registerProvider('OC\Preview\OpenDocument');
 
-\OC\Preview::registerProvider('OC\Preview\OpenDocument');
+       //.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
+       class StarOffice extends Office {
 
-//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
-class StarOffice extends Office {
+               public function getMimeType() {
+                       return '/application\/vnd.sun.xml.*/';
+               }
 
-       public function getMimeType() {
-               return '/application\/vnd.sun.xml.*/';
        }
 
+       \OC\Preview::registerProvider('OC\Preview\StarOffice');
 }
-
-\OC\Preview::registerProvider('OC\Preview\StarOffice');
\ No newline at end of file
index 5287bbd6ac1c61ec47f580e88cf05718595124b5..673b16edc192ff86b026d9fe3fbe09be818c3425 100644 (file)
@@ -8,15 +8,22 @@
 //both, libreoffice backend and php fallback, need imagick
 if (extension_loaded('imagick')) {
        $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions')));
-       $whichLibreOffice = shell_exec('which libreoffice');
-       $isLibreOfficeAvailable = !empty($whichLibreOffice);
-       $whichOpenOffice = shell_exec('which libreoffice');
-       $isOpenOfficeAvailable = !empty($whichOpenOffice);
-       //let's see if there is libreoffice or openoffice on this machine
-       if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) {
-               require_once('office-cl.php');
-       }else{
+
+       // movie preview is currently not supported on Windows
+       if (!\OC_Util::runningOnWindows()) {
+               $whichLibreOffice = shell_exec('which libreoffice');
+               $isLibreOfficeAvailable = !empty($whichLibreOffice);
+               $whichOpenOffice = shell_exec('which libreoffice');
+               $isOpenOfficeAvailable = !empty($whichOpenOffice);
+               //let's see if there is libreoffice or openoffice on this machine
+               if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) {
+                       require_once('office-cl.php');
+               }else{
+                       //in case there isn't, use our fallback
+                       require_once('office-fallback.php');
+               }
+       } else {
                //in case there isn't, use our fallback
                require_once('office-fallback.php');
        }
-}
\ No newline at end of file
+}