/** * @param $element * @return $this */ public function setDataFromElement($element) { $this->data = null; $this->id = new Data\Id($element); $this->fullPath = $element->getFullPath(); $this->creationDate = $element->getCreationDate(); $this->modificationDate = $element->getModificationDate(); $this->userModification = $element->getUserModification(); $this->userOwner = $element->getUserOwner(); $this->type = $element->getType(); if ($element instanceof Object\Concrete) { $this->subtype = $element->getClassName(); } else { $this->subtype = $this->type; } $this->properties = ""; $properties = $element->getProperties(); if (is_array($properties)) { foreach ($properties as $nextProperty) { $pData = (string) $nextProperty->getData(); if ($nextProperty->getName() == "bool") { $pData = $pData ? "true" : "false"; } $this->properties .= $nextProperty->getName() . ":" . $pData . " "; } } $this->data = ""; if ($element instanceof Document) { if ($element instanceof Document\Folder) { $this->data = $element->getKey(); $this->published = true; } else { if ($element instanceof Document\Link) { $this->published = $element->isPublished(); $this->data = $element->getTitle() . " " . $element->getHref(); } else { if ($element instanceof Document\PageSnippet) { $this->published = $element->isPublished(); $elements = $element->getElements(); if (is_array($elements) && !empty($elements)) { foreach ($elements as $tag) { if ($tag instanceof Document\Tag\TagInterface) { ob_start(); $this->data .= strip_tags($tag->frontend()) . " "; $this->data .= ob_get_clean(); } } } if ($element instanceof Document\Page) { $this->published = $element->isPublished(); $this->data .= " " . $element->getTitle() . " " . $element->getDescription() . " " . $element->getKeywords() . " " . $element->getPrettyUrl(); } } } } } else { if ($element instanceof Asset) { $this->data = $element->getFilename(); foreach ($element->getMetadata() as $md) { $this->data .= " " . $md["name"] . ":" . $md["data"]; } if ($element instanceof Asset\Document && \Pimcore\Document::isAvailable()) { if (\Pimcore\Document::isFileTypeSupported($element->getFilename())) { $contentText = $element->getText(); $contentText = str_replace(["\r\n", "\r", "\n", "\t", "\f"], " ", $contentText); $contentText = preg_replace("/[ ]+/", " ", $contentText); $this->data .= " " . $contentText; } } $this->published = true; } else { if ($element instanceof Object\AbstractObject) { if ($element instanceof Object\Concrete) { $getInheritedValues = Object\AbstractObject::doGetInheritedValues(); Object\AbstractObject::setGetInheritedValues(true); $this->published = $element->isPublished(); foreach ($element->getClass()->getFieldDefinitions() as $key => $value) { $this->data .= $value->getDataForSearchIndex($element) . " "; } Object\AbstractObject::setGetInheritedValues($getInheritedValues); } else { if ($element instanceof Object\Folder) { $this->data = $element->getKey(); $this->published = true; } } } else { \Logger::crit("Search\\Backend\\Data received an unknown element!"); } } } if ($element instanceof Element\ElementInterface) { $this->data = "ID: " . $element->getId() . " \nPath: " . $this->getFullPath() . " \n" . $this->cleanupData($this->data); } return $this; }
public function getFolderContentPreviewAction() { $folder = Asset::getById($this->getParam("id")); $start = 0; $limit = 10; if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } $condition = "path LIKE '" . ($folder->getFullPath() == "/" ? "/%'" : $folder->getFullPath() . "/%'") . " AND type != 'folder'"; $list = Asset::getList(array("condition" => $condition, "limit" => $limit, "offset" => $start, "orderKey" => "filename", "order" => "asc")); $assets = array(); foreach ($list as $asset) { $thumbnailMethod = ""; if ($asset instanceof Asset\Image) { $thumbnailMethod = "getThumbnail"; } else { if ($asset instanceof Asset\Video && \Pimcore\Video::isAvailable()) { $thumbnailMethod = "getImageThumbnail"; } else { if ($asset instanceof Asset\Document && \Pimcore\Document::isAvailable()) { $thumbnailMethod = "getImageThumbnail"; } } } if (!empty($thumbnailMethod)) { $assets[] = array("id" => $asset->getId(), "type" => $asset->getType(), "filename" => $asset->getFilename(), "url" => "/admin/asset/get-" . $asset->getType() . "-thumbnail/id/" . $asset->getId() . "/treepreview/true", "idPath" => $data["idPath"] = Element\Service::getIdPath($asset)); } } $this->_helper->json(array("assets" => $assets, "success" => true, "total" => $list->getTotalCount())); }
<?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">
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; }
/** * */ 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]); } }
public function wordExportDownloadAction() { $id = $this->getParam("id"); $exportFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $id . ".html"; // add closing body/html //$f = fopen($exportFile, "a+"); //fwrite($f, "</body></html>"); //fclose($f); // should be done via Pimcore_Document(_Adapter_LibreOffice) in the future if (\Pimcore\Document::isFileTypeSupported("docx")) { $lockKey = "soffice"; Model\Tool\Lock::acquire($lockKey); // avoid parallel conversions of the same document $out = Tool\Console::exec(\Pimcore\Document\Adapter\LibreOffice::getLibreOfficeCli() . ' --headless --convert-to docx:"Office Open XML Text" --outdir ' . PIMCORE_TEMPORARY_DIRECTORY . " " . $exportFile); \Logger::debug("LibreOffice Output was: " . $out); $tmpName = PIMCORE_TEMPORARY_DIRECTORY . "/" . preg_replace("/\\." . File::getFileExtension($exportFile) . "\$/", ".docx", basename($exportFile)); Model\Tool\Lock::release($lockKey); // end what should be done in Pimcore_Document header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"); header('Content-Disposition: attachment; filename="' . basename($tmpName) . '"'); } else { // no conversion, output html file $tmpName = $exportFile; header("Content-Type: text/html"); header('Content-Disposition: attachment; filename="' . basename($tmpName) . '"'); } while (@ob_end_flush()) { } flush(); readfile($tmpName); @unlink($exportFile); @unlink($tmpName); exit; }