Esempio n. 1
0
 /**
  * Gets a thumbnail of the specified file
  *
  * @since API version 1.0
  *
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @param int $x
  * @param int $y
  * @param string $file
  * @return JSONResponse|DownloadResponse
  */
 public function getThumbnail($x, $y, $file)
 {
     if ($x < 1 || $y < 1) {
         return new JSONResponse('Requested size must be numeric and a positive value.', Http::STATUS_BAD_REQUEST);
     }
     try {
         $preview = new Preview('', 'files', $file, $x, $y, true);
         echo $preview->showPreview('image/png');
         return new DownloadResponse($file . '.png', 'image/png');
     } catch (\Exception $e) {
         return new JSONResponse('File not found.', Http::STATUS_NOT_FOUND);
     }
 }
Esempio n. 2
0
 /**
  * Asks core for a preview based on our criteria
  *
  * @todo Need to read scaling setting from settings
  *
  * @param bool $keepAspect
  *
  * @return \OC_Image
  */
 private function getPreviewFromCore($keepAspect)
 {
     list($maxX, $maxY) = $this->dims;
     $this->preview->setMaxX($maxX);
     $this->preview->setMaxY($maxY);
     $this->preview->setScalingUp(false);
     $this->preview->setKeepAspect($keepAspect);
     //$this->logger->debug("[PreviewService] preview {preview}", ['preview' => $this->preview]);
     $previewData = $this->preview->getPreview();
     return $previewData;
 }
Esempio n. 3
0
 /**
  * Asks core for a preview based on our criteria
  *
  * @todo Need to read scaling setting from settings
  *
  * @param bool $keepAspect
  *
  * @return \OC_Image
  */
 private function getPreviewFromCore($keepAspect)
 {
     //$this->logger->debug("[PreviewService] Fetching the preview");
     list($maxX, $maxY) = $this->dims;
     $this->preview->setMaxX($maxX);
     $this->preview->setMaxY($maxY);
     $this->preview->setScalingUp(false);
     $this->preview->setKeepAspect($keepAspect);
     //$this->logger->debug("[PreviewService] preview {preview}", ['preview' => $this->preview]);
     try {
         // Can generate encryption Exceptions...
         $previewData = $this->preview->getPreview();
     } catch (\Exception $exception) {
         return null;
     }
     return $previewData;
 }
Esempio n. 4
0
					<video tabindex="0" controls="" preload="none">
						<source src="<?php 
        p($_['downloadURL']);
        ?>
" type="<?php 
        p($_['mimetype']);
        ?>
" />
					</video>
				</div>
			<?php 
    } else {
        ?>
				<div id="imgframe">
					<?php 
        $size = \OC\Preview::isMimeSupported($_['mimetype']) ? 500 : 128;
        ?>
					<img
						src="<?php 
        p(OCP\Util::linkToRoute('core_ajax_public_preview', array('x' => $size, 'y' => $size, 'file' => $_['directory_path'], 't' => $_['dirToken'])));
        ?>
"
						class="publicpreview"
						alt="" />
				</div>
			<?php 
    }
    ?>
			<div class="directDownload">
				<a href="<?php 
    p($_['downloadURL']);
