ILIAS  release_8 Revision v8.24
class.ilObjMediaPoolGUI.php
Go to the documentation of this file.
1<?php
2
27
39{
43 protected string $mode;
44 protected int $mep_item_id = 0;
46 protected ilTabsGUI $tabs;
47 protected ilHelpGUI $help;
50 protected ilLogger $mep_log;
51 public bool $output_prepared;
52
53 public function __construct(
54 int $a_id = 0,
55 int $a_id_type = self::REPOSITORY_NODE_ID,
56 int $a_parent_node_id = 0
57 ) {
58 global $DIC;
59
60 $this->mep_request = $DIC->mediaPool()
61 ->internal()
62 ->gui()
63 ->standardRequest();
64 $this->mep_item_id = $this->mep_request->getItemId();
65
66 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
67
68 $this->tabs = $DIC->tabs();
69 $this->locator = $DIC["ilLocator"];
70 $this->help = $DIC["ilHelp"];
71
72 $this->main_tpl = $DIC->ui()->mainTemplate();
73
74 $this->upload = $DIC->upload();
75
76 $this->mep_log = ilLoggerFactory::getLogger("mep");
77
78
79 $this->mode = ($this->mep_request->getMode() !== "")
80 ? $this->mep_request->getMode()
81 : "listMedia";
82 $this->gui = $DIC->mediaPool()->internal()->gui();
83 }
84
85 protected function getMediaPool(): ilObjMediaPool
86 {
88 $mp = $this->object;
89 return $mp;
90 }
91
95 protected function afterConstructor(): void
96 {
98 if ($this->mep_item_id == 0 && !$this->getCreationMode()) {
99 $tree = $this->object->getTree();
100 $this->mep_item_id = $tree->readRootId();
101 }
102
103 $lng->loadLanguageModule("mep");
104
105 if ($this->ctrl->getCmd() === "explorer") {
106 $this->ctrl->saveParameter($this, array("ref_id"));
107 } else {
108 $this->ctrl->saveParameter($this, array("ref_id", "mepitem_id"));
109 }
110 $this->ctrl->saveParameter($this, array("mep_mode"));
111
112 $lng->loadLanguageModule("content");
113 }
114
115 final public function getType(): string
116 {
117 return "mep";
118 }
119
125 public function executeCommand(): void
126 {
127 $ilTabs = $this->tabs;
129 $ilAccess = $this->access;
131 $ilCtrl = $this->ctrl;
132
133 $tree = null;
134 if ($this->object) {
135 $tree = $this->object->getTree();
136 }
137
138 $next_class = $this->ctrl->getNextClass($this);
139 $cmd = $this->ctrl->getCmd();
140 $new_type = $this->mep_request->getNewType();
141
142
143
144 if ($new_type !== "" && ($cmd !== "confirmRemove" && $cmd !== "copyToClipboard"
145 && $cmd !== "pasteFromClipboard")) {
146 $this->tpl->setPermanentLink("mep", $this->ref_id);
147 $this->setCreationMode(true);
148 }
149
150 if ($cmd === "create") {
151 switch ($this->mep_request->getNewType()) {
152 case "mob":
153 $this->ctrl->redirectByClass("ilobjmediaobjectgui", "create");
154 break;
155
156 case "fold":
157 $this->ctrl->redirectByClass("ilobjfoldergui", "create");
158 break;
159 }
160 }
161
162 switch ($next_class) {
163 case 'ilobjectmetadatagui':
164 $this->checkPermission("write");
165
166 $this->prepareOutput();
167 $this->addHeaderAction();
168
169 $this->tabs_gui->activateTab('meta_data');
170 $md_gui = new ilObjectMetaDataGUI($this->object, ['mob', "mpg"]);
171 $this->ctrl->forwardCommand($md_gui);
172 $this->tpl->printToStdout();
173 break;
174
175 case strtolower(ilRepoStandardUploadHandlerGUI::class):
176 $this->checkPermission("write");
177 $form = $this->getBulkUploadForm();
178 $gui = $form->getRepoStandardUploadHandlerGUI("media_files");
179 $this->ctrl->forwardCommand($gui);
180 break;
181
182 case 'ilmediapoolpagegui':
183 $this->checkPermission("write");
184 $this->prepareOutput();
185 //$this->addHeaderAction();
186 $ilTabs->clearTargets();
187 $ilCtrl->setReturn($this, "returnFromItem");
188 $mep_page_gui = new ilMediaPoolPageGUI(
189 $this->mep_item_id,
190 $this->mep_request->getOldNr()
191 );
192 $mep_page_gui->setPoolGUI($this);
193 $mep_page_gui->setAdvMdRecordObject($this->object->getRefId(), "mep", "mpg");
194
195 if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
196 $mep_page_gui->setEnableEditing(false);
197 }
198 $ret = $this->ctrl->forwardCommand($mep_page_gui);
199 if ($ret != "") {
200 $tpl->setContent($ret);
201 }
202 $this->tpl->printToStdout();
203 break;
204
205 case "ilobjmediaobjectgui":
206 $this->checkPermission("write");
207 if ($cmd === "create" || $cmd === "save" || $cmd === "cancel") {
208 $ret_obj = $this->mep_item_id;
209 $ilObjMediaObjectGUI = new ilObjMediaObjectGUI("", 0, false, false);
210 $ilObjMediaObjectGUI->setWidthPreset((int) $this->getMediaPool()->getDefaultWidth());
211 $ilObjMediaObjectGUI->setHeightPreset((int) $this->getMediaPool()->getDefaultHeight());
212 } else {
213 $ret_obj = $tree->getParentId($this->mep_item_id);
214 $ilObjMediaObjectGUI = new ilObjMediaObjectGUI("", ilMediaPoolItem::lookupForeignId($this->mep_item_id), false, false);
215 $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
216 $ilTabs->setBackTarget(
217 $lng->txt("back"),
218 $this->ctrl->getLinkTarget(
219 $this,
220 $this->mode
221 )
222 );
223 }
224 if ($this->ctrl->getCmdClass() === "ilinternallinkgui") {
225 $this->ctrl->setReturn($this, "explorer");
226 } else {
227 $this->ctrl->setParameter($this, "mepitem_id", $ret_obj);
228 $this->ctrl->setReturn(
229 $this,
230 $this->mode
231 );
232 $this->ctrl->setParameter($this, "mepitem_id", $this->mep_item_id);
233 }
234 $this->getTemplate();
235 $ilObjMediaObjectGUI->setTabs();
236 $this->setLocator();
237
238 // set adv metadata record dobject
239 $ilObjMediaObjectGUI->setAdvMdRecordObject($this->object->getRefId(), "mep", "mob");
240
241 $ret = $this->ctrl->forwardCommand($ilObjMediaObjectGUI);
242 if ($cmd === "save") {
243 $object = $ilObjMediaObjectGUI->getObject();
244 if (!is_null($object)) {
245 $mep_item = new ilMediaPoolItem();
246 $mep_item->setTitle($object->getTitle());
247 $mep_item->setType("mob");
248 $mep_item->setForeignId($object->getId());
249 $mep_item->create();
250
251 $parent = $this->mep_item_id;
252 $tree->insertNode($mep_item->getId(), $parent);
254 "ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" .
255 $this->requested_ref_id . "&mepitem_id=" . $this->mep_item_id
256 );
257 }
258 }
259 $this->tpl->printToStdout();
260 break;
261
262 case "ilobjfoldergui":
263 $this->checkPermission("write");
264 $this->addHeaderAction();
265 $folder_gui = new ilObjFolderGUI("", 0, false, false);
266 $this->ctrl->setReturn($this, "listMedia");
267 $cmd .= "Object";
268 switch ($cmd) {
269 case "createObject":
270 $this->prepareOutput();
271 $folder_gui = new ilObjFolderGUI("", 0, false, false);
272 $folder_gui->setFormAction(
273 "save",
274 $this->ctrl->getFormActionByClass("ilobjfoldergui")
275 );
276 $folder_gui->createObject();
277 $this->tpl->printToStdout();
278 break;
279
280 case "saveObject":
281 $parent = $this->mep_item_id;
282 $folder_gui->setFolderTree($tree);
283 $folder_gui->saveObject();
284 break;
285
286 case "editObject":
287 $this->prepareOutput();
288 $folder_gui = new ilObjFolderGUI(
289 "",
290 ilMediaPoolItem::lookupForeignId($this->mep_item_id),
291 false,
292 false
293 );
294 $this->ctrl->setParameter($this, "foldereditmode", "1");
295 $folder_gui->setFormAction("update", $this->ctrl->getFormActionByClass("ilobjfoldergui"));
296 $folder_gui->editObject();
297 $this->tpl->printToStdout();
298 break;
299
300 case "updateObject":
301 $folder_gui = new ilObjFolderGUI(
302 "",
303 ilMediaPoolItem::lookupForeignId($this->mep_item_id),
304 false,
305 false
306 );
307 $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
308 $this->ctrl->setReturn($this, "listMedia");
309 $folder_gui->updateObject(); // this returns to parent
310 break;
311
312 case "cancelObject":
313 if ($this->mep_request->getFolderEditMode()) {
314 $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
315 }
316 $this->ctrl->redirect($this, "listMedia");
317 break;
318 }
319 break;
320
321 case "ileditclipboardgui":
322 $this->prepareOutput();
323 $this->addHeaderAction();
324 $this->ctrl->setReturn($this, $this->mode);
325 $clip_gui = new ilEditClipboardGUI();
326 $clip_gui->setMultipleSelections(true);
327 $clip_gui->setInsertButtonTitle($lng->txt("mep_copy_to_mep"));
328 $ilTabs->setTabActive("clipboard");
329 $this->ctrl->forwardCommand($clip_gui);
330 $this->tpl->printToStdout();
331 break;
332
333 case 'ilinfoscreengui':
334 $this->prepareOutput();
335 $this->addHeaderAction();
336 $this->infoScreen();
337 $this->tpl->printToStdout();
338 break;
339
340 case 'ilpermissiongui':
341 $this->checkPermission("edit_permission");
342 $this->prepareOutput();
343 $this->addHeaderAction();
344 $perm_gui = new ilPermissionGUI($this);
345 $ilTabs->activateTab("perm_settings");
346 $this->ctrl->forwardCommand($perm_gui);
347 $this->tpl->printToStdout();
348 break;
349
350 case "ilexportgui":
351 $this->checkPermission("write");
352 $this->prepareOutput();
353 $this->addHeaderAction();
354 $ilTabs->activateTab("export");
355 $exp_gui = new ilExportGUI($this);
356 $exp_gui->addFormat("xml");
357 $ot = ilObjectTranslation::getInstance($this->object->getId());
358 if ($ot->getContentActivated()) {
359 $exp_gui->addFormat("xml_master", "XML (" . $lng->txt("mep_master_language_only") . ")", $this, "export");
360 $exp_gui->addFormat("xml_masternomedia", "XML (" . $lng->txt("mep_master_language_only_no_media") . ")", $this, "export");
361 }
362 $this->ctrl->forwardCommand($exp_gui);
363 $this->tpl->printToStdout();
364 break;
365
366 case "ilfilesystemgui":
367 $this->checkPermission("write");
368 $this->prepareOutput();
369 $this->addHeaderAction();
370 $ilTabs->clearTargets();
371 $ilTabs->setBackTarget(
372 $lng->txt("back"),
373 $ilCtrl->getLinkTarget($this, "listMedia")
374 );
375 $mset = new ilSetting("mobs");
376 $import_directory_factory = new ilImportDirectoryFactory();
377 $mob_import_directory = $import_directory_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_MOB);
378 if ($mob_import_directory->exists()) {
379 $fs_gui = new ilFileSystemGUI($mob_import_directory->getAbsolutePath());
380 $fs_gui->setPostDirPath(true);
381 $fs_gui->setTableId("mepud" . $this->object->getId());
382 $fs_gui->setAllowFileCreation(false);
383 $fs_gui->setAllowDirectoryCreation(false);
384 $fs_gui->clearCommands();
385 $fs_gui->addCommand(
386 $this,
387 "selectUploadDirFiles",
388 $this->lng->txt("mep_sel_upload_dir_files"),
389 false,
390 true
391 );
392 $this->ctrl->forwardCommand($fs_gui);
393 }
394 $this->tpl->printToStdout();
395 break;
396
397 case "ilcommonactiondispatchergui":
399 $this->ctrl->forwardCommand($gui);
400 break;
401
402 case 'ilobjecttranslationgui':
403 $this->prepareOutput();
404 $this->addHeaderAction();
405 //$this->setTabs("settings");
406 $ilTabs->activateTab("settings");
407 $this->setSettingsSubTabs("obj_multilinguality");
408 $transgui = new ilObjectTranslationGUI($this);
409 $transgui->setTitleDescrOnlyMode(false);
410 $this->ctrl->forwardCommand($transgui);
411 $this->tpl->printToStdout();
412 break;
413
414 case "ilmediapoolimportgui":
415 $this->prepareOutput();
416 $this->addHeaderAction();
417 $this->checkPermission("write");
418 $ilTabs->activateTab("import");
419 $gui = new ilMediaPoolImportGUI($this->getMediaPool());
420 $this->ctrl->forwardCommand($gui);
421 $this->tpl->printToStdout();
422 break;
423
424 case "ilmobmultisrtuploadgui":
425 $this->checkPermission("write");
426 $this->prepareOutput();
427 $this->addHeaderAction();
428 $this->setContentSubTabs("srt_files");
429 $gui = new ilMobMultiSrtUploadGUI(new ilMepMultiSrt($this->getMediaPool()));
430 $this->ctrl->forwardCommand($gui);
431 $this->tpl->printToStdout();
432 break;
433
434
435 default:
436 $this->prepareOutput();
437 $this->addHeaderAction();
438 $cmd = $this->ctrl->getCmd("listMedia") ?: "listMedia";
439 $this->$cmd();
440 if (!$this->getCreationMode()) {
441 $this->tpl->printToStdout();
442 }
443 break;
444 }
445 }
446
450 protected function returnFromItem(): void
451 {
453
454 $type = ilMediaPoolItem::lookupType($this->mep_item_id);
455 if ($type !== "fold") {
456 $tree = $this->object->getTree();
457 $fold_id = $tree->getParentId($this->mep_item_id);
458 if ($fold_id > 0) {
459 $ctrl->setParameter($this, "mepitem_id", $fold_id);
460 $ctrl->redirect($this, "listMedia");
461 }
462 }
463 $this->listMedia();
464 }
465
466 public function createMediaObject(): void
467 {
468 $this->ctrl->redirectByClass("ilobjmediaobjectgui", "create");
469 }
470
471 protected function initCreationForms(string $new_type): array
472 {
473 $forms = array(self::CFORM_NEW => $this->initCreateForm($new_type),
474 self::CFORM_IMPORT => $this->initImportForm($new_type));
475
476 return $forms;
477 }
478
479 protected function afterSave(ilObject $new_object): void
480 {
481 // always send a message
482 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
483
484 //ilUtil::redirect($this->getReturnLocation("save","adm_object.php?".$this->link_params));
485 ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&ref_id=" . $new_object->getRefId() . "&cmd=listMedia");
486 }
487
488 protected function initEditCustomForm(ilPropertyFormGUI $a_form): void
489 {
490 $obj_service = $this->object_service;
491
492 // default width
493 $ni = new ilNumberInputGUI($this->lng->txt("mep_default_width"), "default_width");
494 $ni->setMinValue(0);
495 $ni->setSuffix("px");
496 $ni->setMaxLength(5);
497 $ni->setSize(5);
498 $a_form->addItem($ni);
499
500 // default height
501 $ni = new ilNumberInputGUI($this->lng->txt("mep_default_height"), "default_height");
502 $ni->setSuffix("px");
503 $ni->setMinValue(0);
504 $ni->setMaxLength(5);
505 $ni->setSize(5);
506 $ni->setInfo($this->lng->txt("mep_default_width_height_info"));
507 $a_form->addItem($ni);
508
509 // presentation
510 $pres = new ilFormSectionHeaderGUI();
511 $pres->setTitle($this->lng->txt('obj_presentation'));
512 $a_form->addItem($pres);
513
514 // tile image
515 $obj_service->commonSettings()->legacyForm($a_form, $this->object)->addTileImage();
516
517 // additional features
518 $feat = new ilFormSectionHeaderGUI();
519 $feat->setTitle($this->lng->txt('obj_features'));
520 $a_form->addItem($feat);
521
523 $this->object->getId(),
524 $a_form,
525 array(
527 )
528 );
529 }
530
534 public function edit(): void
535 {
537 $ilTabs = $this->tabs_gui;
538
539 $this->setSettingsSubTabs("settings");
540
541 if (!$this->checkPermissionBool("write")) {
542 throw new ilPermissionException($this->lng->txt("msg_no_perm_write"));
543 }
544
545 $ilTabs->activateTab("settings");
546
547 $form = $this->initEditForm();
548 $values = $this->getEditFormValues();
549 if ($values) {
550 $form->setValuesByArray($values, true);
551 }
552
553 $this->addExternalEditFormCustom($form);
554
556 }
557
558
559 protected function getEditFormCustomValues(array &$a_values): void
560 {
561 $ot = ilObjectTranslation::getInstance($this->getMediaPool()->getId());
562 if ($ot->getContentActivated()) {
563 $a_values["title"] = $ot->getDefaultTitle();
564 $a_values["desc"] = $ot->getDefaultDescription();
565 }
566 if ($this->getMediaPool()->getDefaultWidth() > 0) {
567 $a_values["default_width"] = $this->object->getDefaultWidth();
568 }
569 if ($this->getMediaPool()->getDefaultHeight() > 0) {
570 $a_values["default_height"] = $this->object->getDefaultHeight();
571 }
572 }
573
574 protected function updateCustom(ilPropertyFormGUI $form): void
575 {
576 $obj_service = $this->object_service;
577
578 $ot = ilObjectTranslation::getInstance($this->getMediaPool()->getId());
579 if ($ot->getContentActivated()) {
580 $ot->setDefaultTitle($form->getInput('title'));
581 $ot->setDefaultDescription($form->getInput('desc'));
582 $ot->save();
583 }
584
585 $this->getMediaPool()->setDefaultWidth($form->getInput("default_width"));
586 $this->object->setDefaultHeight($form->getInput("default_height"));
587
588 // additional features
590 $this->object->getId(),
591 $form,
592 array(
594 )
595 );
596
597 // tile image
598 $obj_service->commonSettings()->legacyForm($form, $this->object)->saveTileImage();
599 }
600
604 public function listMedia(): void
605 {
606 $ilAccess = $this->access;
608 $ilTabs = $this->tabs;
609 $ilCtrl = $this->ctrl;
610 $ilToolbar = $this->toolbar;
612
613 $ilCtrl->setParameter($this, "mep_mode", "listMedia");
614
615 $this->checkPermission("read");
616
617 $ilTabs->setTabActive("content");
618 $this->setContentSubTabs("content");
619
620 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
621 $ilToolbar->addButton(
622 $lng->txt("mep_create_mob"),
623 $ilCtrl->getLinkTarget($this, "createMediaObject")
624 );
625
626 $mset = new ilSetting("mobs");
627 if ($mset->get("mep_activate_pages")) {
628 $ilToolbar->addButton(
629 $lng->txt("mep_create_content_snippet"),
630 $ilCtrl->getLinkTargetByClass(["ilobjmediapoolgui", "ilmediapoolpagegui"], "createMediaPoolPage")
631 );
632 }
633
634 $ilToolbar->addButton(
635 $lng->txt("mep_create_folder"),
636 $ilCtrl->getLinkTarget($this, "createFolderForm")
637 );
638
639 $upload_factory = new ilImportDirectoryFactory();
640 $media_upload = $upload_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_MOB);
641 if ($media_upload->exists() && $this->rbac_system->checkAccess("visible", SYSTEM_FOLDER_ID)) {
642 $ilToolbar->addButton(
643 $lng->txt("mep_create_from_upload_dir"),
644 $ilCtrl->getLinkTargetByClass("ilfilesystemgui", "listFiles")
645 );
646 }
647
648 $ilToolbar->addButton(
649 $lng->txt("mep_bulk_upload"),
650 $ilCtrl->getLinkTarget($this, "bulkUpload")
651 );
652
653 $move_ids = ilSession::get("mep_move_ids");
654 if (is_array($move_ids) && count($move_ids) > 0) {
655 $ilToolbar->addSeparator();
656 $ilToolbar->addButton(
657 $lng->txt("paste"),
658 $ilCtrl->getLinkTarget($this, "paste")
659 );
660 }
661 }
662
663 $mep_table_gui = new ilMediaPoolTableGUI($this, "listMedia", $this->getMediaPool(), "mepitem_id");
664 $tpl->setContent($mep_table_gui->getHTML());
665 }
666
667 protected function toggleExplorerNodeState(): void
668 {
669 $exp = new ilMediaPoolExplorerGUI($this, "listMedia", $this->getMediaPool());
670 $exp->toggleExplorerNodeState();
671 }
672
676 public function allMedia(): void
677 {
679 $ilTabs = $this->tabs;
680 $ilCtrl = $this->ctrl;
682
683 $ilCtrl->setParameter($this, "mep_mode", "allMedia");
684
685 $this->checkPermission("read");
686 $ilTabs->setTabActive("content");
687 $this->setContentSubTabs("mep_all_mobs");
688
689 $mep_table_gui = new ilMediaPoolTableGUI(
690 $this,
691 "allMedia",
692 $this->getMediaPool(),
693 "mepitem_id",
695 true
696 );
697
698 if ($this->mep_request->getForceFilter() > 0) {
699 $mep_table_gui->setTitleFilter(
700 ilMediaPoolItem::lookupTitle($this->mep_request->getForceFilter())
701 );
702
703 // Read again
704 $mep_table_gui = new ilMediaPoolTableGUI(
705 $this,
706 "allMedia",
707 $this->getMediaPool(),
708 "mepitem_id",
710 true
711 );
712 }
713
714 $tpl->setContent($mep_table_gui->getHTML());
715 }
716
720 public function applyFilter(): void
721 {
722 $mtab = new ilMediaPoolTableGUI(
723 $this,
724 "allMedia",
725 $this->getMediaPool(),
726 "mepitem_id",
728 true
729 );
730 $mtab->writeFilterToSession();
731 $mtab->resetOffset();
732 $this->allMedia();
733 }
734
735 public function resetFilter(): void
736 {
737 $mtab = new ilMediaPoolTableGUI(
738 $this,
739 "allMedia",
740 $this->getMediaPool(),
741 "mepitem_id",
743 true
744 );
745 $mtab->resetFilter();
746 $mtab->resetOffset();
747 $this->allMedia();
748 }
749
753 public function getTemplate(): void
754 {
755 $this->tpl->loadStandardTemplate();
756 }
757
758
762 public function getParentFolderId(): ?int
763 {
764 if ($this->mep_item_id == 0) {
765 return null;
766 }
767 $par_id = $this->object->getPoolTree()->getParentId($this->mep_item_id);
768 if ($par_id != $this->object->getPoolTree()->getRootId()) {
769 return (int) $par_id;
770 }
771
772 return null;
773 }
774
778 protected function showMedia(): void
779 {
780 $this->checkPermission("read");
781 $link_xml = "";
782 $pg_frame = "";
783
784 $item = new ilMediaPoolItem($this->mep_item_id);
785 $mob_id = $item->getForeignId();
786
787 $this->tpl = new ilGlobalTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
788 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
789 $this->tpl->setVariable(
790 "LOCATION_CONTENT_STYLESHEET",
792 );
793
794
796 $media_obj = new ilObjMediaObject($mob_id);
797
798
799 $this->tpl->setVariable("TITLE", " - " . $media_obj->getTitle());
800
801 $xml = "<dummy>";
802 // todo: we get always the first alias now (problem if mob is used multiple
803 // times in page)
804 $xml .= $media_obj->getXML(IL_MODE_ALIAS);
805 $xml .= $media_obj->getXML(IL_MODE_OUTPUT);
806 $xml .= $link_xml;
807 $xml .= "</dummy>";
808
809 $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
810 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
811 $xh = xslt_create();
812
813 $wb_path = ilFileUtils::getWebspaceDir("output") . "/";
814
815 $mode = ($this->ctrl->getCmd() !== "showPreview")
816 ? "fullscreen"
817 : "media";
818 $enlarge_path = ilUtil::getImagePath("enlarge.svg", false, "output");
819 $fullscreen_link =
820 $this->ctrl->getLinkTarget($this, "showFullscreen", "", false, false);
821 $params = array('mode' => $mode, 'enlarge_path' => $enlarge_path,
822 'link_params' => "ref_id=" . $this->requested_ref_id,'fullscreen_link' => $fullscreen_link,
823 'enable_html_mob' => ilObjMediaObject::isTypeAllowed("html") ? "y" : "n",
824 'ref_id' => $this->requested_ref_id, 'pg_frame' => $pg_frame, 'webspace_path' => $wb_path);
825 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
826 xslt_free($xh);
827 // unmask user html
828 $this->tpl->setVariable("MEDIA_CONTENT", $output);
829 }
830
837 public function showPage(): void
838 {
839 //$tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
840 $tpl = new ilGlobalTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
841
845
846 // get page object
847 $page_gui = $this->getMediaPoolPageGUI($this->mep_item_id);
848 $page_gui->setTemplate($tpl);
849
850 $page_gui->setTemplateOutput(false);
851 $page_gui->setHeader("");
852 $ret = $page_gui->showPage(true);
853
854 //$tpl->setBodyClass("ilMediaPoolPagePreviewBody");
855 $tpl->setVariable("MEDIA_CONTENT", "<div>" . $ret . "</div>");
856
857
859 exit;
860 }
861
867 protected function getMediaPoolPageGUI($mep_item_id, $old_nr = 0)
868 {
869 include_once("./Modules/MediaPool/classes/class.ilMediaPoolPageGUI.php");
870 $page_gui = new ilMediaPoolPageGUI($mep_item_id, $old_nr);
871 $page_gui->setPoolGUI($this);
872
873 return $page_gui;
874 }
875
876
880 public function showPreview(): void
881 {
882 $this->checkPermission("read");
883
884 $item = new ilMediaPoolItem($this->mep_item_id);
885
886 switch ($item->getType()) {
887 case "mob":
888 $this->showMedia();
889 break;
890
891 case "pg":
892 $this->showPage();
893 break;
894 }
895 }
896
897
901 public function showFullscreen(): void
902 {
903 $this->showMedia();
904 }
905
909 public function confirmRemove(): void
910 {
911 $ilCtrl = $this->ctrl;
913
914 $this->checkPermission("write");
915
916 $ids = $this->mep_request->getItemIds();
917 if (count($ids) === 0) {
918 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
919 $ilCtrl->redirect($this, "");
920 }
921
922 // display confirmation message
923 $cgui = new ilConfirmationGUI();
924 $cgui->setFormAction($this->ctrl->getFormAction($this));
925 $cgui->setHeaderText($this->lng->txt("info_remove_sure"));
926 $cgui->setCancel($this->lng->txt("cancel"), "cancelRemove");
927 $cgui->setConfirm($this->lng->txt("confirm"), "remove");
928
929 foreach ($ids as $obj_id) {
932
933 // check whether page can be removed
934 $add = "";
935 if ($type === "pg") {
936 $usages = ilPageContentUsage::getUsages("incl", $obj_id, false);
937 if (count($usages) > 0) {
938 $this->main_tpl->setOnScreenMessage('failure', sprintf($lng->txt("mep_content_snippet_in_use"), $title), true);
939 $ilCtrl->redirect($this, "listMedia");
940 } else {
941 // check whether the snippet is used in older versions of pages
942 $usages = ilPageContentUsage::getUsages("incl", $obj_id, true);
943 if (count($usages) > 0) {
944 $add = "<div class='small'>" . $lng->txt("mep_content_snippet_used_in_older_versions") . "</div>";
945 }
946 }
947 }
948
949 $caption =
950 " " . $title . $add;
951
952 $cgui->addItem("id[]", $obj_id, $caption);
953 }
954
955 $this->tpl->setContent($cgui->getHTML());
956 }
957
961 public function openClipboard(): void
962 {
963 $ilCtrl = $this->ctrl;
964
965 $this->checkPermission("write");
966
967 $ilCtrl->setParameterByClass(
968 "ileditclipboardgui",
969 "returnCommand",
970 rawurlencode($ilCtrl->getLinkTarget(
971 $this,
972 "insertFromClipboard",
973 "",
974 false,
975 false
976 ))
977 );
978 $ilCtrl->redirectByClass("ilEditClipboardGUI", "getObject");
979 }
980
981
985 public function insertFromClipboard(): void
986 {
987 $this->checkPermission("write");
988
990 $not_inserted = array();
991 foreach ($ids as $id2) {
992 $id = explode(":", $id2);
993 $type = $id[0];
994 $id = $id[1];
995
996 if ($type === "mob") { // media object
997 if (ilObjMediaPool::isForeignIdInTree($this->object->getId(), $id)) {
998 $not_inserted[] = ilObject::_lookupTitle($id) . " [" .
999 $id . "]";
1000 } else {
1001 $item = new ilMediaPoolItem();
1002 $item->setType("mob");
1003 $item->setForeignId($id);
1004 $item->setTitle(ilObject::_lookupTitle($id));
1005 $item->create();
1006 if ($item->getId() > 0) {
1007 $this->object->insertInTree($item->getId(), $this->mep_item_id);
1008 }
1009 }
1010 }
1011 if ($type === "incl") { // content snippet
1012 if (ilObjMediaPool::isItemIdInTree($this->object->getId(), $id)) {
1013 $not_inserted[] = ilMediaPoolPage::lookupTitle($id) . " [" .
1014 $id . "]";
1015 } else {
1016 $original = new ilMediaPoolPage($id);
1017
1018 // copy the page into the pool
1019 $item = new ilMediaPoolItem();
1020 $item->setType("pg");
1021 $item->setTitle(ilMediaPoolItem::lookupTitle($id));
1022 $item->create();
1023 if ($item->getId() > 0) {
1024 $this->object->insertInTree($item->getId(), $this->mep_item_id);
1025
1026 // create page
1027 $page = new ilMediaPoolPage();
1028 $page->setId($item->getId());
1029 $page->setParentId($this->object->getId());
1030 $page->create(false);
1031
1032 // copy content
1033 $original->copy($page->getId(), $page->getParentType(), $page->getParentId(), true);
1034 }
1035 }
1036 }
1037 }
1038 if (count($not_inserted) > 0) {
1039 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("mep_not_insert_already_exist") . "<br>" .
1040 implode("<br>", $not_inserted), true);
1041 }
1042 $this->ctrl->redirect($this, $this->mode);
1043 }
1044
1045
1049 public function cancelRemove(): void
1050 {
1051 $this->ctrl->redirect($this, $this->mode);
1052 }
1053
1054 public function remove(): void
1055 {
1056 $this->checkPermission("write");
1057
1058 $ids = $this->mep_request->getItemIds();
1059 foreach ($ids as $obj_id) {
1060 $this->object->deleteChild($obj_id);
1061 }
1062
1063 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("cont_obj_removed"), true);
1064 $this->ctrl->redirect($this, $this->mode);
1065 }
1066
1067
1071 public function copyToClipboard(): void
1072 {
1074
1075 $this->checkPermission("write");
1076
1077 $ids = $this->mep_request->getItemIds();
1078 if (count($ids) === 0) {
1079 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
1080 $this->ctrl->redirect($this, $this->mode);
1081 }
1082
1083 foreach ($ids as $obj_id) {
1085 if ($type === "fold") {
1086 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("cont_cant_copy_folders"), true);
1087 $this->ctrl->redirect($this, $this->mode);
1088 }
1089 }
1090 foreach ($ids as $obj_id) {
1093 if ($type === "mob") {
1094 $ilUser->addObjectToClipboard($fid, "mob", "");
1095 }
1096 if ($type === "pg") {
1097 $ilUser->addObjectToClipboard($obj_id, "incl", "");
1098 }
1099 }
1100 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("copied_to_clipboard"), true);
1101 $this->ctrl->redirect($this, $this->mode);
1102 }
1103
1107 protected function addLocatorItems(): void
1108 {
1109 $ilLocator = $this->locator;
1110 $ilAccess = $this->access;
1111 if (!$this->getCreationMode() && $this->ctrl->getCmd() !== "explorer") {
1112 $tree = $this->object->getTree();
1115 foreach ($path as $node) {
1116 if ($node["child"] == $tree->getRootId()) {
1117 $this->ctrl->setParameter($this, "mepitem_id", "");
1118 $link = "";
1119 if ($ilAccess->checkAccess("read", "", $this->object->getRefId())) {
1120 $link = $this->ctrl->getLinkTarget($this, "listMedia");
1121 } elseif ($ilAccess->checkAccess("visible", "", $this->object->getRefId())) {
1122 $link = $this->ctrl->getLinkTarget($this, "infoScreen");
1123 }
1124 $title = $this->object->getTitle();
1125 $this->ctrl->setParameter($this, "mepitem_id", $this->mep_item_id);
1126 $ilLocator->addItem($title, $link, "", $this->requested_ref_id);
1127 }
1128 }
1129 }
1130 }
1131
1135
1136 public function createFolderForm(): void
1137 {
1138 $tpl = $this->tpl;
1139
1140 $this->checkPermission("write");
1141
1142 $this->initFolderForm("create");
1143 $tpl->setContent($this->form->getHTML());
1144 }
1145
1146 public function editFolder(): void
1147 {
1148 $tpl = $this->tpl;
1149
1150 $this->checkPermission("write");
1151
1152 $this->initFolderForm();
1153 $this->getFolderValues();
1154 $tpl->setContent($this->form->getHTML());
1155 }
1156
1160 public function getFolderValues(): void
1161 {
1162 $values = array();
1163
1164 $values["title"] = ilMediaPoolItem::lookupTitle($this->mep_item_id);
1165
1166 $this->form->setValuesByArray($values);
1167 }
1168
1172 public function saveFolder(): void
1173 {
1174 $tpl = $this->tpl;
1175 $lng = $this->lng;
1176 $ilCtrl = $this->ctrl;
1177
1178 $this->checkPermission("write");
1179
1180 $this->initFolderForm("create");
1181 if ($this->form->checkInput()) {
1182 if ($this->object->createFolder($this->form->getInput("title"), $this->mep_item_id)) {
1183 $this->main_tpl->setOnScreenMessage('success', $lng->txt("mep_folder_created"), true);
1184 }
1185 $ilCtrl->redirect($this, "listMedia");
1186 }
1187
1188 $this->form->setValuesByPost();
1189 $tpl->setContent($this->form->getHTML());
1190 }
1191
1192 public function updateFolder(): void
1193 {
1194 $lng = $this->lng;
1195 $ilCtrl = $this->ctrl;
1196 $tpl = $this->tpl;
1197
1198 $this->checkPermission("write");
1199
1200 $this->initFolderForm("edit");
1201 if ($this->form->checkInput()) {
1202 $item = new ilMediaPoolItem($this->mep_item_id);
1203 $item->setTitle($this->form->getInput("title"));
1204 $item->update();
1205 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1206 $ilCtrl->setParameter(
1207 $this,
1208 "mepitem_id",
1209 $this->object->getTree()->getParentId($this->mep_item_id)
1210 );
1211 $ilCtrl->redirect($this, "listMedia");
1212 }
1213
1214 $this->form->setValuesByPost();
1215 $tpl->setContent($this->form->getHTML());
1216 }
1217
1222 public function initFolderForm(string $a_mode = "edit"): void
1223 {
1224 $lng = $this->lng;
1225 $ilCtrl = $this->ctrl;
1226
1227 $this->form = new ilPropertyFormGUI();
1228
1229 // desc
1230 $ti = new ilTextInputGUI($lng->txt("title"), "title");
1231 $ti->setMaxLength(128);
1232 $ti->setRequired(true);
1233 $this->form->addItem($ti);
1234
1235 // save and cancel commands
1236 if ($a_mode === "create") {
1237 $this->form->addCommandButton("saveFolder", $lng->txt("save"));
1238 $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
1239 $this->form->setTitle($lng->txt("mep_new_folder"));
1240 } else {
1241 $this->form->addCommandButton("updateFolder", $lng->txt("save"));
1242 $this->form->addCommandButton("cancelFolderUpdate", $lng->txt("cancel"));
1243 $this->form->setTitle($lng->txt("mep_edit_folder"));
1244 }
1245
1246 $this->form->setFormAction($ilCtrl->getFormAction($this));
1247 }
1248
1249 public function cancelFolderUpdate(): void
1250 {
1251 $ilCtrl = $this->ctrl;
1252 $ilCtrl->setParameter(
1253 $this,
1254 "mepitem_id",
1255 $this->object->getTree()->getParentId($this->mep_item_id)
1256 );
1257 $ilCtrl->redirect($this, "listMedia");
1258 }
1259
1260 public function cancelSave(): void
1261 {
1262 $ilCtrl = $this->ctrl;
1263 $ilCtrl->redirect($this, "listMedia");
1264 }
1265
1269
1273 public function setContentSubTabs(
1274 string $a_active
1275 ): void {
1276 $ilAccess = $this->access;
1277 $ilTabs = $this->tabs;
1278 $ilCtrl = $this->ctrl;
1279
1280 $ilTabs->addSubTab("content", $this->lng->txt("objs_fold"), $this->ctrl->getLinkTarget($this, ""));
1281
1282 $ilCtrl->setParameter($this, "mepitem_id", "");
1283 $ilTabs->addSubTab("mep_all_mobs", $this->lng->txt("mep_all_mobs"), $this->ctrl->getLinkTarget($this, "allMedia"));
1284 $ilCtrl->setParameter($this, "mepitem_id", $this->mep_item_id);
1285
1286 if ($ilAccess->checkAccess('write', '', $this->ref_id)) {
1287 $ilTabs->addSubTab(
1288 "srt_files",
1289 $this->lng->txt("mep_media_subtitles"),
1290 $ilCtrl->getLinkTargetByClass("ilmobmultisrtuploadgui", "")
1291 );
1292 }
1293
1294 $ilTabs->activateSubTab($a_active);
1295 }
1296
1297 protected function setTabs(): void
1298 {
1299 $ilAccess = $this->access;
1300 $ilTabs = $this->tabs;
1301 $ilHelp = $this->help;
1302
1303 $ilHelp->setScreenIdComponent("mep");
1304
1305 if ($ilAccess->checkAccess('read', '', $this->ref_id) ||
1306 $ilAccess->checkAccess('write', '', $this->ref_id)) {
1307 $ilTabs->addTab("content", $this->lng->txt("mep_content"), $this->ctrl->getLinkTarget($this, ""));
1308 }
1309
1310 // info tab
1311 if ($ilAccess->checkAccess('visible', '', $this->ref_id) ||
1312 $ilAccess->checkAccess('read', '', $this->ref_id) ||
1313 $ilAccess->checkAccess('write', '', $this->ref_id)) {
1314 $force_active = $this->ctrl->getNextClass() === "ilinfoscreengui"
1315 || strtolower($this->ctrl->getCmdClass()) === "ilnotegui";
1316 $ilTabs->addTarget(
1317 "info_short",
1318 $this->ctrl->getLinkTargetByClass(
1319 array("ilobjmediapoolgui", "ilinfoscreengui"),
1320 "showSummary"
1321 ),
1322 array("showSummary", "infoScreen"),
1323 "",
1324 "",
1325 $force_active
1326 );
1327 }
1328
1329 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1330 $ilTabs->addTarget(
1331 "settings",
1332 $this->ctrl->getLinkTarget($this, "edit"),
1333 "edit",
1334 array("", "ilobjmediapoolgui")
1335 );
1336 }
1337 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1338 $ilTabs->addTarget(
1339 "clipboard",
1340 $this->ctrl->getLinkTarget($this, "openClipboard"),
1341 "view",
1342 "ileditclipboardgui"
1343 );
1344 }
1345
1346 // properties
1347 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1348 // meta data
1349 $mdgui = new ilObjectMetaDataGUI($this->object, ['mob', "mpg"]);
1350 $mdtab = $mdgui->getTab();
1351 if ($mdtab) {
1352 $ilTabs->addTarget(
1353 "meta_data",
1354 $mdtab,
1355 "",
1356 "ilobjectmetadatagui"
1357 );
1358 }
1359 }
1360
1361 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1362 $ilTabs->addTarget(
1363 "export",
1364 $this->ctrl->getLinkTargetByClass("ilexportgui", ""),
1365 "",
1366 "ilexportgui"
1367 );
1368
1369 $ilTabs->addTarget(
1370 "import",
1371 $this->ctrl->getLinkTargetByClass("ilmediapoolimportgui", ""),
1372 "",
1373 "ilmediapoolimportgui"
1374 );
1375 }
1376
1377 if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId())) {
1378 $ilTabs->addTarget(
1379 "perm_settings",
1380 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
1381 array("perm","info","owner"),
1382 'ilpermissiongui'
1383 );
1384 }
1385 }
1386
1387 public function setSettingsSubTabs(
1388 string $a_active
1389 ): void {
1390 $ilTabs = $this->tabs;
1391 $lng = $this->lng;
1392 $ilAccess = $this->access;
1393
1394 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1395 $ilTabs->addSubTab(
1396 "settings",
1397 $lng->txt("settings"),
1398 $this->ctrl->getLinkTarget($this, "edit")
1399 );
1400
1401 $mset = new ilSetting("mobs");
1402 if ($mset->get("mep_activate_pages")) {
1403 $ilTabs->addSubTabTarget(
1404 "obj_multilinguality",
1405 $this->ctrl->getLinkTargetByClass("ilobjecttranslationgui", "")
1406 );
1407 }
1408 }
1409
1410 $ilTabs->setSubTabActive($a_active);
1411 }
1412
1413
1414 public static function _goto(string $a_target): void
1415 {
1416 global $DIC;
1417 $main_tpl = $DIC->ui()->mainTemplate();
1418
1419 $ilAccess = $DIC->access();
1420 $lng = $DIC->language();
1421 $ctrl = $DIC->ctrl();
1422
1423 $subitem_id = "";
1424 $targets = explode('_', $a_target);
1425 $ref_id = $targets[0];
1426 if (count((array) $targets) > 1) {
1427 $subitem_id = $targets[1];
1428 }
1429
1430 $ctrl->setParameterByClass("ilMediaPoolPresentationGUI", "ref_id", $ref_id);
1431 if ($ilAccess->checkAccess("read", "", $ref_id)) {
1432 $ctrl->setParameterByClass("ilMediaPoolPresentationGUI", "mepitem_id", $subitem_id);
1433 $ctrl->redirectByClass("ilMediaPoolPresentationGUI", "");
1434 } elseif ($ilAccess->checkAccess("visible", "", $ref_id)) {
1435 $ctrl->redirectByClass("ilMediaPoolPresentationGUI", "infoScreen");
1436 } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
1437 $main_tpl->setOnScreenMessage('failure', sprintf(
1438 $lng->txt("msg_no_perm_read_item"),
1440 ), true);
1442 }
1443
1444 throw new ilPermissionException($lng->txt("msg_no_perm_read"));
1445 }
1446
1450 public function infoScreenObject(): void
1451 {
1452 $this->ctrl->setCmd("showSummary");
1453 $this->ctrl->setCmdClass("ilinfoscreengui");
1454 $this->infoScreen();
1455 }
1456
1462 public function infoScreen(): void
1463 {
1464 $this->tabs->activateTab("info_short");
1465 $ilAccess = $this->access;
1466
1467 if (!$ilAccess->checkAccess("visible", "", $this->ref_id) &&
1468 !$ilAccess->checkAccess("read", "", $this->ref_id) &&
1469 !$ilAccess->checkAccess("write", "", $this->ref_id)) {
1470 throw new ilPermissionException($this->lng->txt("msg_no_perm_read"));
1471 }
1472
1473 if ($this->ctrl->getCmd() === "infoScreen") {
1474 $this->ctrl->setCmd("showSummary");
1475 $this->ctrl->setCmdClass("ilinfoscreengui");
1476 }
1477
1478 $info = new ilInfoScreenGUI($this);
1479
1480 $info->enablePrivateNotes();
1481
1482
1483 // standard meta data
1484 $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
1485
1486 // forward the command
1487 $this->ctrl->forwardCommand($info);
1488 }
1489
1490
1494
1498 public function selectUploadDirFiles(
1499 ?array $a_files = null
1500 ): void {
1501 $tpl = $this->tpl;
1502 $ilTabs = $this->tabs;
1503 $lng = $this->lng;
1504 $ilCtrl = $this->ctrl;
1505 $ilToolbar = $this->toolbar;
1506
1507
1508 if (!$a_files) {
1509 $a_files = $this->mep_request->getFiles();
1510 }
1511
1512 $ilTabs->clearTargets();
1513 $ilTabs->setBackTarget(
1514 $lng->txt("back"),
1515 $ilCtrl->getLinkTarget($this, "listMedia")
1516 );
1517
1518 $this->checkPermission("write");
1519
1520 if ($this->rbac_system->checkAccess("visible", SYSTEM_FOLDER_ID)) {
1521 $tb = new ilToolbarGUI();
1522 // action type
1523 $options = array(
1524 "rename" => $lng->txt("mep_up_dir_move"),
1525 "copy" => $lng->txt("mep_up_dir_copy"),
1526 );
1527 $si = new ilSelectInputGUI("", "action");
1528 $si->setOptions($options);
1529 $tb->addInputItem($si);
1530 $tb->setCloseFormTag(false);
1531 $tb->setFormAction($ilCtrl->getFormAction($this));
1532 $tb->setFormName("mep_up_form");
1533
1534 $tab = new ilUploadDirFilesTableGUI(
1535 $this,
1536 "selectUploadDirFiles",
1537 $a_files
1538 );
1539 $tab->setFormName("mep_up_form");
1540 $tpl->setContent($tb->getHTML() . $tab->getHTML());
1541 }
1542 }
1543
1547 public function createMediaFromUploadDir(): void
1548 {
1549 $this->checkPermission("write");
1550
1551 $import_directory_factory = new ilImportDirectoryFactory();
1552 $mob_import_directory = $import_directory_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_MOB);
1553 $upload_dir = $mob_import_directory->getAbsolutePath();
1554
1555 $files = $this->mep_request->getFiles();
1556 if ($this->rbac_system->checkAccess("visible", SYSTEM_FOLDER_ID)) {
1557 foreach ($files as $f) {
1558 $f = str_replace("..", "", $f);
1559 $fullpath = $upload_dir . "/" . $f;
1560 $mob = new ilObjMediaObject();
1561 $mob->setTitle(basename($fullpath));
1562 $mob->setDescription("");
1563 $mob->create();
1564
1565 // determine and create mob directory, move uploaded file to directory
1566 //$mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob->getId();
1567 $mob->createDirectory();
1568 $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
1569
1570 $media_item = new ilMediaItem();
1571 $mob->addMediaItem($media_item);
1572 $media_item->setPurpose("Standard");
1573
1574 $file = $mob_dir . "/" . basename($fullpath);
1575
1576 // virus handling
1577 $vir = ilVirusScanner::virusHandling($fullpath, basename($fullpath));
1578 if (!$vir[0]) {
1579 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("file_is_infected") . "<br />" . $vir[1], true);
1580 ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" .
1581 $this->requested_ref_id . "&mepitem_id=" . $this->mep_item_id);
1582 }
1583
1584 switch ($this->mep_request->getFileAction()) {
1585 case "rename":
1586 rename($fullpath, $file);
1587 break;
1588
1589 case "copy":
1590 copy($fullpath, $file);
1591 break;
1592 }
1593
1594 // get mime type
1596 $location = basename($fullpath);
1597
1598 // set real meta and object data
1599 $media_item->setFormat($format);
1600 $media_item->setLocation($location);
1601 $media_item->setLocationType("LocalFile");
1602
1603 $mob->setDescription($format);
1604
1605 // determine width and height of known image types
1607 $format,
1608 "File",
1609 $mob_dir . "/" . $location,
1610 $media_item->getLocation(),
1611 true,
1612 true,
1613 null,
1614 null
1615 );
1616 $media_item->setWidth($wh["width"]);
1617 $media_item->setHeight($wh["height"]);
1618
1619 $media_item->setHAlign("Left");
1621 $mob->update();
1622
1623
1624 // put it into current folder
1625 $mep_item = new ilMediaPoolItem();
1626 $mep_item->setTitle($mob->getTitle());
1627 $mep_item->setType("mob");
1628 $mep_item->setForeignId($mob->getId());
1629 $mep_item->create();
1630
1631 $tree = $this->object->getTree();
1632 $parent = $this->mep_item_id;
1633 $tree->insertNode($mep_item->getId(), $parent);
1634 }
1635 }
1636 ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" .
1637 $this->requested_ref_id . "&mepitem_id=" . $this->mep_item_id);
1638 }
1639
1643 public static function getPreviewModalHTML(
1644 int $a_mpool_ref_id,
1646 ): string {
1647 global $DIC;
1648
1649 $tpl = $DIC["tpl"];
1650 $ilCtrl = $DIC->ctrl();
1651 $lng = $DIC->language();
1652 $request = $DIC->mediaPool()
1653 ->internal()
1654 ->gui()
1655 ->standardRequest();
1656
1658
1659 $tpl->addJavaScript("./Modules/MediaPool/js/ilMediaPool.js");
1660
1661 $ilCtrl->setParameterByClass("ilobjmediapoolgui", "mepitem_id", "");
1662 $ilCtrl->setParameterByClass("ilobjmediapoolgui", "ref_id", $a_mpool_ref_id);
1663 $tpl->addOnloadCode("il.MediaPool.setPreviewUrl('" . $ilCtrl->getLinkTargetByClass(array("ilmediapoolpresentationgui", "ilobjmediapoolgui"), "showPreview", "", false, false) . "');");
1664 $ilCtrl->setParameterByClass("ilobjmediapoolgui", "mepitem_id", $request->getItemId());
1665 $ilCtrl->setParameterByClass(
1666 "ilobjmediapoolgui",
1667 "ref_id",
1668 $request->getRefId()
1669 );
1670
1671 $modal = ilModalGUI::getInstance();
1672 $modal->setHeading($lng->txt("preview"));
1673 $modal->setId("ilMepPreview");
1674 $modal->setType(ilModalGUI::TYPE_LARGE);
1675 $modal->setBody("<iframe id='ilMepPreviewContent'></iframe>");
1676
1677 return $modal->getHTML();
1678 }
1679
1680 public function export(): void
1681 {
1682 $ot = ilObjectTranslation::getInstance($this->object->getId());
1683 $opt = "";
1684 if ($ot->getContentActivated()) {
1685 $format = explode("_", $this->mep_request->getExportFormat());
1686 $opt = ilUtil::stripSlashes($format[1]);
1687 }
1688
1689 $this->object->exportXML($opt);
1690 }
1691
1692 //
1693 // BULK UPLOAD
1694 //
1695
1696 protected function bulkUpload(): void
1697 {
1698 $this->checkPermission("write");
1699
1700 $main_tpl = $this->main_tpl;
1701
1702 $form = $this->getBulkUploadForm();
1703 $main_tpl->setContent($form->render());
1704 }
1705
1706 protected function getBulkUploadForm(): FormAdapterGUI
1707 {
1708 if (is_null($this->bulk_upload_form)) {
1709 $mep_hash = uniqid();
1710 $this->ctrl->setParameter($this, "mep_hash", $mep_hash);
1711 $this->bulk_upload_form = $this->gui
1712 ->form(self::class, 'performBulkUpload')
1713 ->section("props", $this->lng->txt('mep_bulk_upload'))
1714 ->file(
1715 "media_files",
1716 $this->lng->txt("mep_media_files"),
1717 \Closure::fromCallable([$this, 'handleUploadResult']),
1718 "mep_id",
1719 "",
1720 20
1721 );
1722 // ->meta()->text()->meta()->textarea()
1723 }
1724 return $this->bulk_upload_form;
1725 }
1726
1727 protected function handleUploadResult(
1728 FileUpload $upload,
1729 UploadResult $result
1731 $title = $result->getName();
1732
1733 $mob = new ilObjMediaObject();
1734 $mob->setTitle($title);
1735 $mob->setDescription("");
1736 $mob->create();
1737
1738 $mob->createDirectory();
1739 $media_item = new ilMediaItem();
1740 $mob->addMediaItem($media_item);
1741 $media_item->setPurpose("Standard");
1742
1743 $mob_dir = ilObjMediaObject::_getRelativeDirectory($mob->getId());
1744 $file_name = ilObjMediaObject::fixFilename($title);
1745 $file = $mob_dir . "/" . $file_name;
1746
1747 $upload->moveOneFileTo(
1748 $result,
1749 $mob_dir,
1750 Location::WEB,
1751 $file_name,
1752 true
1753 );
1754
1755 $mep_item = new ilMediaPoolItem();
1756 $mep_item->setTitle($title);
1757 $mep_item->setType("mob");
1758 $mep_item->setForeignId($mob->getId());
1759 $mep_item->create();
1760
1761 $tree = $this->object->getTree();
1762 $parent = $this->mep_item_id;
1763 $tree->insertNode($mep_item->getId(), $parent);
1764
1765 // get mime type
1767 $location = $file_name;
1768
1769 // set real meta and object data
1770 $media_item->setFormat($format);
1771 $media_item->setLocation($location);
1772 $media_item->setLocationType("LocalFile");
1773 $media_item->setUploadHash($this->mep_request->getUploadHash());
1774 $mob->update();
1775
1776 $item_ids[] = $mob->getId();
1777
1778 $mob = new ilObjMediaObject($mob->getId());
1779 $mob->generatePreviewPic(320, 240);
1780
1781 // duration
1782 $med_item = $mob->getMediaItem("Standard");
1783 $med_item->determineDuration();
1784 $med_item->update();
1785
1786 return new BasicHandlerResult(
1787 "mep_id",
1788 HandlerResult::STATUS_OK,
1789 $med_item->getId(),
1790 ''
1791 );
1792 }
1793
1797 public function performBulkUpload(): void
1798 {
1799 $this->checkPermission("write");
1800 $this->ctrl->setParameter($this, "mep_hash", $this->mep_request->getUploadHash());
1801 $this->ctrl->redirect($this, "editTitlesAndDescriptions");
1802 }
1803
1804 protected function editTitlesAndDescriptions(): void
1805 {
1806 $ctrl = $this->ctrl;
1807 $lng = $this->lng;
1808
1809 $this->checkPermission("write");
1810 $ctrl->saveParameter($this, "mep_hash");
1811
1812 $main_tpl = $this->main_tpl;
1813
1815 $this->mep_request->getUploadHash()
1816 );
1817
1818 $tb = new ilToolbarGUI();
1819 $tb->setFormAction($ctrl->getFormAction($this));
1820 $tb->addFormButton($lng->txt("save"), "saveTitlesAndDescriptions");
1821 $tb->setOpenFormTag(true);
1822 $tb->setCloseFormTag(false);
1823 $tb->setId("tb_top");
1824
1825 $html = $tb->getHTML();
1826 foreach ($media_items as $mi) {
1827 $acc = new ilAccordionGUI();
1828 $acc->setBehaviour(ilAccordionGUI::ALL_CLOSED);
1829 $acc->setId("acc_" . $mi["mob_id"]);
1830
1831 $mob = new ilObjMediaObject($mi["mob_id"]);
1832 $form = $this->initMediaBulkForm($mi["mob_id"], $mob->getTitle());
1833 $acc->addItem($mob->getTitle(), $form->getHTML());
1834
1835 $html .= $acc->getHTML();
1836 }
1837
1838 $html .= $tb->getHTML();
1839 $tb->setOpenFormTag(false);
1840 $tb->setCloseFormTag(true);
1841 $tb->setId("tb_bottom");
1842
1843 $main_tpl->setContent($html);
1844 }
1845
1849 public function initMediaBulkForm(
1850 int $a_id,
1851 string $a_title
1853 $lng = $this->lng;
1854
1855 $form = new ilPropertyFormGUI();
1856 $form->setOpenTag(false);
1857 $form->setCloseTag(false);
1858
1859 // title
1860 $ti = new ilTextInputGUI($lng->txt("title"), "title_" . $a_id);
1861 $ti->setValue($a_title);
1862 $form->addItem($ti);
1863
1864 // description
1865 $ti = new ilTextAreaInputGUI($lng->txt("description"), "description_" . $a_id);
1866 $form->addItem($ti);
1867
1868 return $form;
1869 }
1870
1871 protected function saveTitlesAndDescriptions(): void
1872 {
1873 $lng = $this->lng;
1874 $ctrl = $this->ctrl;
1875
1876 $this->checkPermission("write");
1878 $this->mep_request->getUploadHash()
1879 );
1880
1881 foreach ($media_items as $mi) {
1882 $mob = new ilObjMediaObject($mi["mob_id"]);
1883 $form = $this->initMediaBulkForm($mi["mob_id"], $mob->getTitle());
1884 $form->checkInput();
1885 $title = $form->getInput("title_" . $mi["mob_id"]);
1886 $desc = $form->getInput("description_" . $mi["mob_id"]);
1887 if (trim($title) !== "") {
1888 $mob->setTitle($title);
1889 }
1890 $mob->setDescription($desc);
1891 $mob->update();
1892 }
1893 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1894 $ctrl->redirect($this, "listMedia");
1895 }
1896
1897 protected function move(): void
1898 {
1899 ilSession::set("mep_move_ids", $this->mep_request->getItemIds());
1900 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("mep_move_select_insert"), true);
1901 $this->ctrl->redirect($this, "listMedia");
1902 }
1903
1904 protected function paste(): void
1905 {
1907 $target_tree = $this->object->getTree();
1908
1909 // sanity check
1910 $move_ids = ilSession::get("mep_move_ids");
1911 if (is_array($move_ids)) {
1912 foreach ($move_ids as $id) {
1914
1915 $parent_id = $this->mep_request->getItemId();
1916 if (ilMediaPoolItem::lookupType($parent_id) !== "fold") {
1917 $parent_id = $target_tree->readRootId();
1918 }
1919
1920 $subnodes = [];
1921 foreach ($pool_ids as $pool_id) {
1922 $pool = new ilObjMediaPool($pool_id, false);
1923 $source_tree = $pool->getTree();
1924
1925 // if source tree == target tree, check if target is within source tree
1926 $subnodes = $source_tree->getSubtree($source_tree->getNodeData($id));
1927 if ($pool_id == $target_tree->getTreeId()) {
1928 // check, if target is within subtree
1929 foreach ($subnodes as $subnode) {
1930 if ($subnode["child"] == $parent_id) {
1931 $this->main_tpl->setOnScreenMessage(
1932 'failure',
1933 $this->lng->txt("mep_target_in_source_not_allowed"),
1934 true
1935 );
1936
1937 $this->ctrl->redirect($this, "listMedia");
1938 }
1939 }
1940 }
1941 $source_tree->deleteTree($source_tree->getNodeData($id));
1942 }
1943
1944 $target_tree->insertNode($id, $parent_id);
1945 foreach ($subnodes as $node) {
1946 if ($node["child"] != $id) {
1947 $target_tree->insertNode($node["child"], $node["parent"]);
1948 }
1949 }
1950 }
1951 }
1952 ilSession::clear("mep_move_ids");
1953 $this->ctrl->redirect($this, "listMedia");
1954 }
1955}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
const IL_MODE_ALIAS
const IL_MODE_OUTPUT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
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...
File System Explorer GUI class.
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static renameExecutables(string $a_dir)
setCloseTag(bool $a_val)
setOpenTag(bool $a_open)
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
Help GUI class.
Class ilInfoScreenGUI.
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getMediaItemsForUploadHash(string $a_hash)
Get media items for upload hash.
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 getPoolForItemId(int $a_id)
static lookupTitle(int $a_id)
static lookupForeignId(int $a_id)
static lookupType(int $a_id)
Class ilMediaPoolPage GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupTitle(int $a_page_id)
TableGUI class for recent changes in wiki.
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 getInstance()
This class represents a number property in a property form.
Class ilObjFolderGUI.
Editing User Interface for MediaObjects within LMs (see ILIAS DTD)
static includePresentationJS(ilGlobalTemplateInterface $a_tpl=null)
Include media object presentation JS.
static isTypeAllowed(string $a_type)
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)
static fixFilename(string $a_name)
Fix filename of uploaded file.
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
static _getRelativeDirectory(int $a_mob_id)
Get relative (to webspace dir) directory.
static _getDirectory(int $a_mob_id)
Get absolute directory.
User Interface class for media pool objects.
afterSave(ilObject $new_object)
Post (successful) object creation hook.
StandardGUIRequest $mep_request
initMediaBulkForm(int $a_id, string $a_title)
Init media bulk form.
cancelRemove()
cancel deletion of media objects/folders
performBulkUpload()
Save bulk upload form.
getTemplate()
Get standard template.
showMedia()
show media object
setTabs()
create tabs (repository/workspace switch)
addLocatorItems()
add locator items for media pool
getFolderValues()
Get current values for folder from.
showFullscreen()
show media fullscreen
updateCustom(ilPropertyFormGUI $form)
Insert custom update form values into object.
allMedia()
list all media objects
openClipboard()
paste from clipboard
selectUploadDirFiles(?array $a_files=null)
Select files from upload directory.
createMediaFromUploadDir()
Create media object from upload directory.
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
setSettingsSubTabs(string $a_active)
getParentFolderId()
Get folder parent ID.
getMediaPoolPageGUI($mep_item_id, $old_nr=0)
Get media pool page.
handleUploadResult(FileUpload $upload, UploadResult $result)
confirmRemove()
confirm remove of mobs
static getPreviewModalHTML(int $a_mpool_ref_id, ilGlobalTemplateInterface $a_tpl)
Get preview modal html.
FormAdapterGUI $bulk_upload_form
infoScreenObject()
this one is called from the info button in the repository
ilGlobalTemplateInterface $main_tpl
showPreview()
Show content snippet.
saveFolder()
Save folder form.
static _goto(string $a_target)
getEditFormCustomValues(array &$a_values)
Add values to custom edit fields.
initEditCustomForm(ilPropertyFormGUI $a_form)
Add custom fields to update form.
infoScreen()
show information screen
initCreationForms(string $new_type)
Init creation forms.
returnFromItem()
Return from item editing.
insertFromClipboard()
insert media object from clipboard
copyToClipboard()
copy media objects to clipboard
setContentSubTabs(string $a_active)
Set sub tabs for content tab.
listMedia()
list media objects
getType()
Functions that must be overwritten.
initFolderForm(string $a_mode="edit")
InternalGUIService $gui
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isItemIdInTree(int $a_pool_id, int $a_item_id)
Check whether a mep item id is in the media pool.
static isForeignIdInTree(int $a_pool_id, int $a_foreign_id)
Check whether foreign id is in tree.
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
New implementation of ilObjectGUI.
ilAccessHandler $access
ilGlobalTemplateInterface $tpl
setCreationMode(bool $mode=true)
if true, a creation screen is displayed the current [ref_id] don't belong to the current class!...
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
ilLocatorGUI $locator
setLocator()
set Locator
ilObjectService $object_service
prepareOutput(bool $show_sub_objects=true)
checkPermission(string $perm, string $cmd="", string $type="", int $ref_id=null)
ilToolbarGUI $toolbar
initImportForm(string $new_type)
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
addExternalEditFormCustom(ilPropertyFormGUI $form)
addHeaderAction()
Add header action menu.
initCreateForm(string $new_type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static updateServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
static initServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static getUsages(string $a_pc_type, int $a_pc_id, bool $a_incl_hist=true)
Get usages.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This class represents a selection list property in a property form.
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
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 text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
insertNode(int $a_node_id, int $a_parent_id, int $a_pos=self::POS_LAST_NODE, bool $a_reset_deletion_date=false)
insert new node with node_id under parent node with parent_id
getParentId(int $a_node_id)
get parent id of given node
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
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 redirect(string $a_script)
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
xslt_free(&$proc)
xslt_create()
moveOneFileTo(UploadResult $uploadResult, string $destination, int $location=Location::STORAGE, string $file_name='', bool $override_existing=false)
Moves a single File (the attributes, metadata and upload-status of which are contained in UploadResul...
Interface Location.
Definition: Location.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
printToStdout(string $part=self::DEFAULT_BLOCK, bool $has_tabs=true, bool $skip_main_menu=false)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
addCss(string $a_css_file, string $media="screen")
Add a css file that should be included in the header.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
exit
Definition: login.php:28
$ref_id
Definition: ltiauth.php:67
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
$path
Definition: ltiservices.php:32
$format
Definition: metadata.php:235
$xml
Definition: metadata.php:351
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd)
$lng