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
71 $unzip = $this->irss->getContainerZip($rid);
72 $uri = $this->irss->stream($rid)->getMetadata(
"uri");
73 $zip_archive = new \ZipArchive();
74 $zip_archive->open($uri, \ZipArchive::RDONLY);
76 foreach ($unzip->getPaths() as
$path) {
77 if (str_starts_with(
$path,
".")) {
80 if (!str_starts_with(
$path,
"images")) {
83 if (!in_array(strtolower(pathinfo(
$path, PATHINFO_EXTENSION)), [
"jpg",
"png",
"gif",
"svg"])) {
86 $att = $zip_archive->statName(
$path);
87 if ($include_size_info) {
88 $full_path = $this->irss->getContainerUri($rid,
$path);
90 $stream = $this->irss->getStreamOfContainerEntry($rid,
$path);
91 $content = $stream->getContents();
92 $image_size = getimagesizefromstring($content);
93 }
catch (\Exception
$e) {
95 $width = $image_size[0] ?? 0;
96 $height = $image_size[1] ?? 0;
102 $this->irss->getContainerUri($rid,
$path),
111 $dir = $this->
dir($style_id);
112 if ($this->web_files->hasDir($dir)) {
113 foreach ($this->web_files->listContents($dir) as $meta) {
114 if ($meta->isFile()) {
115 $size = $this->web_files->getSize(
119 $image_size = getimagesize($this->
getWebPath($meta->getPath()));
120 $width = $image_size[0] ?? 0;
121 $height = $image_size[1] ?? 0;
137 return $this->irss->getStreamOfContainerEntry(
148 $this->irss->addStreamToContainer(
158 if (str_starts_with(
$path,
"http")) {
165 public function getByFilename(
int $style_id,
string $rid,
string $filename): ?
Image
168 foreach ($this->getImages($style_id, $rid) as $i) {
179 $dir = $this->dir($style_id);
180 $this->web_files->delete($dir .
"/" .
$filename);
187 $this->irss->addUploadToContainer(
This class provides the data size with additional information to remove the work to calculate the siz...
addStream(string $rid, string $image, FileStream $stream)
getImageStream(string $rid, string $image)
getImages(int $style_id, string $rid, bool $include_size_info=false)
Get images of style.
InternalDataService $factory
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...
if(!file_exists('../ilias.ini.php'))