ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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)
 
 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")
 
 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 }
$path
Definition: ltiservices.php:30

References $path.

◆ 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 227 of file MediaObjectManager.php.

231 : void {
233 try {
234 $log->debug('Trying to fetch thumbnail from URL: {thumbnail_url}', [
235 'thumbnail_url' => $url,
236 ]);
237 $curl = new \ilCurlConnection($url);
238 $curl->init(true);
239 $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
240 $curl->setOpt(CURLOPT_VERBOSE, true);
241 $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
242 $curl->setOpt(CURLOPT_TIMEOUT_MS, 5000);
243 $curl->setOpt(CURLOPT_TIMEOUT, 5);
244 $curl->setOpt(CURLOPT_FAILONERROR, true);
245 $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
246 $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
247
248 $str = $curl->exec();
249 $info = $curl->getInfo();
250
251 $log->debug('cURL Info: {info}', [
252 'info' => print_r($info, true)
253 ]);
254
255 $status = $info['http_code'] ?? '';
256 if ((int) $status === 200) {
257 $log->debug('Successfully fetched preview file from URL: Received {bytes} bytes', [
258 'bytes' => (string) strlen($str),
259 ]);
260 } else {
261 $log->error('Could not fetch thumbnail from YouTube: {thumbnail_url}', [
262 'thumbnail_url' => $url,
263 ]);
264 }
265
266 $res = fopen('php://memory', 'r+');
267 fwrite($res, $str);
268 rewind($res);
269 $stream = new Stream($res);
270 $this->repo->addStream(
271 $mob_id,
272 $target_location,
273 $stream
274 );
275 } catch (\Exception $e) {
276 $log->error('Could not fetch thumbnail from Url: {message}', [
277 'message' => $e->getMessage(),
278 ]);
279 $log->error($e->getTraceAsString());
280 }
281 }
$info
Definition: entry_point.php:21
$log
Definition: ltiresult.php:34
$res
Definition: ltiservices.php:69
$url
Definition: shib_logout.php:68

References $info, $log, $res, and $url.

◆ addStream()

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

Definition at line 101 of file MediaObjectManager.php.

105 : void {
106 $this->repo->addStream($mob_id, $location, $stream);
107 }
$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 159 of file MediaObjectManager.php.

162 : void {
163 $this->repo->deliverEntry($mob_id, $path);
164 }

◆ generateMissingVTT()

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

Definition at line 303 of file MediaObjectManager.php.

303 : void
304 {
305 $names = array_map(static function (array $i) {
306 return $i["file"];
307 }, $this->getSrtFiles($mob_id));
308 $missing_vtt = [];
309 foreach ($names as $name) {
310 if (str_ends_with($name, ".srt")) {
311 $vtt = str_replace(".srt", ".vtt", $name);
312 if (!in_array($vtt, $names) && !in_array($vtt, $missing_vtt)) {
313 $missing_vtt[] = $vtt;
314 }
315 }
316 }
317 foreach ($missing_vtt as $vtt_name) {
318 $srt_name = str_replace(".vtt", ".srt", $vtt_name);
319 $srt_content = stream_get_contents($this->repo->getLocationStream($mob_id, "srt/" . $srt_name)->detach());
320 $vtt_content = $this->srtToVtt($srt_content);
321 $this->repo->addString($mob_id, "/srt/" . $vtt_name, $vtt_content);
322 }
323 }
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 167 of file MediaObjectManager.php.

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

◆ getContainerResource()

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

Definition at line 130 of file MediaObjectManager.php.

132 : ?StorableResource {
133 return $this->repo->getContainerResource($mob_id);
134 }

◆ getContainerResourceId()

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

Definition at line 136 of file MediaObjectManager.php.

138 : ?ResourceIdentification {
139 return $this->repo->getContainerResourceId($mob_id);
140 }

◆ getFilesOfPath()

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

Definition at line 142 of file MediaObjectManager.php.

145 : array {
146 return $this->repo->getFilesOfPath($mob_id, $dir_path);
147 }

◆ getInfoOfEntry()

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

Definition at line 149 of file MediaObjectManager.php.

152 : array {
153 return $this->repo->getInfoOfEntry(
154 $mob_id,
155 $path
156 );
157 }

◆ getLastChangeTimestamp()

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

Definition at line 361 of file MediaObjectManager.php.

361 : int
362 {
363 return $this->repo->getLastChangeTimestamp($mob_id);
364 }

◆ getLocalSrc()

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

Definition at line 109 of file MediaObjectManager.php.

109 : string
110 {
111 $src = $this->repo->getLocalSrc(
112 $mob_id,
114 );
115 if ($src === "") { // fallback: old source
116 $path_to_file = \ilObjMediaObject::_getURL($mob_id) . "/" . $location;
117 try {
118 $src = \ilWACSignedPath::signFile($path_to_file);
119 } catch (\Exception $e) {
120 }
121 }
122 return $src;
123 }
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:

◆ 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 283 of file MediaObjectManager.php.

283 : array
284 {
285 $srt_files = [];
286 $valid_suffixes = $vtt_only
287 ? ["vtt"]
288 : ["srt", "vtt"];
289 foreach ($this->getFilesOfPath($mob_id, "/srt") as $i) {
290 $name = explode(".", $i["basename"]);
291 if (in_array($name[1], $valid_suffixes) && substr($name[0], 0, 9) == "subtitle_") {
292 $srt_files[] = [
293 "file" => $i["basename"],
294 "full_path" => $i["path"],
295 "src" => $this->getLocalSrc($mob_id, $i["path"]),
296 "language" => substr($name[0], 9, 2)
297 ];
298 }
299 }
300 return $srt_files;
301 }
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 125 of file MediaObjectManager.php.

125 : bool
126 {
127 return $this->repo->hasLocalFile($mob_id, $location);
128 }

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 }

◆ srtToVtt()

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

Definition at line 325 of file MediaObjectManager.php.

325 : string
326 {
327 // Remove UTF-8 BOM if present
328 $srt_text = preg_replace('/^\xEF\xBB\xBF/', '', $srt_text);
329
330 // Normalise line-endings and split cues
331 $srt_text = preg_replace('~\r\n?~', "\n", $srt_text);
332 $blocks = preg_split("/\n{2,}/", trim($srt_text));
333
334 $vttLines = ['WEBVTT', '']; // header + blank line
335
336 foreach ($blocks as $block) {
337 $lines = explode("\n", $block);
338
339 if (count($lines) < 2) {
340 continue; // malformed cue
341 }
342
343 /* cue number? allow BOM or spaces either side */
344 if (preg_match('/^\s*\d+\s*$/u', $lines[0])) {
345 array_shift($lines); // drop it
346 }
347
348 /* now $lines[0] *is* the time-code line → , → . */
349 $lines[0] = preg_replace(
350 '/(\d{2}:\d{2}:\d{2}),(\d{3})/',
351 '$1.$2',
352 $lines[0]
353 );
354
355 $vttLines = array_merge($vttLines, $lines, ['']);
356 }
357
358 return implode("\n", $vttLines);
359 }

◆ updateLastChange()

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

Definition at line 366 of file MediaObjectManager.php.

366 : void
367 {
368 $this->repo->updateLastChangeTimestamp($mob_id, time());
369 }

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: