ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
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)
 

Protected Attributes

ImageOutputOptions $output_options
 
Images $image_converters
 
MediaObjectRepository $repo
 

Detailed Description

Definition at line 33 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  }

Member Function Documentation

◆ addFileFromLegacyUpload()

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

Definition at line 68 of file MediaObjectManager.php.

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

◆ addFileFromLocal()

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

Definition at line 81 of file MediaObjectManager.php.

81  : void
82  {
83  $this->repo->addFileFromLocal($mob_id, $tmp_name, $path);
84  }
$path
Definition: ltiservices.php:29

◆ addFileFromUpload()

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

Definition at line 73 of file MediaObjectManager.php.

References $path.

77  : void {
78  $this->repo->addFileFromUpload($mob_id, $result, $path);
79  }
$path
Definition: ltiservices.php:29

◆ addLocalDirectory()

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

Definition at line 63 of file MediaObjectManager.php.

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

◆ addPreviewFromUrl()

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

Definition at line 226 of file MediaObjectManager.php.

References $res.

230  : void {
231  $str = file_get_contents($url);
232  $res = fopen('php://memory', 'r+');
233  fwrite($res, $str);
234  rewind($res);
235  $stream = new Stream($res);
236  $this->repo->addStream(
237  $mob_id,
238  $target_location,
239  $stream
240  );
241  }
$res
Definition: ltiservices.php:66
$url
Definition: shib_logout.php:68

◆ addStream()

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

Definition at line 100 of file MediaObjectManager.php.

104  : void {
105  $this->repo->addStream($mob_id, $location, $stream);
106  }
$location
Definition: buildRTE.php:22

◆ create()

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

Definition at line 50 of file MediaObjectManager.php.

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

◆ deliverEntry()

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

Definition at line 158 of file MediaObjectManager.php.

161  : void {
162  $this->repo->deliverEntry($mob_id, $path);
163  }
$path
Definition: ltiservices.php:29

◆ generateMissingVTT()

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

Definition at line 263 of file MediaObjectManager.php.

References ILIAS\MediaObjects\MediaObjectManager\getSrtFiles(), and ILIAS\MediaObjects\MediaObjectManager\srtToVtt().

263  : void
264  {
265  $names = array_map(static function (array $i) {
266  return $i["file"];
267  }, $this->getSrtFiles($mob_id));
268  $missing_vtt = [];
269  foreach ($names as $name) {
270  if (str_ends_with($name, ".srt")) {
271  $vtt = str_replace(".srt", ".vtt", $name);
272  if (!in_array($vtt, $names) && !in_array($vtt, $missing_vtt)) {
273  $missing_vtt[] = $vtt;
274  }
275  }
276  }
277  foreach ($missing_vtt as $vtt_name) {
278  $srt_name = str_replace(".vtt", ".srt", $vtt_name);
279  $srt_content = stream_get_contents($this->repo->getLocationStream($mob_id, "srt/" . $srt_name)->detach());
280  $vtt_content = $this->srtToVtt($srt_content);
281  $this->repo->addString($mob_id, "/srt/" . $vtt_name, $vtt_content);
282  }
283  }
getSrtFiles(int $mob_id, bool $vtt_only=false)
+ Here is the call graph for this function:

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

References ilObjMediaObject\DEFAULT_PREVIEW_SIZE, ilFFmpeg\extractPNGFromVideoInZip(), and ILIAS\Filesystem\Util\Convert\ImageOutputOptions\FORMAT_PNG.

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

◆ getContainerResource()

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

Definition at line 129 of file MediaObjectManager.php.

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

◆ getContainerResourceId()

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

Definition at line 135 of file MediaObjectManager.php.

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

◆ getFilesOfPath()

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

Definition at line 141 of file MediaObjectManager.php.

Referenced by ILIAS\MediaObjects\MediaObjectManager\getSrtFiles().

144  : array {
145  return $this->repo->getFilesOfPath($mob_id, $dir_path);
146  }
+ Here is the caller graph for this function:

◆ getInfoOfEntry()

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

Definition at line 148 of file MediaObjectManager.php.

151  : array {
152  return $this->repo->getInfoOfEntry(
153  $mob_id,
154  $path
155  );
156  }
$path
Definition: ltiservices.php:29

