19declare(strict_types=1);
36 protected const DIR_PATH =
"sty/sty_%id%/images";
54 protected function dir(
int $style_id): string
56 return str_replace(
"%id%", (
string) $style_id, self::DIR_PATH);
68 bool $include_size_info =
false,
69 bool $include_legacy_dir =
true
73 $unzip = $this->irss->getContainerZip($rid);
74 $uri = $this->irss->stream($rid)->getMetadata(
"uri");
75 $zip_archive = new \ZipArchive();
76 $zip_archive->open($uri, \ZipArchive::RDONLY);
78 foreach ($unzip->getPaths() as
$path) {
79 if (str_starts_with(
$path,
".")) {
82 if (!str_starts_with(
$path,
"images")) {
85 if (!in_array(strtolower(pathinfo(
$path, PATHINFO_EXTENSION)), [
"jpg",
"png",
"gif",
"svg"])) {
88 $att = $zip_archive->statName(
$path);
89 if ($include_size_info) {
90 $full_path = $this->irss->getContainerUri($rid,
$path);
92 $stream = $this->irss->getStreamOfContainerEntry($rid,
$path);
93 $content = $stream->getContents();
94 $image_size = getimagesizefromstring($content);
95 }
catch (\Exception
$e) {
97 $width = $image_size[0] ?? 0;
98 $height = $image_size[1] ?? 0;
105 $this->irss->getContainerUri($rid,
$path),
113 if ($has_images || !$include_legacy_dir) {
117 $dir = $this->
dir($style_id);
118 if ($this->web_files->hasDir($dir)) {
119 foreach ($this->web_files->listContents($dir) as $meta) {
120 if ($meta->isFile()) {
121 $size = $this->web_files->getSize(
125 $image_size = getimagesize($this->
getWebPath($meta->getPath()));
126 $width = $image_size[0] ?? 0;
127 $height = $image_size[1] ?? 0;
142 $dir = $this->dir($style_id);
143 if ($this->web_files->hasDir($dir)) {
153 $images = iterator_to_array($this->getImages($style_id, $rid, false, false));
154 return count($images) > 0;
161 return $this->irss->getStreamOfContainerEntry(
172 $this->irss->addStreamToContainer(
182 if (str_starts_with(
$path,
"http")) {
189 public function getByFilename(
int $style_id,
string $rid,
string $filename): ?
Image
192 foreach ($this->getImages($style_id, $rid) as $i) {
203 $dir = $this->dir($style_id);
204 $this->web_files->delete($dir .
"/" .
$filename);
211 $this->irss->addUploadToContainer(
This class provides the data size with additional information to remove the work to calculate the siz...
getImages(int $style_id, string $rid, bool $include_size_info=false, bool $include_legacy_dir=true)
Get images of style.
addStream(string $rid, string $image, FileStream $stream)
hasImages(int $style_id, string $rid)
getImageStream(string $rid, string $image)
InternalDataService $factory
hasLegacyDir(int $style_id)
deleteImageByFilename(int $style_id, string $filename)
importFromUploadResult(string $rid, UploadResult $result,)
Filesystem Filesystem $web_files
__construct(InternalDataService $factory, Filesystem\Filesystem $web_files, FileUpload $upload, protected IRSSWrapper $irss)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The filesystem interface provides the public interface for the Filesystem service API consumer.
The base interface for all filesystem streams.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...