ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
4 define ("IL_MODE_ALIAS", 1);
5 define ("IL_MODE_OUTPUT", 2);
6 define ("IL_MODE_FULL", 3);
7 
8 require_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
9 include_once "./Services/Object/classes/class.ilObject.php";
10 
27 {
28  var $is_alias;
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  $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
130  self::handleQuotaUpdate($this);
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 
357  function hasFullscreenItem()
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 
474  self::handleQuotaUpdate($this);
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 
519  self::handleQuotaUpdate($this);
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  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  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 
636  function createDirectory()
637  {
639  }
640 
644  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  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
720  }
721 
722  // Text Representation
723  if ($item->getTextRepresentation() != "")
724  {
725  $xml .= "<TextRepresentation>".
726  str_replace("&", "&amp;", $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  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
756  $this->handleAmps($item->getLocation())."</Location>";
757 
758  // Format
759  $xml.= "<Format>".$item->getFormat()."</Format>";
760 
761  // Layout
762  $width = ($item->getWidth() != "")
763  ? "Width=\"".$item->getWidth()."\""
764  : "";
765  $height = ($item->getHeight() != "")
766  ? "Height=\"".$item->getHeight()."\""
767  : "";
768  $halign = ($item->getHAlign() != "")
769  ? "HorizontalAlign=\"".$item->getHAlign()."\""
770  : "";
771  $xml .= "<Layout $width $height $halign />";
772 
773  // Caption
774  if ($item->getCaption() != "")
775  {
776  $xml .= "<Caption Align=\"bottom\">".
777  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
778  }
779 
780  // Text Representation
781  if ($item->getTextRepresentation() != "")
782  {
783  $xml .= "<TextRepresentation>".
784  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
785  }
786 
787  // Parameter
788  $parameters = $item->getParameters();
789  foreach ($parameters as $name => $value)
790  {
791  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
792  }
793  $xml .= $item->getMapAreasXML();
794 
795  // Subtitles
796  if ($item->getPurpose() == "Standard")
797  {
798  $srts = $this->getSrtFiles();
799  foreach ($srts as $srt)
800  {
801  $def = "";
802  $meta_lang = "";
803  if ($ilUser->getLanguage() != $meta_lang &&
804  $ilUser->getLanguage() == $srt["language"])
805  {
806  $def = ' Default="true" ';
807  }
808  $xml .= "<Subtitle File=\"".$srt["full_path"].
809  "\" Language=\"".$srt["language"]."\" ".$def."/>";
810  }
811  }
812  $xml .= "</MediaItem>";
813  }
814  break;
815 
816  // full xml for export
817  case IL_MODE_FULL:
818 
819 // $meta =& $this->getMetaData();
820  $xml = "<MediaObject>";
821 
822  // meta data
823  include_once("Services/MetaData/classes/class.ilMD2XML.php");
824  $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
825  $md2xml->setExportMode(true);
826  $md2xml->startExport();
827  $xml.= $md2xml->getXML();
828 
829  $media_items =& $this->getMediaItems();
830  for($i=0; $i<count($media_items); $i++)
831  {
832  $item =& $media_items[$i];
833 
834  // highlight mode
835  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
836 
837  // Location
838  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
839  $this->handleAmps($item->getLocation())."</Location>";
840 
841  // Format
842  $xml.= "<Format>".$item->getFormat()."</Format>";
843 
844  // Layout
845  $width = ($item->getWidth() != "")
846  ? "Width=\"".$item->getWidth()."\""
847  : "";
848  $height = ($item->getHeight() != "")
849  ? "Height=\"".$item->getHeight()."\""
850  : "";
851  $halign = ($item->getHAlign() != "")
852  ? "HorizontalAlign=\"".$item->getHAlign()."\""
853  : "";
854  $xml .= "<Layout $width $height $halign />";
855 
856  // Caption
857  if ($item->getCaption() != "")
858  {
859  $xml .= "<Caption Align=\"bottom\">".
860  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
861  }
862 
863  // Text Representation
864  if ($item->getTextRepresentation() != "")
865  {
866  $xml .= "<TextRepresentation>".
867  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
868  }
869 
870  // Parameter
871  $parameters = $item->getParameters();
872  foreach ($parameters as $name => $value)
873  {
874  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
875  }
876  $xml .= $item->getMapAreasXML(true, $a_inst);
877  $xml .= "</MediaItem>";
878  }
879  break;
880  }
881  $xml .= "</MediaObject>";
882  return $xml;
883  }
884 
888  function handleAmps($a_str)
889  {
890  $a_str = str_replace("&amp;", "&", $a_str);
891  $a_str = str_replace("&", "&amp;", $a_str);
892  return $a_str;
893  }
894 
898  function exportXML(&$a_xml_writer, $a_inst = 0)
899  {
900  $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
901  }
902 
903 
911  function exportFiles($a_target_dir)
912  {
913  $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
914  ilUtil::makeDir($a_target_dir."/objects/".$subdir);
915 
916  $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
917  ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
918 //echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
919  }
920 
921  function exportMediaFullscreen($a_target_dir, $pg_obj)
922  {
923  $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
924  $a_target_dir = $a_target_dir."/objects/".$subdir;
925  ilUtil::makeDir($a_target_dir);
926  $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Modules/LearningModule");
927  $tpl->setCurrentBlock("ilMedia");
928 
929  //$int_links = $page_object->getInternalLinks();
930  $med_links = ilMediaItem::_getMapAreasIntLinks($this->getId());
931 
932  // @todo
933  //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets());
934 
935  require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
936  //$media_obj = new ilObjMediaObject($_GET["mob_id"]);
937  require_once("./Services/COPage/classes/class.ilPageObject.php");
938 
939  $xml = "<dummy>";
940  // todo: we get always the first alias now (problem if mob is used multiple
941  // times in page)
942  $xml.= $pg_obj->getMediaAliasElement($this->getId());
943  $xml.= $this->getXML(IL_MODE_OUTPUT);
944  //$xml.= $link_xml;
945  $xml.="</dummy>";
946 
947  //die(htmlspecialchars($xml));
948 
949  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
950  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
951  $xh = xslt_create();
952 
953  //echo "<b>XML:</b>".htmlentities($xml);
954  // determine target frames for internal links
955  $wb_path = "";
956  $enlarge_path = "";
957  $params = array ('mode' => "fullscreen", 'enlarge_path' => $enlarge_path,
958  'link_params' => "ref_id=".$_GET["ref_id"],'fullscreen_link' => "",
959  'ref_id' => $_GET["ref_id"], 'webspace_path' => $wb_path);
960  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
961  //echo xslt_error($xh);
962  xslt_free($xh);
963 
964  // unmask user html
965  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
966  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "../../css/style.css");
967  $tpl->setVariable("LOCATION_STYLESHEET", "../../css/system.css");
968  $tpl->setVariable("MEDIA_CONTENT", $output);
969  $output = $tpl->get();
970  //$output = preg_replace("/\/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
971  $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
972  $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i","../../players",$output);
973  $output = preg_replace("/\.\/".str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory())."/i","../../players",$output);
974  $output = preg_replace("/file=..\/..\/..\//i","file=../objects/".$subdir."/",$output);
975  //die(htmlspecialchars($output));
976  fwrite(fopen($a_target_dir.'/fullscreen.html','w'), $output );
977  }
978 
979  function modifyExportIdentifier($a_tag, $a_param, $a_value)
980  {
981  if ($a_tag == "Identifier" && $a_param == "Entry")
982  {
983  $a_value = ilUtil::insertInstIntoID($a_value);
984  }
985 
986  return $a_value;
987  }
988 
989 
991  // EDIT METHODS: these methods act on the media alias in the dom
993 
1000  function setContainsIntLink($a_contains_link)
1001  {
1002  $this->contains_int_link = $a_contains_link;
1003  }
1004 
1009  function containsIntLink()
1010  {
1011  return $this->contains_int_link;
1012  }
1013 
1017  function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1018  {
1019  global $ilDB;
1020 
1021  $and_hist = "";
1022  if ($a_usage_hist_nr !== false)
1023  {
1024  $and_hist = " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
1025  }
1026 
1027  $mob_ids = array();
1028  $set = $ilDB->query("SELECT id FROM mob_usage".
1029  " WHERE usage_type = ".$ilDB->quote($a_type, "text").
1030  " AND usage_id = ".$ilDB->quote($a_id, "integer").
1031  " AND usage_lang = ".$ilDB->quote($a_lang, "text").
1032  $and_hist);
1033  while($row = $ilDB->fetchAssoc($set))
1034  {
1035  $mob_ids[] = $row["id"];
1036  }
1037 
1038  $q = "DELETE FROM mob_usage WHERE usage_type = ".
1039  $ilDB->quote($a_type, "text").
1040  " AND usage_id= ".$ilDB->quote($a_id, "integer").
1041  " AND usage_lang = ".$ilDB->quote($a_lang, "text").
1042  $and_hist;
1043  $ilDB->manipulate($q);
1044 
1045  foreach($mob_ids as $mob_id)
1046  {
1047  self::handleQuotaUpdate(new self($mob_id));
1048  }
1049  }
1050 
1054  function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1055  {
1056  global $ilDB;
1057 
1058  $lstr = "";
1059  if ($a_lang != "")
1060  {
1061  $lstr = " AND usage_lang = ".$ilDB->quote($a_lang, "text");
1062  }
1063  $hist_str = "";
1064  if ($a_usage_hist_nr !== false)
1065  {
1066  $hist_str = " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
1067  }
1068 
1069  $q = "SELECT * FROM mob_usage WHERE ".
1070  "usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1071  "usage_id = ".$ilDB->quote($a_id, "integer").
1072  $lstr.$hist_str;
1073  $mobs = array();
1074  $mob_set = $ilDB->query($q);
1075  while($mob_rec = $ilDB->fetchAssoc($mob_set))
1076  {
1077  if (ilObject::_lookupType($mob_rec["id"]) == "mob")
1078  {
1079  $mobs[$mob_rec["id"]] = $mob_rec["id"];
1080  }
1081  }
1082 
1083  return $mobs;
1084  }
1085 
1089  function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1090  {
1091  global $ilDB;
1092 
1093  $ilDB->replace("mob_usage",
1094  array(
1095  "id" => array("integer", (int) $a_mob_id),
1096  "usage_type" => array("text", $a_type),
1097  "usage_id" => array("integer", $a_id),
1098  "usage_lang" => array("text", $a_lang),
1099  "usage_hist_nr" => array("integer", (int) $a_usage_hist_nr)
1100  ),
1101  array()
1102  );
1103 
1104  self::handleQuotaUpdate(new self($a_mob_id));
1105  }
1106 
1110  function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1111  {
1112  global $ilDB;
1113 
1114  $q = "DELETE FROM mob_usage WHERE ".
1115  " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
1116  " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1117  " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
1118  " usage_lang = ".$ilDB->quote($a_lang, "text")." AND ".
1119  " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
1120  $ilDB->manipulate($q);
1121 
1122  self::handleQuotaUpdate(new self($a_mob_id));
1123  }
1124 
1128  function getUsages($a_include_history = true)
1129  {
1130  return $this->lookupUsages($this->getId(), $a_include_history);
1131  }
1132 
1138  function lookupUsages($a_id, $a_include_history = true)
1139  {
1140  global $ilDB;
1141 
1142  $hist_str = "";
1143  if ($a_include_history)
1144  {
1145  $hist_str = ", usage_hist_nr";
1146  }
1147 
1148  // get usages in pages
1149  $q = "SELECT DISTINCT usage_type, usage_id, usage_lang".$hist_str." FROM mob_usage WHERE id = ".
1150  $ilDB->quote($a_id, "integer");
1151 
1152  if (!$a_include_history)
1153  {
1154  $q.= " AND usage_hist_nr = ".$ilDB->quote(0, "integer");
1155  }
1156 
1157  $us_set = $ilDB->query($q);
1158  $ret = array();
1159  while($us_rec = $ilDB->fetchAssoc($us_set))
1160  {
1161  $ut = "";
1162  if(is_int(strpos($us_rec["usage_type"], ":")))
1163  {
1164  $us_arr = explode(":", $us_rec["usage_type"]);
1165  $ut = $us_arr[1];
1166  $ct = $us_arr[0];
1167  }
1168 
1169  // check whether page exists
1170  $skip = false;
1171  if ($ut == "pg")
1172  {
1173  include_once("./Services/COPage/classes/class.ilPageObject.php");
1174  if (!ilPageObject::_exists($ct, $us_rec["usage_id"]))
1175  {
1176  $skip = true;
1177  }
1178  }
1179 
1180  if (!$skip)
1181  {
1182  $ret[] = array("type" => $us_rec["usage_type"],
1183  "id" => $us_rec["usage_id"],
1184  "lang" => $us_rec["usage_lang"],
1185  "hist_nr" => $us_rec["usage_hist_nr"]);
1186  }
1187  }
1188 
1189  // get usages in media pools
1190  $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = ".
1191  $ilDB->quote($a_id, "integer")." AND mep_item.type = ".$ilDB->quote("mob", "text");
1192  $us_set = $ilDB->query($q);
1193  while($us_rec = $ilDB->fetchAssoc($us_set))
1194  {
1195  $ret[] = array("type" => "mep",
1196  "id" => $us_rec["mep_id"]);
1197  }
1198 
1199  // get usages in news items (media casts)
1200  include_once("./Services/News/classes/class.ilNewsItem.php");
1201  $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
1202  foreach($news_usages as $nu)
1203  {
1204  $ret[] = $nu;
1205  }
1206 
1207 
1208  // get usages in map areas
1209  $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area ".
1210  " WHERE area.item_id = it.id ".
1211  " AND area.link_type = ".$ilDB->quote("int", "text")." ".
1212  " AND area.target = ".$ilDB->quote("il__mob_".$a_id, "text");
1213  $us_set = $ilDB->query($q);
1214  while($us_rec = $ilDB->fetchAssoc($us_set))
1215  {
1216  $ret[] = array("type" => "map",
1217  "id" => $us_rec["mob_id"]);
1218  }
1219 
1220  // get usages in personal clipboards
1221  $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
1222  foreach ($users as $user)
1223  {
1224  $ret[] = array("type" => "clip",
1225  "id" => $user);
1226  }
1227 
1228  return $ret;
1229  }
1230 
1236  function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
1237  {
1238  if(is_int(strpos($a_usage["type"], ":")))
1239  {
1240  $us_arr = explode(":", $a_usage["type"]);
1241  $type = $us_arr[1];
1242  $cont_type = $us_arr[0];
1243  }
1244  else
1245  {
1246  $type = $a_usage["type"];
1247  }
1248 
1249  $id = $a_usage["id"];
1250  $obj_id = false;
1251 
1252  switch($type)
1253  {
1254  // RTE / tiny mce
1255  case "html":
1256 
1257  switch($cont_type)
1258  {
1259  case "qpl":
1260  // Question Pool *Question* Text (Test)
1261  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1262  $qinfo = assQuestion::_getQuestionInfo($id);
1263  if ($qinfo["original_id"] > 0)
1264  {
1265  include_once("./Modules/Test/classes/class.ilObjTest.php");
1266  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1267  }
1268  else
1269  {
1270  $obj_id = $qinfo["obj_fi"]; // usage in pool
1271  }
1272  break;
1273 
1274  case "spl":
1275  // Question Pool *Question* Text (Survey)
1276  include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
1278  if ($quest)
1279  {
1280  $parent_id = $quest->getObjId();
1281 
1282  // pool question copy - find survey, do not use pool itself
1283  if ($quest->getOriginalId() &&
1284  ilObject::_lookupType($parent_id) == "spl")
1285  {
1286  $obj_id = SurveyQuestion::_lookupSurveyObjId($id);
1287  }
1288  // original question (in pool or survey)
1289  else
1290  {
1291  $obj_id = $parent_id;
1292  }
1293 
1294  unset($quest);
1295  }
1296  break;
1297 
1298  case "exca":
1299  // Exercise assignment
1300  $returned_pk = $a_usage['id'];
1301  // #15995 - we are just checking against exercise object
1302  include_once 'Modules/Exercise/classes/class.ilExSubmission.php';
1303  $obj_id = ilExSubmission::lookupExerciseIdForReturnedId($returned_pk);
1304  break;
1305 
1306  case "frm":
1307  // Forum
1308  $post_pk = $a_usage['id'];
1309  include_once 'Modules/Forum/classes/class.ilForumPost.php';
1310  include_once 'Modules/Forum/classes/class.ilForum.php';
1311  $oPost = new ilForumPost($post_pk);
1312  $frm_pk = $oPost->getForumId();
1313  $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1314  break;
1315 
1316  // temporary items (per user)
1317  case "frm~":
1318  case "exca~":
1319  $obj_id = $a_usage['id'];
1320  break;
1321 
1322  // "old" category pages
1323  case "cat":
1324  // InfoScreen Text
1325  case "tst":
1326  case "svy":
1327  // data collection
1328  case "dcl":
1329  $obj_id = $id;
1330  break;
1331  }
1332  break;
1333 
1334  // page editor
1335  case "pg":
1336 
1337  switch($cont_type)
1338  {
1339  // question feedback // parent obj id is q id
1340  case "qfbg":
1341  include_once('./Services/COPage/classes/class.ilPageObject.php');
1342  $id = ilPageObject::lookupParentId($id, 'qfbg');
1343  // note: no break here, we only altered the $id to the question id
1344 
1345  case "qpl":
1346  // Question Pool Question Pages
1347  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1348  $qinfo = assQuestion::_getQuestionInfo($id);
1349  if ($qinfo["original_id"] > 0)
1350  {
1351  include_once("./Modules/Test/classes/class.ilObjTest.php");
1352  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1353  }
1354  else
1355  {
1356  $obj_id = $qinfo["obj_fi"]; // usage in pool
1357  }
1358  if ($obj_id == 0) // this is the case, if question is in learning module -> get lm id
1359  {
1360  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
1361  $pinfo = ilPCQuestion::_getPageForQuestionId($id, "lm");
1362  if ($pinfo && $pinfo["parent_type"] == "lm")
1363  {
1364  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1365  $obj_id = ilLMObject::_lookupContObjID($pinfo["page_id"]);
1366  }
1367  $pinfo = ilPCQuestion::_getPageForQuestionId($id, "sahs");
1368  if ($pinfo && $pinfo["parent_type"] == "sahs")
1369  {
1370  include_once("./Modules/SCORM2004/classes/class.ilSCORM2004Node.php");
1371  $obj_id = ilSCORM2004Node::_lookupSLMID($pinfo["page_id"]);
1372  }
1373  }
1374  break;
1375 
1376  case "lm":
1377  case "dbk":
1378  // learning modules
1379  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1380  $obj_id = ilLMObject::_lookupContObjID($id);
1381  break;
1382 
1383  case "gdf":
1384  // glossary definition
1385  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1386  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1387  $term_id = ilGlossaryDefinition::_lookupTermId($id);
1388  $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1389  break;
1390 
1391  case "wpg":
1392  // wiki page
1393  include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
1394  $obj_id = ilWikiPage::lookupObjIdByPage($id);
1395  break;
1396 
1397  case "sahs":
1398  // sahs page
1399  // can this implementation be used for other content types, too?
1400  include_once('./Services/COPage/classes/class.ilPageObject.php');
1401  $obj_id = ilPageObject::lookupParentId($id, 'sahs');
1402  break;
1403 
1404  case "prtf":
1405  // portfolio
1406  include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
1408  break;
1409 
1410  case "prtt":
1411  // portfolio template
1412  include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
1414  break;
1415 
1416  case "blp":
1417  // blog
1418  include_once('./Services/COPage/classes/class.ilPageObject.php');
1419  $obj_id = ilPageObject::lookupParentId($id, 'blp');
1420  break;
1421 
1422  case "impr":
1423  // imprint page - always id 1
1424  // fallthrough
1425 
1426  case "crs":
1427  case "grp":
1428  case "cat":
1429  case "fold":
1430  case "root":
1431  case "cont":
1432  case "cstr":
1433  // repository pages
1434  $obj_id = $id;
1435  break;
1436  }
1437  break;
1438 
1439  // Media Pool
1440  case "mep":
1441  $obj_id = $id;
1442  break;
1443 
1444  // News Context Object (e.g. MediaCast)
1445  case "news":
1446  include_once("./Services/News/classes/class.ilNewsItem.php");
1447  $obj_id = ilNewsItem::_lookupContextObjId($id);
1448  break;
1449  }
1450 
1451  return $obj_id;
1452  }
1453 
1461  function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1462  {
1463  $file_path = pathinfo($a_file);
1464  $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
1465  strlen($file_path["extension"]) - 1)."_".
1466  $a_width."_".
1467  $a_height.".".$file_path["extension"];
1468  $target_file = $file_path["dirname"]."/".
1469  $location;
1470  ilUtil::resizeImage($a_file, $target_file,
1471  (int) $a_width, (int) $a_height, $a_constrain_prop);
1472 
1473  return $location;
1474  }
1475 
1483  static function getMimeType($a_file, $a_external = false)
1484  {
1485  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1487  return $mime;
1488  }
1489 
1493  static function _determineWidthHeight($a_format, $a_type,
1494  $a_file, $a_reference, $a_constrain_proportions, $a_use_original,
1495  $a_user_width, $a_user_height)
1496  {
1497  global $lng;
1498 
1499  // determine width and height of known image types
1500  $width = 640;
1501  $height = 360;
1502  $info = "";
1503 
1504  if ($a_format == "audio/mpeg")
1505  {
1506  $width = 300;
1507  $height = 20;
1508  }
1509 
1510  if (ilUtil::deducibleSize($a_format))
1511  {
1512  include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1513  if ($a_type == "File")
1514  {
1516  }
1517  else
1518  {
1519  $size = ilMediaImageUtil::getImageSize($a_reference);
1520  }
1521  }
1522 
1523  if ($a_use_original)
1524  {
1525  if ($size[0] > 0 && $size[1] > 0)
1526  {
1527  $width = $size[0];
1528  $height = $size[1];
1529  }
1530  else
1531  {
1532  $info = $lng->txt("cont_could_not_determine_resource_size");
1533  }
1534  }
1535  else
1536  {
1537  $w = (int) $a_user_width;
1538  $h = (int) $a_user_height;
1539  $width = $w;
1540  $height = $h;
1541 //echo "<br>C-$width-$height-";
1542  if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions)
1543  {
1544  if ($size[0] > 0 && $size[1] > 0)
1545  {
1546  if ($w > 0)
1547  {
1548  $wr = $size[0] / $w;
1549  }
1550  if ($h > 0)
1551  {
1552  $hr = $size[1] / $h;
1553  }
1554 //echo "<br>+".$wr."+".$size[0]."+".$w."+";
1555 //echo "<br>+".$hr."+".$size[1]."+".$h."+";
1556  $r = max($wr, $hr);
1557  if ($r > 0)
1558  {
1559  $width = (int) ($size[0]/$r);
1560  $height = (int) ($size[1]/$r);
1561  }
1562  }
1563  }
1564 //echo "<br>D-$width-$height-";
1565  }
1566 //echo "<br>E-$width-$height-";
1567  return array("width" => $width, "height" => $height, "info" => $info);
1568  }
1569 
1574  static function _getSimpleMimeTypes()
1575  {
1576  return array("image/x-ms-bmp", "image/gif", "image/jpeg", "image/x-portable-bitmap",
1577  "image/png", "image/psd", "image/tiff", "application/pdf");
1578  }
1579 
1580  function getDataDirectory()
1581  {
1582  return ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
1583  }
1584 
1591  static function _useAutoStartParameterOnly($a_loc, $a_format)
1592  {
1593  $lpath = pathinfo($a_loc);
1594  if ($lpath["extension"] == "mp3" && $a_format == "audio/mpeg")
1595  {
1596  return true;
1597  }
1598  if ($lpath["extension"] == "flv")
1599  {
1600  return true;
1601  }
1602  if (in_array($a_format, array("video/mp4", "video/webm")))
1603  {
1604  return true;
1605  }
1606  return false;
1607  }
1608 
1612  public static function _saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
1613  {
1614  // create dummy object in db (we need an id)
1615  $media_object = new ilObjMediaObject();
1616  $media_object->setTitle($name);
1617  $media_object->setDescription("");
1618  $media_object->create();
1619 
1620  // determine and create mob directory, move uploaded file to directory
1621  $media_object->createDirectory();
1622  $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1623 
1624  $media_item =& new ilMediaItem();
1625  $media_object->addMediaItem($media_item);
1626  $media_item->setPurpose("Standard");
1627 
1628  $file = $mob_dir."/".$name;
1629  if ($upload)
1630  {
1631  ilUtil::moveUploadedFile($tmp_name,$name, $file);
1632  }
1633  else
1634  {
1635  copy($tmp_name, $file);
1636  }
1637  // get mime type
1639  $location = $name;
1640  // set real meta and object data
1641  $media_item->setFormat($format);
1642  $media_item->setLocation($location);
1643  $media_item->setLocationType("LocalFile");
1644  $media_object->setTitle($name);
1645  $media_object->setDescription($format);
1646 
1647  if (ilUtil::deducibleSize($format))
1648  {
1649  include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
1651  $media_item->setWidth($size[0]);
1652  $media_item->setHeight($size[1]);
1653  }
1654  $media_item->setHAlign("Left");
1655 
1656  self::renameExecutables($mob_dir);
1657  include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1658  ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1659 
1660  $media_object->update();
1661 
1662  return $media_object;
1663  }
1664 
1668  function uploadAdditionalFile($a_name, $tmp_name, $a_subdir = "", $a_mode = "move_uploaded")
1669  {
1670  $a_subdir = str_replace("..", "", $a_subdir);
1671  $dir = $mob_dir = ilObjMediaObject::_getDirectory($this->getId());
1672  if ($a_subdir != "")
1673  {
1674  $dir.= "/".$a_subdir;
1675  }
1676  ilUtil::makeDirParents($dir);
1677  ilUtil::moveUploadedFile($tmp_name, $a_name, $dir."/".$a_name, true, $a_mode);
1678  self::renameExecutables($mob_dir);
1679  include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
1680  ilMediaSvgSanitizer::sanitizeDir($mob_dir); // see #20339
1681 
1682  }
1683 
1690  function uploadSrtFile($a_tmp_name, $a_language, $a_mode = "move_uploaded")
1691  {
1692  if (is_file($a_tmp_name) && $a_language != "")
1693  {
1694  $this->uploadAdditionalFile("subtitle_".$a_language.".srt", $a_tmp_name, "srt", $a_mode);
1695  return true;
1696  }
1697  return false;
1698  }
1699 
1703  function getSrtFiles()
1704  {
1705  $srt_dir = ilObjMediaObject::_getDirectory($this->getId())."/srt";
1706 
1707  if (!is_dir($srt_dir))
1708  {
1709  return array();
1710  }
1711 
1712  $items = ilUtil::getDir($srt_dir);
1713 
1714  $srt_files = array();
1715  foreach ($items as $i)
1716  {
1717  if (!in_array($i["entry"], array(".", "..")) && $i["type"] == "file")
1718  {
1719  $name = explode(".", $i["entry"]);
1720  if ($name[1] == "srt" && substr($name[0], 0, 9) == "subtitle_")
1721  {
1722  $srt_files[] = array("file" => $i["entry"],
1723  "full_path" => "srt/".$i["entry"], "language" => substr($name[0], 9, 2));
1724  }
1725  }
1726  }
1727 
1728  return $srt_files;
1729  }
1730 
1734  function makeThumbnail($a_file, $a_thumbname, $a_format = "png",
1735  $a_size = "80")
1736  {
1737  $m_dir = ilObjMediaObject::_getDirectory($this->getId());
1739  self::_createThumbnailDirectory($this->getId());
1740  ilUtil::convertImage($m_dir."/".$a_file,
1741  $t_dir."/".$a_thumbname, $a_format, $a_size);
1742  }
1743 
1750  static function getThumbnailPath($a_mob_id, $a_thumbname)
1751  {
1752  $t_dir = ilObjMediaObject::_getThumbnailDirectory($a_mob_id);
1753  return $t_dir."/".$a_thumbname;
1754  }
1755 
1756 
1760  function removeAdditionalFile($a_file)
1761  {
1762  $file = str_replace("..", "", $a_file);
1764  if (is_file($file))
1765  {
1766  unlink($file);
1767  }
1768  }
1769 
1770 
1774  function getLinkedMediaObjects($a_ignore = "")
1775  {
1776  $linked = array();
1777 
1778  if (!is_array($a_ignore))
1779  {
1780  $a_ignore = array();
1781  }
1782 
1783  // get linked media objects (map areas)
1784  $med_items = $this->getMediaItems();
1785 
1786  foreach($med_items as $med_item)
1787  {
1788  $int_links = ilMapArea::_getIntLinks($med_item->getId());
1789  foreach ($int_links as $k => $int_link)
1790  {
1791  if ($int_link["Type"] == "MediaObject")
1792  {
1793  include_once("./Services/Link/classes/class.ilInternalLink.php");
1794  $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1795  if (ilObject::_exists($l_id))
1796  {
1797  if (!in_array($l_id, $linked) &&
1798  !in_array($l_id, $a_ignore))
1799  {
1800  $linked[] = $l_id;
1801  }
1802  }
1803  }
1804  }
1805  }
1806 //var_dump($linked);
1807  return $linked;
1808  }
1809 
1813  static function getRestrictedFileTypes()
1814  {
1815  return array_filter(self::getAllowedFileTypes(), function ($v) {
1816  return !in_array($v, self::getForbiddenFileTypes());
1817  });
1818  }
1819 
1825  static function getForbiddenFileTypes()
1826  {
1827  $mset = new ilSetting("mobs");
1828  if (trim($mset->get("black_list_file_types")) == "")
1829  {
1830  return array();
1831  }
1832  return array_map(function ($v)
1833  {
1834  return strtolower(trim($v));
1835  },
1836  explode(",", $mset->get("black_list_file_types")));
1837  }
1838 
1844  static function getAllowedFileTypes()
1845  {
1846  $mset = new ilSetting("mobs");
1847  if (trim($mset->get("restricted_file_types")) == "")
1848  {
1849  return array();
1850  }
1851  return array_map(function ($v)
1852  {
1853  return strtolower(trim($v));
1854  },
1855  explode(",", $mset->get("restricted_file_types")));
1856  }
1857 
1864  static function isTypeAllowed($a_type)
1865  {
1866  if (in_array($a_type, self::getForbiddenFileTypes()))
1867  {
1868  return false;
1869  }
1870  if (count(self::getAllowedFileTypes()) == 0 || in_array($a_type, self::getAllowedFileTypes()))
1871  {
1872  return true;
1873  }
1874  return false;
1875  }
1876 
1877 
1881  function duplicate()
1882  {
1883  $new_obj = new ilObjMediaObject();
1884  $new_obj->setTitle($this->getTitle());
1885  $new_obj->setDescription($this->getDescription());
1886 
1887  // media items
1888  foreach($this->getMediaItems() as $key => $val)
1889  {
1890  $new_obj->addMediaItem($val);
1891  }
1892 
1893  $new_obj->create(false, true);
1894 
1895  // files
1896  $new_obj->createDirectory();
1897  self::_createThumbnailDirectory($new_obj->getId());
1899  ilObjMediaObject::_getDirectory($new_obj->getId()));
1901  ilObjMediaObject::_getThumbnailDirectory($new_obj->getId()));
1902 
1903  // meta data
1904  include_once("Services/MetaData/classes/class.ilMD.php");
1905  $md = new ilMD(0, $this->getId(), "mob");
1906  $new_md = $md->cloneMD(0, $new_obj->getId(), "mob");
1907 
1908  return $new_obj;
1909  }
1910 
1917  function uploadVideoPreviewPic($a_prevpic)
1918  {
1919  $pi = pathinfo($a_prevpic["name"]);
1920  $ext = $pi["extension"];
1921  if (in_array($ext, array("jpg", "jpeg", "png")))
1922  {
1923  $this->uploadAdditionalFile("mob_vpreview.".$ext, $a_prevpic["tmp_name"]);
1924  }
1925  }
1926 
1933  function generatePreviewPic($a_width, $a_height)
1934  {
1935  $item = $this->getMediaItem("Standard");
1936 
1937  if ($item->getLocationType() == "LocalFile" &&
1938  is_int(strpos($item->getFormat(), "image/")))
1939  {
1940  $dir = ilObjMediaObject::_getDirectory($this->getId());
1941  $file = $dir."/".
1942  $item->getLocation();
1943  if (is_file($file))
1944  {
1945  if(ilUtil::isConvertVersionAtLeast("6.3.8-3"))
1946  {
1947  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");
1948  }
1949  else
1950  {
1951  ilUtil::convertImage($file, $dir."/mob_vpreview.png", "PNG", $a_width."x".$a_height);
1952  }
1953  }
1954  }
1955  }
1956 
1963  function getVideoPreviewPic($a_filename_only = false)
1964  {
1965  $dir = ilObjMediaObject::_getDirectory($this->getId());
1966  $ppics = array("mob_vpreview.jpg",
1967  "mob_vpreview.jpeg",
1968  "mob_vpreview.png");
1969  foreach ($ppics as $p)
1970  {
1971  if (is_file($dir."/".$p))
1972  {
1973  if ($a_filename_only)
1974  {
1975  return $p;
1976  }
1977  else
1978  {
1979  return $dir."/".$p;
1980  }
1981  }
1982  }
1983  return "";
1984  }
1985 
1992  static function fixFilename($a_name)
1993  {
1994  $a_name = ilUtil::getASCIIFilename($a_name);
1995 
1996  $rchars = array("`", "=", "$", "{", "}", "'", ";", " ", "(", ")");
1997  $a_name = str_replace($rchars, "_", $a_name);
1998  $a_name = str_replace("__", "_", $a_name);
1999  return $a_name;
2000  }
2001 
2002 
2010  {
2011  return ilObjMediaObject::_getDirectory($this->getId()."/srt/tmp");
2012  }
2013 
2014 
2021  function uploadMultipleSubtitleFile($a_file)
2022  {
2023  global $lng, $ilUser;
2024 
2025  include_once("./Services/MediaObjects/exceptions/class.ilMediaObjectsException.php");
2026  if (!is_file($a_file["tmp_name"]))
2027  {
2028  throw new ilMediaObjectsException($lng->txt("mob_file_could_not_be_uploaded"));
2029  }
2030 
2031  $dir = $this->getMultiSrtUploadDir();
2032  ilUtil::delDir($dir, true);
2033  ilUtil::makeDirParents($dir);
2034  ilUtil::moveUploadedFile($a_file["tmp_name"], "multi_srt.zip", $dir."/"."multi_srt.zip");
2035  ilUtil::unzip($dir."/multi_srt.zip", true);
2036  }
2037 
2042  {
2044  }
2045 
2049  function getMultiSrtFiles()
2050  {
2051  $items = array();
2052 
2053  include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
2055 
2056  $dir = $this->getMultiSrtUploadDir();
2057  $files = ilUtil::getDir($dir);
2058  foreach ($files as $k => $i)
2059  {
2060  // check directory
2061  if ($i["type"] == "file" && !in_array($k, array(".", "..")))
2062  {
2063  if (pathinfo($k, PATHINFO_EXTENSION) == "srt")
2064  {
2065  $lang = "";
2066  if (substr($k, strlen($k) - 7, 1) == "_")
2067  {
2068  $lang = substr($k, strlen($k) - 6, 2);
2069  if (!in_array($lang, $lang_codes))
2070  {
2071  $lang = "";
2072  }
2073  }
2074  $items[] = array("filename" => $k, "lang" => $lang);
2075  }
2076  }
2077  }
2078  return $items;
2079  }
2080 
2086  static function renameExecutables($a_dir)
2087  {
2088  ilUtil::renameExecutables($a_dir);
2089  if (!self::isTypeAllowed("html"))
2090  {
2091  ilUtil::rRenameSuffix($a_dir, "html", "sec"); // see #20187
2092  }
2093  }
2094 }
2095 ?>
static isConvertVersionAtLeast($a_version)
Compare convert version numbers.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
xslt_create()
static makeDirParents($a_dir)
Create a new directory and all parent directories.
_writeTitle($a_obj_id, $a_title)
write title to db (static)
getSrtFiles()
Get srt files.
ILIAS Setting Class.
print $file
static _lookupLocationForMobId($a_mob_id, $a_purpose)
Lookup location for mob id.
static _lookupObjIdForForumId($a_for_id)
$size
Definition: RandomTest.php:79
uploadMultipleSubtitleFile($a_file)
Upload multi srt file.
getVideoPreviewPic($a_filename_only=false)
Get video preview pic.
setDescription($a_description)
set description of media object
& getMediaItem($a_purpose)
get item for media purpose
static getImageSize($a_location)
Get image size from location.
static rRenameSuffix($a_dir, $a_old_suffix, $a_new_suffix)
Renames all files with certain suffix and gives them a new suffix.
ilObjMediaObject($a_id=0)
Constructor public.
const IL_MODE_FULL
read()
read media object data from db
removeAdditionalFile($a_file)
Remove additional file.
static _lookupSurveyObjId($a_question_id)
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static sanitizeDir($a_path)
Sanitize directory recursively.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
$_GET["client_id"]
static lookupMimeType($path_to_file, $fallback=self::APPLICATION__OCTET_STREAM, $a_external=false)
$location
Definition: buildRTE.php:44
$h
_writeDescription($a_obj_id, $a_desc)
write description to db (static)
xslt_free(&$proc)
General exception class for media objects.
Class ilObject Basic functions for all objects.
getMultiSrtFiles()
Get all srt files of srt multi upload.
static findPortfolioForPage($a_page_id)
Get portfolio id of page id.
& _getQuestionInfo($question_id)
Returns question information from the database.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
lookupUsages($a_id, $a_include_history=true)
Lookup usages of media object.
getUsages($a_include_history=true)
get all usages of current media object
createDirectory()
Create file directory of media object.
static deducibleSize($a_mime)
checks if mime type is provided by getimagesize()
_getPageForQuestionId($a_q_id, $a_parent_type="")
Get page for question id.
static lookupExerciseIdForReturnedId($a_returned_id)
Get exercise from submission id (used in ilObjMediaObject)
_lookupTestObjIdForQuestionId($a_q_id)
Get test Object ID for question ID.
static _getURL($a_mob_id)
get directory for files of media object (static)
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
$w
_createThumbnailDirectory($a_obj_id)
Create thumbnail directory.
_removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
updateMetaData()
update meta data entry
global $tpl
Definition: ilias.php:8
static handleQuotaUpdate(ilObjMediaObject $a_mob)
static isTypeAllowed($a_type)
Is type allowed.
static lookupParentId($a_id, $a_type)
Lookup parent id.
makeThumbnail($a_file, $a_thumbname, $a_format="png", $a_size="80")
Make thumbnail.
clearMultiSrtDirectory()
Clear multi feedback directory.
update($a_upload=false)
update media object in db
_lookupSLMID($a_id)
Lookup Scorm Learning Module ID for node id.
$info
Definition: example_052.php:80
getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids=false)
Get&#39;s the repository object ID of a parent object, if possible.
getImportId()
get import id
$r
Definition: example_031.php:79
_saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static resizeImage($a_from, $a_to, $a_width, $a_height, $a_constrain_prop=false)
resize image
static getThumbnailPath($a_mob_id, $a_thumbname)
Get thumbnail path.
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.
static _lookupMediaObjectUsages($a_mob_id)
Lookup media object usage(s)
static execConvert($args)
execute convert command
$mobs
MDUpdateListener($a_element)
Meta data update listener.
uploadSrtFile($a_tmp_name, $a_language, $a_mode="move_uploaded")
Upload srt file.
static renameExecutables($a_dir)
Rename executables.
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 _exists($a_id)
checks wether a lm content object with specified id exists or not
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=TRUE)
Create new media object and update page in db and return new media object.
modifyExportIdentifier($a_tag, $a_param, $a_value)
static fixFilename($a_name)
Fix filename of uploaded file.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
special template class to simplify handling of ITX/PEAR
_lookupContObjID($a_id)
get learning module / digibook id for lm object
Class ilMediaItem.
_deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
static
static getFlashVideoPlayerDirectory()
Get flash video player directory.
getLinkedMediaObjects($a_ignore="")
Get all media objects linked in map areas of this media object.
redirection script todo: (a better solution should control the processing via a xml file) ...
static createDirectory($a_dir, $a_mod=0755)
create directory
Class ilObjMediaObject.
generatePreviewPic($a_width, $a_height)
Upload video preview picture.
_getMapAreasIntLinks($a_mob_id)
get all internal links of map areas of a mob
hasPurposeItem($purpose)
returns wether object has media item with specific purpose
getType()
get object type public
static getHtmlPath($relative_path)
get url of path
exportXML(&$a_xml_writer, $a_inst=0)
export XML
const IL_MODE_ALIAS
static _lookupType($a_id, $a_reference=false)
lookup object type
static getForbiddenFileTypes()
Get forbidden file types.
getMultiSrtUploadDir()
Get directory for multi srt upload.
containsIntLink()
returns true, if mob was marked as containing an intern link (via setContainsIntLink) (this method sh...
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static _lookupItemPath($a_mob_id, $a_url_encode=false, $a_web=true, $a_purpose="")
Get path for item with specific purpose.
static _lookGlossaryID($term_id)
get glossary id form term id
deleteMetaData()
delete meta data entry
getFilesOfDirectory($a_subdir="")
Get files of directory.
getXML($a_mode=IL_MODE_FULL, $a_inst=0)
get MediaObject XLM Tag
deleteAllItemsOfMob($a_mob_id)
static
addMediaItem($a_item)
add media item to media object
exportMediaFullscreen($a_target_dir, $pg_obj)
_getThumbnailDirectory($a_mob_id, $a_mode="filesystem")
get directory for files of media object (static)
static getMimeType($a_file, $a_external=false)
get mime type for file
global $ilUser
Definition: imgupload.php:15
static getRestrictedFileTypes()
Get restricted file types (this is for the input form, this list will be empty, if "allowed list" is ...
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
global $ilSetting
Definition: privfeed.php:40
& getMediaItems()
get all media items
static getAllowedFileTypes()
Get allowed file types.
static escapeShellArg($a_arg)
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.
$path
Definition: index.php:22
global $ilDB
static _useAutoStartParameterOnly($a_loc, $a_format)
Check whether only autostart parameter should be supported (instead of parameters input field...
static _lookupStandardItemPath($a_mob_id, $a_url_encode=false, $a_web=true)
Get path for standard item.
static _lookupContextObjId($a_news_id)
Context Object ID.
uploadVideoPreviewPic($a_prevpic)
Upload video preview picture.
static insertInstIntoID($a_value)
inserts installation id into ILIAS id
const IL_MODE_OUTPUT
_getMediaItemsOfMOb(&$a_mob)
read media items into media objects (static)
duplicate()
Duplicate media object, return new media object.
removeAllMediaItems()
remove all media items
static getLogger($a_component_id)
Get component logger.
_getIntLinks($a_item_id)
get all internal links of a media items map areas
setAlias($a_is_alias)
set wether page object is an alias
exportFiles($a_target_dir)
export all media files of object to target directory note: target directory must be the export target...
_getUsersForClipboadObject($a_type, $a_id)
get all users, that have a certain object within their clipboard
static _getSimpleMimeTypes()
Get simple mime types that deactivate parameter property files tab in ILIAS.
& _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
create($a_create_meta_data=false, $a_save_media_items=true)
create media object in db
handleAmps($a_str)
Replace "&" (if not an "&amp;") with "&amp;".
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getWebspaceDir($mode="filesystem")
get webspace directory
getDescription()
get description of media object
createMetaData()
create meta data entry
$params
Definition: example_049.php:96
_resizeImage($a_file, $a_width, $a_height, $a_constrain_prop=false)
resize image and return new image file ("_width_height" string appended)
_getDirectory($a_mob_id)
get directory for files of media object (static)
_lookupTermId($a_def_id)
Looks up term id for a definition id.
setContainsIntLink($a_contains_link)
content parser set this flag to true, if the media object contains internal links (this method should...
static lookupObjIdByPage($a_page_id)
returns the wiki/object id to a given page id