ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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;
40 public $id;
43
48 public function __construct($a_id = 0)
49 {
50 global $DIC;
51
52 $this->user = $DIC->user();
53 $this->app_event_handler = $DIC["ilAppEventHandler"];
54 $this->lng = $DIC->language();
55 $this->is_alias = false;
56 $this->media_items = array();
57 $this->contains_int_link = false;
58 $this->type = "mob";
59 parent::__construct($a_id, false);
60 }
61
62 public function setRefId($a_id)
63 {
64 $this->ilias->raiseError("Operation ilObjMedia::setRefId() not allowed.", $this->ilias->error_obj->FATAL);
65 }
66
67 public function getRefId()
68 {
69 return false;
70 }
71
72 public function putInTree($a_parent_ref)
73 {
74 $this->ilias->raiseError("Operation ilObjMedia::putInTree() not allowed.", $this->ilias->error_obj->FATAL);
75 }
76
77 public function createReference()
78 {
79 $this->ilias->raiseError("Operation ilObjMedia::createReference() not allowed.", $this->ilias->error_obj->FATAL);
80 }
81
82 public function setTitle($a_title)
83 {
84 parent::setTitle($a_title);
85 }
86
87 public function getTitle()
88 {
89 return parent::getTitle();
90 }
91
99 public static function _exists($a_id, $a_reference = false, $a_type = null)
100 {
101 global $DIC;
102
103 $ilDB = $DIC->database();
104
105 include_once("./Services/Link/classes/class.ilInternalLink.php");
106 if (is_int(strpos($a_id, "_"))) {
108 }
109
110 if (parent::_exists($a_id, false) && ilObject::_lookupType($a_id) == "mob") {
111 return true;
112 }
113 return false;
114 }
115
119 public function delete()
120 {
121 $mob_logger = ilLoggerFactory::getLogger('mob');
122 $mob_logger->debug("ilObjMediaObject: Delete called for media object ID '" . $this->getId() . "'.");
123
124 if (!($this->getId() > 0)) {
125 return;
126 }
127
128 $usages = $this->getUsages();
129
130 $mob_logger->debug("ilObjMediaObject: ... Found " . count($usages) . " usages.");
131
132 if (count($usages) == 0) {
133 // remove directory
135
136 // remove thumbnail directory
138
139 // delete meta data of mob
140 $this->deleteMetaData();
141
142 // delete media items
144
145 // this is just to make sure, there should be no entries left at
146 // this point as they depend on the usage
148
149 // delete object
150 parent::delete();
151
152 $mob_logger->debug("ilObjMediaObject: ... deleted.");
153 } else {
154 foreach ($usages as $u) {
155 $mob_logger->debug("ilObjMediaObject: ... usage type:" . $u["type"] .
156 ", id:" . $u["id"] .
157 ", lang:" . $u["lang"] .
158 ", hist_nr:" . $u["hist_nr"] . ".");
159 }
160 $mob_logger->debug("ilObjMediaObject: ... not deleted.");
161 }
162 }
163
169 public function getDescription()
170 {
171 return parent::getDescription();
172 }
173
177 public function setDescription($a_description)
178 {
179 parent::setDescription($a_description);
180 }
181
193 public function MDUpdateListener($a_element)
194 {
195 include_once 'Services/MetaData/classes/class.ilMD.php';
196
197 switch ($a_element) {
198 case 'General':
199
200 // Update Title and description
201 $md = new ilMD(0, $this->getId(), $this->getType());
202 $md_gen = $md->getGeneral();
203
204 if (is_object($md_gen)) {
205 ilObject::_writeTitle($this->getId(), $md_gen->getTitle());
206 $this->setTitle($md_gen->getTitle());
207
208 foreach ($md_gen->getDescriptionIds() as $id) {
209 $md_des = $md_gen->getDescription($id);
210 ilObject::_writeDescription($this->getId(), $md_des->getDescription());
211 $this->setDescription($md_des->getDescription());
212 break;
213 }
214 }
215
216 break;
217
218 default:
219 }
220 return true;
221 }
222
226 public function createMetaData()
227 {
228 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
229
231
232 $md_creator = new ilMDCreator(0, $this->getId(), $this->getType());
233 $md_creator->setTitle($this->getTitle());
234 $md_creator->setTitleLanguage($ilUser->getPref('language'));
235 $md_creator->setDescription($this->getDescription());
236 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
237 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
238 $md_creator->setLanguage($ilUser->getPref('language'));
239 $md_creator->create();
240
241 return true;
242 }
243
247 public function updateMetaData()
248 {
249 include_once("Services/MetaData/classes/class.ilMD.php");
250 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
251 include_once("Services/MetaData/classes/class.ilMDDescription.php");
252
253 $md = new ilMD(0, $this->getId(), $this->getType());
254 $md_gen = $md->getGeneral();
255 $md_gen->setTitle($this->getTitle());
256
257 // sets first description (maybe not appropriate)
258 $md_des_ids = $md_gen->getDescriptionIds();
259 if (count($md_des_ids) > 0) {
260 $md_des = $md_gen->getDescription($md_des_ids[0]);
261 $md_des->setDescription($this->getDescription());
262 $md_des->update();
263 }
264 $md_gen->update();
265 }
266
270 public function deleteMetaData()
271 {
272 // Delete meta data
273 include_once('Services/MetaData/classes/class.ilMD.php');
274 $md = new ilMD(0, $this->getId(), $this->getType());
275 $md->deleteAll();
276 }
277
278
284 public function addMediaItem($a_item)
285 {
286 $this->media_items[] = $a_item;
287 }
288
289
295 public function &getMediaItems()
296 {
297 return $this->media_items;
298 }
299
306 public function &getMediaItem($a_purpose)
307 {
308 foreach ($this->media_items as $media_item) {
309 if ($media_item->getPurpose() == $a_purpose) {
310 return $media_item;
311 }
312 }
313 return false;
314 }
315
316
320 public function removeMediaItem($a_purpose)
321 {
322 foreach ($this->media_items as $key => $media_item) {
323 if ($media_item->getPurpose() == $a_purpose) {
324 unset($this->media_items[$key]);
325 }
326 }
327 // update numbers and keys
328 $i = 1;
329 $media_items = array();
330 foreach ($this->media_items as $media_item) {
331 $media_items [$i] = $media_item;
332 $media_item->setMobId($this->getId());
333 $media_item->setNr($i);
334 $i++;
335 }
336 $this->media_items = $media_items;
337 }
338
342 public function removeAllMediaItems()
343 {
344 $this->media_items = array();
345 }
346
347
348 public function getMediaItemNr($a_purpose)
349 {
350 for ($i=0; $i<count($this->media_items); $i++) {
351 if ($this->media_items[$i]->getPurpose() == $a_purpose) {
352 return $i + 1;
353 }
354 }
355 return false;
356 }
357
358
359 public function hasFullscreenItem()
360 {
361 return $this->hasPurposeItem("Fullscreen");
362 }
363
370 public function hasPurposeItem($purpose)
371 {
372 if (is_object($this->getMediaItem($purpose))) {
373 return true;
374 } else {
375 return false;
376 }
377 }
378
379
380
384 public function read()
385 {
386 //echo "<br>ilObjMediaObject:read";
387 parent::read();
388
389 // get media items
391 }
392
396 public function setId($a_id)
397 {
398 $this->id = $a_id;
399 }
400
401 public function getId()
402 {
403 return $this->id;
404 }
405
409 public function setAlias($a_is_alias)
410 {
411 $this->is_alias = $a_is_alias;
412 }
413
414 public function isAlias()
415 {
416 return $this->is_alias;
417 }
418
419 public function setOriginID($a_id)
420 {
421 return $this->origin_id = $a_id;
422 }
423
424 public function getOriginID()
425 {
426 return $this->origin_id;
427 }
428
429 /*
430 function getimportId()
431 {
432 return $this->meta_data->getImportIdentifierEntryID();
433 }*/
434
435
439 public function getImportId()
440 {
441 return $this->import_id;
442 }
443
444 public function setImportId($a_id)
445 {
446 $this->import_id = $a_id;
447 }
448
452 public function create($a_create_meta_data = false, $a_save_media_items = true)
453 {
454 parent::create();
455
456 if (!$a_create_meta_data) {
457 $this->createMetaData();
458 }
459
460 if ($a_save_media_items) {
461 $media_items = $this->getMediaItems();
462 for ($i=0; $i<count($media_items); $i++) {
463 $item = $media_items[$i];
464 $item->setMobId($this->getId());
465 $item->setNr($i+1);
466 $item->create();
467 }
468 }
469
471
472 $ilAppEventHandler = $this->app_event_handler;
473 $ilAppEventHandler->raise(
474 'Services/MediaObjects',
475 'create',
476 array('object' => $this,
477 'obj_type' => 'mob',
478 'obj_id' => $this->getId())
479 );
480 }
481
482
486 public function update($a_upload=false)
487 {
489
490 if (!$a_upload) {
491 $this->updateMetaData();
492 }
493
495
496 // iterate all items
497 $media_items = $this->getMediaItems();
498 $j = 1;
499 foreach ($media_items as $key => $val) {
500 $item = $media_items[$key];
501 if (is_object($item)) {
502 $item->setMobId($this->getId());
503 $item->setNr($j);
504 if ($item->getLocationType() == "Reference") {
505 $item->extractUrlParameters();
506 }
507 $item->create();
508 $j++;
509 }
510 }
511
513 $ilAppEventHandler = $this->app_event_handler;
514 $ilAppEventHandler->raise(
515 'Services/MediaObjects',
516 'update',
517 array('object' => $this,
518 'obj_type' => 'mob',
519 'obj_id' => $this->getId())
520 );
521 }
522
523 protected static function handleQuotaUpdate(ilObjMediaObject $a_mob)
524 {
525 global $DIC;
526
527 $ilSetting = $DIC->settings();
528
529 // if neither workspace nor portfolios are activated, we skip
530 // the quota update here. this due to performance reasons on installations
531 // that do not use workspace/portfolios, but heavily copy content.
532 // in extreme cases (media object in pool and personal blog, deactivate workspace, change media object,
533 // this may lead to incorrect data in the quota calculation)
534 if ($ilSetting->get("disable_personal_workspace") && !$ilSetting->get('user_portfolios')) {
535 return;
536 }
537
538 $parent_obj_ids = array();
539 foreach ($a_mob->getUsages() as $item) {
540 $parent_obj_id = $a_mob->getParentObjectIdForUsage($item);
541 if ($parent_obj_id &&
542 !in_array($parent_obj_id, $parent_obj_ids)) {
543 $parent_obj_ids[]= $parent_obj_id;
544 }
545 }
546
547 // we could suppress this if object is present in a (repository) media pool
548 // but this would lead to "quota-breaches" when the pool item is deleted
549 // and "suddenly" all workspace owners get filesize added to their
550 // respective quotas, regardless of current status
551
552 include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
554 $a_mob->getType(),
555 $a_mob->getId(),
556 ilUtil::dirSize($a_mob->getDataDirectory()),
557 $parent_obj_ids
558 );
559 }
560
566 public static function _getDirectory($a_mob_id)
567 {
568 return ilUtil::getWebspaceDir() . "/mobs/mm_" . $a_mob_id;
569 }
570
576 public static function _getURL($a_mob_id)
577 {
578 return ilUtil::getHtmlPath(ilUtil::getWebspaceDir() . "/mobs/mm_" . $a_mob_id);
579 }
580
586 public static function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
587 {
588 return ilUtil::getWebspaceDir($a_mode) . "/thumbs/mm_" . $a_mob_id;
589 }
590
596 public static function _lookupStandardItemPath(
597 $a_mob_id,
598 $a_url_encode = false,
599 $a_web = true
600 ) {
601 return ilObjMediaObject::_lookupItemPath($a_mob_id, $a_url_encode, $a_web, "Standard");
602 }
603
609 public static function _lookupItemPath(
610 $a_mob_id,
611 $a_url_encode = false,
612 $a_web = true,
613 $a_purpose = ""
614 ) {
615 if ($a_purpose == "") {
616 $a_purpose = "Standard";
617 }
618 $location = ilMediaItem::_lookupLocationForMobId($a_mob_id, $a_purpose);
619 if (preg_match("/https?\:/i", $location)) {
620 return $location;
621 }
622
623 if ($a_url_encode) {
624 $location = rawurlencode($location);
625 }
626
627 $path = ($a_web)
628 ? ILIAS_HTTP_PATH
629 : ".";
630
631 return $path . "/data/" . CLIENT_ID . "/mobs/mm_" . $a_mob_id . "/" . $location;
632 }
633
637 public function createDirectory()
638 {
640 }
641
645 public static function _createThumbnailDirectory($a_obj_id)
646 {
648 ilUtil::createDirectory(ilUtil::getWebspaceDir() . "/thumbs/mm_" . $a_obj_id);
649 }
650
657 public function getFilesOfDirectory($a_subdir = "")
658 {
659 $a_subdir = str_replace("..", "", $a_subdir);
660 $dir = ilObjMediaObject::_getDirectory($this->getId());
661 if ($a_subdir != "") {
662 $dir.= "/" . $a_subdir;
663 }
664
665 $files = array();
666 if (is_dir($dir)) {
667 $entries = ilUtil::getDir($dir);
668 foreach ($entries as $e) {
669 if (is_file($dir . "/" . $e["entry"]) && $e["entry"] != "." && $e["entry"] != "..") {
670 $files[] = $e["entry"];
671 }
672 }
673 }
674
675 return $files;
676 }
677
678
683 public function getXML($a_mode = IL_MODE_FULL, $a_inst = 0, $a_sign_locals = false)
684 {
686
687 // TODO: full implementation of all parameters
688 //echo "-".$a_mode."-";
689 switch ($a_mode) {
690 case IL_MODE_ALIAS:
691 $xml = "<MediaObject>";
692 $xml .= "<MediaAlias OriginId=\"il__mob_" . $this->getId() . "\"/>";
693 $media_items = $this->getMediaItems();
694 for ($i=0; $i<count($media_items); $i++) {
695 $item = $media_items[$i];
696 $xml .= "<MediaAliasItem Purpose=\"" . $item->getPurpose() . "\">";
697
698 // Layout
699 $width = ($item->getWidth() != "")
700 ? "Width=\"" . $item->getWidth() . "\""
701 : "";
702 $height = ($item->getHeight() != "")
703 ? "Height=\"" . $item->getHeight() . "\""
704 : "";
705 $halign = ($item->getHAlign() != "")
706 ? "HorizontalAlign=\"" . $item->getHAlign() . "\""
707 : "";
708 $xml .= "<Layout $width $height $halign />";
709
710 // Caption
711 if ($item->getCaption() != "") {
712 $xml .= "<Caption Align=\"bottom\">" .
713 $this->escapeProperty($item->getCaption()) . "</Caption>";
714 }
715
716 // Text Representation
717 if ($item->getTextRepresentation() != "") {
718 $xml .= "<TextRepresentation>" .
719 $this->escapeProperty($item->getTextRepresentation()) . "</TextRepresentation>";
720 }
721
722 // Parameter
723 $parameters = $item->getParameters();
724 foreach ($parameters as $name => $value) {
725 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
726 }
727 $xml .= $item->getMapAreasXML();
728 $xml .= "</MediaAliasItem>";
729 }
730 break;
731
732 // for output we need technical sections of meta data
733 case IL_MODE_OUTPUT:
734
735 // get first technical section
736// $meta = $this->getMetaData();
737 $xml = "<MediaObject Id=\"il__mob_" . $this->getId() . "\">";
738
739 $media_items = $this->getMediaItems();
740 for ($i=0; $i<count($media_items); $i++) {
741 $item = $media_items[$i];
742
743 $xml .= "<MediaItem Purpose=\"" . $item->getPurpose() . "\">";
744
745 if ($a_sign_locals && $item->getLocationType() == "LocalFile") {
746 require_once 'Services/WebAccessChecker/classes/class.ilWACSignedPath.php';
747 $location = ilWACSignedPath::signFile($this->getDataDirectory() . "/" . $item->getLocation());
748 $location = substr($location, strrpos($location, "/") + 1);
749 } else {
750 $location = $item->getLocation();
751 if ($item->getLocationType() != "LocalFile") { //#25941
753 }
754 }
755
756 $xml.= "<Location Type=\"" . $item->getLocationType() . "\">" .
757 $this->handleAmps($location) . "</Location>";
758
759 // Format
760 $xml.= "<Format>" . $item->getFormat() . "</Format>";
761
762 // Layout
763 $width = ($item->getWidth() != "")
764 ? "Width=\"" . $item->getWidth() . "\""
765 : "";
766 $height = ($item->getHeight() != "")
767 ? "Height=\"" . $item->getHeight() . "\""
768 : "";
769 $halign = ($item->getHAlign() != "")
770 ? "HorizontalAlign=\"" . $item->getHAlign() . "\""
771 : "";
772 $xml .= "<Layout $width $height $halign />";
773
774 // Caption
775 if ($item->getCaption() != "") {
776 $xml .= "<Caption Align=\"bottom\">" .
777 $this->escapeProperty($item->getCaption()) . "</Caption>";
778 }
779
780 // Text Representation
781 if ($item->getTextRepresentation() != "") {
782 $xml .= "<TextRepresentation>" .
783 $this->escapeProperty($item->getTextRepresentation()) . "</TextRepresentation>";
784 }
785
786 // Title
787 if ($this->getTitle() != "") {
788 $xml .= "<Title>" .
789 str_replace("&", "&amp;", $this->getTitle()) . "</Title>";
790 }
791
792 // Parameter
793 $parameters = $item->getParameters();
794 foreach ($parameters as $name => $value) {
795 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
796 }
797 $xml .= $item->getMapAreasXML();
798
799 // Subtitles
800 if ($item->getPurpose() == "Standard") {
801 $srts = $this->getSrtFiles();
802 foreach ($srts as $srt) {
803 $def = "";
804 $meta_lang = "";
805 if ($ilUser->getLanguage() != $meta_lang &&
806 $ilUser->getLanguage() == $srt["language"]) {
807 $def = ' Default="true" ';
808 }
809 $xml .= "<Subtitle File=\"" . $srt["full_path"] .
810 "\" Language=\"" . $srt["language"] . "\" " . $def . "/>";
811 }
812 }
813 $xml .= "</MediaItem>";
814 }
815 break;
816
817 // full xml for export
818 case IL_MODE_FULL:
819
820// $meta = $this->getMetaData();
821 $xml = "<MediaObject>";
822
823 // meta data
824 include_once("Services/MetaData/classes/class.ilMD2XML.php");
825 $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
826 $md2xml->setExportMode(true);
827 $md2xml->startExport();
828 $xml.= $md2xml->getXML();
829
830 $media_items = $this->getMediaItems();
831 for ($i=0; $i<count($media_items); $i++) {
832 $item = $media_items[$i];
833
834 // highlight mode
835 $xml .= "<MediaItem Purpose=\"" . $item->getPurpose() . "\">";
836
837 // Location
838 $xml.= "<Location Type=\"" . $item->getLocationType() . "\">" .
839 $this->handleAmps($item->getLocation()) . "</Location>";
840
841 // Format
842 $xml.= "<Format>" . $item->getFormat() . "</Format>";
843
844 // Layout
845 $width = ($item->getWidth() != "")
846 ? "Width=\"" . $item->getWidth() . "\""
847 : "";
848 $height = ($item->getHeight() != "")
849 ? "Height=\"" . $item->getHeight() . "\""
850 : "";
851 $halign = ($item->getHAlign() != "")
852 ? "HorizontalAlign=\"" . $item->getHAlign() . "\""
853 : "";
854 $xml .= "<Layout $width $height $halign />";
855
856 // Caption
857 if ($item->getCaption() != "") {
858 $xml .= "<Caption Align=\"bottom\">" .
859 str_replace("&", "&amp;", $item->getCaption()) . "</Caption>";
860 }
861
862 // Text Representation
863 if ($item->getTextRepresentation() != "") {
864 $xml .= "<TextRepresentation>" .
865 str_replace("&", "&amp;", $item->getTextRepresentation()) . "</TextRepresentation>";
866 }
867
868 // Parameter
869 $parameters = $item->getParameters();
870 foreach ($parameters as $name => $value) {
871 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
872 }
873 $xml .= $item->getMapAreasXML(true, $a_inst);
874 $xml .= "</MediaItem>";
875 }
876 break;
877 }
878 $xml .= "</MediaObject>";
879 return $xml;
880 }
881
888 protected function escapeProperty($a_value)
889 {
890 return htmlspecialchars($a_value);
891 }
892
893
897 public function handleAmps($a_str)
898 {
899 $a_str = str_replace("&amp;", "&", $a_str);
900 $a_str = str_replace("&", "&amp;", $a_str);
901 return $a_str;
902 }
903
907 public function exportXML(&$a_xml_writer, $a_inst = 0)
908 {
909 $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
910 }
911
912
920 public function exportFiles($a_target_dir)
921 {
922 $subdir = "il_" . IL_INST_ID . "_mob_" . $this->getId();
923 ilUtil::makeDir($a_target_dir . "/objects/" . $subdir);
924
925 $mobdir = ilUtil::getWebspaceDir() . "/mobs/mm_" . $this->getId();
926 ilUtil::rCopy($mobdir, $a_target_dir . "/objects/" . $subdir);
927 //echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
928 }
929
930 public function exportMediaFullscreen($a_target_dir, $pg_obj)
931 {
932 $subdir = "il_" . IL_INST_ID . "_mob_" . $this->getId();
933 $a_target_dir = $a_target_dir . "/objects/" . $subdir;
934 ilUtil::makeDir($a_target_dir);
935 $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Modules/LearningModule");
936 $tpl->setCurrentBlock("ilMedia");
937
938 //$int_links = $page_object->getInternalLinks();
939 $med_links = ilMediaItem::_getMapAreasIntLinks($this->getId());
940
941 // @todo
942 //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets());
943
944 require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
945 //$media_obj = new ilObjMediaObject($_GET["mob_id"]);
946 require_once("./Services/COPage/classes/class.ilPageObject.php");
947
948 $xml = "<dummy>";
949 // todo: we get always the first alias now (problem if mob is used multiple
950 // times in page)
951 $xml.= $pg_obj->getMediaAliasElement($this->getId());
952 $xml.= $this->getXML(IL_MODE_OUTPUT);
953 //$xml.= $link_xml;
954 $xml.="</dummy>";
955
956 //die(htmlspecialchars($xml));
957
958 $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
959 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
960 $xh = xslt_create();
961
962 //echo "<b>XML:</b>".htmlentities($xml);
963 // determine target frames for internal links
964 $wb_path = "";
965 $enlarge_path = "";
966 $params = array('mode' => "fullscreen", 'enlarge_path' => $enlarge_path,
967 'link_params' => "ref_id=" . $_GET["ref_id"],'fullscreen_link' => "",
968 'ref_id' => $_GET["ref_id"], 'webspace_path' => $wb_path);
969 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
970 //echo xslt_error($xh);
971 xslt_free($xh);
972
973 // unmask user html
974 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
975 $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "../../css/style.css");
976 $tpl->setVariable("LOCATION_STYLESHEET", "../../css/system.css");
977 $tpl->setVariable("MEDIA_CONTENT", $output);
978 $output = $tpl->get();
979 //$output = preg_replace("/\/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
980 $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i", "$2", $output);
981 $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i", "../../players", $output);
982 $output = preg_replace("/\.\/" . str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory()) . "/i", "../../players", $output);
983 $output = preg_replace("/file=..\/..\/..\//i", "file=../objects/" . $subdir . "/", $output);
984 //die(htmlspecialchars($output));
985 fwrite(fopen($a_target_dir . '/fullscreen.html', 'w'), $output);
986 }
987
988 public function modifyExportIdentifier($a_tag, $a_param, $a_value)
989 {
990 if ($a_tag == "Identifier" && $a_param == "Entry") {
991 $a_value = ilUtil::insertInstIntoID($a_value);
992 }
993
994 return $a_value;
995 }
996
997
999 // EDIT METHODS: these methods act on the media alias in the dom
1001
1008 public function setContainsIntLink($a_contains_link)
1009 {
1010 $this->contains_int_link = $a_contains_link;
1011 }
1012
1017 public function containsIntLink()
1018 {
1020 }
1021
1025 public static function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1026 {
1027 global $DIC;
1028
1029 $ilDB = $DIC->database();
1030
1031 $and_hist = "";
1032 if ($a_usage_hist_nr !== false) {
1033 $and_hist = " AND usage_hist_nr = " . $ilDB->quote($a_usage_hist_nr, "integer");
1034 }
1035
1036 $mob_ids = array();
1037 $set = $ilDB->query("SELECT id FROM mob_usage" .
1038 " WHERE usage_type = " . $ilDB->quote($a_type, "text") .
1039 " AND usage_id = " . $ilDB->quote($a_id, "integer") .
1040 " AND usage_lang = " . $ilDB->quote($a_lang, "text") .
1041 $and_hist);
1042 while ($row = $ilDB->fetchAssoc($set)) {
1043 $mob_ids[] = $row["id"];
1044 }
1045
1046 $q = "DELETE FROM mob_usage WHERE usage_type = " .
1047 $ilDB->quote($a_type, "text") .
1048 " AND usage_id= " . $ilDB->quote($a_id, "integer") .
1049 " AND usage_lang = " . $ilDB->quote($a_lang, "text") .
1050 $and_hist;
1051 $ilDB->manipulate($q);
1052
1053 foreach ($mob_ids as $mob_id) {
1054 self::handleQuotaUpdate(new self($mob_id));
1055 }
1056 }
1057
1061 public static function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1062 {
1063 global $DIC;
1064
1065 $ilDB = $DIC->database();
1066
1067 $lstr = "";
1068 if ($a_lang != "") {
1069 $lstr = " AND usage_lang = " . $ilDB->quote($a_lang, "text");
1070 }
1071 $hist_str = "";
1072 if ($a_usage_hist_nr !== false) {
1073 $hist_str = " AND usage_hist_nr = " . $ilDB->quote($a_usage_hist_nr, "integer");
1074 }
1075
1076 $q = "SELECT * FROM mob_usage WHERE " .
1077 "usage_type = " . $ilDB->quote($a_type, "text") . " AND " .
1078 "usage_id = " . $ilDB->quote($a_id, "integer") .
1079 $lstr . $hist_str;
1080 $mobs = array();
1081 $mob_set = $ilDB->query($q);
1082 while ($mob_rec = $ilDB->fetchAssoc($mob_set)) {
1083 if (ilObject::_lookupType($mob_rec["id"]) == "mob") {
1084 $mobs[$mob_rec["id"]] = $mob_rec["id"];
1085 }
1086 }
1087
1088 return $mobs;
1089 }
1090
1094 public static function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1095 {
1096 global $DIC;
1097
1098 $ilDB = $DIC->database();
1099
1100 $ilDB->replace(
1101 "mob_usage",
1102 array(
1103 "id" => array("integer", (int) $a_mob_id),
1104 "usage_type" => array("text", $a_type),
1105 "usage_id" => array("integer", $a_id),
1106 "usage_lang" => array("text", $a_lang),
1107 "usage_hist_nr" => array("integer", (int) $a_usage_hist_nr)
1108 ),
1109 array()
1110 );
1111
1112 self::handleQuotaUpdate(new self($a_mob_id));
1113 }
1114
1118 public static function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1119 {
1120 global $DIC;
1121
1122 $ilDB = $DIC->database();
1123
1124 $q = "DELETE FROM mob_usage WHERE " .
1125 " id = " . $ilDB->quote((int) $a_mob_id, "integer") . " AND " .
1126 " usage_type = " . $ilDB->quote($a_type, "text") . " AND " .
1127 " usage_id = " . $ilDB->quote((int) $a_id, "integer") . " AND " .
1128 " usage_lang = " . $ilDB->quote($a_lang, "text") . " AND " .
1129 " usage_hist_nr = " . $ilDB->quote((int) $a_usage_hist_nr, "integer");
1130 $ilDB->manipulate($q);
1131
1132 self::handleQuotaUpdate(new self($a_mob_id));
1133 }
1134
1138 public function getUsages($a_include_history = true)
1139 {
1140 return self::lookupUsages($this->getId(), $a_include_history);
1141 }
1142
1148 public static function lookupUsages($a_id, $a_include_history = true)
1149 {
1150 global $DIC;
1151
1152 $ilDB = $DIC->database();
1153
1154 $hist_str = "";
1155 if ($a_include_history) {
1156 $hist_str = ", usage_hist_nr";
1157 }
1158
1159 // get usages in pages
1160 $q = "SELECT DISTINCT usage_type, usage_id, usage_lang" . $hist_str . " FROM mob_usage WHERE id = " .
1161 $ilDB->quote($a_id, "integer");
1162
1163 if (!$a_include_history) {
1164 $q.= " AND usage_hist_nr = " . $ilDB->quote(0, "integer");
1165 }
1166
1167 $us_set = $ilDB->query($q);
1168 $ret = array();
1169 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
1170 $ut = "";
1171 if (is_int(strpos($us_rec["usage_type"], ":"))) {
1172 $us_arr = explode(":", $us_rec["usage_type"]);
1173 $ut = $us_arr[1];
1174 $ct = $us_arr[0];
1175 }
1176
1177 // check whether page exists
1178 $skip = false;
1179 if ($ut == "pg") {
1180 include_once("./Services/COPage/classes/class.ilPageObject.php");
1181 if (!ilPageObject::_exists($ct, $us_rec["usage_id"])) {
1182 $skip = true;
1183 }
1184 }
1185
1186 if (!$skip) {
1187 $ret[] = array("type" => $us_rec["usage_type"],
1188 "id" => $us_rec["usage_id"],
1189 "lang" => $us_rec["usage_lang"],
1190 "hist_nr" => $us_rec["usage_hist_nr"]);
1191 }
1192 }
1193
1194 // get usages in media pools
1195 $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = " .
1196 $ilDB->quote($a_id, "integer") . " AND mep_item.type = " . $ilDB->quote("mob", "text");
1197 $us_set = $ilDB->query($q);
1198 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
1199 $ret[] = array("type" => "mep",
1200 "id" => $us_rec["mep_id"]);
1201 }
1202
1203 // get usages in news items (media casts)
1204 include_once("./Services/News/classes/class.ilNewsItem.php");
1205 $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
1206 foreach ($news_usages as $nu) {
1207 $ret[] = $nu;
1208 }
1209
1210
1211 // get usages in map areas
1212 $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area " .
1213 " WHERE area.item_id = it.id " .
1214 " AND area.link_type = " . $ilDB->quote("int", "text") . " " .
1215 " AND area.target = " . $ilDB->quote("il__mob_" . $a_id, "text");
1216 $us_set = $ilDB->query($q);
1217 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
1218 $ret[] = array("type" => "map",
1219 "id" => $us_rec["mob_id"]);
1220 }
1221
1222 // get usages in personal clipboards
1224 foreach ($users as $user) {
1225 $ret[] = array("type" => "clip",
1226 "id" => $user);
1227 }
1228
1229 return $ret;
1230 }
1231
1237 public static function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
1238 {
1239 if (is_int(strpos($a_usage["type"], ":"))) {
1240 $us_arr = explode(":", $a_usage["type"]);
1241 $type = $us_arr[1];
1242 $cont_type = $us_arr[0];
1243 } else {
1244 $type = $a_usage["type"];
1245 }
1246
1247 $id = $a_usage["id"];
1248 $obj_id = false;
1249
1250 switch ($type) {
1251 // RTE / tiny mce
1252 case "html":
1253
1254 switch ($cont_type) {
1255 case "qpl":
1256 // Question Pool *Question* Text (Test)
1257 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1259 if ($qinfo["original_id"] > 0) {
1260 include_once("./Modules/Test/classes/class.ilObjTest.php");
1261 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1262 } else {
1263 $obj_id = $qinfo["obj_fi"]; // usage in pool
1264 }
1265 break;
1266
1267 case "spl":
1268 // Question Pool *Question* Text (Survey)
1269 include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
1271 if ($quest) {
1272 $parent_id = $quest->getObjId();
1273
1274 // pool question copy - find survey, do not use pool itself
1275 if ($quest->getOriginalId() &&
1276 ilObject::_lookupType($parent_id) == "spl") {
1278 }
1279 // original question (in pool or survey)
1280 else {
1281 $obj_id = $parent_id;
1282 }
1283
1284 unset($quest);
1285 }
1286 break;
1287
1288 case "exca":
1289 // Exercise assignment
1290 $returned_pk = $a_usage['id'];
1291 // #15995 - we are just checking against exercise object
1292 include_once 'Modules/Exercise/classes/class.ilExSubmission.php';
1293 $obj_id = ilExSubmission::lookupExerciseIdForReturnedId($returned_pk);
1294 break;
1295
1296 case "frm":
1297 // Forum
1298 $post_pk = $a_usage['id'];
1299 include_once 'Modules/Forum/classes/class.ilForumPost.php';
1300 include_once 'Modules/Forum/classes/class.ilForum.php';
1301 $oPost = new ilForumPost($post_pk);
1302 $frm_pk = $oPost->getForumId();
1303 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1304 break;
1305
1306
1307 case "frm~d":
1308 $draft_id = $a_usage['id'];
1309 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
1310 include_once 'Modules/Forum/classes/class.ilForum.php';
1311 $oDraft = ilForumPostDraft::newInstanceByDraftId($draft_id);
1312
1313 $frm_pk = $oDraft->getForumId();
1314 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1315 break;
1316 case "frm~h":
1317 $history_id = $a_usage['id'];
1318 include_once 'Modules/Forum/classes/class.ilForumDraftsHistory.php';
1319 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
1320 include_once 'Modules/Forum/classes/class.ilForum.php';
1321 $oHistoryDraft = new ilForumDraftsHistory($history_id);
1322 $oDraft = ilForumPostDraft::newInstanceByDraftId($oHistoryDraft->getDraftId());
1323
1324 $frm_pk = $oDraft->getForumId();
1325 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1326 break;
1327 // temporary items (per user)
1328 case "frm~":
1329 case "exca~":
1330 $obj_id = $a_usage['id'];
1331 break;
1332
1333 // "old" category pages
1334 case "cat":
1335 // InfoScreen Text
1336 case "tst":
1337 case "svy":
1338 // data collection
1339 case "dcl":
1340 $obj_id = $id;
1341 break;
1342 }
1343 break;
1344
1345 // page editor
1346 case "pg":
1347
1348 switch ($cont_type) {
1349 // question feedback // parent obj id is q id
1350 case "qfbg":
1351 include_once('./Services/COPage/classes/class.ilPageObject.php');
1353 // note: no break here, we only altered the $id to the question id
1354
1355 // no break
1356 case "qpl":
1357 // Question Pool Question Pages
1358 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1360 if ($qinfo["original_id"] > 0) {
1361 include_once("./Modules/Test/classes/class.ilObjTest.php");
1362 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1363 } else {
1364 $obj_id = $qinfo["obj_fi"]; // usage in pool
1365 }
1366 if ($obj_id == 0) { // this is the case, if question is in learning module -> get lm id
1367 include_once("./Services/COPage/classes/class.ilPCQuestion.php");
1369 if ($pinfo && $pinfo["parent_type"] == "lm") {
1370 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1371 $obj_id = ilLMObject::_lookupContObjID($pinfo["page_id"]);
1372 }
1373 $pinfo = ilPCQuestion::_getPageForQuestionId($id, "sahs");
1374 if ($pinfo && $pinfo["parent_type"] == "sahs") {
1375 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
1376 $obj_id = ilSCORM2004Node::_lookupSLMID($pinfo["page_id"]);
1377 }
1378 }
1379 break;
1380
1381 case "lm":
1382 // learning modules
1383 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1385 break;
1386
1387 case "gdf":
1388 // glossary definition
1389 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1390 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1392 $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1393 break;
1394
1395 case "wpg":
1396 // wiki page
1397 include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
1399 break;
1400
1401 case "sahs":
1402 // sahs page
1403 // can this implementation be used for other content types, too?
1404 include_once('./Services/COPage/classes/class.ilPageObject.php');
1405 $obj_id = ilPageObject::lookupParentId($id, 'sahs');
1406 break;
1407
1408 case "prtf":
1409 // portfolio
1410 include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
1412 break;
1413
1414 case "prtt":
1415 // portfolio template
1416 include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
1418 break;
1419
1420 case "blp":
1421 // blog
1422 include_once('./Services/COPage/classes/class.ilPageObject.php');
1423 $obj_id = ilPageObject::lookupParentId($id, 'blp');
1424 break;
1425
1426 case "impr":
1427 // imprint page - always id 1
1428 // fallthrough
1429
1430 case "crs":
1431 case "grp":
1432 case "cat":
1433 case "fold":
1434 case "root":
1435 case "cont":
1436 case "cstr":
1437 // repository pages
1438 $obj_id = $id;
1439 break;
1440 }
1441 break;
1442
1443 // Media Pool
1444 case "mep":
1445 $obj_id = $id;
1446 break;
1447
1448 // News Context Object (e.g. MediaCast)
1449 case "news":
1450 include_once("./Services/News/classes/class.ilNewsItem.php");
1452 break;
1453 }
1454
1455 return $obj_id;
1456 }
1457
1465 public static function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1466 {
1467 $file_path = pathinfo($a_file);
1468 $location = substr($file_path["basename"], 0, strlen($file_path["basename"]) -
1469 strlen($file_path["extension"]) - 1) . "_" .
1470 $a_width . "_" .
1471 $a_height . "." . $file_path["extension"];
1472 $target_file = $file_path["dirname"] . "/" .
1473 $location;
1475 $a_file,
1476 $target_file,
1477 (int) $a_width,
1478 (int) $a_height,
1479 $a_constrain_prop
1480 );
1481
1482 return $location;
1483 }
1484
1492 public static function getMimeType($a_file, $a_external = null)
1493 {
1494 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1496 return $mime;
1497 }
1498
1502 public static function _determineWidthHeight(
1503 $a_format,
1504 $a_type,
1505 $a_file,
1506 $a_reference,
1507 $a_constrain_proportions,
1508 $a_use_original,
1509 $a_user_width,
1510 $a_user_height
1511 ) {
1512 global $DIC;
1513
1514 $lng = $DIC->language();
1515
1516 // determine width and height of known image types
1517 //$width = 640;
1518 //$height = 360;
1519 $info = "";
1520
1521 if ($a_format == "audio/mpeg") {
1522 $width = 300;
1523 $height = 20;
1524 }
1525
1526 if (ilUtil::deducibleSize($a_format)) {
1527 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1528 if ($a_type == "File") {
1530 } else {
1531 $size = ilMediaImageUtil::getImageSize($a_reference);
1532 }
1533 }
1534
1535 if ($a_use_original) {
1536 if ($size[0] > 0 && $size[1] > 0) {
1537 //$width = $size[0];
1538 //$height = $size[1];
1539 $width = "";
1540 $height = "";
1541 } else {
1542 $info = $lng->txt("cont_could_not_determine_resource_size");
1543 }
1544 } else {
1545 $w = (int) $a_user_width;
1546 $h = (int) $a_user_height;
1547 $width = $w;
1548 $height = $h;
1549 //echo "<br>C-$width-$height-";
1550 if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions) {
1551 if ($size[0] > 0 && $size[1] > 0) {
1552 if ($w > 0) {
1553 $wr = $size[0] / $w;
1554 }
1555 if ($h > 0) {
1556 $hr = $size[1] / $h;
1557 }
1558 //echo "<br>+".$wr."+".$size[0]."+".$w."+";
1559 //echo "<br>+".$hr."+".$size[1]."+".$h."+";
1560 $r = max($wr, $hr);
1561 if ($r > 0) {
1562 $width = (int) ($size[0]/$r);
1563 $height = (int) ($size[1]/$r);
1564 }
1565 }
1566 }
1567 //echo "<br>D-$width-$height-";
1568 }
1569 //echo "<br>E-$width-$height-";
1570
1571 if ($width == 0 && $a_user_width === "") {
1572 $width = "";
1573 }
1574 if ($height == 0 && $a_user_height === "") {
1575 $height = "";
1576 }
1577
1578 return array("width" => $width, "height" => $height, "info" => $info);
1579 }
1580
1585 public static function _getSimpleMimeTypes()
1586 {
1587 return array("image/x-ms-bmp", "image/gif", "image/jpeg", "image/x-portable-bitmap",
1588 "image/png", "image/psd", "image/tiff", "application/pdf");
1589 }
1590
1591 public function getDataDirectory()
1592 {
1593 return ilUtil::getWebspaceDir() . "/mobs/mm_" . $this->getId();
1594 }
1595
1602 public static function _useAutoStartParameterOnly($a_loc, $a_format)
1603 {
1604 $lpath = pathinfo($a_loc);
1605 if ($lpath["extension"] == "mp3" && $a_format == "audio/mpeg") {
1606 return true;
1607 }
1608 if ($lpath["extension"] == "flv") {
1609 return true;
1610 }
1611 if (in_array($a_format, array("video/mp4", "video/webm"))) {
1612 return true;
1613 }
1614 return false;
1615 }
1616
1620 public static function _saveTempFileAsMediaObject($name, $tmp_name, $upload = true)
1621 {
1622 // create dummy object in db (we need an id)
1623 $media_object = new ilObjMediaObject();
1624 $media_object->setTitle($name);
1625 $media_object->setDescription("");
1626 $media_object->create();
1627
1628 // determine and create mob directory, move uploaded file to directory
1629 $media_object->createDirectory();
1630 $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1631
1632 $media_item = new ilMediaItem();
1633 $media_object->addMediaItem($media_item);
1634 $media_item->setPurpose("Standard");
1635
1636 $file = $mob_dir . "/" . $name;
1637 if ($upload) {
1638 ilUtil::moveUploadedFile($tmp_name, $name, $file);
1639 } else {
1640 copy($tmp_name, $file);
1641 }
1642 // get mime type
1644 $location = $name;
1645 // set real meta and object data
1646 $media_item->setFormat($format);
1647 $media_item->setLocation($location);
1648 $media_item->setLocationType("LocalFile");
1649 $media_object->setTitle($name);
1650 $media_object->setDescription($format);
1651
1653 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1655 $media_item->setWidth($size[0]);
1656 $media_item->setHeight($size[1]);
1657 }
1658 $media_item->setHAlign("Left");
1659
1660 self::renameExecutables($mob_dir);
1661 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1662 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1663
1664 $media_object->update();
1665
1666 return $media_object;
1667 }
1668
1672 public function uploadAdditionalFile($a_name, $tmp_name, $a_subdir = "", $a_mode = "move_uploaded")
1673 {
1674 $a_subdir = str_replace("..", "", $a_subdir);
1675 $dir = $mob_dir = ilObjMediaObject::_getDirectory($this->getId());
1676 if ($a_subdir != "") {
1677 $dir.= "/" . $a_subdir;
1678 }
1680 if ($a_mode == "rename") {
1681 rename($tmp_name, $dir . "/" . $a_name);
1682 } else {
1683 ilUtil::moveUploadedFile($tmp_name, $a_name, $dir . "/" . $a_name, true, $a_mode);
1684 }
1685 self::renameExecutables($mob_dir);
1686 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1687 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1688 }
1689
1696 public function uploadSrtFile($a_tmp_name, $a_language, $a_mode = "move_uploaded")
1697 {
1698 if (is_file($a_tmp_name) && $a_language != "") {
1699 $this->uploadAdditionalFile("subtitle_" . $a_language . ".srt", $a_tmp_name, "srt", $a_mode);
1700 return true;
1701 }
1702 return false;
1703 }
1704
1708 public function getSrtFiles()
1709 {
1710 $srt_dir = ilObjMediaObject::_getDirectory($this->getId()) . "/srt";
1711
1712 if (!is_dir($srt_dir)) {
1713 return array();
1714 }
1715
1716 $items = ilUtil::getDir($srt_dir);
1717
1718 $srt_files = array();
1719 foreach ($items as $i) {
1720 if (!in_array($i["entry"], array(".", "..")) && $i["type"] == "file") {
1721 $name = explode(".", $i["entry"]);
1722 if ($name[1] == "srt" && substr($name[0], 0, 9) == "subtitle_") {
1723 $srt_files[] = array("file" => $i["entry"],
1724 "full_path" => "srt/" . $i["entry"], "language" => substr($name[0], 9, 2));
1725 }
1726 }
1727 }
1728
1729 return $srt_files;
1730 }
1731
1735 public function makeThumbnail(
1736 $a_file,
1737 $a_thumbname,
1738 $a_format = "png",
1739 $a_size = "80"
1740 ) {
1741 $m_dir = ilObjMediaObject::_getDirectory($this->getId());
1745 $m_dir . "/" . $a_file,
1746 $t_dir . "/" . $a_thumbname,
1747 $a_format,
1748 $a_size
1749 );
1750 }
1751
1758 public static function getThumbnailPath($a_mob_id, $a_thumbname)
1759 {
1760 $t_dir = ilObjMediaObject::_getThumbnailDirectory($a_mob_id);
1761 return $t_dir . "/" . $a_thumbname;
1762 }
1763
1764
1768 public function removeAdditionalFile($a_file)
1769 {
1770 $file = str_replace("..", "", $a_file);
1772 if (is_file($file)) {
1773 unlink($file);
1774 }
1775 }
1776
1777
1781 public function getLinkedMediaObjects($a_ignore = "")
1782 {
1783 $linked = array();
1784
1785 if (!is_array($a_ignore)) {
1786 $a_ignore = array();
1787 }
1788
1789 // get linked media objects (map areas)
1790 $med_items = $this->getMediaItems();
1791
1792 foreach ($med_items as $med_item) {
1793 $int_links = ilMapArea::_getIntLinks($med_item->getId());
1794 foreach ($int_links as $k => $int_link) {
1795 if ($int_link["Type"] == "MediaObject") {
1796 include_once("./Services/Link/classes/class.ilInternalLink.php");
1797 $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1798 if (ilObject::_exists($l_id)) {
1799 if (!in_array($l_id, $linked) &&
1800 !in_array($l_id, $a_ignore)) {
1801 $linked[] = $l_id;
1802 }
1803 }
1804 }
1805 }
1806 }
1807 //var_dump($linked);
1808 return $linked;
1809 }
1810
1814 public static function getRestrictedFileTypes()
1815 {
1816 return array_filter(self::getAllowedFileTypes(), function ($v) {
1817 return !in_array($v, self::getForbiddenFileTypes());
1818 });
1819 }
1820
1826 public static function getForbiddenFileTypes()
1827 {
1828 $mset = new ilSetting("mobs");
1829 if (trim($mset->get("black_list_file_types")) == "") {
1830 return array();
1831 }
1832 return array_map(
1833 function ($v) {
1834 return strtolower(trim($v));
1835 },
1836 explode(",", $mset->get("black_list_file_types"))
1837 );
1838 }
1839
1845 public static function getAllowedFileTypes()
1846 {
1847 $mset = new ilSetting("mobs");
1848 if (trim($mset->get("restricted_file_types")) == "") {
1849 return array();
1850 }
1851 return array_map(
1852 function ($v) {
1853 return strtolower(trim($v));
1854 },
1855 explode(",", $mset->get("restricted_file_types"))
1856 );
1857 }
1858
1865 public static function isTypeAllowed($a_type)
1866 {
1867 if (in_array($a_type, self::getForbiddenFileTypes())) {
1868 return false;
1869 }
1870 if (count(self::getAllowedFileTypes()) == 0 || in_array($a_type, self::getAllowedFileTypes())) {
1871 return true;
1872 }
1873 return false;
1874 }
1875
1876
1880 public function duplicate()
1881 {
1882 $new_obj = new ilObjMediaObject();
1883 $new_obj->setTitle($this->getTitle());
1884 $new_obj->setDescription($this->getDescription());
1885
1886 // media items
1887 foreach ($this->getMediaItems() as $key => $val) {
1888 $new_obj->addMediaItem($val);
1889 }
1890
1891 $new_obj->create(false, true);
1892
1893 // files
1894 $new_obj->createDirectory();
1895 self::_createThumbnailDirectory($new_obj->getId());
1898 ilObjMediaObject::_getDirectory($new_obj->getId())
1899 );
1903 );
1904
1905 // meta data
1906 include_once("Services/MetaData/classes/class.ilMD.php");
1907 $md = new ilMD(0, $this->getId(), "mob");
1908 $new_md = $md->cloneMD(0, $new_obj->getId(), "mob");
1909
1910 return $new_obj;
1911 }
1912
1919 public function uploadVideoPreviewPic($a_prevpic)
1920 {
1921 // remove old one
1922 if ($this->getVideoPreviewPic(true) != "") {
1923 $this->removeAdditionalFile($this->getVideoPreviewPic(true));
1924 }
1925
1926 $pi = pathinfo($a_prevpic["name"]);
1927 $ext = $pi["extension"];
1928 if (in_array($ext, array("jpg", "jpeg", "png"))) {
1929 $this->uploadAdditionalFile("mob_vpreview." . $ext, $a_prevpic["tmp_name"]);
1930 }
1931 }
1932
1939 public function generatePreviewPic($a_width, $a_height)
1940 {
1941 $item = $this->getMediaItem("Standard");
1942
1943 if ($item->getLocationType() == "LocalFile" &&
1944 is_int(strpos($item->getFormat(), "image/"))) {
1945 $dir = ilObjMediaObject::_getDirectory($this->getId());
1946 $file = $dir . "/" .
1947 $item->getLocation();
1948 if (is_file($file)) {
1949 if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
1950 ilUtil::execConvert(ilUtil::escapeShellArg($file) . "[0] -geometry " . $a_width . "x" . $a_height . "^ -gravity center -extent " . $a_width . "x" . $a_height . " PNG:" . $dir . "/mob_vpreview.png");
1951 } else {
1952 ilUtil::convertImage($file, $dir . "/mob_vpreview.png", "PNG", $a_width . "x" . $a_height);
1953 }
1954 }
1955 }
1956 }
1957
1964 public function getVideoPreviewPic($a_filename_only = false)
1965 {
1966 $dir = ilObjMediaObject::_getDirectory($this->getId());
1967 $ppics = array("mob_vpreview.jpg",
1968 "mob_vpreview.jpeg",
1969 "mob_vpreview.png");
1970 foreach ($ppics as $p) {
1971 if (is_file($dir . "/" . $p)) {
1972 if ($a_filename_only) {
1973 return $p;
1974 } else {
1975 return $dir . "/" . $p;
1976 }
1977 }
1978 }
1979 return "";
1980 }
1981
1988 public static function fixFilename($a_name)
1989 {
1990 $a_name = ilUtil::getASCIIFilename($a_name);
1991
1992 $rchars = array("`", "=", "$", "{", "}", "'", ";", " ", "(", ")");
1993 $a_name = str_replace($rchars, "_", $a_name);
1994 $a_name = str_replace("__", "_", $a_name);
1995 return $a_name;
1996 }
1997
1998
2005 public function getMultiSrtUploadDir()
2006 {
2007 return ilObjMediaObject::_getDirectory($this->getId() . "/srt/tmp");
2008 }
2009
2010
2017 public function uploadMultipleSubtitleFile($a_file)
2018 {
2019 $lng = $this->lng;
2021
2022 include_once("./Services/MediaObjects/exceptions/class.ilMediaObjectsException.php");
2023 if (!is_file($a_file["tmp_name"])) {
2024 throw new ilMediaObjectsException($lng->txt("mob_file_could_not_be_uploaded"));
2025 }
2026
2027 $dir = $this->getMultiSrtUploadDir();
2028 ilUtil::delDir($dir, true);
2030 ilUtil::moveUploadedFile($a_file["tmp_name"], "multi_srt.zip", $dir . "/" . "multi_srt.zip");
2031 ilUtil::unzip($dir . "/multi_srt.zip", true);
2032 }
2033
2037 public function clearMultiSrtDirectory()
2038 {
2040 }
2041
2045 public function getMultiSrtFiles()
2046 {
2047 $items = array();
2048
2049 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
2051
2052 $dir = $this->getMultiSrtUploadDir();
2053 $files = ilUtil::getDir($dir);
2054 foreach ($files as $k => $i) {
2055 // check directory
2056 if ($i["type"] == "file" && !in_array($k, array(".", ".."))) {
2057 if (pathinfo($k, PATHINFO_EXTENSION) == "srt") {
2058 $lang = "";
2059 if (substr($k, strlen($k) - 7, 1) == "_") {
2060 $lang = substr($k, strlen($k) - 6, 2);
2061 if (!in_array($lang, $lang_codes)) {
2062 $lang = "";
2063 }
2064 }
2065 $items[] = array("filename" => $k, "lang" => $lang);
2066 }
2067 }
2068 }
2069 return $items;
2070 }
2071
2077 public static function renameExecutables($a_dir)
2078 {
2080 if (!self::isTypeAllowed("html")) {
2081 ilUtil::rRenameSuffix($a_dir, "html", "sec"); // see #20187
2082 }
2083 }
2084}
user()
Definition: user.php:4
$size
Definition: RandomTest.php:84
$tpl
Definition: ilias.php:10
$files
Definition: add-vimline.php:18
$users
Definition: authpage.php:44
$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 handleUpdatedSourceObject($a_src_obj_type, $a_src_obj_id, $a_src_filesize, $a_owner_obj_ids=null, $a_is_prtf=false)
Find and update/create all related entries for source object.
static lookupExerciseIdForReturnedId($a_returned_id)
Get exercise from submission id (used in ilObjMediaObject)
Class ilForumDraftHistory.
static newInstanceByDraftId($draft_id)
static _lookupObjIdForForumId($a_for_id)
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.
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)
& getMediaItem($a_purpose)
get item for media purpose
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
getId()
get object id @access public
static getAllowedFileTypes()
Get allowed file types.
static _useAutoStartParameterOnly($a_loc, $a_format)
Check whether only autostart parameter should be supported (instead of parameters input field.
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 directory for files of media object (static)
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
static _getSimpleMimeTypes()
Get simple mime types that deactivate parameter property files tab in ILIAS.
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)
generatePreviewPic($a_width, $a_height)
Upload video preview picture.
createMetaData()
create meta data entry
modifyExportIdentifier($a_tag, $a_param, $a_value)
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.
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
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.
special template class to simplify handling of ITX/PEAR
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 rRenameSuffix($a_dir, $a_old_suffix, $a_new_suffix)
Renames all files with certain suffix and gives them a new suffix.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static getHtmlPath($relative_path)
get url of path
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
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
$lang
Definition: consent.php:3
$def
Definition: croninfo.php:21
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
$h
$w
$r
Definition: example_031.php:79
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
xslt_free(&$proc)
xslt_create()
if($format !==null) $name
Definition: metadata.php:146
$format
Definition: metadata.php:141
$xml
Definition: metadata.php:240
$info
Definition: index.php:5
static getDescription()
Definition: Php.php:51
update($pash, $contents, Config $config)
redirection script todo: (a better solution should control the processing via a xml file)
$ret
Definition: parser.php:6
global $ilSetting
Definition: privfeed.php:17
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC
Definition: saml.php:7
global $ilDB
$mobs
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92
$params
Definition: disable.php:11