ILIAS  release_8 Revision v8.24
class.ilObjMediaObjectGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
32 protected int $height_preset = 0;
33 protected int $width_preset = 0;
34 protected string $back_title = "";
36 protected ilHelpGUI $help;
37 protected ilTabsGUI $tabs;
38
39 // $adv_ref_id - $adv_type - $adv_subtype:
40 // Object, that defines the adv md records being used. Default is $this->object, but the
41 // context may set another object (e.g. media pool for media objects)
42 protected ?int $adv_ref_id = null;
43 protected ?string $adv_type = null;
44 protected ?string $adv_subtype = null;
45 protected \ILIAS\MediaObjects\MediaType\MediaTypeManager $media_type;
46 public string $header = "";
47 public string $target_script = "";
48 public bool $enabledmapareas = true;
49
53 public function __construct(
54 $a_data,
55 int $a_id = 0,
56 bool $a_call_by_reference = false,
57 bool $a_prepare_output = false
58 ) {
59 global $DIC;
60
61 $this->access = $DIC->access();
62 $this->error = $DIC["ilErr"];
63 $this->help = $DIC["ilHelp"];
64 $this->tabs = $DIC->tabs();
65 $this->toolbar = $DIC->toolbar();
66 $this->user = $DIC->user();
67 $lng = $DIC->language();
68 $ilCtrl = $DIC->ctrl();
69 $this->media_type = $DIC->mediaObjects()
70 ->internal()
71 ->domain()
72 ->mediaType();
73
74 $this->ctrl = $ilCtrl;
75 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
76 $this->lng = $lng;
77 $this->back_title = "";
78 $this->type = "mob";
79
80 $this->sub_title_request = $DIC->mediaObjects()
81 ->internal()
82 ->gui()
83 ->subTitles()
84 ->request();
85
87 $this->file_service_settings = $DIC->fileServiceSettings();
88 }
89
94 public function setAdvMdRecordObject(
95 int $a_adv_ref_id,
96 string $a_adv_type,
97 string $a_adv_subtype = "-"
98 ): void {
99 $this->adv_ref_id = $a_adv_ref_id;
100 $this->adv_type = $a_adv_type;
101 $this->adv_subtype = $a_adv_subtype;
102 }
103
108 public function getAdvMdRecordObject(): ?array
109 {
110 if ($this->adv_type == null) {
111 throw new ilMediaObjectsException("Missing obj type (getAdvMdRecordObject)");
112 // seems to be obsolete, since $this->obj_type is non-existent
113 //return [$this->ref_id, $this->obj_type, $this->sub_type];
114 }
115 return [$this->adv_ref_id, $this->adv_type, $this->adv_subtype];
116 }
117
118 public function setHeader(
119 string $a_title = ""
120 ): void {
121 $this->header = $a_title;
122 }
123
124 public function getHeader(): string
125 {
126 return $this->header;
127 }
128
129 public function setEnabledMapAreas(
130 bool $a_enabledmapareas
131 ): void {
132 $this->enabledmapareas = $a_enabledmapareas;
133 }
134
135 public function getEnabledMapAreas(): bool
136 {
137 return $this->enabledmapareas;
138 }
139
143 public function setWidthPreset(int $a_val): void
144 {
145 $this->width_preset = $a_val;
146 }
147
148 public function getWidthPreset(): int
149 {
150 return $this->width_preset;
151 }
152
156 public function setHeightPreset(int $a_val): void
157 {
158 $this->height_preset = $a_val;
159 }
160
161 public function getHeightPreset(): int
162 {
163 return $this->height_preset;
164 }
165
166 public function getForm(): ilPropertyFormGUI
167 {
168 return $this->form_gui;
169 }
170
171 protected function assignObject(): void
172 {
173 if ($this->id != 0) {
174 $this->object = new ilObjMediaObject($this->id);
175 }
176 }
177
181 public function returnToContextObject(): void
182 {
183 $this->ctrl->returnToParent($this);
184 }
185
189 public function executeCommand(): void
190 {
192
193 $next_class = $this->ctrl->getNextClass($this);
194 $cmd = $this->ctrl->getCmd();
195 $ret = "";
196
197 switch ($next_class) {
198 case 'ilobjectmetadatagui':
199 $md_gui = new ilObjectMetaDataGUI(null, $this->object->getType(), $this->object->getId());
200 // object is subtype, so we have to do it ourselves
201 $md_gui->addMDObserver($this->object, 'MDUpdateListener', 'General');
202
203 // set adv metadata record dobject
204 if ($this->adv_type != "") {
205 $md_gui->setAdvMdRecordObject($this->adv_ref_id, $this->adv_type, $this->adv_subtype);
206 }
207
208 $this->ctrl->forwardCommand($md_gui);
209 break;
210
211 case "ilimagemapeditorgui":
213 $mob = $this->object;
214 $image_map_edit = new ilImageMapEditorGUI($mob);
215 $ret = $this->ctrl->forwardCommand($image_map_edit);
216 $tpl->setContent($ret);
217 $this->checkFixSize();
218 break;
219
220 case "ilfilesystemgui":
221 $fs_gui = new ilFileSystemGUI(ilFileUtils::getWebspaceDir() . "/mobs/mm_" . $this->object->getId());
222 $fs_gui->setAllowedSuffixes(ilObjMediaObject::getRestrictedFileTypes());
223 $fs_gui->setForbiddenSuffixes(ilObjMediaObject::getForbiddenFileTypes());
224 $fs_gui->activateLabels(true, $this->lng->txt("cont_purpose"));
225 $fs_gui->setTableId("mobfs" . $this->object->getId());
226 $fs_gui->labelFile(
227 $this->object->getMediaItem("Standard")->getLocation(),
228 $this->lng->txt("cont_std_view")
229 );
230 if ($this->object->hasFullscreenItem()) {
231 $fs_gui->labelFile(
232 $this->object->getMediaItem("Fullscreen")->getLocation(),
233 $this->lng->txt("cont_fullscreen")
234 );
235 }
236 $fs_gui->addCommand($this, "assignStandardObject", $this->lng->txt("cont_assign_std"));
237 $fs_gui->addCommand($this, "assignFullscreenObject", $this->lng->txt("cont_assign_full"));
239 $ret = $this->ctrl->forwardCommand($fs_gui);
242 break;
243
244
245 default:
246 /*
247 if (isset($_POST["editImagemapForward"]) ||
248 isset($_POST["editImagemapForward_x"]) ||
249 isset($_POST["editImagemapForward_y"])) {
250 $cmd = "editImagemapForward";
251 }*/
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 {
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");
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 // standard parameters
385 if ($a_mode == "edit" &&
386 $this->media_type->usesParameterProperty($std_item->getFormat())) {
387 if ($this->media_type->usesAutoStartParameterOnly(
388 $std_item->getLocation(),
389 $std_item->getFormat()
390 )) { // autostart
391 /*$auto = new ilCheckboxInputGUI($lng->txt("cont_autostart"), "standard_autostart");
392 $this->form_gui->addItem($auto);*/
393 } else { // parameters
394 $par = new ilTextAreaInputGUI($lng->txt("cont_parameter"), "standard_parameters");
395 $par->setRows(5);
396 $par->setCols(50);
397 $this->form_gui->addItem($par);
398 }
399 }
400
401 if ($a_mode == "edit") {
402 $full_item = $this->object->getMediaItem("Fullscreen");
403 }
404
405 // fullscreen view resource
406 $fs_sec = new ilFormSectionHeaderGUI();
407 $fs_sec->setTitle($lng->txt("cont_fullscreen"));
408 $this->form_gui->addItem($fs_sec);
409
410 $radio_prop2 = new ilRadioGroupInputGUI($lng->txt("cont_resource"), "full_type");
411 $op1 = new ilRadioOption($lng->txt("cont_none"), "None");
412 $radio_prop2->addOption($op1);
413 $op4 = new ilRadioOption($lng->txt("cont_use_same_resource_as_above"), "Standard");
414 $radio_prop2->addOption($op4);
415 $op2 = new ilRadioOption($lng->txt("cont_file"), "File");
416 $up = new ilFileInputGUI("", "full_file");
418 $up->setForbiddenSuffixes(ilObjMediaObject::getForbiddenFileTypes());
419 $up->setInfo("");
420 if ($a_mode == "create" || !$full_item || $full_item->getLocationType() != "LocalFile") {
421 $up->setRequired(true);
422 }
423 $op2->addSubItem($up);
424 $radio_prop2->addOption($op2);
425 $op3 = new ilRadioOption($lng->txt("url"), "Reference");
426 $ref = new ilUriInputGUI("", "full_reference");
427 $ref->setInfo($lng->txt("cont_ref_helptext"));
428 $ref->setRequired(true);
429 $op3->addSubItem($ref);
430 $radio_prop2->addOption($op3);
431 $radio_prop2->setValue("None");
432 $this->form_gui->addItem($radio_prop2);
433
434 // fullscreen format
435 if ($a_mode == "edit") {
436 if ($this->object->hasFullscreenItem()) {
437 $format = new ilNonEditableValueGUI($lng->txt("cont_format"), "full_format");
438 $format->setValue($full_item->getFormat());
439 $this->form_gui->addItem($format);
440 }
441 }
442
443 // fullscreen size
444 $full_support_constraint_props = false;
445 $radio_size = new ilRadioGroupInputGUI($lng->txt("size"), "full_size");
446 if ($a_mode == "edit") {
447 $add_str = "";
448 if ($this->object->hasFullscreenItem() && ($orig_size = $full_item->getOriginalSize())) {
449 $add_str = " (" . ($orig_size["width"] ?? "") . " x " . ($orig_size["height"] ?? "") . ")";
450
451 if (is_int(strpos($full_item->getFormat(), "image"))
452 && $full_item->getLocationType() == "LocalFile") {
453 $full_support_constraint_props = true;
454 }
455 }
456 $op1 = new ilRadioOption($lng->txt("cont_resource_size") . $add_str, "original");
457 $op1->setInfo($lng->txt("cont_resource_size_info"));
458 $op2 = new ilRadioOption($lng->txt("cont_custom_size"), "selected");
459 } else {
460 $op1 = new ilRadioOption($lng->txt("cont_orig_size"), "original");
461 $op1->setInfo($lng->txt("cont_resource_size_info"));
462 $op2 = new ilRadioOption($lng->txt("cont_adjust_size"), "selected");
463 }
464 $radio_size->addOption($op1);
465
466 // width/height
467 $width_height = new ilWidthHeightInputGUI($lng->txt("cont_width") .
468 " / " . $lng->txt("cont_height"), "full_width_height");
469 if ($full_support_constraint_props) {
470 $width_height->setSupportConstraintsProps(true);
471 $width_height->setConstrainProportions(true);
472 }
473 $op2->addSubItem($width_height);
474
475 // resize image
476 if ($a_mode == "edit") {
477 $full_item = $this->object->getMediaItem("Fullscreen");
478 if ($this->object->hasFullscreenItem() &&
479 is_int(strpos($full_item->getFormat(), "image")) &&
480 $full_item->getLocationType() == "LocalFile") {
481 $resize = new ilCheckboxInputGUI(
482 $lng->txt("cont_resize_img"),
483 "full_resize"
484 );
485 $op2->addSubItem($resize);
486 }
487 }
488
489 $radio_size->setValue("original");
490 $radio_size->addOption($op2);
491 $this->form_gui->addItem($radio_size);
492
493 // fullscreen caption
494 $caption = new ilTextAreaInputGUI($lng->txt("cont_caption"), "full_caption");
495 $caption->setCols(30);
496 $caption->setRows(2);
497 $this->form_gui->addItem($caption);
498
499 /*$caption = new ilTextInputGUI($lng->txt("cont_caption"), "full_caption");
500 $caption->setSize(40);
501 $caption->setMaxLength(200);
502 $this->form_gui->addItem($caption);*/
503
504 // text representation (alt text)
505 if ($a_mode == "edit" && $this->object->hasFullscreenItem() && $this->media_type->usesAltTextProperty($std_item->getFormat())) {
506 $ta = new ilTextAreaInputGUI($lng->txt("text_repr"), "full_text_representation");
507 $ta->setCols(30);
508 $ta->setRows(2);
509 $ta->setInfo($lng->txt("text_repr_info"));
510 $this->form_gui->addItem($ta);
511 }
512
513
514 // fullscreen parameters
515 if ($a_mode == "edit" && $this->object->hasFullscreenItem() &&
516 $this->media_type->usesParameterProperty($full_item->getFormat())) {
517 if ($this->media_type->usesAutoStartParameterOnly(
518 $full_item->getLocation(),
519 $full_item->getFormat()
520 )) {
521 /*$auto = new ilCheckboxInputGUI($lng->txt("cont_autostart"), "full_autostart");
522 $this->form_gui->addItem($auto);*/
523 } else {
524 $par = new ilTextAreaInputGUI($lng->txt("cont_parameter"), "full_parameters");
525 $par->setRows(5);
526 $par->setCols(50);
527 $this->form_gui->addItem($par);
528 }
529 }
530
531
532 if ($a_mode == "edit") {
533 $this->form_gui->setTitle($lng->txt("cont_edit_mob"));
534 $this->form_gui->addCommandButton("saveProperties", $lng->txt("save"));
535 } else {
536 $this->form_gui->setTitle($lng->txt("cont_insert_mob"));
537 $this->form_gui->addCommandButton("save", $lng->txt("save"));
538 $this->form_gui->addCommandButton("cancel", $lng->txt("cancel"));
539 }
540 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
541 }
542
546 protected function checkFixSize(): void
547 {
548 $std_item = $this->object->getMediaItem("Standard");
549 if ($std_item->getWidth() == "" || $std_item->getHeight() == "") {
550 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("mob_no_fixed_size_map_editing"));
551 }
552 }
553
554
558 public function getValues(): void
559 {
560 $values = array();
561
562 $values["standard_title"] = $this->object->getTitle();
563
564 $std_item = $this->object->getMediaItem("Standard");
565 if ($std_item->getLocationType() == "LocalFile") {
566 $values["standard_type"] = "File";
567 $values["standard_file"] = $std_item->getLocation();
568 } else {
569 $values["standard_type"] = "Reference";
570 $values["standard_reference"] = $std_item->getLocation();
571 }
572 $values["standard_format"] = $std_item->getFormat();
573 $values["standard_width_height"]["width"] = $std_item->getWidth();
574 $values["standard_width_height"]["height"] = $std_item->getHeight();
575 $values["standard_width_height"]["constr_prop"] = true;
576
577 $values["standard_size"] = "selected";
578
579 $orig_size = $std_item->getOriginalSize();
580 if ($std_item->getWidth() == "" && $std_item->getHeight() == "") {
581 $values["standard_size"] = "original";
582 $values["standard_width_height"]["width"] = $orig_size["width"] ?? "";
583 $values["standard_width_height"]["height"] = $orig_size["height"] ?? "";
584 }
585
586 $values["standard_caption"] = $std_item->getCaption();
587 $values["text_representation"] = $std_item->getTextRepresentation();
588 if ($this->media_type->usesAutoStartParameterOnly(
589 $std_item->getLocation(),
590 $std_item->getFormat()
591 )) {
592 /*$par = $std_item->getParameters();
593 if ($par["autostart"]) {
594 $values["standard_autostart"] = true;
595 }*/
596 } else {
597 $values["standard_parameters"] = $std_item->getParameterString();
598 }
599
600 $values["full_type"] = "None";
601 $values["full_size"] = "original";
602 if ($this->object->hasFullscreenItem()) {
603 $full_item = $this->object->getMediaItem("Fullscreen");
604 if ($full_item->getLocationType() == "LocalFile") {
605 $values["full_type"] = "File";
606 $values["full_file"] = $full_item->getLocation();
607 } else {
608 $values["full_type"] = "Reference";
609 $values["full_reference"] = $full_item->getLocation();
610 }
611 $values["full_format"] = $full_item->getFormat();
612 $values["full_width_height"]["width"] = $full_item->getWidth();
613 $values["full_width_height"]["height"] = $full_item->getHeight();
614 $values["full_width_height"]["constr_prop"] = true;
615
616 $values["full_size"] = "selected";
617
618 $orig_size = $full_item->getOriginalSize();
619 if ($full_item->getWidth() == "" &&
620 $full_item->getHeight() == "") {
621 $values["full_size"] = "original";
622 $values["full_width_height"]["width"] = $orig_size["width"] ?? "";
623 $values["full_width_height"]["height"] = $orig_size["height"] ?? "";
624 }
625 $values["full_caption"] = $full_item->getCaption();
626 if ($this->media_type->usesAutoStartParameterOnly(
627 $full_item->getLocation(),
628 $full_item->getFormat()
629 )) {
630 /*$par = $full_item->getParameters();
631 if ($par["autostart"]) {
632 $values["full_autostart"] = true;
633 }*/
634 } else {
635 $values["full_parameters"] = $full_item->getParameterString();
636 }
637 $values["full_text_representation"] = $full_item->getTextRepresentation();
638 }
639
640 $this->form_gui->setValuesByArray($values);
641 }
642
646 public function saveObject(): void
647 {
650 $this->initForm();
651 if ($this->form_gui->checkInput()) {
652 $this->object = new ilObjMediaObject();
653 $this->setObjectPerCreationForm($this->object);
654 $this->tpl->setOnScreenMessage('success', $lng->txt("saved_media_object"), true);
655 } else {
656 $this->form_gui->setValuesByPost();
657 $tpl->setContent($this->form_gui->getHTML());
658 }
659 }
660
661 public function checkFormInput(): bool
662 {
663 if (!$this->form_gui->checkInput()) {
664 $this->form_gui->setValuesByPost();
665 return false;
666 }
667 return true;
668 }
669
670
675 ilObjMediaObject $a_mob
676 ): void {
677 $form = $this->form_gui;
678
679 $location = "";
680 $file_name = "";
681 $file = "";
682 $type = "";
683
684 // determinte title and format
685 if (trim($form->getInput("standard_title")) != "") {
686 $title = trim($form->getInput("standard_title"));
687 } else {
688 if ($form->getInput("standard_type") == "File") {
689 $title = $_FILES['standard_file']['name'];
690 } else {
691 $title = $form->getInput("standard_reference");
692 }
693 }
694
695 $a_mob->setTitle($title);
696 $a_mob->setDescription("");
697 $a_mob->create();
698
699 // determine and create mob directory, move uploaded file to directory
700 //$mob_dir = ilFileUtils::getWebspaceDir()."/mobs/mm_".$a_mob->getId();
701 $a_mob->createDirectory();
702 $mob_dir = ilObjMediaObject::_getDirectory($a_mob->getId());
703
704 $media_item = new ilMediaItem();
705 $a_mob->addMediaItem($media_item);
706 $media_item->setPurpose("Standard");
707
708 if ($form->getInput("standard_type") == "File") {
709 $file_name = ilObjMediaObject::fixFilename($_FILES['standard_file']['name']);
710 $file = $mob_dir . "/" . $file_name;
712 $_FILES['standard_file']['tmp_name'],
713 $file_name,
714 $file
715 );
716
717 // get mime type
719 $location = $file_name;
720
721 // resize standard images
722 if ($form->getInput("standard_size") != "original" &&
723 is_int(strpos($format, "image"))) {
724 $wh_input = $form->getInput("standard_width_height");
725
727 $file,
728 (int) $wh_input["width"],
729 (int) $wh_input["height"],
730 (bool) ($wh_input["constr_prop"] ?? false)
731 );
732 }
733
734 // set real meta and object data
735 $media_item->setFormat($format);
736 $media_item->setLocation($location);
737 $media_item->setLocationType("LocalFile");
738 $a_mob->generatePreviewPic(320, 240);
739 } else { // standard type: reference
740 $format = ilObjMediaObject::getMimeType($form->getInput("standard_reference"), true);
741 $media_item->setFormat($format);
742 $media_item->setLocation(ilUtil::secureLink($form->getInput("standard_reference")));
743 $media_item->setLocationType("Reference");
744
745 try {
746 $a_mob->getExternalMetadata();
747 } catch (Exception $e) {
748 }
749 }
750
751 // determine width and height of known image types
752 $wh_input = $form->getInput("standard_width_height");
754 $format,
755 $form->getInput("standard_type"),
756 $mob_dir . "/" . $location,
757 $media_item->getLocation(),
758 (bool) ($wh_input["constr_prop"] ?? false),
759 ($form->getInput("standard_size") == "original"),
760 ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
761 ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
762 );
763 $media_item->setWidth($wh["width"]);
764 $media_item->setHeight($wh["height"]);
765 if ($wh["info"] != "") {
766 $this->tpl->setOnScreenMessage('info', $wh["info"], true);
767 }
768
769 if ($form->getInput("standard_caption") != "") {
770 $media_item->setCaption($form->getInput("standard_caption"));
771 }
772
773
774 $media_item->setHAlign("Left");
775
776 // fullscreen view
777 if ($form->getInput("full_type") != "None") {
778 $media_item2 = new ilMediaItem();
779 $a_mob->addMediaItem($media_item2);
780 $media_item2->setPurpose("Fullscreen");
781
782 // move file / set format and location
783 if ($form->getInput("full_type") == "File") {
784 $format = $location = "";
785 if ($_FILES['full_file']['name'] != "") {
786 $full_file_name = ilObjMediaObject::fixFilename($_FILES['full_file']['name']);
787 $file = $mob_dir . "/" . $full_file_name;
789 $_FILES['full_file']['tmp_name'],
790 $full_file_name,
791 $file
792 );
794 $location = $full_file_name;
795 }
796 } elseif ($form->getInput("full_type") == "Standard" && $form->getInput("standard_type") == "File") {
797 $location = $file_name;
798 }
799
800 // resize file
801 if ($form->getInput("full_type") == "File" ||
802 ($form->getInput("full_type") == "Standard" && $form->getInput("standard_type") == "File")) {
803 if (($form->getInput("full_size") != "original" &&
804 is_int(strpos($format, "image")))
805 ) {
806 $full_wh_input = $form->getInput("full_width_height");
808 $file,
809 (int) $full_wh_input["width"],
810 (int) $full_wh_input["height"],
811 (bool) ($full_wh_input["constr_prop"] ?? false)
812 );
813 }
814
815 $media_item2->setFormat($format);
816 $media_item2->setLocation($location);
817 $media_item2->setLocationType("LocalFile");
818 $type = "File";
819 }
820
821 if ($form->getInput("full_type") == "Reference") {
822 $format = $location = "";
823 if ($form->getInput("full_reference") != "") {
824 $format = ilObjMediaObject::getMimeType($form->getInput("full_reference"), true);
825 $location = ilUtil::stripSlashes($form->getInput("full_reference"));
826 }
827 }
828
829 if ($form->getInput("full_type") == "Reference" ||
830 ($form->getInput("full_type") == "Standard" && $form->getInput("standard_type") == "Reference")) {
831 $media_item2->setFormat($format);
832 $media_item2->setLocation($location);
833 $media_item2->setLocationType("Reference");
834 $type = "Reference";
835 }
836
837 // determine width and height of known image types
838 $wh_input = $form->getInput("full_width_height");
840 $format,
841 $type,
842 $mob_dir . "/" . $location,
843 $media_item2->getLocation(),
844 (bool) ($wh_input["constr_prop"] ?? false),
845 ($form->getInput("full_size") == "original"),
846 ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
847 ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
848 );
849
850 $media_item2->setWidth($wh["width"]);
851 $media_item2->setHeight($wh["height"]);
852
853 if ($form->getInput("full_caption") != "") {
854 $media_item2->setCaption($form->getInput("full_caption"));
855 }
856 }
857
859 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
860 $a_mob->update();
861 }
862
863
868 public function cancelObject(): void
869 {
870 $this->ctrl->returnToParent($this);
871 }
872
873 public function editObject(): void
874 {
876
877 $this->setPropertiesSubTabs("general");
878
879 $this->initForm("edit");
880 $this->getValues();
881 $tpl->setContent($this->form_gui->getHTML());
882 }
883
884
888 public function resizeImagesObject(): void
889 {
890 // directory
891 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
892
893 // standard item
894 $std_item = $this->object->getMediaItem("Standard");
895 if ($std_item->getLocationType() == "LocalFile" &&
896 is_int(strpos($std_item->getFormat(), "image"))
897 ) {
898 $file = $mob_dir . "/" . $std_item->getLocation();
900 $file,
901 $std_item->getWidth(),
902 $std_item->getHeight()
903 );
904 $std_item->setLocation($location);
905 $std_item->update();
906 }
907
908 // fullscreen item
909 if ($this->object->hasFullscreenItem()) {
910 $full_item = $this->object->getMediaItem("Fullscreen");
911 if ($full_item->getLocationType() == "LocalFile" &&
912 is_int(strpos($full_item->getFormat(), "image"))
913 ) {
914 $file = $mob_dir . "/" . $full_item->getLocation();
916 $file,
917 $full_item->getWidth(),
918 $full_item->getHeight()
919 );
920 $full_item->setLocation($location);
921 $full_item->update();
922 }
923 }
924
925 $this->ctrl->redirect($this, "edit");
926 }
927
928
932 public function getStandardSizeObject(): void
933 {
934 $std_item = $this->object->getMediaItem("Standard");
935 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
936
937 if ($std_item->getLocationType() == "LocalFile") {
938 $file = $mob_dir . "/" . $std_item->getLocation();
939
940 $size = ilMediaImageUtil::getImageSize($file);
941
942 $std_item->setWidth($size[0]);
943 $std_item->setHeight($size[1]);
944 $this->object->update();
945 }
946 $this->ctrl->redirect($this, "edit");
947 }
948
949
953 public function getFullscreenSizeObject(): void
954 {
955 $full_item = $this->object->getMediaItem("Fullscreen");
956 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
957
958 if ($full_item->getLocationType() == "LocalFile") {
959 $file = $mob_dir . "/" . $full_item->getLocation();
960 $size = ilMediaImageUtil::getImageSize($file);
961 $full_item->setWidth($size[0]);
962 $full_item->setHeight($size[1]);
963 $this->object->update();
964 }
965 $this->ctrl->redirect($this, "edit");
966 }
967
968 public function savePropertiesObject(): void
969 {
972 $file = "";
973 $type = "";
974
975 $this->initForm("edit");
976 $form = $this->form_gui;
977
978 if ($form->checkInput()) {
979 $title = trim($form->getInput("standard_title"));
980 $this->object->setTitle($title);
981
982 $std_item = $this->object->getMediaItem("Standard");
983 $location = $std_item->getLocation();
984 $format = $std_item->getFormat();
985 if ($form->getInput("standard_type") == "Reference") {
986 $format = ilObjMediaObject::getMimeType($form->getInput("standard_reference"), true);
987 $std_item->setFormat($format);
988 $std_item->setLocation(ilUtil::secureLink($form->getInput("standard_reference")));
989 $std_item->setLocationType("Reference");
990 }
991 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
992 if ($form->getInput("standard_type") == "File") {
993 $resize = false;
994 if ($_FILES['standard_file']['name'] != "") {
995 $file_name = ilObjMediaObject::fixFilename($_FILES['standard_file']['name']);
996 $file = $mob_dir . "/" . $file_name;
998 $_FILES['standard_file']['tmp_name'],
999 $file_name,
1000 $file
1001 );
1002
1003 // get mime type
1005 $location = $file_name;
1006
1007 $resize = true;
1008 } elseif ($form->getInput("standard_resize")) {
1009 $file = $mob_dir . "/" . $location;
1010 $resize = true;
1011 }
1012
1013 // resize
1014 if ($resize) {
1015 if ($form->getInput("standard_size") != "original" &&
1016 is_int(strpos($format, "image"))) {
1017 $wh_input = $form->getInput("standard_width_height");
1019 $file,
1020 (int) $wh_input["width"],
1021 (int) $wh_input["height"],
1022 (bool) ($wh_input["constr_prop"] ?? false)
1023 );
1024 }
1025 $std_item->setFormat($format);
1026 $std_item->setLocation($location);
1027 }
1028
1029 $std_item->setLocationType("LocalFile");
1030 }
1031 $this->object->setDescription($format);
1032 // determine width and height of known image types
1033 $wh_input = $form->getInput("standard_width_height");
1035 $format,
1036 $form->getInput("standard_type"),
1037 $mob_dir . "/" . $location,
1038 $std_item->getLocation(),
1039 (bool) ($wh_input["constr_prop"] ?? false),
1040 ($form->getInput("standard_size") == "original"),
1041 ($wh_input["width"] == "") ? null : (int) $wh_input["width"],
1042 ($wh_input["height"] == "") ? null : (int) $wh_input["height"]
1043 );
1044 if ($wh["info"] != "") {
1045 $this->tpl->setOnScreenMessage('info', $wh["info"], true);
1046 }
1047 $std_item->setWidth($wh["width"]);
1048 $std_item->setHeight($wh["height"]);
1049
1050 // set caption
1051 $std_item->setCaption($form->getInput("standard_caption"));
1052
1053 // text representation
1054 $std_item->setTextRepresentation($form->getInput("text_representation"));
1055
1056 // set parameters
1057 if ($this->media_type->usesParameterProperty($std_item->getFormat())) {
1058 if ($this->media_type->usesAutoStartParameterOnly(
1059 $std_item->getLocation(),
1060 $std_item->getFormat()
1061 )) {
1062 /*
1063 if ($_POST["standard_autostart"]) { // save only autostart flag
1064 $std_item->setParameters('autostart="true"');
1065 } else {
1066 $std_item->setParameters("");
1067 }*/
1068 } else {
1069 $std_item->setParameters(utf8_decode($form->getInput("standard_parameters")));
1070 }
1071 }
1072
1073 // "None" selected
1074 if ($form->getInput("full_type") == "None") {
1075 if ($this->object->hasFullscreenItem()) { // delete existing
1076 $this->object->removeMediaItem("Fullscreen");
1077 }
1078 } else { // Not "None" -> we need one
1079 if ($this->object->hasFullscreenItem()) { // take existing one
1080 $full_item = $this->object->getMediaItem("Fullscreen");
1081 } else { // create one
1082 $full_item = new ilMediaItem();
1083 $this->object->addMediaItem($full_item);
1084 $full_item->setPurpose("Fullscreen");
1085 }
1086 $location = $full_item->getLocation();
1087 $format = $full_item->getFormat();
1088 if ($form->getInput("full_type") == "Reference") {
1089 $format = ilObjMediaObject::getMimeType($form->getInput("full_reference"), true);
1090 $full_item->setFormat($format);
1091 $full_item->setLocationType("Reference");
1092 $location = ilUtil::secureLink($form->getInput("full_reference"));
1093 $type = "Reference";
1094 $full_item->setLocation($location);
1095 }
1096 $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
1097 if ($form->getInput("full_type") == "File") {
1098 $resize = false;
1099 if ($_FILES['full_file']['name'] != "") {
1100 $full_file_name = ilObjMediaObject::fixFilename($_FILES['full_file']['name']);
1101 $file = $mob_dir . "/" . $full_file_name;
1103 $_FILES['full_file']['tmp_name'],
1104 $full_file_name,
1105 $file
1106 );
1107
1109 $location = $full_file_name;
1110
1111 $resize = true;
1112 } elseif ($form->getInput("full_resize")) {
1113 $file = $mob_dir . "/" . $location;
1114 $resize = true;
1115 }
1116
1117 // resize
1118 if ($resize) {
1119 if ($form->getInput("full_size") != "original" &&
1120 is_int(strpos($format, "image"))) {
1121 $wh_input = $form->getInput("full_width_height");
1123 $file,
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 //echo "-".$_POST["full_size"]."-".is_int(strpos($format, "image"))."-".$full_item->getLocationType()."-";
1148 if ($form->getInput("full_size") != "original" &&
1149 is_int(strpos($format, "image")) &&
1150 $full_item->getLocationType() == "LocalFile") {
1151 $file = $mob_dir . "/" . $location;
1152 $wh_input = $form->getInput("full_width_height");
1154 $file,
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 /*
1195 if ($_POST["full_autostart"]) { // save only autostart flag
1196 $full_item->setParameters('autostart="true"');
1197 } else {
1198 $full_item->setParameters("");
1199 }*/
1200 } else {
1201 $full_item->setParameters(utf8_decode($form->getInput("full_parameters")));
1202 }
1203 }
1204 }
1205
1208
1209 $this->object->update();
1210 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1211 $this->ctrl->redirect($this, "edit");
1212 } else {
1213 $this->form_gui->setValuesByPost();
1214 $tpl->setContent($this->form_gui->getHTML());
1215 }
1216 }
1217
1221 public function assignStandardObject(
1222 string $a_file
1223 ): void {
1224 // determine directory
1225 $cur_subdir = dirname($a_file);
1226 $mob_dir = ilFileUtils::getWebspaceDir() . "/mobs/mm_" . $this->object->getId();
1227 $cur_dir = (!empty($cur_subdir))
1228 ? $mob_dir . "/" . $cur_subdir
1229 : $mob_dir;
1230 $file = $cur_dir . "/" . basename($a_file);
1231 $location = $a_file;
1232
1233 if (!is_file($file)) {
1234 $this->ilias->raiseError($this->lng->txt("cont_select_file"), $this->ilias->error_obj->MESSAGE);
1235 }
1236
1237 $std_item = $this->object->getMediaItem("Standard");
1238 $std_item->setLocationType("LocalFile");
1239 $std_item->setLocation($location);
1241 $std_item->setFormat($format);
1242 $this->object->update();
1243 // $this->ctrl->saveParameter($this, "cdir");
1244 $this->ctrl->redirectByClass("ilfilesystemgui", "listFiles");
1245 }
1246
1247
1251 public function assignFullscreenObject(
1252 string $a_file
1253 ): void {
1254 // determine directory
1255 $cur_subdir = dirname($a_file);
1256 $mob_dir = ilFileUtils::getWebspaceDir() . "/mobs/mm_" . $this->object->getId();
1257 $cur_dir = (!empty($cur_subdir))
1258 ? $mob_dir . "/" . $cur_subdir
1259 : $mob_dir;
1260 $file = $cur_dir . "/" . basename($a_file);
1261 $location = $a_file;
1262
1263 if (!is_file($file)) {
1264 $this->ilias->raiseError($this->lng->txt("cont_select_file"), $this->ilias->error_obj->MESSAGE);
1265 }
1266
1267 if (!$this->object->hasFullscreenItem()) { // create new fullscreen item
1268 $std_item = $this->object->getMediaItem("Standard");
1269 $mob_dir = ilFileUtils::getWebspaceDir() . "/mobs/mm_" . $this->object->getId();
1270 $file = $mob_dir . "/" . $location;
1271 $full_item = new ilMediaItem();
1272 $full_item->setMobId($std_item->getMobId());
1273 $full_item->setLocation($location);
1274 $full_item->setLocationType("LocalFile");
1275 $full_item->setFormat(ilObjMediaObject::getMimeType($file));
1276 $full_item->setPurpose("Fullscreen");
1277 $this->object->addMediaItem($full_item);
1278 } else { // alter existing fullscreen item
1279 $full_item = $this->object->getMediaItem("Fullscreen");
1280
1281 $full_item->setLocationType("LocalFile");
1282 $full_item->setLocation($location);
1284 $full_item->setFormat($format);
1285 }
1286 $this->object->update();
1287 // $this->ctrl->saveParameter($this, "cdir");
1288 $this->ctrl->redirectByClass("ilfilesystemgui", "listFiles");
1289 }
1290
1291
1295 public function removeFullscreenObject(): void
1296 {
1297 $this->object->removeMediaItem("Fullscreen");
1298 $this->object->update();
1299
1300 $this->ctrl->redirect($this, "edit");
1301 }
1302
1306 public function addFullscreenObject(): void
1307 {
1308 if (!$this->object->hasFullscreenItem()) {
1309 $std_item = $this->object->getMediaItem("Standard");
1310 $full_item = new ilMediaItem();
1311 $full_item->setMobId($std_item->getMobId());
1312 $full_item->setLocation($std_item->getLocation());
1313 $full_item->setLocationType($std_item->getLocationType());
1314 $full_item->setFormat($std_item->getFormat());
1315 $full_item->setWidth($std_item->getWidth());
1316 $full_item->setHeight($std_item->getHeight());
1317 $full_item->setCaption($std_item->getCaption());
1318 $full_item->setTextRepresentation($std_item->getTextRepresentation());
1319 $full_item->setPurpose("Fullscreen");
1320 $this->object->addMediaItem($full_item);
1321
1322 $this->object->update();
1323 }
1324
1325 $this->ctrl->redirect($this, "edit");
1326 }
1327
1331 public function showAllUsagesObject(): void
1332 {
1333 $this->showUsagesObject(true);
1334 }
1335
1336
1340 public function showUsagesObject(
1341 bool $a_all = false
1342 ): void {
1343 $tpl = $this->tpl;
1344 $ilTabs = $this->tabs;
1345 $lng = $this->lng;
1346 $ilCtrl = $this->ctrl;
1347
1348 $ilTabs->addSubTab(
1349 "current_usages",
1350 $lng->txt("cont_current_usages"),
1351 $ilCtrl->getLinkTarget($this, "showUsages")
1352 );
1353
1354 $ilTabs->addSubTab(
1355 "all_usages",
1356 $lng->txt("cont_all_usages"),
1357 $ilCtrl->getLinkTarget($this, "showAllUsages")
1358 );
1359
1360 if ($a_all) {
1361 $ilTabs->activateSubTab("all_usages");
1362 $cmd = "showAllUsages";
1363 } else {
1364 $ilTabs->activateSubTab("current_usages");
1365 $cmd = "showUsages";
1366 }
1367
1369 $mob = $this->object;
1370 $usages_table = new ilMediaObjectUsagesTableGUI(
1371 $this,
1372 $cmd,
1373 $mob,
1374 $a_all
1375 );
1376 $tpl->setContent($usages_table->getHTML());
1377 }
1378
1382 public static function _getMediaInfoHTML(
1383 ilObjMediaObject $a_mob
1384 ): string {
1385 global $DIC;
1386
1387 $lng = $DIC->language();
1388
1389 $tpl = new ilTemplate("tpl.media_info.html", true, true, "Services/MediaObjects");
1390 $types = array("Standard", "Fullscreen");
1391 foreach ($types as $type) {
1392 if ($type == "Fullscreen" && !$a_mob->hasFullscreenItem()) {
1393 continue;
1394 }
1395
1396 $med = $a_mob->getMediaItem($type);
1397 if (!$med) {
1398 return "";
1399 }
1400
1401 $tpl->setCurrentBlock("media_info");
1402 if ($type == "Standard") {
1403 $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_std_view"));
1404 } else {
1405 $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_fullscreen"));
1406 }
1407 $tpl->setVariable("TXT_TYPE", $lng->txt("cont_" . strtolower($med->getLocationType())));
1408 $tpl->setVariable("VAL_LOCATION", $med->getLocation());
1409 if ($med->getLocationType() == "LocalFile") {
1410 $file = ilObjMediaObject::_getDirectory($med->getMobId()) . "/" . $med->getLocation();
1411 if (is_file($file)) {
1412 $size = filesize($file);
1413 } else {
1414 $size = 0;
1415 }
1416 $tpl->setVariable("VAL_FILE_SIZE", " ($size " . $lng->txt("bytes") . ")");
1417 }
1418 $tpl->setVariable("TXT_FORMAT", $lng->txt("cont_format"));
1419 $tpl->setVariable("VAL_FORMAT", $med->getFormat());
1420 if ($med->getWidth() != "" && $med->getHeight() != "") {
1421 $tpl->setCurrentBlock("size");
1422 $tpl->setVariable("TXT_SIZE", $lng->txt("size"));
1423 $tpl->setVariable("VAL_SIZE", $med->getWidth() . "x" . $med->getHeight());
1424 $tpl->parseCurrentBlock();
1425 }
1426
1427 // original size
1428 if ($orig_size = $med->getOriginalSize()) {
1429 if (($orig_size["width"] ?? "") !== $med->getWidth() ||
1430 ($orig_size["height"] ?? "") !== $med->getHeight()) {
1431 $tpl->setCurrentBlock("orig_size");
1432 $tpl->setVariable("TXT_ORIG_SIZE", $lng->txt("cont_orig_size"));
1433 $tpl->setVariable("ORIG_WIDTH", $orig_size["width"]);
1434 $tpl->setVariable("ORIG_HEIGHT", $orig_size["height"]);
1435 $tpl->parseCurrentBlock();
1436 }
1437 }
1438
1439 // output caption
1440 if (strlen($med->getCaption())) {
1441 $tpl->setCurrentBlock('additional_info');
1442 $tpl->setVariable('ADD_INFO', $lng->txt('cont_caption') . ': ' . $med->getCaption());
1443 $tpl->parseCurrentBlock();
1444 }
1445
1446 // output keywords
1447 if ($type == "Standard") {
1448 if (count($kws = ilMDKeyword::lookupKeywords(0, $med->getMobId()))) {
1449 $tpl->setCurrentBlock('additional_info');
1450 $tpl->setVariable('ADD_INFO', $lng->txt('keywords') . ': ' . implode(', ', $kws));
1451 $tpl->parseCurrentBlock();
1452 }
1453 }
1454
1455 $tpl->setCurrentBlock("media_info");
1456 $tpl->parseCurrentBlock();
1457 }
1458
1459 return $tpl->get();
1460 }
1461
1465 public function setTabs(): void
1466 {
1467 // catch feedback message
1468 $this->getTabs();
1469
1470 //$this->tpl->clearHeader();
1471 if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject") {
1472 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_mob.svg"));
1473 $this->tpl->setTitle($this->object->getTitle());
1474 } else {
1475 //$title = $this->object->getTitle();
1476 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_mob.svg"));
1477 $this->tpl->setTitle($this->lng->txt("cont_create_mob"));
1478 }
1479 }
1480
1481 public function getTabs(): void
1482 {
1483 $ilHelp = $this->help;
1484
1485 $ilHelp->setScreenIdComponent("mob");
1486
1487 if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject"
1488 && $this->object->getId() > 0) {
1489 // object properties
1490 $this->tabs_gui->addTarget(
1491 "cont_mob_def_prop",
1492 $this->ctrl->getLinkTarget($this, "edit"),
1493 "edit",
1494 get_class($this)
1495 );
1496
1497 $st_item = $this->object->getMediaItem("Standard");
1498
1499 // link areas
1500
1501 if (is_object($st_item) && $this->getEnabledMapAreas()) {
1502 $format = $st_item->getFormat();
1503 if (substr($format, 0, 5) == "image" && !is_int(strpos($format, "svg"))) {
1504 $this->tabs_gui->addTarget(
1505 "cont_def_map_areas",
1506 $this->ctrl->getLinkTargetByClass(
1507 array("ilobjmediaobjectgui", "ilimagemapeditorgui"),
1508 "editMapAreas"
1509 ),
1510 "editMapAreas",
1511 "ilimagemapeditorgui"
1512 );
1513 }
1514 }
1515
1516 // object usages
1517 $this->tabs_gui->addTarget(
1518 "cont_mob_usages",
1519 $this->ctrl->getLinkTarget($this, "showUsages"),
1520 "showUsages",
1521 get_class($this)
1522 );
1523
1524 // object files
1525 $std_item = $this->object->getMediaItem("Standard");
1526 $full_item = $this->object->getMediaItem("Fullscreen");
1527 $mset = new ilSetting("mobs");
1528 if ($mset->get("file_manager_always") ||
1529 ($this->media_type->usesParameterProperty($std_item->getFormat()) ||
1530 (is_object($full_item) && $this->media_type->usesParameterProperty($full_item->getFormat())))
1531 ) {
1532 $this->tabs_gui->addTarget(
1533 "cont_files",
1534 $this->ctrl->getLinkTargetByClass(
1535 array("ilobjmediaobjectgui", "ilfilesystemgui"),
1536 "listFiles"
1537 ),
1538 "",
1539 "ilfilesystemgui"
1540 );
1541 }
1542
1543 $mdgui = new ilObjectMetaDataGUI(null, $this->object->getType(), $this->object->getId());
1544 $mdtab = $mdgui->getTab("ilobjmediaobjectgui");
1545 if ($mdtab) {
1546 $this->tabs_gui->addTarget(
1547 "meta_data",
1548 $mdtab,
1549 "",
1550 "ilmdeditorgui"
1551 );
1552 }
1553 }
1554
1555 // back to upper context
1556 if ($this->back_title != "") {
1557 $this->tabs_gui->setBackTarget(
1558 $this->back_title,
1559 $this->ctrl->getParentReturn($this)
1560 );
1561 }
1562 }
1563
1567 public static function includePresentationJS(
1568 ilGlobalTemplateInterface $a_tpl = null
1569 ): void {
1570 global $DIC;
1571
1572 $tpl = $DIC["tpl"];
1573
1574 if ($a_tpl == null) {
1575 $a_tpl = $tpl;
1576 }
1577
1579 $a_tpl->addJavaScript(iljQueryUtil::getLocalMaphilightPath());
1580 $a_tpl->addJavaScript("./Services/COPage/js/ilCOPagePres.js");
1581
1583 }
1584
1585 public function setPropertiesSubTabs(
1586 string $a_active
1587 ): void {
1588 $ilTabs = $this->tabs;
1589 $ilCtrl = $this->ctrl;
1590 $lng = $this->lng;
1591
1592 $ilTabs->activateTab("cont_mob_def_prop");
1593
1594 $ilTabs->addSubTab(
1595 "general",
1596 $lng->txt("mob_general"),
1597 $ilCtrl->getLinkTarget($this, "edit")
1598 );
1599
1600 if ($this->object->getMediaItem("Standard")->getFormat() == "video/webm" ||
1601 $this->object->getMediaItem("Standard")->getFormat() == "video/mp4") {
1602 $ilTabs->addSubTab(
1603 "subtitles",
1604 $lng->txt("mob_subtitles"),
1605 $ilCtrl->getLinkTarget($this, "listSubtitleFiles")
1606 );
1607 }
1608
1609 $ilTabs->activateSubTab($a_active);
1610 }
1611
1612 public function listSubtitleFilesObject(): void
1613 {
1614 $ilToolbar = $this->toolbar;
1615 $tpl = $this->tpl;
1616 $ilCtrl = $this->ctrl;
1617 $lng = $this->lng;
1618 $ilUser = $this->user;
1619
1620 $this->setPropertiesSubTabs("subtitles");
1621
1622 if (!in_array("srt", $this->file_service_settings->getWhiteListedSuffixes())) {
1623 $tpl->setOnScreenMessage("info", $lng->txt("mob_srt_not_allowed"));
1624 } else {
1625
1626 // upload file
1627 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
1628 $fi = new ilFileInputGUI($lng->txt("mob_subtitle_file") . " (.srt)", "subtitle_file");
1629 $fi->setSuffixes(array("srt"));
1630 $ilToolbar->addInputItem($fi, true);
1631
1632 // language
1634 $si = new ilSelectInputGUI($this->lng->txt("mob_language"), "language");
1635 $si->setOptions($options);
1636 $si->setValue($ilUser->getLanguage());
1637 $ilToolbar->addInputItem($si, true);
1638
1639 $ilToolbar->addFormButton($lng->txt("upload"), "uploadSubtitleFile");
1640
1641 $ilToolbar->addSeparator();
1642 $ilToolbar->addFormButton($lng->txt("mob_upload_multi_srt"), "uploadMultipleSubtitleFileForm");
1643 }
1644
1646 $mob = $this->object;
1647 $tab = new ilMobSubtitleTableGUI($this, "listSubtitleFiles", $mob);
1648
1649 $tpl->setContent($tab->getHTML());
1650 }
1651
1652 public function uploadSubtitleFileObject(): void
1653 {
1654 $lng = $this->lng;
1655 $ilCtrl = $this->ctrl;
1656
1657 if ($this->object->uploadSrtFile(
1658 $_FILES["subtitle_file"]["tmp_name"],
1659 $this->sub_title_request->getLanguage()
1660 )) {
1661 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1662 }
1663 $ilCtrl->redirect($this, "listSubtitleFiles");
1664 }
1665
1669 public function confirmSrtDeletionObject(): void
1670 {
1671 $ilCtrl = $this->ctrl;
1672 $tpl = $this->tpl;
1673 $lng = $this->lng;
1674
1675 $lng->loadLanguageModule("meta");
1676
1677 $srts = $this->sub_title_request->getSrtFiles();
1678 if (count($srts) == 0) {
1679 $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1680 $ilCtrl->redirect($this, "listSubtitleFiles");
1681 } else {
1682 $cgui = new ilConfirmationGUI();
1683 $cgui->setFormAction($ilCtrl->getFormAction($this));
1684 $cgui->setHeaderText($lng->txt("mob_really_delete_srt"));
1685 $cgui->setCancel($lng->txt("cancel"), "listSubtitleFiles");
1686 $cgui->setConfirm($lng->txt("delete"), "deleteSrtFiles");
1687
1688 foreach ($srts as $i) {
1689 $cgui->addItem("srt[]", $i, "subtitle_" . $i . ".srt (" . $lng->txt("meta_l_" . $i) . ")");
1690 }
1691
1692 $tpl->setContent($cgui->getHTML());
1693 }
1694 }
1695
1699 public function deleteSrtFilesObject(): void
1700 {
1701 $lng = $this->lng;
1702 $ilCtrl = $this->ctrl;
1703
1704 $srts = $this->sub_title_request->getSrtFiles();
1705 foreach ($srts as $i) {
1706 if (strlen($i) == 2 && !is_int(strpos($i, "."))) {
1707 $this->object->removeAdditionalFile("srt/subtitle_" . $i . ".srt");
1708 }
1709 }
1710 $this->tpl->setOnScreenMessage('success', $lng->txt("mob_srt_files_deleted"), true);
1711 $ilCtrl->redirect($this, "listSubtitleFiles");
1712 }
1713
1715 {
1716 $ilToolbar = $this->toolbar;
1717 $lng = $this->lng;
1718 $ilCtrl = $this->ctrl;
1719
1720 $this->tpl->setOnScreenMessage('info', $lng->txt("mob_upload_multi_srt_howto"));
1721
1722 $this->setPropertiesSubTabs("subtitles");
1723
1724 // upload file
1725 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
1726 $fi = new ilFileInputGUI($lng->txt("mob_subtitle_file") . " (.zip)", "subtitle_file");
1727 $fi->setSuffixes(array("zip"));
1728 $ilToolbar->addInputItem($fi, true);
1729
1730 $ilToolbar->addFormButton($lng->txt("upload"), "uploadMultipleSubtitleFile");
1731 }
1732
1733 public function uploadMultipleSubtitleFileObject(): void
1734 {
1735 try {
1736 $this->object->uploadMultipleSubtitleFile(ilArrayUtil::stripSlashesArray($_FILES["subtitle_file"]));
1737 $this->ctrl->redirect($this, "showMultiSubtitleConfirmationTable");
1738 } catch (ilMediaObjectsException $e) {
1739 $this->tpl->setOnScreenMessage('failure', $e->getMessage(), true);
1740 $this->ctrl->redirect($this, "uploadMultipleSubtitleFileForm");
1741 }
1742 }
1743
1748 {
1749 $tpl = $this->tpl;
1750
1751 $this->setPropertiesSubTabs("subtitles");
1752
1753 $tab = new ilMultiSrtConfirmationTable2GUI($this, "showMultiSubtitleConfirmationTable");
1754 $tpl->setContent($tab->getHTML());
1755 }
1756
1760 public function cancelMultiSrtObject(): void
1761 {
1762 $this->object->clearMultiSrtDirectory();
1763 $this->ctrl->redirect($this, "listSubtitleFiles");
1764 }
1765
1769 public function saveMultiSrtObject(): void
1770 {
1771 $ilCtrl = $this->ctrl;
1772 $srt_files = $this->object->getMultiSrtFiles();
1773 $files = $this->sub_title_request->getFiles();
1774 foreach ($files as $f) {
1775 foreach ($srt_files as $srt_file) {
1776 if ($f == $srt_file["filename"]) {
1777 $this->object->uploadSrtFile($this->object->getMultiSrtUploadDir() . "/" . $srt_file["filename"], $srt_file["lang"], "rename");
1778 }
1779 }
1780 }
1781 $this->object->clearMultiSrtDirectory();
1782 $ilCtrl->redirect($this, "listSubtitleFiles");
1783 }
1784}
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 uses PEAR error class.
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...
File System Explorer GUI class.
static getWebspaceDir(string $mode="filesystem")
get webspace directory
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...
Help GUI class.
User interface class for map editor.
loadLanguageModule(string $a_module)
Load language module.
static lookupKeywords(int $a_rbac_id, int $a_obj_id, bool $a_return_ids=false)
static getImageSize(string $a_location)
Get image size from location.
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...
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...
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...
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.
static includePresentationJS(ilGlobalTemplateInterface $a_tpl=null)
Include media object presentation JS.
__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.
removeFullscreenObject()
remove fullscreen view
getTabs()
@abstract overwrite in derived GUI class of your object type
setPropertiesSubTabs(string $a_active)
createObject()
create new object form
ilFileServicesSettings $file_service_settings
setEnabledMapAreas(bool $a_enabledmapareas)
setHeightPreset(int $a_val)
Set height preset (e.g.
getFullscreenSizeObject()
set original size of fullscreen file
assignFullscreenObject(string $a_file)
assign file to fullscreen view
static _getMediaInfoHTML(ilObjMediaObject $a_mob)
get media info as html
resizeImagesObject()
resize images to specified size
assignStandardObject(string $a_file)
assign file to standard view
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.
addFullscreenObject()
add fullscreen view
create(bool $a_create_meta_data=false, bool $a_save_media_items=true)
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)
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 getRestrictedFileTypes()
Get restricted file types (this is for the input form, this list will be empty, if "allowed list" is ...
static fixFilename(string $a_name)
Fix filename of uploaded file.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
createDirectory()
Create file directory of media object.
static renameExecutables(string $a_dir)
addMediaItem(ilMediaItem $a_item)
static _getDirectory(int $a_mob_id)
Get absolute directory.
static getForbiddenFileTypes()
Get forbidden file types.
update(bool $a_upload=false)
Class ilObjectGUI Basic methods of all Output classes.
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $title)
setDescription(string $desc)
static initMediaElementJs(ilGlobalTemplateInterface $a_tpl=null)
Init mediaelement.js scripts.
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
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 $img, 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 getLocalMaphilightPath()
Get local path of maphilight file.
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$format
Definition: metadata.php:235
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
header include for all ilias files.
$type
$lng