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