ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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/COPage/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
125  self::handleQuotaUpdate($this);
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 
339  function hasFullscreenItem()
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 
456  self::handleQuotaUpdate($this);
457  }
458 
459 
463  function update($a_upload=false)
464  {
465  parent::update();
466 
467  if(!$a_upload)
468  {
469  $this->updateMetaData();
470  }
471 
473 
474  // iterate all items
475  $media_items =& $this->getMediaItems();
476  $j = 1;
477  foreach($media_items as $key => $val)
478  {
479  $item =& $media_items[$key];
480  if (is_object($item))
481  {
482  $item->setMobId($this->getId());
483  $item->setNr($j);
484  if ($item->getLocationType() == "Reference")
485  {
486  $item->extractUrlParameters();
487  }
488  $item->create();
489  $j++;
490  }
491  }
492 
493  self::handleQuotaUpdate($this);
494  }
495 
496  protected static function handleQuotaUpdate(ilObjMediaObject $a_mob)
497  {
498  global $ilSetting;
499 
500  // if neither workspace nor portfolios are activated, we skip
501  // the quota update here. this due to performance reasons on installations
502  // that do not use workspace/portfolios, but heavily copy content.
503  // in extreme cases (media object in pool and personal blog, deactivate workspace, change media object,
504  // this may lead to incorrect data in the quota calculation)
505  if ($ilSetting->get("disable_personal_workspace") && !$ilSetting->get('user_portfolios'))
506  {
507  return;
508  }
509 
510  $parent_obj_ids = array();
511  foreach($a_mob->getUsages() as $item)
512  {
513  $parent_obj_id = $a_mob->getParentObjectIdForUsage($item);
514  if($parent_obj_id &&
515  !in_array($parent_obj_id, $parent_obj_ids))
516  {
517  $parent_obj_ids[]= $parent_obj_id;
518  }
519  }
520 
521  // we could suppress this if object is present in a (repository) media pool
522  // but this would lead to "quota-breaches" when the pool item is deleted
523  // and "suddenly" all workspace owners get filesize added to their
524  // respective quotas, regardless of current status
525 
526  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
528  $a_mob->getId(),
529  ilUtil::dirSize($a_mob->getDataDirectory()),
530  $parent_obj_ids);
531  }
532 
538  function _getDirectory($a_mob_id)
539  {
540  return ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
541  }
542 
548  function _getURL($a_mob_id)
549  {
550  return ilUtil::getHtmlPath(ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id);
551  }
552 
558  function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
559  {
560  return ilUtil::getWebspaceDir($a_mode)."/thumbs/mm_".$a_mob_id;
561  }
562 
568  static function _lookupStandardItemPath($a_mob_id, $a_url_encode = false,
569  $a_web = true)
570  {
571  return ilObjMediaObject::_lookupItemPath($a_mob_id, $a_url_encode, $a_web, "Standard");
572  }
573 
579  static function _lookupItemPath($a_mob_id, $a_url_encode = false,
580  $a_web = true, $a_purpose = "")
581  {
582  if ($a_purpose == "")
583  {
584  $a_purpose = "Standard";
585  }
586  $location = ilMediaItem::_lookupLocationForMobId($a_mob_id, $a_purpose);
587  if (preg_match("/https?\:/i",$location))
588  return $location;
589 
590  if ($a_url_encode)
591  $location = rawurlencode($location);
592 
593  $path = ($a_web)
594  ? ILIAS_HTTP_PATH
595  : ".";
596 
597  return $path."/data/".CLIENT_ID."/mobs/mm_".$a_mob_id."/".$location;
598  }
599 
603  function createDirectory()
604  {
606  }
607 
611  function _createThumbnailDirectory($a_obj_id)
612  {
614  ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs/mm_".$a_obj_id);
615  }
616 
623  function getFilesOfDirectory($a_subdir = "")
624  {
625  $a_subdir = str_replace("..", "", $a_subdir);
626  $dir = ilObjMediaObject::_getDirectory($this->getId());
627  if ($a_subdir != "")
628  {
629  $dir.= "/".$a_subdir;
630  }
631 
632  $files = array();
633  if (is_dir($dir))
634  {
635  $entries = ilUtil::getDir($dir);
636  foreach ($entries as $e)
637  {
638  if (is_file($dir."/".$e["entry"]) && $e["entry"] != "." && $e["entry"] != "..")
639  {
640  $files[] = $e["entry"];
641  }
642  }
643  }
644 
645  return $files;
646  }
647 
648 
653  function getXML($a_mode = IL_MODE_FULL, $a_inst = 0)
654  {
655  global $ilUser;
656 
657  // TODO: full implementation of all parameters
658 //echo "-".$a_mode."-";
659  switch ($a_mode)
660  {
661  case IL_MODE_ALIAS:
662  $xml = "<MediaObject>";
663  $xml .= "<MediaAlias OriginId=\"il__mob_".$this->getId()."\"/>";
664  $media_items =& $this->getMediaItems();
665  for($i=0; $i<count($media_items); $i++)
666  {
667  $item =& $media_items[$i];
668  $xml .= "<MediaAliasItem Purpose=\"".$item->getPurpose()."\">";
669 
670  // Layout
671  $width = ($item->getWidth() != "")
672  ? "Width=\"".$item->getWidth()."\""
673  : "";
674  $height = ($item->getHeight() != "")
675  ? "Height=\"".$item->getHeight()."\""
676  : "";
677  $halign = ($item->getHAlign() != "")
678  ? "HorizontalAlign=\"".$item->getHAlign()."\""
679  : "";
680  $xml .= "<Layout $width $height $halign />";
681 
682  // Caption
683  if ($item->getCaption() != "")
684  {
685  $xml .= "<Caption Align=\"bottom\">".
686  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
687  }
688 
689  // Text Representation
690  if ($item->getTextRepresentation() != "")
691  {
692  $xml .= "<TextRepresentation>".
693  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
694  }
695 
696  // Parameter
697  $parameters = $item->getParameters();
698  foreach ($parameters as $name => $value)
699  {
700  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
701  }
702  $xml .= $item->getMapAreasXML();
703  $xml .= "</MediaAliasItem>";
704  }
705  break;
706 
707  // for output we need technical sections of meta data
708  case IL_MODE_OUTPUT:
709 
710  // get first technical section
711 // $meta =& $this->getMetaData();
712  $xml = "<MediaObject Id=\"il__mob_".$this->getId()."\">";
713 
714  $media_items =& $this->getMediaItems();
715  for($i=0; $i<count($media_items); $i++)
716  {
717  $item =& $media_items[$i];
718 
719  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
720 
721  // Location
722  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
723  $this->handleAmps($item->getLocation())."</Location>";
724 
725  // Format
726  $xml.= "<Format>".$item->getFormat()."</Format>";
727 
728  // Layout
729  $width = ($item->getWidth() != "")
730  ? "Width=\"".$item->getWidth()."\""
731  : "";
732  $height = ($item->getHeight() != "")
733  ? "Height=\"".$item->getHeight()."\""
734  : "";
735  $halign = ($item->getHAlign() != "")
736  ? "HorizontalAlign=\"".$item->getHAlign()."\""
737  : "";
738  $xml .= "<Layout $width $height $halign />";
739 
740  // Caption
741  if ($item->getCaption() != "")
742  {
743  $xml .= "<Caption Align=\"bottom\">".
744  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
745  }
746 
747  // Text Representation
748  if ($item->getTextRepresentation() != "")
749  {
750  $xml .= "<TextRepresentation>".
751  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
752  }
753 
754  // Parameter
755  $parameters = $item->getParameters();
756  foreach ($parameters as $name => $value)
757  {
758  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
759  }
760  $xml .= $item->getMapAreasXML();
761 
762  // Subtitles
763  if ($item->getPurpose() == "Standard")
764  {
765  $srts = $this->getSrtFiles();
766  foreach ($srts as $srt)
767  {
768  $def = "";
769  $meta_lang = "";
770  if ($ilUser->getLanguage() != $meta_lang &&
771  $ilUser->getLanguage() == $srt["language"])
772  {
773  $def = ' Default="true" ';
774  }
775  $xml .= "<Subtitle File=\"".$srt["full_path"].
776  "\" Language=\"".$srt["language"]."\" ".$def."/>";
777  }
778  }
779  $xml .= "</MediaItem>";
780  }
781  break;
782 
783  // full xml for export
784  case IL_MODE_FULL:
785 
786 // $meta =& $this->getMetaData();
787  $xml = "<MediaObject>";
788 
789  // meta data
790  include_once("Services/MetaData/classes/class.ilMD2XML.php");
791  $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
792  $md2xml->setExportMode(true);
793  $md2xml->startExport();
794  $xml.= $md2xml->getXML();
795 
796  $media_items =& $this->getMediaItems();
797  for($i=0; $i<count($media_items); $i++)
798  {
799  $item =& $media_items[$i];
800 
801  // highlight mode
802  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
803 
804  // Location
805  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
806  $this->handleAmps($item->getLocation())."</Location>";
807 
808  // Format
809  $xml.= "<Format>".$item->getFormat()."</Format>";
810 
811  // Layout
812  $width = ($item->getWidth() != "")
813  ? "Width=\"".$item->getWidth()."\""
814  : "";
815  $height = ($item->getHeight() != "")
816  ? "Height=\"".$item->getHeight()."\""
817  : "";
818  $halign = ($item->getHAlign() != "")
819  ? "HorizontalAlign=\"".$item->getHAlign()."\""
820  : "";
821  $xml .= "<Layout $width $height $halign />";
822 
823  // Caption
824  if ($item->getCaption() != "")
825  {
826  $xml .= "<Caption Align=\"bottom\">".
827  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
828  }
829 
830  // Text Representation
831  if ($item->getTextRepresentation() != "")
832  {
833  $xml .= "<TextRepresentation>".
834  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
835  }
836 
837  // Parameter
838  $parameters = $item->getParameters();
839  foreach ($parameters as $name => $value)
840  {
841  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
842  }
843  $xml .= $item->getMapAreasXML(true, $a_inst);
844  $xml .= "</MediaItem>";
845  }
846  break;
847  }
848  $xml .= "</MediaObject>";
849  return $xml;
850  }
851 
855  function handleAmps($a_str)
856  {
857  $a_str = str_replace("&amp;", "&", $a_str);
858  $a_str = str_replace("&", "&amp;", $a_str);
859  return $a_str;
860  }
861 
865  function exportXML(&$a_xml_writer, $a_inst = 0)
866  {
867  $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
868  }
869 
870 
878  function exportFiles($a_target_dir)
879  {
880  $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
881  ilUtil::makeDir($a_target_dir."/objects/".$subdir);
882 
883  $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
884  ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
885 //echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
886  }
887 
888  function exportMediaFullscreen($a_target_dir, $pg_obj)
889  {
890  $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
891  $a_target_dir = $a_target_dir."/objects/".$subdir;
892  ilUtil::makeDir($a_target_dir);
893  $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Modules/LearningModule");
894  $tpl->setCurrentBlock("ilMedia");
895 
896  //$int_links = $page_object->getInternalLinks();
897  $med_links = ilMediaItem::_getMapAreasIntLinks($this->getId());
898 
899  // @todo
900  //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets());
901 
902  require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
903  //$media_obj = new ilObjMediaObject($_GET["mob_id"]);
904  require_once("./Services/COPage/classes/class.ilPageObject.php");
905 
906  $xml = "<dummy>";
907  // todo: we get always the first alias now (problem if mob is used multiple
908  // times in page)
909  $xml.= $pg_obj->getMediaAliasElement($this->getId());
910  $xml.= $this->getXML(IL_MODE_OUTPUT);
911  //$xml.= $link_xml;
912  $xml.="</dummy>";
913 
914  //die(htmlspecialchars($xml));
915 
916  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
917  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
918  $xh = xslt_create();
919 
920  //echo "<b>XML:</b>".htmlentities($xml);
921  // determine target frames for internal links
922  $wb_path = "";
923  $enlarge_path = "";
924  $params = array ('mode' => "fullscreen", 'enlarge_path' => $enlarge_path,
925  'link_params' => "ref_id=".$_GET["ref_id"],'fullscreen_link' => "",
926  'ref_id' => $_GET["ref_id"], 'webspace_path' => $wb_path);
927  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
928  //echo xslt_error($xh);
929  xslt_free($xh);
930 
931  // unmask user html
932  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
933  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "../../css/style.css");
934  $tpl->setVariable("LOCATION_STYLESHEET", "../../css/system.css");
935  $tpl->setVariable("MEDIA_CONTENT", $output);
936  $output = $tpl->get();
937  //$output = preg_replace("/\/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
938  $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
939  $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i","../../players",$output);
940  $output = preg_replace("/\.\/".str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory())."/i","../../players",$output);
941  $output = preg_replace("/file=..\/..\/..\//i","file=../objects/".$subdir."/",$output);
942  //die(htmlspecialchars($output));
943  fwrite(fopen($a_target_dir.'/fullscreen.html','w'), $output );
944  }
945 
946  function modifyExportIdentifier($a_tag, $a_param, $a_value)
947  {
948  if ($a_tag == "Identifier" && $a_param == "Entry")
949  {
950  $a_value = ilUtil::insertInstIntoID($a_value);
951  }
952 
953  return $a_value;
954  }
955 
956 
958  // EDIT METHODS: these methods act on the media alias in the dom
960 
967  function setContainsIntLink($a_contains_link)
968  {
969  $this->contains_int_link = $a_contains_link;
970  }
971 
976  function containsIntLink()
977  {
979  }
980 
984  function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
985  {
986  global $ilDB;
987 
988  $and_hist = "";
989  if ($a_usage_hist_nr !== false)
990  {
991  $and_hist = " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
992  }
993 
994  $mob_ids = array();
995  $set = $ilDB->query("SELECT id FROM mob_usage".
996  " WHERE usage_type = ".$ilDB->quote($a_type, "text").
997  " AND usage_id = ".$ilDB->quote($a_id, "integer").
998  " AND usage_lang = ".$ilDB->quote($a_lang, "text").
999  $and_hist);
1000  while($row = $ilDB->fetchAssoc($set))
1001  {
1002  $mob_ids[] = $row["id"];
1003  }
1004 
1005  $q = "DELETE FROM mob_usage WHERE usage_type = ".
1006  $ilDB->quote($a_type, "text").
1007  " AND usage_id= ".$ilDB->quote($a_id, "integer").
1008  " AND usage_lang = ".$ilDB->quote($a_lang, "text").
1009  $and_hist;
1010  $ilDB->manipulate($q);
1011 
1012  foreach($mob_ids as $mob_id)
1013  {
1014  self::handleQuotaUpdate(new self($mob_id));
1015  }
1016  }
1017 
1021  function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1022  {
1023  global $ilDB;
1024 
1025  $q = "SELECT * FROM mob_usage WHERE ".
1026  "usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1027  "usage_id = ".$ilDB->quote($a_id, "integer")." AND ".
1028  "usage_lang = ".$ilDB->quote($a_lang, "text")." AND ".
1029  "usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
1030  $mobs = array();
1031  $mob_set = $ilDB->query($q);
1032  while($mob_rec = $ilDB->fetchAssoc($mob_set))
1033  {
1034  if (ilObject::_lookupType($mob_rec["id"]) == "mob")
1035  {
1036  $mobs[$mob_rec["id"]] = $mob_rec["id"];
1037  }
1038  }
1039 
1040  return $mobs;
1041  }
1042 
1046  function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1047  {
1048  global $ilDB;
1049 
1050  $q = "DELETE FROM mob_usage WHERE ".
1051  " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
1052  " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1053  " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
1054  " usage_lang = ".$ilDB->quote($a_lang, "text")." AND ".
1055  " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
1056  $ilDB->manipulate($q);
1057  $q = "INSERT INTO mob_usage (id, usage_type, usage_id, usage_hist_nr, usage_lang) VALUES".
1058  " (".$ilDB->quote((int) $a_mob_id, "integer").",".
1059  $ilDB->quote($a_type, "text").",".
1060  $ilDB->quote((int) $a_id, "integer").",".
1061  $ilDB->quote((int) $a_usage_hist_nr, "integer").",".
1062  $ilDB->quote($a_lang, "text").
1063  ")";
1064  $ilDB->manipulate($q);
1065 
1066  self::handleQuotaUpdate(new self($a_mob_id));
1067  }
1068 
1072  function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_lang = "-")
1073  {
1074  global $ilDB;
1075 
1076  $q = "DELETE FROM mob_usage WHERE ".
1077  " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
1078  " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
1079  " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
1080  " usage_lang = ".$ilDB->quote($a_lang, "text")." AND ".
1081  " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
1082  $ilDB->manipulate($q);
1083 
1084  self::handleQuotaUpdate(new self($a_mob_id));
1085  }
1086 
1090  function getUsages($a_include_history = true)
1091  {
1092  return $this->lookupUsages($this->getId(), $a_include_history);
1093  }
1094 
1100  function lookupUsages($a_id, $a_include_history = true)
1101  {
1102  global $ilDB;
1103 
1104  $hist_str = "";
1105  if ($a_include_history)
1106  {
1107  $hist_str = ", usage_hist_nr";
1108  }
1109 
1110  // get usages in pages
1111  $q = "SELECT DISTINCT usage_type, usage_id, usage_lang".$hist_str." FROM mob_usage WHERE id = ".
1112  $ilDB->quote($a_id, "integer");
1113 
1114  if (!$a_include_history)
1115  {
1116  $q.= " AND usage_hist_nr = ".$ilDB->quote(0, "integer");
1117  }
1118 
1119  $us_set = $ilDB->query($q);
1120  $ret = array();
1121  while($us_rec = $ilDB->fetchAssoc($us_set))
1122  {
1123  $ut = "";
1124  if(is_int(strpos($us_rec["usage_type"], ":")))
1125  {
1126  $us_arr = explode(":", $us_rec["usage_type"]);
1127  $ut = $us_arr[1];
1128  $ct = $us_arr[0];
1129  }
1130 
1131  // check whether page exists
1132  $skip = false;
1133  if ($ut == "pg")
1134  {
1135  include_once("./Services/COPage/classes/class.ilPageObject.php");
1136  if (!ilPageObject::_exists($ct, $us_rec["usage_id"]))
1137  {
1138  $skip = true;
1139  }
1140  }
1141 
1142  if (!$skip)
1143  {
1144  $ret[] = array("type" => $us_rec["usage_type"],
1145  "id" => $us_rec["usage_id"],
1146  "lang" => $us_rec["usage_lang"],
1147  "hist_nr" => $us_rec["usage_hist_nr"]);
1148  }
1149  }
1150 
1151  // get usages in media pools
1152  $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = ".
1153  $ilDB->quote($a_id, "integer")." AND mep_item.type = ".$ilDB->quote("mob", "text");
1154  $us_set = $ilDB->query($q);
1155  while($us_rec = $ilDB->fetchAssoc($us_set))
1156  {
1157  $ret[] = array("type" => "mep",
1158  "id" => $us_rec["mep_id"]);
1159  }
1160 
1161  // get usages in news items (media casts)
1162  include_once("./Services/News/classes/class.ilNewsItem.php");
1163  $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
1164  foreach($news_usages as $nu)
1165  {
1166  $ret[] = $nu;
1167  }
1168 
1169 
1170  // get usages in map areas
1171  $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area ".
1172  " WHERE area.item_id = it.id ".
1173  " AND area.link_type = ".$ilDB->quote("int", "text")." ".
1174  " AND area.target = ".$ilDB->quote("il__mob_".$a_id, "text");
1175  $us_set = $ilDB->query($q);
1176  while($us_rec = $ilDB->fetchAssoc($us_set))
1177  {
1178  $ret[] = array("type" => "map",
1179  "id" => $us_rec["mob_id"]);
1180  }
1181 
1182  // get usages in personal clipboards
1183  $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
1184  foreach ($users as $user)
1185  {
1186  $ret[] = array("type" => "clip",
1187  "id" => $user);
1188  }
1189 
1190  return $ret;
1191  }
1192 
1198  function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
1199  {
1200  if(is_int(strpos($a_usage["type"], ":")))
1201  {
1202  $us_arr = explode(":", $a_usage["type"]);
1203  $type = $us_arr[1];
1204  $cont_type = $us_arr[0];
1205  }
1206  else
1207  {
1208  $type = $a_usage["type"];
1209  }
1210 
1211  $id = $a_usage["id"];
1212  $obj_id = false;
1213 
1214  switch($type)
1215  {
1216  // RTE / tiny mce
1217  case "html":
1218 
1219  switch($cont_type)
1220  {
1221  case "qpl":
1222  // Question Pool *Question* Text (Test)
1223  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1225  if ($qinfo["original_id"] > 0)
1226  {
1227  include_once("./Modules/Test/classes/class.ilObjTest.php");
1228  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1229  }
1230  else
1231  {
1232  $obj_id = $qinfo["obj_fi"]; // usage in pool
1233  }
1234  break;
1235 
1236  case "spl":
1237  // Question Pool *Question* Text (Survey)
1238  include_once("./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php");
1240  if($quest)
1241  {
1242  if ($quest->getOriginalId() > 0)
1243  {
1244  $obj_id = $quest->getSurveyId();
1245  }
1246  else
1247  {
1248  $obj_id = $quest->getObjId(); // usage in pool
1249  }
1250  unset($quest);
1251  }
1252  break;
1253 
1254  case "exca":
1255  // Exercise assignment
1256  $returned_pk = $a_usage['id'];
1257  // we are just checking against exercise object
1258  include_once 'Modules/Exercise/classes/class.ilObjExercise.php';
1259  $obj_id = ilObjExercise::lookupExerciseIdForReturnedId($returned_pk);
1260  break;
1261 
1262  case "frm":
1263  // Forum
1264  $post_pk = $a_usage['id'];
1265  include_once 'Modules/Forum/classes/class.ilForumPost.php';
1266  include_once 'Modules/Forum/classes/class.ilForum.php';
1267  $oPost = new ilForumPost($post_pk);
1268  $frm_pk = $oPost->getForumId();
1269  $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1270  break;
1271 
1272  // temporary items (per user)
1273  case "frm~":
1274  case "exca~":
1275  $obj_id = $a_usage['id'];
1276  break;
1277 
1278  // "old" category pages
1279  case "cat":
1280  // InfoScreen Text
1281  case "tst":
1282  case "svy":
1283  // data collection
1284  case "dcl":
1285  $obj_id = $id;
1286  break;
1287  }
1288  break;
1289 
1290  // page editor
1291  case "pg":
1292 
1293  switch($cont_type)
1294  {
1295  // question feedback // parent obj id is q id
1296  case "qfbg":
1297  include_once('./Services/COPage/classes/class.ilPageObject.php');
1299  // note: no break here, we only altered the $id to the question id
1300 
1301  case "qpl":
1302  // Question Pool Question Pages
1303  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1305  if ($qinfo["original_id"] > 0)
1306  {
1307  include_once("./Modules/Test/classes/class.ilObjTest.php");
1308  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1309  }
1310  else
1311  {
1312  $obj_id = $qinfo["obj_fi"]; // usage in pool
1313  }
1314  if ($obj_id == 0) // this is the case, if question is in learning module -> get lm id
1315  {
1316  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
1317  $pinfo = ilPCQuestion::_getPageForQuestionId($id, "lm");
1318  if ($pinfo && $pinfo["parent_type"] == "lm")
1319  {
1320  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1321  $obj_id = ilLMObject::_lookupContObjID($pinfo["page_id"]);
1322  }
1323  $pinfo = ilPCQuestion::_getPageForQuestionId($id, "sahs");
1324  if ($pinfo && $pinfo["parent_type"] == "sahs")
1325  {
1326  include_once("./Modules/SCORM2004/classes/class.ilSCORM2004Node.php");
1327  $obj_id = ilSCORM2004Node::_lookupSLMID($pinfo["page_id"]);
1328  }
1329  }
1330  break;
1331 
1332  case "lm":
1333  case "dbk":
1334  // learning modules
1335  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1336  $obj_id = ilLMObject::_lookupContObjID($id);
1337  break;
1338 
1339  case "gdf":
1340  // glossary definition
1341  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1342  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1344  $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1345  break;
1346 
1347  case "wpg":
1348  // wiki page
1349  include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
1351  break;
1352 
1353  case "sahs":
1354  // sahs page
1355  // can this implementation be used for other content types, too?
1356  include_once('./Services/COPage/classes/class.ilPageObject.php');
1357  $obj_id = ilPageObject::lookupParentId($id, 'sahs');
1358  break;
1359 
1360  case "prtf":
1361  // portfolio
1362  include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
1364  break;
1365 
1366  case "prtt":
1367  // portfolio template
1368  include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
1370  break;
1371 
1372  case "blp":
1373  // blog
1374  include_once('./Services/COPage/classes/class.ilPageObject.php');
1375  $obj_id = ilPageObject::lookupParentId($id, 'blp');
1376  break;
1377 
1378  case "impr":
1379  // imprint page - always id 1
1380  // fallthrough
1381 
1382  case "crs":
1383  case "grp":
1384  case "cat":
1385  case "fold":
1386  case "root":
1387  case "cont":
1388  // repository pages
1389  $obj_id = $id;
1390  break;
1391  }
1392  break;
1393 
1394  // Media Pool
1395  case "mep":
1396  $obj_id = $id;
1397  break;
1398 
1399  // News Context Object (e.g. MediaCast)
1400  case "news":
1401  include_once("./Services/News/classes/class.ilNewsItem.php");
1403  break;
1404  }
1405 
1406  return $obj_id;
1407  }
1408 
1416  function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1417  {
1418  $file_path = pathinfo($a_file);
1419  $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
1420  strlen($file_path["extension"]) - 1)."_".
1421  $a_width."_".
1422  $a_height.".".$file_path["extension"];
1423  $target_file = $file_path["dirname"]."/".
1424  $location;
1425  ilUtil::resizeImage($a_file, $target_file,
1426  (int) $a_width, (int) $a_height, $a_constrain_prop);
1427 
1428  return $location;
1429  }
1430 
1438  static function getMimeType($a_file)
1439  {
1440  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1441  $mime = ilMimeTypeUtil::getMimeType($a_file);
1442  return $mime;
1443  }
1444 
1448  static function _determineWidthHeight($a_def_width, $a_def_height, $a_format, $a_type,
1449  $a_file, $a_reference, $a_constrain_proportions, $a_use_original,
1450  $a_user_width, $a_user_height)
1451  {
1452  global $lng;
1453 
1454  // determine width and height of known image types
1455  $width = $a_def_width;
1456  $height = $a_def_height;
1457  $info = "";
1458 
1459  if ($a_format == "audio/mpeg")
1460  {
1461  $width = 300;
1462  $height = 20;
1463  }
1464 
1465  if (ilUtil::deducibleSize($a_format))
1466  {
1467  if ($a_type == "File")
1468  {
1469  $size = @getimagesize($a_file);
1470  }
1471  else
1472  {
1473  $size = @getimagesize($a_reference);
1474  }
1475  }
1476 
1477  if ($a_use_original)
1478  {
1479  if ($size[0] > 0 && $size[1] > 0)
1480  {
1481  $width = $size[0];
1482  $height = $size[1];
1483  }
1484  else
1485  {
1486  $info = $lng->txt("cont_could_not_determine_resource_size");
1487  }
1488  }
1489  else
1490  {
1491  $w = (int) $a_user_width;
1492  $h = (int) $a_user_height;
1493  $width = $w;
1494  $height = $h;
1495 //echo "<br>C-$width-$height-";
1496  if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions)
1497  {
1498  if ($size[0] > 0 && $size[1] > 0)
1499  {
1500  if ($w > 0)
1501  {
1502  $wr = $size[0] / $w;
1503  }
1504  if ($h > 0)
1505  {
1506  $hr = $size[1] / $h;
1507  }
1508 //echo "<br>+".$wr."+".$size[0]."+".$w."+";
1509 //echo "<br>+".$hr."+".$size[1]."+".$h."+";
1510  $r = max($wr, $hr);
1511  if ($r > 0)
1512  {
1513  $width = (int) ($size[0]/$r);
1514  $height = (int) ($size[1]/$r);
1515  }
1516  }
1517  }
1518 //echo "<br>D-$width-$height-";
1519  }
1520 //echo "<br>E-$width-$height-";
1521  return array("width" => $width, "height" => $height, "info" => $info);
1522  }
1523 
1528  static function _getSimpleMimeTypes()
1529  {
1530  return array("image/x-ms-bmp", "image/gif", "image/jpeg", "image/x-portable-bitmap",
1531  "image/png", "image/psd", "image/tiff", "application/pdf");
1532  }
1533 
1534  function getDataDirectory()
1535  {
1536  return ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
1537  }
1538 
1545  static function _useAutoStartParameterOnly($a_loc, $a_format)
1546  {
1547  $lpath = pathinfo($a_loc);
1548  if ($lpath["extension"] == "mp3" && $a_format == "audio/mpeg")
1549  {
1550  return true;
1551  }
1552  if ($lpath["extension"] == "flv")
1553  {
1554  return true;
1555  }
1556  if (in_array($a_format, array("video/mp4", "video/webm")))
1557  {
1558  return true;
1559  }
1560  return false;
1561  }
1562 
1566  function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
1567  {
1568  // create dummy object in db (we need an id)
1569  $media_object = new ilObjMediaObject();
1570  $media_object->setTitle($name);
1571  $media_object->setDescription("");
1572  $media_object->create();
1573 
1574  // determine and create mob directory, move uploaded file to directory
1575  $media_object->createDirectory();
1576  $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1577 
1578  $media_item =& new ilMediaItem();
1579  $media_object->addMediaItem($media_item);
1580  $media_item->setPurpose("Standard");
1581 
1582  $file = $mob_dir."/".$name;
1583  if ($upload)
1584  {
1585  ilUtil::moveUploadedFile($tmp_name,$name, $file);
1586  }
1587  else
1588  {
1589  copy($tmp_name, $file);
1590  }
1591  // get mime type
1593  $location = $name;
1594  // set real meta and object data
1595  $media_item->setFormat($format);
1596  $media_item->setLocation($location);
1597  $media_item->setLocationType("LocalFile");
1598  $media_object->setTitle($name);
1599  $media_object->setDescription($format);
1600 
1601  if (ilUtil::deducibleSize($format))
1602  {
1603  $size = getimagesize($file);
1604  $media_item->setWidth($size[0]);
1605  $media_item->setHeight($size[1]);
1606  }
1607  $media_item->setHAlign("Left");
1608 
1609  ilUtil::renameExecutables($mob_dir);
1610  $media_object->update();
1611 
1612  return $media_object;
1613  }
1614 
1618  function uploadAdditionalFile($a_name, $tmp_name, $a_subdir = "")
1619  {
1620  $a_subdir = str_replace("..", "", $a_subdir);
1621  $dir = $mob_dir = ilObjMediaObject::_getDirectory($this->getId());
1622  if ($a_subdir != "")
1623  {
1624  $dir.= "/".$a_subdir;
1625  }
1626  ilUtil::makeDirParents($dir);
1627  ilUtil::moveUploadedFile($tmp_name, $a_name, $dir."/".$a_name);
1628  ilUtil::renameExecutables($mob_dir);
1629  }
1630 
1637  function uploadSrtFile($a_tmp_name, $a_language)
1638  {
1639  if (is_file($a_tmp_name) && $a_language != "")
1640  {
1641  $this->uploadAdditionalFile("subtitle_".$a_language.".srt", $a_tmp_name, "srt");
1642  return true;
1643  }
1644  return false;
1645  }
1646 
1650  function getSrtFiles()
1651  {
1652  $srt_dir = ilObjMediaObject::_getDirectory($this->getId())."/srt";
1653 
1654  if (!is_dir($srt_dir))
1655  {
1656  return array();
1657  }
1658 
1659  $items = ilUtil::getDir($srt_dir);
1660 
1661  $srt_files = array();
1662  foreach ($items as $i)
1663  {
1664  if (!in_array($i["entry"], array(".", "..")) && $i["type"] == "file")
1665  {
1666  $name = explode(".", $i["entry"]);
1667  if ($name[1] == "srt" && substr($name[0], 0, 9) == "subtitle_")
1668  {
1669  $srt_files[] = array("file" => $i["entry"],
1670  "full_path" => "srt/".$i["entry"], "language" => substr($name[0], 9, 2));
1671  }
1672  }
1673  }
1674 
1675  return $srt_files;
1676  }
1677 
1681  function makeThumbnail($a_file, $a_thumbname, $a_format = "png",
1682  $a_size = "80")
1683  {
1684  $m_dir = ilObjMediaObject::_getDirectory($this->getId());
1687  ilUtil::convertImage($m_dir."/".$a_file,
1688  $t_dir."/".$a_thumbname, $a_format, $a_size);
1689  }
1690 
1697  static function getThumbnailPath($a_mob_id, $a_thumbname)
1698  {
1699  $t_dir = ilObjMediaObject::_getThumbnailDirectory($a_mob_id);
1700  return $t_dir."/".$a_thumbname;
1701  }
1702 
1703 
1707  function removeAdditionalFile($a_file)
1708  {
1709  $file = str_replace("..", "", $a_file);
1711  if (is_file($file))
1712  {
1713  unlink($file);
1714  }
1715  }
1716 
1717 
1721  function getLinkedMediaObjects($a_ignore = "")
1722  {
1723  $linked = array();
1724 
1725  if (!is_array($a_ignore))
1726  {
1727  $a_ignore = array();
1728  }
1729 
1730  // get linked media objects (map areas)
1731  $med_items = $this->getMediaItems();
1732 
1733  foreach($med_items as $med_item)
1734  {
1735  $int_links = ilMapArea::_getIntLinks($med_item->getId());
1736  foreach ($int_links as $k => $int_link)
1737  {
1738  if ($int_link["Type"] == "MediaObject")
1739  {
1740  include_once("./Services/COPage/classes/class.ilInternalLink.php");
1741  $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1742  if (ilObject::_exists($l_id))
1743  {
1744  if (!in_array($l_id, $linked) &&
1745  !in_array($l_id, $a_ignore))
1746  {
1747  $linked[] = $l_id;
1748  }
1749  }
1750  }
1751  }
1752  }
1753 //var_dump($linked);
1754  return $linked;
1755  }
1756 
1760  static function getRestrictedFileTypes()
1761  {
1762  $mset = new ilSetting("mobs");
1763  $str = $mset->get("restricted_file_types");
1764  $types = explode(",", $str);
1765  $suffixes = array();
1766  if (count($types) > 0)
1767  {
1768  foreach ($types as $k => $t)
1769  {
1770  if (($s = strtolower(trim($t))) != "")
1771  {
1772  $suffixes[] = $s;
1773  }
1774  }
1775  }
1776  return $suffixes;
1777  }
1778 
1782  function duplicate()
1783  {
1784  $new_obj = new ilObjMediaObject();
1785  $new_obj->setTitle($this->getTitle());
1786  $new_obj->setDescription($this->getDescription());
1787 
1788  // media items
1789  foreach($this->getMediaItems() as $key => $val)
1790  {
1791  $new_obj->addMediaItem($val);
1792  }
1793 
1794  $new_obj->create(false, true);
1795 
1796  // files
1797  $new_obj->createDirectory();
1798  self::_createThumbnailDirectory($new_obj->getId());
1800  ilObjMediaObject::_getDirectory($new_obj->getId()));
1801  ilUtil::rCopy(ilObjMediaObject::_getThumbnailDirectory($this->getId()),
1802  ilObjMediaObject::_getThumbnailDirectory($new_obj->getId()));
1803 
1804  // meta data
1805  include_once("Services/MetaData/classes/class.ilMD.php");
1806  $md = new ilMD(0, $this->getId(), "mob");
1807  $new_md = $md->cloneMD(0, $new_obj->getId(), "mob");
1808 
1809  return $new_obj;
1810  }
1811 
1818  function uploadVideoPreviewPic($a_prevpic)
1819  {
1820  $pi = pathinfo($a_prevpic["name"]);
1821  $ext = $pi["extension"];
1822  if (in_array($ext, array("jpg", "jpeg", "png")))
1823  {
1824  $this->uploadAdditionalFile("mob_vpreview.".$ext, $a_prevpic["tmp_name"]);
1825  }
1826  }
1827 
1834  function generatePreviewPic($a_width, $a_height)
1835  {
1836  $item = $this->getMediaItem("Standard");
1837 
1838  if ($item->getLocationType() == "LocalFile" &&
1839  is_int(strpos($item->getFormat(), "image/")))
1840  {
1841  $dir = ilObjMediaObject::_getDirectory($this->getId());
1842  $file = $dir."/".
1843  $item->getLocation();
1844  if (is_file($file))
1845  {
1846  if(ilUtil::isConvertVersionAtLeast("6.3.8-3"))
1847  {
1848  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");
1849  }
1850  else
1851  {
1852  ilUtil::convertImage($file, $dir."/mob_vpreview.png", "PNG", $a_width."x".$a_height);
1853  }
1854  }
1855  }
1856  }
1857 
1864  function getVideoPreviewPic($a_filename_only = false)
1865  {
1866  $dir = ilObjMediaObject::_getDirectory($this->getId());
1867  $ppics = array("mob_vpreview.jpg",
1868  "mob_vpreview.jpeg",
1869  "mob_vpreview.png");
1870  foreach ($ppics as $p)
1871  {
1872  if (is_file($dir."/".$p))
1873  {
1874  if ($a_filename_only)
1875  {
1876  return $p;
1877  }
1878  else
1879  {
1880  return $dir."/".$p;
1881  }
1882  }
1883  }
1884  return "";
1885  }
1886 
1887 }
1888 ?>