Example #1
0
 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;
 }
Example #2
0
 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;
 }
Example #3
0
 public static function getEditFormHTML($userField, $htmlControl)
 {
     $html = '';
     $values = $userField['VALUE'];
     if (!is_array($values)) {
         $values = array($userField['VALUE']);
     }
     $urlManager = Driver::getInstance()->getUrlManager();
     foreach ($values as $value) {
         if (!$value) {
             continue;
         }
         list($type, $realValue) = self::detectType($value);
         if ($type == self::TYPE_ALREADY_ATTACHED) {
             $attachedObject = AttachedObject::loadById($realValue, array('OBJECT'));
             $name = htmlspecialcharsbx($attachedObject->getObject()->getName());
             $size = \CFile::formatSize($attachedObject->getObject()->getSize());
             $html .= '<br/><a href="' . $urlManager->getUrlUfController('download', array('attachedId' => $realValue)) . '">' . $name . ' (' . $size . ')</a>';
         }
     }
     return $html;
 }
Example #4
0
 /**
  * Lists folder contents
  * @param $path
  * @param $folderId
  * @return mixed
  */
 public function listFolder($path, $folderId)
 {
     if ($path === '/') {
         $folderId = 'root';
     }
     $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
     $http->setHeader('Content-Type', 'application/json; charset=UTF-8');
     $http->setHeader('Authorization', "Bearer {$this->getAccessToken()}");
     if ($http->get(self::API_URL_V2 . "/files?q='{$folderId}'+in+parents") === false) {
         $errorString = implode('; ', array_keys($http->getError()));
         $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_LIST_FOLDER)));
         return null;
     }
     if (!$this->checkHttpResponse($http)) {
         return null;
     }
     $items = Json::decode($http->getResult());
     if ($items === null) {
         $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON)));
         return null;
     }
     if (!isset($items['items'])) {
         $this->errorCollection->add(array(new Error('Could not find items in response', self::ERROR_HTTP_LIST_FOLDER)));
         return null;
     }
     $reformatItems = array();
     foreach ($items['items'] as $item) {
         $isFolder = $item['mimeType'] === 'application/vnd.google-apps.folder';
         $dateTime = new \DateTime($item['modifiedDate']);
         $reformatItems[$item['id']] = array('id' => $item['id'], 'name' => $item['title'], 'type' => $isFolder ? 'folder' : 'file', 'size' => $isFolder ? '' : \CFile::formatSize($item['fileSize']), 'sizeInt' => $isFolder ? '' : $item['fileSize'], 'modifyBy' => '', 'modifyDate' => $dateTime->format('d.m.Y'), 'modifyDateInt' => $dateTime->getTimestamp(), 'provider' => static::getCode());
         if (!$isFolder && empty($item['fileSize'])) {
             //Google.Drive doesn't show size of google documents. We should export docs
             $reformatItems[$item['id']]['size'] = $reformatItems[$item['id']]['sizeInt'] = '';
         }
         if (!$isFolder) {
             $reformatItems[$item['id']]['ext'] = getFileExtension($item['title']);
         }
     }
     unset($item);
     return $reformatItems;
 }
