ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\Style\Content\ImageFileRepo Class Reference
+ Collaboration diagram for ILIAS\Style\Content\ImageFileRepo:

Public Member Functions

 __construct (InternalDataService $factory, Filesystem\Filesystem $web_files, FileUpload $upload, protected IRSSWrapper $irss)
 
 getImages (int $style_id, string $rid, bool $include_size_info=false, bool $include_legacy_dir=true)
 Get images of style. More...
 
 hasLegacyDir (int $style_id)
 
 hasImages (int $style_id, string $rid)
 
 getImageStream (string $rid, string $image)
 
 addStream (string $rid, string $image, FileStream $stream)
 
 getWebPath (string $path)
 
 deleteImageByFilename (int $style_id, string $filename)
 
 importFromUploadResult (string $rid, UploadResult $result,)
 

Protected Member Functions

 dir (int $style_id)
 

Protected Attributes

const DIR_PATH = "sty/sty_%id%/images"
 
InternalDataService $factory
 
Filesystem Filesystem $web_files
 
FileUpload $upload
 

Detailed Description

Definition at line 34 of file class.ImageFileRepo.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Style\Content\ImageFileRepo::__construct ( InternalDataService  $factory,
Filesystem\Filesystem  $web_files,
FileUpload  $upload,
protected IRSSWrapper  $irss 
)

Member Function Documentation

◆ addStream()

ILIAS\Style\Content\ImageFileRepo::addStream ( string  $rid,
string  $image,
FileStream  $stream 
)

Definition at line 167 of file class.ImageFileRepo.php.

171 : void {
172 $this->irss->addStreamToContainer(
173 $rid,
174 $stream,
175 "images/" . $image
176 );
177 }

◆ deleteImageByFilename()

ILIAS\Style\Content\ImageFileRepo::deleteImageByFilename ( int  $style_id,
string  $filename 
)

Definition at line 201 of file class.ImageFileRepo.php.

201 : void
202 {
203 $dir = $this->dir($style_id);
204 $this->web_files->delete($dir . "/" . $filename);
205 }
$filename
Definition: buildRTE.php:78

References $filename.

◆ dir()

ILIAS\Style\Content\ImageFileRepo::dir ( int  $style_id)
protected

Definition at line 54 of file class.ImageFileRepo.php.

54 : string
55 {
56 return str_replace("%id%", (string) $style_id, self::DIR_PATH);
57 }

◆ getImages()

ILIAS\Style\Content\ImageFileRepo::getImages ( int  $style_id,
string  $rid,
bool  $include_size_info = false,
bool  $include_legacy_dir = true 
)

Get images of style.

Parameters
int$style_id
Returns
Generator
Exceptions
Filesystem

Exception\DirectoryNotFoundException

Definition at line 65 of file class.ImageFileRepo.php.

70 : Generator {
71 $has_images = false;
72 if ($rid !== "") {
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);
77
78 foreach ($unzip->getPaths() as $path) {
79 if (str_starts_with($path, ".")) {
80 continue;
81 }
82 if (!str_starts_with($path, "images")) {
83 continue;
84 }
85 if (!in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), ["jpg", "png", "gif", "svg"])) {
86 continue;
87 }
88 $att = $zip_archive->statName($path);
89 if ($include_size_info) {
90 $full_path = $this->irss->getContainerUri($rid, $path);
91 try {
92 $stream = $this->irss->getStreamOfContainerEntry($rid, $path);
93 $content = $stream->getContents();
94 $image_size = getimagesizefromstring($content);
95 } catch (\Exception $e) {
96 }
97 $width = $image_size[0] ?? 0;
98 $height = $image_size[1] ?? 0;
99 } else {
100 $width = 0;
101 $height = 0;
102 }
103 $has_images = true;
104 yield $this->factory->image(
105 $this->irss->getContainerUri($rid, $path),
106 new DataSize($att["size"], DataSize::KB),
107 $width,
108 $height
109 );
110 }
111 }
112
113 if ($has_images || !$include_legacy_dir) {
114 return;
115 }
116
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(
122 $meta->getPath(),
124 );
125 $image_size = getimagesize($this->getWebPath($meta->getPath()));
126 $width = $image_size[0] ?? 0;
127 $height = $image_size[1] ?? 0;
128 yield $this->factory->image(
129 $meta->getPath(),
130 $size,
131 $width,
132 $height
133 );
134 }
135 }
136 }
137 }
$path
Definition: ltiservices.php:30

References Vendor\Package\$e, $path, factory(), and ILIAS\Data\DataSize\KB.

+ Here is the call graph for this function:

◆ getImageStream()

ILIAS\Style\Content\ImageFileRepo::getImageStream ( string  $rid,
string  $image 
)

Definition at line 157 of file class.ImageFileRepo.php.

160 : ZIPStream {
161 return $this->irss->getStreamOfContainerEntry(
162 $rid,
163 "images/" . $image
164 );
165 }

◆ getWebPath()

ILIAS\Style\Content\ImageFileRepo::getWebPath ( string  $path)

Definition at line 180 of file class.ImageFileRepo.php.

180 : string
181 {
182 if (str_starts_with($path, "http")) {
183 return $path;
184 }
185 return ILIAS_WEB_DIR . "/" . CLIENT_ID . "/" . $path;
186 }
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45

References $path, CLIENT_ID, and ILIAS_WEB_DIR.

◆ hasImages()

ILIAS\Style\Content\ImageFileRepo::hasImages ( int  $style_id,
string  $rid 
)

Definition at line 149 of file class.ImageFileRepo.php.

152 : bool {
153 $images = iterator_to_array($this->getImages($style_id, $rid, false, false));
154 return count($images) > 0;
155 }
getImages(int $style_id, string $rid, bool $include_size_info=false, bool $include_legacy_dir=true)
Get images of style.

◆ hasLegacyDir()

ILIAS\Style\Content\ImageFileRepo::hasLegacyDir ( int  $style_id)

Definition at line 139 of file class.ImageFileRepo.php.

141 : bool {
142 $dir = $this->dir($style_id);
143 if ($this->web_files->hasDir($dir)) {
144 return true;
145 }
146 return false;
147 }

◆ importFromUploadResult()

ILIAS\Style\Content\ImageFileRepo::importFromUploadResult ( string  $rid,
UploadResult  $result 
)

Definition at line 207 of file class.ImageFileRepo.php.

210 : void {
211 $this->irss->addUploadToContainer(
212 $rid,
213 $result
214 );
215 }

Field Documentation

◆ $factory

InternalDataService ILIAS\Style\Content\ImageFileRepo::$factory
protected

◆ $upload

FileUpload ILIAS\Style\Content\ImageFileRepo::$upload
protected

◆ $web_files

Filesystem Filesystem ILIAS\Style\Content\ImageFileRepo::$web_files
protected

◆ DIR_PATH

const ILIAS\Style\Content\ImageFileRepo::DIR_PATH = "sty/sty_%id%/images"
protected

Definition at line 36 of file class.ImageFileRepo.php.


The documentation for this class was generated from the following file: