public static function get($name)
{
if (!$name) {
return null;
}
return self::getInstance($name, function ($name) {
$media_path = rex_path::addonCache('mediapool', $name . '.media');
if (!file_exists($media_path)) {
rex_media_cache::generate($name);
}
if (file_exists($media_path)) {
$cache = rex_file::getCache($media_path);
$aliasMap = ['filename' => 'name', 'filetype' => 'type', 'filesize' => 'size'];
$media = new self();
foreach ($cache as $key => $value) {
if (array_key_exists($key, $aliasMap)) {
$var_name = $aliasMap[$key];
} else {
$var_name = $key;
}
$media->{$var_name} = $value;
}
$media->category = null;
return $media;
}
return null;
});
}
protected function getOutput() { $id = $this->getArg('id', 0, true); if (!in_array($this->getContext(), ['module', 'action']) || !is_numeric($id) || $id < 1 || $id > 10) { return false; } $value = $this->getContextData()->getValue('media' . $id); if ($this->hasArg('isset') && $this->getArg('isset')) { return $value ? 'true' : 'false'; } if ($this->hasArg('widget') && $this->getArg('widget')) { if (!$this->environmentIs(self::ENV_INPUT)) { return false; } $args = []; foreach (['category', 'preview', 'types'] as $key) { if ($this->hasArg($key)) { $args[$key] = $this->getArg($key); } } $value = self::getWidget($id, 'REX_INPUT_MEDIA[' . $id . ']', $value, $args); } else { if ($this->hasArg('output') && $this->getArg('output') == 'mimetype') { $media = rex_media::get($value); if ($media) { $value = $media->getType(); } } } return self::quote($value); }