Example #5
0
    private function getGridData($gridId, $showDeleted = false)
    {
        $grid = array('ID' => $gridId);
        $gridOptions = new CGridOptions($grid['ID']);
        $gridSort = $gridOptions->getSorting(array('sort' => array('NAME' => 'ASC'), 'vars' => array('by' => 'by', 'order' => 'order')));
        $filter = array();
        $grid['SORT'] = $gridSort['sort'];
        $grid['SORT_VARS'] = $gridSort['vars'];
        $grid['MODE'] = $this->getViewMode();
        $possibleColumnForSorting = array('UPDATE_TIME' => array('ALIAS' => 'UPDATE_TIME', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_UPDATE_TIME')), 'NAME' => array('ALIAS' => 'NAME', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_NAME')), 'FORMATTED_SIZE' => array('ALIAS' => 'SIZE', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_FORMATTED_SIZE')));
        $byColumn = key($grid['SORT']);
        if (!isset($possibleColumnForSorting[$byColumn]) || strtolower($grid['SORT'][$byColumn]) !== 'desc' && strtolower($grid['SORT'][$byColumn]) !== 'asc') {
            $grid['SORT'] = array();
        }
        $order = $grid['SORT'];
        $byColumn = key($order);
        $sortingColumns = array('TYPE' => array(SORT_NUMERIC, SORT_ASC), $possibleColumnForSorting[$byColumn]['ALIAS'] => strtolower($order[$byColumn]) === 'asc' ? SORT_ASC : SORT_DESC);
        if ($byColumn !== 'NAME') {
            $sortingColumns[$possibleColumnForSorting['NAME']['ALIAS']] = SORT_ASC;
        }
        $securityContext = $this->storage->getCurrentUserSecurityContext();
        $proxyType = $this->storage->getProxyType();
        $isStorageCurrentUser = $proxyType instanceof ProxyType\User && $proxyType->getTitleForCurrentUser() != $proxyType->getTitle();
        $parameters = array('with' => array('CREATE_USER'), 'filter' => array('PARENT_ID' => $this->folder->getRealObjectId(), 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE));
        $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY'));
        $needPagination = $this->needPagination();
        $pageNumber = (int) $this->request->getQuery('pageNumber');
        if ($pageNumber <= 0) {
            $pageNumber = 1;
        }
        if ($needPagination) {
            $parameters['order'] = array();
            foreach ($sortingColumns as $columnName => $columnData) {
                if (is_array($columnData)) {
                    $parameters['order'][$columnName] = in_array(SORT_DESC, $columnData, true) ? 'DESC' : 'ASC';
                } else {
                    $parameters['order'][$columnName] = SORT_DESC === $columnData ? 'DESC' : 'ASC';
                }
            }
            unset($columnName, $columnData);
            $parameters['limit'] = self::COUNT_ON_PAGE + 1;
            // +1 because we want to know about existence next page
            $parameters['offset'] = self::COUNT_ON_PAGE * ($pageNumber - 1);
        }
        $this->folder->preloadOperationsForChildren($securityContext);
        $sharedObjectIds = $this->getUserShareObjectIds();
        $isDesktopDiskInstall = \Bitrix\Disk\Desktop::isDesktopDiskInstall();
        $nowTime = time() + CTimeZone::getOffset();
        $fullFormatWithoutSec = preg_replace('/:s$/', '', CAllDatabase::dateFormatToPHP(CSite::GetDateFormat("FULL")));
        $urlManager = Driver::getInstance()->getUrlManager();
        $rows = array();
        $storageTitle = $proxyType->getTitle();
        $isEnabledShowExtendedRights = $this->storage->isEnabledShowExtendedRights();
        $result = $this->folder->getList($parameters);
        $countObjectsOnPage = 0;
        $needShowNextPagePagination = false;
        while ($row = $result->fetch()) {
            $countObjectsOnPage++;
            if ($needPagination && $countObjectsOnPage > self::COUNT_ON_PAGE) {
                $needShowNextPagePagination = true;
                break;
            }
            $object = BaseObject::buildFromArray($row);
            /** @var File|Folder $object */
            $name = $object->getName();
            $objectId = $object->getId();
            $exportData = array('TYPE' => $object->getType(), 'NAME' => $name, 'ID' => $objectId);
            $relativePath = trim($this->arParams['RELATIVE_PATH'], '/');
            $detailPageFile = CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_FILE_VIEW'], array('FILE_ID' => $objectId, 'FILE_PATH' => ltrim($relativePath . '/' . $name, '/')));
            $listingPage = rtrim(CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_FOLDER_LIST'], array('PATH' => $relativePath)), '/');
            $isFolder = $object instanceof Folder;
            $actions = $tileActions = $columns = array();
            if ($object->canRead($securityContext)) {
                $exportData['OPEN_URL'] = $urlManager->encodeUrn($isFolder ? $listingPage . '/' . $name . '/' : $detailPageFile);
                $actions[] = array("PSEUDO_NAME" => "open", "DEFAULT" => true, "ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_OPEN'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "')");
                if (!$object->canChangeRights($securityContext) && !$object->canShare($securityContext)) {
                    $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk.showSharingDetailWithoutEdit({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})");
                } elseif ($object->canChangeRights($securityContext)) {
                    $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showSharingDetailWithChangeRights({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})");
                } elseif ($object->canShare($securityContext)) {
                    $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showSharingDetailWithSharing({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})");
                }
                if ($isEnabledShowExtendedRights && !$object->isLink() && $object->canChangeRights($securityContext)) {
                    $actions[] = array("PSEUDO_NAME" => "rights", "ICONCLASS" => "rights", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_RIGHTS_SETTINGS'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showRightsOnObjectDetail({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})");
                }
                if (!$isFolder) {
                    $actions[] = array("PSEUDO_NAME" => "download", "ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_DOWNLOAD'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadFile($object) . "')");
                }
                $actions[] = array("PSEUDO_NAME" => "copy", "ICONCLASS" => "copy", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_COPY'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openCopyModalWindow({\n\t\t\t\t\t\tid: {$this->storage->getRootObjectId()},\n\t\t\t\t\t\tname: '" . CUtil::JSEscape($storageTitle) . "'\n\t\t\t\t\t}, {\n\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "'\n\t\t\t\t\t});");
                if ($object->canDelete($securityContext)) {
                    $actions[] = array("PSEUDO_NAME" => "move", "ICONCLASS" => "move", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_MOVE'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openMoveModalWindow({\n\t\t\t\t\t\t\tid: {$this->storage->getRootObjectId()},\n\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($storageTitle) . "'\n\t\t\t\t\t\t}, {\n\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "'\n\t\t\t\t\t\t});");
                }
                if (!$isStorageCurrentUser && (!isset($sharedObjectIds[$object->getRealObjectId()]) || $sharedObjectIds[$object->getRealObjectId()]['TO_ENTITY'] != Sharing::CODE_USER . $this->getUser()->getId())) {
                    $actions[] = array("PSEUDO_NAME" => "connect", "ICONCLASS" => "connect", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_CONNECT'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].connectObjectToDisk({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "',\n\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});");
                }
                if (!$isFolder) {
                    $actions[] = array("ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_GET_EXT_LINK'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].getExternalLink({$objectId});");
                    $downloadLink = $urlManager->getUrlForShowFile($object, array(), true);
                    $actions[] = array("ICONCLASS" => "show", 'PSEUDO_NAME' => 'internal_link', 'PSEUDO_VALUE' => $downloadLink, "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_COPY_INTERNAL_LINK'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].getInternalLink('{$downloadLink}');");
                    $actions[] = array("ICONCLASS" => "history", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_HISTORY'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "#tab-history')");
                }
            }
            if ($object->canRename($securityContext)) {
                $actions[] = array("TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_RENAME'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].renameInline({$objectId})");
            }
            if ((!empty($sharedObjectIds[$objectId]) || $object->isLink()) && $object->canRead($securityContext)) {
                $tileActions['SHARE_INFO'] = array("ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_DETAIL_SHARE_INFO'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showShareInfoSmallView({\n\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t }\n\t\t\t\t\t})");
            }
            $columnsBizProc = array('BIZPROC' => '');
            $bizprocIcon = array('BIZPROC' => '');
            if ($this->arParams['STATUS_BIZPROC'] && !$isFolder) {
                list($actions, $columnsBizProc, $bizprocIcon) = $this->getBizProcData($object, $securityContext, $actions, $columnsBizProc, $bizprocIcon, $exportData);
            }
            if ($object->canDelete($securityContext)) {
                if ($object->isLink()) {
                    $actions[] = array("PSEUDO_NAME" => "detach", "ICONCLASS" => "detach", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_DETACH_BUTTON'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openConfirmDetach({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})");
                } elseif ($object->getCode() !== Folder::CODE_FOR_UPLOADED_FILES) {
                    $actions[] = array("PSEUDO_NAME" => "delete", "ICONCLASS" => "delete", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_MARK_DELETED'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openConfirmDelete({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t },\n\t\t\t\t\t\t\t\tcanDelete: {$object->canDelete($securityContext)}\n\t\t\t\t\t\t\t})");
                }
            }
            $iconClass = Ui\Icon::getIconClassByObject($object, !empty($sharedObjectIds[$objectId]));
            $dataAttributesForViewer = '';
            if ($isFolder) {
                $dataAttributesForViewer = Ui\Viewer::getAttributesByObject($object);
                if ($grid['MODE'] === 'tile') {
                    $exportData['VIEWER_ATTRS'] = $dataAttributesForViewer;
                    $dataAttributesForViewer = '';
                }
                $nameSpecialChars = htmlspecialcharsbx($name);
                $columnName = "\n\t\t\t\t\t<table class=\"bx-disk-object-name\"><tr>\n\t\t\t\t\t\t\t<td style=\"width: 45px;\"><div data-object-id=\"{$objectId}\" class=\"draggable bx-file-icon-container-small {$iconClass}\"></div></td>\n\t\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$objectId}\" href=\"{$exportData['OPEN_URL']}\" {$dataAttributesForViewer}>{$nameSpecialChars}</a></td>\n\t\t\t\t\t</tr></table>\n\t\t\t\t";
            } else {
                $externalId = '';
                if ($isDesktopDiskInstall && $isStorageCurrentUser) {
                    $externalId = "st{$this->storage->getId()}|{$this->storage->getRootObjectId()}|f{$objectId}";
                }
                $dataAttributesForViewer = Ui\Viewer::getAttributesByObject($object, array('canUpdate' => $object->canUpdate($securityContext), 'relativePath' => $relativePath . '/' . $name, 'externalId' => $externalId));
                if ($grid['MODE'] === 'tile') {
                    $exportData['VIEWER_ATTRS'] = $dataAttributesForViewer;
                    $dataAttributesForViewer = '';
                }
                $nameSpecialChars = htmlspecialcharsbx($name);
                $columnName = "\n\t\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=\"{$objectId}\" class=\"draggable bx-file-icon-container-small {$iconClass}\"></div></td>\n\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$objectId}\" href=\"{$exportData['OPEN_URL']}\" {$dataAttributesForViewer}>{$nameSpecialChars}</a></td>\n\t\t\t\t\t\t<td>{$bizprocIcon['BIZPROC']}</td>\n\t\t\t\t\t</tr></table>\n\t\t\t\t";
            }
            $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getCreatedBy()));
            $timestampCreate = $object->getCreateTime()->toUserTime()->getTimestamp();
            $timestampUpdate = $object->getUpdateTime()->toUserTime()->getTimestamp();
            $columns = array('CREATE_TIME' => $nowTime - $timestampCreate > 158400 ? formatDate($fullFormatWithoutSec, $timestampCreate, $nowTime) : formatDate('x', $timestampCreate, $nowTime), 'UPDATE_TIME' => $nowTime - $timestampCreate > 158400 ? formatDate($fullFormatWithoutSec, $timestampUpdate, $nowTime) : formatDate('x', $timestampUpdate, $nowTime), 'NAME' => $columnName, 'FORMATTED_SIZE' => $isFolder ? '' : CFile::formatSize($object->getSize()), 'CREATE_USER' => "\n\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($object->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t");
            if ($this->arParams['STATUS_BIZPROC']) {
                $columns['BIZPROC'] = $columnsBizProc["BIZPROC"];
            }
            $exportData['ICON_CLASS'] = $iconClass;
            if ($grid['MODE'] === 'tile') {
                $exportData['IS_IMAGE'] = $isFolder ? false : \Bitrix\Disk\TypeFile::isImage($object);
                if ($exportData['IS_IMAGE']) {
                    $exportData['SRC_IMAGE'] = $urlManager->getUrlForShowFile($object, array('exact' => 'Y', 'width' => 64, 'height' => 64));
                }
                $exportData['UPDATE_TIME'] = $columns['UPDATE_TIME'];
            }
            $exportData['IS_SHARED'] = !empty($sharedObjectIds[$objectId]);
            $exportData['IS_LINK'] = $object->isLink();
            $tildaExportData = array();
            foreach ($exportData as $exportName => $exportValue) {
                $tildaExportData['~' . $exportName] = $exportValue;
            }
            unset($exportRow);
            $rows[] = array('data' => array_merge($exportData, $tildaExportData), 'columns' => $columns, 'actions' => $actions, 'tileActions' => $tileActions, 'TYPE' => $exportData['TYPE'], 'NAME' => $exportData['NAME'], 'UPDATE_TIME' => $object->getUpdateTime()->getTimestamp(), 'SIZE' => $isFolder ? 0 : $object->getSize());
        }
        unset($object);
        if (!$needPagination) {
            Collection::sortByColumn($rows, $sortingColumns);
        }
        $grid['HEADERS'] = array(array('id' => 'ID', 'name' => 'ID', 'sort' => isset($possibleColumnForSorting['ID']) ? 'ID' : false, 'default' => false), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_NAME'), 'sort' => isset($possibleColumnForSorting['NAME']) ? 'NAME' : false, 'default' => true, 'editable' => array('size' => 45)), array('id' => 'CREATE_TIME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_CREATE_TIME'), 'sort' => isset($possibleColumnForSorting['CREATE_TIME']) ? 'CREATE_TIME' : false, 'default' => false), array('id' => 'UPDATE_TIME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_UPDATE_TIME'), 'sort' => isset($possibleColumnForSorting['UPDATE_TIME']) ? 'UPDATE_TIME' : false, 'default' => true), array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_CREATE_USER'), 'sort' => isset($possibleColumnForSorting['CREATE_USER']) ? 'CREATE_USER' : false, 'default' => false), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_FORMATTED_SIZE'), 'sort' => isset($possibleColumnForSorting['FORMATTED_SIZE']) ? 'FORMATTED_SIZE' : false, 'default' => true));
        if ($this->arParams['STATUS_BIZPROC']) {
            $grid['HEADERS'][] = array('id' => 'BIZPROC', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_BIZPROC'), 'default' => false);
        }
        $grid['DATA_FOR_PAGINATION'] = array('ENABLED' => $needPagination);
        if ($needPagination) {
            $grid['DATA_FOR_PAGINATION']['SHOW_NEXT_PAGE'] = $needShowNextPagePagination;
            $grid['DATA_FOR_PAGINATION']['CURRENT_PAGE'] = $pageNumber;
        }
        $grid['COLUMN_FOR_SORTING'] = $possibleColumnForSorting;
        $grid['ROWS'] = $rows;
        $grid['ROWS_COUNT'] = count($rows);
        $grid['FOOTER'] = array();
        if (isModuleInstalled('bitrix24')) {
            list($freeSpace, $diskSize) = $this->getDiskSpace();
            $freeSpace = CFile::formatSize($freeSpace);
            $diskSize = CFile::formatSize($diskSize);
            $grid['FOOTER'] = array(array('custom_html' => '
						<td class="tar" style="width: 100%;">' . Loc::getMessage('DISK_FOLDER_LIST_B24_LABEL_DISK_SPACE', array('#FREE_SPACE#' => '<span>' . $freeSpace, '#DISK_SIZE#' => $diskSize . '</span>')) . '</span></td>
					'), array('custom_html' => '
						<td class="tar"><a class="bx-disk-mp-link-addhdd" href="' . Loc::getMessage('DISK_FOLDER_LIST_B24_URL_DISK_SPACE') . '" target="_blank">+ <span>' . Loc::getMessage('DISK_FOLDER_LIST_B24_APPEND_DISK_SPACE') . '</span></a></td>
					'));
        }
        return $grid;
    }
Example #6
0
 private function loadFilesData()
 {
     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);
     }
     $files = array();
     $driver = \Bitrix\Disk\Driver::getInstance();
     $urlManager = $driver->getUrlManager();
     $userFieldManager = $driver->getUserFieldManager();
     $userFieldManager->loadBatchAttachedObject($values);
     foreach ($values as $id) {
         $attachedModel = null;
         list($type, $realValue) = FileUserType::detectType($id);
         if ($realValue <= 0) {
             continue;
         } elseif ($type == FileUserType::TYPE_NEW_OBJECT) {
             /** @var File $fileModel */
             $fileModel = File::loadById($realValue);
             if (!$fileModel || !$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext())) {
                 continue;
             }
         } else {
             /** @var \Bitrix\Disk\AttachedObject $attachedModel */
             $attachedModel = $userFieldManager->getAttachedObjectById($realValue);
             if (!$attachedModel) {
                 continue;
             }
             if (!$this->editMode) {
                 $attachedModel->setOperableEntity(array('ENTITY_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_ID'], 'ENTITY_VALUE_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_VALUE_ID']));
             }
             /** @var File $fileModel */
             $fileModel = $attachedModel->getFile();
         }
         $name = $fileModel->getName();
         $data = array('ID' => $id, 'NAME' => $name, 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($fileModel->getExtension()), 'EDITABLE' => DocumentHandler::isEditable($fileModel->getExtension()), 'CAN_UPDATE' => $attachedModel ? $attachedModel->canUpdate($userId) : $fileModel->canUpdate($fileModel->getStorage()->getCurrentUserSecurityContext()), 'FROM_EXTERNAL_SYSTEM' => $fileModel->getContentProvider() && $fileModel->getCreatedBy() == $userId, 'EXTENSION' => $fileModel->getExtension(), 'SIZE' => \CFile::formatSize($fileModel->getSize()), 'XML_ID' => $fileModel->getXmlId(), 'FILE_ID' => $fileModel->getId(), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($id, 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($id, 'gdrive'), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $id)), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyToMe', array('attachedId' => $id)), 'DELETE_URL' => "");
         if (\Bitrix\Disk\TypeFile::isImage($fileModel)) {
             $this->arParams['PARAMS']['THUMB_SIZE'] = $this->arParams['PARAMS']['THUMB_SIZE'] > 0 ? $this->arParams['PARAMS']['THUMB_SIZE'] : 100;
             $data["PREVIEW_URL"] = $attachedModel === null ? $urlManager->getUrlForShowFile($fileModel) : $urlManager->getUrlUfController('show', array('attachedId' => $id));
             $data["IMAGE"] = $fileModel->getFile();
         }
         if ($this->editMode) {
             $data['STORAGE'] = $fileModel->getStorage()->getProxyType()->getTitleForCurrentUser() . ' / ' . $fileModel->getParent()->getName();
         } else {
             $data['ATTRIBUTES_FOR_VIEWER'] = Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('canUpdate' => $data['CAN_UPDATE'], 'canFakeUpdate' => true, 'showStorage' => false, 'externalId' => false, 'relativePath' => false));
         }
         $files[] = $data;
     }
     unset($id);
     return $files;
 }
