ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\MediaObjects\MediaObjectManager Class Reference
+ Collaboration diagram for ILIAS\MediaObjects\MediaObjectManager:

Public Member Functions

 __construct (protected InternalDataService $data, InternalRepoService $repo, protected InternalDomainService $domain, protected \ilMobStakeholder $stakeholder)
 
 create (int $id, string $title, int $from_mob_id=0)
 
 addLocalDirectory (int $mob_id, string $dir)
 
 addFileFromLegacyUpload (int $mob_id, string $tmp_name, string $target_path="")
 
 addFileFromUpload (int $mob_id, UploadResult $result, string $path="/")
 
 addFileFromLocal (int $mob_id, string $tmp_name, string $path)
 
 removeLocation (int $mob_id, string $location)
 
 getLocationStream (int $mob_id, string $location)
 
 getLocationContent (int $mob_id, string $location)
 
 addStream (int $mob_id, string $location, FileStream $stream)
 
 getLocalSrc (int $mob_id, string $location)
 
 hasLocalFile (int $mob_id, string $location)
 
 getContainerResource (int $mob_id)
 
 getContainerResourceId (int $mob_id)
 
 getFilesOfPath (int $mob_id, string $dir_path)
 
 getInfoOfEntry (int $mob_id, string $path)
 
 deliverEntry (int $mob_id, string $path)
 
 generatePreview (int $mob_id, string $location, bool $local, string $format, int $sec=1, string $target_location="mob_vpreview.png")
 
 resizeImage (int $mob_id, string $location, string $format, int $width, int $height, bool $a_constrain_prop=false)
 
 addPreviewFromUrl (int $mob_id, string $url, string $target_location)
 
 getSrtFiles (int $mob_id, bool $vtt_only=false)
 
 generateMissingVTT (int $mob_id)
 
 srtToVtt (string $srt_text)
 
 getLastChangeTimestamp (int $mob_id)
 
 updateLastChange (int $mob_id)
 

Protected Attributes

ilLogger $logger
 
ImageOutputOptions $output_options
 
Images $image_converters
 
MediaObjectRepository $repo
 

Detailed Description

Definition at line 32 of file MediaObjectManager.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MediaObjects\MediaObjectManager::__construct ( protected InternalDataService  $data,
InternalRepoService  $repo,
protected InternalDomainService  $domain,
protected \ilMobStakeholder  $stakeholder 
)

Definition at line 39 of file MediaObjectManager.php.

44 {
45 $this->repo = $repo->mediaObject();
46 $this->image_converters = new Images(true);
47 $this->output_options = new ImageOutputOptions();
48 $this->logger = \ilLoggerFactory::getLogger('mob');
49 }
static getLogger(string $a_component_id)
Get component logger.

