Ejemplo n.º 1
0
 /**
  * Gets data attributes by object (folder or file) to viewer.
  * @param File|Folder|BaseObject $object Target object.
  * @param array                  $additionalParams Additional parameters 'relativePath', 'externalId', 'canUpdate', 'showStorage'.
  * @return string
  */
 public static function getAttributesByObject(BaseObject $object, array $additionalParams = array())
 {
     $urlManager = Driver::getInstance()->getUrlManager();
     $name = $object->getName();
     $dateTime = $object->getUpdateTime();
     if ($object instanceof Folder) {
         $user = $object->getCreateUser();
         $dataAttributesForViewer = 'data-bx-viewer="folder" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="" ' . 'data-bx-owner="' . htmlspecialcharsbx($user ? $user->getFormattedName() : '') . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
         return $dataAttributesForViewer;
     }
     if (!$object instanceof File) {
         return '';
     }
     if (DocumentHandler::isEditable($object->getExtension())) {
         $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowFileByService($object->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="' . (DocumentHandler::isNeedConvertExtension($object->getExtension()) ? '1' : '') . '" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($object->getSize())) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
     } elseif (Viewer::isViewable($object->getExtension())) {
         $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowFileByService($object->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="0" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($object->getSize())) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
     } elseif (TypeFile::isImage($object)) {
         $dataAttributesForViewer = 'data-bx-viewer="image" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
     } else {
         $user = $object->getCreateUser();
         $dataAttributesForViewer = 'data-bx-viewer="unknown" ' . 'data-bx-src="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadFile($object) . '" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-owner="' . htmlspecialcharsbx($user ? $user->getFormattedName() : '') . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($object->getSize())) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($dateTime) . '" ';
     }
     $dataAttributesForViewer .= " bx-attach-file-id=\"{$object->getId()}\"" . " data-bx-version=\"\"" . " data-bx-history=\"\"" . " data-bx-historyPage=\"\"";
     if (!empty($additionalParams['relativePath'])) {
         $dataAttributesForViewer .= ' data-bx-relativePath="' . htmlspecialcharsbx($additionalParams['relativePath'] . '/' . $name) . '" ';
     }
     if (!empty($additionalParams['externalId'])) {
         $dataAttributesForViewer .= ' data-bx-externalId="' . htmlspecialcharsbx($additionalParams['externalId']) . '" ';
     }
     if (!empty($additionalParams['canUpdate'])) {
         $dataAttributesForViewer .= ' data-bx-edit="' . $urlManager->getUrlForStartEditFile($object->getId(), 'gdrive') . '" ';
     }
     if (!empty($additionalParams['showStorage'])) {
         $dataAttributesForViewer .= ' data-bx-storage="' . htmlspecialcharsbx($object->getParent()->getName()) . '" ';
     }
     return $dataAttributesForViewer;
 }
Ejemplo n.º 2
0
 public static function getIconClassByObject(BaseObject $object, $appendSharedClass = false)
 {
     $class = '';
     if ($object instanceof Folder) {
         $class = 'bx-disk-folder-icon';
     } elseif ($object instanceof File) {
         $class = 'bx-disk-file-icon';
         $ext = strtolower($object->getExtension());
         if (isset(self::$possibleIconClasses[$ext])) {
             $class .= ' ' . self::$possibleIconClasses[$ext];
         } elseif (TypeFile::isImage($object)) {
             $class .= ' ' . self::$possibleIconClasses['img'];
         } elseif (TypeFile::isVideo($object)) {
             $class .= ' ' . self::$possibleIconClasses['vid'];
         }
     }
     if ($object->isLink()) {
         $class .= ' icon-shared shared icon-shared_2';
     } elseif ($appendSharedClass) {
         $class .= ' icon-shared shared icon-shared_1 icon-shared_2';
     }
     return $class;
 }