/** * Repacks exported document from Google.Drive, which has wrong order files in archive to show preview * in Google.Viewer. In Google.Viewer document should have file '[Content_Types].xml' on first position in archive. * @param FileData $fileData * @return FileData * @throws IO\FileNotFoundException * @throws IO\InvalidPathException * @internal */ public function repackDocument(FileData $fileData) { if (!extension_loaded('zip')) { return null; } if (!TypeFile::isDocument($fileData->getName())) { return null; } $file = new IO\File($fileData->getSrc()); if (!$file->isExists() || $file->getSize() > 15 * 1024 * 1024) { return null; } unset($file); $ds = DIRECTORY_SEPARATOR; $targetDir = \CTempFile::getDirectoryName(2, 'disk_repack' . $ds . md5(uniqid('di', true))); checkDirPath($targetDir); $targetDir = IO\Path::normalize($targetDir) . $ds; $zipOrigin = new \ZipArchive(); if (!$zipOrigin->open($fileData->getSrc())) { return null; } if ($zipOrigin->getNameIndex(0) === '[Content_Types].xml') { $zipOrigin->close(); return null; } if (!$zipOrigin->extractTo($targetDir)) { $zipOrigin->close(); return null; } $zipOrigin->close(); unset($zipOrigin); if (is_dir($targetDir) !== true) { return null; } $newName = md5(uniqid('di', true)); $newFilepath = $targetDir . '..' . $ds . $newName; $repackedZip = new \ZipArchive(); if (!$repackedZip->open($newFilepath, \ZipArchive::CREATE)) { return null; } $source = realpath($targetDir); $repackedZip->addFile($source . $ds . '[Content_Types].xml', '[Content_Types].xml'); $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file) { if ($file->getBasename() === '[Content_Types].xml') { continue; } $file = str_replace('\\', '/', $file); $file = realpath($file); if (is_dir($file) === true) { $repackedZip->addEmptyDir(str_replace('\\', '/', str_replace($source . $ds, '', $file . $ds))); } elseif (is_file($file) === true) { $repackedZip->addFile($file, str_replace('\\', '/', str_replace($source . $ds, '', $file))); } } $repackedZip->close(); $newFileData = new FileData(); $newFileData->setSrc($newFilepath); return $newFileData; }
" type="text"> </div> </div> </td> </tr> </table> <a class="bx-disk-btn bx-disk-btn-big bx-disk-btn-green" href="<?php echo $arResult['FILE']['DOWNLOAD_URL']; ?> "><?php echo Loc::getMessage('DISK_FILE_VIEW_FILE_DOWNLOAD'); ?> </a> <?php if (!empty($arResult['CAN_UPDATE']) && \Bitrix\Disk\TypeFile::isDocument($arResult['FILE']['NAME'])) { ?> <a id="bx-disk-file-edit-btn" class="bx-disk-btn bx-disk-btn-big bx-disk-btn-lightgray" href=""><?php echo Loc::getMessage('DISK_FILE_VIEW_FILE_EDIT'); ?> </a><?php } ?> <?php if (!empty($arResult['CAN_UPDATE'])) { ?> <a id="bx-disk-file-upload-btn" class="bx-disk-btn bx-disk-btn-big bx-disk-btn-lightgray" href="javascript:void(0);"><?php echo Loc::getMessage('DISK_FILE_VIEW_FILE_UPLOAD_VERSION'); ?> </a><?php }
private function getFileContent(File $file) { static $maxFileSize = null; if (!isset($maxFileSize)) { $maxFileSize = Option::get("search", "max_file_size", 0) * 1024; } $searchData = ''; $searchData .= strip_tags($file->getName()) . "\r\n"; $searchData .= strip_tags($file->getCreateUser()->getFormattedName()) . "\r\n"; if ($maxFileSize > 0 && $file->getSize() > $maxFileSize) { return $searchData; } $searchDataFile = array(); $fileArray = null; //improve work with s3 if (!ModuleManager::isModuleInstalled('bitrix24') || TypeFile::isDocument($file)) { $fileArray = CFile::makeFileArray($file->getFileId()); } if ($fileArray && $fileArray['tmp_name']) { $fileAbsPath = \CBXVirtualIo::getInstance()->getLogicalName($fileArray['tmp_name']); foreach (GetModuleEvents('search', 'OnSearchGetFileContent', true) as $event) { if ($searchDataFile = executeModuleEventEx($event, array($fileAbsPath, getFileExtension($fileArray['name'])))) { break; } } return is_array($searchDataFile) ? $searchData . "\r\n" . $searchDataFile['CONTENT'] : $searchData; } return $searchData; }