Esempio n. 5
0
                return '/image\\/svg\\+xml/';
            }
            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;
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\SVG');
    }
}
Esempio n. 6
0
        }
        $lines = preg_split("/\r\n|\n|\r/", $content);
        $fontSize = 5;
        //5px
        $lineSize = ceil($fontSize * 1.25);
        $image = imagecreate($maxX, $maxY);
        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;
            imagestring($image, 1, $x, $y, $line, $textColor);
            if ($index * $lineSize >= $maxY) {
                break;
            }
        }
        $image = new \OC_Image($image);
        return $image->valid() ? $image : false;
    }
}
\OC\Preview::registerProvider('OC\\Preview\\TXT');
class MarkDown extends TXT
{
    public function getMimeType()
    {
        return '/text\\/(x-)?markdown/';
    }
}
\OC\Preview::registerProvider('OC\\Preview\\MarkDown');
Esempio n. 7
0
            {
                // TODO: use proc_open() and stream the source file ?
                $absPath = \OC_Helper::tmpFile();
                $tmpPath = \OC_Helper::tmpFile();
                $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);
                if (self::$avconvBinary) {
                    $cmd = self::$avconvBinary . ' -an -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
                } else {
                    $cmd = self::$ffmpegBinary . ' -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
                }
                exec($cmd, $output, $returnCode);
                unlink($absPath);
                if ($returnCode === 0) {
                    $image = new \OC_Image();
                    $image->loadFromFile($tmpPath);
                    unlink($tmpPath);
                    return $image->valid() ? $image : false;
                }
                return false;
            }
        }
        // a bit hacky but didn't want to use subclasses
        Movie::$avconvBinary = $avconvBinary;
        Movie::$ffmpegBinary = $ffmpegBinary;
        \OC\Preview::registerProvider('OC\\Preview\\Movie');
    }
}
Esempio n. 8
0
            public function getMimeType()
            {
                return '/application\\/illustrator/';
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\Illustrator');
    }
    // Requires adding 'eps' => array('application/postscript', null), to lib/private/mimetypes.list.php
    if (count($checkImagick->queryFormats('EPS')) === 1) {
        //.eps
        class Postscript extends Bitmap
        {
            public function getMimeType()
            {
                return '/application\\/postscript/';
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\Postscript');
    }
    if (count($checkImagick->queryFormats('PSD')) === 1) {
        //.psd
        class Photoshop extends Bitmap
        {
            public function getMimeType()
            {
                return '/application\\/x-photoshop/';
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\Photoshop');
    }
}
Esempio n. 9
0
class Image extends Provider
{
    public function getMimeType()
    {
        return '/image\\/(?!tiff$)(?!svg.*).*/';
    }
    public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
    {
        //get fileinfo
        $fileInfo = $fileview->getFileInfo($path);
        if (!$fileInfo) {
            return false;
        }
        $maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
        $size = $fileInfo->getSize();
        if ($maxSizeForImages !== -1 && $size > $maxSizeForImages * 1024 * 1024) {
            return false;
        }
        $image = new \OC_Image();
        if ($fileInfo['encrypted'] === true) {
            $fileName = $fileview->toTmpFile($path);
        } else {
            $fileName = $fileview->getLocalFile($path);
        }
        $image->loadFromFile($fileName);
        return $image->valid() ? $image : false;
    }
}
\OC\Preview::registerProvider('OC\\Preview\\Image');
 /**
  * @brief returns true if the passed mime type is supported
  * @param string $mimeType
  * @return boolean
  */
 function isMimeSupported($mimeType = '*')
 {
     return \OC\Preview::isMimeSupported($mimeType);
 }
Esempio n. 11
0
<?php

$l = OC_L10N::get('files_opds');
require 'files_opds/lib/epub-preview.php';
\OCP\App::registerPersonal('files_opds', 'personal');
\OCP\App::registerAdmin('files_opds', 'admin');
/* register preview provider */
\OC\Preview::registerProvider('OC\\Preview\\Epub');
Esempio n. 12
0
 /**
  * @param $filePath User/files/....
  * @return string
  */
 public static function prevImg($filePath)
 {
     //        $filePath = 'files/Photos/Paris.jpg';
     //$preview = \OC::$server->getPreviewManager()->createPreview($filePath, 128, 128, true);
     $conf = explode('/files/', $filePath);
     $preview = new Preview($conf[0], '/', 'files/' . $conf[1], 128, 128, true);
     $resp = new DataDisplayResponse($preview->getPreview()->data(), Http::STATUS_OK, ['Content-Type' => 'image/png']);
     $src = 'data: ' . $preview->getPreview()->mimeType() . ';base64,' . base64_encode($resp->render());
     return $src;
 }
Esempio n. 13
0
    {
        return '/.*/';
    }
    public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
    {
        $mimetype = $fileview->getMimeType($path);
        $path = \OC_Helper::mimetypeIcon($mimetype);
        $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
        $svgPath = substr_replace($path, 'svg', -3);
        if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) {
            // http://www.php.net/manual/de/imagick.setresolution.php#85284
            $svg = new \Imagick();
            $svg->readImage($svgPath);
            $res = $svg->getImageResolution();
            $x_ratio = $res['x'] / $svg->getImageWidth();
            $y_ratio = $res['y'] / $svg->getImageHeight();
            $svg->removeImage();
            $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio);
            $svg->setBackgroundColor(new \ImagickPixel('transparent'));
            $svg->readImage($svgPath);
            $svg->setImageFormat('png32');
            $image = new \OC_Image();
            $image->loadFromData($svg);
        } else {
            $image = new \OC_Image($path);
        }
        return $image;
    }
}
\OC\Preview::registerProvider('OC\\Preview\\Unknown');
Esempio n. 14
0
 /**
  * Check if a preview can be generated for a file
  *
  * @param \OC\Files\FileInfo $file
  * @return bool
  */
 function isAvailable($file)
 {
     return \OC\Preview::isAvailable($file);
 }