Example #7
0
 /**
  * Lists folder contents
  * @param $path
  * @param $folderId
  * @return mixed
  */
 public function listFolder($path, $folderId)
 {
     if ($path === '/') {
         $folderId = '';
     } else {
         $folderId = $this->getForApiDecodedId($folderId);
     }
     $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
     $http->setHeader('Content-Type', 'application/json; charset=UTF-8');
     $http->setHeader('Authorization', "Bearer {$this->getAccessToken()}");
     if ($http->get(self::API_URL . "/metadata/auto/{$folderId}") === false) {
         $errorString = implode('; ', array_keys($http->getError()));
         $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_LIST_FOLDER)));
         return null;
     }
     if (!$this->checkHttpResponse($http)) {
         return null;
     }
     $items = Json::decode($http->getResult());
     if ($items === null) {
         $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON)));
         return null;
     }
     if (!isset($items['contents'])) {
         $this->errorCollection->add(array(new Error('Could not find items in response', self::ERROR_HTTP_LIST_FOLDER)));
         return null;
     }
     $reformatItems = array();
     foreach ($items['contents'] as $item) {
         $isFolder = (bool) $item['is_dir'];
         $dateTime = \DateTime::createFromFormat('D, d M Y H:i:s T', $item['modified']);
         $pseudoId = base64_encode($item['path']);
         $reformatItems[$pseudoId] = array('id' => $pseudoId, 'name' => bx_basename($item['path']), 'type' => $isFolder ? 'folder' : 'file', 'size' => $isFolder ? '' : \CFile::formatSize($item['bytes']), 'sizeInt' => $isFolder ? '' : $item['bytes'], 'modifyBy' => '', 'modifyDate' => $dateTime->format('d.m.Y'), 'modifyDateInt' => $dateTime->getTimestamp(), 'provider' => static::getCode());
         if (!$isFolder) {
             $reformatItems[$pseudoId]['storage'] = '';
             $reformatItems[$pseudoId]['ext'] = getFileExtension($reformatItems[$pseudoId]['name']);
         }
     }
     unset($item);
     return $reformatItems;
 }
 public function getFileListByUser($user, array $filter = array())
 {
     $items = array();
     $urlManager = Driver::getInstance()->getUrlManager();
     foreach ($this->getFileModelListByUser($user, $filter) as $file) {
         $id = FileUserType::NEW_FILE_PREFIX . $file->getId();
         $items[$id] = array('id' => $id, 'name' => $file->getName(), 'type' => 'file', 'size' => \CFile::formatSize($file->getSize()), 'sizeInt' => $file->getSize(), 'modifyBy' => $file->getUpdateUser()->getFormattedName(), 'modifyDate' => $file->getUpdateTime()->format('d.m.Y'), 'modifyDateInt' => $file->getUpdateTime()->getTimestamp(), 'ext' => $file->getExtension());
         if (TypeFile::isImage($file)) {
             $items[$id]['previewUrl'] = $urlManager->getUrlForShowFile($file);
         }
     }
     unset($file);
     return $items;
 }
