/** * ћетод публикует документ. “о есть делает его доступным в публичной части сайта. * * @param string $documentId - код документа. */ public function PublishDocument($documentId) { global $DB; $ID = intval($documentId); $db_element = CIBlockElement::getList(array(), array("ID" => $ID, "SHOW_HISTORY" => "Y"), false, false, array("ID", "TIMESTAMP_X", "MODIFIED_BY", "DATE_CREATE", "CREATED_BY", "IBLOCK_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "SORT", "NAME", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_TEXT", "DETAIL_TEXT_TYPE", "WF_STATUS_ID", "WF_PARENT_ELEMENT_ID", "WF_NEW", "WF_COMMENTS", "IN_SECTIONS", "CODE", "TAGS", "XML_ID", "TMP_ID")); if ($element = $db_element->fetch()) { $parentId = intval($element["WF_PARENT_ELEMENT_ID"]); if ($parentId) { $elementObject = new CIBlockElement(); $element["WF_PARENT_ELEMENT_ID"] = false; if ($element["PREVIEW_PICTURE"]) { $element["PREVIEW_PICTURE"] = CFile::makeFileArray($element["PREVIEW_PICTURE"]); } else { $element["PREVIEW_PICTURE"] = array("tmp_name" => "", "del" => "Y"); } if ($element["DETAIL_PICTURE"]) { $element["DETAIL_PICTURE"] = CFile::makeFileArray($element["DETAIL_PICTURE"]); } else { $element["DETAIL_PICTURE"] = array("tmp_name" => "", "del" => "Y"); } $element["IBLOCK_SECTION"] = array(); if ($element["IN_SECTIONS"] == "Y") { $sectionsQuery = CIBlockElement::getElementGroups($element["ID"], true, array('ID', 'IBLOCK_ELEMENT_ID')); while ($section = $sectionsQuery->fetch()) { $element["IBLOCK_SECTION"][] = $section["ID"]; } } $element["PROPERTY_VALUES"] = array(); $props =& $element["PROPERTY_VALUES"]; //Delete old files $propsQuery = CIBlockElement::getProperty($element["IBLOCK_ID"], $parentId, array("value_id" => "asc"), array("PROPERTY_TYPE" => "F", "EMPTY" => "N")); while ($prop = $propsQuery->fetch()) { if (!array_key_exists($prop["ID"], $props)) { $props[$prop["ID"]] = array(); } $props[$prop["ID"]][$prop["PROPERTY_VALUE_ID"]] = array("VALUE" => array("tmp_name" => "", "del" => "Y"), "DESCRIPTION" => false); } //Add new proiperty values $propsQuery = CIBlockElement::getProperty($element["IBLOCK_ID"], $element["ID"], array("value_id" => "asc")); $i = 0; while ($prop = $propsQuery->fetch()) { $i++; if (!array_key_exists($prop["ID"], $props)) { $props[$prop["ID"]] = array(); } if ($prop["PROPERTY_VALUE_ID"]) { if ($prop["PROPERTY_TYPE"] == "F") { $props[$prop["ID"]]["n" . $i] = array("VALUE" => CFile::makeFileArray($prop["VALUE"]), "DESCRIPTION" => $prop["DESCRIPTION"]); } else { $props[$prop["ID"]]["n" . $i] = array("VALUE" => $prop["VALUE"], "DESCRIPTION" => $prop["DESCRIPTION"]); } } } $elementObject->update($parentId, $element); CBPDocument::mergeDocuments(array("lists", get_called_class(), $parentId), array("lists", get_called_class(), $documentId)); CIBlockElement::delete($ID); CIBlockElement::wF_CleanUpHistoryCopies($parentId, 0); $strSql = "update b_iblock_element set WF_STATUS_ID='1', WF_NEW=NULL WHERE ID=" . $parentId . " AND WF_PARENT_ELEMENT_ID IS NULL"; $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br>LINE: " . __LINE__); CIBlockElement::updateSearch($parentId); return $parentId; } else { CIBlockElement::wF_CleanUpHistoryCopies($ID, 0); $strSql = "update b_iblock_element set WF_STATUS_ID='1', WF_NEW=NULL WHERE ID=" . $ID . " AND WF_PARENT_ELEMENT_ID IS NULL"; $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br>LINE: " . __LINE__); CIBlockElement::updateSearch($ID); return $ID; } } return false; }
/** * @param int|array $fileID * @param int $storageTypeID * @return array|null */ public static function makeFileArray($fileID, $storageTypeID) { if (!is_integer($storageTypeID)) { $storageTypeID = (int) $storageTypeID; } if ($storageTypeID === StorageType::Disk) { if (!is_array($fileID)) { return DiskManager::makeFileArray($fileID); } $result = array(); foreach ($fileID as $ID) { $ary = DiskManager::makeFileArray($ID); if (is_array($ary)) { $result[] = $ary; } } return $result; } elseif ($storageTypeID === StorageType::WebDav) { if (!is_array($fileID)) { return \CCrmWebDavHelper::makeElementFileArray($fileID); } $result = array(); foreach ($fileID as $ID) { $ary = \CCrmWebDavHelper::makeElementFileArray($ID); if (is_array($ary)) { $result[] = $ary; } } return $result; } elseif ($storageTypeID === StorageType::File) { if (!is_array($fileID)) { return \CFile::makeFileArray($fileID); } $result = array(); foreach ($fileID as $ID) { $ary = \CFile::makeFileArray($ID); if (is_array($ary)) { $result[] = $ary; } } return $result; } throw new Main\NotSupportedException("Storage type: '{$storageTypeID}' is not supported in current context"); }
$APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } IncludeModuleLangFile(__FILE__); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/mail/include.php"; $dbr = $DB->Query("SELECT * FROM b_mail_msg_attachment WHERE ID=" . intval($ID)); if ($dbr_arr = $dbr->Fetch()) { $utfName = CHTTP::urnEncode($dbr_arr['FILE_NAME'], 'UTF-8'); $translitName = CUtil::translit($dbr_arr['FILE_NAME'], LANGUAGE_ID, array('max_len' => 1024, 'safe_chars' => '.', 'replace_space' => '-')); header("Content-Type: application/force-download; name=\"" . $translitName . "\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $dbr_arr["FILE_SIZE"]); header("Content-Disposition: attachment; filename=\"" . $translitName . "\"; filename*=utf-8''" . $utfName); header("Expires: 0"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); if ($dbr_arr['FILE_ID']) { if ($file = CFile::makeFileArray($dbr_arr['FILE_ID'])) { readfile($file['tmp_name']); } } else { echo $dbr_arr['FILE_DATA']; } die; } $APPLICATION->SetTitle(GetMessage("EDIT_MESSAGE_TITLE")); require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_admin_after.php"; $aMenu = array(array("TEXT" => GetMessage("MAIL_ATTACH_BACKLINK"), "LINK" => "mail_message_admin.php?lang=" . LANG)); $context = new CAdminContextMenu($aMenu); $context->Show(); CAdminMessage::ShowMessage(GetMessage("MAIL_ATTACH_ERROR")); require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/epilog_admin.php";
protected function processActionCommit() { $this->checkRequiredPostParams(array('editSessionId')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $this->checkUpdatePermissions(); $currentSession = $this->getEditSessionByCurrentUser((int) $this->request->getPost('editSessionId')); if (!$currentSession) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_EDIT_SESSION'), self::ERROR_COULD_NOT_FIND_EDIT_SESSION))); $this->sendJsonErrorResponse(); } $tmpFile = \CTempFile::getFileName(uniqid('_wd')); checkDirPath($tmpFile); $fileData = new FileData(); $fileData->setId($currentSession->getServiceFileId()); $fileData->setSrc($tmpFile); $newNameFileAfterConvert = null; if ($this->documentHandler->isNeedConvertExtension($this->file->getExtension())) { $newNameFileAfterConvert = getFileNameWithoutExtension($this->file->getName()) . '.' . $this->documentHandler->getConvertExtension($this->file->getExtension()); $fileData->setMimeType(TypeFile::getMimeTypeByFilename($newNameFileAfterConvert)); } else { $fileData->setMimeType(TypeFile::getMimeTypeByFilename($this->file->getName())); } $fileData = $this->documentHandler->downloadFile($fileData); if (!$fileData) { if ($this->documentHandler->isRequiredAuthorization()) { $this->sendNeedAuth(); } $this->errorCollection->add($this->documentHandler->getErrors()); $this->sendJsonErrorResponse(); } $this->deleteEditSession($currentSession); $oldName = $this->file->getName(); //rename in cloud service $renameInCloud = $fileData->getName() && $fileData->getName() != $this->file->getName(); if ($newNameFileAfterConvert || $renameInCloud) { if ($newNameFileAfterConvert && $renameInCloud) { $newNameFileAfterConvert = getFileNameWithoutExtension($fileData->getName()) . '.' . getFileExtension($newNameFileAfterConvert); } $this->file->rename($newNameFileAfterConvert); } $fileArray = \CFile::makeFileArray($tmpFile); $fileArray['name'] = $this->file->getName(); $fileArray['type'] = $fileData->getMimeType(); $fileArray['MODULE_ID'] = Driver::INTERNAL_MODULE_ID; /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $fileId = \CFile::saveFile($fileArray, Driver::INTERNAL_MODULE_ID); if (!$fileId) { \CFile::delete($fileId); $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_SAVE_FILE'), self::ERROR_COULD_NOT_SAVE_FILE))); $this->sendJsonErrorResponse(); } $versionModel = $this->file->addVersion(array('ID' => $fileId, 'FILE_SIZE' => $fileArray['size']), $this->getUser()->getId(), true); if (!$versionModel) { \CFile::delete($fileId); $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_ADD_VERSION'), self::ERROR_COULD_NOT_ADD_VERSION))); $this->errorCollection->add($this->file->getErrors()); $this->sendJsonErrorResponse(); } if ($this->isLastEditSessionForFile()) { $this->deleteFile($currentSession, $fileData); } $this->sendJsonSuccessResponse(array('objectId' => $this->file->getId(), 'newName' => $this->file->getName(), 'oldName' => $oldName)); }
/** * @param bool $getFromFileIfPossible * @return string|null */ public function getSrc($getFromFileIfPossible = true) { if (!$this->src && $getFromFileIfPossible && $this->file instanceof File) { $fileArray = \CFile::makeFileArray($this->file->getFileId()); if (!is_array($fileArray)) { return null; } $this->src = $fileArray['tmp_name']; } return $this->src; }
public function uploadVersion(Entry $entry) { if (!$entry->getTmpFile()) { $this->errorCollection->addOne(new Error('Could not find cloud import', self::ERROR_COULD_NOT_FIND_CLOUD_IMPORT)); return null; } if ($entry->getContentSize() != $entry->getDownloadedContentSize()) { $this->errorCollection->addOne(new Error('Content size != downloaded content size')); return null; } /** @var File $file */ $file = $entry->getObject(); if (!$file) { $this->errorCollection->addOne(new Error('Could not get file from cloud import record')); return null; } $tmpFile = $entry->getTmpFile(); $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath()); $version = $file->uploadVersion($fileArray, $this->documentHandler->getUserId()); if (!$version) { $tmpFile->delete(); $this->errorCollection->add($file->getErrors()); return null; } $entry->linkVersion($version); return $version; }
/** * @param $name * @param $targetElementId * @param TmpFile $tmpFile * @param array $data * @return array|bool * @throws AccessDeniedException */ public function updateFile($name, $targetElementId, TmpFile $tmpFile, array $data = array()) { /** @var File $file */ $file = File::loadById($targetElementId); if (!$file) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetElementId}", 11154))); $tmpFile->delete(); return false; } if (!$file->canUpdate($this->storage->getCurrentUserSecurityContext())) { $tmpFile->delete(); throw new AccessDeniedException(); } /** @var array $fileArray */ if ($tmpFile->isCloud() && $tmpFile->getContentType()) { /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $fileId = \CFile::saveFile(array('name' => $tmpFile->getFilename(), 'tmp_name' => $tmpFile->getAbsolutePath(), 'type' => $tmpFile->getContentType()), Driver::INTERNAL_MODULE_ID, true, true); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $fileArray = \CFile::getFileArray($fileId); if (!$fileArray) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " getFileArray", 1115541))); $tmpFile->delete(); return false; } if (!empty($data['originalTimestamp'])) { $fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp'])); } if ($file->addVersion($fileArray, $this->getUser()->getId())) { $tmpFile->delete(); $this->loadFormattedFolderTreeAndBreadcrumbs(); return $this->formatFileToResponse($file); } else { \CFile::delete($fileId); } } else { $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath()); if (!$fileArray) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " MakeFileArray", 11155))); $tmpFile->delete(); return false; } if (!empty($data['originalTimestamp'])) { $fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp'])); } if ($file->uploadVersion($fileArray, $this->getUser()->getId())) { $tmpFile->delete(); $this->loadFormattedFolderTreeAndBreadcrumbs(); return $this->formatFileToResponse($file); } } $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadVersion", 11156))); $this->errorCollection->add($file->getErrors()); $tmpFile->delete(); return false; }
public static function getContents($attachment) { if (!is_array($attachment)) { if ($res = CMailAttachment::getByID($attachment)) { $attachment = $res->fetch(); } } if (!is_array($attachment) || !isset($attachment['FILE_DATA']) && empty($attachment['FILE_ID'])) { return false; } if ($attachment['FILE_ID'] > 0) { if ($file = CFile::makeFileArray($attachment['FILE_ID'])) { return file_get_contents($file['tmp_name']); } } else { return $attachment['FILE_DATA']; } }
/** * @param $name * @param $targetElementId * @param TmpFile $tmpFile * @return array|boolean */ public function updateFile($name, $targetElementId, TmpFile $tmpFile) { /** @var File $file */ $file = File::loadById($targetElementId); if (!$file) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetElementId}", 11154))); $tmpFile->delete(); return false; } if (!$file->canUpdate($this->storage->getCurrentUserSecurityContext())) { $tmpFile->delete(); throw new AccessDeniedException(); } $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath()); if (!$fileArray) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " MakeFileArray", 11155))); $tmpFile->delete(); return false; } if ($file->uploadVersion($fileArray, $this->getUser()->getId())) { $tmpFile->delete(); $this->loadFormattedFolderTreeAndBreadcrumbs(); return $this->formatFileToResponse($file); } $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadVersion", 11156))); $this->errorCollection->add($file->getErrors()); $tmpFile->delete(); return false; }