示例#1
0
 public function setUp()
 {
     $avconvBinary = \OC_Helper::findBinaryPath('avconv');
     $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg');
     if ($avconvBinary || $ffmpegBinary) {
         parent::setUp();
         \OC\Preview\Movie::$avconvBinary = $avconvBinary;
         \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary;
         $fileName = 'testimage.mp4';
         $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName);
         $this->width = 560;
         $this->height = 320;
         $this->provider = new \OC\Preview\Movie();
     } else {
         $this->markTestSkipped('No Movie provider present');
     }
 }
 /**
  * Register the default providers (if enabled)
  */
 protected function registerCoreProviders()
 {
     if ($this->registeredCoreProviders) {
         return;
     }
     $this->registeredCoreProviders = true;
     $this->registerCoreProvider('OC\\Preview\\TXT', '/text\\/plain/');
     $this->registerCoreProvider('OC\\Preview\\MarkDown', '/text\\/(x-)?markdown/');
     $this->registerCoreProvider('OC\\Preview\\PNG', '/image\\/png/');
     $this->registerCoreProvider('OC\\Preview\\JPEG', '/image\\/jpeg/');
     $this->registerCoreProvider('OC\\Preview\\GIF', '/image\\/gif/');
     $this->registerCoreProvider('OC\\Preview\\BMP', '/image\\/bmp/');
     $this->registerCoreProvider('OC\\Preview\\XBitmap', '/image\\/x-xbitmap/');
     $this->registerCoreProvider('OC\\Preview\\MP3', '/audio\\/mpeg/');
     // SVG, Office and Bitmap require imagick
     if (extension_loaded('imagick')) {
         $checkImagick = new \Imagick();
         $imagickProviders = ['SVG' => ['mimetype' => '/image\\/svg\\+xml/', 'class' => '\\OC\\Preview\\SVG'], 'TIFF' => ['mimetype' => '/image\\/tiff/', 'class' => '\\OC\\Preview\\TIFF'], 'PDF' => ['mimetype' => '/application\\/pdf/', 'class' => '\\OC\\Preview\\PDF'], 'AI' => ['mimetype' => '/application\\/illustrator/', 'class' => '\\OC\\Preview\\Illustrator'], 'PSD' => ['mimetype' => '/application\\/x-photoshop/', 'class' => '\\OC\\Preview\\Photoshop'], 'EPS' => ['mimetype' => '/application\\/postscript/', 'class' => '\\OC\\Preview\\Postscript'], 'TTF' => ['mimetype' => '/application\\/(?:font-sfnt|x-font$)/', 'class' => '\\OC\\Preview\\Font']];
         foreach ($imagickProviders as $queryFormat => $provider) {
             $class = $provider['class'];
             if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
                 continue;
             }
             if (count($checkImagick->queryFormats($queryFormat)) === 1) {
                 $this->registerCoreProvider($class, $provider['mimetype']);
             }
         }
         if (count($checkImagick->queryFormats('PDF')) === 1) {
             // Office previews are currently not supported on Windows
             if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('shell_exec')) {
                 $officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null));
                 if (!$officeFound) {
                     //let's see if there is libreoffice or openoffice on this machine
                     $whichLibreOffice = shell_exec('command -v libreoffice');
                     $officeFound = !empty($whichLibreOffice);
                     if (!$officeFound) {
                         $whichOpenOffice = shell_exec('command -v openoffice');
                         $officeFound = !empty($whichOpenOffice);
                     }
                 }
                 if ($officeFound) {
                     $this->registerCoreProvider('\\OC\\Preview\\MSOfficeDoc', '/application\\/msword/');
                     $this->registerCoreProvider('\\OC\\Preview\\MSOffice2003', '/application\\/vnd.ms-.*/');
                     $this->registerCoreProvider('\\OC\\Preview\\MSOffice2007', '/application\\/vnd.openxmlformats-officedocument.*/');
                     $this->registerCoreProvider('\\OC\\Preview\\OpenDocument', '/application\\/vnd.oasis.opendocument.*/');
                     $this->registerCoreProvider('\\OC\\Preview\\StarOffice', '/application\\/vnd.sun.xml.*/');
                 }
             }
         }
     }
     // Video requires avconv or ffmpeg and is therefor
     // currently not supported on Windows.
     if (in_array('OC\\Preview\\Movie', $this->getEnabledDefaultProvider()) && !\OC_Util::runningOnWindows()) {
         $avconvBinary = \OC_Helper::findBinaryPath('avconv');
         $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg');
         if ($avconvBinary || $ffmpegBinary) {
             // FIXME // a bit hacky but didn't want to use subclasses
             \OC\Preview\Movie::$avconvBinary = $avconvBinary;
             \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary;
             $this->registerCoreProvider('\\OC\\Preview\\Movie', '/video\\/.*/');
         }
     }
 }
示例#3
0
 protected static function registerCoreProviders()
 {
     self::registerProvider('OC\\Preview\\TXT');
     self::registerProvider('OC\\Preview\\MarkDown');
     self::registerProvider('OC\\Preview\\Image');
     self::registerProvider('OC\\Preview\\MP3');
     // SVG, Office and Bitmap require imagick
     if (extension_loaded('imagick')) {
         $checkImagick = new \Imagick();
         $imagickProviders = array('SVG' => 'OC\\Preview\\SVG', 'TIFF' => 'OC\\Preview\\TIFF', 'PDF' => 'OC\\Preview\\PDF', 'AI' => 'OC\\Preview\\Illustrator', 'PSD' => 'OC\\Preview\\Photoshop', 'EPS' => 'OC\\Preview\\Postscript');
         foreach ($imagickProviders as $queryFormat => $provider) {
             if (count($checkImagick->queryFormats($queryFormat)) === 1) {
                 self::registerProvider($provider);
             }
         }
         if (count($checkImagick->queryFormats('PDF')) === 1) {
             // Office previews are currently not supported on Windows
             if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('shell_exec')) {
                 $officeFound = is_string(\OC::$server->getConfig()->getSystemValue('preview_libreoffice_path', null));
                 if (!$officeFound) {
                     //let's see if there is libreoffice or openoffice on this machine
                     $whichLibreOffice = shell_exec('command -v libreoffice');
                     $officeFound = !empty($whichLibreOffice);
                     if (!$officeFound) {
                         $whichOpenOffice = shell_exec('command -v openoffice');
                         $officeFound = !empty($whichOpenOffice);
                     }
                 }
                 if ($officeFound) {
                     self::registerProvider('OC\\Preview\\MSOfficeDoc');
                     self::registerProvider('OC\\Preview\\MSOffice2003');
                     self::registerProvider('OC\\Preview\\MSOffice2007');
                     self::registerProvider('OC\\Preview\\OpenDocument');
                     self::registerProvider('OC\\Preview\\StarOffice');
                 }
             }
         }
     }
     // Video requires avconv or ffmpeg and is therefor
     // currently not supported on Windows.
     if (!\OC_Util::runningOnWindows()) {
         $avconvBinary = \OC_Helper::findBinaryPath('avconv');
         $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg');
         if ($avconvBinary || $ffmpegBinary) {
             // FIXME // a bit hacky but didn't want to use subclasses
             \OC\Preview\Movie::$avconvBinary = $avconvBinary;
             \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary;
             self::registerProvider('OC\\Preview\\Movie');
         }
     }
 }