◆ getLocalSrc()

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

Definition at line 108 of file MediaObjectManager.php.

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

Referenced by ILIAS\MediaObjects\MediaObjectManager\getSrtFiles().

108  : string
109  {
110  $src = $this->repo->getLocalSrc(
111  $mob_id,
112  $location
113  );
114  if ($src === "") { // fallback: old source
115  $path_to_file = \ilObjMediaObject::_getURL($mob_id) . "/" . $location;
116  try {
117  $src = \ilWACSignedPath::signFile($path_to_file);
118  } catch (Exception $e) {
119  }
120  }
121  return $src;
122  }
$location
Definition: buildRTE.php:22
static signFile(string $path_to_file)
static _getURL(int $a_mob_id)
get directory for files of media object
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLocationStream()

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

Definition at line 93 of file MediaObjectManager.php.

96  : ZIPStream {
97  return $this->repo->getLocationStream($mob_id, $location);
98  }
$location
Definition: buildRTE.php:22

◆ getSrtFiles()

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

Definition at line 243 of file MediaObjectManager.php.

References ILIAS\MediaObjects\MediaObjectManager\getFilesOfPath(), and ILIAS\MediaObjects\MediaObjectManager\getLocalSrc().

Referenced by ILIAS\MediaObjects\MediaObjectManager\generateMissingVTT().

243  : array
244  {
245  $srt_files = [];
246  $valid_suffixes = $vtt_only
247  ? ["vtt"]
248  : ["srt", "vtt"];
249  foreach ($this->getFilesOfPath($mob_id, "/srt") as $i) {
250  $name = explode(".", $i["basename"]);
251  if (in_array($name[1], $valid_suffixes) && substr($name[0], 0, 9) == "subtitle_") {
252  $srt_files[] = [
253  "file" => $i["basename"],
254  "full_path" => $i["path"],
255  "src" => $this->getLocalSrc($mob_id, $i["path"]),
256  "language" => substr($name[0], 9, 2)
257  ];
258  }
259  }
260  return $srt_files;
261  }
getLocalSrc(int $mob_id, string $location)
getFilesOfPath(int $mob_id, string $dir_path)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasLocalFile()

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

Definition at line 124 of file MediaObjectManager.php.

124  : bool
125  {
126  return $this->repo->hasLocalFile($mob_id, $location);
127  }
$location
Definition: buildRTE.php:22

◆ removeLocation()

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

Definition at line 86 of file MediaObjectManager.php.

89  : void {
90  $this->repo->removeLocation($mob_id, $location);
91  }
$location
Definition: buildRTE.php:22

◆ srtToVtt()

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

Definition at line 285 of file MediaObjectManager.php.

Referenced by ILIAS\MediaObjects\MediaObjectManager\generateMissingVTT().

285  : string
286  {
287  // Remove UTF-8 BOM if present
288  $srt_text = preg_replace('/^\xEF\xBB\xBF/', '', $srt_text);
289 
290  // Normalise line-endings and split cues
291  $srt_text = preg_replace('~\r\n?~', "\n", $srt_text);
292  $blocks = preg_split("/\n{2,}/", trim($srt_text));
293 
294  $vttLines = ['WEBVTT', '']; // header + blank line
295 
296  foreach ($blocks as $block) {
297  $lines = explode("\n", $block);
298 
299  if (count($lines) < 2) {
300  continue; // malformed cue
301  }
302 
303  /* cue number? allow BOM or spaces either side */
304  if (preg_match('/^\s*\d+\s*$/u', $lines[0])) {
305  array_shift($lines); // drop it
306  }
307 
308  /* now $lines[0] *is* the time-code line → , → . */
309  $lines[0] = preg_replace(
310  '/(\d{2}:\d{2}:\d{2}),(\d{3})/',
311  '$1.$2',
312  $lines[0]
313  );
314 
315  $vttLines = array_merge($vttLines, $lines, ['']);
316  }
317 
318  return implode("\n", $vttLines);
319  }
+ Here is the caller graph for this function:

Field Documentation

◆ $image_converters

Images ILIAS\MediaObjects\MediaObjectManager::$image_converters
protected

Definition at line 36 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

Definition at line 37 of file MediaObjectManager.php.


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