ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjMediaObject.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4define("IL_MODE_ALIAS", 1);
5define("IL_MODE_OUTPUT", 2);
6define("IL_MODE_FULL", 3);
7
8require_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
9include_once "./Services/Object/classes/class.ilObject.php";
10
27{
31 protected $user;
32
37
38 public $is_alias;
39 public $origin_id;
42
47 public function __construct($a_id = 0)
48 {
49 global $DIC;
50
51 $this->user = $DIC->user();
52 $this->app_event_handler = $DIC["ilAppEventHandler"];
53 $this->lng = $DIC->language();
54 $this->is_alias = false;
55 $this->media_items = array();
56 $this->contains_int_link = false;
57 $this->type = "mob";
58 parent::__construct($a_id, false);
59 }
60
61 public function setRefId($a_id)
62 {
63 $this->ilias->raiseError("Operation ilObjMedia::setRefId() not allowed.", $this->ilias->error_obj->FATAL);
64 }
65
66 public function getRefId()
67 {
68 return false;
69 }
70
71 public function putInTree($a_parent_ref)
72 {
73 $this->ilias->raiseError("Operation ilObjMedia::putInTree() not allowed.", $this->ilias->error_obj->FATAL);
74 }
75
76 public function createReference()
77 {
78 $this->ilias->raiseError("Operation ilObjMedia::createReference() not allowed.", $this->ilias->error_obj->FATAL);
79 }
80
81 public function setTitle($a_title)
82 {
83 parent::setTitle($a_title);
84 }
85
86 public function getTitle()
87 {
88 return parent::getTitle();
89 }
90
98 public static function _exists($a_id, $a_reference = false, $a_type = null)
99 {
100 global $DIC;
101
102 $ilDB = $DIC->database();
103
104 include_once("./Services/Link/classes/class.ilInternalLink.php");
105 if (is_int(strpos($a_id, "_"))) {
107 }
108
109 if (parent::_exists($a_id, false) && ilObject::_lookupType($a_id) == "mob") {
110 return true;
111 }
112 return false;
113 }
114
118 public function delete()
119 {
120 $mob_logger = ilLoggerFactory::getLogger('mob');
121 $mob_logger->debug("ilObjMediaObject: Delete called for media object ID '" . $this->getId() . "'.");
122
123 if (!($this->getId() > 0)) {
124 return;
125 }
126
127 $usages = $this->getUsages();
128
129 $mob_logger->debug("ilObjMediaObject: ... Found " . count($usages) . " usages.");
130
131 if (count($usages) == 0) {
132 // remove directory
134
135 // remove thumbnail directory
137
138 // delete meta data of mob
139 $this->deleteMetaData();
140
141 // delete media items
143
144 // this is just to make sure, there should be no entries left at
145 // this point as they depend on the usage
147
148 // delete object
149 parent::delete();
150
151 $mob_logger->debug("ilObjMediaObject: ... deleted.");
152 } else {
153 foreach ($usages as $u) {
154 $mob_logger->debug("ilObjMediaObject: ... usage type:" . $u["type"] .
155 ", id:" . $u["id"] .
156 ", lang:" . $u["lang"] .
157 ", hist_nr:" . $u["hist_nr"] . ".");
158 }
159 $mob_logger->debug("ilObjMediaObject: ... not deleted.");
160 }
161 }
162
168 public function getDescription()
169 {
170 return parent::getDescription();
171 }
172
176 public function setDescription($a_description)
177 {
178 parent::setDescription($a_description);
179 }
180
192 public function MDUpdateListener($a_element)
193 {
194 include_once 'Services/MetaData/classes/class.ilMD.php';
195
196 switch ($a_element) {
197 case 'General':
198
199 // Update Title and description
200 $md = new ilMD(0, $this->getId(), $this->getType());
201 $md_gen = $md->getGeneral();
202
203 if (is_object($md_gen)) {
204 ilObject::_writeTitle($this->getId(), $md_gen->getTitle());
205 $this->setTitle($md_gen->getTitle());
206
207 foreach ($md_gen->getDescriptionIds() as $id) {
208 $md_des = $md_gen->getDescription($id);
209 ilObject::_writeDescription($this->getId(), $md_des->getDescription());
210 $this->setDescription($md_des->getDescription());
211 break;
212 }
213 }
214
215 break;
216
217 default:
218 }
219 return true;
220 }
221
225 public function createMetaData()
226 {
227 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
228
230
231 $md_creator = new ilMDCreator(0, $this->getId(), $this->getType());
232 $md_creator->setTitle($this->getTitle());
233 $md_creator->setTitleLanguage($ilUser->getPref('language'));
234 $md_creator->setDescription($this->getDescription());
235 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
236 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
237 $md_creator->setLanguage($ilUser->getPref('language'));
238 $md_creator->create();
239
240 return true;
241 }
242
246 public function updateMetaData()
247 {
248 include_once("Services/MetaData/classes/class.ilMD.php");
249 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
250 include_once("Services/MetaData/classes/class.ilMDDescription.php");
251
252 $md = new ilMD(0, $this->getId(), $this->getType());
253 $md_gen = $md->getGeneral();
254 $md_gen->setTitle($this->getTitle());
255
256 // sets first description (maybe not appropriate)
257 $md_des_ids = $md_gen->getDescriptionIds();
258 if (count($md_des_ids) > 0) {
259 $md_des = $md_gen->getDescription($md_des_ids[0]);
260 $md_des->setDescription($this->getDescription());
261 $md_des->update();
262 }
263 $md_gen->update();
264 }
265
269 public function deleteMetaData()
270 {
271 // Delete meta data
272 include_once('Services/MetaData/classes/class.ilMD.php');
273 $md = new ilMD(0, $this->getId(), $this->getType());
274 $md->deleteAll();
275 }
276
277
283 public function addMediaItem($a_item)
284 {
285 $this->media_items[] = $a_item;
286 }
287
288
294 public function &getMediaItems()
295 {
296 return $this->media_items;
297 }
298
305 public function getMediaItem($a_purpose) : ?ilMediaItem
306 {
307 foreach ($this->media_items as $media_item) {
308 if ($media_item->getPurpose() == $a_purpose) {
309 return $media_item;
310 }
311 }
312 return null;
313 }
314
315
319 public function removeMediaItem($a_purpose)
320 {
321 foreach ($this->media_items as $key => $media_item) {
322 if ($media_item->getPurpose() == $a_purpose) {
323 unset($this->media_items[$key]);
324 }
325 }
326 // update numbers and keys
327 $i = 1;
328 $media_items = array();
329 foreach ($this->media_items as $media_item) {
330 $media_items [$i] = $media_item;
331 $media_item->setMobId($this->getId());
332 $media_item->setNr($i);
333 $i++;
334 }
335 $this->media_items = $media_items;
336 }
337
341 public function removeAllMediaItems()
342 {
343 $this->media_items = array();
344 }
345
346
347 public function getMediaItemNr($a_purpose)
348 {
349 for ($i = 0; $i < count($this->media_items); $i++) {
350 if ($this->media_items[$i]->getPurpose() == $a_purpose) {
351 return $i + 1;
352 }
353 }
354 return false;
355 }
356
357
358 public function hasFullscreenItem()
359 {
360 return $this->hasPurposeItem("Fullscreen");
361 }
362
369 public function hasPurposeItem($purpose)
370 {
371 if (is_object($this->getMediaItem($purpose))) {
372 return true;
373 } else {
374 return false;
375 }
376 }
377
378
379
383 public function read()
384 {
385 //echo "<br>ilObjMediaObject:read";
386 parent::read();
387
388 // get media items
390 }
391
395 public function setAlias($a_is_alias)
396 {
397 $this->is_alias = $a_is_alias;
398 }
399
400 public function isAlias()
401 {
402 return $this->is_alias;
403 }
404
405 public function setOriginID($a_id)
406 {
407 return $this->origin_id = $a_id;
408 }
409
410 public function getOriginID()
411 {
412 return $this->origin_id;
413 }
414
415 /*
416 function getimportId()
417 {
418 return $this->meta_data->getImportIdentifierEntryID();
419 }*/
420
421
425 public function getImportId()
426 {
427 return $this->import_id;
428 }
429
430 public function setImportId($a_id)
431 {
432 $this->import_id = $a_id;
433 }
434
438 public function create($a_create_meta_data = false, $a_save_media_items = true)
439 {
440 parent::create();
441
442 if (!$a_create_meta_data) {
443 $this->createMetaData();
444 }
445
446 if ($a_save_media_items) {
447 $media_items = $this->getMediaItems();
448 for ($i = 0; $i < count($media_items); $i++) {
449 $item = $media_items[$i];
450 $item->setMobId($this->getId());
451 $item->setNr($i + 1);
452 $item->create();
453 }
454 }
455
457
458 $ilAppEventHandler = $this->app_event_handler;
459 $ilAppEventHandler->raise(
460 'Services/MediaObjects',
461 'create',
462 array('object' => $this,
463 'obj_type' => 'mob',
464 'obj_id' => $this->getId())
465 );
466 }
467
468
472 public function update($a_upload = false)
473 {
474 parent::update();
475
476 if (!$a_upload) {
477 $this->updateMetaData();
478 }
479
480 // iterate all items
481 $media_items = $this->getMediaItems();
482
484
485 $j = 1;
486 foreach ($media_items as $key => $val) {
487 $item = $media_items[$key];
488 if (is_object($item)) {
489 $item->setMobId($this->getId());
490 $item->setNr($j);
491 if ($item->getLocationType() == "Reference") {
492 $item->extractUrlParameters();
493 }
494 $item->create();
495 $j++;
496 }
497 }
498
500 $ilAppEventHandler = $this->app_event_handler;
501 $ilAppEventHandler->raise(
502 'Services/MediaObjects',
503 'update',
504 array('object' => $this,
505 'obj_type' => 'mob',
506 'obj_id' => $this->getId())
507 );
508 }
509
510 protected static function handleQuotaUpdate(ilObjMediaObject $a_mob)
511 {
512 }
513
520 public static function _getDirectory($a_mob_id)
521 {
522 return ilUtil::getWebspaceDir() . "/" . self::_getRelativeDirectory($a_mob_id);
523 }
524
531 public static function _getRelativeDirectory($a_mob_id)
532 {
533 return "mobs/mm_" . $a_mob_id;
534 }
535
536
542 public static function _getURL($a_mob_id)
543 {
544 return ilUtil::getHtmlPath(ilUtil::getWebspaceDir() . "/mobs/mm_" . $a_mob_id);
545 }
546
552 public static function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
553 {
554 return ilUtil::getWebspaceDir($a_mode) . "/thumbs/mm_" . $a_mob_id;
555 }
556
562 public static function _lookupStandardItemPath(
563 $a_mob_id,
564 $a_url_encode = false,
565 $a_web = true
566 ) {
567 return ilObjMediaObject::_lookupItemPath($a_mob_id, $a_url_encode, $a_web, "Standard");
568 }
569
575 public static function _lookupItemPath(
576 $a_mob_id,
577 $a_url_encode = false,
578 $a_web = true,
579 $a_purpose = ""
580 ) {
581 if ($a_purpose == "") {
582 $a_purpose = "Standard";
583 }
584 $location = ilMediaItem::_lookupLocationForMobId($a_mob_id, $a_purpose);
585 if (preg_match("/https?\:/i", $location)) {
586 return $location;
587 }
588
589 if ($a_url_encode) {
590 $location = rawurlencode($location);
591 }
592
593 $path = ($a_web)
594 ? ILIAS_HTTP_PATH
595 : ".";
596
597 return $path . "/data/" . CLIENT_ID . "/mobs/mm_" . $a_mob_id . "/" . $location;
598 }
599
603 public function createDirectory()
604 {
605 $path = ilObjMediaObject::_getDirectory($this->getId());
607 if (!is_dir($path)) {
608 $this->ilias->raiseError("Failed to create directory $path.", $this->ilias->error_obj->FATAL);
609 }
610 }
611
615 public static function _createThumbnailDirectory($a_obj_id)
616 {
618 ilUtil::createDirectory(ilUtil::getWebspaceDir() . "/thumbs/mm_" . $a_obj_id);
619 }
620
627 public function getFilesOfDirectory($a_subdir = "")
628 {
629 $a_subdir = str_replace("..", "", $a_subdir);
630 $dir = ilObjMediaObject::_getDirectory($this->getId());
631 if ($a_subdir != "") {
632 $dir .= "/" . $a_subdir;
633 }
634
635 $files = array();
636 if (is_dir($dir)) {
637 $entries = ilUtil::getDir($dir);
638 foreach ($entries as $e) {
639 if (is_file($dir . "/" . $e["entry"]) && $e["entry"] != "." && $e["entry"] != "..") {
640 $files[] = $e["entry"];
641 }
642 }
643 }
644
645 return $files;
646 }
647
648
653 public function getXML($a_mode = IL_MODE_FULL, $a_inst = 0, $a_sign_locals = false)
654 {
656
657 // TODO: full implementation of all parameters
658 //echo "-".$a_mode."-";
659 switch ($a_mode) {
660 case IL_MODE_ALIAS:
661 $xml = "<MediaObject>";
662 $xml .= "<MediaAlias OriginId=\"il__mob_" . $this->getId() . "\"/>";
663 $media_items = $this->getMediaItems();
664 for ($i = 0; $i < count($media_items); $i++) {
665 $item = $media_items[$i];
666 $xml .= "<MediaAliasItem Purpose=\"" . $item->getPurpose() . "\">";
667
668 // Layout
669 $width = ($item->getWidth() != "")
670 ? "Width=\"" . $item->getWidth() . "\""
671 : "";
672 $height = ($item->getHeight() != "")
673 ? "Height=\"" . $item->getHeight() . "\""
674 : "";
675 $halign = ($item->getHAlign() != "")
676 ? "HorizontalAlign=\"" . $item->getHAlign() . "\""
677 : "";
678 $xml .= "<Layout $width $height $halign />";
679
680 // Caption
681 if ($item->getCaption() != "") {
682 $xml .= "<Caption Align=\"bottom\">" .
683 $this->escapeProperty($item->getCaption()) . "</Caption>";
684 }
685
686 // Text Representation
687 if ($item->getTextRepresentation() != "") {
688 $xml .= "<TextRepresentation>" .
689 $this->escapeProperty($item->getTextRepresentation()) . "</TextRepresentation>";
690 }
691
692 // Parameter
693 $parameters = $item->getParameters();
694 foreach ($parameters as $name => $value) {
695 $xml .= "<Parameter Name=\"$name\" Value=\"" . $this->escapeProperty($value) . "\"/>";
696 }
697 $xml .= $item->getMapAreasXML();
698 $xml .= "</MediaAliasItem>";
699 }
700 break;
701
702 // for output we need technical sections of meta data
703 case IL_MODE_OUTPUT:
704
705 // get first technical section
706// $meta = $this->getMetaData();
707 $xml = "<MediaObject Id=\"il__mob_" . $this->getId() . "\">";
708
709 $media_items = $this->getMediaItems();
710 for ($i = 0; $i < count($media_items); $i++) {
711 $item = $media_items[$i];
712
713 $xml .= "<MediaItem Purpose=\"" . $item->getPurpose() . "\">";
714
715 if ($a_sign_locals && $item->getLocationType() == "LocalFile") {
716 require_once 'Services/WebAccessChecker/classes/class.ilWACSignedPath.php';
717 $location = ilWACSignedPath::signFile($this->getDataDirectory() . "/" . $item->getLocation());
718 $location = substr($location, strrpos($location, "/") + 1);
719 } else {
720 $location = $item->getLocation();
721 if ($item->getLocationType() != "LocalFile") { //#25941
723 }
724 }
725
726 $xml .= "<Location Type=\"" . $item->getLocationType() . "\">" .
727 $this->handleAmps($location) . "</Location>";
728
729 // Format
730 $xml .= "<Format>" . $item->getFormat() . "</Format>";
731
732 // Layout
733 $width = ($item->getWidth() != "")
734 ? "Width=\"" . $item->getWidth() . "\""
735 : "";
736 $height = ($item->getHeight() != "")
737 ? "Height=\"" . $item->getHeight() . "\""
738 : "";
739 $halign = ($item->getHAlign() != "")
740 ? "HorizontalAlign=\"" . $item->getHAlign() . "\""
741 : "";
742 $xml .= "<Layout $width $height $halign />";
743
744 // Caption
745 if ($item->getCaption() != "") {
746 $xml .= "<Caption Align=\"bottom\">" .
747 $this->escapeProperty($item->getCaption()) . "</Caption>";
748 }
749
750 // Text Representation
751 if ($item->getTextRepresentation() != "") {
752 $xml .= "<TextRepresentation>" .
753 $this->escapeProperty($item->getTextRepresentation()) . "</TextRepresentation>";
754 }
755
756 // Title
757 if ($this->getTitle() != "") {
758 $xml .= "<Title>" .
759 $this->escapeProperty($this->getTitle()) . "</Title>";
760 }
761
762 // Parameter
763 $parameters = $item->getParameters();
764 foreach ($parameters as $name => $value) {
765 $xml .= "<Parameter Name=\"$name\" Value=\"" . $this->escapeProperty($value) . "\"/>";
766 }
767 $xml .= $item->getMapAreasXML();
768
769 // Subtitles
770 if ($item->getPurpose() == "Standard") {
771 $srts = $this->getSrtFiles();
772 foreach ($srts as $srt) {
773 $def = "";
774 $meta_lang = "";
775 if ($ilUser->getLanguage() != $meta_lang &&
776 $ilUser->getLanguage() == $srt["language"]) {
777 $def = ' Default="true" ';
778 }
779 $xml .= "<Subtitle File=\"" . $srt["full_path"] .
780 "\" Language=\"" . $srt["language"] . "\" " . $def . "/>";
781 }
782 }
783 $xml .= "</MediaItem>";
784 }
785 break;
786
787 // full xml for export
788 case IL_MODE_FULL:
789
790// $meta = $this->getMetaData();
791 $xml = "<MediaObject>";
792
793 // meta data
794 include_once("Services/MetaData/classes/class.ilMD2XML.php");
795 $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
796 $md2xml->setExportMode(true);
797 $md2xml->startExport();
798 $xml .= $md2xml->getXML();
799
800 $media_items = $this->getMediaItems();
801 for ($i = 0; $i < count($media_items); $i++) {
802 $item = $media_items[$i];
803
804 // highlight mode
805 $xml .= "<MediaItem Purpose=\"" . $item->getPurpose() . "\">";
806
807 // Location
808 $xml .= "<Location Type=\"" . $item->getLocationType() . "\">" .
809 $this->handleAmps($item->getLocation()) . "</Location>";
810
811 // Format
812 $xml .= "<Format>" . $item->getFormat() . "</Format>";
813
814 // Layout
815 $width = ($item->getWidth() != "")
816 ? "Width=\"" . $item->getWidth() . "\""
817 : "";
818 $height = ($item->getHeight() != "")
819 ? "Height=\"" . $item->getHeight() . "\""
820 : "";
821 $halign = ($item->getHAlign() != "")
822 ? "HorizontalAlign=\"" . $item->getHAlign() . "\""
823 : "";
824 $xml .= "<Layout $width $height $halign />";
825
826 // Caption
827 if ($item->getCaption() != "") {
828 $xml .= "<Caption Align=\"bottom\">" .
829 str_replace("&", "&amp;", $item->getCaption()) . "</Caption>";
830 }
831
832 // Text Representation
833 if ($item->getTextRepresentation() != "") {
834 $xml .= "<TextRepresentation>" .
835 str_replace("&", "&amp;", $item->getTextRepresentation()) . "</TextRepresentation>";
836 }
837
838 // Parameter
839 $parameters = $item->getParameters();
840 foreach ($parameters as $name => $value) {
841 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
842 }
843 $xml .= $item->getMapAreasXML(true, $a_inst);
844 $xml .= "</MediaItem>";
845 }
846 break;
847 }
848 $xml .= "</MediaObject>";
849 return $xml;
850 }
851
858 protected function escapeProperty($a_value)
859 {
860 return htmlspecialchars($a_value);
861 }
862
863
867 public function handleAmps($a_str)
868 {
869 $a_str = str_replace("&amp;", "&", $a_str);
870 $a_str = str_replace("&", "&amp;", $a_str);
871 return $a_str;
872 }
873
877 public function exportXML(&$a_xml_writer, $a_inst = 0)
878 {
879 $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
880 }
881
882
890 public function exportFiles($a_target_dir)
891 {
892 $subdir = "il_" . IL_INST_ID . "_mob_" . $this->getId();
893 ilUtil::makeDir($a_target_dir . "/objects/" . $subdir);
894
895 $mobdir = ilUtil::getWebspaceDir() . "/mobs/mm_" . $this->getId();
896 ilUtil::rCopy($mobdir, $a_target_dir . "/objects/" . $subdir);
897 //echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
898 }
899
900 public function exportMediaFullscreen($a_target_dir, $pg_obj)
901 {
902 $subdir = "il_" . IL_INST_ID . "_mob_" . $this->getId();
903 $a_target_dir = $a_target_dir . "/objects/" . $subdir;
904 ilUtil::makeDir($a_target_dir);
905 $tpl = new ilGlobalTemplate("tpl.fullscreen.html", true, true, "Modules/LearningModule");
906 $tpl->setCurrentBlock("ilMedia");
907
908 //$int_links = $page_object->getInternalLinks();
909 $med_links = ilMediaItem::_getMapAreasIntLinks($this->getId());
910
911 // @todo
912 //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets());
913
914 require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
915 //$media_obj = new ilObjMediaObject($_GET["mob_id"]);
916 require_once("./Services/COPage/classes/class.ilPageObject.php");
917
918 $xml = "<dummy>";
919 // todo: we get always the first alias now (problem if mob is used multiple
920 // times in page)
921 $xml .= $pg_obj->getMediaAliasElement($this->getId());
922 $xml .= $this->getXML(IL_MODE_OUTPUT);
923 //$xml.= $link_xml;
924 $xml .= "</dummy>";
925
926 //die(htmlspecialchars($xml));
927
928 $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
929 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
930 $xh = xslt_create();
931
932 //echo "<b>XML:</b>".htmlentities($xml);
933 // determine target frames for internal links
934 $wb_path = "";
935 $enlarge_path = "";
936 $params = array('mode' => "fullscreen", 'enlarge_path' => $enlarge_path,
937 'link_params' => "ref_id=" . $_GET["ref_id"],'fullscreen_link' => "",
938 'enable_html_mob' => ilObjMediaObject::isTypeAllowed("html") ? "y" : "n",
939 'ref_id' => $_GET["ref_id"], 'webspace_path' => $wb_path);
940 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
941 //echo xslt_error($xh);
942 xslt_free($xh);
943
944 // unmask user html
945 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
946 $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "../../css/style.css");
947 $tpl->setVariable("LOCATION_STYLESHEET", "../../css/system.css");
948 $tpl->setVariable("MEDIA_CONTENT", $output);
949 $output = $tpl->get();
950 //$output = preg_replace("/\/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
951 $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i", "$2", $output);
952 $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i", "../../players", $output);
953 $output = preg_replace("/\.\/" . str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory()) . "/i", "../../players", $output);
954 $output = preg_replace("/file=..\/..\/..\//i", "file=../objects/" . $subdir . "/", $output);
955 //die(htmlspecialchars($output));
956 fwrite(fopen($a_target_dir . '/fullscreen.html', 'w'), $output);
957 }
958
959 public function modifyExportIdentifier($a_tag, $a_param, $a_value)
960 {
961 if ($a_tag == "Identifier" && $a_param == "Entry") {
962 $a_value = ilUtil::insertInstIntoID($a_value);
963 }
964
965 return $a_value;
966 }
967
968
970 // EDIT METHODS: these methods act on the media alias in the dom
972
979 public function setContainsIntLink($a_contains_link)
980 {
981 $this->contains_int_link = $a_contains_link;
982 }
983
988 public function containsIntLink()
989 {
991 }
992
996 public static function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
997 {
998 global $DIC;
999
1000 $ilDB = $DIC->database();
1001
1002 $and_hist = "";
1003 if ($a_usage_hist_nr !== false) {
1004 $and_hist = " AND usage_hist_nr = " . $ilDB->quote($a_usage_hist_nr, "integer");
1005 }
1006
1007 $mob_ids = array();
1008 $set = $ilDB->query("SELECT id FROM mob_usage" .
1009 " WHERE usage_type = " . $ilDB->quote($a_type, "text") .
1010 " AND usage_id = " . $ilDB->quote($a_id, "integer") .
1011 " AND usage_lang = " . $ilDB->quote($a_lang, "text") .
1012 $and_hist);
1013 while ($row = $ilDB->fetchAssoc($set)) {
1014 $mob_ids[] = $row["id"];
1015 }
1016
1017 $q = "DELETE FROM mob_usage WHERE usage_type = " .
1018 $ilDB->quote($a_type, "text") .
1019 " AND usage_id= " . $ilDB->quote($a_id, "integer") .
1020 " AND usage_lang = " . $ilDB->quote($a_lang, "text") .
1021 $and_hist;
1022 $ilDB->manipulate($q);
1023
1024 foreach ($mob_ids as $mob_id) {
1025 self::handleQuotaUpdate(new self($mob_id));
1026 }
1027 }
1028
1032 public static function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1033 {
1034 global $DIC;
1035
1036 $ilDB = $DIC->database();
1037
1038 $lstr = "";
1039 if ($a_lang != "") {
1040 $lstr = " AND usage_lang = " . $ilDB->quote($a_lang, "text");
1041 }
1042 $hist_str = "";
1043 if ($a_usage_hist_nr !== false) {
1044 $hist_str = " AND usage_hist_nr = " . $ilDB->quote($a_usage_hist_nr, "integer");
1045 }
1046
1047 $q = "SELECT * FROM mob_usage WHERE " .
1048 "usage_type = " . $ilDB->quote($a_type, "text") . " AND " .
1049 "usage_id = " . $ilDB->quote($a_id, "integer") .
1050 $lstr . $hist_str;
1051 $mobs = array();
1052 $mob_set = $ilDB->query($q);
1053 while ($mob_rec = $ilDB->fetchAssoc($mob_set)) {
1054 if (ilObject::_lookupType($mob_rec["id"]) == "mob") {
1055 $mobs[$mob_rec["id"]] = $mob_rec["id"];
1056 }
1057 }
1058
1059 return $mobs;
1060 }
1061
1065 public static function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1066 {
1067 global $DIC;
1068
1069 $ilDB = $DIC->database();
1070
1071 $ilDB->replace(
1072 "mob_usage",
1073 array(
1074 "id" => array("integer", (int) $a_mob_id),
1075 "usage_type" => array("text", $a_type),
1076 "usage_id" => array("integer", $a_id),
1077 "usage_lang" => array("text", $a_lang),
1078 "usage_hist_nr" => array("integer", (int) $a_usage_hist_nr)
1079 ),
1080 array()
1081 );
1082
1083 self::handleQuotaUpdate(new self($a_mob_id));
1084 }
1085
1089 public static function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1090 {
1091 global $DIC;
1092
1093 $ilDB = $DIC->database();
1094
1095 $q = "DELETE FROM mob_usage WHERE " .
1096 " id = " . $ilDB->quote((int) $a_mob_id, "integer") . " AND " .
1097 " usage_type = " . $ilDB->quote($a_type, "text") . " AND " .
1098 " usage_id = " . $ilDB->quote((int) $a_id, "integer") . " AND " .
1099 " usage_lang = " . $ilDB->quote($a_lang, "text") . " AND " .
1100 " usage_hist_nr = " . $ilDB->quote((int) $a_usage_hist_nr, "integer");
1101 $ilDB->manipulate($q);
1102
1103 self::handleQuotaUpdate(new self($a_mob_id));
1104 }
1105
1109 public function getUsages($a_include_history = true)
1110 {
1111 return self::lookupUsages($this->getId(), $a_include_history);
1112 }
1113
1119 public static function lookupUsages($a_id, $a_include_history = true)
1120 {
1121 global $DIC;
1122
1123 $ilDB = $DIC->database();
1124
1125 $hist_str = "";
1126 if ($a_include_history) {
1127 $hist_str = ", usage_hist_nr";
1128 }
1129
1130 // get usages in pages
1131 $q = "SELECT DISTINCT usage_type, usage_id, usage_lang" . $hist_str . " FROM mob_usage WHERE id = " .
1132 $ilDB->quote($a_id, "integer");
1133
1134 if (!$a_include_history) {
1135 $q .= " AND usage_hist_nr = " . $ilDB->quote(0, "integer");
1136 }
1137
1138 $us_set = $ilDB->query($q);
1139 $ret = array();
1140 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
1141 $ut = "";
1142 if (is_int(strpos($us_rec["usage_type"], ":"))) {
1143 $us_arr = explode(":", $us_rec["usage_type"]);
1144 $ut = $us_arr[1];
1145 $ct = $us_arr[0];
1146 }
1147
1148 // check whether page exists
1149 $skip = false;
1150 if ($ut == "pg") {
1151 include_once("./Services/COPage/classes/class.ilPageObject.php");
1152 if (!ilPageObject::_exists($ct, $us_rec["usage_id"])) {
1153 $skip = true;
1154 }
1155 }
1156
1157 if (!$skip) {
1158 $ret[] = array("type" => $us_rec["usage_type"],
1159 "id" => $us_rec["usage_id"],
1160 "lang" => $us_rec["usage_lang"],
1161 "hist_nr" => $us_rec["usage_hist_nr"]);
1162 }
1163 }
1164
1165 // get usages in media pools
1166 $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = " .
1167 $ilDB->quote($a_id, "integer") . " AND mep_item.type = " . $ilDB->quote("mob", "text");
1168 $us_set = $ilDB->query($q);
1169 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
1170 $ret[] = array("type" => "mep",
1171 "id" => $us_rec["mep_id"]);
1172 }
1173
1174 // get usages in news items (media casts)
1175 include_once("./Services/News/classes/class.ilNewsItem.php");
1176 $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
1177 foreach ($news_usages as $nu) {
1178 $ret[] = $nu;
1179 }
1180
1181
1182 // get usages in map areas
1183 $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area " .
1184 " WHERE area.item_id = it.id " .
1185 " AND area.link_type = " . $ilDB->quote("int", "text") . " " .
1186 " AND area.target = " . $ilDB->quote("il__mob_" . $a_id, "text");
1187 $us_set = $ilDB->query($q);
1188 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
1189 $ret[] = array("type" => "map",
1190 "id" => $us_rec["mob_id"]);
1191 }
1192
1193 // get usages in personal clipboards
1194 $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
1195 foreach ($users as $user) {
1196 $ret[] = array("type" => "clip",
1197 "id" => $user);
1198 }
1199
1200 return $ret;
1201 }
1202
1208 public static function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
1209 {
1210 if (is_int(strpos($a_usage["type"], ":"))) {
1211 $us_arr = explode(":", $a_usage["type"]);
1212 $type = $us_arr[1];
1213 $cont_type = $us_arr[0];
1214 } else {
1215 $type = $a_usage["type"];
1216 }
1217
1218 $id = $a_usage["id"];
1219 $obj_id = false;
1220
1221 switch ($type) {
1222 // RTE / tiny mce
1223 case "html":
1224
1225 switch ($cont_type) {
1226 case "qpl":
1227 // Question Pool *Question* Text (Test)
1228 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1230 if ($qinfo["original_id"] > 0) {
1231 include_once("./Modules/Test/classes/class.ilObjTest.php");
1232 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1233 } else {
1234 $obj_id = $qinfo["obj_fi"]; // usage in pool
1235 }
1236 break;
1237
1238 case "spl":
1239 // Question Pool *Question* Text (Survey)
1241 if ($quest) {
1242 $parent_id = $quest->getObjId();
1243
1244 // pool question copy - find survey, do not use pool itself
1245 if ($quest->getOriginalId() &&
1246 ilObject::_lookupType($parent_id) == "spl") {
1248 }
1249 // original question (in pool or survey)
1250 else {
1251 $obj_id = $parent_id;
1252 }
1253
1254 unset($quest);
1255 }
1256 break;
1257
1258 case "exca":
1259 // Exercise assignment
1260 $returned_pk = $a_usage['id'];
1261 // #15995 - we are just checking against exercise object
1262 include_once 'Modules/Exercise/classes/class.ilExSubmission.php';
1263 $obj_id = ilExSubmission::lookupExerciseIdForReturnedId($returned_pk);
1264 break;
1265
1266 case "frm":
1267 // Forum
1268 $post_pk = $a_usage['id'];
1269 include_once 'Modules/Forum/classes/class.ilForumPost.php';
1270 include_once 'Modules/Forum/classes/class.ilForum.php';
1271 $oPost = new ilForumPost($post_pk);
1272 $frm_pk = $oPost->getForumId();
1273 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1274 break;
1275
1276
1277 case "frm~d":
1278 $draft_id = $a_usage['id'];
1279 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
1280 include_once 'Modules/Forum/classes/class.ilForum.php';
1281 $oDraft = ilForumPostDraft::newInstanceByDraftId($draft_id);
1282
1283 $frm_pk = $oDraft->getForumId();
1284 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1285 break;
1286 case "frm~h":
1287 $history_id = $a_usage['id'];
1288 include_once 'Modules/Forum/classes/class.ilForumDraftsHistory.php';
1289 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
1290 include_once 'Modules/Forum/classes/class.ilForum.php';
1291 $oHistoryDraft = new ilForumDraftsHistory($history_id);
1292 $oDraft = ilForumPostDraft::newInstanceByDraftId($oHistoryDraft->getDraftId());
1293
1294 $frm_pk = $oDraft->getForumId();
1295 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1296 break;
1297 // temporary items (per user)
1298 case "frm~":
1299 case "exca~":
1300 $obj_id = $a_usage['id'];
1301 break;
1302
1303 // "old" category pages
1304 case "cat":
1305 // InfoScreen Text
1306 case "tst":
1307 case "svy":
1308 // data collection
1309 case "dcl":
1310 $obj_id = $id;
1311 break;
1312 }
1313 break;
1314
1315 // page editor
1316 case "pg":
1317
1318 switch ($cont_type) {
1319 // question feedback // parent obj id is q id
1320 case "qfbg":
1321 include_once('./Services/COPage/classes/class.ilPageObject.php');
1323 // note: no break here, we only altered the $id to the question id
1324
1325 // no break
1326 case "qpl":
1327 // Question Pool Question Pages
1328 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1330 if ($qinfo["original_id"] > 0) {
1331 include_once("./Modules/Test/classes/class.ilObjTest.php");
1332 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1333 } else {
1334 $obj_id = $qinfo["obj_fi"]; // usage in pool
1335 }
1336 if ($obj_id == 0) { // this is the case, if question is in learning module -> get lm id
1337 include_once("./Services/COPage/classes/class.ilPCQuestion.php");
1339 if ($pinfo && $pinfo["parent_type"] == "lm") {
1340 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1341 $obj_id = ilLMObject::_lookupContObjID($pinfo["page_id"]);
1342 }
1343 $pinfo = ilPCQuestion::_getPageForQuestionId($id, "sahs");
1344 if ($pinfo && $pinfo["parent_type"] == "sahs") {
1345 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
1346 $obj_id = ilSCORM2004Node::_lookupSLMID($pinfo["page_id"]);
1347 }
1348 }
1349 break;
1350
1351 case "lm":
1352 // learning modules
1353 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1355 break;
1356
1357 case "gdf":
1358 // glossary definition
1360 $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1361 break;
1362
1363 case "wpg":
1364 // wiki page
1365 include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
1367 break;
1368
1369 case "sahs":
1370 // sahs page
1371 // can this implementation be used for other content types, too?
1372 include_once('./Services/COPage/classes/class.ilPageObject.php');
1373 $obj_id = ilPageObject::lookupParentId($id, 'sahs');
1374 break;
1375
1376 case "prtf":
1377 // portfolio
1378 include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
1380 break;
1381
1382 case "prtt":
1383 // portfolio template
1384 include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
1386 break;
1387
1388 case "blp":
1389 // blog
1390 include_once('./Services/COPage/classes/class.ilPageObject.php');
1391 $obj_id = ilPageObject::lookupParentId($id, 'blp');
1392 break;
1393
1394 case "impr":
1395 // imprint page - always id 1
1396 // fallthrough
1397
1398 case "crs":
1399 case "grp":
1400 case "cat":
1401 case "fold":
1402 case "root":
1403 case "cont":
1404 case "copa":
1405 case "cstr":
1406 // repository pages
1407 $obj_id = $id;
1408 break;
1409 }
1410 break;
1411
1412 // Media Pool
1413 case "mep":
1414 $obj_id = $id;
1415 break;
1416
1417 // News Context Object (e.g. MediaCast)
1418 case "news":
1419 include_once("./Services/News/classes/class.ilNewsItem.php");
1421 break;
1422 }
1423
1424 return $obj_id;
1425 }
1426
1434 public static function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1435 {
1436 $file_path = pathinfo($a_file);
1437 $location = substr($file_path["basename"], 0, strlen($file_path["basename"]) -
1438 strlen($file_path["extension"]) - 1) . "_" .
1439 $a_width . "_" .
1440 $a_height . "." . $file_path["extension"];
1441 $target_file = $file_path["dirname"] . "/" .
1442 $location;
1444 $a_file,
1445 $target_file,
1446 (int) $a_width,
1447 (int) $a_height,
1448 $a_constrain_prop
1449 );
1450
1451 return $location;
1452 }
1453
1461 public static function getMimeType($a_file, $a_external = null)
1462 {
1463 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1465 return $mime;
1466 }
1467
1471 public static function _determineWidthHeight(
1472 $a_format,
1473 $a_type,
1474 $a_file,
1475 $a_reference,
1476 $a_constrain_proportions,
1477 $a_use_original,
1478 $a_user_width,
1479 $a_user_height
1480 ) {
1481 global $DIC;
1482
1483 $lng = $DIC->language();
1484
1485 // determine width and height of known image types
1486 //$width = 640;
1487 //$height = 360;
1488 $info = "";
1489
1490 if ($a_format == "audio/mpeg") {
1491 $width = 300;
1492 $height = 20;
1493 }
1494 if (ilUtil::deducibleSize($a_format)) {
1495 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1496 if ($a_type == "File") {
1498 } else {
1499 $size = ilMediaImageUtil::getImageSize($a_reference);
1500 }
1501 }
1502
1503 if ($a_use_original) {
1504 if ($size[0] > 0 && $size[1] > 0) {
1505 //$width = $size[0];
1506 //$height = $size[1];
1507 $width = "";
1508 $height = "";
1509 } else {
1510 $info = $lng->txt("cont_could_not_determine_resource_size");
1511 }
1512 } else {
1513 $w = (int) $a_user_width;
1514 $h = (int) $a_user_height;
1515 $width = $w;
1516 $height = $h;
1517 //echo "<br>C-$width-$height-";
1518 if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions) {
1519 if ($size[0] > 0 && $size[1] > 0) {
1520 if ($w > 0) {
1521 $wr = $size[0] / $w;
1522 }
1523 if ($h > 0) {
1524 $hr = $size[1] / $h;
1525 }
1526 //echo "<br>+".$wr."+".$size[0]."+".$w."+";
1527 //echo "<br>+".$hr."+".$size[1]."+".$h."+";
1528 $r = max($wr, $hr);
1529 if ($r > 0) {
1530 $width = (int) round($size[0] / $r);
1531 $height = (int) round($size[1] / $r);
1532 }
1533 }
1534 }
1535 //echo "<br>D-$width-$height-";
1536 }
1537 //echo "<br>E-$width-$height-";
1538
1539 if ($width == 0 && $a_user_width === "") {
1540 $width = "";
1541 }
1542 if ($height == 0 && $a_user_height === "") {
1543 $height = "";
1544 }
1545 return array("width" => $width, "height" => $height, "info" => $info);
1546 }
1547
1548 public function getDataDirectory()
1549 {
1550 return ilUtil::getWebspaceDir() . "/mobs/mm_" . $this->getId();
1551 }
1552
1556 public static function _saveTempFileAsMediaObject($name, $tmp_name, $upload = true)
1557 {
1558 // create dummy object in db (we need an id)
1559 $media_object = new ilObjMediaObject();
1560 $media_object->setTitle($name);
1561 $media_object->setDescription("");
1562 $media_object->create();
1563
1564 // determine and create mob directory, move uploaded file to directory
1565 $media_object->createDirectory();
1566 $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1567
1568 $media_item = new ilMediaItem();
1569 $media_object->addMediaItem($media_item);
1570 $media_item->setPurpose("Standard");
1571
1572 $file = $mob_dir . "/" . $name;
1573 if ($upload) {
1574 ilUtil::moveUploadedFile($tmp_name, $name, $file);
1575 } else {
1576 copy($tmp_name, $file);
1577 }
1578 // get mime type
1580 $location = $name;
1581 // set real meta and object data
1582 $media_item->setFormat($format);
1583 $media_item->setLocation($location);
1584 $media_item->setLocationType("LocalFile");
1585 $media_object->setTitle($name);
1586 $media_object->setDescription($format);
1587
1589 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1591 $media_item->setWidth($size[0]);
1592 $media_item->setHeight($size[1]);
1593 }
1594 $media_item->setHAlign("Left");
1595
1596 self::renameExecutables($mob_dir);
1597 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1598 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1599
1600 $media_object->update();
1601
1602 return $media_object;
1603 }
1604
1608 public function uploadAdditionalFile($a_name, $tmp_name, $a_subdir = "", $a_mode = "move_uploaded")
1609 {
1610 $a_subdir = str_replace("..", "", $a_subdir);
1611 $dir = $mob_dir = ilObjMediaObject::_getDirectory($this->getId());
1612 if ($a_subdir != "") {
1613 $dir .= "/" . $a_subdir;
1614 }
1616 if ($a_mode == "rename") {
1617 rename($tmp_name, $dir . "/" . $a_name);
1618 } else {
1619 ilUtil::moveUploadedFile($tmp_name, $a_name, $dir . "/" . $a_name, true, $a_mode);
1620 }
1621 self::renameExecutables($mob_dir);
1622 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1623 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1624 }
1625
1632 public function uploadSrtFile($a_tmp_name, $a_language, $a_mode = "move_uploaded")
1633 {
1634 if (is_file($a_tmp_name) && $a_language != "") {
1635 $this->uploadAdditionalFile("subtitle_" . $a_language . ".srt", $a_tmp_name, "srt", $a_mode);
1636 return true;
1637 }
1638 return false;
1639 }
1640
1644 public function getSrtFiles()
1645 {
1646 $srt_dir = ilObjMediaObject::_getDirectory($this->getId()) . "/srt";
1647
1648 if (!is_dir($srt_dir)) {
1649 return array();
1650 }
1651
1652 $items = ilUtil::getDir($srt_dir);
1653
1654 $srt_files = array();
1655 foreach ($items as $i) {
1656 if (!in_array($i["entry"], array(".", "..")) && $i["type"] == "file") {
1657 $name = explode(".", $i["entry"]);
1658 if ($name[1] == "srt" && substr($name[0], 0, 9) == "subtitle_") {
1659 $srt_files[] = array("file" => $i["entry"],
1660 "full_path" => "srt/" . $i["entry"], "language" => substr($name[0], 9, 2));
1661 }
1662 }
1663 }
1664
1665 return $srt_files;
1666 }
1667
1671 public function makeThumbnail(
1672 $a_file,
1673 $a_thumbname,
1674 $a_format = "png",
1675 $a_size = "80"
1676 ) {
1677 $size = (int) $a_size;
1678 $m_dir = ilObjMediaObject::_getDirectory($this->getId());
1680 $file = $m_dir . "/" . $a_file;
1681
1682 $mime = ilObjMediaObject::getMimeType($file);
1683 $wh = ilMediaImageUtil::getImageSize($file);
1684
1685 // see #8602
1686 if ($size > (int) $wh[0] && $size > $wh[1]) {
1687 $a_size = "";
1688 }
1689
1690 $m_dir = ilObjMediaObject::_getDirectory($this->getId());
1694 $m_dir . "/" . $a_file,
1695 $t_dir . "/" . $a_thumbname,
1696 $a_format,
1697 $a_size
1698 );
1699 }
1700
1707 public static function getThumbnailPath($a_mob_id, $a_thumbname)
1708 {
1709 $t_dir = ilObjMediaObject::_getThumbnailDirectory($a_mob_id);
1710 return $t_dir . "/" . $a_thumbname;
1711 }
1712
1713
1717 public function removeAdditionalFile($a_file)
1718 {
1719 $file = str_replace("..", "", $a_file);
1720 $file = ilObjMediaObject::_getDirectory($this->getId()) . "/" . $file;
1721 if (is_file($file)) {
1722 unlink($file);
1723 }
1724 }
1725
1726
1730 public function getLinkedMediaObjects($a_ignore = "")
1731 {
1732 $linked = array();
1733
1734 if (!is_array($a_ignore)) {
1735 $a_ignore = array();
1736 }
1737
1738 // get linked media objects (map areas)
1739 $med_items = $this->getMediaItems();
1740
1741 foreach ($med_items as $med_item) {
1742 $int_links = ilMapArea::_getIntLinks($med_item->getId());
1743 foreach ($int_links as $k => $int_link) {
1744 if ($int_link["Type"] == "MediaObject") {
1745 include_once("./Services/Link/classes/class.ilInternalLink.php");
1746 $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1747 if (ilObject::_exists($l_id)) {
1748 if (!in_array($l_id, $linked) &&
1749 !in_array($l_id, $a_ignore)) {
1750 $linked[] = $l_id;
1751 }
1752 }
1753 }
1754 }
1755 }
1756 //var_dump($linked);
1757 return $linked;
1758 }
1759
1763 public static function getRestrictedFileTypes()
1764 {
1765 return array_filter(self::getAllowedFileTypes(), function ($v) {
1766 return !in_array($v, self::getForbiddenFileTypes());
1767 });
1768 }
1769
1775 public static function getForbiddenFileTypes()
1776 {
1777 $mset = new ilSetting("mobs");
1778 if (trim($mset->get("black_list_file_types")) == "") {
1779 return array();
1780 }
1781 return array_map(
1782 function ($v) {
1783 return strtolower(trim($v));
1784 },
1785 explode(",", $mset->get("black_list_file_types"))
1786 );
1787 }
1788
1794 public static function getAllowedFileTypes()
1795 {
1796 $mset = new ilSetting("mobs");
1797 if (trim($mset->get("restricted_file_types")) == "") {
1798 return array();
1799 }
1800 return array_map(
1801 function ($v) {
1802 return strtolower(trim($v));
1803 },
1804 explode(",", $mset->get("restricted_file_types"))
1805 );
1806 }
1807
1814 public static function isTypeAllowed($a_type)
1815 {
1816 if (in_array($a_type, self::getForbiddenFileTypes())) {
1817 return false;
1818 }
1819 if (count(self::getAllowedFileTypes()) == 0 || in_array($a_type, self::getAllowedFileTypes())) {
1820 return true;
1821 }
1822 return false;
1823 }
1824
1825
1829 public function duplicate()
1830 {
1831 $new_obj = new ilObjMediaObject();
1832 $new_obj->setTitle($this->getTitle());
1833 $new_obj->setDescription($this->getDescription());
1834
1835 // media items
1836 foreach ($this->getMediaItems() as $key => $val) {
1837 $new_obj->addMediaItem($val);
1838 }
1839
1840 $new_obj->create(false, true);
1841
1842 // files
1843 $new_obj->createDirectory();
1844 self::_createThumbnailDirectory($new_obj->getId());
1847 ilObjMediaObject::_getDirectory($new_obj->getId())
1848 );
1852 );
1853
1854 // meta data
1855 include_once("Services/MetaData/classes/class.ilMD.php");
1856 $md = new ilMD(0, $this->getId(), "mob");
1857 $new_md = $md->cloneMD(0, $new_obj->getId(), "mob");
1858
1859 return $new_obj;
1860 }
1861
1868 public function uploadVideoPreviewPic($a_prevpic)
1869 {
1870 // remove old one
1871 if ($this->getVideoPreviewPic(true) != "") {
1872 $this->removeAdditionalFile($this->getVideoPreviewPic(true));
1873 }
1874
1875 $pi = pathinfo($a_prevpic["name"]);
1876 $ext = $pi["extension"];
1877 if (in_array($ext, array("jpg", "jpeg", "png"))) {
1878 $this->uploadAdditionalFile("mob_vpreview." . $ext, $a_prevpic["tmp_name"]);
1879 }
1880 }
1881
1888 public function generatePreviewPic($a_width, $a_height, $sec = 1)
1889 {
1890 $item = $this->getMediaItem("Standard");
1891 if ($item->getFormat() === "image/svg+xml") {
1892 return;
1893 }
1894
1895 if ($item->getLocationType() == "LocalFile") {
1896 if (is_int(strpos($item->getFormat(), "image/"))) {
1897 $dir = ilObjMediaObject::_getDirectory($this->getId());
1898 $file = $dir . "/" .
1899 $item->getLocation();
1900 if (is_file($file)) {
1901 if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
1904 $file
1905 ) . "[0] -geometry " . $a_width . "x" . $a_height . "^ -gravity center -extent " . $a_width . "x" . $a_height . " PNG:" . $dir . "/mob_vpreview.png"
1906 );
1907 } else {
1908 ilUtil::convertImage($file, $dir . "/mob_vpreview.png", "PNG", $a_width . "x" . $a_height);
1909 }
1910 }
1911 }
1912
1913 if (is_int(strpos($item->getFormat(), "video/"))) {
1914 try {
1915 if ($sec < 0) {
1916 $sec = 0;
1917 }
1918 if ($this->getVideoPreviewPic() != "") {
1919 $this->removeAdditionalFile($this->getVideoPreviewPic(true));
1920 }
1921 include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1922 $med = $this->getMediaItem("Standard");
1923 $mob_file = ilObjMediaObject::_getDirectory($this->getId()) . "/" . $med->getLocation();
1925 $mob_file,
1926 "mob_vpreview.png",
1928 $sec
1929 );
1930 } catch (ilException $e) {
1932
1933 $message = '';
1934 if (is_array($ret) && count($ret) > 0) {
1935 $message = "\n" . implode("\n", $ret);
1936 }
1937
1939 $logger = $GLOBALS['DIC']->logger()->mob();
1940 $logger->warning($e->getMessage() . $message);
1941 $logger->logStack(ilLogLevel::WARNING);
1942 }
1943 }
1944 }
1945 }
1946
1953 public function getVideoPreviewPic($a_filename_only = false)
1954 {
1955 $dir = ilObjMediaObject::_getDirectory($this->getId());
1956 $ppics = array("mob_vpreview.jpg",
1957 "mob_vpreview.jpeg",
1958 "mob_vpreview.png");
1959 foreach ($ppics as $p) {
1960 if (is_file($dir . "/" . $p)) {
1961 if ($a_filename_only) {
1962 return $p;
1963 } else {
1964 return $dir . "/" . $p;
1965 }
1966 }
1967 }
1968 return "";
1969 }
1970
1977 public static function fixFilename($a_name)
1978 {
1979 $a_name = ilUtil::getASCIIFilename($a_name);
1980
1981 $rchars = array("`", "=", "$", "{", "}", "'", ";", " ", "(", ")");
1982 $a_name = str_replace($rchars, "_", $a_name);
1983 $a_name = str_replace("__", "_", $a_name);
1984 return $a_name;
1985 }
1986
1987
1994 public function getMultiSrtUploadDir()
1995 {
1996 return ilObjMediaObject::_getDirectory($this->getId() . "/srt/tmp");
1997 }
1998
1999
2006 public function uploadMultipleSubtitleFile($a_file)
2007 {
2008 $lng = $this->lng;
2010
2011 include_once("./Services/MediaObjects/exceptions/class.ilMediaObjectsException.php");
2012 if (!is_file($a_file["tmp_name"])) {
2013 throw new ilMediaObjectsException($lng->txt("mob_file_could_not_be_uploaded"));
2014 }
2015
2016 $dir = $this->getMultiSrtUploadDir();
2017 ilUtil::delDir($dir, true);
2019 ilUtil::moveUploadedFile($a_file["tmp_name"], "multi_srt.zip", $dir . "/" . "multi_srt.zip");
2020 ilUtil::unzip($dir . "/multi_srt.zip", true);
2021 }
2022
2026 public function clearMultiSrtDirectory()
2027 {
2029 }
2030
2034 public function getMultiSrtFiles()
2035 {
2036 $items = array();
2037
2038 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
2040
2041 $dir = $this->getMultiSrtUploadDir();
2042 $files = ilUtil::getDir($dir);
2043 foreach ($files as $k => $i) {
2044 // check directory
2045 if ($i["type"] == "file" && !in_array($k, array(".", ".."))) {
2046 if (pathinfo($k, PATHINFO_EXTENSION) == "srt") {
2047 $lang = "";
2048 if (substr($k, strlen($k) - 7, 1) == "_") {
2049 $lang = substr($k, strlen($k) - 6, 2);
2050 if (!in_array($lang, $lang_codes)) {
2051 $lang = "";
2052 }
2053 }
2054 $items[] = array("filename" => $k, "lang" => $lang);
2055 }
2056 }
2057 }
2058 return $items;
2059 }
2060
2066 public static function renameExecutables($a_dir)
2067 {
2069 if (!self::isTypeAllowed("html")) {
2070 ilUtil::rRenameSuffix($a_dir, "html", "sec"); // see #20187
2071 }
2072 }
2073}
user()
Definition: user.php:4
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$size
Definition: RandomTest.php:84
$location
Definition: buildRTE.php:44
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static _lookupSurveyObjId($a_question_id)
const IL_MODE_ALIAS
const IL_MODE_OUTPUT
const IL_MODE_FULL
static _getQuestionInfo($question_id)
Returns question information from the database.
static lookupExerciseIdForReturnedId($a_returned_id)
Get exercise from submission id (used in ilObjMediaObject)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLastReturnValues()
Get last return values.
static extractImage( $a_file, $a_target_filename, $a_target_dir="", $a_sec=1)
Extract image from video file.
Class ilForumDraftHistory.
static newInstanceByDraftId($draft_id)
static _lookupObjIdForForumId($a_for_id)
special template class to simplify handling of ITX/PEAR
static _lookupTermId($a_def_id)
Looks up term id for a definition id.
static _lookGlossaryID($term_id)
get glossary id form term id
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static getLogger($a_component_id)
Get component logger.
static _getIntLinks($a_item_id)
get all internal links of a media items map areas
static getImageSize($a_location)
Get image size from location.
Class ilMediaItem Media Item, component of a media object (file or reference)
static deleteAllItemsOfMob($a_mob_id)
Delete all items of a mob.
static _getMediaItemsOfMOb(&$a_mob)
read media items into media objects (static)
static _getMapAreasIntLinks($a_mob_id)
get all internal links of map areas of a mob
static _lookupLocationForMobId($a_mob_id, $a_purpose)
Lookup location for mob id.
General exception class for media objects.
static sanitizeDir($a_path)
Sanitize directory recursively.
static lookupMimeType($path_to_file, $fallback=self::APPLICATION__OCTET_STREAM, $a_external=null)
static _lookupContextObjId($a_news_id)
Context Object ID.
static _lookupMediaObjectUsages($a_mob_id)
Lookup media object usage(s)
Class ilObjMediaObject.
MDUpdateListener($a_element)
Meta data update listener.
update($a_upload=false)
update media object in db
getXML($a_mode=IL_MODE_FULL, $a_inst=0, $a_sign_locals=false)
get MediaObject XLM Tag
getMultiSrtFiles()
Get all srt files of srt multi upload.
exportMediaFullscreen($a_target_dir, $pg_obj)
uploadVideoPreviewPic($a_prevpic)
Upload video preview picture.
setTitle($a_title)
set object title
static _getThumbnailDirectory($a_mob_id, $a_mode="filesystem")
get directory for files of media object (static)
static isTypeAllowed($a_type)
Is type allowed.
static getThumbnailPath($a_mob_id, $a_thumbname)
Get thumbnail path.
getTitle()
get object title @access public
static _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
static
exportFiles($a_target_dir)
export all media files of object to target directory note: target directory must be the export target...
addMediaItem($a_item)
add media item to media object
getMultiSrtUploadDir()
Get directory for multi srt upload.
static getMimeType($a_file, $a_external=null)
get mime type for file
getRefId()
get reference id @access public
static getAllowedFileTypes()
Get allowed file types.
static handleQuotaUpdate(ilObjMediaObject $a_mob)
static _lookupItemPath( $a_mob_id, $a_url_encode=false, $a_web=true, $a_purpose="")
Get path for item with specific purpose.
uploadAdditionalFile($a_name, $tmp_name, $a_subdir="", $a_mode="move_uploaded")
Create new media object and update page in db and return new media object.
containsIntLink()
returns true, if mob was marked as containing an intern link (via setContainsIntLink) (this method sh...
uploadMultipleSubtitleFile($a_file)
Upload multi srt file.
static getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids=false)
Get's the repository object ID of a parent object, if possible.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
makeThumbnail( $a_file, $a_thumbname, $a_format="png", $a_size="80")
Make thumbnail.
setRefId($a_id)
set reference id @access public
static getRestrictedFileTypes()
Get restricted file types (this is for the input form, this list will be empty, if "allowed list" is ...
setImportId($a_id)
set import id
updateMetaData()
update meta data entry
deleteMetaData()
delete meta data entry
escapeProperty($a_value)
Escape property (e.g.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _getDirectory($a_mob_id)
Get absolute directory.
clearMultiSrtDirectory()
Clear multi feedback directory.
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
setAlias($a_is_alias)
set wether page object is an alias
& getMediaItems()
get all media items
createReference()
creates reference for object
read()
read media object data from db
handleAmps($a_str)
Replace "&" (if not an "&") with "&".
static _lookupStandardItemPath( $a_mob_id, $a_url_encode=false, $a_web=true)
Get path for standard item.
duplicate()
Duplicate media object, return new media object.
static fixFilename($a_name)
Fix filename of uploaded file.
getVideoPreviewPic($a_filename_only=false)
Get video preview pic.
removeAllMediaItems()
remove all media items
create($a_create_meta_data=false, $a_save_media_items=true)
create media object in db
createDirectory()
Create file directory of media object.
getLinkedMediaObjects($a_ignore="")
Get all media objects linked in map areas of this media object.
static _createThumbnailDirectory($a_obj_id)
Create thumbnail directory.
uploadSrtFile($a_tmp_name, $a_language, $a_mode="move_uploaded")
Upload srt file.
static _getURL($a_mob_id)
get directory for files of media object (static)
createMetaData()
create meta data entry
modifyExportIdentifier($a_tag, $a_param, $a_value)
static _getRelativeDirectory($a_mob_id)
Get relative (to webspace dir) directory.
static _determineWidthHeight( $a_format, $a_type, $a_file, $a_reference, $a_constrain_proportions, $a_use_original, $a_user_width, $a_user_height)
Determine width and height.
setContainsIntLink($a_contains_link)
content parser set this flag to true, if the media object contains internal links (this method should...
getUsages($a_include_history=true)
get all usages of current media object
getFilesOfDirectory($a_subdir="")
Get files of directory.
removeAdditionalFile($a_file)
Remove additional file.
exportXML(&$a_xml_writer, $a_inst=0)
export XML
static _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop=false)
resize image and return new image file ("_width_height" string appended)
hasPurposeItem($purpose)
returns wether object has media item with specific purpose
static getForbiddenFileTypes()
Get forbidden file types.
__construct($a_id=0)
Constructor @access public.
getMediaItem($a_purpose)
get item for media purpose
putInTree($a_parent_ref)
maybe this method should be in tree object!?
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
setDescription($a_description)
set description of media object
static lookupUsages($a_id, $a_include_history=true)
Lookup usages of media object.
static renameExecutables($a_dir)
Rename executables.
getDescription()
get description of media object
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
static _lookupTestObjIdForQuestionId($a_q_id)
Get test Object ID for question ID.
static _getUsersForClipboadObject($a_type, $a_id)
get all users, that have a certain object within their clipboard
Class ilObject Basic functions for all objects.
getType()
get object type @access public
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
getId()
get object id @access public
static _writeTitle($a_obj_id, $a_title)
write title to db (static)
static _lookupType($a_id, $a_reference=false)
lookup object type
static _writeDescription($a_obj_id, $a_desc)
write description to db (static)
static _getPageForQuestionId($a_q_id, $a_parent_type="")
Get page for question id.
static lookupParentId($a_id, $a_type)
Lookup parent id.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
static getFlashVideoPlayerDirectory()
Get flash video player directory.
static findPortfolioForPage($a_page_id)
Get portfolio id of page id.
static _lookupSLMID($a_id)
Lookup Scorm Learning Module ID for node id.
ILIAS Setting Class.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static isConvertVersionAtLeast($a_version)
Compare convert version numbers.
static insertInstIntoID($a_value)
inserts installation id into ILIAS id
static escapeShellArg($a_arg)
static getWebspaceDir($mode="filesystem")
get webspace directory
static execConvert($args)
execute convert command
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static resizeImage($a_from, $a_to, $a_width, $a_height, $a_constrain_prop=false)
resize image
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static rRenameSuffix(string $a_dir, string $a_old_suffix, string $a_new_suffix)
Renames all files with certain suffix and gives them a new suffix.
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static getHtmlPath($relative_path)
get url of path
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static deducibleSize($a_mime)
checks if mime type is provided by getimagesize()
static secureUrl($url)
Prepare secure href attribute.
static createDirectory($a_dir, $a_mod=0755)
create directory
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
static signFile($path_to_file)
static lookupObjIdByPage($a_page_id)
returns the wiki/object id to a given page id
const CLIENT_ID
Definition: constants.php:39
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
$mobs
Definition: imgupload.php:54
$ilUser
Definition: imgupload.php:18
xslt_free(&$proc)
xslt_create()
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
if($format !==null) $name
Definition: metadata.php:230
$format
Definition: metadata.php:218
$i
Definition: metadata.php:24
$xml
Definition: metadata.php:332
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)
$ret
Definition: parser.php:6
global $ilDB
$lang
Definition: xapiexit.php:8
$message
Definition: xapiexit.php:14