Esempio n. 15
0
use Imagick;
if (extension_loaded('imagick')) {
    $checkImagick = new Imagick();
    if (count($checkImagick->queryFormats('TIFF')) === 1) {
        class TIFF extends Provider
        {
            public function getMimeType()
            {
                return '/image\\/tiff/';
            }
            public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
            {
                $tmpPath = $fileview->toTmpFile($path);
                //create imagick object from TIFF
                try {
                    $tiff = new Imagick($tmpPath);
                    $tiff->setImageFormat('png');
                } catch (\Exception $e) {
                    \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
                    return false;
                }
                unlink($tmpPath);
                //new image object
                $image = new \OC_Image($tiff);
                //check if image object is valid
                return $image->valid() ? $image : false;
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\TIFF');
    }
}
Esempio n. 16
0
        }
    }
    \OC\Preview::registerProvider('OC\\Preview\\MSOffice2003');
    //.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
    class MSOffice2007 extends Office
    {
        public function getMimeType()
        {
            return '/application\\/vnd.openxmlformats-officedocument.*/';
        }
    }
    \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
    {
        public function getMimeType()
        {
            return '/application\\/vnd.oasis.opendocument.*/';
        }
    }
    \OC\Preview::registerProvider('OC\\Preview\\OpenDocument');
    //.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
    class StarOffice extends Office
    {
        public function getMimeType()
        {
            return '/application\\/vnd.sun.xml.*/';
        }
    }
    \OC\Preview::registerProvider('OC\\Preview\\StarOffice');
}
Esempio n. 17
0
OCP\Util::addScript('files', 'jquery.iframe-transport');
OCP\Util::addScript('files', 'jquery.fileupload');
// JS required for folders
OCP\Util::addStyle('files', 'files');
OCP\Util::addStyle('files', 'upload');
OCP\Util::addScript('files', 'filesummary');
OCP\Util::addScript('files', 'breadcrumb');
OCP\Util::addScript('files', 'files');
OCP\Util::addScript('files', 'filelist');
OCP\Util::addscript('files', 'keyboardshortcuts');
$thumbSize = 1024;
$previewSupported = OC\Preview::isMimeSupported($_['mimetype']) ? 'true' : 'false';
?>

<?php 
if (\OC\Preview::isMimeSupported($_['mimetype'])) {
    /* This enables preview images for links (e.g. on Facebook, Google+, ...)*/
    ?>
	<link rel="image_src" href="<?php 
    p(OCP\Util::linkToRoute('core_ajax_public_preview', array('x' => $thumbSize, 'y' => $thumbSize, 'file' => $_['directory_path'], 't' => $_['dirToken'])));
    ?>
" />
<?php 
}
?>

<div id="notification-container">
	<div id="notification" style="display: none;"></div>
</div>

<input type="hidden" id="filesApp" name="filesApp" value="1">
        foreach ($iter as $item) {
            if (is_file($item)) {
                $fileInfo = new SplFileInfo($item);
                // Is this an image ?
                $imgExt = strtolower($fileInfo->getExtension());
                if (in_array($imgExt, $fetchExt)) {
                    // get file name without $userDir
                    $shortFileName = substr($item, strlen($userDir));
                    // workaround for jpg == jpeg for showPreview method
                    if ($imgExt === 'jpg') {
                        $imgExt = 'jpeg';
                    }
                    // to check if preview exists on disk
                    $fileView = new \OC\Files\View('/' . $user . '/' . $currentDir);
                    $id = $fileView->getFileInfo($shortFileName)->getId();
                    // For each size
                    for ($x = 0; $x < $max_sf; $x++) {
                        // Generates missing thumbnails
                        if (!file_exists($datadir . '/' . $user . '/thumbnails/' . $id . '/' . $sizes[$x][0] . '-' . $sizes[$x][1] . '.png')) {
                            $preview = new Preview($user, $currentDir, $shortFileName, $sizes[$x][0], $sizes[$x][1], true);
                            $preview->showPreview('image/' . $imgExt);
                        }
                    }
                }
            }
        }
    }
}
?>

Esempio n. 19
0
 public static function post_delete($args, $prefix = '')
 {
     $path = Files\Filesystem::normalizePath($args['path']);
     $preview = new Preview(\OC_User::getUser(), $prefix, $path);
     $preview->deleteAllPreviews();
 }
class XLS extends MSOfficeExcel
{
    public function getMimeType()
    {
        return '/application\\/vnd.ms-excel/';
    }
}
\OC\Preview::registerProvider('OC\\Preview\\XLS');
class XLSX extends MSOfficeExcel
{
    public function getMimeType()
    {
        return '/application\\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/';
    }
}
\OC\Preview::registerProvider('OC\\Preview\\XLSX');
/* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ...
class MSOfficePowerPoint extends Provider {

	public function getMimeType() {
		return null;
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		return false;
	}

}

class PPT extends MSOfficePowerPoint {