ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 ilObjMediaObject($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::ilObject($a_id, false);
45 }
46
47 function setRefId()
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()
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)
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 if (!($this->getId() > 0))
103 {
104 return;
105 }
106
107 $usages = $this->getUsages();
108
109 if (count($usages) == 0)
110 {
111 // remove directory
113
114 // remove thumbnail directory
116
117 // delete meta data of mob
118 $this->deleteMetaData();
119
120 // delete media items
122
123 // this is just to make sure, there should be no entries left at
124 // this point as they depend on the usage
126
127 // delete object
128 parent::delete();
129 }
130 }
131
137 function getDescription()
138 {
139 return parent::getDescription();
140 }
141
145 function setDescription($a_description)
146 {
147 parent::setDescription($a_description);
148 }
149
161 function MDUpdateListener($a_element)
162 {
163 include_once 'Services/MetaData/classes/class.ilMD.php';
164
165 switch($a_element)
166 {
167 case 'General':
168
169 // Update Title and description
170 $md = new ilMD(0, $this->getId(), $this->getType());
171 $md_gen = $md->getGeneral();
172
173 if (is_object($md_gen))
174 {
175 ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
176 $this->setTitle($md_gen->getTitle());
177
178 foreach($md_gen->getDescriptionIds() as $id)
179 {
180 $md_des = $md_gen->getDescription($id);
181 ilObject::_writeDescription($this->getId(),$md_des->getDescription());
182 $this->setDescription($md_des->getDescription());
183 break;
184 }
185 }
186
187 break;
188
189 default:
190 }
191 return true;
192 }
193
197 function createMetaData()
198 {
199 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
200
201 global $ilUser;
202
203 $md_creator = new ilMDCreator(0, $this->getId(), $this->getType());
204 $md_creator->setTitle($this->getTitle());
205 $md_creator->setTitleLanguage($ilUser->getPref('language'));
206 $md_creator->setDescription($this->getDescription());
207 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
208 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
209 $md_creator->setLanguage($ilUser->getPref('language'));
210 $md_creator->create();
211
212 return true;
213 }
214
218 function updateMetaData()
219 {
220 include_once("Services/MetaData/classes/class.ilMD.php");
221 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
222 include_once("Services/MetaData/classes/class.ilMDDescription.php");
223
224 $md =& new ilMD(0, $this->getId(), $this->getType());
225 $md_gen =& $md->getGeneral();
226 $md_gen->setTitle($this->getTitle());
227
228 // sets first description (maybe not appropriate)
229 $md_des_ids =& $md_gen->getDescriptionIds();
230 if (count($md_des_ids) > 0)
231 {
232 $md_des =& $md_gen->getDescription($md_des_ids[0]);
233 $md_des->setDescription($this->getDescription());
234 $md_des->update();
235 }
236 $md_gen->update();
237
238 }
239
243 function deleteMetaData()
244 {
245 // Delete meta data
246 include_once('Services/MetaData/classes/class.ilMD.php');
247 $md = new ilMD(0, $this->getId(), $this->getType());
248 $md->deleteAll();
249 }
250
251
257 function addMediaItem($a_item)
258 {
259 $this->media_items[] = $a_item;
260 }
261
262
268 function &getMediaItems()
269 {
270 return $this->media_items;
271 }
272
279 function &getMediaItem($a_purpose)
280 {
281 foreach ($this->media_items as $media_item)
282 {
283 if($media_item->getPurpose() == $a_purpose)
284 {
285 return $media_item;
286 }
287 }
288 return false;
289 }
290
291
295 function removeMediaItem($a_purpose)
296 {
297 foreach ($this->media_items as $key => $media_item)
298 {
299 if($media_item->getPurpose() == $a_purpose)
300 {
301 unset($this->media_items[$key]);
302 }
303 }
304 // update numbers and keys
305 $i = 1;
306 $media_items = array();
307 foreach ($this->media_items as $media_item)
308 {
309 $media_items [$i] = $media_item;
310 $media_item->setMobId($this->getId());
311 $media_item->setNr($i);
312 $i++;
313 }
314 $this->media_items = $media_items;
315 }
316
321 {
322 $this->media_items = array();
323 }
324
325
326 function getMediaItemNr($a_purpose)
327 {
328 for($i=0; $i<count($this->media_items); $i++)
329 {
330 if($this->media_items[$i]->getPurpose() == $a_purpose)
331 {
332 return $i + 1;
333 }
334 }
335 return false;
336 }
337
338
340 {
341 return $this->hasPurposeItem("Fullscreen");
342 }
343
350 function hasPurposeItem($purpose)
351 {
352 if(is_object($this->getMediaItem($purpose)))
353 {
354 return true;
355 }
356 else
357 {
358 return false;
359 }
360 }
361
362
363
367 function read()
368 {
369//echo "<br>ilObjMediaObject:read";
370 parent::read();
371
372 // get media items
374 }
375
379 function setId($a_id)
380 {
381 $this->id = $a_id;
382 }
383
384 function getId()
385 {
386 return $this->id;
387 }
388
392 function setAlias($a_is_alias)
393 {
394 $this->is_alias = $a_is_alias;
395 }
396
397 function isAlias()
398 {
399 return $this->is_alias;
400 }
401
402 function setOriginID($a_id)
403 {
404 return $this->origin_id = $a_id;
405 }
406
407 function getOriginID()
408 {
409 return $this->origin_id;
410 }
411
412 /*
413 function getimportId()
414 {
415 return $this->meta_data->getImportIdentifierEntryID();
416 }*/
417
418
422 function getImportId()
423 {
424 return $this->import_id;
425 }
426
427 function setImportId($a_id)
428 {
429 $this->import_id = $a_id;
430 }
431
435 function create($a_create_meta_data = false, $a_save_media_items = true)
436 {
437 parent::create();
438
439 if (!$a_create_meta_data)
440 {
441 $this->createMetaData();
442 }
443
444 if ($a_save_media_items)
445 {
446 $media_items =& $this->getMediaItems();
447 for($i=0; $i<count($media_items); $i++)
448 {
449 $item =& $media_items[$i];
450 $item->setMobId($this->getId());
451 $item->setNr($i+1);
452 $item->create();
453 }
454 }
455
457
458 global $ilAppEventHandler;
459 $ilAppEventHandler->raise('Services/MediaObjects',
460 'create',
461 array('object' => $this,
462 'obj_type' => 'mob',
463 'obj_id' => $this->getId())
464 );
465 }
466
467
471 function update($a_upload=false)
472 {
473 parent::update();
474
475 if(!$a_upload)
476 {
477 $this->updateMetaData();
478 }
479
481
482 // iterate all items
483 $media_items =& $this->getMediaItems();
484 $j = 1;
485 foreach($media_items as $key => $val)
486 {
487 $item =& $media_items[$key];
488 if (is_object($item))
489 {
490 $item->setMobId($this->getId());
491 $item->setNr($j);
492 if ($item->getLocationType() == "Reference")
493 {
494 $item->extractUrlParameters();
495 }
496 $item->create();
497 $j++;
498 }
499 }
500
502
503 global $ilAppEventHandler;
504 $ilAppEventHandler->raise('Services/MediaObjects',
505 'update',
506 array('object' => $this,
507 'obj_type' => 'mob',
508 'obj_id' => $this->getId())
509 );
510
511 }
512
513 protected static function handleQuotaUpdate(ilObjMediaObject $a_mob)
514 {
515 global $ilSetting;
516
517 // if neither workspace nor portfolios are activated, we skip
518 // the quota update here. this due to performance reasons on installations
519 // that do not use workspace/portfolios, but heavily copy content.
520 // in extreme cases (media object in pool and personal blog, deactivate workspace, change media object,
521 // this may lead to incorrect data in the quota calculation)
522 if ($ilSetting->get("disable_personal_workspace") && !$ilSetting->get('user_portfolios'))
523 {
524 return;
525 }
526
527 $parent_obj_ids = array();
528 foreach($a_mob->getUsages() as $item)
529 {
530 $parent_obj_id = $a_mob->getParentObjectIdForUsage($item);
531 if($parent_obj_id &&
532 !in_array($parent_obj_id, $parent_obj_ids))
533 {
534 $parent_obj_ids[]= $parent_obj_id;
535 }
536 }
537
538 // we could suppress this if object is present in a (repository) media pool
539 // but this would lead to "quota-breaches" when the pool item is deleted
540 // and "suddenly" all workspace owners get filesize added to their
541 // respective quotas, regardless of current status
542
543 include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
545 $a_mob->getId(),
546 ilUtil::dirSize($a_mob->getDataDirectory()),
547 $parent_obj_ids);
548 }
549
555 function _getDirectory($a_mob_id)
556 {
557 return ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
558 }
559
565 function _getURL($a_mob_id)
566 {
567 return ilUtil::getHtmlPath(ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id);
568 }
569
575 function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
576 {
577 return ilUtil::getWebspaceDir($a_mode)."/thumbs/mm_".$a_mob_id;
578 }
579
585 static function _lookupStandardItemPath($a_mob_id, $a_url_encode = false,
586 $a_web = true)
587 {
588 return ilObjMediaObject::_lookupItemPath($a_mob_id, $a_url_encode, $a_web, "Standard");
589 }
590
596 static function _lookupItemPath($a_mob_id, $a_url_encode = false,
597 $a_web = true, $a_purpose = "")
598 {
599 if ($a_purpose == "")
600 {
601 $a_purpose = "Standard";
602 }
603 $location = ilMediaItem::_lookupLocationForMobId($a_mob_id, $a_purpose);
604 if (preg_match("/https?\:/i",$location))
605 return $location;
606
607 if ($a_url_encode)
608 $location = rawurlencode($location);
609
610 $path = ($a_web)
611 ? ILIAS_HTTP_PATH
612 : ".";
613
614 return $path."/data/".CLIENT_ID."/mobs/mm_".$a_mob_id."/".$location;
615 }
616
621 {
623 }
624
628 function _createThumbnailDirectory($a_obj_id)
629 {
631 ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs/mm_".$a_obj_id);
632 }
633
640 function getFilesOfDirectory($a_subdir = "")
641 {
642 $a_subdir = str_replace("..", "", $a_subdir);
643 $dir = ilObjMediaObject::_getDirectory($this->getId());
644 if ($a_subdir != "")
645 {
646 $dir.= "/".$a_subdir;
647 }
648
649 $files = array();
650 if (is_dir($dir))
651 {
652 $entries = ilUtil::getDir($dir);
653 foreach ($entries as $e)
654 {
655 if (is_file($dir."/".$e["entry"]) && $e["entry"] != "." && $e["entry"] != "..")
656 {
657 $files[] = $e["entry"];
658 }
659 }
660 }
661
662 return $files;
663 }
664
665
670 function getXML($a_mode = IL_MODE_FULL, $a_inst = 0)
671 {
672 global $ilUser;
673
674 // TODO: full implementation of all parameters
675//echo "-".$a_mode."-";
676 switch ($a_mode)
677 {
678 case IL_MODE_ALIAS:
679 $xml = "<MediaObject>";
680 $xml .= "<MediaAlias OriginId=\"il__mob_".$this->getId()."\"/>";
681 $media_items =& $this->getMediaItems();
682 for($i=0; $i<count($media_items); $i++)
683 {
684 $item =& $media_items[$i];
685 $xml .= "<MediaAliasItem Purpose=\"".$item->getPurpose()."\">";
686
687 // Layout
688 $width = ($item->getWidth() != "")
689 ? "Width=\"".$item->getWidth()."\""
690 : "";
691 $height = ($item->getHeight() != "")
692 ? "Height=\"".$item->getHeight()."\""
693 : "";
694 $halign = ($item->getHAlign() != "")
695 ? "HorizontalAlign=\"".$item->getHAlign()."\""
696 : "";
697 $xml .= "<Layout $width $height $halign />";
698
699 // Caption
700 if ($item->getCaption() != "")
701 {
702 $xml .= "<Caption Align=\"bottom\">".
703 str_replace("&", "&amp;", $item->getCaption())."</Caption>";
704 }
705
706 // Text Representation
707 if ($item->getTextRepresentation() != "")
708 {
709 $xml .= "<TextRepresentation>".
710 str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
711 }
712
713 // Parameter
714 $parameters = $item->getParameters();
715 foreach ($parameters as $name => $value)
716 {
717 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
718 }
719 $xml .= $item->getMapAreasXML();
720 $xml .= "</MediaAliasItem>";
721 }
722 break;
723
724 // for output we need technical sections of meta data
725 case IL_MODE_OUTPUT:
726
727 // get first technical section
728// $meta =& $this->getMetaData();
729 $xml = "<MediaObject Id=\"il__mob_".$this->getId()."\">";
730
731 $media_items =& $this->getMediaItems();
732 for($i=0; $i<count($media_items); $i++)
733 {
734 $item =& $media_items[$i];
735
736 $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
737
738 // Location
739 $xml.= "<Location Type=\"".$item->getLocationType()."\">".
740 $this->handleAmps($item->getLocation())."</Location>";
741
742 // Format
743 $xml.= "<Format>".$item->getFormat()."</Format>";
744
745 // Layout
746 $width = ($item->getWidth() != "")
747 ? "Width=\"".$item->getWidth()."\""
748 : "";
749 $height = ($item->getHeight() != "")
750 ? "Height=\"".$item->getHeight()."\""
751 : "";
752 $halign = ($item->getHAlign() != "")
753 ? "HorizontalAlign=\"".$item->getHAlign()."\""
754 : "";
755 $xml .= "<Layout $width $height $halign />";
756
757 // Caption
758 if ($item->getCaption() != "")
759 {
760 $xml .= "<Caption Align=\"bottom\">".
761 str_replace("&", "&amp;", $item->getCaption())."</Caption>";
762 }
763
764 // Text Representation
765 if ($item->getTextRepresentation() != "")
766 {
767 $xml .= "<TextRepresentation>".
768 str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
769 }
770
771 // Parameter
772 $parameters = $item->getParameters();
773 foreach ($parameters as $name => $value)
774 {
775 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
776 }
777 $xml .= $item->getMapAreasXML();
778
779 // Subtitles
780 if ($item->getPurpose() == "Standard")
781 {
782 $srts = $this->getSrtFiles();
783 foreach ($srts as $srt)
784 {
785 $def = "";
786 $meta_lang = "";
787 if ($ilUser->getLanguage() != $meta_lang &&
788 $ilUser->getLanguage() == $srt["language"])
789 {
790 $def = ' Default="true" ';
791 }
792 $xml .= "<Subtitle File=\"".$srt["full_path"].
793 "\" Language=\"".$srt["language"]."\" ".$def."/>";
794 }
795 }
796 $xml .= "</MediaItem>";
797 }
798 break;
799
800 // full xml for export
801 case IL_MODE_FULL:
802
803// $meta =& $this->getMetaData();
804 $xml = "<MediaObject>";
805
806 // meta data
807 include_once("Services/MetaData/classes/class.ilMD2XML.php");
808 $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
809 $md2xml->setExportMode(true);
810 $md2xml->startExport();
811 $xml.= $md2xml->getXML();
812
813 $media_items =& $this->getMediaItems();
814 for($i=0; $i<count($media_items); $i++)
815 {
816 $item =& $media_items[$i];
817
818 // highlight mode
819 $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
820
821 // Location
822 $xml.= "<Location Type=\"".$item->getLocationType()."\">".
823 $this->handleAmps($item->getLocation())."</Location>";
824
825 // Format
826 $xml.= "<Format>".$item->getFormat()."</Format>";
827
828 // Layout
829 $width = ($item->getWidth() != "")
830 ? "Width=\"".$item->getWidth()."\""
831 : "";
832 $height = ($item->getHeight() != "")
833 ? "Height=\"".$item->getHeight()."\""
834 : "";
835 $halign = ($item->getHAlign() != "")
836 ? "HorizontalAlign=\"".$item->getHAlign()."\""
837 : "";
838 $xml .= "<Layout $width $height $halign />";
839
840 // Caption
841 if ($item->getCaption() != "")
842 {
843 $xml .= "<Caption Align=\"bottom\">".
844 str_replace("&", "&amp;", $item->getCaption())."</Caption>";
845 }
846
847 // Text Representation
848 if ($item->getTextRepresentation() != "")
849 {
850 $xml .= "<TextRepresentation>".
851 str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
852 }
853
854 // Parameter
855 $parameters = $item->getParameters();
856 foreach ($parameters as $name => $value)
857 {
858 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
859 }
860 $xml .= $item->getMapAreasXML(true, $a_inst);
861 $xml .= "</MediaItem>";
862 }
863 break;
864 }
865 $xml .= "</MediaObject>";
866 return $xml;
867 }
868
872 function handleAmps($a_str)
873 {
874 $a_str = str_replace("&amp;", "&", $a_str);
875 $a_str = str_replace("&", "&amp;", $a_str);
876 return $a_str;
877 }
878
882 function exportXML(&$a_xml_writer, $a_inst = 0)
883 {
884 $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
885 }
886
887
895 function exportFiles($a_target_dir)
896 {
897 $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
898 ilUtil::makeDir($a_target_dir."/objects/".$subdir);
899
900 $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
901 ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
902//echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
903 }
904
905 function exportMediaFullscreen($a_target_dir, $pg_obj)
906 {
907 $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
908 $a_target_dir = $a_target_dir."/objects/".$subdir;
909 ilUtil::makeDir($a_target_dir);
910 $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Modules/LearningModule");
911 $tpl->setCurrentBlock("ilMedia");
912
913 //$int_links = $page_object->getInternalLinks();
914 $med_links = ilMediaItem::_getMapAreasIntLinks($this->getId());
915
916 // @todo
917 //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets());
918
919 require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
920 //$media_obj = new ilObjMediaObject($_GET["mob_id"]);
921 require_once("./Services/COPage/classes/class.ilPageObject.php");
922
923 $xml = "<dummy>";
924 // todo: we get always the first alias now (problem if mob is used multiple
925 // times in page)
926 $xml.= $pg_obj->getMediaAliasElement($this->getId());
927 $xml.= $this->getXML(IL_MODE_OUTPUT);
928 //$xml.= $link_xml;
929 $xml.="</dummy>";
930
931 //die(htmlspecialchars($xml));
932
933 $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
934 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
935 $xh = xslt_create();
936
937 //echo "<b>XML:</b>".htmlentities($xml);
938 // determine target frames for internal links
939 $wb_path = "";
940 $enlarge_path = "";
941 $params = array ('mode' => "fullscreen", 'enlarge_path' => $enlarge_path,
942 'link_params' => "ref_id=".$_GET["ref_id"],'fullscreen_link' => "",
943 'ref_id' => $_GET["ref_id"], 'webspace_path' => $wb_path);
944 $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
945 //echo xslt_error($xh);
946 xslt_free($xh);
947
948 // unmask user html
949 include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
950 $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "../../css/style.css");
951 $tpl->setVariable("LOCATION_STYLESHEET", "../../css/system.css");
952 $tpl->setVariable("MEDIA_CONTENT", $output);
953 $output = $tpl->get();
954 //$output = preg_replace("/\/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
955 $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
956 $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i","../../players",$output);
957 $output = preg_replace("/\.\/".str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory())."/i","../../players",$output);
958 $output = preg_replace("/file=..\/..\/..\//i","file=../objects/".$subdir."/",$output);
959 //die(htmlspecialchars($output));
960 fwrite(fopen($a_target_dir.'/fullscreen.html','w'), $output );
961 }
962
963 function modifyExportIdentifier($a_tag, $a_param, $a_value)
964 {
965 if ($a_tag == "Identifier" && $a_param == "Entry")
966 {
967 $a_value = ilUtil::insertInstIntoID($a_value);
968 }
969
970 return $a_value;
971 }
972
973
975 // EDIT METHODS: these methods act on the media alias in the dom
977
984 function setContainsIntLink($a_contains_link)
985 {
986 $this->contains_int_link = $a_contains_link;
987 }
988
994 {
996 }
997
1001 function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1002 {
1003 global $ilDB;
1004
1005 $and_hist = "";
1006 if ($a_usage_hist_nr !== false)
1007 {
1008 $and_hist = " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
1009 }
1010
1011 $mob_ids = array();
1012 $set = $ilDB->query("SELECT id FROM mob_usage".
1013 " WHERE usage_type = ".$ilDB->quote($a_type, "text").
1014 " AND usage_id = ".$ilDB->quote($a_id, "integer").
1015 " AND usage_lang = ".$ilDB->quote($a_lang, "text").
1016 $and_hist);
1017 while($row = $ilDB->fetchAssoc($set))
1018 {
1019 $mob_ids[] = $row["id"];
1020 }
1021
1022 $q = "DELETE FROM mob_usage WHERE usage_type = ".
1023 $ilDB->quote($a_type, "text").
1024 " AND usage_id= ".$ilDB->quote($a_id, "integer").
1025 " AND usage_lang = ".$ilDB->quote($a_lang, "text").
1026 $and_hist;
1027 $ilDB->manipulate($q);
1028
1029 foreach($mob_ids as $mob_id)
1030 {
1031 self::handleQuotaUpdate(new self($mob_id));
1032 }
1033 }
1034
1038 function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1039 {
1040 global $ilDB;
1041
1042 $lstr = "";
1043 if ($a_lang != "")
1044 {
1045 $lstr = " AND usage_lang = ".$ilDB->quote($a_lang, "text");
1046 }
1047 $hist_str = "";
1048 if ($a_usage_hist_nr !== false)
1049 {
1050 $hist_str = " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
1051 }
1052
1053 $q = "SELECT * FROM mob_usage WHERE ".
1054 "usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1055 "usage_id = ".$ilDB->quote($a_id, "integer").
1056 $lstr.$hist_str;
1057 $mobs = array();
1058 $mob_set = $ilDB->query($q);
1059 while($mob_rec = $ilDB->fetchAssoc($mob_set))
1060 {
1061 if (ilObject::_lookupType($mob_rec["id"]) == "mob")
1062 {
1063 $mobs[$mob_rec["id"]] = $mob_rec["id"];
1064 }
1065 }
1066
1067 return $mobs;
1068 }
1069
1073 function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1074 {
1075 global $ilDB;
1076
1077 $ilDB->replace("mob_usage",
1078 array(
1079 "id" => array("integer", (int) $a_mob_id),
1080 "usage_type" => array("text", $a_type),
1081 "usage_id" => array("integer", $a_id),
1082 "usage_lang" => array("text", $a_lang),
1083 "usage_hist_nr" => array("integer", (int) $a_usage_hist_nr)
1084 ),
1085 array()
1086 );
1087
1088 self::handleQuotaUpdate(new self($a_mob_id));
1089 }
1090
1094 function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1095 {
1096 global $ilDB;
1097
1098 $q = "DELETE FROM mob_usage WHERE ".
1099 " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
1100 " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1101 " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
1102 " usage_lang = ".$ilDB->quote($a_lang, "text")." AND ".
1103 " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
1104 $ilDB->manipulate($q);
1105
1106 self::handleQuotaUpdate(new self($a_mob_id));
1107 }
1108
1112 function getUsages($a_include_history = true)
1113 {
1114 return $this->lookupUsages($this->getId(), $a_include_history);
1115 }
1116
1122 function lookupUsages($a_id, $a_include_history = true)
1123 {
1124 global $ilDB;
1125
1126 $hist_str = "";
1127 if ($a_include_history)
1128 {
1129 $hist_str = ", usage_hist_nr";
1130 }
1131
1132 // get usages in pages
1133 $q = "SELECT DISTINCT usage_type, usage_id, usage_lang".$hist_str." FROM mob_usage WHERE id = ".
1134 $ilDB->quote($a_id, "integer");
1135
1136 if (!$a_include_history)
1137 {
1138 $q.= " AND usage_hist_nr = ".$ilDB->quote(0, "integer");
1139 }
1140
1141 $us_set = $ilDB->query($q);
1142 $ret = array();
1143 while($us_rec = $ilDB->fetchAssoc($us_set))
1144 {
1145 $ut = "";
1146 if(is_int(strpos($us_rec["usage_type"], ":")))
1147 {
1148 $us_arr = explode(":", $us_rec["usage_type"]);
1149 $ut = $us_arr[1];
1150 $ct = $us_arr[0];
1151 }
1152
1153 // check whether page exists
1154 $skip = false;
1155 if ($ut == "pg")
1156 {
1157 include_once("./Services/COPage/classes/class.ilPageObject.php");
1158 if (!ilPageObject::_exists($ct, $us_rec["usage_id"]))
1159 {
1160 $skip = true;
1161 }
1162 }
1163
1164 if (!$skip)
1165 {
1166 $ret[] = array("type" => $us_rec["usage_type"],
1167 "id" => $us_rec["usage_id"],
1168 "lang" => $us_rec["usage_lang"],
1169 "hist_nr" => $us_rec["usage_hist_nr"]);
1170 }
1171 }
1172
1173 // get usages in media pools
1174 $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = ".
1175 $ilDB->quote($a_id, "integer")." AND mep_item.type = ".$ilDB->quote("mob", "text");
1176 $us_set = $ilDB->query($q);
1177 while($us_rec = $ilDB->fetchAssoc($us_set))
1178 {
1179 $ret[] = array("type" => "mep",
1180 "id" => $us_rec["mep_id"]);
1181 }
1182
1183 // get usages in news items (media casts)
1184 include_once("./Services/News/classes/class.ilNewsItem.php");
1185 $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
1186 foreach($news_usages as $nu)
1187 {
1188 $ret[] = $nu;
1189 }
1190
1191
1192 // get usages in map areas
1193 $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area ".
1194 " WHERE area.item_id = it.id ".
1195 " AND area.link_type = ".$ilDB->quote("int", "text")." ".
1196 " AND area.target = ".$ilDB->quote("il__mob_".$a_id, "text");
1197 $us_set = $ilDB->query($q);
1198 while($us_rec = $ilDB->fetchAssoc($us_set))
1199 {
1200 $ret[] = array("type" => "map",
1201 "id" => $us_rec["mob_id"]);
1202 }
1203
1204 // get usages in personal clipboards
1205 $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
1206 foreach ($users as $user)
1207 {
1208 $ret[] = array("type" => "clip",
1209 "id" => $user);
1210 }
1211
1212 return $ret;
1213 }
1214
1220 function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
1221 {
1222 if(is_int(strpos($a_usage["type"], ":")))
1223 {
1224 $us_arr = explode(":", $a_usage["type"]);
1225 $type = $us_arr[1];
1226 $cont_type = $us_arr[0];
1227 }
1228 else
1229 {
1230 $type = $a_usage["type"];
1231 }
1232
1233 $id = $a_usage["id"];
1234 $obj_id = false;
1235
1236 switch($type)
1237 {
1238 // RTE / tiny mce
1239 case "html":
1240
1241 switch($cont_type)
1242 {
1243 case "qpl":
1244 // Question Pool *Question* Text (Test)
1245 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1247 if ($qinfo["original_id"] > 0)
1248 {
1249 include_once("./Modules/Test/classes/class.ilObjTest.php");
1250 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1251 }
1252 else
1253 {
1254 $obj_id = $qinfo["obj_fi"]; // usage in pool
1255 }
1256 break;
1257
1258 case "spl":
1259 // Question Pool *Question* Text (Survey)
1260 include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
1262 if ($quest)
1263 {
1264 $parent_id = $quest->getObjId();
1265
1266 // pool question copy - find survey, do not use pool itself
1267 if ($quest->getOriginalId() &&
1268 ilObject::_lookupType($parent_id) == "spl")
1269 {
1271 }
1272 // original question (in pool or survey)
1273 else
1274 {
1275 $obj_id = $parent_id;
1276 }
1277
1278 unset($quest);
1279 }
1280 break;
1281
1282 case "exca":
1283 // Exercise assignment
1284 $returned_pk = $a_usage['id'];
1285 // we are just checking against exercise object
1286 include_once 'Modules/Exercise/classes/class.ilObjExercise.php';
1287 $obj_id = ilObjExercise::lookupExerciseIdForReturnedId($returned_pk);
1288 break;
1289
1290 case "frm":
1291 // Forum
1292 $post_pk = $a_usage['id'];
1293 include_once 'Modules/Forum/classes/class.ilForumPost.php';
1294 include_once 'Modules/Forum/classes/class.ilForum.php';
1295 $oPost = new ilForumPost($post_pk);
1296 $frm_pk = $oPost->getForumId();
1297 $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1298 break;
1299
1300 // temporary items (per user)
1301 case "frm~":
1302 case "exca~":
1303 $obj_id = $a_usage['id'];
1304 break;
1305
1306 // "old" category pages
1307 case "cat":
1308 // InfoScreen Text
1309 case "tst":
1310 case "svy":
1311 // data collection
1312 case "dcl":
1313 $obj_id = $id;
1314 break;
1315 }
1316 break;
1317
1318 // page editor
1319 case "pg":
1320
1321 switch($cont_type)
1322 {
1323 // question feedback // parent obj id is q id
1324 case "qfbg":
1325 include_once('./Services/COPage/classes/class.ilPageObject.php');
1327 // note: no break here, we only altered the $id to the question id
1328
1329 case "qpl":
1330 // Question Pool Question Pages
1331 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1333 if ($qinfo["original_id"] > 0)
1334 {
1335 include_once("./Modules/Test/classes/class.ilObjTest.php");
1336 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1337 }
1338 else
1339 {
1340 $obj_id = $qinfo["obj_fi"]; // usage in pool
1341 }
1342 if ($obj_id == 0) // this is the case, if question is in learning module -> get lm id
1343 {
1344 include_once("./Services/COPage/classes/class.ilPCQuestion.php");
1346 if ($pinfo && $pinfo["parent_type"] == "lm")
1347 {
1348 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1349 $obj_id = ilLMObject::_lookupContObjID($pinfo["page_id"]);
1350 }
1351 $pinfo = ilPCQuestion::_getPageForQuestionId($id, "sahs");
1352 if ($pinfo && $pinfo["parent_type"] == "sahs")
1353 {
1354 include_once("./Modules/SCORM2004/classes/class.ilSCORM2004Node.php");
1355 $obj_id = ilSCORM2004Node::_lookupSLMID($pinfo["page_id"]);
1356 }
1357 }
1358 break;
1359
1360 case "lm":
1361 case "dbk":
1362 // learning modules
1363 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1365 break;
1366
1367 case "gdf":
1368 // glossary definition
1369 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1370 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1372 $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1373 break;
1374
1375 case "wpg":
1376 // wiki page
1377 include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
1379 break;
1380
1381 case "sahs":
1382 // sahs page
1383 // can this implementation be used for other content types, too?
1384 include_once('./Services/COPage/classes/class.ilPageObject.php');
1385 $obj_id = ilPageObject::lookupParentId($id, 'sahs');
1386 break;
1387
1388 case "prtf":
1389 // portfolio
1390 include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
1392 break;
1393
1394 case "prtt":
1395 // portfolio template
1396 include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
1398 break;
1399
1400 case "blp":
1401 // blog
1402 include_once('./Services/COPage/classes/class.ilPageObject.php');
1403 $obj_id = ilPageObject::lookupParentId($id, 'blp');
1404 break;
1405
1406 case "impr":
1407 // imprint page - always id 1
1408 // fallthrough
1409
1410 case "crs":
1411 case "grp":
1412 case "cat":
1413 case "fold":
1414 case "root":
1415 case "cont":
1416 case "cstr":
1417 // repository pages
1418 $obj_id = $id;
1419 break;
1420 }
1421 break;
1422
1423 // Media Pool
1424 case "mep":
1425 $obj_id = $id;
1426 break;
1427
1428 // News Context Object (e.g. MediaCast)
1429 case "news":
1430 include_once("./Services/News/classes/class.ilNewsItem.php");
1432 break;
1433 }
1434
1435 return $obj_id;
1436 }
1437
1445 function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1446 {
1447 $file_path = pathinfo($a_file);
1448 $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
1449 strlen($file_path["extension"]) - 1)."_".
1450 $a_width."_".
1451 $a_height.".".$file_path["extension"];
1452 $target_file = $file_path["dirname"]."/".
1453 $location;
1454 ilUtil::resizeImage($a_file, $target_file,
1455 (int) $a_width, (int) $a_height, $a_constrain_prop);
1456
1457 return $location;
1458 }
1459
1467 static function getMimeType($a_file)
1468 {
1469 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1470 $mime = ilMimeTypeUtil::getMimeType($a_file);
1471 return $mime;
1472 }
1473
1477 static function _determineWidthHeight($a_def_width, $a_def_height, $a_format, $a_type,
1478 $a_file, $a_reference, $a_constrain_proportions, $a_use_original,
1479 $a_user_width, $a_user_height)
1480 {
1481 global $lng;
1482
1483 // determine width and height of known image types
1484 $width = $a_def_width;
1485 $height = $a_def_height;
1486 $info = "";
1487
1488 if ($a_format == "audio/mpeg")
1489 {
1490 $width = 300;
1491 $height = 20;
1492 }
1493
1494 if (ilUtil::deducibleSize($a_format))
1495 {
1496 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1497 if ($a_type == "File")
1498 {
1500 }
1501 else
1502 {
1503 $size = ilMediaImageUtil::getImageSize($a_reference);
1504 }
1505 }
1506
1507 if ($a_use_original)
1508 {
1509 if ($size[0] > 0 && $size[1] > 0)
1510 {
1511 $width = $size[0];
1512 $height = $size[1];
1513 }
1514 else
1515 {
1516 $info = $lng->txt("cont_could_not_determine_resource_size");
1517 }
1518 }
1519 else
1520 {
1521 $w = (int) $a_user_width;
1522 $h = (int) $a_user_height;
1523 $width = $w;
1524 $height = $h;
1525//echo "<br>C-$width-$height-";
1526 if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions)
1527 {
1528 if ($size[0] > 0 && $size[1] > 0)
1529 {
1530 if ($w > 0)
1531 {
1532 $wr = $size[0] / $w;
1533 }
1534 if ($h > 0)
1535 {
1536 $hr = $size[1] / $h;
1537 }
1538//echo "<br>+".$wr."+".$size[0]."+".$w."+";
1539//echo "<br>+".$hr."+".$size[1]."+".$h."+";
1540 $r = max($wr, $hr);
1541 if ($r > 0)
1542 {
1543 $width = (int) ($size[0]/$r);
1544 $height = (int) ($size[1]/$r);
1545 }
1546 }
1547 }
1548//echo "<br>D-$width-$height-";
1549 }
1550//echo "<br>E-$width-$height-";
1551 return array("width" => $width, "height" => $height, "info" => $info);
1552 }
1553
1558 static function _getSimpleMimeTypes()
1559 {
1560 return array("image/x-ms-bmp", "image/gif", "image/jpeg", "image/x-portable-bitmap",
1561 "image/png", "image/psd", "image/tiff", "application/pdf");
1562 }
1563
1565 {
1566 return ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
1567 }
1568
1575 static function _useAutoStartParameterOnly($a_loc, $a_format)
1576 {
1577 $lpath = pathinfo($a_loc);
1578 if ($lpath["extension"] == "mp3" && $a_format == "audio/mpeg")
1579 {
1580 return true;
1581 }
1582 if ($lpath["extension"] == "flv")
1583 {
1584 return true;
1585 }
1586 if (in_array($a_format, array("video/mp4", "video/webm")))
1587 {
1588 return true;
1589 }
1590 return false;
1591 }
1592
1596 function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
1597 {
1598 // create dummy object in db (we need an id)
1599 $media_object = new ilObjMediaObject();
1600 $media_object->setTitle($name);
1601 $media_object->setDescription("");
1602 $media_object->create();
1603
1604 // determine and create mob directory, move uploaded file to directory
1605 $media_object->createDirectory();
1606 $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1607
1608 $media_item =& new ilMediaItem();
1609 $media_object->addMediaItem($media_item);
1610 $media_item->setPurpose("Standard");
1611
1612 $file = $mob_dir."/".$name;
1613 if ($upload)
1614 {
1615 ilUtil::moveUploadedFile($tmp_name,$name, $file);
1616 }
1617 else
1618 {
1619 copy($tmp_name, $file);
1620 }
1621 // get mime type
1623 $location = $name;
1624 // set real meta and object data
1625 $media_item->setFormat($format);
1626 $media_item->setLocation($location);
1627 $media_item->setLocationType("LocalFile");
1628 $media_object->setTitle($name);
1629 $media_object->setDescription($format);
1630
1631 if (ilUtil::deducibleSize($format))
1632 {
1633 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1635 $media_item->setWidth($size[0]);
1636 $media_item->setHeight($size[1]);
1637 }
1638 $media_item->setHAlign("Left");
1639
1640 self::renameExecutables($mob_dir);
1641 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1642 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1643
1644 $media_object->update();
1645
1646 return $media_object;
1647 }
1648
1652 function uploadAdditionalFile($a_name, $tmp_name, $a_subdir = "")
1653 {
1654 $a_subdir = str_replace("..", "", $a_subdir);
1655 $dir = $mob_dir = ilObjMediaObject::_getDirectory($this->getId());
1656 if ($a_subdir != "")
1657 {
1658 $dir.= "/".$a_subdir;
1659 }
1661 ilUtil::moveUploadedFile($tmp_name, $a_name, $dir."/".$a_name);
1662 self::renameExecutables($mob_dir);
1663 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1664 ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1665
1666 }
1667
1674 function uploadSrtFile($a_tmp_name, $a_language)
1675 {
1676 if (is_file($a_tmp_name) && $a_language != "")
1677 {
1678 $this->uploadAdditionalFile("subtitle_".$a_language.".srt", $a_tmp_name, "srt");
1679 return true;
1680 }
1681 return false;
1682 }
1683
1687 function getSrtFiles()
1688 {
1689 $srt_dir = ilObjMediaObject::_getDirectory($this->getId())."/srt";
1690
1691 if (!is_dir($srt_dir))
1692 {
1693 return array();
1694 }
1695
1696 $items = ilUtil::getDir($srt_dir);
1697
1698 $srt_files = array();
1699 foreach ($items as $i)
1700 {
1701 if (!in_array($i["entry"], array(".", "..")) && $i["type"] == "file")
1702 {
1703 $name = explode(".", $i["entry"]);
1704 if ($name[1] == "srt" && substr($name[0], 0, 9) == "subtitle_")
1705 {
1706 $srt_files[] = array("file" => $i["entry"],
1707 "full_path" => "srt/".$i["entry"], "language" => substr($name[0], 9, 2));
1708 }
1709 }
1710 }
1711
1712 return $srt_files;
1713 }
1714
1718 function makeThumbnail($a_file, $a_thumbname, $a_format = "png",
1719 $a_size = "80")
1720 {
1721 $m_dir = ilObjMediaObject::_getDirectory($this->getId());
1724 ilUtil::convertImage($m_dir."/".$a_file,
1725 $t_dir."/".$a_thumbname, $a_format, $a_size);
1726 }
1727
1734 static function getThumbnailPath($a_mob_id, $a_thumbname)
1735 {
1736 $t_dir = ilObjMediaObject::_getThumbnailDirectory($a_mob_id);
1737 return $t_dir."/".$a_thumbname;
1738 }
1739
1740
1744 function removeAdditionalFile($a_file)
1745 {
1746 $file = str_replace("..", "", $a_file);
1748 if (is_file($file))
1749 {
1750 unlink($file);
1751 }
1752 }
1753
1754
1758 function getLinkedMediaObjects($a_ignore = "")
1759 {
1760 $linked = array();
1761
1762 if (!is_array($a_ignore))
1763 {
1764 $a_ignore = array();
1765 }
1766
1767 // get linked media objects (map areas)
1768 $med_items = $this->getMediaItems();
1769
1770 foreach($med_items as $med_item)
1771 {
1772 $int_links = ilMapArea::_getIntLinks($med_item->getId());
1773 foreach ($int_links as $k => $int_link)
1774 {
1775 if ($int_link["Type"] == "MediaObject")
1776 {
1777 include_once("./Services/Link/classes/class.ilInternalLink.php");
1778 $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1779 if (ilObject::_exists($l_id))
1780 {
1781 if (!in_array($l_id, $linked) &&
1782 !in_array($l_id, $a_ignore))
1783 {
1784 $linked[] = $l_id;
1785 }
1786 }
1787 }
1788 }
1789 }
1790//var_dump($linked);
1791 return $linked;
1792 }
1793
1797 static function getRestrictedFileTypes()
1798 {
1799 return array_filter(self::getAllowedFileTypes(), function ($v) {
1800 return !in_array($v, self::getForbiddenFileTypes());
1801 });
1802 }
1803
1809 static function getForbiddenFileTypes()
1810 {
1811 $mset = new ilSetting("mobs");
1812 if (trim($mset->get("black_list_file_types")) == "")
1813 {
1814 return array();
1815 }
1816 return array_map(function ($v)
1817 {
1818 return strtolower(trim($v));
1819 },
1820 explode(",", $mset->get("black_list_file_types")));
1821 }
1822
1828 static function getAllowedFileTypes()
1829 {
1830 $mset = new ilSetting("mobs");
1831 if (trim($mset->get("restricted_file_types")) == "")
1832 {
1833 return array();
1834 }
1835 return array_map(function ($v)
1836 {
1837 return strtolower(trim($v));
1838 },
1839 explode(",", $mset->get("restricted_file_types")));
1840 }
1841
1848 static function isTypeAllowed($a_type)
1849 {
1850 if (in_array($a_type, self::getForbiddenFileTypes()))
1851 {
1852 return false;
1853 }
1854 if (count(self::getAllowedFileTypes()) == 0 || in_array($a_type, self::getAllowedFileTypes()))
1855 {
1856 return true;
1857 }
1858 return false;
1859 }
1860
1861
1865 function duplicate()
1866 {
1867 $new_obj = new ilObjMediaObject();
1868 $new_obj->setTitle($this->getTitle());
1869 $new_obj->setDescription($this->getDescription());
1870
1871 // media items
1872 foreach($this->getMediaItems() as $key => $val)
1873 {
1874 $new_obj->addMediaItem($val);
1875 }
1876
1877 $new_obj->create(false, true);
1878
1879 // files
1880 $new_obj->createDirectory();
1881 self::_createThumbnailDirectory($new_obj->getId());
1883 ilObjMediaObject::_getDirectory($new_obj->getId()));
1885 ilObjMediaObject::_getThumbnailDirectory($new_obj->getId()));
1886
1887 // meta data
1888 include_once("Services/MetaData/classes/class.ilMD.php");
1889 $md = new ilMD(0, $this->getId(), "mob");
1890 $new_md = $md->cloneMD(0, $new_obj->getId(), "mob");
1891
1892 return $new_obj;
1893 }
1894
1901 function uploadVideoPreviewPic($a_prevpic)
1902 {
1903 $pi = pathinfo($a_prevpic["name"]);
1904 $ext = $pi["extension"];
1905 if (in_array($ext, array("jpg", "jpeg", "png")))
1906 {
1907 $this->uploadAdditionalFile("mob_vpreview.".$ext, $a_prevpic["tmp_name"]);
1908 }
1909 }
1910
1917 function generatePreviewPic($a_width, $a_height)
1918 {
1919 $item = $this->getMediaItem("Standard");
1920
1921 if ($item->getLocationType() == "LocalFile" &&
1922 is_int(strpos($item->getFormat(), "image/")))
1923 {
1924 $dir = ilObjMediaObject::_getDirectory($this->getId());
1925 $file = $dir."/".
1926 $item->getLocation();
1927 if (is_file($file))
1928 {
1929 if(ilUtil::isConvertVersionAtLeast("6.3.8-3"))
1930 {
1931 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");
1932 }
1933 else
1934 {
1935 ilUtil::convertImage($file, $dir."/mob_vpreview.png", "PNG", $a_width."x".$a_height);
1936 }
1937 }
1938 }
1939 }
1940
1947 function getVideoPreviewPic($a_filename_only = false)
1948 {
1949 $dir = ilObjMediaObject::_getDirectory($this->getId());
1950 $ppics = array("mob_vpreview.jpg",
1951 "mob_vpreview.jpeg",
1952 "mob_vpreview.png");
1953 foreach ($ppics as $p)
1954 {
1955 if (is_file($dir."/".$p))
1956 {
1957 if ($a_filename_only)
1958 {
1959 return $p;
1960 }
1961 else
1962 {
1963 return $dir."/".$p;
1964 }
1965 }
1966 }
1967 return "";
1968 }
1969
1976 static function fixFilename($a_name)
1977 {
1978 $a_name = ilUtil::getASCIIFilename($a_name);
1979
1980 $rchars = array("`", "=", "$", "{", "}", "'", ";", " ", "(", ")");
1981 $a_name = str_replace($rchars, "_", $a_name);
1982 $a_name = str_replace("__", "_", $a_name);
1983 return $a_name;
1984 }
1985
1991 static function renameExecutables($a_dir)
1992 {
1994 if (!self::isTypeAllowed("html"))
1995 {
1996 ilUtil::rRenameSuffix($a_dir, "html", "sec"); // see #20187
1997 }
1998 }
1999
2000
2001}
2002?>
print $file
$size
Definition: RandomTest.php:79
global $tpl
Definition: ilias.php:8
$location
Definition: buildRTE.php:44
$_GET["client_id"]
& _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
& _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 _lookupObjIdForForumId($a_for_id)
_lookupTermId($a_def_id)
Looks up term id for a definition id.
static _lookGlossaryID($term_id)
get glossary id form term id
_lookupContObjID($a_id)
get learning module / digibook id for lm object
_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 _lookupLocationForMobId($a_mob_id, $a_purpose)
Lookup location for mob id.
_getMapAreasIntLinks($a_mob_id)
get all internal links of map areas of a mob
deleteAllItemsOfMob($a_mob_id)
static
_getMediaItemsOfMOb(&$a_mob)
read media items into media objects (static)
static sanitizeDir($a_path)
Sanitize directory recursively.
static getMimeType($a_file="", $a_filename="", $a_mime="")
Get Mime type.
static _lookupContextObjId($a_news_id)
Context Object ID.
static _lookupMediaObjectUsages($a_mob_id)
Lookup media object usage(s)
static lookupExerciseIdForReturnedId($a_returned_id)
Class ilObjMediaObject.
_createThumbnailDirectory($a_obj_id)
Create thumbnail directory.
MDUpdateListener($a_element)
Meta data update listener.
update($a_upload=false)
update media object in db
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 isTypeAllowed($a_type)
Is type allowed.
static getThumbnailPath($a_mob_id, $a_thumbname)
Get thumbnail path.
getTitle()
get object title @access public
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
makeThumbnail($a_file, $a_thumbname, $a_format="png", $a_size="80")
Make thumbnail.
getRefId()
get reference id @access public
_deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
static
uploadAdditionalFile($a_name, $tmp_name, $a_subdir="")
Create new media object and update page in db and return new media object.
lookupUsages($a_id, $a_include_history=true)
Lookup usages of media object.
getId()
get object id @access public
_getDirectory($a_mob_id)
get directory for files of media object (static)
static getAllowedFileTypes()
Get allowed file types.
_getURL($a_mob_id)
get directory for files of media object (static)
static _useAutoStartParameterOnly($a_loc, $a_format)
Check whether only autostart parameter should be supported (instead of parameters input field.
static _determineWidthHeight($a_def_width, $a_def_height, $a_format, $a_type, $a_file, $a_reference, $a_constrain_proportions, $a_use_original, $a_user_width, $a_user_height)
Determine width and height.
static handleQuotaUpdate(ilObjMediaObject $a_mob)
uploadSrtFile($a_tmp_name, $a_language)
Upload srt file.
containsIntLink()
returns true, if mob was marked as containing an intern link (via setContainsIntLink) (this method sh...
static getMimeType($a_file)
get mime type for file
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
ilObjMediaObject($a_id=0)
Constructor @access public.
setAlias($a_is_alias)
set wether page object is an alias
& getMediaItems()
get all media items
_resizeImage($a_file, $a_width, $a_height, $a_constrain_prop=false)
resize image and return new image file ("_width_height" string appended)
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.
_saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
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.
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.
generatePreviewPic($a_width, $a_height)
Upload video preview picture.
createMetaData()
create meta data entry
modifyExportIdentifier($a_tag, $a_param, $a_value)
setContainsIntLink($a_contains_link)
content parser set this flag to true, if the media object contains internal links (this method should...
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
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
& _saveTempFileAsMediaObject($name, $tmp_name, $upload=TRUE)
Create new media object and update page in db and return new media object.
hasPurposeItem($purpose)
returns wether object has media item with specific purpose
static getForbiddenFileTypes()
Get forbidden file types.
static _exists($a_id)
checks wether a lm content object with specified id exists or not
_getThumbnailDirectory($a_mob_id, $a_mode="filesystem")
get directory for files of media object (static)
_removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
setDescription($a_description)
set description of media object
static renameExecutables($a_dir)
Rename executables.
getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids=false)
Get's the repository object ID of a parent object, if possible.
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
_lookupTestObjIdForQuestionId($a_q_id)
Get test Object ID for question ID.
_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
_writeTitle($a_obj_id, $a_title)
write title to db (static)
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
_writeDescription($a_obj_id, $a_desc)
write description to db (static)
static _lookupType($a_id, $a_reference=false)
lookup object type
_getPageForQuestionId($a_q_id, $a_parent_type="")
Get page for question id.
static _exists($a_parent_type, $a_id, $a_lang="")
Checks whether page exists.
static lookupParentId($a_id, $a_type)
Lookup parent id.
static getFlashVideoPlayerDirectory()
Get flash video player directory.
static findPortfolioForPage($a_page_id)
Get portfolio id of page id.
_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 makeDirParents($a_dir)
Create a new directory and all parent directories.
static deducibleSize($a_mime)
checks if mime type is provided by getimagesize()
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
xslt_free(&$proc)
xslt_create()
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:40
$path
Definition: index.php:22
global $ilDB
$mobs
global $ilUser
Definition: imgupload.php:15