Example #9
0
 private function getGridData($gridId)
 {
     $grid = array('ID' => $gridId);
     $filter = array();
     $securityContext = $this->storage->getCurrentUserSecurityContext();
     //shown trash can root
     if ($this->arParams['RELATIVE_PATH'] == '/') {
         $filter['DELETED_TYPE'] = ObjectTable::DELETED_TYPE_ROOT;
         $items = $this->folder->getDescendants($securityContext, array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => $filter));
     } else {
         $filter['DELETED_TYPE'] = ObjectTable::DELETED_TYPE_CHILD;
         $items = $this->folder->getChildren($securityContext, array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => $filter));
     }
     if (count($items)) {
         $this->folder->preloadOperationsForChildren($securityContext);
     }
     $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
     $rows = array();
     foreach ($items as $object) {
         /** @var File|Folder $object */
         $exportData = $object->toArray();
         $relativePath = trim($this->arParams['RELATIVE_PATH'], '/');
         $detailPageFile = CComponentEngine::MakePathFromTemplate($this->arParams['PATH_TO_TRASHCAN_FILE_VIEW'], array('FILE_ID' => $object->getId(), 'TRASH_FILE_PATH' => ltrim($relativePath . '/' . $object->getOriginalName(), '/')));
         $listingPage = rtrim(CComponentEngine::MakePathFromTemplate($this->arParams['PATH_TO_TRASHCAN_LIST'], array('TRASH_PATH' => $relativePath)), '/');
         $isFolder = $object instanceof Folder;
         $actions = array();
         $exportData['OPEN_URL'] = $urlManager->encodeUrn($isFolder ? $listingPage . '/' . $object->getOriginalName() : $detailPageFile);
         $actions[] = array("PSEUDO_NAME" => "open", "ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_OPEN'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "')");
         if (!$isFolder) {
             $actions[] = array("PSEUDO_NAME" => "download", "ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_DOWNLOAD'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadFile($object) . "')");
         }
         if ($object->isDeleted() && $object->canRestore($securityContext)) {
             $actions[] = array("ICONCLASS" => "restore", "PSEUDO_NAME" => "restore", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_RESTORE'), "ONCLICK" => "BX.Disk['TrashCanClass_{$this->getComponentId()}'].openConfirmRestore({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$object->getId()},\n\t\t\t\t\t\t\t\tname: '{$object->getName()}',\n\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t})");
         }
         if ($object->canDelete($securityContext)) {
             $actions[] = array("ICONCLASS" => "destroy", "PSEUDO_NAME" => "destroy", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_DESTROY'), "ONCLICK" => "BX.Disk['TrashCanClass_{$this->getComponentId()}'].openConfirmDelete({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$object->getId()},\n\t\t\t\t\t\t\t\tname: '{$object->getName()}',\n\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t})");
         }
         if ($isFolder) {
             $uri = $urlManager->encodeUrn($listingPage . '/' . $object->getOriginalName());
         } else {
             $uri = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->encodeUrn($detailPageFile);
         }
         $iconClass = \Bitrix\Disk\Ui\Icon::getIconClassByObject($object);
         $name = htmlspecialcharsbx($object->getName());
         $updateDateTime = $object->getUpdateTime();
         $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=\"{$object->getId()}\" class=\"bx-file-icon-container-small {$iconClass}\"></div></td>\n\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$object->getId()}\" href=\"{$uri}\" data-bx-dateModify=\"" . htmlspecialcharsbx($updateDateTime) . "\">{$name}</a></td>\n\t\t\t\t</tr></table>\n\t\t\t";
         $deletedTime = $object->getDeleteTime();
         $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getCreatedBy()));
         $deletedByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getDeletedBy()));
         $columns = array('CREATE_TIME' => formatDate('x', $object->getCreateTime()->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'UPDATE_TIME' => formatDate('x', $updateDateTime->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'DELETE_TIME' => formatDate('x', $deletedTime->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'NAME' => $columnName, 'FORMATTED_SIZE' => $isFolder ? '' : CFile::formatSize($object->getSize()), 'CREATE_USER' => "\n\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($object->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t", 'DELETE_USER' => "\n\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$deletedByLink}\" id=\"\">" . htmlspecialcharsbx($object->getDeleteUser()->getFormattedName()) . "</a></div>\n\t\t\t\t");
         $exportData['ICON_CLASS'] = $iconClass;
         $exportData['IS_SHARED'] = false;
         $exportData['IS_LINK'] = false;
         $tildaExportData = array();
         foreach ($exportData as $exportName => $exportValue) {
             $tildaExportData['~' . $exportName] = $exportValue;
         }
         unset($exportRow);
         $rows[] = array('data' => array_merge($exportData, $tildaExportData), 'columns' => $columns, 'actions' => $actions, 'DELETE_TIME' => $deletedTime->getTimestamp());
     }
     unset($object);
     Collection::sortByColumn($rows, array('DELETE_TIME' => SORT_DESC));
     $grid['HEADERS'] = array(array('id' => 'ID', 'name' => 'ID', 'default' => false), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_NAME'), 'default' => true), array('id' => 'DELETE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_DELETE_TIME'), 'default' => true), array('id' => 'CREATE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_CREATE_TIME'), 'default' => false), array('id' => 'UPDATE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_UPDATE_TIME'), 'default' => false), array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_CREATE_USER'), 'default' => false), array('id' => 'DELETE_USER', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_DELETE_USER'), 'default' => false), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_FORMATTED_SIZE'), 'default' => true));
     $grid['ROWS'] = $rows;
     $grid['ROWS_COUNT'] = count($rows);
     $grid['FOOTER'] = array();
     return $grid;
 }
 protected function processActionPublishBlank()
 {
     $this->checkRequiredGetParams(array('type'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $fileData = new BlankFileData($this->request->getQuery('type'));
     if ($this->request->getPost('targetFolderId')) {
         $folder = Folder::loadById((int) $this->request->getPost('targetFolderId'), array('STORAGE'));
         if (!$folder) {
             $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER'), self::ERROR_COULD_NOT_FIND_FOLDER)));
             $this->sendJsonErrorResponse();
         }
     } else {
         $userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
         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();
     }
     $storage = $folder->getStorage();
     if (!$folder->canAdd($storage->getCurrentUserSecurityContext())) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS)));
         $this->sendJsonErrorResponse();
     }
     $newFile = $folder->addBlankFile(array('NAME' => $fileData->getName(), 'CREATED_BY' => $this->getUser()->getId(), 'MIME_TYPE' => $fileData->getMimeType()), 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();
     }
     $this->sendJsonSuccessResponse(array('ufValue' => FileUserType::NEW_FILE_PREFIX . $newFile->getId(), 'id' => $newFile->getId(), 'object' => array('id' => $newFile->getId(), 'name' => $newFile->getName(), 'sizeInt' => $newFile->getSize(), 'size' => \CFile::formatSize($newFile->getSize()), 'extension' => $newFile->getExtension(), 'nameWithoutExtension' => getFileNameWithoutExtension($newFile->getName())), 'folderName' => $storage->getProxyType()->getTitleForCurrentUser() . ' / ' . $folder->getName(), 'link' => Driver::getInstance()->getUrlManager()->getUrlForStartEditFile($newFile->getId(), self::CODE)));
 }
