ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjMediaObjectGUI.php
Go to the documentation of this file.
1 <?php
2 
23 
31 {
32  protected \ILIAS\MediaObjects\MediaObjectManager $media_manager;
33  protected \ILIAS\MediaObjects\Video\GUIService $video_gui;
37  protected int $height_preset = 0;
38  protected int $width_preset = 0;
39  protected string $back_title = "";
41  protected ilHelpGUI $help;
42  protected ilTabsGUI $tabs;
43  protected MetadataManager $md;
44 
45  // $adv_ref_id - $adv_type - $adv_subtype:
46  // Object, that defines the adv md records being used. Default is $this->object, but the
47  // context may set another object (e.g. media pool for media objects)
48  protected ?int $adv_ref_id = null;
49  protected ?string $adv_type = null;
50  protected ?string $adv_subtype = null;
51  protected \ILIAS\MediaObjects\MediaType\MediaTypeManager $media_type;
52  public string $header = "";
53  public string $target_script = "";
54  public bool $enabledmapareas = true;
55 
59  public function __construct(
60  $a_data,
61  int $a_id = 0,
62  bool $a_call_by_reference = false,
63  bool $a_prepare_output = false
64  ) {
65  global $DIC;
66 
67  $this->access = $DIC->access();
68  $this->error = $DIC["ilErr"];
69  $this->help = $DIC["ilHelp"];
70  $this->tabs = $DIC->tabs();
71  $this->toolbar = $DIC->toolbar();
72  $this->user = $DIC->user();
73  $lng = $DIC->language();
74  $ilCtrl = $DIC->ctrl();
75  $domain = $DIC->mediaObjects()
76  ->internal()
77  ->domain();
78  $this->media_type = $domain->mediaType();
79 
80  $this->ctrl = $ilCtrl;
81  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
82  $this->lng = $lng;
83  $this->back_title = "";
84  $this->type = "mob";
85 
86  $this->sub_title_request = $DIC->mediaObjects()
87  ->internal()
88  ->gui()
89  ->subTitles()
90  ->request();
91 
92  $lng->loadLanguageModule("mob");
93  $this->file_service_settings = $DIC->fileServiceSettings();
94  $this->video_gui = $DIC->mediaObjects()->internal()->gui()->video();
95  $this->md = $DIC->mediaObjects()->internal()->domain()->metadata();
96  $this->media_manager = $domain->mediaObject();
97  }
98 
103  public function setAdvMdRecordObject(
104  int $a_adv_ref_id,
105  string $a_adv_type,
106  string $a_adv_subtype = "-"
107  ): void {
108  $this->adv_ref_id = $a_adv_ref_id;
109  $this->adv_type = $a_adv_type;
110  $this->adv_subtype = $a_adv_subtype;
111  }
112 
117  public function getAdvMdRecordObject(): ?array
118  {
119  if ($this->adv_type == null) {
120  throw new ilMediaObjectsException("Missing obj type (getAdvMdRecordObject)");
121  // seems to be obsolete, since $this->obj_type is non-existent
122  //return [$this->ref_id, $this->obj_type, $this->sub_type];
123  }
125  }
126 
127  public function setHeader(
128  string $a_title = ""
129  ): void {
130  $this->header = $a_title;
131  }
132 
133  public function getHeader(): string
134  {
135  return $this->header;
136  }
137 
138  public function setEnabledMapAreas(
139  bool $a_enabledmapareas
140  ): void {
141  $this->enabledmapareas = $a_enabledmapareas;
142  }
143 
144  public function getEnabledMapAreas(): bool
145  {
146  return $this->enabledmapareas;
147  }
148 
152  public function setWidthPreset(int $a_val): void
153  {
154  $this->width_preset = $a_val;
155  }
156 
157  public function getWidthPreset(): int
158  {
159  return $this->width_preset;
160  }
161 
165  public function setHeightPreset(int $a_val): void
166  {
167  $this->height_preset = $a_val;
168  }
169 
170  public function getHeightPreset(): int
171  {
172  return $this->height_preset;
173  }
174 
175  public function getForm(): ilPropertyFormGUI
176  {
177  return $this->form_gui;
178  }
179 
180  protected function assignObject(): void
181  {
182  if ($this->id != 0) {
183  $this->object = new ilObjMediaObject($this->id);
184  }
185  }
186 
190  public function returnToContextObject(): void
191  {
192  $this->ctrl->returnToParent($this);
193  }
194 
198  public function executeCommand(): void
199  {
200  $tpl = $this->tpl;
201 
202  $next_class = $this->ctrl->getNextClass($this);
203  $cmd = $this->ctrl->getCmd();
204  $ret = "";
205 
206  switch ($next_class) {
207  case 'ilobjectmetadatagui':
208  $md_gui = new ilObjectMetaDataGUI(null, $this->object->getType(), $this->object->getId());
209  // object is subtype, so we have to do it ourselves
210  $md_gui->addMDObserver($this->object, 'MDUpdateListener', 'General');
211 
212  // set adv metadata record dobject
213  if ($this->adv_type != "") {
214  $md_gui->setAdvMdRecordObject($this->adv_ref_id, $this->adv_type, $this->adv_subtype);
215  }
216 
217  $this->ctrl->forwardCommand($md_gui);
218  break;
219 
220  case "ilimagemapeditorgui":
222  $mob = $this->object;
223  $image_map_edit = new ilImageMapEditorGUI($mob);
224  $ret = $this->ctrl->forwardCommand($image_map_edit);
225  $tpl->setContent($ret);
226  $this->checkFixSize();
227  break;
228 
229  case strtolower(ilContainerResourceGUI::class):
230  $res = $this->media_manager->getContainerResource($this->object->getId());
231  // Build the view configuration
232  $view_configuration = new Configuration(
233  $res,
234  new ilMobStakeholder(),
235  $this->lng->txt('files'),
237  250,
238  true,
239  true
240  );
241 
242  // build the collection GUI
243  $container_gui = new ilContainerResourceGUI(
244  $view_configuration
245  );
246 
247  // forward the command
248  $this->ctrl->forwardCommand($container_gui);
249  break;
250 
251  default:
252  $cmd .= "Object";
253  $ret = $this->$cmd();
254  break;
255  }
256  }
257 
258  public function setBackTitle(string $a_title): void
259  {
260  $this->back_title = $a_title;
261  }
262 
263  public function createObject(): void
264  {
265  $tpl = $this->tpl;
266  $ilHelp = $this->help;
267 
268  $ilHelp->setScreenId("create");
269  $this->initForm();
270  $tpl->setContent($this->form_gui->getHTML());
271  }
272 
273  public function initForm(string $a_mode = "create"): void
274  {
275  $lng = $this->lng;
276  $ilCtrl = $this->ctrl;
277  $add_str = "";
278 
279  $std_item = null;
280  $full_item = null;
281  if ($a_mode == "edit") {
282  $std_item = $this->object->getMediaItem("Standard");
283  }
284 
285  $this->form_gui = new ilPropertyFormGUI();
286 
287  // standard view resource
288  $title = new ilTextInputGUI($lng->txt("title"), "standard_title");
289  $title->setSize(40);
290  $title->setMaxLength(120);
291  $this->form_gui->addItem($title);
292  $radio_prop = new ilRadioGroupInputGUI($lng->txt("cont_resource"), "standard_type");
293  $op1 = new ilRadioOption($lng->txt("cont_file"), "File");
294  $up = new ilFileInputGUI("", "standard_file");
295  $up->setSuffixes(iterator_to_array($this->media_type->getAllowedSuffixes()));
296  //$up->setForbiddenSuffixes(ilObjMediaObject::getForbiddenFileTypes());
297  $up->setInfo("");
298  if ($a_mode == "create" || $std_item->getLocationType() != "LocalFile") {
299  $up->setRequired(true);
300  }
301  $op1->addSubItem($up);
302  $radio_prop->addOption($op1);
303  $op2 = new ilRadioOption($lng->txt("url"), "Reference");
304  $ref = new ilUriInputGUI("", "standard_reference");
305  $ref->setInfo($lng->txt("cont_ref_helptext"));
306  $ref->setRequired(true);
307  $op2->addSubItem($ref);
308  $radio_prop->addOption($op2);
309  $radio_prop->setValue("File");
310  $this->form_gui->addItem($radio_prop);
311 
312  // standard format
313  if ($a_mode == "edit") {
314  $format = new ilNonEditableValueGUI($lng->txt("cont_format"), "standard_format");
315  $format->setValue($std_item->getFormat());
316  $this->form_gui->addItem($format);
317  }
318 
319  // standard size
320  $radio_size = new ilRadioGroupInputGUI($lng->txt("size"), "standard_size");
321  if ($a_mode == "edit") {
322  if ($orig_size = $std_item->getOriginalSize()) {
323  $add_str = " (" . ($orig_size["width"] ?? "") . " x " . ($orig_size["height"] ?? "") . ")";
324  }
325  $op1 = new ilRadioOption($lng->txt("cont_resource_size") . $add_str, "original");
326  $op1->setInfo($lng->txt("cont_resource_size_info"));
327  $op2 = new ilRadioOption($lng->txt("cont_custom_size"), "selected");
328  } else {
329  $op1 = new ilRadioOption($lng->txt("cont_orig_size"), "original");
330  $op1->setInfo($lng->txt("cont_resource_size_info"));
331  $op2 = new ilRadioOption($lng->txt("cont_adjust_size"), "selected");
332  }
333  $radio_size->addOption($op1);
334 
335  // width height
336  $width_height = new ilWidthHeightInputGUI($lng->txt("cont_width") .
337  " / " . $lng->txt("cont_height"), "standard_width_height");
338  if ($a_mode == "edit" && is_int(strpos($std_item->getFormat(), "image"))
339  && $std_item->getLocationType() == "LocalFile") {
340  $width_height->setSupportConstraintsProps(true);
341  $width_height->setConstrainProportions(true);
342  }
343  $op2->addSubItem($width_height);
344 
345  // resize image
346  if ($a_mode == "edit") {
347  $std_item = $this->object->getMediaItem("Standard");
348  if (is_int(strpos($std_item->getFormat(), "image"))
349  && $std_item->getLocationType() == "LocalFile") {
350  $resize = new ilCheckboxInputGUI($lng->txt("cont_resize_img"), "standard_resize");
351  $op2->addSubItem($resize);
352  }
353  }
354 
355  $radio_size->setValue("original");
356  if ($a_mode == "create" && ($this->getHeightPreset() > 0 || $this->getWidthPreset() > 0)) {
357  $radio_size->setValue("selected");
358  $width_height->setWidth($this->getWidthPreset());
359  $width_height->setHeight($this->getHeightPreset());
360  }
361  $radio_size->addOption($op2);
362  $this->form_gui->addItem($radio_size);
363 
364  // standard caption
365  $caption = new ilTextAreaInputGUI($lng->txt("cont_caption"), "standard_caption");
366  $caption->setCols(30);
367  $caption->setRows(2);
368  $this->form_gui->addItem($caption);
369 
370  /*$caption = new ilTextInputGUI($lng->txt("cont_caption"), "standard_caption");
371  $caption->setSize(40);
372  $caption->setMaxLength(200);
373  $this->form_gui->addItem($caption);*/
374 
375  // text representation (alt text)
376  if ($a_mode == "edit" && $this->media_type->usesAltTextProperty($std_item->getFormat())) {
377  $ta = new ilTextAreaInputGUI($lng->txt("text_repr"), "text_representation");
378  $ta->setCols(30);
379  $ta->setRows(2);
380  $ta->setInfo($lng->txt("text_repr_info"));
381  $this->form_gui->addItem($ta);
382  }
383 
384  if ($this->object) {
385  $this->video_gui->addPreviewInput($this->form_gui, $this->object->getId());
386  }
387 
388  // standard parameters
389  if ($a_mode == "edit" &&
390  $this->media_type->usesParameterProperty($std_item->getFormat())) {
391  if ($this->media_type->usesAutoStartParameterOnly(
392  $std_item->getLocation(),
393  $std_item->getFormat()
394  )) { // autostart
395  /*$auto = new ilCheckboxInputGUI($lng->txt("cont_autostart"), "standard_autostart");
396  $this->form_gui->addItem($auto);*/
397  } else { // parameters
398  $par = new ilTextAreaInputGUI($lng->txt("cont_parameter"), "standard_parameters");
399  $par->setRows(5);
400  $par->setCols(50);
401  $this->form_gui->addItem($par);
402  }
403  }
404 
405  if ($a_mode == "edit") {
406  $full_item = $this->object->getMediaItem("Fullscreen");
407  }
408 
409  // fullscreen view resource
410  $fs_sec = new ilFormSectionHeaderGUI();
411  $fs_sec->setTitle($lng->txt("cont_fullscreen"));
412  $this->form_gui->addItem($fs_sec);
413 
414  $radio_prop2 = new ilRadioGroupInputGUI($lng->txt("cont_resource"), "full_type");
415  $op1 = new ilRadioOption($lng->txt("cont_none"), "None");
416  $radio_prop2->addOption($op1);
417  $op4 = new ilRadioOption($lng->txt("cont_use_same_resource_as_above"), "Standard");
418  $radio_prop2->addOption($op4);
419  $op2 = new ilRadioOption($lng->txt("cont_file"), "File");
420  $up = new ilFileInputGUI("", "full_file");
421  $up->setSuffixes(iterator_to_array($this->media_type->getAllowedSuffixes()));
422  //$up->setForbiddenSuffixes(ilObjMediaObject::getForbiddenFileTypes());
423  $up->setInfo("");
424  if ($a_mode == "create" || !$full_item || $full_item->getLocationType() != "LocalFile") {
425  $up->setRequired(true);
426  }
427  $op2->addSubItem($up);
428  $radio_prop2->addOption($op2);
429  $op3 = new ilRadioOption($lng->txt("url"), "Reference");
430  $ref = new ilUriInputGUI("", "full_reference");
431  $ref->setInfo($lng->txt("cont_ref_helptext"));
432  $ref->setRequired(true);
433  $op3->addSubItem($ref);
434  $radio_prop2->addOption($op3);
435  $radio_prop2->setValue("None");
436  $this->form_gui->addItem($radio_prop2);
437 
438  // fullscreen format
439  if ($a_mode == "edit") {
440  if ($this->object->hasFullscreenItem()) {
441  $format = new ilNonEditableValueGUI($lng->txt("cont_format"), "full_format");
442  $format->setValue($full_item->getFormat());
443  $this->form_gui->addItem($format);
444  }
445  }
446 
447  // fullscreen size
448  $full_support_constraint_props = false;
449  $radio_size = new ilRadioGroupInputGUI($lng->txt("size"), "full_size");
450  if ($a_mode == "edit") {
451  $add_str = "";
452  if ($this->object->hasFullscreenItem() && ($orig_size = $full_item->getOriginalSize())) {
453  $add_str = " (" . ($orig_size["width"] ?? "") . " x " . ($orig_size["height"] ?? "") . ")";
454 
455  if (is_int(strpos($full_item->getFormat(), "image"))
456  && $full_item->getLocationType() == "LocalFile") {
457  $full_support_constraint_props = true;
458  }
459  }
460  $op1 = new ilRadioOption($lng->txt("cont_resource_size") . $add_str, "original");
461  $op1->setInfo($lng->txt("cont_resource_size_info"));
462  $op2 = new ilRadioOption($lng->txt("cont_custom_size"), "selected");
463  } else {
464  $op1 = new ilRadioOption($lng->txt("cont_orig_size"), "original");
465  $op1->setInfo($lng->txt("cont_resource_size_info"));
466  $op2 = new ilRadioOption($lng->txt("cont_adjust_size"), "selected");
467  }
468  $radio_size->addOption($op1);
469 
470  // width/height
471  $width_height = new ilWidthHeightInputGUI($lng->txt("cont_width") .
472  " / " . $lng->txt("cont_height"), "full_width_height");
473  if ($full_support_constraint_props) {
474  $width_height->setSupportConstraintsProps(true);
475  $width_height->setConstrainProportions(true);
476  }
477  $op2->addSubItem($width_height);
478 
479  // resize image
480  if ($a_mode == "edit") {
481  $full_item = $this->object->getMediaItem("Fullscreen");
482  if ($this->object->hasFullscreenItem() &&
483  is_int(strpos($full_item->getFormat(), "image")) &&
484  $full_item->getLocationType() == "LocalFile") {
485  $resize = new ilCheckboxInputGUI(
486  $lng->txt("cont_resize_img"),
487  "full_resize"
488  );
489  $op2->addSubItem($resize);
490  }
491  }
492 
493  $radio_size->setValue("original");
494  $radio_size->addOption($op2);
495  $this->form_gui->addItem($radio_size);
496 
497  // fullscreen caption
498  $caption = new ilTextAreaInputGUI($lng->txt("cont_caption"), "full_caption");
499  $caption->setCols(30);
500  $caption->setRows(2);
501  $this->form_gui->addItem($caption);
502 
503  /*$caption = new ilTextInputGUI($lng->txt("cont_caption"), "full_caption");
504  $caption->setSize(40);
505  $caption->setMaxLength(200);
506  $this->form_gui->addItem($caption);*/
507 
508  // text representation (alt text)
509  if ($a_mode == "edit" && $this->object->hasFullscreenItem() && $this->media_type->usesAltTextProperty($std_item->getFormat())) {
510  $ta = new ilTextAreaInputGUI($lng->txt("text_repr"), "full_text_representation");
511  $ta->setCols(30);
512  $ta->setRows(2);
513  $ta->setInfo($lng->txt("text_repr_info"));
514  $this->form_gui->addItem($ta);
515  }
516 
517 
518  // fullscreen parameters
519  if ($a_mode == "edit" && $this->object->hasFullscreenItem() &&
520  $this->media_type->usesParameterProperty($full_item->getFormat())) {
521  if ($this->media_type->usesAutoStartParameterOnly(
522  $full_item->getLocation(),
523  $full_item->getFormat()
524  )) {
525  /*$auto = new ilCheckboxInputGUI($lng->txt("cont_autostart"), "full_autostart");
526  $this->form_gui->addItem($auto);*/
527  } else {
528  $par = new ilTextAreaInputGUI($lng->txt("cont_parameter"), "full_parameters");
529  $par->setRows(5);
530  $par->setCols(50);
531  $this->form_gui->addItem($par);
532  }
533  }
534 
535 
536  if ($a_mode == "edit") {
537  $this->form_gui->setTitle($lng->txt("cont_edit_mob"));
538  $this->form_gui->addCommandButton("saveProperties", $lng->txt("save"));
539  } else {
540  $this->form_gui->setTitle($lng->txt("cont_insert_mob"));
541  $this->form_gui->addCommandButton("save", $lng->txt("save"));
542  $this->form_gui->addCommandButton("cancel", $lng->txt("cancel"));
543  }
544  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
545  }
546 
550  protected function checkFixSize(): void
551  {
552  $std_item = $this->object->getMediaItem("Standard");
553  if ($std_item->getWidth() == "" || $std_item->getHeight() == "") {
554  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("mob_no_fixed_size_map_editing"));
555  }
556  }
557 
558 
562  public function getValues(): void
563  {
564  $values = array();
565 
566  $values["standard_title"] = $this->object->getTitle();
567 
568  $std_item = $this->object->getMediaItem("Standard");
569  if ($std_item->getLocationType() == "LocalFile") {
570  $values["standard_type"] = "File";
571  $values["standard_file"] = $std_item->getLocation();
572  } else {
573  $values["standard_type"] = "Reference";
574  $values["standard_reference"] = $std_item->getLocation();
575  }
576  $values["standard_format"] = $std_item->getFormat();
577  $values["standard_width_height"]["width"] = $std_item->getWidth();
578  $values["standard_width_height"]["height"] = $std_item->getHeight();
579  $values["standard_width_height"]["constr_prop"] = true;
580 
581  $values["standard_size"] = "selected";
582 
583  $orig_size = $std_item->getOriginalSize();
584  if ($std_item->getWidth() == "" && $std_item->getHeight() == "") {
585  $values["standard_size"] = "original";
586  $values["standard_width_height"]["width"] = $orig_size["width"] ?? "";
587  $values["standard_width_height"]["height"] = $orig_size["height"] ?? "";
588  }
589 
590  $values["standard_caption"] = $std_item->getCaption();
591  $values["text_representation"] = $std_item->getTextRepresentation();
592  if ($this->media_type->usesAutoStartParameterOnly(
593  $std_item->getLocation(),
594  $std_item->getFormat()
595  )) {
596  /*$par = $std_item->getParameters();
597  if ($par["autostart"]) {
598  $values["standard_autostart"] = true;
599  }*/
600  } else {
601  $values["standard_parameters"] = $std_item->getParameterString();
602  }
603 
604  $values["full_type"] = "None";
605  $values["full_size"] = "original";
606  if ($this->object->hasFullscreenItem()) {
607  $full_item = $this->object->getMediaItem("Fullscreen");
608  if ($full_item->getLocationType() == "LocalFile") {
609  $values["full_type"] = "File";
610  $values["full_file"] = $full_item->getLocation();
611  } else {
612  $values["full_type"] = "Reference";
613  $values["full_reference"] = $full_item->getLocation();
614  }
615  $values["full_format"] = $full_item->getFormat();
616  $values["full_width_height"]["width"] = $full_item->getWidth();
617  $values["full_width_height"]["height"] = $full_item->getHeight();
618  $values["full_width_height"]["constr_prop"] = true;
619 
620  $values["full_size"] = "selected";
621 
622  $orig_size = $full_item->getOriginalSize();
623  if ($full_item->getWidth() == "" &&
624  $full_item->getHeight() == "") {
625  $values["full_size"] = "original";
626  $values["full_width_height"]["width"] = $orig_size["width"] ?? "";
627  $values["full_width_height"]["height"] = $orig_size["height"] ?? "";
628  }
629  $values["full_caption"] = $full_item->getCaption();
630  if ($this->media_type->usesAutoStartParameterOnly(
631  $full_item->getLocation(),
632  $full_item->getFormat()
633  )) {
634  /*$par = $full_item->getParameters();
635  if ($par["autostart"]) {
636  $values["full_autostart"] = true;
637  }*/
638  } else {
639  $values["full_parameters"] = $full_item->getParameterString();
640  }
641  $values["full_text_representation"] = $full_item->getTextRepresentation();
642  }
643 
644  $this->form_gui->setValuesByArray($values);
645  }
646 
650  public function saveObject(): void
651  {
652  $tpl = $this->tpl;
653  $lng = $this->lng;
654  $this->initForm();
655  if ($this->form_gui->checkInput()) {
656  $this->object = new ilObjMediaObject();
657  $this->setObjectPerCreationForm($this->object);
658  $this->tpl->setOnScreenMessage('success', $lng->txt("saved_media_object"), true);
659  } else {
660  $this->form_gui->setValuesByPost();
661  $tpl->setContent($this->form_gui->getHTML());
662  }
663  }
664 
665  public function checkFormInput(): bool
666  {
667  if (!$this->form_gui->checkInput()) {
668  $this->form_gui->setValuesByPost();
669  return false;
670  }
671  return true;
672  }
673 
674 
678  public function setObjectPerCreationForm(
679  ilObjMediaObject $a_mob
680  ): void {
681  $form = $this->form_gui;
682 
683  $location = "";
684  $file_name = "";
685  $file = "";
686  $type = "";
687 
688  // determinte title and format
689  if (trim($form->getInput("standard_title")) != "") {
690  $title = trim($form->getInput("standard_title"));
691  } else {
692  if ($form->getInput("standard_type") == "File") {
693  $title = $_FILES['standard_file']['name'];
694  } else {
695  $title = $form->getInput("standard_reference");
696  }
697  }
698 
699  $a_mob->setTitle($title);
700  $a_mob->setDescription("");
701  $a_mob->create();
702 
703  // determine and create mob directory, move uploaded file to directory
704  //$mob_dir = ilFileUtils::getWebspaceDir()."/mobs/mm_".$a_mob->getId();
705  //$a_mob->createDirectory();
706  //$mob_dir = ilObjMediaObject::_getDirectory($a_mob->getId());
707 
708 
709  if ($form->getInput("standard_type") == "File") {
710  $width = $height = 0;
711  $constr_prop = false;
712  if ($form->getInput("standard_size") != "original") {
713  $wh_input = $form->getInput("standard_width_height");
714  $width = (int) $wh_input["width"];
715  $height = (int) $wh_input["height"];
716  $constr_prop = ($wh_input["constr_prop"] ?? false);
717  }
718  $media_item = $a_mob->addMediaItemFromLegacyUpload(
719  "Standard",
720  $_FILES["standard_file"]["tmp_name"],
721  $_FILES["standard_file"]["name"],
722  $width,
723  $height,
724  $constr_prop
725  );
726  } else { // standard type: reference
727  $media_item = new ilMediaItem();
728  $a_mob->addMediaItem($media_item);
729  $media_item->setPurpose("Standard");
730 
731  $format = ilObjMediaObject::getMimeType($form->getInput("standard_reference"), true);
732  $media_item->setFormat($format);
733  $media_item->setLocation(ilUtil::secureLink($form->getInput("standard_reference")));
734  $media_item->setLocationType("Reference");
735 
736  try {
737  $a_mob->getExternalMetadata();
738  } catch (Exception $e) {
739  }
740  }
741 
742  // determine width and height of known image types
743  /*
744  $wh_input = $form->getInput("standard_width_height");
745  $wh = ilObjMediaObject::_determineWidthHeight(
746  $media_item->getFormat(),
747  $form->getInput("standard_type"),
748  $mob_dir . "/" . $location,
749  $media_item->getLocation(),
750  (bool) ($wh_input["constr_prop"] ?? false),
751  ($form->getInput("standard_size") == "original"),
752  ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
753  ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
754  );
755  $media_item->setWidth($wh["width"]);
756  $media_item->setHeight($wh["height"]);
757  if ($wh["info"] != "") {
758  $this->tpl->setOnScreenMessage('info', $wh["info"], true);
759  }*/
760 
761  if ($form->getInput("standard_caption") != "") {
762  $media_item->setCaption($form->getInput("standard_caption"));
763  }
764 
765 
766  $media_item->setHAlign("Left");
767 
768  // fullscreen view
769  if ($form->getInput("full_type") != "None") {
770  $media_item2 = new ilMediaItem();
771  $a_mob->addMediaItem($media_item2);
772  $media_item2->setPurpose("Fullscreen");
773 
774  // move file / set format and location
775  if ($form->getInput("full_type") == "File") {
776  $format = $location = "";
777  if ($_FILES['full_file']['name'] != "") {
778  $full_file_name = ilObjMediaObject::fixFilename($_FILES['full_file']['name']);
779  $file = $mob_dir . "/" . $full_file_name;
781  $_FILES['full_file']['tmp_name'],
782  $full_file_name,
783  $file
784  );
785  $format = ilObjMediaObject::getMimeType($file);
786  $location = $full_file_name;
787  }
788  } elseif ($form->getInput("full_type") == "Standard" && $form->getInput("standard_type") == "File") {
789  $location = $file_name;
790  }
791 
792  // resize file
793  if ($form->getInput("full_type") == "File" ||
794  ($form->getInput("full_type") == "Standard" && $form->getInput("standard_type") == "File")) {
795  if (($form->getInput("full_size") != "original" &&
796  is_int(strpos($format, "image")))
797  ) {
798  $full_wh_input = $form->getInput("full_width_height");
800  $file,
801  (int) $full_wh_input["width"],
802  (int) $full_wh_input["height"],
803  (bool) ($full_wh_input["constr_prop"] ?? false)
804  );
805  }
806 
807  $media_item2->setFormat($format);
808  $media_item2->setLocation($location);
809  $media_item2->setLocationType("LocalFile");
810  $type = "File";
811  }
812 
813  if ($form->getInput("full_type") == "Reference") {
814  $format = $location = "";
815  if ($form->getInput("full_reference") != "") {
816  $format = ilObjMediaObject::getMimeType($form->getInput("full_reference"), true);
817  $location = ilUtil::stripSlashes($form->getInput("full_reference"));
818  }
819  }
820 
821  if ($form->getInput("full_type") == "Reference" ||
822  ($form->getInput("full_type") == "Standard" && $form->getInput("standard_type") == "Reference")) {
823  $media_item2->setFormat($format);
824  $media_item2->setLocation($location);
825  $media_item2->setLocationType("Reference");
826  $type = "Reference";
827  }
828 
829  // determine width and height of known image types
830  /*
831  $wh_input = $form->getInput("full_width_height");
832  $wh = ilObjMediaObject::_determineWidthHeight(
833  $format,
834  $type,
835  $mob_dir . "/" . $location,
836  $media_item2->getLocation(),
837  (bool) ($wh_input["constr_prop"] ?? false),
838  ($form->getInput("full_size") == "original"),
839  ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
840  ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
841  );
842 
843  $media_item2->setWidth($wh["width"]);
844  $media_item2->setHeight($wh["height"]);*/
845 
846  if ($form->getInput("full_caption") != "") {
847  $media_item2->setCaption($form->getInput("full_caption"));
848  }
849  }
850 
851  //ilObjMediaObject::renameExecutables($mob_dir);
852  //ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
853  $a_mob->update();
854  }
855 
856 
861  public function cancelObject(): void
862  {
863  $this->ctrl->returnToParent($this);
864  }
865 
866  public function editObject(): void
867  {
868  $tpl = $this->tpl;
869 
870  $this->setPropertiesSubTabs("general");
871  $this->video_gui->addPreviewExtractionToToolbar(
872  $this->object->getId(),
873  self::class
874  );
875  $this->initForm("edit");
876  $this->getValues();
877  $tpl->setContent($this->form_gui->getHTML());
878  }
879 
880  public function extractPreviewImageObject(): void
881  {
882  $ilCtrl = $this->ctrl;
883  $this->video_gui->handleExtractionRequest(
884  $this->object->getId()
885  );
886  $ilCtrl->redirect($this, "edit");
887  }
888 
892  public function resizeImagesObject(): void
893  {
894  // directory
895  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
896 
897  // standard item
898  $std_item = $this->object->getMediaItem("Standard");
899  if ($std_item->getLocationType() == "LocalFile" &&
900  is_int(strpos($std_item->getFormat(), "image"))
901  ) {
902  $file = $mob_dir . "/" . $std_item->getLocation();
904  $file,
905  $std_item->getWidth(),
906  $std_item->getHeight()
907  );
908  $std_item->setLocation($location);
909  $std_item->update();
910  }
911 
912  // fullscreen item
913  if ($this->object->hasFullscreenItem()) {
914  $full_item = $this->object->getMediaItem("Fullscreen");
915  if ($full_item->getLocationType() == "LocalFile" &&
916  is_int(strpos($full_item->getFormat(), "image"))
917  ) {
918  $file = $mob_dir . "/" . $full_item->getLocation();
920  $file,
921  $full_item->getWidth(),
922  $full_item->getHeight()
923  );
924  $full_item->setLocation($location);
925  $full_item->update();
926  }
927  }
928 
929  $this->ctrl->redirect($this, "edit");
930  }
931 
932 
936  public function getStandardSizeObject(): void
937  {
938  $std_item = $this->object->getMediaItem("Standard");
939  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
940 
941  if ($std_item->getLocationType() == "LocalFile") {
942  $file = $mob_dir . "/" . $std_item->getLocation();
943 
944  $size = ilMediaImageUtil::getImageSize($file);
945 
946  $std_item->setWidth($size[0]);
947  $std_item->setHeight($size[1]);
948  $this->object->update();
949  }
950  $this->ctrl->redirect($this, "edit");
951  }
952 
953 
957  public function getFullscreenSizeObject(): void
958  {
959  $full_item = $this->object->getMediaItem("Fullscreen");
960  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
961 
962  if ($full_item->getLocationType() == "LocalFile") {
963  $file = $mob_dir . "/" . $full_item->getLocation();
964  $size = ilMediaImageUtil::getImageSize($file);
965  $full_item->setWidth($size[0]);
966  $full_item->setHeight($size[1]);
967  $this->object->update();
968  }
969  $this->ctrl->redirect($this, "edit");
970  }
971 
972  public function savePropertiesObject(): void
973  {
974  $lng = $this->lng;
975  $tpl = $this->tpl;
976  $file = "";
977  $type = "";
978 
979  $this->initForm("edit");
980  $form = $this->form_gui;
981 
982  if ($form->checkInput()) {
983  $title = trim($form->getInput("standard_title"));
984  $this->object->setTitle($title);
985 
986  $std_item = $this->object->getMediaItem("Standard");
987  $location = $std_item->getLocation();
988  $format = $std_item->getFormat();
989  if ($form->getInput("standard_type") == "Reference") {
990  $format = ilObjMediaObject::getMimeType($form->getInput("standard_reference"), true);
991  $std_item->setFormat($format);
992  $std_item->setLocation(ilUtil::secureLink($form->getInput("standard_reference")));
993  $std_item->setLocationType("Reference");
994  }
995  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
996  if ($form->getInput("standard_type") == "File") {
997  $resize = false;
998  if ($_FILES['standard_file']['name'] != "") {
999  //$file_name = ilObjMediaObject::fixFilename($_FILES['standard_file']['name']);
1000  $file_name = $_FILES['standard_file']['name'];
1001  $this->media_manager->addFileFromLegacyUpload(
1002  $this->object->getId(),
1003  $_FILES['standard_file']['tmp_name']
1004  );
1005 
1006  // get mime type
1007  $format = ilObjMediaObject::getMimeType($file_name, true);
1008  $location = $file_name;
1009 
1010  $resize = true;
1011  } elseif ($form->getInput("standard_resize")) {
1012  $file = $mob_dir . "/" . $location;
1013  $resize = true;
1014  }
1015 
1016  // resize
1017  if ($resize) {
1018  if ($form->getInput("standard_size") != "original" &&
1019  is_int(strpos($format, "image"))) {
1020  $wh_input = $form->getInput("standard_width_height");
1022  $file,
1023  (int) $wh_input["width"],
1024  (int) $wh_input["height"],
1025  (bool) ($wh_input["constr_prop"] ?? false)
1026  );
1027  }
1028  $std_item->setFormat($format);
1029  $std_item->setLocation($location);
1030  }
1031 
1032  $std_item->setLocationType("LocalFile");
1033  }
1034  $this->object->setDescription($format);
1035  // determine width and height of known image types
1036  $wh_input = $form->getInput("standard_width_height");
1038  $format,
1039  $form->getInput("standard_type"),
1040  $mob_dir . "/" . $location,
1041  $std_item->getLocation(),
1042  (bool) ($wh_input["constr_prop"] ?? false),
1043  ($form->getInput("standard_size") == "original"),
1044  ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
1045  ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
1046  );
1047  if ($wh["info"] != "") {
1048  $this->tpl->setOnScreenMessage('info', $wh["info"], true);
1049  }
1050  $std_item->setWidth($wh["width"]);
1051  $std_item->setHeight($wh["height"]);
1052 
1053  // set caption
1054  $std_item->setCaption($form->getInput("standard_caption"));
1055 
1056  // text representation
1057  $std_item->setTextRepresentation($form->getInput("text_representation"));
1058 
1059  $this->video_gui->savePreviewInput($form, $this->object->getId());
1060 
1061  // set parameters
1062  if ($this->media_type->usesParameterProperty($std_item->getFormat())) {
1063  if (!$this->media_type->usesAutoStartParameterOnly(
1064  $std_item->getLocation(),
1065  $std_item->getFormat()
1066  )) {
1067  $std_item->setParameters($form->getInput("standard_parameters"));
1068  }
1069  }
1070 
1071  // "None" selected
1072  if ($form->getInput("full_type") == "None") {
1073  if ($this->object->hasFullscreenItem()) { // delete existing
1074  $this->object->removeMediaItem("Fullscreen");
1075  }
1076  } else { // Not "None" -> we need one
1077  if ($this->object->hasFullscreenItem()) { // take existing one
1078  $full_item = $this->object->getMediaItem("Fullscreen");
1079  } else { // create one
1080  $full_item = new ilMediaItem();
1081  $this->object->addMediaItem($full_item);
1082  $full_item->setPurpose("Fullscreen");
1083  }
1084  $location = $full_item->getLocation();
1085  $format = $full_item->getFormat();
1086  if ($form->getInput("full_type") == "Reference") {
1087  $format = ilObjMediaObject::getMimeType($form->getInput("full_reference"), true);
1088  $full_item->setFormat($format);
1089  $full_item->setLocationType("Reference");
1090  $location = ilUtil::secureLink($form->getInput("full_reference"));
1091  $type = "Reference";
1092  $full_item->setLocation($location);
1093  }
1094  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
1095  if ($form->getInput("full_type") == "File") {
1096  $resize = false;
1097  if ($_FILES['full_file']['name'] != "") {
1098  //$full_file_name = ilObjMediaObject::fixFilename($_FILES['full_file']['name']);
1099  $full_file_name = $_FILES['full_file']['name'];
1100  $this->media_manager->addFileFromLegacyUpload(
1101  $this->object->getId(),
1102  $_FILES['full_file']['tmp_name']
1103  );
1104 
1105  $format = ilObjMediaObject::getMimeType($file);
1106  $location = $full_file_name;
1107 
1108  $resize = true;
1109  } elseif ($form->getInput("full_resize")) {
1110  $file = $mob_dir . "/" . $location;
1111  $resize = true;
1112  }
1113 
1114  // resize
1115  if ($resize) {
1116  if ($form->getInput("full_size") != "original" &&
1117  is_int(strpos($format, "image"))) {
1118  $wh_input = $form->getInput("full_width_height");
1120  $file,
1121  (int) $wh_input["width"],
1122  (int) $wh_input["height"],
1123  (bool) ($wh_input["constr_prop"] ?? false)
1124  );
1125  }
1126  $full_item->setFormat($format);
1127  $full_item->setLocation($location);
1128  }
1129 
1130  $full_item->setLocationType("LocalFile");
1131  $type = "File";
1132  }
1133  if ($form->getInput("full_type") == "Standard") {
1134  $format = $std_item->getFormat();
1135  $location = $std_item->getLocation();
1136  $full_item->setLocationType($std_item->getLocationType());
1137  $full_item->setFormat($format);
1138  $full_item->setLocation($location);
1139  $type = $std_item->getLocationType();
1140  if ($type == "LocalFile") {
1141  $type = "File";
1142  }
1143  // resize image
1144  if ($form->getInput("full_size") != "original" &&
1145  is_int(strpos($format, "image")) &&
1146  $full_item->getLocationType() == "LocalFile") {
1147  $file = $mob_dir . "/" . $location;
1148  $wh_input = $form->getInput("full_width_height");
1150  $file,
1151  (int) $wh_input["width"],
1152  (int) $wh_input["height"],
1153  (bool) ($wh_input["constr_prop"] ?? false)
1154  );
1155  }
1156  }
1157 
1158  // determine width and height of known image types
1159  $wh_input = $form->getInput("full_width_height");
1161  $format,
1162  $type,
1163  $mob_dir . "/" . $location,
1164  $full_item->getLocation(),
1165  (bool) ($wh_input["constr_prop"] ?? false),
1166  ($form->getInput("full_size") == "original"),
1167  ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
1168  ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
1169  );
1170  if ($wh["info"] != "") {
1171  $this->tpl->setOnScreenMessage('info', $wh["info"], true);
1172  }
1173 
1174  $full_item->setWidth($wh["width"]);
1175  $full_item->setHeight($wh["height"]);
1176  $full_item->setLocation($location);
1177 
1178  $full_item->setCaption($form->getInput("full_caption"));
1179 
1180  // text representation
1181  $full_item->setTextRepresentation($form->getInput("full_text_representation"));
1182 
1183 
1184  // set parameters
1185  if ($this->media_type->usesParameterProperty($std_item->getFormat())) {
1186  if (!$this->media_type->usesAutoStartParameterOnly(
1187  $std_item->getLocation(),
1188  $std_item->getFormat()
1189  )) {
1190  $full_item->setParameters($form->getInput("full_parameters"));
1191  }
1192  }
1193  }
1194 
1195  /*
1196  ilObjMediaObject::renameExecutables(ilObjMediaObject::_getDirectory($this->object->getId()));
1197  ilMediaSvgSanitizer::sanitizeDir(ilObjMediaObject::_getDirectory($this->object->getId()));
1198  */ // see #20339
1199 
1200  $this->object->update();
1201  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1202  $this->ctrl->redirect($this, "edit");
1203  } else {
1204  $this->form_gui->setValuesByPost();
1205  $tpl->setContent($this->form_gui->getHTML());
1206  }
1207  }
1208 
1212  public function assignStandardObject(
1213  string $a_file
1214  ): void {
1215  // determine directory
1216  $cur_subdir = dirname($a_file);
1217  $mob_dir = ilFileUtils::getWebspaceDir() . "/mobs/mm_" . $this->object->getId();
1218  $cur_dir = (!empty($cur_subdir))
1219  ? $mob_dir . "/" . $cur_subdir
1220  : $mob_dir;
1221  $file = $cur_dir . "/" . basename($a_file);
1222  $location = $a_file;
1223 
1224  if (!is_file($file)) {
1225  $this->ilias->raiseError($this->lng->txt("cont_select_file"), $this->ilias->error_obj->MESSAGE);
1226  }
1227 
1228  $std_item = $this->object->getMediaItem("Standard");
1229  $std_item->setLocationType("LocalFile");
1230  $std_item->setLocation($location);
1231  $format = ilObjMediaObject::getMimeType($file);
1232  $std_item->setFormat($format);
1233  $this->object->update();
1234  // $this->ctrl->saveParameter($this, "cdir");
1235  $this->ctrl->redirectByClass(ilContainerResourceGUI::class, "listFiles");
1236  }
1237 
1238 
1242  public function assignFullscreenObject(
1243  string $a_file
1244  ): void {
1245  // determine directory
1246  $cur_subdir = dirname($a_file);
1247  $mob_dir = ilFileUtils::getWebspaceDir() . "/mobs/mm_" . $this->object->getId();
1248  $cur_dir = (!empty($cur_subdir))
1249  ? $mob_dir . "/" . $cur_subdir
1250  : $mob_dir;
1251  $file = $cur_dir . "/" . basename($a_file);
1252  $location = $a_file;
1253 
1254  if (!is_file($file)) {
1255  $this->ilias->raiseError($this->lng->txt("cont_select_file"), $this->ilias->error_obj->MESSAGE);
1256  }
1257 
1258  if (!$this->object->hasFullscreenItem()) { // create new fullscreen item
1259  $std_item = $this->object->getMediaItem("Standard");
1260  $mob_dir = ilFileUtils::getWebspaceDir() . "/mobs/mm_" . $this->object->getId();
1261  $file = $mob_dir . "/" . $location;
1262  $full_item = new ilMediaItem();
1263  $full_item->setMobId($std_item->getMobId());
1264  $full_item->setLocation($location);
1265  $full_item->setLocationType("LocalFile");
1266  $full_item->setFormat(ilObjMediaObject::getMimeType($file));
1267  $full_item->setPurpose("Fullscreen");
1268  $this->object->addMediaItem($full_item);
1269  } else { // alter existing fullscreen item
1270  $full_item = $this->object->getMediaItem("Fullscreen");
1271 
1272  $full_item->setLocationType("LocalFile");
1273  $full_item->setLocation($location);
1274  $format = ilObjMediaObject::getMimeType($file);
1275  $full_item->setFormat($format);
1276  }
1277  $this->object->update();
1278  // $this->ctrl->saveParameter($this, "cdir");
1279  $this->ctrl->redirectByClass(ilContainerResourceGUI::class, "listFiles");
1280  }
1281 
1282 
1286  public function removeFullscreenObject(): void
1287  {
1288  $this->object->removeMediaItem("Fullscreen");
1289  $this->object->update();
1290 
1291  $this->ctrl->redirect($this, "edit");
1292  }
1293 
1297  public function addFullscreenObject(): void
1298  {
1299  if (!$this->object->hasFullscreenItem()) {
1300  $std_item = $this->object->getMediaItem("Standard");
1301  $full_item = new ilMediaItem();
1302  $full_item->setMobId($std_item->getMobId());
1303  $full_item->setLocation($std_item->getLocation());
1304  $full_item->setLocationType($std_item->getLocationType());
1305  $full_item->setFormat($std_item->getFormat());
1306  $full_item->setWidth($std_item->getWidth());
1307  $full_item->setHeight($std_item->getHeight());
1308  $full_item->setCaption($std_item->getCaption());
1309  $full_item->setTextRepresentation($std_item->getTextRepresentation());
1310  $full_item->setPurpose("Fullscreen");
1311  $this->object->addMediaItem($full_item);
1312 
1313  $this->object->update();
1314  }
1315 
1316  $this->ctrl->redirect($this, "edit");
1317  }
1318 
1322  public function showAllUsagesObject(): void
1323  {
1324  $this->showUsagesObject(true);
1325  }
1326 
1327 
1331  public function showUsagesObject(
1332  bool $a_all = false
1333  ): void {
1334  $tpl = $this->tpl;
1335  $ilTabs = $this->tabs;
1336  $lng = $this->lng;
1337  $ilCtrl = $this->ctrl;
1338 
1339  $ilTabs->addSubTab(
1340  "current_usages",
1341  $lng->txt("cont_current_usages"),
1342  $ilCtrl->getLinkTarget($this, "showUsages")
1343  );
1344 
1345  $ilTabs->addSubTab(
1346  "all_usages",
1347  $lng->txt("cont_all_usages"),
1348  $ilCtrl->getLinkTarget($this, "showAllUsages")
1349  );
1350 
1351  if ($a_all) {
1352  $ilTabs->activateSubTab("all_usages");
1353  $cmd = "showAllUsages";
1354  } else {
1355  $ilTabs->activateSubTab("current_usages");
1356  $cmd = "showUsages";
1357  }
1358 
1360  $mob = $this->object;
1361  $usages_table = new ilMediaObjectUsagesTableGUI(
1362  $this,
1363  $cmd,
1364  $mob,
1365  $a_all
1366  );
1367  $tpl->setContent($usages_table->getHTML());
1368  }
1369 
1373  public static function _getMediaInfoHTML(
1374  ilObjMediaObject $a_mob
1375  ): string {
1376  global $DIC;
1377 
1378  $lng = $DIC->language();
1379  $lom_services = $DIC->learningObjectMetadata();
1380  $media_manager = $DIC->mediaObjects()->internal()->domain()->mediaObject();
1381 
1382  $tpl = new ilTemplate("tpl.media_info.html", true, true, "components/ILIAS/MediaObjects");
1383  $types = array("Standard", "Fullscreen");
1384  foreach ($types as $type) {
1385  if ($type == "Fullscreen" && !$a_mob->hasFullscreenItem()) {
1386  continue;
1387  }
1388 
1389  $med = $a_mob->getMediaItem($type);
1390  if (!$med) {
1391  return "";
1392  }
1393 
1394  $tpl->setCurrentBlock("media_info");
1395  if ($type == "Standard") {
1396  $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_std_view"));
1397  } else {
1398  $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_fullscreen"));
1399  }
1400  $tpl->setVariable("TXT_TYPE", $lng->txt("cont_" . strtolower($med->getLocationType())));
1401  $tpl->setVariable("VAL_LOCATION", $med->getLocation());
1402  if ($med->getLocationType() == "LocalFile") {
1403 
1404  try {
1405  $info = $media_manager->getInfoOfEntry($med->getMobId(), "/" . $med->getLocation());
1406  } catch (Exception $e) {
1407  }
1408 
1409  $size = $info["size"] ?? 0;
1410  $tpl->setVariable("VAL_FILE_SIZE", " ($size " . $lng->txt("bytes") . ")");
1411  }
1412  $tpl->setVariable("TXT_FORMAT", $lng->txt("cont_format"));
1413  $tpl->setVariable("VAL_FORMAT", $med->getFormat());
1414  if ($med->getWidth() != "" && $med->getHeight() != "") {
1415  $tpl->setCurrentBlock("size");
1416  $tpl->setVariable("TXT_SIZE", $lng->txt("size"));
1417  $tpl->setVariable("VAL_SIZE", $med->getWidth() . "x" . $med->getHeight());
1419  }
1420 
1421  // original size
1422  if ($orig_size = $med->getOriginalSize()) {
1423  if (($orig_size["width"] ?? "") !== $med->getWidth() ||
1424  ($orig_size["height"] ?? "") !== $med->getHeight()) {
1425  $tpl->setCurrentBlock("orig_size");
1426  $tpl->setVariable("TXT_ORIG_SIZE", $lng->txt("cont_orig_size"));
1427  $tpl->setVariable("ORIG_WIDTH", $orig_size["width"]);
1428  $tpl->setVariable("ORIG_HEIGHT", $orig_size["height"]);
1430  }
1431  }
1432 
1433  // output caption
1434  if (strlen($med->getCaption())) {
1435  $tpl->setCurrentBlock('additional_info');
1436  $tpl->setVariable('ADD_INFO', $lng->txt('cont_caption') . ': ' . $med->getCaption());
1438  }
1439 
1440  // output keywords
1441  if ($type == "Standard") {
1442  $keyword_data = $lom_services
1443  ->read(0, $med->getMobId(), 'mob', $lom_services->paths()->keywords())
1444  ->allData($lom_services->paths()->keywords());
1445  $presentable_keywords = $lom_services->dataHelper()->makePresentableAsList(
1446  ', ',
1447  ...$keyword_data
1448  );
1449  if ($presentable_keywords !== '') {
1450  $tpl->setCurrentBlock('additional_info');
1451  $tpl->setVariable('ADD_INFO', $lng->txt('keywords') . ': ' . $presentable_keywords);
1453  }
1454  }
1455 
1456  $tpl->setCurrentBlock("media_info");
1458  }
1459 
1460  return $tpl->get();
1461  }
1462 
1466  public function setTabs(): void
1467  {
1468  // catch feedback message
1469  $this->getTabs();
1470 
1471  //$this->tpl->clearHeader();
1472  if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject") {
1473  $this->tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_mob.svg"));
1474  $this->tpl->setTitle($this->object->getTitle());
1475  } else {
1476  //$title = $this->object->getTitle();
1477  $this->tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_mob.svg"));
1478  $this->tpl->setTitle($this->lng->txt("cont_create_mob"));
1479  }
1480  }
1481 
1482  public function getTabs(): void
1483  {
1484  $ilHelp = $this->help;
1485 
1486  $ilHelp->setScreenIdComponent("mob");
1487 
1488  if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject"
1489  && $this->object->getId() > 0) {
1490  // object properties
1491  $this->tabs_gui->addTarget(
1492  "cont_mob_def_prop",
1493  $this->ctrl->getLinkTarget($this, "edit"),
1494  "edit",
1495  get_class($this)
1496  );
1497 
1498  $st_item = $this->object->getMediaItem("Standard");
1499 
1500  // link areas
1501 
1502  if (is_object($st_item) && $this->getEnabledMapAreas()) {
1503  $format = $st_item->getFormat();
1504  if (substr($format, 0, 5) == "image" && !is_int(strpos($format, "svg"))) {
1505  $this->tabs_gui->addTarget(
1506  "cont_def_map_areas",
1507  $this->ctrl->getLinkTargetByClass(
1508  array("ilobjmediaobjectgui", "ilimagemapeditorgui"),
1509  "editMapAreas"
1510  ),
1511  "editMapAreas",
1512  "ilimagemapeditorgui"
1513  );
1514  }
1515  }
1516 
1517  // object usages
1518  $this->tabs_gui->addTarget(
1519  "cont_mob_usages",
1520  $this->ctrl->getLinkTarget($this, "showUsages"),
1521  "showUsages",
1522  get_class($this)
1523  );
1524 
1525  // object files
1526  $std_item = $this->object->getMediaItem("Standard");
1527  $full_item = $this->object->getMediaItem("Fullscreen");
1528  $mset = new ilSetting("mobs");
1529  if ($mset->get("file_manager_always") ||
1530  ($this->media_type->usesParameterProperty($std_item->getFormat()) ||
1531  (is_object($full_item) && $this->media_type->usesParameterProperty($full_item->getFormat())))
1532  ) {
1533  $this->tabs_gui->addTarget(
1534  "cont_files",
1535  $this->ctrl->getLinkTargetByClass(
1536  array("ilobjmediaobjectgui", ilContainerResourceGUI::class),
1537  ""
1538  ),
1539  "",
1540  "ilContainerResourceGUI"
1541  );
1542  }
1543 
1544  $mdgui = new ilObjectMetaDataGUI(null, $this->object->getType(), $this->object->getId());
1545  $mdtab = $mdgui->getTab("ilobjmediaobjectgui");
1546  if ($mdtab) {
1547  $this->tabs_gui->addTarget(
1548  "meta_data",
1549  $mdtab,
1550  "",
1551  "ilmdeditorgui"
1552  );
1553  }
1554  }
1555 
1556  // back to upper context
1557  if ($this->back_title != "") {
1558  $this->tabs_gui->setBackTarget(
1559  $this->back_title,
1560  $this->ctrl->getParentReturn($this)
1561  );
1562  }
1563  }
1564 
1568  public static function includePresentationJS(
1569  ilGlobalTemplateInterface $a_tpl = null
1570  ): void {
1571  global $DIC;
1572 
1573  $tpl = $DIC["tpl"];
1574 
1575  if ($a_tpl == null) {
1576  $a_tpl = $tpl;
1577  }
1578 
1579  iljQueryUtil::initjQuery($a_tpl);
1580  $a_tpl->addJavaScript(iljQueryUtil::getLocalMaphilightPath());
1581  $a_tpl->addJavaScript("components/ILIAS/COPage/js/ilCOPagePres.js");
1582 
1583  //ilPlayerUtil::initMediaElementJs($a_tpl);
1584  }
1585 
1586  public function setPropertiesSubTabs(
1587  string $a_active
1588  ): void {
1589  $ilTabs = $this->tabs;
1590  $ilCtrl = $this->ctrl;
1591  $lng = $this->lng;
1592 
1593  $ilTabs->activateTab("cont_mob_def_prop");
1594 
1595  $ilTabs->addSubTab(
1596  "general",
1597  $lng->txt("mob_general"),
1598  $ilCtrl->getLinkTarget($this, "edit")
1599  );
1600 
1601  if ($this->object->getMediaItem("Standard")->getFormat() == "video/webm" ||
1602  $this->object->getMediaItem("Standard")->getFormat() == "video/mp4") {
1603  $ilTabs->addSubTab(
1604  "subtitles",
1605  $lng->txt("mob_subtitles"),
1606  $ilCtrl->getLinkTarget($this, "listSubtitleFiles")
1607  );
1608  }
1609 
1610  $ilTabs->activateSubTab($a_active);
1611  }
1612 
1613  public function listSubtitleFilesObject(): void
1614  {
1615  $ilToolbar = $this->toolbar;
1616  $tpl = $this->tpl;
1617  $ilCtrl = $this->ctrl;
1618  $lng = $this->lng;
1619  $ilUser = $this->user;
1620 
1621  $this->setPropertiesSubTabs("subtitles");
1622  $this->media_manager->generateMissingVTT($this->object->getId());
1623 
1624  if (!in_array("vtt", $this->file_service_settings->getWhiteListedSuffixes())) {
1625  $tpl->setOnScreenMessage("info", $lng->txt("mob_srt_not_allowed"));
1626  } else {
1627 
1628  // upload file
1629  $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
1630  $fi = new ilFileInputGUI($lng->txt("mob_subtitle_file") . " (.vtt)", "subtitle_file");
1631  $fi->setSuffixes(array("vtt"));
1632  $ilToolbar->addInputItem($fi, true);
1633 
1634  // language
1635  $options = $this->md->getLOMLanguagesForSelectInputs();
1636  $si = new ilSelectInputGUI($this->lng->txt("mob_language"), "language");
1637  $si->setOptions($options);
1638  $si->setValue($ilUser->getLanguage());
1639  $ilToolbar->addInputItem($si, true);
1640 
1641  $ilToolbar->addFormButton($lng->txt("upload"), "uploadSubtitleFile");
1642 
1643  $ilToolbar->addSeparator();
1644  $ilToolbar->addFormButton($lng->txt("mob_upload_multi_srt"), "uploadMultipleSubtitleFileForm");
1645 
1646  //$ilToolbar->addSeparator();
1647  //$ilToolbar->addFormButton($lng->txt("mob_generate_vtt"), "generateVTT");
1648  }
1649 
1651  $mob = $this->object;
1652  $tab = new ilMobSubtitleTableGUI($this, "listSubtitleFiles", $mob);
1653 
1654  $tpl->setContent($tab->getHTML());
1655  }
1656 
1657  public function uploadSubtitleFileObject(): void
1658  {
1659  $lng = $this->lng;
1660  $ilCtrl = $this->ctrl;
1661 
1662  if ($this->object->uploadSrtFile(
1663  $_FILES["subtitle_file"]["tmp_name"],
1664  $this->sub_title_request->getLanguage()
1665  )) {
1666  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1667  }
1668  $ilCtrl->redirect($this, "listSubtitleFiles");
1669  }
1670 
1674  public function confirmSrtDeletionObject(): void
1675  {
1676  $ilCtrl = $this->ctrl;
1677  $tpl = $this->tpl;
1678  $lng = $this->lng;
1679 
1680  $lng->loadLanguageModule("meta");
1681 
1682  $srts = $this->sub_title_request->getSrtFiles();
1683  if (count($srts) == 0) {
1684  $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1685  $ilCtrl->redirect($this, "listSubtitleFiles");
1686  } else {
1687  $cgui = new ilConfirmationGUI();
1688  $cgui->setFormAction($ilCtrl->getFormAction($this));
1689  $cgui->setHeaderText($lng->txt("mob_really_delete_srt"));
1690  $cgui->setCancel($lng->txt("cancel"), "listSubtitleFiles");
1691  $cgui->setConfirm($lng->txt("delete"), "deleteSrtFiles");
1692  foreach ($srts as $i) {
1693  $p = explode(":", $i);
1694  $cgui->addItem("srt[]", $i, "subtitle_" . $p[0] . ".".$p[1]." (" . $lng->txt("meta_l_" . $p[0]) . ")");
1695  }
1696 
1697  $tpl->setContent($cgui->getHTML());
1698  }
1699  }
1700 
1704  public function deleteSrtFilesObject(): void
1705  {
1706  $lng = $this->lng;
1707  $ilCtrl = $this->ctrl;
1708 
1709  $srts = $this->sub_title_request->getSrtFiles();
1710  $deleted = false;
1711  foreach ($srts as $i) {
1712  if (strlen($i) == 6 && !is_int(strpos($i, "."))) {
1713  $p = explode(":", $i);
1714  $this->object->removeAdditionalFile("srt/subtitle_" . $p[0] . "." . $p[1]);
1715  $deleted = true;
1716  }
1717  }
1718  if ($deleted) {
1719  $this->tpl->setOnScreenMessage('success', $lng->txt("mob_srt_files_deleted"), true);
1720  }
1721  $ilCtrl->redirect($this, "listSubtitleFiles");
1722  }
1723 
1725  {
1726  $ilToolbar = $this->toolbar;
1727  $lng = $this->lng;
1728  $ilCtrl = $this->ctrl;
1729 
1730  $this->tpl->setOnScreenMessage('info', $lng->txt("mob_upload_multi_srt_howto"));
1731 
1732  $this->setPropertiesSubTabs("subtitles");
1733 
1734  // upload file
1735  $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
1736  $fi = new ilFileInputGUI($lng->txt("mob_subtitle_file") . " (.zip)", "subtitle_file");
1737  $fi->setSuffixes(array("zip"));
1738  $ilToolbar->addInputItem($fi, true);
1739 
1740  $ilToolbar->addFormButton($lng->txt("upload"), "uploadMultipleSubtitleFile");
1741  }
1742 
1743  public function uploadMultipleSubtitleFileObject(): void
1744  {
1745  try {
1746  $this->object->uploadMultipleSubtitleFile(ilArrayUtil::stripSlashesArray($_FILES["subtitle_file"]));
1747  $this->ctrl->redirect($this, "showMultiSubtitleConfirmationTable");
1748  } catch (ilMediaObjectsException $e) {
1749  $this->tpl->setOnScreenMessage('failure', $e->getMessage(), true);
1750  $this->ctrl->redirect($this, "uploadMultipleSubtitleFileForm");
1751  }
1752  }
1753 
1758  {
1759  $tpl = $this->tpl;
1760 
1761  $this->setPropertiesSubTabs("subtitles");
1762 
1763  $tab = new ilMultiSrtConfirmationTable2GUI($this, "showMultiSubtitleConfirmationTable");
1764  $tpl->setContent($tab->getHTML());
1765  }
1766 
1770  public function cancelMultiSrtObject(): void
1771  {
1772  $this->object->clearMultiSrtDirectory();
1773  $this->ctrl->redirect($this, "listSubtitleFiles");
1774  }
1775 
1779  public function saveMultiSrtObject(): void
1780  {
1781  $ilCtrl = $this->ctrl;
1782  $srt_files = $this->object->getMultiSrtFiles();
1783  $files = $this->sub_title_request->getFiles();
1784  foreach ($files as $f) {
1785  foreach ($srt_files as $srt_file) {
1786  if ($f == $srt_file["filename"]) {
1787  $this->object->uploadSrtFile($this->object->getMultiSrtUploadDir() . "/" . $srt_file["filename"], $srt_file["lang"], "rename");
1788  }
1789  }
1790  }
1791  $this->object->clearMultiSrtDirectory();
1792  $ilCtrl->redirect($this, "listSubtitleFiles");
1793  }
1794 
1795  protected function generateVTTObject(): void
1796  {
1797  $this->media_manager->generateMissingVTT($this->object->getId());
1798  $this->ctrl->redirect($this, "listSubtitleFiles");
1799  }
1800 }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
setWidthPreset(int $a_val)
Set width preset (e.g.
SubtitlesGUIRequest $sub_title_request
setAdvMdRecordObject(int $a_adv_ref_id, string $a_adv_type, string $a_adv_subtype="-")
Set object, that defines the adv md records being used.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
Class ilObjectMetaDataGUI.
ILIAS MediaObjects MediaObjectManager $media_manager
create(bool $a_create_meta_data=false, bool $a_save_media_items=true, int $from_mob_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
showAllUsagesObject()
Show all media object usages (incl history)
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
addFullscreenObject()
add fullscreen view
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
static _determineWidthHeight(string $a_format, string $a_type, string $a_file, string $a_reference, bool $a_constrain_proportions, bool $a_use_original, ?int $a_user_width=null, ?int $a_user_height=null)
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
ilFileServicesSettings $file_service_settings
showMultiSubtitleConfirmationTableObject()
List of srt files in zip file.
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setEnabledMapAreas(bool $a_enabledmapareas)
This class represents a file property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setInfo(string $a_info)
deleteSrtFilesObject()
Delete srt files.
static includePresentationJS(ilGlobalTemplateInterface $a_tpl=null)
Include media object presentation JS.
setPropertiesSubTabs(string $a_active)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
setHeightPreset(int $a_val)
Set height preset (e.g.
Help GUI class.
addMediaItem(ilMediaItem $a_item)
addMDObserver(object $class, string $method, string $section)
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
ILIAS MediaObjects MediaType MediaTypeManager $media_type
setObjectPerCreationForm(ilObjMediaObject $a_mob)
Set media object values from creation form.
setSuffixes(array $a_suffixes)
loadLanguageModule(string $a_module)
Load language module.
setTitle(string $title)
static _resizeImage(string $a_file, int $a_width, int $a_height, bool $a_constrain_prop=false)
Resize image and return new image file ("_width_height" string appended)
setOptions(array $a_options)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
__construct( $a_data, int $a_id=0, bool $a_call_by_reference=false, bool $a_prepare_output=false)
static secureLink(string $a_str)
saveMultiSrtObject()
Save selected srt files as new srt files.
ILIAS MediaObjects Video GUIService $video_gui
checkFixSize()
Check fix size (for map editing hint)
getValues()
Get values for form.
removeFullscreenObject()
remove fullscreen view
getFullscreenSizeObject()
set original size of fullscreen file
getStandardSizeObject()
set original size of standard file
cancelMultiSrtObject()
Cancel Multi Feedback.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
assignStandardObject(string $a_file)
assign file to standard view
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getDirectory(int $a_mob_id)
Get absolute directory.
This class represents a property in a property form.
ilGlobalTemplateInterface $tpl
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
setScreenId(string $a_id)
setContent(string $a_html)
Sets content for standard template.
addMediaItemFromLegacyUpload(string $purpose, string $tmp_name, string $name, int $resize_width=0, int $resize_height=0, bool $constrain_proportions=true, bool $deduce_size=false)
update(bool $a_upload=false)
setScreenIdComponent(string $a_comp)
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: shib_login.php:25
getMediaItem(string $a_purpose)
get item for media purpose
Class ilMediaItem Media Item, component of a media object (file or reference)
ilToolbarGUI $toolbar
Legacy Uri input.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Class ilObjForumAdministration.
saveObject()
create new media object
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initForm(string $a_mode="create")
static fixFilename(string $a_name)
Fix filename of uploaded file.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
User interface class for map editor.
static getImageSize(string $a_location)
Get image size from location.
getAdvMdRecordObject()
Get adv md record type.
Editing User Interface for MediaObjects within LMs (see ILIAS DTD)
resizeImagesObject()
resize images to specified size
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
confirmSrtDeletionObject()
Confirm srt file deletion.
static getLocalMaphilightPath()
Get local path of maphilight file.
static _getMediaInfoHTML(ilObjMediaObject $a_mob)
get media info as html
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:13
assignFullscreenObject(string $a_file)
assign file to fullscreen view
setDescription(string $description)
static stripSlashesArray(array $a_arr, bool $a_strip_html=true, string $a_allow="")
getTab(string $base_class=null)
Get tab link if available.