isFileTypeSupported() public static method

Checks if a file type is supported by the adapter.
public static isFileTypeSupported ( $filetype ) : boolean
$filetype
return boolean
コード例 #1
0
ファイル: Data.php プロジェクト: sfie/pimcore
 /**
  * @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;
 }
コード例 #2
0
 /**
  * @param $element
  * @return array
  */
 protected function getTreeNodeConfig($element)
 {
     $asset = $element;
     $tmpAsset = array("id" => $asset->getId(), "text" => $asset->getFilename(), "type" => $asset->getType(), "path" => $asset->getFullPath(), "basePath" => $asset->getPath(), "locked" => $asset->isLocked(), "lockOwner" => $asset->getLocked() ? true : false, "elementType" => "asset", "permissions" => array("remove" => $asset->isAllowed("delete"), "settings" => $asset->isAllowed("settings"), "rename" => $asset->isAllowed("rename"), "publish" => $asset->isAllowed("publish"), "view" => $asset->isAllowed("view")));
     // set type specific settings
     if ($asset->getType() == "folder") {
         $tmpAsset["leaf"] = false;
         $tmpAsset["expanded"] = $asset->hasNoChilds();
         $tmpAsset["iconCls"] = "pimcore_icon_folder";
         $tmpAsset["permissions"]["create"] = $asset->isAllowed("create");
         $folderThumbs = array();
         $children = new Asset\Listing();
         $children->setCondition("path LIKE ?", [$asset->getFullPath() . "/%"]);
         $children->setLimit(35);
         foreach ($children as $child) {
             if ($child->isAllowed("list")) {
                 if ($thumbnailUrl = $this->getThumbnailUrl($child)) {
                     $folderThumbs[] = $thumbnailUrl;
                 }
             }
         }
         if (!empty($folderThumbs)) {
             $tmpAsset["thumbnails"] = $folderThumbs;
         }
     } else {
         $tmpAsset["leaf"] = true;
         $tmpAsset["iconCls"] = "pimcore_icon_" . File::getFileExtension($asset->getFilename());
     }
     $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId());
     if ($asset->getType() == "image") {
         try {
             $tmpAsset["thumbnail"] = $this->getThumbnailUrl($asset);
             // this is for backward-compatibility, to calculate the dimensions if they are not there
             if (!$asset->getCustomSetting("imageDimensionsCalculated")) {
                 $asset->save();
             }
             // we need the dimensions for the wysiwyg editors, so that they can resize the image immediately
             if ($asset->getCustomSetting("imageWidth") && $asset->getCustomSetting("imageHeight")) {
                 $tmpAsset["imageWidth"] = $asset->getCustomSetting("imageWidth");
                 $tmpAsset["imageHeight"] = $asset->getCustomSetting("imageHeight");
             }
         } catch (\Exception $e) {
             \Logger::debug("Cannot get dimensions of image, seems to be broken.");
         }
     } else {
         if ($asset->getType() == "video") {
             try {
                 if (\Pimcore\Video::isAvailable()) {
                     $tmpAsset["thumbnail"] = $this->getThumbnailUrl($asset);
                 }
             } catch (\Exception $e) {
                 \Logger::debug("Cannot get dimensions of video, seems to be broken.");
             }
         } else {
             if ($asset->getType() == "document") {
                 try {
                     // add the PDF check here, otherwise the preview layer in admin is shown without content
                     if (\Pimcore\Document::isAvailable() && \Pimcore\Document::isFileTypeSupported($asset->getFilename())) {
                         $tmpAsset["thumbnail"] = $this->getThumbnailUrl($asset);
                     }
                 } catch (\Exception $e) {
                     \Logger::debug("Cannot get dimensions of video, seems to be broken.");
                 }
             }
         }
     }
     $tmpAsset["cls"] = "";
     if ($asset->isLocked()) {
         $tmpAsset["cls"] .= "pimcore_treenode_locked ";
     }
     if ($asset->getLocked()) {
         $tmpAsset["cls"] .= "pimcore_treenode_lockOwner ";
     }
     return $tmpAsset;
 }
コード例 #3
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;
 }
コード例 #4
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">
コード例 #5
0
 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;
 }