ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
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;
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
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 }
124 return [$this->adv_ref_id, $this->adv_type, $this->adv_subtype];
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 {
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;
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
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");
799 $location = $this->media_manager->resizeImage(
800 $this->object->getId(),
801 $full_file_name,
802 $format,
803 (int) $full_wh_input["width"],
804 (int) $full_wh_input["height"],
805 (bool) ($full_wh_input["constr_prop"] ?? false)
806 );
807 }
808
809 $media_item2->setFormat($format);
810 $media_item2->setLocation($location);
811 $media_item2->setLocationType("LocalFile");
812 $type = "File";
813 }
814
815 if ($form->getInput("full_type") == "Reference") {
816 $format = $location = "";
817 if ($form->getInput("full_reference") != "") {
818 $format = ilObjMediaObject::getMimeType($form->getInput("full_reference"), true);
819 $location = ilUtil::stripSlashes($form->getInput("full_reference"));
820 }
821 }
822
823 if ($form->getInput("full_type") == "Reference" ||
824 ($form->getInput("full_type") == "Standard" && $form->getInput("standard_type") == "Reference")) {
825 $media_item2->setFormat($format);
826 $media_item2->setLocation($location);
827 $media_item2->setLocationType("Reference");
828 $type = "Reference";
829 }
830
831 // determine width and height of known image types
832 /*
833 $wh_input = $form->getInput("full_width_height");
834 $wh = ilObjMediaObject::_determineWidthHeight(
835 $format,
836 $type,
837 $mob_dir . "/" . $location,
838 $media_item2->getLocation(),
839 (bool) ($wh_input["constr_prop"] ?? false),
840 ($form->getInput("full_size") == "original"),
841 ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
842 ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
843 );
844
845 $media_item2->setWidth($wh["width"]);
846 $media_item2->setHeight($wh["height"]);*/
847
848 if ($form->getInput("full_caption") != "") {
849 $media_item2->setCaption($form->getInput("full_caption"));
850 }
851 }
852
853 //ilObjMediaObject::renameExecutables($mob_dir);
854 //ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
855 $a_mob->update();
856 }
857
858
863 public function cancelObject(): void
864 {
865 $this->ctrl->returnToParent($this);
866 }
867
868 public function editObject(): void
869 {
870 $tpl = $this->tpl;
871
872 $this->setPropertiesSubTabs("general");
873 $this->video_gui->addPreviewExtractionToToolbar(
874 $this->object->getId(),
875 self::class
876 );
877 $this->initForm("edit");
878 $this->getValues();
879 $tpl->setContent($this->form_gui->getHTML());
880 }
881
882 public function extractPreviewImageObject(): void
883 {
884 $ilCtrl = $this->ctrl;
885 $this->video_gui->handleExtractionRequest(
886 $this->object->getId()
887 );
888 $ilCtrl->redirect($this, "edit");
889 }
890
894 public function resizeImagesObject(): void
895 {
896 // standard item
897 $std_item = $this->object->getMediaItem("Standard");
898 if ($std_item->getLocationType() == "LocalFile" &&
899 is_int(strpos($std_item->getFormat(), "image"))
900 ) {
901 $location = $this->media_manager->resizeImage(
902 $this->object->getId(),
903 $std_item->getLocation(),
904 $std_item->getFormat(),
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 $location = $this->media_manager->resizeImage(
919 $this->object->getId(),
920 $full_item->getLocation(),
921 $full_item->getFormat(),
922 $full_item->getWidth(),
923 $full_item->getHeight()
924 );
925 $full_item->setLocation($location);
926 $full_item->update();
927 }
928 }
929
930 $this->ctrl->redirect($this, "edit");
931 }
932
933
937 public function getStandardSizeObject(): void
938 {
939 $std_item = $this->object->getMediaItem("Standard");
940 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
941
942 if ($std_item->getLocationType() == "LocalFile") {
943 $file = $mob_dir . "/" . $std_item->getLocation();
944
945 $size = ilMediaImageUtil::getImageSize($file);
946
947 $std_item->setWidth($size[0]);
948 $std_item->setHeight($size[1]);
949 $this->object->update();
950 }
951 $this->ctrl->redirect($this, "edit");
952 }
953
954
958 public function getFullscreenSizeObject(): void
959 {
960 $full_item = $this->object->getMediaItem("Fullscreen");
961 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
962
963 if ($full_item->getLocationType() == "LocalFile") {
964 $file = $mob_dir . "/" . $full_item->getLocation();
965 $size = ilMediaImageUtil::getImageSize($file);
966 $full_item->setWidth($size[0]);
967 $full_item->setHeight($size[1]);
968 $this->object->update();
969 }
970 $this->ctrl->redirect($this, "edit");
971 }
972
973 public function savePropertiesObject(): void
974 {
976 $tpl = $this->tpl;
977 $file = "";
978 $type = "";
979
980 $this->initForm("edit");
981 $form = $this->form_gui;
982
983 if ($form->checkInput()) {
984 $title = trim($form->getInput("standard_title"));
985 $this->object->setTitle($title);
986
987 $std_item = $this->object->getMediaItem("Standard");
988 $location = $std_item->getLocation();
989 $format = $std_item->getFormat();
990 if ($form->getInput("standard_type") == "Reference") {
991 $format = ilObjMediaObject::getMimeType($form->getInput("standard_reference"), true);
992 $std_item->setFormat($format);
993 $std_item->setLocation(ilUtil::secureLink($form->getInput("standard_reference")));
994 $std_item->setLocationType("Reference");
995 }
996 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
997 if ($form->getInput("standard_type") == "File") {
998 $resize = false;
999 if ($_FILES['standard_file']['name'] != "") {
1000 //$file_name = ilObjMediaObject::fixFilename($_FILES['standard_file']['name']);
1001 $file_name = $_FILES['standard_file']['name'];
1002 $this->media_manager->addFileFromLegacyUpload(
1003 $this->object->getId(),
1004 $_FILES['standard_file']['tmp_name']
1005 );
1006
1007 // get mime type
1008 $format = ilObjMediaObject::getMimeType($file_name, true);
1009 $location = $file_name;
1010
1011 $resize = true;
1012 } elseif ($form->getInput("standard_resize")) {
1013 $file = $mob_dir . "/" . $location;
1014 $resize = true;
1015 }
1016
1017 // resize
1018 if ($resize) {
1019 if ($form->getInput("standard_size") != "original" &&
1020 is_int(strpos($format, "image"))) {
1021 $wh_input = $form->getInput("standard_width_height");
1022 $location = $this->media_manager->resizeImage(
1023 $this->object->getId(),
1024 $location,
1025 $format,
1026 (int) $wh_input["width"],
1027 (int) $wh_input["height"],
1028 (bool) ($wh_input["constr_prop"] ?? false)
1029 );
1030 }
1031 $std_item->setFormat($format);
1032 $std_item->setLocation($location);
1033 }
1034
1035 $std_item->setLocationType("LocalFile");
1036 }
1037 $this->object->setDescription($format);
1038 // determine width and height of known image types
1039 $wh_input = $form->getInput("standard_width_height");
1041 $format,
1042 $form->getInput("standard_type"),
1043 $mob_dir . "/" . $location,
1044 $std_item->getLocation(),
1045 (bool) ($wh_input["constr_prop"] ?? false),
1046 ($form->getInput("standard_size") == "original"),
1047 ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
1048 ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
1049 );
1050 if ($wh["info"] != "") {
1051 $this->tpl->setOnScreenMessage('info', $wh["info"], true);
1052 }
1053 $std_item->setWidth($wh["width"]);
1054 $std_item->setHeight($wh["height"]);
1055
1056 // set caption
1057 $std_item->setCaption($form->getInput("standard_caption"));
1058
1059 // text representation
1060 $std_item->setTextRepresentation($form->getInput("text_representation"));
1061
1062 $this->video_gui->savePreviewInput($form, $this->object->getId());
1063
1064 // set parameters
1065 if ($this->media_type->usesParameterProperty($std_item->getFormat())) {
1066 if (!$this->media_type->usesAutoStartParameterOnly(
1067 $std_item->getLocation(),
1068 $std_item->getFormat()
1069 )) {
1070 $std_item->setParameters($form->getInput("standard_parameters"));
1071 }
1072 }
1073
1074 // "None" selected
1075 if ($form->getInput("full_type") == "None") {
1076 if ($this->object->hasFullscreenItem()) { // delete existing
1077 $this->object->removeMediaItem("Fullscreen");
1078 }
1079 } else { // Not "None" -> we need one
1080 if ($this->object->hasFullscreenItem()) { // take existing one
1081 $full_item = $this->object->getMediaItem("Fullscreen");
1082 } else { // create one
1083 $full_item = new ilMediaItem();
1084 $this->object->addMediaItem($full_item);
1085 $full_item->setPurpose("Fullscreen");
1086 }
1087 $location = $full_item->getLocation();
1088 $format = $full_item->getFormat();
1089 if ($form->getInput("full_type") == "Reference") {
1090 $format = ilObjMediaObject::getMimeType($form->getInput("full_reference"), true);
1091 $full_item->setFormat($format);
1092 $full_item->setLocationType("Reference");
1093 $location = ilUtil::secureLink($form->getInput("full_reference"));
1094 $type = "Reference";
1095 $full_item->setLocation($location);
1096 }
1097 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
1098 if ($form->getInput("full_type") == "File") {
1099 $resize = false;
1100 if ($_FILES['full_file']['name'] != "") {
1101 $full_file_name = $_FILES['full_file']['name'];
1102 $this->media_manager->addFileFromLegacyUpload(
1103 $this->object->getId(),
1104 $_FILES['full_file']['tmp_name']
1105 );
1106
1107 $format = ilObjMediaObject::getMimeType($full_file_name);
1108 $location = $full_file_name;
1109
1110 $resize = true;
1111 } elseif ($form->getInput("full_resize")) {
1112 $resize = true;
1113 }
1114
1115 // resize
1116 if ($resize) {
1117 if ($form->getInput("full_size") != "original" &&
1118 is_int(strpos($format, "image"))) {
1119 $wh_input = $form->getInput("full_width_height");
1120 $location = $this->media_manager->resizeImage(
1121 $this->object->getId(),
1122 $location,
1123 $format,
1124 (int) $wh_input["width"],
1125 (int) $wh_input["height"],
1126 (bool) ($wh_input["constr_prop"] ?? false)
1127 );
1128 }
1129 $full_item->setFormat($format);
1130 $full_item->setLocation($location);
1131 }
1132
1133 $full_item->setLocationType("LocalFile");
1134 $type = "File";
1135 }
1136 if ($form->getInput("full_type") == "Standard") {
1137 $format = $std_item->getFormat();
1138 $location = $std_item->getLocation();
1139 $full_item->setLocationType($std_item->getLocationType());
1140 $full_item->setFormat($format);
1141 $full_item->setLocation($location);
1142 $type = $std_item->getLocationType();
1143 if ($type == "LocalFile") {
1144 $type = "File";
1145 }
1146 // resize image
1147 if ($form->getInput("full_size") != "original" &&
1148 is_int(strpos($format, "image")) &&
1149 $full_item->getLocationType() == "LocalFile") {
1150 $wh_input = $form->getInput("full_width_height");
1151 $location = $this->media_manager->resizeImage(
1152 $this->object->getId(),
1153 $location,
1154 $format,
1155 (int) $wh_input["width"],
1156 (int) $wh_input["height"],
1157 (bool) ($wh_input["constr_prop"] ?? false)
1158 );
1159 }
1160 }
1161
1162 // determine width and height of known image types
1163 $wh_input = $form->getInput("full_width_height");
1165 $format,
1166 $type,
1167 $mob_dir . "/" . $location,
1168 $full_item->getLocation(),
1169 (bool) ($wh_input["constr_prop"] ?? false),
1170 ($form->getInput("full_size") == "original"),
1171 ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
1172 ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
1173 );
1174 if ($wh["info"] != "") {
1175 $this->tpl->setOnScreenMessage('info', $wh["info"], true);
1176 }
1177
1178 $full_item->setWidth($wh["width"]);
1179 $full_item->setHeight($wh["height"]);
1180 $full_item->setLocation($location);
1181
1182 $full_item->setCaption($form->getInput("full_caption"));
1183
1184 // text representation
1185 $full_item->setTextRepresentation($form->getInput("full_text_representation"));
1186
1187
1188 // set parameters
1189 if ($this->media_type->usesParameterProperty($std_item->getFormat())) {
1190 if (!$this->media_type->usesAutoStartParameterOnly(
1191 $std_item->getLocation(),
1192 $std_item->getFormat()
1193 )) {
1194 $full_item->setParameters($form->getInput("full_parameters"));
1195 }
1196 }
1197 }
1198
1199 $this->object->update();
1200 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1201 $this->ctrl->redirect($this, "edit");
1202 } else {
1203 $this->form_gui->setValuesByPost();
1204 $tpl->setContent($this->form_gui->getHTML());
1205 }
1206 }
1207
1211 public function showAllUsagesObject(): void
1212 {
1213 $this->showUsagesObject(true);
1214 }
1215
1216
1220 public function showUsagesObject(
1221 bool $a_all = false
1222 ): void {
1223 $tpl = $this->tpl;
1224 $ilTabs = $this->tabs;
1225 $lng = $this->lng;
1226 $ilCtrl = $this->ctrl;
1227
1228 $ilTabs->addSubTab(
1229 "current_usages",
1230 $lng->txt("cont_current_usages"),
1231 $ilCtrl->getLinkTarget($this, "showUsages")
1232 );
1233
1234 $ilTabs->addSubTab(
1235 "all_usages",
1236 $lng->txt("cont_all_usages"),
1237 $ilCtrl->getLinkTarget($this, "showAllUsages")
1238 );
1239
1240 if ($a_all) {
1241 $ilTabs->activateSubTab("all_usages");
1242 $cmd = "showAllUsages";
1243 } else {
1244 $ilTabs->activateSubTab("current_usages");
1245 $cmd = "showUsages";
1246 }
1247
1249 $mob = $this->object;
1250 $usages_table = new ilMediaObjectUsagesTableGUI(
1251 $this,
1252 $cmd,
1253 $mob,
1254 $a_all
1255 );
1256 $tpl->setContent($usages_table->getHTML());
1257 }
1258
1262 public static function _getMediaInfoHTML(
1263 ilObjMediaObject $a_mob
1264 ): string {
1265 global $DIC;
1266
1267 $lng = $DIC->language();
1268 $lom_services = $DIC->learningObjectMetadata();
1269 $media_manager = $DIC->mediaObjects()->internal()->domain()->mediaObject();
1270
1271 $tpl = new ilTemplate("tpl.media_info.html", true, true, "components/ILIAS/MediaObjects");
1272 $types = array("Standard", "Fullscreen");
1273 foreach ($types as $type) {
1274 if ($type == "Fullscreen" && !$a_mob->hasFullscreenItem()) {
1275 continue;
1276 }
1277
1278 $med = $a_mob->getMediaItem($type);
1279 if (!$med) {
1280 return "";
1281 }
1282
1283 $tpl->setCurrentBlock("media_info");
1284 if ($type == "Standard") {
1285 $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_std_view"));
1286 } else {
1287 $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_fullscreen"));
1288 }
1289 $tpl->setVariable("TXT_TYPE", $lng->txt("cont_" . strtolower($med->getLocationType())));
1290 $tpl->setVariable("VAL_LOCATION", $med->getLocation());
1291 if ($med->getLocationType() == "LocalFile") {
1292
1293 try {
1294 $info = $media_manager->getInfoOfEntry($med->getMobId(), "/" . $med->getLocation());
1295 } catch (Exception $e) {
1296 }
1297
1298 $size = $info["size"] ?? 0;
1299 $tpl->setVariable("VAL_FILE_SIZE", " ($size " . $lng->txt("bytes") . ")");
1300 }
1301 $tpl->setVariable("TXT_FORMAT", $lng->txt("cont_format"));
1302 $tpl->setVariable("VAL_FORMAT", $med->getFormat());
1303 if ($med->getWidth() != "" && $med->getHeight() != "") {
1304 $tpl->setCurrentBlock("size");
1305 $tpl->setVariable("TXT_SIZE", $lng->txt("size"));
1306 $tpl->setVariable("VAL_SIZE", $med->getWidth() . "x" . $med->getHeight());
1307 $tpl->parseCurrentBlock();
1308 }
1309
1310 // original size
1311 if ($orig_size = $med->getOriginalSize()) {
1312 if (($orig_size["width"] ?? "") !== $med->getWidth() ||
1313 ($orig_size["height"] ?? "") !== $med->getHeight()) {
1314 $tpl->setCurrentBlock("orig_size");
1315 $tpl->setVariable("TXT_ORIG_SIZE", $lng->txt("cont_orig_size"));
1316 $tpl->setVariable("ORIG_WIDTH", $orig_size["width"]);
1317 $tpl->setVariable("ORIG_HEIGHT", $orig_size["height"]);
1318 $tpl->parseCurrentBlock();
1319 }
1320 }
1321
1322 // output caption
1323 if (strlen($med->getCaption())) {
1324 $tpl->setCurrentBlock('additional_info');
1325 $tpl->setVariable('ADD_INFO', $lng->txt('cont_caption') . ': ' . $med->getCaption());
1326 $tpl->parseCurrentBlock();
1327 }
1328
1329 // output keywords
1330 if ($type == "Standard") {
1331 $keyword_data = $lom_services
1332 ->read(0, $med->getMobId(), 'mob', $lom_services->paths()->keywords())
1333 ->allData($lom_services->paths()->keywords());
1334 $presentable_keywords = $lom_services->dataHelper()->makePresentableAsList(
1335 ', ',
1336 ...$keyword_data
1337 );
1338 if ($presentable_keywords !== '') {
1339 $tpl->setCurrentBlock('additional_info');
1340 $tpl->setVariable('ADD_INFO', $lng->txt('keywords') . ': ' . $presentable_keywords);
1341 $tpl->parseCurrentBlock();
1342 }
1343 }
1344
1345 $tpl->setCurrentBlock("media_info");
1346 $tpl->parseCurrentBlock();
1347 }
1348
1349 return $tpl->get();
1350 }
1351
1355 public function setTabs(): void
1356 {
1357 // catch feedback message
1358 $this->getTabs();
1359
1360 //$this->tpl->clearHeader();
1361 if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject") {
1362 $this->tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_mob.svg"));
1363 $this->tpl->setTitle($this->object->getTitle());
1364 } else {
1365 //$title = $this->object->getTitle();
1366 $this->tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_mob.svg"));
1367 $this->tpl->setTitle($this->lng->txt("cont_create_mob"));
1368 }
1369 }
1370
1371 public function getTabs(): void
1372 {
1373 $ilHelp = $this->help;
1374
1375 $ilHelp->setScreenIdComponent("mob");
1376
1377 if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject"
1378 && $this->object->getId() > 0) {
1379 // object properties
1380 $this->tabs_gui->addTarget(
1381 "cont_mob_def_prop",
1382 $this->ctrl->getLinkTarget($this, "edit"),
1383 "edit",
1384 get_class($this)
1385 );
1386
1387 $st_item = $this->object->getMediaItem("Standard");
1388
1389 // link areas
1390
1391 if (is_object($st_item) && $this->getEnabledMapAreas()) {
1392 $format = $st_item->getFormat();
1393 if (substr($format, 0, 5) == "image" && !is_int(strpos($format, "svg"))) {
1394 $this->tabs_gui->addTarget(
1395 "cont_def_map_areas",
1396 $this->ctrl->getLinkTargetByClass(
1397 array("ilobjmediaobjectgui", "ilimagemapeditorgui"),
1398 "editMapAreas"
1399 ),
1400 "editMapAreas",
1401 "ilimagemapeditorgui"
1402 );
1403 }
1404 }
1405
1406 // object usages
1407 $this->tabs_gui->addTarget(
1408 "cont_mob_usages",
1409 $this->ctrl->getLinkTarget($this, "showUsages"),
1410 "showUsages",
1411 get_class($this)
1412 );
1413
1414 // object files
1415 $std_item = $this->object->getMediaItem("Standard");
1416 $full_item = $this->object->getMediaItem("Fullscreen");
1417 $mset = new ilSetting("mobs");
1418 if ($mset->get("file_manager_always") ||
1419 ($this->media_type->usesParameterProperty($std_item->getFormat()) ||
1420 (is_object($full_item) && $this->media_type->usesParameterProperty($full_item->getFormat())))
1421 ) {
1422 $this->tabs_gui->addTarget(
1423 "cont_files",
1424 $this->ctrl->getLinkTargetByClass(
1425 array("ilobjmediaobjectgui", ilContainerResourceGUI::class),
1426 ""
1427 ),
1428 "",
1429 "ilContainerResourceGUI"
1430 );
1431 }
1432
1433 $mdgui = new ilObjectMetaDataGUI(null, $this->object->getType(), $this->object->getId());
1434 $mdtab = $mdgui->getTab("ilobjmediaobjectgui");
1435 if ($mdtab) {
1436 $this->tabs_gui->addTarget(
1437 "meta_data",
1438 $mdtab,
1439 "",
1440 "ilmdeditorgui"
1441 );
1442 }
1443 }
1444
1445 // back to upper context
1446 if ($this->back_title != "") {
1447 $this->tabs_gui->setBackTarget(
1448 $this->back_title,
1449 $this->ctrl->getParentReturn($this)
1450 );
1451 }
1452 }
1453
1457 public static function includePresentationJS(
1458 ?ilGlobalTemplateInterface $a_tpl = null
1459 ): void {
1460 global $DIC;
1461
1462 $tpl = $DIC["tpl"];
1463
1464 if ($a_tpl == null) {
1465 $a_tpl = $tpl;
1466 }
1467
1469 $a_tpl->addJavaScript("components/ILIAS/COPage/js/ilCOPagePres.js");
1470
1471 //ilPlayerUtil::initMediaElementJs($a_tpl);
1472 }
1473
1474 public function setPropertiesSubTabs(
1475 string $a_active
1476 ): void {
1477 $ilTabs = $this->tabs;
1478 $ilCtrl = $this->ctrl;
1479 $lng = $this->lng;
1480
1481 $ilTabs->activateTab("cont_mob_def_prop");
1482
1483 $ilTabs->addSubTab(
1484 "general",
1485 $lng->txt("mob_general"),
1486 $ilCtrl->getLinkTarget($this, "edit")
1487 );
1488
1489 if ($this->object->getMediaItem("Standard")->getFormat() == "video/webm" ||
1490 $this->object->getMediaItem("Standard")->getFormat() == "video/mp4") {
1491 $ilTabs->addSubTab(
1492 "subtitles",
1493 $lng->txt("mob_subtitles"),
1494 $ilCtrl->getLinkTarget($this, "listSubtitleFiles")
1495 );
1496 }
1497
1498 $ilTabs->activateSubTab($a_active);
1499 }
1500
1501 public function listSubtitleFilesObject(): void
1502 {
1503 $ilToolbar = $this->toolbar;
1504 $tpl = $this->tpl;
1505 $ilCtrl = $this->ctrl;
1506 $lng = $this->lng;
1507 $ilUser = $this->user;
1508
1509 $this->setPropertiesSubTabs("subtitles");
1510 $this->media_manager->generateMissingVTT($this->object->getId());
1511
1512 if (!in_array("vtt", $this->file_service_settings->getWhiteListedSuffixes())) {
1513 $tpl->setOnScreenMessage("info", $lng->txt("mob_srt_not_allowed"));
1514 } else {
1515
1516 // upload file
1517 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
1518 $fi = new ilFileInputGUI($lng->txt("mob_subtitle_file") . " (.vtt)", "subtitle_file");
1519 $fi->setSuffixes(array("vtt"));
1520 $ilToolbar->addInputItem($fi, true);
1521
1522 // language
1523 $options = $this->md->getLOMLanguagesForSelectInputs();
1524 $si = new ilSelectInputGUI($this->lng->txt("mob_language"), "language");
1525 $si->setOptions($options);
1526 $si->setValue($ilUser->getLanguage());
1527 $ilToolbar->addInputItem($si, true);
1528
1529 $ilToolbar->addFormButton($lng->txt("upload"), "uploadSubtitleFile");
1530
1531 $ilToolbar->addSeparator();
1532 $ilToolbar->addFormButton($lng->txt("mob_upload_multi_srt"), "uploadMultipleSubtitleFileForm");
1533
1534 //$ilToolbar->addSeparator();
1535 //$ilToolbar->addFormButton($lng->txt("mob_generate_vtt"), "generateVTT");
1536 }
1537
1539 $mob = $this->object;
1540 $tab = new ilMobSubtitleTableGUI($this, "listSubtitleFiles", $mob);
1541
1542 $tpl->setContent($tab->getHTML());
1543 }
1544
1545 public function uploadSubtitleFileObject(): void
1546 {
1547 $lng = $this->lng;
1548 $ilCtrl = $this->ctrl;
1549
1550 if ($this->object->uploadSrtFile(
1551 $_FILES["subtitle_file"]["tmp_name"],
1552 $this->sub_title_request->getLanguage()
1553 )) {
1554 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1555 }
1556 $ilCtrl->redirect($this, "listSubtitleFiles");
1557 }
1558
1562 public function confirmSrtDeletionObject(): void
1563 {
1564 $ilCtrl = $this->ctrl;
1565 $tpl = $this->tpl;
1566 $lng = $this->lng;
1567
1568 $lng->loadLanguageModule("meta");
1569
1570 $srts = $this->sub_title_request->getSrtFiles();
1571 if (count($srts) == 0) {
1572 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1573 $ilCtrl->redirect($this, "listSubtitleFiles");
1574 } else {
1575 $cgui = new ilConfirmationGUI();
1576 $cgui->setFormAction($ilCtrl->getFormAction($this));
1577 $cgui->setHeaderText($lng->txt("mob_really_delete_srt"));
1578 $cgui->setCancel($lng->txt("cancel"), "listSubtitleFiles");
1579 $cgui->setConfirm($lng->txt("delete"), "deleteSrtFiles");
1580 foreach ($srts as $i) {
1581 $p = explode(":", $i);
1582 $cgui->addItem("srt[]", $i, "subtitle_" . $p[0] . "." . $p[1] . " (" . $lng->txt("meta_l_" . $p[0]) . ")");
1583 }
1584
1585 $tpl->setContent($cgui->getHTML());
1586 }
1587 }
1588
1592 public function deleteSrtFilesObject(): void
1593 {
1594 $lng = $this->lng;
1595 $ilCtrl = $this->ctrl;
1596
1597 $srts = $this->sub_title_request->getSrtFiles();
1598 $deleted = false;
1599 foreach ($srts as $i) {
1600 if (strlen($i) == 6 && !is_int(strpos($i, "."))) {
1601 $p = explode(":", $i);
1602 $this->object->removeAdditionalFile("srt/subtitle_" . $p[0] . "." . $p[1]);
1603 $deleted = true;
1604 }
1605 }
1606 if ($deleted) {
1607 $this->tpl->setOnScreenMessage('success', $lng->txt("mob_srt_files_deleted"), true);
1608 }
1609 $ilCtrl->redirect($this, "listSubtitleFiles");
1610 }
1611
1613 {
1614 $ilToolbar = $this->toolbar;
1615 $lng = $this->lng;
1616 $ilCtrl = $this->ctrl;
1617
1618 $this->tpl->setOnScreenMessage('info', $lng->txt("mob_upload_multi_srt_howto"));
1619
1620 $this->setPropertiesSubTabs("subtitles");
1621
1622 // upload file
1623 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
1624 $fi = new ilFileInputGUI($lng->txt("mob_subtitle_file") . " (.zip)", "subtitle_file");
1625 $fi->setSuffixes(array("zip"));
1626 $ilToolbar->addInputItem($fi, true);
1627
1628 $ilToolbar->addFormButton($lng->txt("upload"), "uploadMultipleSubtitleFile");
1629 }
1630
1631 public function uploadMultipleSubtitleFileObject(): void
1632 {
1633 try {
1634 $this->object->uploadMultipleSubtitleFile(ilArrayUtil::stripSlashesArray($_FILES["subtitle_file"]));
1635 $this->ctrl->redirect($this, "showMultiSubtitleConfirmationTable");
1636 } catch (ilMediaObjectsException $e) {
1637 $this->tpl->setOnScreenMessage('failure', $e->getMessage(), true);
1638 $this->ctrl->redirect($this, "uploadMultipleSubtitleFileForm");
1639 }
1640 }
1641
1646 {
1647 $tpl = $this->tpl;
1648
1649 $this->setPropertiesSubTabs("subtitles");
1650
1651 $tab = new ilMultiSrtConfirmationTable2GUI($this, "showMultiSubtitleConfirmationTable");
1652 $tpl->setContent($tab->getHTML());
1653 }
1654
1658 public function cancelMultiSrtObject(): void
1659 {
1660 $this->object->clearMultiSrtDirectory();
1661 $this->ctrl->redirect($this, "listSubtitleFiles");
1662 }
1663
1667 public function saveMultiSrtObject(): void
1668 {
1669 $ilCtrl = $this->ctrl;
1670 $srt_files = $this->object->getMultiSrtFiles();
1671 $files = $this->sub_title_request->getFiles();
1672 foreach ($files as $f) {
1673 foreach ($srt_files as $srt_file) {
1674 if ($f == $srt_file["filename"]) {
1675 $this->object->uploadSrtFile($this->object->getMultiSrtUploadDir() . "/" . $srt_file["filename"], $srt_file["lang"], "rename");
1676 }
1677 }
1678 }
1679 $this->object->clearMultiSrtDirectory();
1680 $ilCtrl->redirect($this, "listSubtitleFiles");
1681 }
1682
1683 protected function generateVTTObject(): void
1684 {
1685 $this->media_manager->generateMissingVTT($this->object->getId());
1686 $this->ctrl->redirect($this, "listSubtitleFiles");
1687 }
1688}
$location
Definition: buildRTE.php:22
error(string $a_errmsg)
static stripSlashesArray(array $a_arr, bool $a_strip_html=true, string $a_allow="")
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling.
This class represents a file property in a property form.
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 class represents a section header in a property form.
Help GUI class.
User interface class for map editor.
loadLanguageModule(string $a_module)
Load language module.
static getImageSize(string $a_location)
Get image size from location.
Class ilMediaItem Media Item, component of a media object (file or reference)
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...
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...
This class represents a non editable value in a property form.
Editing User Interface for MediaObjects within LMs (see ILIAS DTD)
getAdvMdRecordObject()
Get adv md record type.
deleteSrtFilesObject()
Delete srt files.
cancelMultiSrtObject()
Cancel Multi Feedback.
getValues()
Get values for form.
checkFixSize()
Check fix size (for map editing hint)
showAllUsagesObject()
Show all media object usages (incl history)
initForm(string $a_mode="create")
saveObject()
create new media object
showMultiSubtitleConfirmationTableObject()
List of srt files in zip file.
__construct( $a_data, int $a_id=0, bool $a_call_by_reference=false, bool $a_prepare_output=false)
SubtitlesGUIRequest $sub_title_request
setWidthPreset(int $a_val)
Set width preset (e.g.
getStandardSizeObject()
set original size of standard file
confirmSrtDeletionObject()
Confirm srt file deletion.
getTabs()
@abstract overwrite in derived GUI class of your object type
setPropertiesSubTabs(string $a_active)
createObject()
create new object form
ilFileServicesSettings $file_service_settings
ILIAS MediaObjects MediaObjectManager $media_manager
setEnabledMapAreas(bool $a_enabledmapareas)
ILIAS MediaObjects Video GUIService $video_gui
setHeightPreset(int $a_val)
Set height preset (e.g.
getFullscreenSizeObject()
set original size of fullscreen file
static includePresentationJS(?ilGlobalTemplateInterface $a_tpl=null)
Include media object presentation JS.
static _getMediaInfoHTML(ilObjMediaObject $a_mob)
get media info as html
resizeImagesObject()
resize images to specified size
setObjectPerCreationForm(ilObjMediaObject $a_mob)
Set media object values from creation form.
saveMultiSrtObject()
Save selected srt files as new srt files.
ILIAS MediaObjects MediaType MediaTypeManager $media_type
setAdvMdRecordObject(int $a_adv_ref_id, string $a_adv_type, string $a_adv_subtype="-")
Set object, that defines the adv md records being used.
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)
getMediaItem(string $a_purpose)
get item for media purpose
static fixFilename(string $a_name)
Fix filename of uploaded file.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
addMediaItem(ilMediaItem $a_item)
addMediaItemFromLegacyUpload(string $purpose, string $tmp_name, string $name, int $resize_width=0, int $resize_height=0, bool $constrain_proportions=true, bool $deduce_size=false)
create(bool $a_create_meta_data=false, bool $a_save_media_items=true, int $from_mob_id=0)
static _getDirectory(int $a_mob_id)
Get absolute directory.
update(bool $a_upload=false)
Class ilObjectGUI Basic methods of all Output classes.
ilLanguage $lng
Class ilObjectMetaDataGUI.
setTitle(string $title)
setDescription(string $description)
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
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)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static secureLink(string $a_str)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static initjQuery(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
$info
Definition: entry_point.php:21
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26