Example #11
0
 function processActionHandleFile($hash, &$file, &$package, &$upload, &$error)
 {
     $errorCollection = new ErrorCollection();
     $storage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
     if (!$storage) {
         $errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_CONTROLLER_ERROR_COULD_NOT_FIND_USER_STORAGE'), self::ERROR_COULD_NOT_FIND_USER_STORAGE)));
         $error = implode(" ", $errorCollection->toArray());
         return false;
     }
     $folder = $storage->getFolderForUploadedFiles($this->getUser()->getId());
     if (!$folder) {
         $errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_CONTROLLER_ERROR_COULD_NOT_FIND_FIND_FOLDER'), self::ERROR_COULD_NOT_FIND_FOLDER)));
         $error = implode(" ", $errorCollection->toArray());
         return false;
     }
     $urlManager = Driver::getInstance()->getUrlManager();
     if ($folder->canAdd($storage->getCurrentUserSecurityContext())) {
         $fileModel = $folder->uploadFile($file["files"]["default"], array('NAME' => $file['name'], 'CREATED_BY' => $this->getUser()->getId()), array(), true);
         if ($fileModel) {
             $name = $fileModel->getName();
             $id = FileUserType::NEW_FILE_PREFIX . $fileModel->getId();
             $file = array_merge($file, array('id' => $id, 'originalId' => $fileModel->getId(), 'name' => $name, 'label' => getFileNameWithoutExtension($name), 'ext' => $fileModel->getExtension(), 'size' => \CFile::formatSize($fileModel->getSize()), 'sizeInt' => $fileModel->getSize(), 'storage' => $storage->getProxyType()->getTitleForCurrentUser() . ' / ' . $folder->getName(), 'deleteUrl' => $urlManager->getUrlUfController('deleteFile', array('attachedId' => $id)), 'canChangeName' => true), TypeFile::isImage($name) ? array('previewUrl' => $urlManager->getUrlForShowFile($fileModel, array("width" => 100, "height" => 100))) : array());
         } else {
             $error = is_array($folder->getErrors()) ? implode(" ", $folder->getErrors()) : 'The file has not been saved';
         }
     }
     return empty($error);
 }
