diff options
author | Georg Ehrke <developer@georgehrke.com> | 2013-07-30 12:29:12 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2013-07-30 12:33:54 +0200 |
commit | ac6a3133eca86b853da838ae310534b76e9fb662 (patch) | |
tree | d74eab54dcc560ca77b5561892363971d710ee19 /lib/preview | |
parent | 7425efade78a04f20cb3cc83f964c6a00094b6ce (diff) | |
download | nextcloud-server-ac6a3133eca86b853da838ae310534b76e9fb662.tar.gz nextcloud-server-ac6a3133eca86b853da838ae310534b76e9fb662.zip |
style fixes
Diffstat (limited to 'lib/preview')
-rw-r--r-- | lib/preview/images.php | 7 | ||||
-rw-r--r-- | lib/preview/libreoffice-cl.php | 24 | ||||
-rw-r--r-- | lib/preview/movies.php | 22 | ||||
-rw-r--r-- | lib/preview/mp3.php | 22 | ||||
-rw-r--r-- | lib/preview/msoffice.php | 24 | ||||
-rw-r--r-- | lib/preview/office.php | 7 | ||||
-rw-r--r-- | lib/preview/pdf.php | 8 | ||||
-rw-r--r-- | lib/preview/txt.php | 15 | ||||
-rw-r--r-- | lib/preview/unknown.php | 8 |
9 files changed, 77 insertions, 60 deletions
diff --git a/lib/preview/images.php b/lib/preview/images.php index 987aa9aef0a..9aec967282d 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -16,10 +16,13 @@ class Image extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { //get fileinfo - $fileinfo = $fileview->getFileInfo($path); + $fileInfo = $fileview->getFileInfo($path); + if(!$fileInfo) { + return false; + } //check if file is encrypted - if($fileinfo['encrypted'] === true) { + if($fileInfo['encrypted'] === true) { $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r'))); }else{ $image = new \OC_Image(); diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 2749c4867e9..0f4ec3d0348 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -22,28 +22,30 @@ class Office extends Provider { return false; } - $abspath = $fileview->toTmpFile($path); + $absPath = $fileview->toTmpFile($path); - $tmpdir = get_temp_dir(); + $tmpDir = get_temp_dir(); - $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpdir) . ' ' . escapeshellarg($abspath); - $export = 'export HOME=/' . $tmpdir; + $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath); + $export = 'export HOME=/' . $tmpDir; shell_exec($export . "\n" . $exec); //create imagick object from pdf try{ - $pdf = new \imagick($abspath . '.pdf' . '[0]'); + $pdf = new \imagick($absPath . '.pdf' . '[0]'); $pdf->setImageFormat('jpg'); - }catch(\Exception $e){ + }catch (\Exception $e) { + unlink($absPath); + unlink($absPath . '.pdf'); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } $image = new \OC_Image($pdf); - unlink($abspath); - unlink($abspath . '.pdf'); + unlink($absPath); + unlink($absPath . '.pdf'); return $image->valid() ? $image : false; } @@ -55,11 +57,13 @@ class Office extends Provider { $cmd = \OC_Config::getValue('preview_libreoffice_path', null); } - if($cmd === '' && shell_exec('libreoffice --headless --version')) { + $whichLibreOffice = shell_exec('which libreoffice'); + if($cmd === '' && !empty($whichLibreOffice)) { $cmd = 'libreoffice'; } - if($cmd === '' && shell_exec('openoffice --headless --version')) { + $whichOpenOffice = shell_exec('which openoffice'); + if($cmd === '' && !empty($whichOpenOffice)) { $cmd = 'openoffice'; } diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 8531050d112..e2a1b8edddc 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -8,7 +8,11 @@ */ namespace OC\Preview; -if(!is_null(shell_exec('ffmpeg -version'))) { +$isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); +$whichFFMPEG = shell_exec('which ffmpeg'); +$isFFMPEGAvailable = !empty($whichFFMPEG); + +if($isShellExecEnabled && $isFFMPEGAvailable) { class Movie extends Provider { @@ -17,23 +21,23 @@ if(!is_null(shell_exec('ffmpeg -version'))) { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $abspath = \OC_Helper::tmpFile(); - $tmppath = \OC_Helper::tmpFile(); + $absPath = \OC_Helper::tmpFile(); + $tmpPath = \OC_Helper::tmpFile(); $handle = $fileview->fopen($path, 'rb'); $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576 - file_put_contents($abspath, $firstmb); + 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 = 'ffmpeg -an -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); + //$cmd = 'ffmpeg -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath; + $cmd = 'ffmpeg -an -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmpPath); 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; } diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 835ff529000..1eed566315c 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -18,19 +18,21 @@ class MP3 extends Provider { $getID3 = new \getID3(); - $tmppath = $fileview->toTmpFile($path); - - $tags = $getID3->analyze($tmppath); - \getid3_lib::CopyTagsToComments($tags); - $picture = @$tags['id3v2']['APIC'][0]['data']; - - unlink($tmppath); + $tmpPath = $fileview->toTmpFile($path); + + $tags = $getID3->analyze($tmpPath); + \getid3_lib::CopyTagsToComments($tags); + if(isset($tags['id3v2']['APIC'][0]['data'])) { + $picture = @$tags['id3v2']['APIC'][0]['data']; + unlink($tmpPath); + $image = new \OC_Image($picture); + return $image->valid() ? $image : $this->getNoCoverThumbnail(); + } - $image = new \OC_Image($picture); - return $image->valid() ? $image : $this->getNoCoverThumbnail($maxX, $maxY); + return $this->getNoCoverThumbnail(); } - public function getNoCoverThumbnail($maxX, $maxY) { + private function getNoCoverThumbnail() { $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png'; if(!file_exists($icon)) { diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index ccf1d674c7a..e69ab0ab8cb 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -32,16 +32,16 @@ class DOCX extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { require_once('phpdocx/classes/TransformDoc.inc'); - $tmpdoc = $fileview->toTmpFile($path); + $tmpDoc = $fileview->toTmpFile($path); $transformdoc = new \TransformDoc(); - $transformdoc->setStrFile($tmpdoc); - $transformdoc->generatePDF($tmpdoc); + $transformdoc->setStrFile($tmpDoc); + $transformdoc->generatePDF($tmpDoc); - $pdf = new \imagick($tmpdoc . '[0]'); + $pdf = new \imagick($tmpDoc . '[0]'); $pdf->setImageFormat('jpg'); - unlink($tmpdoc); + unlink($tmpDoc); $image = new \OC_Image($pdf); @@ -62,23 +62,23 @@ class MSOfficeExcel extends Provider { require_once('PHPExcel/Classes/PHPExcel.php'); require_once('PHPExcel/Classes/PHPExcel/IOFactory.php'); - $abspath = $fileview->toTmpFile($path); - $tmppath = \OC_Helper::tmpFile(); + $absPath = $fileview->toTmpFile($path); + $tmpPath = \OC_Helper::tmpFile(); $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf'; \PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath); - $phpexcel = new \PHPExcel($abspath); + $phpexcel = new \PHPExcel($absPath); $excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF'); - $excel->save($tmppath); + $excel->save($tmpPath); - $pdf = new \imagick($tmppath . '[0]'); + $pdf = new \imagick($tmpPath . '[0]'); $pdf->setImageFormat('jpg'); - unlink($abspath); - unlink($tmppath); + unlink($absPath); + unlink($tmpPath); $image = new \OC_Image($pdf); diff --git a/lib/preview/office.php b/lib/preview/office.php index b6783bc5798..b93e1e57c8b 100644 --- a/lib/preview/office.php +++ b/lib/preview/office.php @@ -7,8 +7,13 @@ */ //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(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) { require_once('libreoffice-cl.php'); }else{ //in case there isn't, use our fallback diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 3eabd201156..723dc1d80d2 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -16,18 +16,18 @@ if (extension_loaded('imagick')) { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $tmppath = $fileview->toTmpFile($path); + $tmpPath = $fileview->toTmpFile($path); //create imagick object from pdf try{ - $pdf = new \imagick($tmppath . '[0]'); + $pdf = new \imagick($tmpPath . '[0]'); $pdf->setImageFormat('jpg'); - }catch(\Exception $e){ + }catch (\Exception $e) { \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } - unlink($tmppath); + unlink($tmpPath); //new image object $image = new \OC_Image($pdf); diff --git a/lib/preview/txt.php b/lib/preview/txt.php index c7b8fabc6b0..89927fd580a 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -18,24 +18,23 @@ class TXT extends Provider { $content = stream_get_contents($content); $lines = preg_split("/\r\n|\n|\r/", $content); - $numoflines = count($lines); - $fontsize = 5; //5px - $linesize = ceil($fontsize * 1.25); + $fontSize = 5; //5px + $lineSize = ceil($fontSize * 1.25); $image = imagecreate($maxX, $maxY); - $imagecolor = imagecolorallocate($image, 255, 255, 255); - $textcolor = imagecolorallocate($image, 0, 0, 0); + imagecolorallocate($image, 255, 255, 255); + $textColor = imagecolorallocate($image, 0, 0, 0); foreach($lines as $index => $line) { $index = $index + 1; $x = (int) 1; - $y = (int) ($index * $linesize) - $fontsize; + $y = (int) ($index * $lineSize) - $fontSize; - imagestring($image, 1, $x, $y, $line, $textcolor); + imagestring($image, 1, $x, $y, $line, $textColor); - if(($index * $linesize) >= $maxY) { + if(($index * $lineSize) >= $maxY) { break; } } diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index a31b365722e..ba13ca35d66 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -20,7 +20,7 @@ class Unknown extends Provider { list($type, $subtype) = explode('/', $mimetype); } - $iconsroot = \OC::$SERVERROOT . '/core/img/filetypes/'; + $iconsRoot = \OC::$SERVERROOT . '/core/img/filetypes/'; if(isset($type)){ $icons = array($mimetype, $type, 'text'); @@ -30,10 +30,10 @@ class Unknown extends Provider { foreach($icons as $icon) { $icon = str_replace('/', '-', $icon); - $iconpath = $iconsroot . $icon . '.png'; + $iconPath = $iconsRoot . $icon . '.png'; - if(file_exists($iconpath)) { - return new \OC_Image($iconpath); + if(file_exists($iconPath)) { + return new \OC_Image($iconPath); } } return false; |