References ILIAS\MediaObjects\MediaObjectManager\$repo, ilLoggerFactory\getLogger(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ addFileFromLegacyUpload()

ILIAS\MediaObjects\MediaObjectManager::addFileFromLegacyUpload ( int  $mob_id,
string  $tmp_name,
string  $target_path = "" 
)

Definition at line 69 of file MediaObjectManager.php.

69 : void
70 {
71 $this->repo->addFileFromLegacyUpload($mob_id, $tmp_name, $target_path);
72 }

◆ addFileFromLocal()

ILIAS\MediaObjects\MediaObjectManager::addFileFromLocal ( int  $mob_id,
string  $tmp_name,
string  $path 
)

Definition at line 82 of file MediaObjectManager.php.

82 : void
83 {
84 $this->repo->addFileFromLocal($mob_id, $tmp_name, $path);
85 }

◆ addFileFromUpload()

ILIAS\MediaObjects\MediaObjectManager::addFileFromUpload ( int  $mob_id,
UploadResult  $result,
string  $path = "/" 
)

Definition at line 74 of file MediaObjectManager.php.

78 : void {
79 $this->repo->addFileFromUpload($mob_id, $result, $path);
80 }

◆ addLocalDirectory()

ILIAS\MediaObjects\MediaObjectManager::addLocalDirectory ( int  $mob_id,
string  $dir 
)

Definition at line 64 of file MediaObjectManager.php.

64 : void
65 {
66 $this->repo->addLocalDirectory($mob_id, $dir);
67 }

◆ addPreviewFromUrl()

ILIAS\MediaObjects\MediaObjectManager::addPreviewFromUrl ( int  $mob_id,
string  $url,
string  $target_location 
)

Definition at line 284 of file MediaObjectManager.php.

288 : void {
290 try {
291 $log->debug('Trying to fetch thumbnail from URL: {thumbnail_url}', [
292 'thumbnail_url' => $url,
293 ]);
294 $curl = new \ilCurlConnection($url);
295 $curl->init(true);
296 $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
297 $curl->setOpt(CURLOPT_VERBOSE, true);
298 $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
299 $curl->setOpt(CURLOPT_TIMEOUT_MS, 5000);
300 $curl->setOpt(CURLOPT_TIMEOUT, 5);
301 $curl->setOpt(CURLOPT_FAILONERROR, true);
302 $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
303 $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
304
305 $str = $curl->exec();
306 $info = $curl->getInfo();
307
308 $log->debug('cURL Info: {info}', [
309 'info' => print_r($info, true)
310 ]);
311
312 $status = $info['http_code'] ?? '';
313 if ((int) $status === 200) {
314 $log->debug('Successfully fetched preview file from URL: Received {bytes} bytes', [
315 'bytes' => (string) strlen($str),
316 ]);
317 } else {
318 $log->error('Could not fetch thumbnail from YouTube: {thumbnail_url}', [
319 'thumbnail_url' => $url,
320 ]);
321 }
322
323 $res = fopen('php://memory', 'r+');
324 fwrite($res, $str);
325 rewind($res);
326 $stream = new Stream($res);
327 $this->repo->addStream(
328 $mob_id,
329 $target_location,
330 $stream
331 );
332 } catch (\Exception $e) {
333 $log->error('Could not fetch thumbnail from Url: {message}', [
334 'message' => $e->getMessage(),
335 ]);
336 $log->error($e->getTraceAsString());
337 }
338 }
$info
Definition: entry_point.php:21
$log
Definition: ltiauth.php:50
foreach($_POST as $key=> $value) $res

References $info, $log, and $res.

◆ addStream()

ILIAS\MediaObjects\MediaObjectManager::addStream ( int  $mob_id,
string  $location,
FileStream  $stream 
)

Definition at line 108 of file MediaObjectManager.php.

112 : void {
113 $this->repo->addStream($mob_id, $location, $stream);
114 }
$location
Definition: buildRTE.php:22

◆ create()

ILIAS\MediaObjects\MediaObjectManager::create ( int  $id,
string  $title,
int  $from_mob_id = 0 
)

Definition at line 51 of file MediaObjectManager.php.

55 : void {
56 $this->repo->create(
57 $id,
58 $title,
59 $this->stakeholder,
60 $from_mob_id
61 );
62 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ deliverEntry()

ILIAS\MediaObjects\MediaObjectManager::deliverEntry ( int  $mob_id,
string  $path 
)

Definition at line 166 of file MediaObjectManager.php.

169 : void {
170 $this->repo->deliverEntry($mob_id, $path);
171 }

◆ generateMissingVTT()

ILIAS\MediaObjects\MediaObjectManager::generateMissingVTT ( int  $mob_id)

Definition at line 360 of file MediaObjectManager.php.

360 : void
361 {
362 $names = array_map(static function (array $i) {
363 return $i["file"];
364 }, $this->getSrtFiles($mob_id));
365 $missing_vtt = [];
366 foreach ($names as $name) {
367 if (str_ends_with($name, ".srt")) {
368 $vtt = str_replace(".srt", ".vtt", $name);
369 if (!in_array($vtt, $names) && !in_array($vtt, $missing_vtt)) {
370 $missing_vtt[] = $vtt;
371 }
372 }
373 }
374 foreach ($missing_vtt as $vtt_name) {
375 $srt_name = str_replace(".vtt", ".srt", $vtt_name);
376 $srt_content = stream_get_contents($this->repo->getLocationStream($mob_id, "srt/" . $srt_name)->detach());
377 $vtt_content = $this->srtToVtt($srt_content);
378 $this->repo->addString($mob_id, "/srt/" . $vtt_name, $vtt_content);
379 }
380 }
getSrtFiles(int $mob_id, bool $vtt_only=false)

◆ generatePreview()

ILIAS\MediaObjects\MediaObjectManager::generatePreview ( int  $mob_id,
string  $location,
bool  $local,
string  $format,
int  $sec = 1,
string  $target_location = "mob_vpreview.png" 
)

Definition at line 174 of file MediaObjectManager.php.

181 : void {
182
183 $is_image = is_int(strpos($format, "image/"));
184 $is_video = in_array($format, ["video/mp4", "video/webm"]);
185
186 if ($local) {
187 if ($is_image) {
189 $image_quality = 60;
190
191 // the zip stream is not seekable, which is needed by Imagick
192 // so we create a seekable stream first
193 $tempStream = fopen('php://temp', 'w+');
194 stream_copy_to_stream($this->repo->getLocationStream($mob_id, $location)->detach(), $tempStream);
195 rewind($tempStream);
196 $stream = new Stream($tempStream);
197
198 $converter = $this->image_converters->resizeToFixedSize(
199 $stream,
200 $width,
201 $height,
202 true,
203 $this->output_options
204 ->withQuality($image_quality)
206 );
207 $this->repo->addStream(
208 $mob_id,
209 $target_location,
210 $converter->getStream()
211 );
212 fclose($tempStream);
213 }
214 if ($is_video) {
215 $zip_uri = $this->repo->getContainerPath($mob_id);
217 $zip_uri,
218 $location,
219 $sec
220 );
221 if ($image_str === "") {
222 return;
223 }
224 $png_res = fopen('php://memory', 'r+');
225 fwrite($png_res, $image_str);
226 rewind($png_res);
227 $png_stream = new Stream($png_res);
228 $this->repo->addStream(
229 $mob_id,
230 $target_location,
231 $png_stream
232 );
233 }
234 }
235 }
static extractPNGFromVideoInZip(string $zip, string $path, int $sec=1)

◆ getContainerResource()

ILIAS\MediaObjects\MediaObjectManager::getContainerResource ( int  $mob_id)

Definition at line 137 of file MediaObjectManager.php.

139 : ?StorableResource {
140 return $this->repo->getContainerResource($mob_id);
141 }

◆ getContainerResourceId()

ILIAS\MediaObjects\MediaObjectManager::getContainerResourceId ( int  $mob_id)

Definition at line 143 of file MediaObjectManager.php.

145 : ?ResourceIdentification {
146 return $this->repo->getContainerResourceId($mob_id);
147 }

◆ getFilesOfPath()

ILIAS\MediaObjects\MediaObjectManager::getFilesOfPath ( int  $mob_id,
string  $dir_path 
)

Definition at line 149 of file MediaObjectManager.php.

152 : array {
153 return $this->repo->getFilesOfPath($mob_id, $dir_path);
154 }

◆ getInfoOfEntry()

ILIAS\MediaObjects\MediaObjectManager::getInfoOfEntry ( int  $mob_id,
string  $path 
)

Definition at line 156 of file MediaObjectManager.php.

159 : array {
160 return $this->repo->getInfoOfEntry(
161 $mob_id,
162 $path
163 );
164 }

◆ getLastChangeTimestamp()

ILIAS\MediaObjects\MediaObjectManager::getLastChangeTimestamp ( int  $mob_id)

Definition at line 418 of file MediaObjectManager.php.

418 : int
419 {
420 return $this->repo->getLastChangeTimestamp($mob_id);
421 }

◆ getLocalSrc()

ILIAS\MediaObjects\MediaObjectManager::getLocalSrc ( int  $mob_id,
string  $location 
)

Definition at line 116 of file MediaObjectManager.php.

116 : string
117 {
118 $src = $this->repo->getLocalSrc(
119 $mob_id,
121 );
122 if ($src === "") { // fallback: old source
123 $path_to_file = \ilObjMediaObject::_getURL($mob_id) . "/" . $location;
124 try {
125 $src = \ilWACSignedPath::signFile($path_to_file);
126 } catch (\Exception $e) {
127 }
128 }
129 return $src;
130 }
static _getURL(int $a_mob_id)
get directory for files of media object
static signFile(string $path_to_file)

References Vendor\Package\$e, $location, ilObjMediaObject\_getURL(), and ilWACSignedPath\signFile().

+ Here is the call graph for this function:

◆ getLocationContent()

ILIAS\MediaObjects\MediaObjectManager::getLocationContent ( int  $mob_id,
string  $location 
)

Definition at line 101 of file MediaObjectManager.php.

104 : string {
105 return $this->repo->getLocationContent($mob_id, $location);
106 }

◆ getLocationStream()

ILIAS\MediaObjects\MediaObjectManager::getLocationStream ( int  $mob_id,
string  $location 
)

Definition at line 94 of file MediaObjectManager.php.

97 : ZIPStream {
98 return $this->repo->getLocationStream($mob_id, $location);
99 }

◆ getSrtFiles()

ILIAS\MediaObjects\MediaObjectManager::getSrtFiles ( int  $mob_id,
bool  $vtt_only = false 
)

Definition at line 340 of file MediaObjectManager.php.

340 : array
341 {
342 $srt_files = [];
343 $valid_suffixes = $vtt_only
344 ? ["vtt"]
345 : ["srt", "vtt"];
346 foreach ($this->getFilesOfPath($mob_id, "/srt") as $i) {
347 $name = explode(".", $i["basename"]);
348 if (in_array($name[1], $valid_suffixes) && substr($name[0], 0, 9) == "subtitle_") {
349 $srt_files[] = [
350 "file" => $i["basename"],
351 "full_path" => $i["path"],
352 "src" => $this->getLocalSrc($mob_id, $i["path"]),
353 "language" => substr($name[0], 9, 2)
354 ];
355 }
356 }
357 return $srt_files;
358 }
getLocalSrc(int $mob_id, string $location)
getFilesOfPath(int $mob_id, string $dir_path)

◆ hasLocalFile()

ILIAS\MediaObjects\MediaObjectManager::hasLocalFile ( int  $mob_id,
string  $location 
)

Definition at line 132 of file MediaObjectManager.php.

132 : bool
133 {
134 return $this->repo->hasLocalFile($mob_id, $location);
135 }

References $location.

◆ removeLocation()

ILIAS\MediaObjects\MediaObjectManager::removeLocation ( int  $mob_id,
string  $location 
)

Definition at line 87 of file MediaObjectManager.php.

90 : void {
91 $this->repo->removeLocation($mob_id, $location);
92 }

◆ resizeImage()

ILIAS\MediaObjects\MediaObjectManager::resizeImage ( int  $mob_id,
string  $location,
string  $format,
int  $width,
int  $height,
bool  $a_constrain_prop = false 
)

Definition at line 237 of file MediaObjectManager.php.

244 : string {
245
246 if (!is_int(strpos($format, "image/"))) {
247 return "";
248 }
249
250 $file_path = pathinfo($location);
251 $new_location = substr($file_path["basename"], 0, strlen($file_path["basename"]) -
252 strlen($file_path["extension"]) - 1) . "_" .
253 $width . "_" .
254 $height . "." . $file_path["extension"];
255
256
257 $image_quality = 60;
258
259 // the zip stream is not seekable, which is needed by Imagick
260 // so we create a seekable stream first
261 $tempStream = fopen('php://temp', 'w+');
262 stream_copy_to_stream($this->repo->getLocationStream($mob_id, $location)->detach(), $tempStream);
263 rewind($tempStream);
264 $stream = new Stream($tempStream);
265
266 $converter = $this->image_converters->resizeToFixedSize(
267 $stream,
268 $width,
269 $height,
270 false,
271 $this->output_options
272 //->withQuality($image_quality)
273 //->withFormat(ImageOutputOptions::FORMAT_PNG)
274 );
275 $this->repo->addStream(
276 $mob_id,
277 $new_location,
278 $converter->getStream()
279 );
280 fclose($tempStream);
281 return $new_location;
282 }

◆ srtToVtt()

ILIAS\MediaObjects\MediaObjectManager::srtToVtt ( string  $srt_text)

Definition at line 382 of file MediaObjectManager.php.

382 : string
383 {
384 // Remove UTF-8 BOM if present
385 $srt_text = preg_replace('/^\xEF\xBB\xBF/', '', $srt_text);
386
387 // Normalise line-endings and split cues
388 $srt_text = preg_replace('~\r\n?~', "\n", $srt_text);
389 $blocks = preg_split("/\n{2,}/", trim($srt_text));
390
391 $vttLines = ['WEBVTT', '']; // header + blank line
392
393 foreach ($blocks as $block) {
394 $lines = explode("\n", $block);
395
396 if (count($lines) < 2) {
397 continue; // malformed cue
398 }
399
400 /* cue number? allow BOM or spaces either side */
401 if (preg_match('/^\s*\d+\s*$/u', $lines[0])) {
402 array_shift($lines); // drop it
403 }
404
405 /* now $lines[0] *is* the time-code line → , → . */
406 $lines[0] = preg_replace(
407 '/(\d{2}:\d{2}:\d{2}),(\d{3})/',
408 '$1.$2',
409 $lines[0]
410 );
411
412 $vttLines = array_merge($vttLines, $lines, ['']);
413 }
414
415 return implode("\n", $vttLines);
416 }

◆ updateLastChange()

ILIAS\MediaObjects\MediaObjectManager::updateLastChange ( int  $mob_id)

Definition at line 423 of file MediaObjectManager.php.

423 : void
424 {
425 $this->repo->updateLastChangeTimestamp($mob_id, time());
426 }

Field Documentation

◆ $image_converters

Images ILIAS\MediaObjects\MediaObjectManager::$image_converters
protected

Definition at line 36 of file MediaObjectManager.php.

◆ $logger

ilLogger ILIAS\MediaObjects\MediaObjectManager::$logger
protected

Definition at line 34 of file MediaObjectManager.php.

◆ $output_options

ImageOutputOptions ILIAS\MediaObjects\MediaObjectManager::$output_options
protected

Definition at line 35 of file MediaObjectManager.php.

◆ $repo

MediaObjectRepository ILIAS\MediaObjects\MediaObjectManager::$repo
protected

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