Example #12
0
 protected function processActionSaveSettingsExternalLink()
 {
     /** @var File $file */
     /** @var ExternalLink $extLink */
     list($file, $extLink) = $this->getFileAndExternalLink();
     if (!$extLink) {
         $this->sendJsonErrorResponse();
     }
     if ($this->request->getPost('deathTime')) {
         $extLink->changeDeathTime(DateTime::createFromTimestamp(time() + (int) $this->request->getPost('deathTime')));
     }
     if ($this->request->getPost('password')) {
         $extLink->changePassword($this->request->getPost('password'));
     }
     $this->sendJsonSuccessResponse(array('object' => array('name' => $file->getName(), 'size' => \CFile::formatSize($file->getSize()), 'date' => (string) $file->getUpdateTime()), 'linkData' => array('hasPassword' => $extLink->hasPassword(), 'hasDeathTime' => $extLink->hasDeathTime(), 'hash' => $extLink->getHash(), 'link' => Driver::getInstance()->getUrlManager()->getShortUrlExternalLink(array('hash' => $extLink->getHash(), 'action' => 'default'), true))));
 }
Example #13
0
 private function getVersionGridData($gridId)
 {
     $grid = array('ID' => $gridId);
     $gridOptions = new CGridOptions($grid['ID']);
     $gridSort = $gridOptions->getSorting(array('sort' => array('ID' => 'desc'), 'vars' => array('by' => 'by', 'order' => 'order')));
     $grid['SORT'] = $gridSort['sort'];
     $grid['SORT_VARS'] = $gridSort['vars'];
     $this->arResult['ITEMS'] = $this->file->getVersions(array('with' => array('CREATE_USER'), 'order' => $gridSort['sort']));
     $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
     $rows = array();
     foreach ($this->arResult['ITEMS'] as $version) {
         /** @var $version Version */
         $objectArray = $version->toArray();
         $actions = array(array("ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_FILE_VIEW_HISTORY_ACT_DOWNLOAD'), "DEFAULT" => true, "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadVersion($version) . "')"));
         $securityContext = $this->storage->getCurrentUserSecurityContext();
         if ($this->file->canRestore($securityContext)) {
             $actions[] = array("ICONCLASS" => "restore", "TEXT" => Loc::getMessage('DISK_FILE_VIEW_HISTORY_ACT_RESTORE'), "DEFAULT" => true, "ONCLICK" => "BX.Disk['FileViewClass_{$this->getComponentId()}'].openConfirmRestore({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$this->file->getId()},\n\t\t\t\t\t\t\t\tname: '{$this->file->getName()}'\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tversion: {\n\t\t\t\t\t\t\t\tid: {$version->getId()}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})");
         }
         if ($this->file->canRestore($securityContext) && $this->file->canDelete($securityContext)) {
             $actions[] = array("ICONCLASS" => "delete", "TEXT" => Loc::getMessage('DISK_FILE_VIEW_HISTORY_ACT_DELETE'), "DEFAULT" => true, "ONCLICK" => "BX.Disk['FileViewClass_{$this->getComponentId()}'].openConfirmDeleteVersion({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$this->file->getId()},\n\t\t\t\t\t\t\t\tname: '{$this->file->getName()}'\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tversion: {\n\t\t\t\t\t\t\t\tid: {$version->getId()}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})");
         }
         $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $version->getCreatedBy()));
         $dataAttributesForViewer = Ui\Viewer::getAttributesByVersion($version);
         $rows[] = array('data' => $objectArray, 'columns' => array('FORMATTED_SIZE' => CFile::formatSize($version->getSize()), 'NAME' => "<a href='' {$dataAttributesForViewer}>" . $version->getName() . "</a>", 'CREATE_USER' => "\n\t\t\t\t\t\t<div class=\"bx-disk-user-link\"><span class=\"bx-disk-filepage-fileinfo-ownner-avatar\" style=\"background-image: url({$version->getCreateUser()->getAvatarSrc()});\"></span><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($version->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t\t", 'CREATE_TIME_VERSION' => $version->getCreateTime(), 'CREATE_TIME_FILE' => $version->getObjectCreateTime(), 'UPDATE_TIME_FILE' => $version->getObjectUpdateTime()), 'actions' => $actions);
     }
     unset($version);
     $grid['ROWS'] = $rows;
     $grid['ROWS_COUNT'] = count($rows);
     $grid['HEADERS'] = array(array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_FILE_VIEW_VERSION_COLUMN_CREATE_USER_2'), 'default' => true), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_FILE_VIEW_VERSION_COLUMN_NAME'), 'default' => true), array('id' => 'CREATE_TIME_VERSION', 'name' => Loc::getMessage('DISK_FILE_VIEW_VERSION_COLUMN_CREATE_TIME_2'), 'default' => true), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_FILE_VIEW_VERSION_COLUMN_FORMATTED_SIZE'), 'default' => true), array('id' => 'ID', 'name' => 'ID', 'default' => false, 'show_checkbox' => true));
     return $grid;
 }
 protected function processActionSaveBlank()
 {
     $this->checkRequiredGetParams(array('type'));
     $this->checkRequiredPostParams(array('editSessionId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $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 BlankFileData($this->request->getQuery('type'));
     $fileData->setId($currentSession->getServiceFileId());
     $fileData->setSrc($tmpFile);
     $fileData = $this->documentHandler->downloadFile($fileData);
     if (!$fileData) {
         if ($this->documentHandler->isRequiredAuthorization()) {
             $this->sendNeedAuth();
         }
         $this->errorCollection->add($this->documentHandler->getErrors());
         $this->sendJsonErrorResponse();
     }
     $fileArray = \CFile::makeFileArray($tmpFile);
     $fileArray['name'] = $fileData->getName();
     $fileArray['type'] = $fileData->getMimeType();
     $fileArray['MODULE_ID'] = Driver::INTERNAL_MODULE_ID;
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $fileId = \CFile::saveFile($fileArray, Driver::INTERNAL_MODULE_ID);
     if (!$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();
     }
     $folder = null;
     if (!empty($_REQUEST['targetFolderId'])) {
         $folder = $this->getFolderToSaveFile((int) $_REQUEST['targetFolderId']);
     }
     if (!$folder) {
         $userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
         if (!$userStorage) {
             \CFile::delete($fileId);
             $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_STORAGE'), self::ERROR_COULD_NOT_FIND_STORAGE)));
             $this->sendJsonErrorResponse();
         }
         $folder = $userStorage->getFolderForCreatedFiles();
     }
     if (!$folder) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_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())) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS)));
         $this->sendJsonErrorResponse();
     }
     $newFile = $folder->addFile(array('NAME' => $fileData->getName(), 'FILE_ID' => $fileId, 'SIZE' => $fileArray['size'], 'CREATED_BY' => $this->getUser()->getId()), array(), true);
     if (!$newFile) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_CREATE_FILE'), self::ERROR_COULD_NOT_CREATE_FILE)));
         $this->errorCollection->add($folder->getErrors());
         $this->sendJsonErrorResponse();
     }
     $this->deleteEditSession($currentSession);
     $this->deleteFile($currentSession, $fileData);
     $this->sendJsonSuccessResponse(array('folderName' => $folder->getName(), 'objectId' => $newFile->getId(), 'sizeInt' => $newFile->getSize(), 'size' => \CFile::formatSize($newFile->getSize()), 'name' => $newFile->getName(), 'extension' => $newFile->getExtension(), 'nameWithoutExtension' => getFileNameWithoutExtension($newFile->getName())));
 }
