ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 Get images of style. More...
 
 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 143 of file class.ImageFileRepo.php.

147 : void {
148 $this->irss->addStreamToContainer(
149 $rid,
150 $stream,
151 "images/" . $image
152 );
153 }

◆ deleteImageByFilename()

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

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

177 : void
178 {
179 $dir = $this->dir($style_id);
180 $this->web_files->delete($dir . "/" . $filename);
181 }
$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 
)

Get images of style.

Parameters
int$style_id
Returns
Generator
Exceptions
Filesystem

Exception\DirectoryNotFoundException

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

69 : Generator {
70 if ($rid !== "") {
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);
75
76 foreach ($unzip->getPaths() as $path) {
77 if (str_starts_with($path, ".")) {
78 continue;
79 }
80 if (!str_starts_with($path, "images")) {
81 continue;
82 }
83 if (!in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), ["jpg", "png", "gif", "svg"])) {
84 continue;
85 }
86 $att = $zip_archive->statName($path);
87 if ($include_size_info) {
88 $full_path = $this->irss->getContainerUri($rid, $path);
89 try {
90 $stream = $this->irss->getStreamOfContainerEntry($rid, $path);
91 $content = $stream->getContents();
92 $image_size = getimagesizefromstring($content);
93 } catch (\Exception $e) {
94 }
95 $width = $image_size[0] ?? 0;
96 $height = $image_size[1] ?? 0;
97 } else {
98 $width = 0;
99 $height = 0;
100 }
101 yield $this->factory->image(
102 $this->irss->getContainerUri($rid, $path),
103 new DataSize($att["size"], DataSize::KB),
104 $width,
105 $height
106 );
107 }
108 }
109
110
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(
116 $meta->getPath(),
118 );
119 $image_size = getimagesize($this->getWebPath($meta->getPath()));
120 $width = $image_size[0] ?? 0;
121 $height = $image_size[1] ?? 0;
122 yield $this->factory->image(
123 $meta->getPath(),
124 $size,
125 $width,
126 $height
127 );
128 }
129 }
130 }
131 }
$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 133 of file class.ImageFileRepo.php.

136 : ZIPStream {
137 return $this->irss->getStreamOfContainerEntry(
138 $rid,
139 "images/" . $image
140 );
141 }

◆ getWebPath()

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

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

156 : string
157 {
158 if (str_starts_with($path, "http")) {
159 return $path;
160 }
161 return ILIAS_WEB_DIR . "/" . CLIENT_ID . "/" . $path;
162 }
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45

References $path, CLIENT_ID, and ILIAS_WEB_DIR.

◆ importFromUploadResult()

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

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

186 : void {
187 $this->irss->addUploadToContainer(
188 $rid,
189 $result
190 );
191 }

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: