ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
30 var $id;
33
38 function __construct($a_id = 0)
39 {
40 $this->is_alias = false;
41 $this->media_items = array();
42 $this->contains_int_link = false;
43 $this->type = "mob";
44 parent::__construct($a_id, false);
45 }
46
47 function setRefId($a_id)
48 {
49 $this->ilias->raiseError("Operation ilObjMedia::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
50 }
51
52 function getRefId()
53 {
54 return false;
55 }
56
57 function putInTree($a_parent_ref)
58 {
59 $this->ilias->raiseError("Operation ilObjMedia::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
60 }
61
62 function createReference()
63 {
64 $this->ilias->raiseError("Operation ilObjMedia::createReference() not allowed.",$this->ilias->error_obj->FATAL);
65 }
66
67 function setTitle($a_title)
68 {
69 parent::setTitle($a_title);
70 }
71
72 function getTitle()
73 {
74 return parent::getTitle();
75 }
76
84 public static function _exists($a_id, $a_reference = false, $a_type = NULL)
85 {
86 global $ilDB;
87
88 include_once("./Services/Link/classes/class.ilInternalLink.php");
89 if (is_int(strpos($a_id, "_")))
90 {
92 }
93
94 return parent::_exists($a_id, false);
95 }
96
100 function delete()
101 {
102 $mob_logger = ilLoggerFactory::getLogger('mob');
103 $mob_logger->debug("ilObjMediaObject: Delete called for media object ID '".$this->getId()."'.");
104
105 if (!($this->getId() > 0))
106 {
107 return;
108 }
109
110 $usages = $this->getUsages();
111
112 $mob_logger->debug("ilObjMediaObject: ... Found ".count($usages)." usages.");
113
114 if (count($usages) == 0)
115 {
116 // remove directory
118
119 // remove thumbnail directory
121
122 // delete meta data of mob
123 $this->deleteMetaData();
124
125 // delete media items
127
128 // this is just to make sure, there should be no entries left at
129 // this point as they depend on the usage
131
132 // delete object
133 parent::delete();
134
135 $mob_logger->debug("ilObjMediaObject: ... deleted.");
136 }
137 else
138 {
139 foreach ($usages as $u)
140 {
141 $mob_logger->debug("ilObjMediaObject: ... usage type:".$u["type"].
142 ", id:".$u["id"].
143 ", lang:".$u["lang"].
144 ", hist_nr:".$u["hist_nr"].".");
145 }
146 $mob_logger->debug("ilObjMediaObject: ... not deleted.");
147 }
148 }
149
155 function getDescription()
156 {
157 return parent::getDescription();
158 }
159
163 function setDescription($a_description)
164 {
165 parent::setDescription($a_description);
166 }
167
179 function MDUpdateListener($a_element)
180 {
181 include_once 'Services/MetaData/classes/class.ilMD.php';
182
183 switch($a_element)
184 {
185 case 'General':
186
187 // Update Title and description
188 $md = new ilMD(0, $this->getId(), $this->getType());
189 $md_gen = $md->getGeneral();
190
191 if (is_object($md_gen))
192 {
193 ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
194 $this->setTitle($md_gen->getTitle());
195
196 foreach($md_gen->getDescriptionIds() as $id)
197 {
198 $md_des = $md_gen->getDescription($id);
199 ilObject::_writeDescription($this->getId(),$md_des->getDescription());
200 $this->setDescription($md_des->getDescription());
201 break;
202 }
203 }
204
205 break;
206
207 default:
208 }
209 return true;
210 }
211
215 function createMetaData()
216 {
217 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
218
219 global $ilUser;
220
221 $md_creator = new ilMDCreator(0, $this->getId(), $this->getType());
222 $md_creator->setTitle($this->getTitle());
223 $md_creator->setTitleLanguage($ilUser->getPref('language'));
224 $md_creator->setDescription($this->getDescription());
225 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
226 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
227 $md_creator->setLanguage($ilUser->getPref('language'));
228 $md_creator->create();
229
230 return true;
231 }
232
236 function updateMetaData()
237 {
238 include_once("Services/MetaData/classes/class.ilMD.php");
239 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
240 include_once("Services/MetaData/classes/class.ilMDDescription.php");
241
242 $md = new ilMD(0, $this->getId(), $this->getType());
243 $md_gen = $md->getGeneral();
244 $md_gen->setTitle($this->getTitle());
245
246 // sets first description (maybe not appropriate)
247 $md_des_ids = $md_gen->getDescriptionIds();
248 if (count($md_des_ids) > 0)
249 {
250 $md_des = $md_gen->getDescription($md_des_ids[0]);
251 $md_des->setDescription($this->getDescription());
252 $md_des->update();
253 }
254 $md_gen->update();
255
256 }
257
261 function deleteMetaData()
262 {
263 // Delete meta data
264 include_once('Services/MetaData/classes/class.ilMD.php');
265 $md = new ilMD(0, $this->getId(), $this->getType());
266 $md->deleteAll();
267 }
268
269
275 function addMediaItem($a_item)
276 {
277 $this->media_items[] = $a_item;
278 }
279
280
286 function &getMediaItems()
287 {
288 return $this->media_items;
289 }
290
297 function &getMediaItem($a_purpose)
298 {
299 foreach ($this->media_items as $media_item)
300 {
301 if($media_item->getPurpose() == $a_purpose)
302 {
303 return $media_item;
304 }
305 }
306 return false;
307 }
308
309
313 function removeMediaItem($a_purpose)
314 {
315 foreach ($this->media_items as $key => $media_item)
316 {
317 if($media_item->getPurpose() == $a_purpose)
318 {
319 unset($this->media_items[$key]);
320 }
321 }
322 // update numbers and keys
323 $i = 1;
324 $media_items = array();
325 foreach ($this->media_items as $media_item)
326 {
327 $media_items [$i] = $media_item;
328 $media_item->setMobId($this->getId());
329 $media_item->setNr($i);
330 $i++;
331 }
332 $this->media_items = $media_items;
333 }
334
339 {
340 $this->media_items = array();
341 }
342
343
344 function getMediaItemNr($a_purpose)
345 {
346 for($i=0; $i<count($this->media_items); $i++)
347 {
348 if($this->media_items[$i]->getPurpose() == $a_purpose)
349 {
350 return $i + 1;
351 }
352 }
353 return false;
354 }
355
356
358 {
359 return $this->hasPurposeItem("Fullscreen");
360 }
361
368 function hasPurposeItem($purpose)
369 {
370 if(is_object($this->getMediaItem($purpose)))
371 {
372 return true;
373 }
374 else
375 {
376 return false;
377 }
378 }
379
380
381
385 function read()
386 {
387//echo "<br>ilObjMediaObject:read";
388 parent::read();
389
390 // get media items
392 }
393
397 function setId($a_id)
398 {
399 $this->id = $a_id;
400 }
401
402 function getId()
403 {
404 return $this->id;
405 }
406
410 function setAlias($a_is_alias)
411 {
412 $this->is_alias = $a_is_alias;
413 }
414
415 function isAlias()
416 {
417 return $this->is_alias;
418 }
419
420 function setOriginID($a_id)
421 {
422 return $this->origin_id = $a_id;
423 }
424
425 function getOriginID()
426 {
427 return $this->origin_id;
428 }
429
430 /*
431 function getimportId()
432 {
433 return $this->meta_data->getImportIdentifierEntryID();
434 }*/
435
436
440 function getImportId()
441 {
442 return $this->import_id;
443 }
444
445 function setImportId($a_id)
446 {
447 $this->import_id = $a_id;
448 }
449
453 function create($a_create_meta_data = false, $a_save_media_items = true)
454 {
455 parent::create();
456
457 if (!$a_create_meta_data)
458 {
459 $this->createMetaData();
460 }
461
462 if ($a_save_media_items)
463 {
464 $media_items = $this->getMediaItems();
465 for($i=0; $i<count($media_items); $i++)
466 {
467 $item = $media_items[$i];
468 $item->setMobId($this->getId());
469 $item->setNr($i+1);
470 $item->create();
471 }
472 }
473
475
476 global $ilAppEventHandler;
477 $ilAppEventHandler->raise('Services/MediaObjects',
478 'create',
479 array('object' => $this,
480 'obj_type' => 'mob',
481 'obj_id' => $this->getId())
482 );
483 }
484
485
489 function update($a_upload=false)
490 {
491 parent::update();
492
493 if(!$a_upload)
494 {
495 $this->updateMetaData();
496 }
497
499
500 // iterate all items
501 $media_items = $this->getMediaItems();
502 $j = 1;
503 foreach($media_items as $key => $val)
504 {
505 $item = $media_items[$key];
506 if (is_object($item))
507 {
508 $item->setMobId($this->getId());
509 $item->setNr($j);
510 if ($item->getLocationType() == "Reference")
511 {
512 $item->extractUrlParameters();
513 }
514 $item->create();
515 $j++;
516 }
517 }
518
520 global $ilAppEventHandler;
521 $ilAppEventHandler->raise('Services/MediaObjects',
522 'update',
523 array('object' => $this,
524 'obj_type' => 'mob',
525 'obj_id' => $this->getId())
526 );
527 }
528
529 protected static function handleQuotaUpdate(ilObjMediaObject $a_mob)
530 {
531 global $ilSetting;
532
533 // if neither workspace nor portfolios are activated, we skip
534 // the quota update here. this due to performance reasons on installations
535 // that do not use workspace/portfolios, but heavily copy content.
536 // in extreme cases (media object in pool and personal blog, deactivate workspace, change media object,
537 // this may lead to incorrect data in the quota calculation)
538 if ($ilSetting->get("disable_personal_workspace") && !$ilSetting->get('user_portfolios'))
539 {
540 return;
541 }
542
543 $parent_obj_ids = array();
544 foreach($a_mob->getUsages() as $item)
545 {
546 $parent_obj_id = $a_mob->getParentObjectIdForUsage($item);
547 if($parent_obj_id &&
548 !in_array($parent_obj_id, $parent_obj_ids))
549 {
550 $parent_obj_ids[]= $parent_obj_id;
551 }
552 }
553
554 // we could suppress this if object is present in a (repository) media pool
555 // but this would lead to "quota-breaches" when the pool item is deleted
556 // and "suddenly" all workspace owners get filesize added to their
557 // respective quotas, regardless of current status
558
559 include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
561 $a_mob->getId(),
562 ilUtil::dirSize($a_mob->getDataDirectory()),
563 $parent_obj_ids);
564 }
565
571 static function _getDirectory($a_mob_id)
572 {
573 return ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
574 }
575
581 public static function _getURL($a_mob_id)
582 {
583 return ilUtil::getHtmlPath(ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id);
584 }
585
591 static function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
592 {
593 return ilUtil::getWebspaceDir($a_mode)."/thumbs/mm_".$a_mob_id;
594 }
595
601 static function _lookupStandardItemPath($a_mob_id, $a_url_encode = false,
602 $a_web = true)
603 {
604 return ilObjMediaObject::_lookupItemPath($a_mob_id, $a_url_encode, $a_web, "Standard");
605 }
606
612 static function _lookupItemPath($a_mob_id, $a_url_encode = false,
613 $a_web = true, $a_purpose = "")
614 {
615 if ($a_purpose == "")
616 {
617 $a_purpose = "Standard";
618 }
619 $location = ilMediaItem::_lookupLocationForMobId($a_mob_id, $a_purpose);
620 if (preg_match("/https?\:/i",$location))
621 return $location;
622
623 if ($a_url_encode)
624 $location = rawurlencode($location);
625
626 $path = ($a_web)
627 ? ILIAS_HTTP_PATH
628 : ".";
629
630 return $path."/data/".CLIENT_ID."/mobs/mm_".$a_mob_id."/".$location;
631 }
632
637 {
639 }
640
644 static function _createThumbnailDirectory($a_obj_id)
645 {
647 ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs/mm_".$a_obj_id);
648 }
649
656 function getFilesOfDirectory($a_subdir = "")
657 {
658 $a_subdir = str_replace("..", "", $a_subdir);
659 $dir = ilObjMediaObject::_getDirectory($this->getId());
660 if ($a_subdir != "")
661 {
662 $dir.= "/".$a_subdir;
663 }
664
665 $files = array();
666 if (is_dir($dir))
667 {
668 $entries = ilUtil::getDir($dir);
669 foreach ($entries as $e)
670 {
671 if (is_file($dir."/".$e["entry"]) && $e["entry"] != "." && $e["entry"] != "..")
672 {
673 $files[] = $e["entry"];
674 }
675 }
676 }
677
678 return $files;
679 }
680
681
686 function getXML($a_mode = IL_MODE_FULL, $a_inst = 0)
687 {
688 global $ilUser;
689
690 // TODO: full implementation of all parameters
691//echo "-".$a_mode."-";
692 switch ($a_mode)
693 {
694 case IL_MODE_ALIAS:
695 $xml = "<MediaObject>";
696 $xml .= "<MediaAlias OriginId=\"il__mob_".$this->getId()."\"/>";
697 $media_items = $this->getMediaItems();
698 for($i=0; $i<count($media_items); $i++)
699 {
700 $item = $media_items[$i];
701 $xml .= "<MediaAliasItem Purpose=\"".$item->getPurpose()."\">";
702
703 // Layout
704 $width = ($item->getWidth() != "")
705 ? "Width=\"".$item->getWidth()."\""
706 : "";
707 $height = ($item->getHeight() != "")
708 ? "Height=\"".$item->getHeight()."\""
709 : "";
710 $halign = ($item->getHAlign() != "")
711 ? "HorizontalAlign=\"".$item->getHAlign()."\""
712 : "";
713 $xml .= "<Layout $width $height $halign />";
714
715 // Caption
716 if ($item->getCaption() != "")
717 {
718 $xml .= "<Caption Align=\"bottom\">".
719 $this->escapeProperty($item->getCaption())."</Caption>";
720 }
721
722 // Text Representation
723 if ($item->getTextRepresentation() != "")
724 {
725 $xml .= "<TextRepresentation>".
726 $this->escapeProperty($item->getTextRepresentation())."</TextRepresentation>";
727 }
728
729 // Parameter
730 $parameters = $item->getParameters();
731 foreach ($parameters as $name => $value)
732 {
733 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
734 }
735 $xml .= $item->getMapAreasXML();
736 $xml .= "</MediaAliasItem>";
737 }
738 break;
739
740 // for output we need technical sections of meta data
741 case IL_MODE_OUTPUT:
742
743 // get first technical section
744// $meta = $this->getMetaData();
745 $xml = "<MediaObject Id=\"il__mob_".$this->getId()."\">";
746
747 $media_items = $this->getMediaItems();
748 for($i=0; $i<count($media_items); $i++)
749 {
750 $item = $media_items[$i];
751
752 $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
753
754 // Location
755 $loc = ($item->getLocationType() == "Reference")
756 ? ilUtil::secureUrl($item->getLocation())
757 : $item->getLocation();
758 $xml.= "<Location Type=\"".$item->getLocationType()."\">".
759 $this->handleAmps($loc)."</Location>";
760
761 // Format
762 $xml.= "<Format>".$item->getFormat()."</Format>";
763
764 // Layout
765 $width = ($item->getWidth() != "")
766 ? "Width=\"".$item->getWidth()."\""
767 : "";
768 $height = ($item->getHeight() != "")
769 ? "Height=\"".$item->getHeight()."\""
770 : "";
771 $halign = ($item->getHAlign() != "")
772 ? "HorizontalAlign=\"".$item->getHAlign()."\""
773 : "";
774 $xml .= "<Layout $width $height $halign />";
775
776 // Caption
777 if ($item->getCaption() != "")
778 {
779 $xml .= "<Caption Align=\"bottom\">".
780 $this->escapeProperty($item->getCaption())."</Caption>";
781 }
782
783 // Text Representation
784 if ($item->getTextRepresentation() != "")
785 {
786 $xml .= "<TextRepresentation>".
787 $this->escapeProperty($item->getTextRepresentation())."</TextRepresentation>";
788 }
789
790 // Parameter
791 $parameters = $item->getParameters();
792 foreach ($parameters as $name => $value)
793 {
794 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
795 }
796 $xml .= $item->getMapAreasXML();
797
798 // Subtitles
799 if ($item->getPurpose() == "Standard")
800 {
801 $srts = $this->getSrtFiles();
802 foreach ($srts as $srt)
803 {
804 $def = "";
805 $meta_lang = "";
806 if ($ilUser->getLanguage() != $meta_lang &&
807 $ilUser->getLanguage() == $srt["language"])
808 {
809 $def = ' Default="true" ';
810 }
811 $xml .= "<Subtitle File=\"".$srt["full_path"].
812 "\" Language=\"".$srt["language"]."\" ".$def."/>";
813 }
814 }
815 $xml .= "</MediaItem>";
816 }
817 break;
818
819 // full xml for export
820 case IL_MODE_FULL:
821
822// $meta = $this->getMetaData();
823 $xml = "<MediaObject>";
824
825 // meta data
826 include_once("Services/MetaData/classes/class.ilMD2XML.php");
827 $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
828 $md2xml->setExportMode(true);
829 $md2xml->startExport();
830 $xml.= $md2xml->getXML();
831
832 $media_items = $this->getMediaItems();
833 for($i=0; $i<count($media_items); $i++)
834 {
835 $item = $media_items[$i];
836
837 // highlight mode
838 $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
839
840 // Location
841 $xml.= "<Location Type=\"".$item->getLocationType()."\">".
842 $this->handleAmps($item->getLocation())."</Location>";
843
844 // Format
845 $xml.= "<Format>".$item->getFormat()."</Format>";
846
847 // Layout
848 $width = ($item->getWidth() != "")
849 ? "Width=\"".$item->getWidth()."\""
850 : "";
851 $height = ($item->getHeight() != "")
852 ? "Height=\"".$item->getHeight()."\""
853 : "";
854 $halign = ($item->getHAlign() != "")
855 ? "HorizontalAlign=\"".$item->getHAlign()."\""
856 : "";
857 $xml .= "<Layout $width $height $halign />";
858
859 // Caption
860 if ($item->getCaption() != "")
861 {
862 $xml .= "<Caption Align=\"bottom\">".
863 str_replace("&", "&amp;", $item->getCaption())."</Caption>";
864 }
865
866 // Text Representation
867 if ($item->getTextRepresentation() != "")
868 {
869 $xml .= "<TextRepresentation>".
870 str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
871 }
872
873 // Parameter
874 $parameters = $item->getParameters();
875 foreach ($parameters as $name => $value)
876 {
877 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
878 }
879 $xml .= $item->getMapAreasXML(true, $a_inst);
880 $xml .= "</MediaItem>";
881 }
882 break;
883 }
884 $xml .= "</MediaObject>";
885 return $xml;
886 }
887
894 protected function escapeProperty($a_value)
895 {
896 return htmlspecialchars($a_value);
897 }
898
899
903 function handleAmps($a_str)
904 {
905 $a_str = str_replace("&amp;", "&", $a_str);
906 $a_str = str_replace("&", "&amp;", $a_str);
907 return $a_str;
908 }
909
913 function exportXML(&$a_xml_writer, $a_inst = 0)
914 {
915 $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
916 }
917
918
926 function exportFiles($a_target_dir)
927 {
928 $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
929 ilUtil::makeDir($a_target_dir."/objects/".$subdir);
930
931 $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
932 ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
933//echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
934 }
935
936 function exportMediaFullscreen($a_target_dir, $pg_obj)
937 {
938 $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
939 $a_target_dir = $a_target_dir."/objects/".$subdir;
940 ilUtil::makeDir($a_target_dir);
941 $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Modules/LearningModule");
942 $tpl->setCurrentBlock("ilMedia");
943
944 //$int_links = $page_object->getInternalLinks();
945 $med_links = ilMediaItem::_getMapAreasIntLinks($this->getId());
946
947 // @todo
948 //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets());
949
950 require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
951 //$media_obj = new ilObjMediaObject($_GET["mob_id"]);
952 require_once("./Services/COPage/classes/class.ilPageObject.php");
953
954 $xml = "<dummy>";
955 // todo: we get always the first alias now (problem if mob is used multiple
956 // times in page)
957 $xml.= $pg_obj->getMediaAliasElement($this->getId());
958 $xml.= $this->getXML(IL_MODE_OUTPUT);
959 //$xml.= $link_xml;
960 $xml.="</dummy>";
961
962 //die(htmlspecialchars($xml));
963
964 $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
965 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
966 $xh = xslt_create();
967
968 //echo "<b>XML:</b>".htmlentities($xml);
969 // determine target frames for internal links
970 $wb_path = "";
971 $enlarge_path = "";
972 $params = array ('mode' => "fullscreen", 'enlarge_path' => $enlarge_path,
973 'link_params' => "ref_id=".$_GET["ref_id"],'fullscreen_link' => "",
974 'ref_id' => $_GET["ref_id"], 'webspace_path' => $wb_path);
975 $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
976 //echo xslt_error($xh);
977 xslt_free($xh);
978
979 // unmask user html
980 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
981 $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "../../css/style.css");
982 $tpl->setVariable("LOCATION_STYLESHEET", "../../css/system.css");
983 $tpl->setVariable("MEDIA_CONTENT", $output);
984 $output = $tpl->get();
985 //$output = preg_replace("/\/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
986 $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
987 $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i","../../players",$output);
988 $output = preg_replace("/\.\/".str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory())."/i","../../players",$output);
989 $output = preg_replace("/file=..\/..\/..\//i","file=../objects/".$subdir."/",$output);
990 //die(htmlspecialchars($output));
991 fwrite(fopen($a_target_dir.'/fullscreen.html','w'), $output );
992 }
993
994 function modifyExportIdentifier($a_tag, $a_param, $a_value)
995 {
996 if ($a_tag == "Identifier" && $a_param == "Entry")
997 {
998 $a_value = ilUtil::insertInstIntoID($a_value);
999 }
1000
1001 return $a_value;
1002 }
1003
1004
1006 // EDIT METHODS: these methods act on the media alias in the dom
1008
1015 function setContainsIntLink($a_contains_link)
1016 {
1017 $this->contains_int_link = $a_contains_link;
1018 }
1019
1025 {
1027 }
1028
1032 static function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1033 {
1034 global $ilDB;
1035
1036 $and_hist = "";
1037 if ($a_usage_hist_nr !== false)
1038 {
1039 $and_hist = " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
1040 }
1041
1042 $mob_ids = array();
1043 $set = $ilDB->query("SELECT id FROM mob_usage".
1044 " WHERE usage_type = ".$ilDB->quote($a_type, "text").
1045 " AND usage_id = ".$ilDB->quote($a_id, "integer").
1046 " AND usage_lang = ".$ilDB->quote($a_lang, "text").
1047 $and_hist);
1048 while($row = $ilDB->fetchAssoc($set))
1049 {
1050 $mob_ids[] = $row["id"];
1051 }
1052
1053 $q = "DELETE FROM mob_usage WHERE usage_type = ".
1054 $ilDB->quote($a_type, "text").
1055 " AND usage_id= ".$ilDB->quote($a_id, "integer").
1056 " AND usage_lang = ".$ilDB->quote($a_lang, "text").
1057 $and_hist;
1058 $ilDB->manipulate($q);
1059
1060 foreach($mob_ids as $mob_id)
1061 {
1062 self::handleQuotaUpdate(new self($mob_id));
1063 }
1064 }
1065
1069 static function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1070 {
1071 global $ilDB;
1072
1073 $lstr = "";
1074 if ($a_lang != "")
1075 {
1076 $lstr = " AND usage_lang = ".$ilDB->quote($a_lang, "text");
1077 }
1078 $hist_str = "";
1079 if ($a_usage_hist_nr !== false)
1080 {
1081 $hist_str = " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
1082 }
1083
1084 $q = "SELECT * FROM mob_usage WHERE ".
1085 "usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1086 "usage_id = ".$ilDB->quote($a_id, "integer").
1087 $lstr.$hist_str;
1088 $mobs = array();
1089 $mob_set = $ilDB->query($q);
1090 while($mob_rec = $ilDB->fetchAssoc($mob_set))
1091 {
1092 if (ilObject::_lookupType($mob_rec["id"]) == "mob")
1093 {
1094 $mobs[$mob_rec["id"]] = $mob_rec["id"];
1095 }
1096 }
1097
1098 return $mobs;
1099 }
1100
1104 static function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1105 {
1106 global $ilDB;
1107
1108 $ilDB->replace("mob_usage",
1109 array(
1110 "id" => array("integer", (int) $a_mob_id),
1111 "usage_type" => array("text", $a_type),
1112 "usage_id" => array("integer", $a_id),
1113 "usage_lang" => array("text", $a_lang),
1114 "usage_hist_nr" => array("integer", (int) $a_usage_hist_nr)
1115 ),
1116 array()
1117 );
1118
1119 self::handleQuotaUpdate(new self($a_mob_id));
1120 }
1121
1125 static function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1126 {
1127 global $ilDB;
1128
1129 $q = "DELETE FROM mob_usage WHERE ".
1130 " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
1131 " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1132 " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
1133 " usage_lang = ".$ilDB->quote($a_lang, "text")." AND ".
1134 " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
1135 $ilDB->manipulate($q);
1136
1137 self::handleQuotaUpdate(new self($a_mob_id));
1138 }
1139
1143 function getUsages($a_include_history = true)
1144 {
1145 return self::lookupUsages($this->getId(), $a_include_history);
1146 }
1147
1153 static function lookupUsages($a_id, $a_include_history = true)
1154 {
1155 global $ilDB;
1156
1157 $hist_str = "";
1158 if ($a_include_history)
1159 {
1160 $hist_str = ", usage_hist_nr";
1161 }
1162
1163 // get usages in pages
1164 $q = "SELECT DISTINCT usage_type, usage_id, usage_lang".$hist_str." FROM mob_usage WHERE id = ".
1165 $ilDB->quote($a_id, "integer");
1166
1167 if (!$a_include_history)
1168 {
1169 $q.= " AND usage_hist_nr = ".$ilDB->quote(0, "integer");
1170 }
1171
1172 $us_set = $ilDB->query($q);
1173 $ret = array();
1174 while($us_rec = $ilDB->fetchAssoc($us_set))
1175 {
1176 $ut = "";
1177 if(is_int(strpos($us_rec["usage_type"], ":")))
1178 {
1179 $us_arr = explode(":", $us_rec["usage_type"]);
1180 $ut = $us_arr[1];
1181 $ct = $us_arr[0];
1182 }
1183
1184 // check whether page exists
1185 $skip = false;
1186 if ($ut == "pg")
1187 {
1188 include_once("./Services/COPage/classes/class.ilPageObject.php");
1189 if (!ilPageObject::_exists($ct, $us_rec["usage_id"]))
1190 {
1191 $skip = true;
1192 }
1193 }
1194
1195 if (!$skip)
1196 {
1197 $ret[] = array("type" => $us_rec["usage_type"],
1198 "id" => $us_rec["usage_id"],
1199 "lang" => $us_rec["usage_lang"],
1200 "hist_nr" => $us_rec["usage_hist_nr"]);
1201 }
1202 }
1203
1204 // get usages in media pools
1205 $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = ".
1206 $ilDB->quote($a_id, "integer")." AND mep_item.type = ".$ilDB->quote("mob", "text");
1207 $us_set = $ilDB->query($q);
1208 while($us_rec = $ilDB->fetchAssoc($us_set))
1209 {
1210 $ret[] = array("type" => "mep",
1211 "id" => $us_rec["mep_id"]);
1212 }
1213
1214 // get usages in news items (media casts)
1215 include_once("./Services/News/classes/class.ilNewsItem.php");
1216 $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
1217 foreach($news_usages as $nu)
1218 {
1219 $ret[] = $nu;
1220 }
1221
1222
1223 // get usages in map areas
1224 $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area ".
1225 " WHERE area.item_id = it.id ".
1226 " AND area.link_type = ".$ilDB->quote("int", "text")." ".
1227 " AND area.target = ".$ilDB->quote("il__mob_".$a_id, "text");
1228 $us_set = $ilDB->query($q);
1229 while($us_rec = $ilDB->fetchAssoc($us_set))
1230 {
1231 $ret[] = array("type" => "map",
1232 "id" => $us_rec["mob_id"]);
1233 }
1234
1235 // get usages in personal clipboards
1236 $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
1237 foreach ($users as $user)
1238 {
1239 $ret[] = array("type" => "clip",
1240 "id" => $user);
1241 }
1242
1243 return $ret;
1244 }
1245
1251 static function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
1252 {
1253 if(is_int(strpos($a_usage["type"], ":")))
1254 {
1255 $us_arr = explode(":", $a_usage["type"]);
1256 $type = $us_arr[1];
1257 $cont_type = $us_arr[0];
1258 }
1259 else
1260 {
1261 $type = $a_usage["type"];
1262 }
1263
1264 $id = $a_usage["id"];
1265 $obj_id = false;
1266
1267 switch($type)
1268 {
1269 // RTE / tiny mce
1270 case "html":
1271
1272 switch($cont_type)
1273 {
1274 case "qpl":
1275 // Question Pool *Question* Text (Test)
1276 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1278 if ($qinfo["original_id"] > 0)
1279 {
1280 include_once("./Modules/Test/classes/class.ilObjTest.php");
1281 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1282 }
1283 else
1284 {
1285 $obj_id = $qinfo["obj_fi"]; // usage in pool
1286 }
1287 break;
1288
1289 case "spl":
1290 // Question Pool *Question* Text (Survey)
1291 include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
1293 if ($quest)
1294 {
1295 $parent_id = $quest->getObjId();
1296
1297 // pool question copy - find survey, do not use pool itself
1298 if ($quest->getOriginalId() &&
1299 ilObject::_lookupType($parent_id) == "spl")
1300 {
1302 }
1303 // original question (in pool or survey)
1304 else
1305 {
1306 $obj_id = $parent_id;
1307 }
1308
1309 unset($quest);
1310 }
1311 break;
1312
1313 case "exca":
1314 // Exercise assignment
1315 $returned_pk = $a_usage['id'];
1316 // #15995 - we are just checking against exercise object
1317 include_once 'Modules/Exercise/classes/class.ilExSubmission.php';
1318 $obj_id = ilExSubmission::lookupExerciseIdForReturnedId($returned_pk);
1319 break;
1320
1321 case "frm":
1322 // Forum
1323 $post_pk = $a_usage['id'];
1324 include_once 'Modules/Forum/classes/class.ilForumPost.php';
1325 include_once 'Modules/Forum/classes/class.ilForum.php';
1326 $oPost = new ilForumPost($post_pk);
1327 $frm_pk = $oPost->getForumId();
1328 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1329 break;
1330
1331
1332 case "frm~d":
1333 $draft_id = $a_usage['id'];
1334 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
1335 include_once 'Modules/Forum/classes/class.ilForum.php';
1336 $oDraft = ilForumPostDraft::newInstanceByDraftId($draft_id);
1337
1338 $frm_pk = $oDraft->getForumId();
1339 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1340 break;
1341 case "frm~h":
1342 $history_id = $a_usage['id'];
1343 include_once 'Modules/Forum/classes/class.ilForumDraftsHistory.php';
1344 include_once 'Modules/Forum/classes/class.ilForumPostDraft.php';
1345 include_once 'Modules/Forum/classes/class.ilForum.php';
1346 $oHistoryDraft = new ilForumDraftsHistory($history_id);
1347 $oDraft = ilForumPostDraft::newInstanceByDraftId($oHistoryDraft->getDraftId());
1348
1349 $frm_pk = $oDraft->getForumId();
1350 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1351 break;
1352 // temporary items (per user)
1353 case "frm~":
1354 case "exca~":
1355 $obj_id = $a_usage['id'];
1356 break;
1357
1358 // "old" category pages
1359 case "cat":
1360 // InfoScreen Text
1361 case "tst":
1362 case "svy":
1363 // data collection
1364 case "dcl":
1365 $obj_id = $id;
1366 break;
1367 }
1368 break;
1369
1370 // page editor
1371 case "pg":
1372
1373 switch($cont_type)
1374 {
1375 // question feedback // parent obj id is q id
1376 case "qfbg":
1377 include_once('./Services/COPage/classes/class.ilPageObject.php');
1379 // note: no break here, we only altered the $id to the question id
1380
1381 case "qpl":
1382 // Question Pool Question Pages
1383 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1385 if ($qinfo["original_id"] > 0)
1386 {
1387 include_once("./Modules/Test/classes/class.ilObjTest.php");
1388 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1389 }
1390 else
1391 {
1392 $obj_id = $qinfo["obj_fi"]; // usage in pool
1393 }
1394 if ($obj_id == 0) // this is the case, if question is in learning module -> get lm id
1395 {
1396 include_once("./Services/COPage/classes/class.ilPCQuestion.php");
1398 if ($pinfo && $pinfo["parent_type"] == "lm")
1399 {
1400 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1401 $obj_id = ilLMObject::_lookupContObjID($pinfo["page_id"]);
1402 }
1403 $pinfo = ilPCQuestion::_getPageForQuestionId($id, "sahs");
1404 if ($pinfo && $pinfo["parent_type"] == "sahs")
1405 {
1406 include_once("./Modules/SCORM2004/classes/class.ilSCORM2004Node.php");
1407 $obj_id = ilSCORM2004Node::_lookupSLMID($pinfo["page_id"]);
1408 }
1409 }
1410 break;
1411
1412 case "lm":
1413 // learning modules
1414 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1416 break;
1417
1418 case "gdf":
1419 // glossary definition
1420 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1421 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1423 $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1424 break;
1425
1426 case "wpg":
1427 // wiki page
1428 include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
1430 break;
1431
1432 case "sahs":
1433 // sahs page
1434 // can this implementation be used for other content types, too?
1435 include_once('./Services/COPage/classes/class.ilPageObject.php');
1436 $obj_id = ilPageObject::lookupParentId($id, 'sahs');
1437 break;
1438
1439 case "prtf":
1440 // portfolio
1441 include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
1443 break;
1444
1445 case "prtt":
1446 // portfolio template
1447 include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
1449 break;
1450
1451 case "blp":
1452 // blog
1453 include_once('./Services/COPage/classes/class.ilPageObject.php');
1454 $obj_id = ilPageObject::lookupParentId($id, 'blp');
1455 break;
1456
1457 case "impr":
1458 // imprint page - always id 1
1459 // fallthrough
1460
1461 case "crs":
1462 case "grp":
1463 case "cat":
1464 case "fold":
1465 case "root":
1466 case "cont":
1467 case "cstr":
1468 // repository pages
1469 $obj_id = $id;
1470 break;
1471 }
1472 break;
1473
1474 // Media Pool
1475 case "mep":
1476 $obj_id = $id;
1477 break;
1478
1479 // News Context Object (e.g. MediaCast)
1480 case "news":
1481 include_once("./Services/News/classes/class.ilNewsItem.php");
1483 break;
1484 }
1485
1486 return $obj_id;
1487 }
1488
1496 static function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1497 {
1498 $file_path = pathinfo($a_file);
1499 $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
1500 strlen($file_path["extension"]) - 1)."_".
1501 $a_width."_".
1502 $a_height.".".$file_path["extension"];
1503 $target_file = $file_path["dirname"]."/".
1504 $location;
1505 ilUtil::resizeImage($a_file, $target_file,
1506 (int) $a_width, (int) $a_height, $a_constrain_prop);
1507
1508 return $location;
1509 }
1510
1518 static function getMimeType($a_file, $a_external = false)
1519 {
1520 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1522 return $mime;
1523 }
1524
1528 static function _determineWidthHeight($a_format, $a_type,
1529 $a_file, $a_reference, $a_constrain_proportions, $a_use_original,
1530 $a_user_width, $a_user_height)
1531 {
1532 global $lng;
1533
1534 // determine width and height of known image types
1535 $width = 640;
1536 $height = 360;
1537 $info = "";
1538
1539 if ($a_format == "audio/mpeg")
1540 {
1541 $width = 300;
1542 $height = 20;
1543 }
1544
1545 if (ilUtil::deducibleSize($a_format))
1546 {
1547 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1548 if ($a_type == "File")
1549 {
1551 }
1552 else
1553 {
1554 $size = ilMediaImageUtil::getImageSize($a_reference);
1555 }
1556 }
1557
1558 if ($a_use_original)
1559 {
1560 if ($size[0] > 0 && $size[1] > 0)
1561 {
1562 //$width = $size[0];
1563 //$height = $size[1];
1564 $width = "";
1565 $height = "";
1566 }
1567 else
1568 {
1569 $info = $lng->txt("cont_could_not_determine_resource_size");
1570 }
1571 }
1572 else
1573 {
1574 $w = (int) $a_user_width;
1575 $h = (int) $a_user_height;
1576 $width = $w;
1577 $height = $h;
1578//echo "<br>C-$width-$height-";
1579 if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions)
1580 {
1581 if ($size[0] > 0 && $size[1] > 0)
1582 {
1583 if ($w > 0)
1584 {
1585 $wr = $size[0] / $w;
1586 }
1587 if ($h > 0)
1588 {
1589 $hr = $size[1] / $h;
1590 }
1591//echo "<br>+".$wr."+".$size[0]."+".$w."+";
1592//echo "<br>+".$hr."+".$size[1]."+".$h."+";
1593 $r = max($wr, $hr);
1594 if ($r > 0)
1595 {
1596 $width = (int) ($size[0]/$r);
1597 $height = (int) ($size[1]/$r);
1598 }
1599 }
1600 }
1601//echo "<br>D-$width-$height-";
1602 }
1603//echo "<br>E-$width-$height-";
1604
1605 if ($width == 0 && $a_user_width === "")
1606 {
1607 $width = "";
1608 }
1609 if ($height == 0 && $a_user_height === "")
1610 {
1611 $height = "";
1612 }
1613
1614 return array("width" => $width, "height" => $height, "info" => $info);
1615 }
1616
1621 static function _getSimpleMimeTypes()
1622 {
1623 return array("image/x-ms-bmp", "image/gif", "image/jpeg", "image/x-portable-bitmap",
1624 "image/png", "image/psd", "image/tiff", "application/pdf");
1625 }
1626
1628 {
1629 return ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
1630 }
1631
1638 static function _useAutoStartParameterOnly($a_loc, $a_format)
1639 {
1640 $lpath = pathinfo($a_loc);
1641 if ($lpath["extension"] == "mp3" && $a_format == "audio/mpeg")
1642 {
1643 return true;
1644 }
1645 if ($lpath["extension"] == "flv")
1646 {
1647 return true;
1648 }
1649 if (in_array($a_format, array("video/mp4", "video/webm")))
1650 {
1651 return true;
1652 }
1653 return false;
1654 }
1655
1659 public static function _saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
1660 {
1661 // create dummy object in db (we need an id)
1662 $media_object = new ilObjMediaObject();
1663 $media_object->setTitle($name);
1664 $media_object->setDescription("");
1665 $media_object->create();
1666
1667 // determine and create mob directory, move uploaded file to directory
1668 $media_object->createDirectory();
1669 $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1670
1671 $media_item = new ilMediaItem();
1672 $media_object->addMediaItem($media_item);
1673 $media_item->setPurpose("Standard");
1674
1675 $file = $mob_dir."/".$name;
1676 if ($upload)
1677 {
1678 ilUtil::moveUploadedFile($tmp_name,$name, $file);
1679 }
1680 else
1681 {
1682 copy($tmp_name, $file);
1683 }
1684 // get mime type
1686 $location = $name;
1687 // set real meta and object data
1688 $media_item->setFormat($format);
1689 $media_item->setLocation($location);
1690 $media_item->setLocationType("LocalFile");
1691 $media_object->setTitle($name);
1692 $media_object->setDescription($format);
1693
1694 if (ilUtil::deducibleSize($format))
1695 {
1696 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1698 $media_item->setWidth($size[0]);
1699 $media_item->setHeight($size[1]);
1700 }
1701 $media_item->setHAlign("Left");
1702
1703 self::renameExecutables($mob_dir);
1704 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1705 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1706
1707 $media_object->update();
1708
1709 return $media_object;
1710 }
1711
1715 function uploadAdditionalFile($a_name, $tmp_name, $a_subdir = "", $a_mode = "move_uploaded")
1716 {
1717 $a_subdir = str_replace("..", "", $a_subdir);
1718 $dir = $mob_dir = ilObjMediaObject::_getDirectory($this->getId());
1719 if ($a_subdir != "")
1720 {
1721 $dir.= "/".$a_subdir;
1722 }
1724 ilUtil::moveUploadedFile($tmp_name, $a_name, $dir."/".$a_name, true, $a_mode);
1725 self::renameExecutables($mob_dir);
1726 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1727 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1728
1729 }
1730
1737 function uploadSrtFile($a_tmp_name, $a_language, $a_mode = "move_uploaded")
1738 {
1739 if (is_file($a_tmp_name) && $a_language != "")
1740 {
1741 $this->uploadAdditionalFile("subtitle_".$a_language.".srt", $a_tmp_name, "srt", $a_mode);
1742 return true;
1743 }
1744 return false;
1745 }
1746
1750 function getSrtFiles()
1751 {
1752 $srt_dir = ilObjMediaObject::_getDirectory($this->getId())."/srt";
1753
1754 if (!is_dir($srt_dir))
1755 {
1756 return array();
1757 }
1758
1759 $items = ilUtil::getDir($srt_dir);
1760
1761 $srt_files = array();
1762 foreach ($items as $i)
1763 {
1764 if (!in_array($i["entry"], array(".", "..")) && $i["type"] == "file")
1765 {
1766 $name = explode(".", $i["entry"]);
1767 if ($name[1] == "srt" && substr($name[0], 0, 9) == "subtitle_")
1768 {
1769 $srt_files[] = array("file" => $i["entry"],
1770 "full_path" => "srt/".$i["entry"], "language" => substr($name[0], 9, 2));
1771 }
1772 }
1773 }
1774
1775 return $srt_files;
1776 }
1777
1781 function makeThumbnail($a_file, $a_thumbname, $a_format = "png",
1782 $a_size = "80")
1783 {
1784 $m_dir = ilObjMediaObject::_getDirectory($this->getId());
1787 ilUtil::convertImage($m_dir."/".$a_file,
1788 $t_dir."/".$a_thumbname, $a_format, $a_size);
1789 }
1790
1797 static function getThumbnailPath($a_mob_id, $a_thumbname)
1798 {
1799 $t_dir = ilObjMediaObject::_getThumbnailDirectory($a_mob_id);
1800 return $t_dir."/".$a_thumbname;
1801 }
1802
1803
1807 function removeAdditionalFile($a_file)
1808 {
1809 $file = str_replace("..", "", $a_file);
1811 if (is_file($file))
1812 {
1813 unlink($file);
1814 }
1815 }
1816
1817
1821 function getLinkedMediaObjects($a_ignore = "")
1822 {
1823 $linked = array();
1824
1825 if (!is_array($a_ignore))
1826 {
1827 $a_ignore = array();
1828 }
1829
1830 // get linked media objects (map areas)
1831 $med_items = $this->getMediaItems();
1832
1833 foreach($med_items as $med_item)
1834 {
1835 $int_links = ilMapArea::_getIntLinks($med_item->getId());
1836 foreach ($int_links as $k => $int_link)
1837 {
1838 if ($int_link["Type"] == "MediaObject")
1839 {
1840 include_once("./Services/Link/classes/class.ilInternalLink.php");
1841 $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1842 if (ilObject::_exists($l_id))
1843 {
1844 if (!in_array($l_id, $linked) &&
1845 !in_array($l_id, $a_ignore))
1846 {
1847 $linked[] = $l_id;
1848 }
1849 }
1850 }
1851 }
1852 }
1853//var_dump($linked);
1854 return $linked;
1855 }
1856
1860 static function getRestrictedFileTypes()
1861 {
1862 return array_filter(self::getAllowedFileTypes(), function ($v) {
1863 return !in_array($v, self::getForbiddenFileTypes());
1864 });
1865 }
1866
1872 static function getForbiddenFileTypes()
1873 {
1874 $mset = new ilSetting("mobs");
1875 if (trim($mset->get("black_list_file_types")) == "")
1876 {
1877 return array();
1878 }
1879 return array_map(function ($v)
1880 {
1881 return strtolower(trim($v));
1882 },
1883 explode(",", $mset->get("black_list_file_types")));
1884 }
1885
1891 static function getAllowedFileTypes()
1892 {
1893 $mset = new ilSetting("mobs");
1894 if (trim($mset->get("restricted_file_types")) == "")
1895 {
1896 return array();
1897 }
1898 return array_map(function ($v)
1899 {
1900 return strtolower(trim($v));
1901 },
1902 explode(",", $mset->get("restricted_file_types")));
1903 }
1904
1911 static function isTypeAllowed($a_type)
1912 {
1913 if (in_array($a_type, self::getForbiddenFileTypes()))
1914 {
1915 return false;
1916 }
1917 if (count(self::getAllowedFileTypes()) == 0 || in_array($a_type, self::getAllowedFileTypes()))
1918 {
1919 return true;
1920 }
1921 return false;
1922 }
1923
1924
1928 function duplicate()
1929 {
1930 $new_obj = new ilObjMediaObject();
1931 $new_obj->setTitle($this->getTitle());
1932 $new_obj->setDescription($this->getDescription());
1933
1934 // media items
1935 foreach($this->getMediaItems() as $key => $val)
1936 {
1937 $new_obj->addMediaItem($val);
1938 }
1939
1940 $new_obj->create(false, true);
1941
1942 // files
1943 $new_obj->createDirectory();
1944 self::_createThumbnailDirectory($new_obj->getId());
1946 ilObjMediaObject::_getDirectory($new_obj->getId()));
1948 ilObjMediaObject::_getThumbnailDirectory($new_obj->getId()));
1949
1950 // meta data
1951 include_once("Services/MetaData/classes/class.ilMD.php");
1952 $md = new ilMD(0, $this->getId(), "mob");
1953 $new_md = $md->cloneMD(0, $new_obj->getId(), "mob");
1954
1955 return $new_obj;
1956 }
1957
1964 function uploadVideoPreviewPic($a_prevpic)
1965 {
1966 // remove old one
1967 if ($this->getVideoPreviewPic(true) != "")
1968 {
1969 $this->removeAdditionalFile($this->getVideoPreviewPic(true));
1970 }
1971
1972 $pi = pathinfo($a_prevpic["name"]);
1973 $ext = $pi["extension"];
1974 if (in_array($ext, array("jpg", "jpeg", "png")))
1975 {
1976 $this->uploadAdditionalFile("mob_vpreview.".$ext, $a_prevpic["tmp_name"]);
1977 }
1978 }
1979
1986 function generatePreviewPic($a_width, $a_height)
1987 {
1988 $item = $this->getMediaItem("Standard");
1989
1990 if ($item->getLocationType() == "LocalFile" &&
1991 is_int(strpos($item->getFormat(), "image/")))
1992 {
1993 $dir = ilObjMediaObject::_getDirectory($this->getId());
1994 $file = $dir."/".
1995 $item->getLocation();
1996 if (is_file($file))
1997 {
1998 if(ilUtil::isConvertVersionAtLeast("6.3.8-3"))
1999 {
2000 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");
2001 }
2002 else
2003 {
2004 ilUtil::convertImage($file, $dir."/mob_vpreview.png", "PNG", $a_width."x".$a_height);
2005 }
2006 }
2007 }
2008 }
2009
2016 function getVideoPreviewPic($a_filename_only = false)
2017 {
2018 $dir = ilObjMediaObject::_getDirectory($this->getId());
2019 $ppics = array("mob_vpreview.jpg",
2020 "mob_vpreview.jpeg",
2021 "mob_vpreview.png");
2022 foreach ($ppics as $p)
2023 {
2024 if (is_file($dir."/".$p))
2025 {
2026 if ($a_filename_only)
2027 {
2028 return $p;
2029 }
2030 else
2031 {
2032 return $dir."/".$p;
2033 }
2034 }
2035 }
2036 return "";
2037 }
2038
2045 static function fixFilename($a_name)
2046 {
2047 $a_name = ilUtil::getASCIIFilename($a_name);
2048
2049 $rchars = array("`", "=", "$", "{", "}", "'", ";", " ", "(", ")");
2050 $a_name = str_replace($rchars, "_", $a_name);
2051 $a_name = str_replace("__", "_", $a_name);
2052 return $a_name;
2053 }
2054
2055
2063 {
2064 return ilObjMediaObject::_getDirectory($this->getId()."/srt/tmp");
2065 }
2066
2067
2075 {
2076 global $lng, $ilUser;
2077
2078 include_once("./Services/MediaObjects/exceptions/class.ilMediaObjectsException.php");
2079 if (!is_file($a_file["tmp_name"]))
2080 {
2081 throw new ilMediaObjectsException($lng->txt("mob_file_could_not_be_uploaded"));
2082 }
2083
2084 $dir = $this->getMultiSrtUploadDir();
2085 ilUtil::delDir($dir, true);
2087 ilUtil::moveUploadedFile($a_file["tmp_name"], "multi_srt.zip", $dir."/"."multi_srt.zip");
2088 ilUtil::unzip($dir."/multi_srt.zip", true);
2089 }
2090
2095 {
2097 }
2098
2103 {
2104 $items = array();
2105
2106 include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
2108
2109 $dir = $this->getMultiSrtUploadDir();
2110 $files = ilUtil::getDir($dir);
2111 foreach ($files as $k => $i)
2112 {
2113 // check directory
2114 if ($i["type"] == "file" && !in_array($k, array(".", "..")))
2115 {
2116 if (pathinfo($k, PATHINFO_EXTENSION) == "srt")
2117 {
2118 $lang = "";
2119 if (substr($k, strlen($k) - 7, 1) == "_")
2120 {
2121 $lang = substr($k, strlen($k) - 6, 2);
2122 if (!in_array($lang, $lang_codes))
2123 {
2124 $lang = "";
2125 }
2126 }
2127 $items[] = array("filename" => $k, "lang" => $lang);
2128 }
2129 }
2130 }
2131 return $items;
2132 }
2133
2139 static function renameExecutables($a_dir)
2140 {
2142 if (!self::isTypeAllowed("html"))
2143 {
2144 ilUtil::rRenameSuffix($a_dir, "html", "sec"); // see #20187
2145 }
2146 }
2147}
2148?>
$size
Definition: RandomTest.php:79
global $tpl
Definition: ilias.php:8
$files
Definition: add-vimline.php:18
$path
Definition: aliased.php:25
$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 _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=false)
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
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.
getXML($a_mode=IL_MODE_FULL, $a_inst=0)
get MediaObject XLM Tag
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.
makeThumbnail($a_file, $a_thumbname, $a_format="png", $a_size="80")
Make thumbnail.
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)
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.
static getMimeType($a_file, $a_external=false)
get mime type for file
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.
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
static _exists($a_id, $a_reference=false, $a_type=NULL)
checks wether a lm content object with specified id exists or not
& 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 "&".
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.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=TRUE)
Create new media object and update page in db and return new media object.
removeAllMediaItems()
remove all media items
create($a_create_meta_data=false, $a_save_media_items=true)
create media object in db
static _lookupStandardItemPath($a_mob_id, $a_url_encode=false, $a_web=true)
Get path for standard item.
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!?
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.
static _lookupItemPath($a_mob_id, $a_url_encode=false, $a_web=true, $a_purpose="")
Get path for item with specific purpose.
getDescription()
get description of 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 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 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 convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
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 lookupObjIdByPage($a_page_id)
returns the wiki/object id to a given page id
$h
$w
$r
Definition: example_031.php:79
$params
Definition: example_049.php:96
$info
Definition: example_052.php:80
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
xslt_free(&$proc)
xslt_create()
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
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 $ilDB
$mobs
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:93