Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
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;
    }
Exemplo n.º 3
0
 protected function processActionDefault()
 {
     $gridId = 'file_version_list';
     $securityContext = $this->storage->getCurrentUserSecurityContext();
     $urlManager = Driver::getInstance()->getUrlManager();
     $this->getApplication()->setTitle($this->storage->getProxyType()->getTitleForCurrentUser());
     $breadcrumbs = $this->getBreadcrumbs();
     $externalLinkData = array();
     $externalLink = $this->getExternalLink();
     if ($externalLink) {
         $externalLinkData = array('LINK' => Driver::getInstance()->getUrlManager()->getShortUrlExternalLink(array('hash' => $externalLink->getHash(), 'action' => 'default'), true));
     }
     $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $this->file->getCreatedBy()));
     $canUpdate = $this->file->canUpdate($securityContext);
     $viewFile = CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_FILE_VIEW'], array('FILE_ID' => $this->file->getId(), 'FILE_PATH' => $this->arParams['RELATIVE_PATH']));
     $this->arResult = array('VERSION_GRID' => array(), 'STORAGE' => $this->storage, 'USE_IN_ENTITIES' => false, 'ENTITIES' => array(), 'SHOW_USER_FIELDS' => false, 'USER_FIELDS' => array(), 'TOOLBAR' => array('BUTTONS' => array(array('TEXT' => Loc::getMessage('DISK_FILE_VIEW_GO_BACK_TEXT'), 'TITLE' => Loc::getMessage('DISK_FILE_VIEW_GO_BACK_TITLE'), 'LINK' => end($breadcrumbs), 'ICON' => 'back'), array('TEXT' => Loc::getMessage('DISK_FILE_VIEW_COPY_LINK_TEXT'), 'TITLE' => Loc::getMessage('DISK_FILE_VIEW_COPY_LINK_TITLE'), 'LINK' => "javascript:BX.Disk['FileViewClass_{$this->getComponentId()}'].getInternalLink();", 'ICON' => 'copy-link'))), 'EXTERNAL_LINK' => $externalLinkData, 'FILE' => array('ID' => $this->file->getId(), 'IS_IMAGE' => TypeFile::isImage($this->file->getName()), 'CREATE_USER' => array('LINK' => $createdByLink, 'NAME' => $this->file->getCreateUser()->getFormattedName(), 'AVA' => $this->file->getCreateUser()->getAvatarSrc(21, 21)), 'VIEWER_ATTRIBUTES' => Ui\Viewer::getAttributesByObject($this->file, array('canUpdate' => $canUpdate)), 'UPDATE_TIME' => $this->file->getUpdateTime(), 'ICON_CLASS' => Icon::getIconClassByObject($this->file), 'NAME' => $this->file->getName(), 'SIZE' => $this->file->getSize(), 'IS_LINK' => $this->file->isLink(), 'FOLDER_LIST_WEBDAV' => rtrim(end($breadcrumbs), '/') . '/' . $this->file->getName(), 'DOWNLOAD_URL' => $urlManager->getUrlForDownloadFile($this->file), 'SHOW_PREVIEW_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlForShowFile($this->file, array('exact' => 'Y', 'width' => 255, 'height' => 255)), 'SHOW_FILE_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlForShowFile($this->file)), 'CAN_UPDATE' => $canUpdate, 'CAN_DELETE' => $this->file->canDelete($securityContext), 'PATH_TO_FILE_VIEW' => $viewFile);
     $attachedObjects = $this->file->getAttachedObjects();
     if ($attachedObjects) {
         $userId = $this->getUser()->getId();
         $this->arResult['USE_IN_ENTITIES'] = true;
         Uf\Connector::setPathToUser($this->arParams['PATH_TO_USER']);
         Uf\Connector::setPathToGroup($this->arParams['PATH_TO_GROUP']);
         foreach ($attachedObjects as $attachedObject) {
             $connector = $attachedObject->getConnector();
             if (!$connector->canRead($userId)) {
                 continue;
             }
             $dataToShow = $connector->getDataToShow();
             if ($dataToShow) {
                 $this->arResult['ENTITIES'][] = $dataToShow;
             }
         }
         unset($attachedObject);
     }
     $userFieldsObject = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager()->getFieldsForObject($this->file);
     foreach ($userFieldsObject as $field) {
         if ($field['VALUE'] !== false) {
             $this->arResult['SHOW_USER_FIELDS'] = true;
             $this->arResult['USER_FIELDS'] = $userFieldsObject;
             break;
         }
     }
     unset($field);
     $this->arParams['STATUS_BIZPROC'] = $this->storage->isEnabledBizProc() && Loader::includeModule("bizproc");
     if ($this->arParams['STATUS_BIZPROC']) {
         $documentData = array('DISK' => array('DOCUMENT_TYPE' => \Bitrix\Disk\BizProcDocument::generateDocumentComplexType($this->storage->getId()), 'DOCUMENT_ID' => \Bitrix\Disk\BizProcDocument::getDocumentComplexId($this->file->getId())), 'WEBDAV' => array('DOCUMENT_TYPE' => \Bitrix\Disk\BizProcDocumentCompatible::generateDocumentComplexType($this->storage->getId()), 'DOCUMENT_ID' => \Bitrix\Disk\BizProcDocumentCompatible::getDocumentComplexId($this->file->getId())));
         $webdavFileId = $this->file->getXmlId();
         if (!empty($webdavFileId)) {
             if (Loader::includeModule("iblock")) {
                 if ($this->storage->getProxyType() instanceof ProxyType\Group) {
                     $iblock = CIBlockElement::getList(array(), array("ID" => $webdavFileId, 'SHOW_NEW' => 'Y'), false, false, array('ID', 'IBLOCK_ID'))->fetch();
                     $entity = 'CIBlockDocumentWebdavSocnet';
                 } else {
                     $iblock = CIBlockElement::getList(array(), array("ID" => $webdavFileId, 'SHOW_NEW' => 'Y'), false, false, array('ID', 'IBLOCK_ID'))->fetch();
                     $entity = 'CIBlockDocumentWebdav';
                 }
                 if (!empty($iblock)) {
                     $documentData['OLD_FILE'] = array('DOCUMENT_TYPE' => array('webdav', $entity, "iblock_" . $iblock['IBLOCK_ID']), 'DOCUMENT_ID' => array('webdav', $entity, $iblock['ID']));
                 }
             }
         }
         $this->getAutoloadTemplateBizProc($documentData);
         if ($this->request->isPost() && intval($this->request->getPost('bizproc_index')) > 0) {
             $this->showBizProc($documentData);
         }
     }
     $this->includeComponentTemplate();
 }
Exemplo n.º 4
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;
 }