/** * @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; }
<?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 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())); }
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; }