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