Example #15
0
 protected function processActionSearchFile($entityType, $entityId, $searchQuery)
 {
     $models = $this->searchObjects($entityType, $entityId, $searchQuery);
     if ($models === null) {
         $this->sendJsonErrorResponse();
     }
     $urlManager = Driver::getInstance()->getUrlManager();
     $urlForLoadItems = $urlManager->getUrlUfController('loadItems');
     $response = array();
     foreach ($models as $item) {
         /** @var File|Folder $item */
         $isFolder = $item instanceof Folder;
         if ($isFolder) {
             continue;
         }
         $id = FileUserType::NEW_FILE_PREFIX . $item->getId();
         $response[$id] = array('id' => $id, 'type' => 'file', 'link' => $urlForLoadItems, 'name' => $item->getName(), 'size' => $isFolder ? '' : \CFile::formatSize($item->getSize()), 'sizeInt' => $isFolder ? '' : $item->getSize(), 'modifyBy' => $item->getUpdateUser()->getFormattedName(), 'modifyDate' => $item->getUpdateTime()->format('d.m.Y'), 'modifyDateInt' => $item->getUpdateTime()->getTimestamp(), 'ext' => $item->getExtension());
     }
     unset($item);
     $this->sendJsonSuccessResponse(array('items' => $response));
 }
