ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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)
 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 135 of file class.ImageFileRepo.php.

139  : void {
140  $this->irss->addStreamToContainer(
141  $rid,
142  $stream,
143  "images/" . $image
144  );
145  }

◆ deleteImageByFilename()

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

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

References ILIAS\Style\Content\ImageFileRepo\dir().

169  : void
170  {
171  $dir = $this->dir($style_id);
172  $this->web_files->delete($dir . "/" . $filename);
173  }
$filename
Definition: buildRTE.php:78
+ Here is the call graph for this function:

◆ dir()

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

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

Referenced by ILIAS\Style\Content\ImageFileRepo\deleteImageByFilename(), and ILIAS\Style\Content\ImageFileRepo\getImages().

54  : string
55  {
56  return str_replace("%id%", (string) $style_id, self::DIR_PATH);
57  }
+ Here is the caller graph for this function:

◆ getImages()

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

Get images of style.

Parameters
int$style_id
Returns
Generator
Exceptions
Filesystem

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

References Vendor\Package\$e, $path, ILIAS\Style\Content\ImageFileRepo\dir(), factory(), ILIAS\Style\Content\ImageFileRepo\getWebPath(), and ILIAS\Data\DataSize\KB.

Referenced by ILIAS\Style\Content\ImageFileRepo\getWebPath().

68  : Generator {
69  if ($rid !== "") {
70  $unzip = $this->irss->getContainerZip($rid);
71  $uri = $this->irss->stream($rid)->getMetadata("uri");
72  $zip_archive = new \ZipArchive();
73  $zip_archive->open($uri, \ZipArchive::RDONLY);
74 
75  foreach ($unzip->getPaths() as $path) {
76  if (str_starts_with($path, ".")) {
77  continue;
78  }
79  if (!str_starts_with($path, "images")) {
80  continue;
81  }
82  if (!in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), ["jpg", "png", "gif", "svg"])) {
83  continue;
84  }
85  $att = $zip_archive->statName($path);
86  $full_path = $this->irss->getContainerUri($rid, $path);
87  try {
88  $image_size = getimagesize($full_path);
89  } catch (\Exception $e) {
90  }
91  $width = $image_size[0] ?? 0;
92  $height = $image_size[1] ?? 0;
93  yield $this->factory->image(
94  $this->irss->getContainerUri($rid, $path),
95  new DataSize($att["size"], DataSize::KB),
96  $width,
97  $height
98  );
99  }
100  }
101 
102 
103  $dir = $this->dir($style_id);
104  if ($this->web_files->hasDir($dir)) {
105  foreach ($this->web_files->listContents($dir) as $meta) {
106  if ($meta->isFile()) {
107  $size = $this->web_files->getSize(
108  $meta->getPath(),
110  );
111  $image_size = getimagesize($this->getWebPath($meta->getPath()));
112  $width = $image_size[0] ?? 0;
113  $height = $image_size[1] ?? 0;
114  yield $this->factory->image(
115  $meta->getPath(),
116  $size,
117  $width,
118  $height
119  );
120  }
121  }
122  }
123  }
factory()
$path
Definition: ltiservices.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageStream()

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

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

128  : ZIPStream {
129  return $this->irss->getStreamOfContainerEntry(
130  $rid,
131  "images/" . $image
132  );
133  }

◆ getWebPath()

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

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

References $filename, $path, CLIENT_ID, ILIAS\Style\Content\ImageFileRepo\getImages(), ILIAS_WEB_DIR, and null.

Referenced by ILIAS\Style\Content\ImageFileRepo\getImages().

148  : string
149  {
150  if (str_starts_with($path, "http")) {
151  return $path;
152  }
153  return ILIAS_WEB_DIR . "/" . CLIENT_ID . "/" . $path;
154  }
$path
Definition: ltiservices.php:29
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importFromUploadResult()

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

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

178  : void {
179  $this->irss->addUploadToContainer(
180  $rid,
181  $result
182  );
183  }

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: