protected static function uploadFile($name, $content, array $parameters = array()) { static::includeDisk(); $storage = Driver::getInstance()->getStorageByUserId($parameters['USER_ID']); if (!$storage) { throw new RestException("Could not find storage for user '" . $parameters['USER_ID'] . "'.", RestException::ERROR_NOT_FOUND); } $folder = $storage->getFolderForUploadedFiles(); if (!$folder) { return false; } $securityContext = $storage->getCurrentUserSecurityContext(); if (!$folder->canAdd($securityContext)) { throw new AccessException(); } $fileData = \CRestUtil::saveFile($content); if (!$fileData) { throw new RestException('Could not save file'); } $file = $folder->uploadFile($fileData, array('NAME' => $name, 'CREATED_BY' => $parameters['USER_ID']), array(), true); if (!$file) { //$folder->getErrors(); throw new RestException("Could not upload file to the storage"); } return $file->getId(); }
/** * Constructor of Externalizer. * @param Service\Base $service Service which provides methods for REST. * @param \CRestServer $restServer REST server object. */ public function __construct(Service\Base $service, \CRestServer $restServer) { $this->urlManager = Disk\Driver::getInstance()->getUrlManager(); $this->host = $this->urlManager->getHostUrl(); $this->restServer = $restServer; $this->service = $service; }
private function getGridData($gridId) { $grid = array('ID' => $gridId); $securityContext = $this->storage->getCurrentUserSecurityContext(); $parameters = array('with' => array('FILE', 'CREATE_USER'), 'filter' => array('IS_EXPIRED' => false, 'OBJECT.STORAGE_ID' => $this->storage->getId(), 'CREATED_BY' => $this->getUser()->getId())); $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('OBJECT_ID', 'OBJECT.CREATED_BY')); $items = ExternalLink::getModelList($parameters); Collection::sortByColumn($items, array('CREATE_TIME' => array(SORT_NUMERIC, SORT_ASC))); $urlManager = Driver::getInstance()->getUrlManager(); $rows = array(); foreach ($items as $externalLink) { /** @var ExternalLink $externalLink */ $exportData = $externalLink->toArray(); $nameSpecialChars = htmlspecialcharsbx($externalLink->getFile()->getName()); $createDateText = htmlspecialcharsbx((string) $externalLink->getCreateTime()); $columnName = "\n\t\t\t\t<table class=\"bx-disk-object-name\"><tr>\n\t\t\t\t\t\t<td style=\"width: 45px;\"><div data-object-id=\"{$externalLink->getId()}\" class=\"draggable bx-file-icon-container-small bx-disk-file-icon\"></div></td>\n\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$externalLink->getId()}\" href=\"\" data-bx-dateModify=\"{$createDateText}\">{$nameSpecialChars}</a></td>\n\t\t\t\t</tr></table>\n\t\t\t"; $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $externalLink->getCreatedBy())); $rows[] = array('data' => $exportData, 'columns' => array('CREATE_TIME' => formatDate('x', $externalLink->getCreateTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'UPDATE_TIME' => formatDate('x', $externalLink->getCreateTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'NAME' => $columnName, 'FORMATTED_SIZE' => CFile::formatSize($externalLink->getFile()->getSize()), 'CREATE_USER' => "\n\t\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($externalLink->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t\t"), 'actions' => array(array("PSEUDO_NAME" => "download", "DEFAULT" => true, "ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_ACT_DOWNLOAD'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadFile($externalLink->getFile()) . "')"), array("PSEUDO_NAME" => "disable_external_link", "ICONCLASS" => "disable_external_link", "TEXT" => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_ACT_DISABLE_EXTERNAL_LINK'), "SHORT_TEXT" => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_ACT_DISABLE_EXTERNAL_LINK_SHORT'), "ONCLICK" => "BX.Disk['ExternalLinkListClass_{$this->getComponentId()}'].disableExternalLink({$externalLink->getId()}, {$externalLink->getObjectId()})"))); } unset($externalLink); $grid['MODE'] = 'list'; $grid['HEADERS'] = array(array('id' => 'ID', 'name' => 'ID', 'default' => false, 'show_checkbox' => true), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_COLUMN_NAME'), 'default' => true), array('id' => 'CREATE_TIME', 'name' => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_COLUMN_CREATE_TIME'), 'default' => true), array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_COLUMN_CREATE_USER'), 'default' => false), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_EXTERNAL_LINK_LIST_COLUMN_FORMATTED_SIZE'), 'default' => true)); $grid['ROWS'] = $rows; $grid['ROWS_COUNT'] = count($rows); $grid['FOOTER'] = array(); return $grid; }
public static function AddBlogPost($arFields) { if (!is_array($_POST)) { $_POST = array(); } $_POST = array_merge($_POST, array("apply" => "Y", "decode" => "N"), $arFields); $strPathToPost = COption::GetOptionString("socialnetwork", "userblogpost_page", false, SITE_ID); $strPathToSmile = COption::GetOptionString("socialnetwork", "smile_page", false, SITE_ID); $BlogGroupID = COption::GetOptionString("socialnetwork", "userbloggroup_id", false, SITE_ID); $arBlogComponentParams = array("IS_REST" => "Y", "ID" => "new", "PATH_TO_POST" => $strPathToPost, "PATH_TO_SMILE" => $strPathToSmile, "GROUP_ID" => $BlogGroupID, "USER_ID" => $GLOBALS["USER"]->GetID(), "USE_SOCNET" => "Y", "MICROBLOG" => "Y"); ob_start(); $result = $GLOBALS["APPLICATION"]->IncludeComponent("bitrix:socialnetwork.blog.post.edit", "", $arBlogComponentParams, false, array("HIDE_ICONS" => "Y")); ob_end_clean(); if (!$result) { throw new Exception('Error'); } else { if (isset($arFields["FILES"]) && \Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk') && ($storage = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId($GLOBALS["USER"]->GetID())) && ($folder = $storage->getFolderForUploadedFiles($GLOBALS["USER"]->GetID()))) { // upload to storage $arResultFile = array(); foreach ($arFields["FILES"] as $tmp) { $arFile = CRestUtil::saveFile($tmp); if (is_array($arFile)) { $file = $folder->uploadFile($arFile, array('NAME' => $arFile["name"], 'CREATED_BY' => $GLOBALS["USER"]->GetID()), array(), true); if ($file) { $arResultFile[] = \Bitrix\Disk\Uf\FileUserType::NEW_FILE_PREFIX . $file->getId(); } } } if (!empty($arResultFile)) { CBlogPost::Update($result, array("HAS_PROPS" => "Y", "UF_BLOG_POST_FILE" => $arResultFile)); } } return $result; } }
private function loadData() { if (empty($this->arParams['PARAMS']['arUserField'])) { return array(); } $userId = $this->getUser()->getId(); $values = $this->arParams['PARAMS']['arUserField']['VALUE']; if (!is_array($this->arParams['PARAMS']['arUserField']['VALUE'])) { $values = array($values); } $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager(); $versions = array(); foreach ($values as $value) { $attachedObjectId = (int) $value; if ($attachedObjectId <= 0) { continue; } /** @var \Bitrix\Disk\AttachedObject $attachedModel */ $attachedModel = \Bitrix\Disk\AttachedObject::loadById($attachedObjectId, array('VERSION.OBJECT')); if (!$attachedModel) { continue; } $version = $attachedModel->getVersion(); if (!$version) { continue; } $extension = $version->getExtension(); $versions[] = array('ID' => $attachedModel->getId(), 'NAME' => $version->getName(), 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($extension), 'EDITABLE' => DocumentHandler::isEditable($extension), 'CAN_UPDATE' => $attachedModel->canUpdate($userId), 'FROM_EXTERNAL_SYSTEM' => $version->getObject()->getContentProvider() && $version->getObject()->getCreatedBy() == $userId, 'EXTENSION' => $extension, 'SIZE' => \CFile::formatSize($version->getSize()), 'HISTORY_URL' => $urlManager->getUrlUfController('history', array('attachedId' => $attachedModel->getId())), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $attachedModel->getId())), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyTome', array('attachedId' => $attachedModel->getId())), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($attachedModel->getId(), 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($attachedModel->getId(), 'gdrive'), 'GLOBAL_CONTENT_VERSION' => $version->getGlobalContentVersion(), 'ATTRIBUTES_FOR_VIEWER' => Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('version' => $version->getGlobalContentVersion(), 'canUpdate' => $attachedModel->canUpdate($userId), 'showStorage' => false, 'externalId' => false, 'relativePath' => false))); } unset($value); return $versions; }
private static function needProxyToDiskByDocType($documentType) { if (!(\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk'))) { return false; } if (empty($documentType)) { return false; } $storage = null; if (substr($documentType, 0, 7) == 'STORAGE') { $storageId = (int) substr($documentType, 8); if ($storageId) { $storage = \Bitrix\Disk\Storage::loadById($storageId); } if ($storage) { return $storage; } } list(, $iblockId, $typeLib, $entityId) = explode('_', $documentType); if ($typeLib == 'user') { $storage = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId($entityId); } elseif ($typeLib == 'group') { $storage = \Bitrix\Disk\Driver::getInstance()->getStorageByGroupId($entityId); } else { return false; } return $storage; }
public static function getDocument($documentId) { $documentId = (int) $documentId; if ($documentId <= 0) { throw new CBPArgumentNullException("documentId"); } $file = File::loadById($documentId); if (!$file) { return null; } $ufFields = Driver::getInstance()->getUserFieldManager()->getFieldsForObject($file); $ufFileRow = array(); if (!empty($ufFields)) { foreach ($ufFields as $fieldKey => $fieldData) { $ufFileRow[$fieldKey] = $fieldData['VALUE']; $ufFileRow[$fieldData['XML_ID']] = $fieldData['VALUE']; } } $fileRow = File::getList(array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => array('ID' => $documentId)))->fetch(); if (!$fileRow) { return null; } if (empty($fileRow["CODE"])) { $fileRow["CODE"] = Loc::getMessage("DISK_BZ_D_NAME_NOT_CODE"); } return array_merge(array("ID" => $fileRow["ID"], "CREATE_TIME" => $fileRow["CREATE_TIME"], "CREATED_BY" => $fileRow["CREATED_BY"], "CREATED_BY_PRINTABLE" => $fileRow['CREATE_USERREF_NAME'] . ' ' . $fileRow['CREATE_USERREF_LAST_NAME'], "UPDATE_TIME" => $fileRow["UPDATE_TIME"], "UPDATED_BY" => $fileRow["UPDATED_BY"], "UPDATED_BY_PRINTABLE" => $fileRow['UPDATE_USERREF_NAME'] . ' ' . $fileRow['UPDATE_USERREF_LAST_NAME'], "DELETE_TIME" => $fileRow["DELETE_TIME"], "DELETED_BY" => $fileRow["DELETED_BY"], "DELETED_BY_PRINTABLE" => $fileRow['DELETE_USERREF_NAME'] . ' ' . $fileRow['DELETE_USERREF_LAST_NAME'], "STORAGE_ID" => $fileRow["STORAGE_ID"], "NAME" => $fileRow["NAME"], "SIZE" => $fileRow["SIZE"], "CODE" => $fileRow["CODE"], "TIMESTAMP_X" => $fileRow["UPDATE_TIME"], "MODIFIED_BY" => $fileRow["CREATED_BY"], "MODIFIED_BY_PRINTABLE" => $fileRow['UPDATE_USERREF_NAME'] . ' ' . $fileRow['UPDATE_USERREF_LAST_NAME'], "DATE_CREATE" => $fileRow["CREATE_TIME"], "FILE_SIZE" => $fileRow["SIZE"]), $ufFileRow); }
function __wd_get_root_section($IBLOCK_ID, $object, $object_id) { $result = CIBlockWebdavSocnet::GetSectionID($IBLOCK_ID, $object, $object_id); if (intval($result) > 0) { return $result; } else { __wd_check_uf_use_bp_property($arParams["IBLOCK_ID"]); $arFields = array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y", "SOCNET_GROUP_ID" => false, "IBLOCK_SECTION_ID" => 0, "UF_USE_BP" => "N"); if ($object == "user") { $dbUser = CUser::GetByID($object_id); $arUser = $dbUser->Fetch(); $arFields["NAME"] = trim($arUser['LAST_NAME'] . " " . $arUser['FIRST_NAME']); $arFields["NAME"] = trim(!empty($arFields["NAME"]) ? $arFields["NAME"] : $arUser['LOGIN']); $arFields['CREATED_BY'] = $arUser['ID']; $arFields['MODIFIED_BY'] = $arUser['ID']; if (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E") { $arTasks = CWebDavIblock::GetTasks(); $arFields['RIGHTS'] = array('n0' => array('GROUP_CODE' => 'U' . $object_id, 'TASK_ID' => $arTasks['X'])); } } else { /* $res = CSocNetGroup::GetByID($arResult["VARIABLES"]["group_id"]); if (!$res) { $arParams["ERROR_MESSAGE"] = GetMessage("SONET_GROUP_NOT_EXISTS"); return 0; } */ $arFields["SOCNET_GROUP_ID"] = $object_id; //$arGroup = CSocNetGroup::GetByID($object_id); $arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $object_id; $dbGroup = CSocNetGroup::GetList(array(), array("ID" => (int) $object_id), false, false, array("ID", "SITE_ID", "NAME")); if ($arGroup = $dbGroup->Fetch()) { $arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $arGroup["NAME"]; } if (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E") { $arTasks = CWebDavIblock::GetTasks(); $arFields['RIGHTS'] = array('n0' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_A', 'TASK_ID' => $arTasks['X']), 'n1' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_E', 'TASK_ID' => $arTasks['W']), 'n2' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_K', 'TASK_ID' => $arTasks['W'])); } } if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk')) { \Bitrix\Disk\Driver::getInstance()->addGroupStorage($arFields["SOCNET_GROUP_ID"]); } $GLOBALS["UF_USE_BP"] = $arFields["UF_USE_BP"]; $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $IBLOCK_ID . "_SECTION", $arFields); $bs = new CIBlockSection(); $sectionID = $bs->Add($arFields); if (!$sectionID) { $arParams["ERROR_MESSAGE"] = $bs->LAST_ERROR; return 0; } WDClearComponentCache(array("webdav.element.edit", "webdav.element.hist", "webdav.element.upload", "webdav.element.view", "webdav.menu", "webdav.section.edit", "webdav.section.list")); return true; /* if ($ob->workflow == 'bizproc') { __wd_create_default_bp_user_and_groups($arBizProcParameters); } */ } }
public function preloadOperationsForChildren($parentObjectId) { $rightsManager = Driver::getInstance()->getRightsManager(); foreach ($rightsManager->getUserOperationsForChildren($parentObjectId, $this->userId) as $objectId => $operations) { $this->operationsCache[$objectId] = $operations; } unset($operations); }
/** * @param AttachedObject $attachedObject * @return static * @throws \Bitrix\Main\SystemException */ public static function buildByAttachedObject(AttachedObject $attachedObject) { /** @var Entry $cloudImport */ $cloudImport = $attachedObject->getObject()->getLastCloudImportEntry(); $documentHandler = Driver::getInstance()->getDocumentHandlersManager()->getHandlerByCode($cloudImport->getService()); if (!$documentHandler) { return null; } return new static($documentHandler); }
/** * Returns tasks by module Disk. * @return array */ protected function getTasks() { $rightsManager = Driver::getInstance()->getRightsManager(); $tasks = array($rightsManager->getTaskById($rightsManager->getTaskIdByName($rightsManager::TASK_FULL)), $rightsManager->getTaskById($rightsManager->getTaskIdByName($rightsManager::TASK_EDIT)), $rightsManager->getTaskById($rightsManager->getTaskIdByName($rightsManager::TASK_READ))); foreach ($tasks as &$task) { $task = array_intersect_key($task, array('ID' => true, 'NAME' => true, 'TITLE' => true)); } unset($task); return $tasks; }
/** * Deletes application storage. * @param array $fields Fields describes application. * @return void */ public static function onRestAppDelete(array $fields) { if (empty($fields['APP_ID']) || empty($fields['CLEAN'])) { return; } $storage = Driver::getInstance()->getStorageByRestApp($fields['APP_ID']); if (!$storage) { return; } $storage->delete(SystemUser::SYSTEM_USER_ID); }
protected function processActionDefault() { $validPassword = true; if ($this->externalLink->hasPassword()) { $validPassword = $this->checkPassword(); } $file = $this->externalLink->getFile(); $downloadToken = Random::getString(12); $this->storeDownloadToken($file, $downloadToken); $this->arResult = array('FILE' => array('ID' => $file->getId(), 'IS_IMAGE' => TypeFile::isImage($file->getName()), 'ICON_CLASS' => Icon::getIconClassByObject($file), 'UPDATE_TIME' => $file->getUpdateTime(), 'NAME' => $file->getName(), 'SIZE' => $file->getSize(), 'DOWNLOAD_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'download', 'token' => $downloadToken)), 'SHOW_PREVIEW_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'showPreview', 'token' => $downloadToken)), 'SHOW_FILE_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'showFile', 'token' => $downloadToken)), 'VIEW_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getShortUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'default'), true), 'VIEW_FULL_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'default'))), 'PROTECTED_BY_PASSWORD' => $this->externalLink->hasPassword(), 'VALID_PASSWORD' => $validPassword); $this->includeComponentTemplate(); }
protected function processActionDefault() { $serverParams = array(); $serverParams["AUTH_MODE"] = "DIGEST"; $serverParams["SECURE"] = !empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] !== "off" || $_SERVER["SERVER_PORT"] == 443; $serverParams["CLIENT_OS"] = $this->getClientOS(); $this->arResult["SERVER_PARAMS"] = $serverParams; $this->arResult["NETWORK_DRIVE_LINK"] = Driver::getInstance()->getUrlManager()->getHostUrl() . $this->getApplication()->GetCurPage(); $this->arResult["TEMPLATE_LINK"] = $this->getApplication()->GetCurPage(); $this->arResult["USER_LOGIN"] = $this->getUser()->GetLogin(); $this->includeComponentTemplate(); }
/** * Adds row to entity table, fills error collection and builds model. * @param array $data Data. * @param ErrorCollection $errorCollection Error collection. * @return \Bitrix\Disk\Internals\Model|static|null * @throws \Bitrix\Main\NotImplementedException * @internal */ public static function add(array $data, ErrorCollection $errorCollection) { $result = FileTable::add($data); if (!$result->isSuccess()) { $errorCollection->addFromResult($result); return null; } $file = static::buildFromResult($result); if ($file && $file->getCreatedBy()) { $driver = Driver::getInstance(); $driver->getRecentlyUsedManager()->push($file->getCreatedBy(), $file->getId()); } return $file; }
protected function processActionGenerateExternalLink() { /** @var File $file */ list($file, $extLink) = $this->getFileAndExternalLink(); if (!$extLink) { $extLink = $file->addExternalLink(array('CREATED_BY' => $this->getUser()->getId(), 'TYPE' => ExternalLinkTable::TYPE_MANUAL)); } if (!$extLink) { $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FILE_VIEW_ERROR_COULD_NOT_CREATE_FIND_EXT_LINK'), self::ERROR_COULD_NOT_CREATE_FIND_EXT_LINK)); $this->errorCollection->add($file->getErrors()); $this->sendJsonErrorResponse(); } $this->sendJsonSuccessResponse(array('hash' => $extLink->getHash(), 'link' => Driver::getInstance()->getUrlManager()->getShortUrlExternalLink(array('hash' => $extLink->getHash(), 'action' => 'default'), true))); }
/** * For UF and work with local editors we have special scenario: * If user don't have permission for update file, * we have to attach new file to entity by posting comment with * alternative version. */ protected function processActionCommit() { $userId = $this->getUser()->getId(); if ($this->attachedModel->canUpdate($userId)) { parent::processActionCommit(); return; } $this->checkRequiredFilesParams(array('file')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $userStorage = Driver::getInstance()->getStorageByUserId($userId); if (!$userStorage) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_STORAGE'), self::ERROR_COULD_NOT_FIND_STORAGE))); $this->sendJsonErrorResponse(); } $folder = $userStorage->getFolderForCreatedFiles(); if (!$folder) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES'), self::ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES))); $this->sendJsonErrorResponse(); } if (!$folder->canAdd($folder->getStorage()->getCurrentUserSecurityContext())) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS))); $this->sendJsonErrorResponse(); } //todo fix Cherezov. Ban encoding 1251 $fileArray = $this->request->getFile('file'); $fileArray['name'] = $this->file->getName(); $newFile = $folder->uploadFile($fileArray, array('NAME' => $this->file->getName(), 'CREATED_BY' => $userId), array(), true); if (!$newFile) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_CREATE_FILE'), self::ERROR_COULD_NOT_CREATE_FILE))); $this->errorCollection->add($folder->getErrors()); $this->sendJsonErrorResponse(); } $valueFileUf = FileUserType::NEW_FILE_PREFIX . $newFile->getId(); /** @var User $createUser */ $createUser = User::loadById($userId); if (!$createUser) { $this->sendJsonErrorResponse(); } $text = Loc::getMessage('DISK_UF_LOCAL_DOC_CONTROLLER_UPLOAD_NEW_VERSION_IN_COMMENT_M'); if ($createUser->getPersonalGender() == 'F') { $text = Loc::getMessage('DISK_UF_LOCAL_DOC_CONTROLLER_UPLOAD_NEW_VERSION_IN_COMMENT_F'); } if ($this->attachedModel->getAllowAutoComment()) { $this->attachedModel->getConnector()->addComment($userId, array('text' => $text, 'fileId' => $valueFileUf)); } $this->sendJsonSuccessResponse(); }
public static function getFileData($fileNodeId, $parameters = array()) { if (!is_array($parameters)) { $parameters = array(); } $result = array('ATTACHMENT_ID' => $fileNodeId); if (!isset($parameters['SERVER']) || !$parameters['SERVER'] instanceof \CRestServer) { return $result; } if (!Loader::includeModule('disk')) { return $result; } $fileNodeId = intval($fileNodeId); if (!$fileNodeId) { return $result; } $result['DOWNLOAD_URL'] = Driver::getInstance()->getUrlManager()->getUrlUfController('download', array('attachedId' => $fileNodeId, 'auth' => $parameters['SERVER']->getAuth())); return $result; }
/** * Returns list of storages. * @param array $filter Filter. * @param array $order Order. * @return Disk\Storage[]|null */ protected function getList(array $filter = array(), array $order = array()) { $securityContext = $this->getSecurityContextByUser($this->userId); $internalizer = new Disk\Rest\Internalizer(new Entity\Storage(), $this); $parameters = array_merge(array('with' => array('ROOT_OBJECT'), 'filter' => array_merge(array('=ROOT_OBJECT.PARENT_ID' => null, '=MODULE_ID' => Disk\Driver::INTERNAL_MODULE_ID, '=RIGHTS_CHECK' => true), $internalizer->cleanFilter($filter)), 'runtime' => array(new ExpressionField('RIGHTS_CHECK', 'CASE WHEN ' . $securityContext->getSqlExpressionForList('%1$s', '%2$s') . ' THEN 1 ELSE 0 END', array('ROOT_OBJECT.ID', 'ROOT_OBJECT.CREATED_BY'), array('data_type' => 'boolean'))), 'order' => $order), Disk\Rest\RestManager::getNavData($this->start)); $parameters = Disk\Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ROOT_OBJECT.ID', 'ROOT_OBJECT.CREATED_BY')); $storages = Disk\Storage::getModelList($parameters); if ($storages === null) { $this->errorCollection->addOne(new Error('Could not load list of storages.')); return null; } foreach ($storages as $key => $storage) { if (!$storage->getProxyType() instanceof Disk\ProxyType\Common && !$storage->getProxyType() instanceof Disk\ProxyType\Group && !$storage->getProxyType() instanceof Disk\ProxyType\User) { unset($storages[$key]); } } unset($storage); return $storages; }
protected function processActionDefault() { $diskSecurityContext = $this->getSecurityContextByUser($this->getUser()); $this->arResult["COMMON_DISK"] = array(); $filterReadableList = array('STORAGE.ENTITY_TYPE' => ProxyType\Common::className()); foreach (Storage::getReadableList($diskSecurityContext, array('filter' => $filterReadableList)) as $storage) { $proxyType = $storage->getProxyType(); if ($storage->getSiteId() != SITE_ID) { continue; } $this->arResult["COMMON_DISK"][$storage->getEntityId()] = array("TITLE" => $proxyType->getEntityTitle(), "URL" => $proxyType->getBaseUrlFolderList(), "ICON" => $proxyType->getEntityImageSrc(64, 64)); } $userId = $this->getUser()->getId(); $storage = Driver::getInstance()->getStorageByUserId($userId); $proxyType = $storage->getProxyType(); $this->arResult["COMMON_DISK"][$storage->getEntityId()] = array("TITLE" => $proxyType->getTitleForCurrentUser(), "URL" => $proxyType->getBaseUrlFolderList(), "ICON" => $proxyType->getEntityImageSrc(64, 64)); $this->arResult["COMMON_DISK"]["GROUP"] = array("TITLE" => Loc::getMessage('DISK_AGGREGATOR_GROUP_TITLE'), "ID" => "bx-disk-aggregator-group-link"); $this->arResult["COMMON_DISK"]["USER"] = array("TITLE" => Loc::getMessage('DISK_AGGREGATOR_USER_TITLE'), "ID" => "bx-disk-aggregator-user-link"); $this->arResult["NETWORK_DRIVE_LINK"] = Driver::getInstance()->getUrlManager()->getHostUrl() . $this->getApplication()->GetCurPage(); $this->includeComponentTemplate(); }
/** * Called before record transformed for log writing. * * @param array &$record Database record. * * @return void */ public function beforeLogFormat(array &$record) { global $USER; if ($record["PARAM_NAME"] !== "FILE_ID" || $record["PARAM_VALUE"] <= 0) { return; } if (!\Bitrix\Main\Loader::includeModule('disk')) { AddMessage2Log('MessageParamHandler::beforeLogFormat: failed to load disk module.'); return; } if (!is_object($USER) || $USER->GetID() < 0) { AddMessage2Log('MessageParamHandler::beforeLogFormat: no user provided.'); return; } /** @var \Bitrix\Disk\File $file */ $fileId = $record["PARAM_VALUE"]; $userId = $USER->GetID(); $file = \Bitrix\Disk\File::loadById($fileId); if (!$file) { AddMessage2Log('MessageParamHandler::beforeLogFormat: file (' . $fileId . ') not found for user (' . $userId . ').'); return; } $externalLink = $file->addExternalLink(array('CREATED_BY' => $userId, 'TYPE' => \Bitrix\Disk\Internals\ExternalLinkTable::TYPE_MANUAL)); if (!$externalLink) { AddMessage2Log('MessageParamHandler::beforeLogFormat: failed to get external link for file (' . $fileId . ').'); AddMessage2Log($file->getErrors()); return; } $url = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $externalLink->getHash(), 'action' => 'default'), true); $fileName = $file->getName(); $fileSize = $file->getSize(); $attach = new \CIMMessageParamAttach(null, \CIMMessageParamAttach::CHAT); $attach->AddFiles(array(array("NAME" => $fileName, "LINK" => $url, "SIZE" => $fileSize))); $record["PARAM_NAME"] = 'ATTACH'; $record["PARAM_VALUE"] = 1; $record["PARAM_JSON"] = $attach->GetJSON(); }
/** * @param $declinedBy * @param bool $withDeletingObject * @return bool */ public function decline($declinedBy, $withDeletingObject = true) { $this->errorCollection->clear(); if ($this->isDeclined()) { return true; } if ($withDeletingObject && ($this->isToUser() || $this->isToGroup() || $this->isToDepartmentChild())) { $linkModel = $this->getLinkObject(); if ($linkModel instanceof FolderLink) { $linkModel->deleteTree($declinedBy); } elseif ($linkModel instanceof FileLink) { $linkModel->deleteWithoutSharing($declinedBy); } } $success = $this->update(array('LINK_OBJECT_ID' => null, 'LINK_STORAGE_ID' => null, 'STATUS' => SharingTable::STATUS_IS_DECLINED)); if (!$success) { return false; } foreach ($this->getChildren() as $childSharing) { $childSharing->decline($declinedBy, $withDeletingObject); } unset($childSharing); if (!$this->getRealObject()) { return true; } if ($this->isToUser() || $this->isToGroup() || $this->isToDepartmentParent()) { $rightsManager = Driver::getInstance()->getRightsManager(); $rightsManager->deleteByDomain($this->getRealObject(), $rightsManager->getSharingDomain($this->id)); } if ($this->isToUser() && !$this->isToDepartmentChild() && self::CODE_USER . $declinedBy == $this->toEntity && $this->fromEntity != $this->toEntity) { $isFolder = $this->getRealObject() instanceof Folder; $message = Loc::getMessage($isFolder ? 'DISK_SHARING_MODEL_TEXT_SELF_DISCONNECT' : 'DISK_SHARING_MODEL_TEXT_SELF_DISCONNECT_FILE', array('#NAME#' => $this->getRealObject()->getName(), '#USERNAME#' => User::loadById($declinedBy)->getFormattedName())); list($subTag, $tag) = $this->getNotifyTags(); Driver::getInstance()->sendNotify($this->createdBy, array('FROM_USER_ID' => $declinedBy, 'NOTIFY_EVENT' => 'sharing', 'NOTIFY_TAG' => $tag, 'NOTIFY_MESSAGE' => $message, 'NOTIFY_MESSAGE_OUT' => strip_tags($message))); } return true; }
$errorMessage .= $e->GetString(); } } } } if (StrLen($errorMessage) <= 0) { $pathToImages = WIZARD_SERVICE_ABSOLUTE_PATH . "/images/"; $arGroupsId = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0); $arGroups = array(0 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_0"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_0"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "Y", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[1], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_0"), "IMAGE_ID" => array("name" => "0.jpg", "type" => "image/jpeg", "tmp_name" => $pathToImages . "/0.jpg", "error" => "0", "size" => @filesize($pathToImages . "/0.jpg"), "MODULE_ID" => "socialnetwork"), "NUMBER_OF_MEMBERS" => 1, "INITIATE_PERMS" => "E", "SPAM_PERMS" => "N", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 1 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_1"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_1"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "Y", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[0], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_1"), "IMAGE_ID" => array("name" => "1.jpg", "type" => "image/jpeg", "tmp_name" => $pathToImages . "/1.jpg", "error" => "0", "size" => @filesize($pathToImages . "/1.jpg"), "MODULE_ID" => "socialnetwork"), "NUMBER_OF_MEMBERS" => 1, "INITIATE_PERMS" => "E", "SPAM_PERMS" => "N", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 2 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_2"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_2"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "Y", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[0], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_2"), "IMAGE_ID" => array("name" => "2.jpg", "type" => "image/jpeg", "tmp_name" => $pathToImages . "/2.jpg", "error" => "0", "size" => @filesize($pathToImages . "/2.jpg"), "MODULE_ID" => "socialnetwork"), "NUMBER_OF_MEMBERS" => 1, "SPAM_PERMS" => "N", "INITIATE_PERMS" => "E", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 3 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_3"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_3"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "Y", "OPENED" => "Y", "SUBJECT_ID" => $arGroupSubjectsId[4], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_3"), "IMAGE_ID" => array("name" => "3.jpg", "type" => "image/jpeg", "tmp_name" => $pathToImages . "/3.jpg", "error" => "0", "size" => @filesize($pathToImages . "/3.jpg"), "MODULE_ID" => "socialnetwork"), "NUMBER_OF_MEMBERS" => 1, "SPAM_PERMS" => "N", "INITIATE_PERMS" => "K", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 4 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_4"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_4"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "Y", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[2], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_4"), "IMAGE_ID" => array("name" => "4.jpg", "type" => "image/jpeg", "tmp_name" => $pathToImages . "/4.jpg", "error" => "0", "size" => @filesize($pathToImages . "/4.jpg"), "MODULE_ID" => "socialnetwork"), "NUMBER_OF_MEMBERS" => 1, "SPAM_PERMS" => "N", "INITIATE_PERMS" => "E", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 5 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_5"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_5"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "Y", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[2], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_5"), "IMAGE_ID" => array("name" => "5.jpg", "type" => "image/jpeg", "tmp_name" => $pathToImages . "/5.jpg", "error" => "0", "size" => @filesize($pathToImages . "/5.jpg"), "MODULE_ID" => "socialnetwork"), "NUMBER_OF_MEMBERS" => 1, "INITIATE_PERMS" => "E", "SPAM_PERMS" => "N", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 6 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_6"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_6"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "Y", "OPENED" => "Y", "SUBJECT_ID" => $arGroupSubjectsId[4], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_6"), "IMAGE_ID" => array("name" => "6.jpg", "type" => "image/jpeg", "tmp_name" => $pathToImages . "/6.jpg", "error" => "0", "size" => @filesize($pathToImages . "/6.jpg"), "MODULE_ID" => "socialnetwork"), "NUMBER_OF_MEMBERS" => 1, "SPAM_PERMS" => "N", "INITIATE_PERMS" => "K", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 7 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_7"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_7"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "Y", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[1], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_7"), "IMAGE_ID" => array("name" => "7.jpg", "type" => "image/jpeg", "tmp_name" => $pathToImages . "/7.jpg", "error" => "0", "size" => @filesize($pathToImages . "/7.jpg"), "MODULE_ID" => "socialnetwork"), "NUMBER_OF_MEMBERS" => 1, "INITIATE_PERMS" => "E", "SPAM_PERMS" => "N", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 8 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_8"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_8"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "N", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[3], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_8"), "NUMBER_OF_MEMBERS" => 1, "INITIATE_PERMS" => "A", "SPAM_PERMS" => "N", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 9 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_9"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_9"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "N", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[3], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_9"), "NUMBER_OF_MEMBERS" => 1, "INITIATE_PERMS" => "A", "SPAM_PERMS" => "N", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()), 10 => array("SITE_ID" => WIZARD_SITE_ID, "NAME" => GetMessage("SONET_GROUP_NAME_10"), "DESCRIPTION" => GetMessage("SONET_GROUP_DESCRIPTION_10"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "ACTIVE" => "Y", "VISIBLE" => "N", "OPENED" => "N", "SUBJECT_ID" => $arGroupSubjectsId[3], "OWNER_ID" => 1, "KEYWORDS" => GetMessage("SONET_GROUP_KEYWORDS_10"), "NUMBER_OF_MEMBERS" => 1, "INITIATE_PERMS" => "A", "SPAM_PERMS" => "N", "=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction())); foreach ($arGroups as $ind => $arGroup) { $dbSubject = CSocNetGroup::GetList(array(), array("NAME" => $arGroup["NAME"], "SITE_ID" => WIZARD_SITE_ID)); if (!$dbSubject->Fetch()) { $idTmp = CSocNetGroup::Add($arGroup); if ($idTmp) { if (CModule::IncludeModule("disk")) { \Bitrix\Disk\Driver::getInstance()->addGroupStorage($idTmp); } $arGroupsId[$ind] = IntVal($idTmp); } else { if ($e = $GLOBALS["APPLICATION"]->GetException()) { $errorMessage .= $e->GetString(); } } } } } if (StrLen($errorMessage) <= 0) { foreach ($arGroupsId as $ind => $val) { CSocNetUserToGroup::Add(array("USER_ID" => 1, "GROUP_ID" => $val, "ROLE" => "A", "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER, "INITIATED_BY_USER_ID" => 1, "MESSAGE" => false)); } }
} } $arCustomPagesPath = array(); if ($arParams["SEF_MODE"] == "Y") { $arVariables = array(); $events = GetModuleEvents("socialnetwork", "OnParseSocNetComponentPath"); while ($arEvent = $events->Fetch()) { ExecuteModuleEventEx($arEvent, array(&$arDefaultUrlTemplates404, &$arCustomPagesPath, $arParams)); } $engine = new CComponentEngine($this); if ($diskEnabled) { $engine->addGreedyPart("#PATH#"); $engine->addGreedyPart("#FILE_PATH#"); $engine->addGreedyPart("#TRASH_PATH#"); $engine->addGreedyPart("#TRASH_FILE_PATH#"); $engine->setResolveCallback(array(\Bitrix\Disk\Driver::getInstance()->getUrlManager(), "resolveSocNetPathComponentEngine")); } $arUrlTemplates = CComponentEngine::MakeComponentUrlTemplates($arDefaultUrlTemplates404, $arParams["SEF_URL_TEMPLATES"]); /* This code is needed to use short paths in WebDAV */ $arUrlTemplates["group_files_short"] = str_replace("#path#", $arDefaultUrlTemplates404["group_files_short"], $arUrlTemplates["group_files"]); /* / This code is needed to use short paths in WebDAV */ $arVariableAliases = CComponentEngine::MakeComponentVariableAliases($arDefaultVariableAliases404, $arParams["VARIABLE_ALIASES"]); $componentPage = $engine->guessComponentPath($arParams["SEF_FOLDER"], $arUrlTemplates, $arVariables); // $componentPage = CComponentEngine::ParseComponentPath($arParams["SEF_FOLDER"], $arUrlTemplates, $arVariables); if (array_key_exists($arVariables["page"], $arDefaultUrlTemplates404)) { $componentPage = $arVariables["page"]; } if (empty($componentPage) || !array_key_exists($componentPage, $arDefaultUrlTemplates404)) { //if (strlen($componentPage) <= 0) $componentPage = "index"; }
/** * @param $userField * @param $value * @param bool $userId False means current user id. * @return array */ public static function checkFields($userField, $value, $userId = false) { $userFieldManager = Driver::getInstance()->getUserFieldManager(); $errors = array(); list($type, $realValue) = static::detectType($value); if ($type == self::TYPE_ALREADY_ATTACHED) { $attachedModel = static::getAttachedObjectById($realValue); if (!$attachedModel) { $errors[] = array("id" => $userField["FIELD_NAME"], "text" => Loc::getMessage('DISK_VERSION_USER_TYPE_ERROR_COULD_NOT_FIND_FILE')); return $errors; } list($connectorClass, $moduleId) = $userFieldManager->getConnectorDataByEntityType($userField['ENTITY_ID']); if (!$userFieldManager->belongsToEntity($attachedModel, $userField['ENTITY_ID'], $userField['ENTITY_VALUE_ID']) && !(is_subclass_of($connectorClass, 'Bitrix\\Disk\\Uf\\ISupportForeignConnector') || in_array('Bitrix\\Disk\\Uf\\ISupportForeignConnector', class_implements($connectorClass)))) { $errors[] = array("id" => $userField["FIELD_NAME"], "text" => Loc::getMessage('DISK_VERSION_USER_TYPE_ERROR_COULD_NOT_FIND_FILE')); return $errors; } } else { if ($realValue <= 0) { $errors[] = array("id" => $userField["FIELD_NAME"], "text" => Loc::getMessage('DISK_VERSION_USER_TYPE_ERROR_INVALID_VALUE')); return $errors; } $version = static::getVersionById($realValue); if (!$version) { $errors[] = array("id" => $userField["FIELD_NAME"], "text" => Loc::getMessage('DISK_VERSION_USER_TYPE_ERROR_COULD_NOT_FIND_FILE')); return $errors; } $file = $version->getObject(); if ($userId === false) { $securityContext = $file->getStorage()->getCurrentUserSecurityContext(); } else { $securityContext = $file->getStorage()->getSecurityContext($userId); } //we don't check rights on file if version create current user. (uf logic, magic) if ($version->getCreatedBy() != self::getActivityUserId() && !$file->canRead($securityContext)) { $errors[] = array("id" => $userField["FIELD_NAME"], "text" => Loc::getMessage('DISK_VERSION_USER_TYPE_ERROR_BAD_RIGHTS')); return $errors; } } return $errors; }
public static function getUFForPostForm($arParams) { $arFileData = array(); $arUF = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields($arParams["ENTITY_TYPE"], $arParams["ENTITY_ID"], LANGUAGE_ID); $ufCode = $arParams["UF_CODE"]; if (!empty($arUF[$ufCode]) && !empty($arUF[$ufCode]["VALUE"])) { if ($arParams["IS_DISK_OR_WEBDAV_INSTALLED"]) { if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::IncludeModule('disk')) { $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager(); $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager(); $userFieldManager->loadBatchAttachedObject($arUF[$ufCode]["VALUE"]); foreach ($arUF[$ufCode]["VALUE"] as $attachedId) { $attachedObject = $userFieldManager->getAttachedObjectById($attachedId); if ($attachedObject) { $file = $attachedObject->getObject(); $fileName = $file->getName(); $fileUrl = $urlManager->getUrlUfController('download', array('attachedId' => $attachedId)); $fileUrl = str_replace("/bitrix/tools/disk/uf.php", SITE_DIR . "mobile/ajax.php", $fileUrl); $fileUrl = $fileUrl . (strpos($fileUrl, "?") === false ? "?" : "&") . "mobile_action=disk_uf_view&filename=" . $fileName; if (\Bitrix\Disk\TypeFile::isImage($file) && ($realFile = $file->getFile())) { $previewImageUrl = $urlManager->getUrlUfController('show', array('attachedId' => $attachedId, 'width' => 144, 'height' => 144, 'exact' => 'Y', 'signature' => \Bitrix\Disk\Security\ParameterSigner::getImageSignature($attachedId, 144, 144))); } else { $previewImageUrl = false; } $icon = CMobileHelper::mobileDiskGetIconByFilename($fileName); $iconUrl = CComponentEngine::makePathFromTemplate('/bitrix/components/bitrix/mobile.disk.file.detail/images/' . $icon); $fileFata = array('type' => $file->getExtension(), 'ufCode' => $ufCode, 'id' => $attachedId, 'extension' => $file->getExtension(), 'name' => $fileName, 'url' => $fileUrl, 'iconUrl' => $iconUrl); if ($previewImageUrl) { $fileFata['previewImageUrl'] = CHTTP::URN2URI($previewImageUrl); } $arFileData[] = $fileFata; } } } else { $data = CWebDavIblock::getRootSectionDataForUser($GLOBALS["USER"]->GetID()); if (is_array($data)) { $ibe = new CIBlockElement(); $dbWDFile = $ibe->GetList(array(), array('ID' => $arUF[$ufCode]["VALUE"], 'IBLOCK_ID' => $data["IBLOCK_ID"]), false, false, array('ID', 'IBLOCK_ID', 'PROPERTY_FILE')); while ($arWDFile = $dbWDFile->Fetch()) { if ($arFile = CFile::GetFileArray($arWDFile["PROPERTY_FILE_VALUE"])) { if (CFile::IsImage($arFile["FILE_NAME"], $arFile["CONTENT_TYPE"])) { $imageResized = CFile::ResizeImageGet($arFile["ID"], array("width" => 144, "height" => 144), BX_RESIZE_IMAGE_EXACT, false, true); $previewImageUrl = $imageResized["src"]; } else { $previewImageUrl = false; } $fileExtension = GetFileExtension($arFile["FILE_NAME"]); $fileData = array('type' => $fileExtension, 'ufCode' => $ufCode, 'id' => $arWDFile["ID"], 'extension' => $fileExtension, 'name' => $arFile["FILE_NAME"], 'url' => $arFile["SRC"]); if ($previewImageUrl) { $fileData['previewImageUrl'] = CHTTP::URN2URI($previewImageUrl); } $arFileData[] = $fileData; } } } } } else { $dbRes = CFile::GetList(array(), array("@ID" => implode(",", $arUF[$ufCode]["VALUE"]))); while ($arFile = $dbRes->GetNext()) { if (CFile::IsImage($arFile["FILE_NAME"], $arFile["CONTENT_TYPE"])) { $imageResized = CFile::ResizeImageGet($arFile["ID"], array("width" => 144, "height" => 144), BX_RESIZE_IMAGE_EXACT, false, true); $previewImageUrl = $imageResized["src"]; } else { $previewImageUrl = false; } $fileExtension = GetFileExtension($arFile["FILE_NAME"]); $fileData = array('type' => $fileExtension, 'ufCode' => $ufCode, 'id' => $arFile["ID"], 'extension' => $fileExtension, 'name' => $arFile["FILE_NAME"], 'downloadUrl' => $arFile["SRC"]); if ($previewImageUrl) { $fileData['previewImageUrl'] = CHTTP::URN2URI($previewImageUrl); } $arFileData[] = $fileData; } } } return $arFileData; }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } if (CModule::IncludeModule('disk')) { \Bitrix\Disk\Driver::getInstance()->getUserFieldManager()->showEdit($arParams, $arResult); }
/** * Duplicate task and return an instance of the clone. * * @param mixed[] $overrideTaskData Task data needs to be overrided externally. * @param mixed[] $parameters Various set of parameters. * * <li> CLONE_CHILD_TASKS boolean clone subtasks or not * <li> CLONE_CHECKLIST_ITEMS boolean clone check list items or not * <li> CLONE_TAGS boolean clone tags or not * <li> CLONE_REMINDERS boolean clone reminders or not * <li> CLONE_TASK_DEPENDENCY boolean clone previous tasks or not * <li> CLONE_FILES boolean clone files or not * * @throws TasksException - on access denied, task not found. * @throws CTaskAssertException. * @throws Exception - on unexpected error. * * @return CTaskItem[] */ public function duplicate($overrideTaskData = array(), $parameters = array('CLONE_CHILD_TASKS' => true, 'CLONE_CHECKLIST_ITEMS' => true, 'CLONE_TAGS' => true, 'CLONE_REMINDERS' => true, 'CLONE_TASK_DEPENDENCY' => true, 'CLONE_FILES' => true)) { if (!is_array($overrideTaskData)) { $overrideTaskData = array(); } if (!is_array($parameters)) { $parameters = array(); } if (!isset($parameters['CLONE_CHILD_TASKS'])) { $parameters['CLONE_CHILD_TASKS'] = true; } if (!isset($parameters['CLONE_CHECKLIST_ITEMS'])) { $parameters['CLONE_CHECKLIST_ITEMS'] = true; } if (!isset($parameters['CLONE_TAGS'])) { $parameters['CLONE_TAGS'] = true; } if (!isset($parameters['CLONE_REMINDERS'])) { $parameters['CLONE_REMINDERS'] = true; } if (!isset($parameters['CLONE_TASK_DEPENDENCY'])) { $parameters['CLONE_TASK_DEPENDENCY'] = true; } if (!isset($parameters['CLONE_FILES'])) { $parameters['CLONE_FILES'] = true; } $result = array(); $data = $this->getData(false); // ensure we have access to the task if (is_array($data)) { $data = array_merge($data, $overrideTaskData); // drop unwanted unset($data['ID']); unset($data['GUID']); unset($data['STATUS']); // detach forum, if any unset($data['FORUM_TOPIC_ID']); unset($data['COMMENTS_COUNT']); // clean dates unset($data['CREATED_DATE']); unset($data['CHANGED_DATE']); unset($data['VIEWED_DATE']); unset($data['STATUS_CHANGED_DATE']); unset($data['CHANGED_BY']); $files = array(); if (is_array($data['UF_TASK_WEBDAV_FILES']) && !empty($data['UF_TASK_WEBDAV_FILES'])) { $files = $data['UF_TASK_WEBDAV_FILES']; } unset($data['UF_TASK_WEBDAV_FILES']); $clone = static::add($data, $this->getExecutiveUserId()); $taskDupId = $clone->getId(); if (intval($taskDupId)) { $result[$clone->getId()] = $clone; if ($parameters['CLONE_CHECKLIST_ITEMS']) { list($arChecklistItems, $arMetaData) = CTaskCheckListItem::fetchList($this, array('SORT_INDEX' => 'ASC')); unset($arMetaData); foreach ($arChecklistItems as $oChecklistItem) { $cliData = $oChecklistItem->getData(); $cliCloneData = array('TITLE' => $cliData['TITLE'], 'IS_COMPLETE' => $cliData['IS_COMPLETE'], 'SORT_INDEX' => $cliData['SORT_INDEX']); CTaskCheckListItem::add($clone, $cliCloneData); } } if ($parameters['CLONE_TAGS']) { $tags = $this->getTags(); if (is_array($tags)) { foreach ($tags as $tag) { if ((string) $tag != '') { $oTag = new CTaskTags(); $oTag->Add(array('TASK_ID' => $taskDupId, 'NAME' => $tag), $this->getExecutiveUserId()); } } } } if ($parameters['CLONE_REMINDERS']) { $res = CTaskReminders::GetList(false, array('TASK_ID' => $this->getId())); while ($item = $res->fetch()) { $item['TASK_ID'] = $taskDupId; $item['USER_ID'] = $this->getExecutiveUserId(); $oReminder = new CTaskReminders(); $oReminder->Add($item); } } if ($parameters['CLONE_TASK_DEPENDENCY']) { $res = CTaskDependence::GetList(array(), array('TASK_ID' => $this->getId())); while ($item = $res->fetch()) { $depInstance = new CTaskDependence(); if (is_array($item)) { $depInstance->Add(array('TASK_ID' => $taskDupId, 'DEPENDS_ON_ID' => $item['DEPENDS_ON_ID'])); } } } if ($parameters['CLONE_FILES'] && !empty($files) && \Bitrix\Main\Loader::includeModule('disk')) { // find which files are new and which are old $old = array(); $new = array(); foreach ($files as $fileId) { if ((string) $fileId) { if (strpos($fileId, 'n') === 0) { $new[] = $fileId; } else { $old[] = $fileId; } } } if (!empty($old)) { $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager(); $old = $userFieldManager->cloneUfValuesFromAttachedObject($old, $this->getExecutiveUserId()); if (is_array($old) && !empty($old)) { $new = array_merge($new, $old); } } if (!empty($new)) { $clone->update(array('UF_TASK_WEBDAV_FILES' => $new)); } } if ($parameters['CLONE_CHILD_TASKS']) { $notifADWasDisabled = CTaskNotifications::disableAutoDeliver(); $clones = $this->duplicateChildTasks($clone); if (is_array($clones)) { foreach ($clones as $cId => $cInst) { $result[$cId] = $cInst; } } if ($notifADWasDisabled) { CTaskNotifications::enableAutoDeliver(); } } } } return $result; }
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } use Bitrix\Main\Localization\Loc; /** @var array $arParams */ /** @var array $arResult */ /** @global CMain $APPLICATION */ /** @global CUser $USER */ /** @global CDatabase $DB */ /** @var CBitrixComponentTemplate $this */ /** @var string $templateName */ /** @var string $templateFile */ /** @var string $templateFolder */ /** @var string $componentPath */ /** @var \Bitrix\Disk\Internals\BaseComponent $component */ $storage = \Bitrix\Disk\Driver::getInstance()->getStorageByGroupId($arResult['VARIABLES']['group_id']); $arResult['VARIABLES']['STORAGE'] = $storage; $arResult["PATH_TO_DISK_BIZPROC_WORKFLOW_EDIT"] = CComponentEngine::MakePathFromTemplate($arResult['PATH_TO_GROUP_DISK_BIZPROC_WORKFLOW_EDIT'], array('group_id' => $arResult['VARIABLES']['group_id'])); $arResult["PATH_TO_FOLDER_LIST"] = CComponentEngine::MakePathFromTemplate($arResult['PATH_TO_GROUP_DISK'], array('group_id' => $arResult['VARIABLES']['group_id'])); $arResult["PATH_TO_DISK_BIZPROC_WORKFLOW_EDIT_TOOLBAR"] = CComponentEngine::MakePathFromTemplate($arResult["PATH_TO_DISK_BIZPROC_WORKFLOW_EDIT"], array("ID" => 0)); $arButtons = array(); $arButtons[] = array("TEXT" => Loc::getMessage("DISK_BIZPROC_BACK_TEXT"), "TITLE" => Loc::getMessage("DISK_BIZPROC_BACK_TITLE"), "LINK" => CComponentEngine::MakePathFromTemplate($arResult["PATH_TO_FOLDER_LIST"], array("PATH" => "")), "ICON" => "back"); $arButtons[] = array("TEXT" => Loc::getMessage("DISK_BIZPROC_STATUS_TEXT"), "TITLE" => Loc::getMessage("DISK_BIZPROC_STATUS_TITLE"), "LINK" => $arResult["PATH_TO_DISK_BIZPROC_WORKFLOW_EDIT_TOOLBAR"] . (strpos($arResult["PATH_TO_DISK_BIZPROC_WORKFLOW_EDIT"], "?") === false ? "?" : "&") . "init=statemachine", "ICON" => "copy-link"); $arButtons[] = array("TEXT" => Loc::getMessage("DISK_BIZPROC_SERIAL_TEXT"), "TITLE" => Loc::getMessage("DISK_BIZPROC_SERIAL_TITLE"), "LINK" => $arResult["PATH_TO_DISK_BIZPROC_WORKFLOW_EDIT_TOOLBAR"] . (strpos($arResult["PATH_TO_DISK_BIZPROC_WORKFLOW_EDIT"], "?") === false ? "?" : ""), "ICON" => "copy-link"); $APPLICATION->includeComponent('bitrix:disk.interface.toolbar', '', array('TOOLBAR_ID' => 'bp_toolbar', 'CLASS_NAME' => 'bx-filepage', 'BUTTONS' => $arButtons), $component, array('HIDE_ICONS' => 'Y')); ?> <div class="bx-disk-bizproc-section"> <?php $APPLICATION->IncludeComponent("bitrix:disk.bizproc.list", ".default", array("MODULE_ID" => \Bitrix\Disk\Driver::INTERNAL_MODULE_ID, "STORAGE_ID" => $arResult["VARIABLES"]["STORAGE"]->getId(), "EDIT_URL" => $arResult["PATH_TO_DISK_BIZPROC_WORKFLOW_EDIT"], "SET_TITLE" => "Y", "NAME_TEMPLATE" => $arParams["NAME_TEMPLATE"]), $component, array("HIDE_ICONS" => "Y")); ?> </div>
/** * Checks read permissions by user for group. * Uses denormalized rights (b_disk_simple_right). * * Be careful^ this is internal method. * @param mixed $user User. * @param int $groupId Id of group. * @internal * @return bool */ public static function canRead($user, $groupId) { $entityType = static::className(); $groupStorage = Storage::buildFromArray(array('ENTITY_ID' => $groupId, 'ENTITY_TYPE' => $entityType)); $proxyType = new static($groupId, $groupStorage); $parameters = array('filter' => array('ENTITY_ID' => (int) $groupId, 'ENTITY_TYPE' => $entityType, 'MODULE_ID' => Driver::INTERNAL_MODULE_ID, 'USE_INTERNAL_RIGHTS' => 1)); $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($proxyType->getSecurityContextByUser($user), $parameters, array('ROOT_OBJECT_ID', 'USE_INTERNAL_RIGHTS')); return (bool) Storage::getList($parameters)->fetch(); }