Example #16
0
echo $arResult['FILE']['CREATE_USER']['AVA'];
?>
);"></span>
													<?php 
echo htmlspecialcharsbx($arResult['FILE']['CREATE_USER']['NAME']);
?>
												</a>
											</td>
										</tr>
										<tr>
											<td class="bx-disk-filepage-fileinfo-param"><?php 
echo Loc::getMessage('DISK_FILE_VIEW_FILE_SIZE');
?>
:</td>
											<td class="bx-disk-filepage-fileinfo-value"><?php 
echo CFile::formatSize($arResult['FILE']['SIZE']);
?>
</td>
										</tr>
										<tr>
											<td class="bx-disk-filepage-fileinfo-param"><?php 
echo Loc::getMessage('DISK_FILE_VIEW_FILE_UPDATE_TIME');
?>
:</td>
											<td class="bx-disk-filepage-fileinfo-value"><?php 
echo $arResult['FILE']['UPDATE_TIME'];
?>
</td>
										</tr
									</tbody>
								</table>
Example #17
0
 /**
  * Lists folder contents
  * @param $path
  * @param $folderId
  * @return mixed
  */
 public function listFolder($path, $folderId)
 {
     if ($path === '/') {
         $folderId = 'root';
     }
     $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
     $http->setHeader('Content-Type', 'application/json; charset=UTF-8');
     $http->setHeader('Authorization', "bearer {$this->getAccessToken()}");
     if ($http->get(self::API_URL_V1 . "/drive/items/{$folderId}?expand=children") === false) {
         $errorString = implode('; ', array_keys($http->getError()));
         $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_LIST_FOLDER)));
         return null;
     }
     if (!$this->checkHttpResponse($http)) {
         return null;
     }
     $items = Json::decode($http->getResult());
     if ($items === null) {
         $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON)));
         return null;
     }
     if (!isset($items['children'])) {
         $this->errorCollection->add(array(new Error('Could not find items in response', self::ERROR_HTTP_LIST_FOLDER)));
         return null;
     }
     $reformatItems = array();
     foreach ($items['children'] as $item) {
         $isFolder = isset($item['folder']);
         $dateTime = new \DateTime($item['lastModifiedDateTime']);
         $reformatItems[$item['id']] = array('id' => $item['id'], 'name' => $item['name'], 'type' => $isFolder ? 'folder' : 'file', 'size' => $isFolder ? '' : \CFile::formatSize($item['size']), 'sizeInt' => $isFolder ? '' : $item['size'], 'modifyBy' => '', 'modifyDate' => $dateTime->format('d.m.Y'), 'modifyDateInt' => $dateTime->getTimestamp(), 'provider' => static::getCode());
         if (!$isFolder) {
             $reformatItems[$item['id']]['storage'] = '';
             $reformatItems[$item['id']]['ext'] = getFileExtension($item['name']);
         }
     }
     unset($item);
     return $reformatItems;
 }