getInstance() public static method

Singleton for Pimcore\Document
public static getInstance ( null $adapter = null ) : boolean | null | Document
$adapter null
return boolean | null | Document
コード例 #1
0
ファイル: Document.php プロジェクト: pimcore/pimcore
 public function getText($page = null)
 {
     if (\Pimcore\Document::isAvailable() && \Pimcore\Document::isFileTypeSupported($this->getFilename())) {
         $cacheKey = "asset_document_text_" . $this->getId() . "_" . ($page ? $page : "all");
         if (!($text = Cache::load($cacheKey))) {
             $document = \Pimcore\Document::getInstance();
             $text = $document->getText($page, $this->getFileSystemPath());
             Cache::save($text, $cacheKey, $this->getCacheTags(), null, 99, true);
             // force cache write
         }
         return $text;
     } else {
         Logger::error("Couldn't get text out of document " . $this->getRealFullPath() . " no document adapter is available");
     }
     return null;
 }
コード例 #2
0
<?php

$pdfPath = null;
// add the PDF check here, otherwise the preview layer in admin is shown without content
if (\Pimcore\Document::isAvailable() && \Pimcore\Document::isFileTypeSupported($this->asset->getFilename())) {
    $document = \Pimcore\Document::getInstance();
    try {
        $pdfFsPath = $document->getPdf($this->asset->getFileSystemPath());
        $pdfPath = str_replace(PIMCORE_DOCUMENT_ROOT, "", $pdfFsPath);
        $results = \Pimcore::getEventManager()->trigger("frontend.path.asset.document.image-thumbnail", $this, ["filesystemPath" => $pdfFsPath, "frontendPath" => $pdfPath]);
        if ($results->count()) {
            $pdfPath = $results->last();
        }
    } catch (\Exception $e) {
        // nothing to do
    }
}
if (strpos($this->asset->getFilename(), ".pdf") !== false) {
    $pdfPath = $this->asset->getFullpath();
}
if ($pdfPath && $this->getParam("native-viewer")) {
    header("Location: " . $pdfPath, true, 301);
    exit;
} else {
    // we use the Google Apps Document Viewer instead
    ?>
<!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <style type="text/css">
コード例 #3
0
ファイル: ImageThumbnail.php プロジェクト: pimcore/pimcore
 /**
  *
  */
 public function generate()
 {
     $errorImage = PIMCORE_PATH . '/static6/img/filetype-not-supported.png';
     $generated = false;
     if (!$this->asset) {
         $this->filesystemPath = $errorImage;
     } elseif (!$this->filesystemPath) {
         $config = $this->getConfig();
         $config->setName("document_" . $config->getName() . "-" . $this->page);
         try {
             $path = null;
             if (!$this->deferred) {
                 $converter = \Pimcore\Document::getInstance();
                 $converter->load($this->asset->getFileSystemPath());
                 $path = PIMCORE_TEMPORARY_DIRECTORY . "/document-image-cache/document_" . $this->asset->getId() . "__thumbnail_" . $this->page . ".png";
                 if (!is_dir(dirname($path))) {
                     \Pimcore\File::mkdir(dirname($path));
                 }
                 $lockKey = "document-thumbnail-" . $this->asset->getId() . "-" . $this->page;
                 if (!is_file($path) && !Model\Tool\Lock::isLocked($lockKey)) {
                     Model\Tool\Lock::lock($lockKey);
                     $converter->saveImage($path, $this->page);
                     $generated = true;
                     Model\Tool\Lock::release($lockKey);
                 } elseif (Model\Tool\Lock::isLocked($lockKey)) {
                     return "/pimcore/static6/img/please-wait.png";
                 }
             }
             if ($config) {
                 $path = Image\Thumbnail\Processor::process($this->asset, $config, $path, $this->deferred, true, $generated);
             }
             $this->filesystemPath = $path;
         } catch (\Exception $e) {
             Logger::error("Couldn't create image-thumbnail of document " . $this->asset->getRealFullPath());
             Logger::error($e);
             $this->filesystemPath = $errorImage;
         }
         \Pimcore::getEventManager()->trigger("asset.document.image-thumbnail", $this, ["deferred" => $this->deferred, "generated" => $generated]);
     }
 }