58 ->setAttribute(
'data-viewer')
59 ->setViewerType(static::getViewerTypeByFile($this->fileData))
60 ->setAttribute(
'data-src', $this->sourceUri)
73 $fileData = \CFile::getByID($fileId)->fetch();
109 return static::buildAsUnknownType(
$sourceUri);
125 'CONTENT_TYPE' =>
'application/octet-stream',
135 return static::buildByFileId($fileId,
$sourceUri);
141 return static::buildAsUnknownType(
$sourceUri);
155 return $this->
setAttribute(
'data-title', htmlspecialcharsbx($title));
160 return $this->
setAttribute(
'data-viewer-type-class', htmlspecialcharsbx($class));
180 return $this->
setAttribute(
'data-viewer-group-by', htmlspecialcharsbx($id));
206 $this->actions[] = $action;
232 return $this->
setAttribute(
'data-viewer-extension', $extension);
250 $this->
setViewerType(static::getViewerTypeByFile($this->fileData));
264 $this->attributes[$name] = $value;
276 unset($this->attributes[$name]);
288 return isset($this->attributes[$name]);
298 if (isset($this->attributes[$name]))
300 return $this->attributes[$name];
320 protected static function getViewerTypeByFile(array $fileArray)
322 $contentType = $fileArray[
'CONTENT_TYPE'];
323 $originalName = $fileArray[
'ORIGINAL_NAME'] ??
null;
325 if (isset(static::$renderClassByContentType[$contentType]))
327 $renderClass = static::$renderClassByContentType[$contentType];
328 if ($renderClass::getSizeRestriction() ===
null)
330 return $renderClass::getJsType();
334 $previewManager =
new PreviewManager();
335 $renderClass = $previewManager->getRenderClassByFile([
336 'contentType' => $contentType,
337 'originalName' => $originalName,
338 'size' => $fileArray[
'FILE_SIZE'] ??
null,
341 if ($renderClass === Renderer\Stub::class)
343 $transformerManager =
new TransformerManager();
344 if ($transformerManager->isAvailable())
347 $transformation = $transformerManager->buildTransformationByFile($fileArray);
350 $contentType = $transformation->getOutputContentType();
351 $renderClass = $previewManager->getRenderClassByFile([
352 'contentType' => $contentType,
353 'originalName' => $originalName,
359 if ($renderClass !== Renderer\RestrictedBySize::class)
361 static::$renderClassByContentType[$fileArray[
'CONTENT_TYPE']] = $renderClass;
364 return $renderClass::getJsType();
372 return (
string)$this;
381 foreach ($this->attributes as $key => $value)
385 $string .=
"{$value} ";
389 $value = htmlspecialcharsbx($value);
390 $string .=
"{$key}=\"{$value}\" ";
396 $string .=
"data-actions='" . htmlspecialcharsbx(Json::encode($this->actions)) .
"'";
409 foreach ($this->attributes as $key => $value)
431 $key = str_replace(
'data-',
'', $key);
432 $key = str_replace(
'-',
' ', mb_strtolower($key));
434 return lcfirst(str_replace(
' ',
'', ucwords($key)));
static tryBuildByFileId($fileId, $sourceUri)
setViewerType(string $type)
static buildByFileId($fileId, $sourceUri)
static buildAsUnknownType($sourceUri)
static buildByFileData(array $fileData, $sourceUri)
setTypeClass(string $class)
setAttribute($name, $value=null)
static tryBuildByFileData(array $fileData, $sourceUri)
convertKeyToDataSet($key)
static $renderClassByContentType