ILIAS  Release_4_1_x_branch Revision 61804
 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 "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  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  // delete object
124  parent::delete();
125  }
126  }
127 
133  function getDescription()
134  {
135  return parent::getDescription();
136  }
137 
141  function setDescription($a_description)
142  {
143  parent::setDescription($a_description);
144  }
145 
157  function MDUpdateListener($a_element)
158  {
159  include_once 'Services/MetaData/classes/class.ilMD.php';
160 
161  switch($a_element)
162  {
163  case 'General':
164 
165  // Update Title and description
166  $md = new ilMD(0, $this->getId(), $this->getType());
167  $md_gen = $md->getGeneral();
168 
169  if (is_object($md_gen))
170  {
171  ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
172  $this->setTitle($md_gen->getTitle());
173 
174  foreach($md_gen->getDescriptionIds() as $id)
175  {
176  $md_des = $md_gen->getDescription($id);
177  ilObject::_writeDescription($this->getId(),$md_des->getDescription());
178  $this->setDescription($md_des->getDescription());
179  break;
180  }
181  }
182 
183  break;
184 
185  default:
186  }
187  return true;
188  }
189 
193  function createMetaData()
194  {
195  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
196 
197  global $ilUser;
198 
199  $md_creator = new ilMDCreator(0, $this->getId(), $this->getType());
200  $md_creator->setTitle($this->getTitle());
201  $md_creator->setTitleLanguage($ilUser->getPref('language'));
202  $md_creator->setDescription($this->getDescription());
203  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
204  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
205  $md_creator->setLanguage($ilUser->getPref('language'));
206  $md_creator->create();
207 
208  return true;
209  }
210 
214  function updateMetaData()
215  {
216  include_once("Services/MetaData/classes/class.ilMD.php");
217  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
218  include_once("Services/MetaData/classes/class.ilMDDescription.php");
219 
220  $md =& new ilMD(0, $this->getId(), $this->getType());
221  $md_gen =& $md->getGeneral();
222  $md_gen->setTitle($this->getTitle());
223 
224  // sets first description (maybe not appropriate)
225  $md_des_ids =& $md_gen->getDescriptionIds();
226  if (count($md_des_ids) > 0)
227  {
228  $md_des =& $md_gen->getDescription($md_des_ids[0]);
229  $md_des->setDescription($this->getDescription());
230  $md_des->update();
231  }
232  $md_gen->update();
233 
234  }
235 
239  function deleteMetaData()
240  {
241  // Delete meta data
242  include_once('Services/MetaData/classes/class.ilMD.php');
243  $md = new ilMD(0, $this->getId(), $this->getType());
244  $md->deleteAll();
245  }
246 
247 
253  function addMediaItem(&$a_item)
254  {
255  $this->media_items[] =& $a_item;
256  }
257 
258 
264  function &getMediaItems()
265  {
266  return $this->media_items;
267  }
268 
275  function &getMediaItem($a_purpose)
276  {
277  foreach ($this->media_items as $media_item)
278  {
279  if($media_item->getPurpose() == $a_purpose)
280  {
281  return $media_item;
282  }
283  }
284  return false;
285  }
286 
287 
291  function removeMediaItem($a_purpose)
292  {
293  foreach ($this->media_items as $key => $media_item)
294  {
295  if($media_item->getPurpose() == $a_purpose)
296  {
297  unset($this->media_items[$key]);
298  }
299  }
300  // update numbers and keys
301  $i = 1;
302  $media_items = array();
303  foreach ($this->media_items as $media_item)
304  {
305  $media_items [$i] = $media_item;
306  $media_item->setMobId($this->getId());
307  $media_item->setNr($i);
308  $i++;
309  }
310  $this->media_items = $media_items;
311  }
312 
317  {
318  $this->media_items = array();
319  }
320 
321 
322  function getMediaItemNr($a_purpose)
323  {
324  for($i=0; $i<count($this->media_items); $i++)
325  {
326  if($this->media_items[$i]->getPurpose() == $a_purpose)
327  {
328  return $i + 1;
329  }
330  }
331  return false;
332  }
333 
334 
335  function hasFullscreenItem()
336  {
337  return $this->hasPurposeItem("Fullscreen");
338  }
339 
346  function hasPurposeItem($purpose)
347  {
348  if(is_object($this->getMediaItem($purpose)))
349  {
350  return true;
351  }
352  else
353  {
354  return false;
355  }
356  }
357 
358 
359 
363  function read()
364  {
365 //echo "<br>ilObjMediaObject:read";
366  parent::read();
367 
368  // get media items
370  }
371 
375  function setId($a_id)
376  {
377  $this->id = $a_id;
378  }
379 
380  function getId()
381  {
382  return $this->id;
383  }
384 
388  function setAlias($a_is_alias)
389  {
390  $this->is_alias = $a_is_alias;
391  }
392 
393  function isAlias()
394  {
395  return $this->is_alias;
396  }
397 
398  function setOriginID($a_id)
399  {
400  return $this->origin_id = $a_id;
401  }
402 
403  function getOriginID()
404  {
405  return $this->origin_id;
406  }
407 
408  /*
409  function getimportId()
410  {
411  return $this->meta_data->getImportIdentifierEntryID();
412  }*/
413 
414 
418  function getImportId()
419  {
420  return $this->import_id;
421  }
422 
423  function setImportId($a_id)
424  {
425  $this->import_id = $a_id;
426  }
427 
431  function create($a_upload = false, $a_save_media_items = true)
432  {
433  parent::create();
434 
435  if (!$a_upload)
436  {
437  $this->createMetaData();
438  }
439 
440  if ($a_save_media_items)
441  {
442  $media_items =& $this->getMediaItems();
443  for($i=0; $i<count($media_items); $i++)
444  {
445  $item =& $media_items[$i];
446  $item->setMobId($this->getId());
447  $item->setNr($i+1);
448  $item->create();
449  }
450  }
451 
452  }
453 
454 
458  function update($a_upload=false)
459  {
460  parent::update();
461  if(!$a_upload)
462  {
463  $this->updateMetaData();
464  }
466 
467  // iterate all items
468  $media_items =& $this->getMediaItems();
469  $j = 1;
470  foreach($media_items as $key => $val)
471  {
472  $item =& $media_items[$key];
473  if (is_object($item))
474  {
475  $item->setMobId($this->getId());
476  $item->setNr($j);
477  if ($item->getLocationType() == "Reference")
478  {
479  $item->extractUrlParameters();
480  }
481  $item->create();
482  $j++;
483  }
484  }
485  }
486 
492  function _getDirectory($a_mob_id)
493  {
494  return ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
495  }
496 
502  function _getURL($a_mob_id)
503  {
504  return ilUtil::getHtmlPath(ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id);
505  }
506 
512  function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
513  {
514  return ilUtil::getWebspaceDir($a_mode)."/thumbs/mm_".$a_mob_id;
515  }
516 
522  static function _lookupStandardItemPath($a_mob_id, $a_url_encode = false,
523  $a_web = true)
524  {
525  return ilObjMediaObject::_lookupItemPath($a_mob_id, $a_url_encode, $a_web, "Standard");
526  }
527 
533  static function _lookupItemPath($a_mob_id, $a_url_encode = false,
534  $a_web = true, $a_purpose = "")
535  {
536  if ($a_purpose == "")
537  {
538  $a_purpose = "Standard";
539  }
540  $location = ilMediaItem::_lookupLocationForMobId($a_mob_id, $a_purpose);
541  if (preg_match("/https?\:/i",$location))
542  return $location;
543 
544  if ($a_url_encode)
545  $location = rawurlencode($location);
546 
547  $path = ($a_web)
548  ? ILIAS_HTTP_PATH
549  : ".";
550 
551  return $path."/data/".CLIENT_ID."/mobs/mm_".$a_mob_id."/".$location;
552  }
553 
557  function createDirectory()
558  {
560  }
561 
565  function _createThumbnailDirectory($a_obj_id)
566  {
568  ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs/mm_".$a_obj_id);
569  }
570 
575  function getXML($a_mode = IL_MODE_FULL, $a_inst = 0)
576  {
577  // TODO: full implementation of all parameters
578 //echo "-".$a_mode."-";
579  switch ($a_mode)
580  {
581  case IL_MODE_ALIAS:
582  $xml = "<MediaObject>";
583  $xml .= "<MediaAlias OriginId=\"il__mob_".$this->getId()."\"/>";
584  $media_items =& $this->getMediaItems();
585  for($i=0; $i<count($media_items); $i++)
586  {
587  $item =& $media_items[$i];
588  $xml .= "<MediaAliasItem Purpose=\"".$item->getPurpose()."\">";
589 
590  // Layout
591  $width = ($item->getWidth() != "")
592  ? "Width=\"".$item->getWidth()."\""
593  : "";
594  $height = ($item->getHeight() != "")
595  ? "Height=\"".$item->getHeight()."\""
596  : "";
597  $halign = ($item->getHAlign() != "")
598  ? "HorizontalAlign=\"".$item->getHAlign()."\""
599  : "";
600  $xml .= "<Layout $width $height $halign />";
601 
602  // Caption
603  if ($item->getCaption() != "")
604  {
605  $xml .= "<Caption Align=\"bottom\">".
606  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
607  }
608 
609  // Text Representation
610  if ($item->getTextRepresentation() != "")
611  {
612  $xml .= "<TextRepresentation>".
613  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
614  }
615 
616  // Parameter
617  $parameters = $item->getParameters();
618  foreach ($parameters as $name => $value)
619  {
620  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
621  }
622  $xml .= "</MediaAliasItem>";
623  }
624  break;
625 
626  // for output we need technical sections of meta data
627  case IL_MODE_OUTPUT:
628 
629  // get first technical section
630 // $meta =& $this->getMetaData();
631  $xml = "<MediaObject Id=\"il__mob_".$this->getId()."\">";
632 
633  $media_items =& $this->getMediaItems();
634  for($i=0; $i<count($media_items); $i++)
635  {
636  $item =& $media_items[$i];
637  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
638 
639  // Location
640  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
641  $this->handleAmps($item->getLocation())."</Location>";
642 
643  // Format
644  $xml.= "<Format>".$item->getFormat()."</Format>";
645 
646  // Layout
647  $width = ($item->getWidth() != "")
648  ? "Width=\"".$item->getWidth()."\""
649  : "";
650  $height = ($item->getHeight() != "")
651  ? "Height=\"".$item->getHeight()."\""
652  : "";
653  $halign = ($item->getHAlign() != "")
654  ? "HorizontalAlign=\"".$item->getHAlign()."\""
655  : "";
656  $xml .= "<Layout $width $height $halign />";
657 
658  // Caption
659  if ($item->getCaption() != "")
660  {
661  $xml .= "<Caption Align=\"bottom\">".
662  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
663  }
664 
665  // Text Representation
666  if ($item->getTextRepresentation() != "")
667  {
668  $xml .= "<TextRepresentation>".
669  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
670  }
671 
672  // Parameter
673  $parameters = $item->getParameters();
674  foreach ($parameters as $name => $value)
675  {
676  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
677  }
678  $xml .= $item->getMapAreasXML();
679  $xml .= "</MediaItem>";
680  }
681  break;
682 
683  // full xml for export
684  case IL_MODE_FULL:
685 
686 // $meta =& $this->getMetaData();
687  $xml = "<MediaObject>";
688 
689  // meta data
690  include_once("Services/MetaData/classes/class.ilMD2XML.php");
691  $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
692  $md2xml->setExportMode(true);
693  $md2xml->startExport();
694  $xml.= $md2xml->getXML();
695 
696  $media_items =& $this->getMediaItems();
697  for($i=0; $i<count($media_items); $i++)
698  {
699  $item =& $media_items[$i];
700  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
701 
702  // Location
703  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
704  $this->handleAmps($item->getLocation())."</Location>";
705 
706  // Format
707  $xml.= "<Format>".$item->getFormat()."</Format>";
708 
709  // Layout
710  $width = ($item->getWidth() != "")
711  ? "Width=\"".$item->getWidth()."\""
712  : "";
713  $height = ($item->getHeight() != "")
714  ? "Height=\"".$item->getHeight()."\""
715  : "";
716  $halign = ($item->getHAlign() != "")
717  ? "HorizontalAlign=\"".$item->getHAlign()."\""
718  : "";
719  $xml .= "<Layout $width $height $halign />";
720 
721  // Caption
722  if ($item->getCaption() != "")
723  {
724  $xml .= "<Caption Align=\"bottom\">".
725  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
726  }
727 
728  // Text Representation
729  if ($item->getTextRepresentation() != "")
730  {
731  $xml .= "<TextRepresentation>".
732  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
733  }
734 
735  // Parameter
736  $parameters = $item->getParameters();
737  foreach ($parameters as $name => $value)
738  {
739  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
740  }
741  $xml .= $item->getMapAreasXML(true, $a_inst);
742  $xml .= "</MediaItem>";
743  }
744  break;
745  }
746  $xml .= "</MediaObject>";
747  return $xml;
748  }
749 
753  function handleAmps($a_str)
754  {
755  $a_str = str_replace("&amp;", "&", $a_str);
756  $a_str = str_replace("&", "&amp;", $a_str);
757  return $a_str;
758  }
759 
763  function exportXML(&$a_xml_writer, $a_inst = 0)
764  {
765  $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
766  }
767 
768 
776  function exportFiles($a_target_dir)
777  {
778  $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
779  ilUtil::makeDir($a_target_dir."/objects/".$subdir);
780 
781  $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
782  ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
783 //echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
784  }
785 
786  function exportMediaFullscreen($a_target_dir, $pg_obj)
787  {
788  $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
789  $a_target_dir = $a_target_dir."/objects/".$subdir;
790  ilUtil::makeDir($a_target_dir);
791  $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Modules/LearningModule");
792  $tpl->setCurrentBlock("ilMedia");
793 
794  //$int_links = $page_object->getInternalLinks();
795  $med_links = ilMediaItem::_getMapAreasIntLinks($this->getId());
796 
797  // @todo
798  //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets());
799 
800  require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
801  //$media_obj = new ilObjMediaObject($_GET["mob_id"]);
802  require_once("./Services/COPage/classes/class.ilPageObject.php");
803 
804  $xml = "<dummy>";
805  // todo: we get always the first alias now (problem if mob is used multiple
806  // times in page)
807  $xml.= $pg_obj->getMediaAliasElement($this->getId());
808  $xml.= $this->getXML(IL_MODE_OUTPUT);
809  //$xml.= $link_xml;
810  $xml.="</dummy>";
811 
812  //die(htmlspecialchars($xml));
813 
814  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
815  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
816  $xh = xslt_create();
817 
818  //echo "<b>XML:</b>".htmlentities($xml);
819  // determine target frames for internal links
820  $wb_path = "";
821  $enlarge_path = "";
822  $params = array ('mode' => "fullscreen", 'enlarge_path' => $enlarge_path,
823  'link_params' => "ref_id=".$_GET["ref_id"],'fullscreen_link' => "",
824  'ref_id' => $_GET["ref_id"], 'webspace_path' => $wb_path);
825  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
826  //echo xslt_error($xh);
827  xslt_free($xh);
828 
829  // unmask user html
830  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "../../css/style.css");
831  $tpl->setVariable("LOCATION_STYLESHEET", "../../css/system.css");
832  $tpl->setVariable("MEDIA_CONTENT", $output);
833  $output = $tpl->get();
834  //$output = preg_replace("/\/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
835  $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output);
836  $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i","../../players",$output);
837  $output = preg_replace("/\.\/Services\/MediaObjects\/flash_flv_player/i","../../players",$output);
838  $output = preg_replace("/file=..\/..\/..\//i","file=../objects/".$subdir."/",$output);
839  //die(htmlspecialchars($output));
840  fwrite(fopen($a_target_dir.'/fullscreen.html','w'), $output );
841  }
842 
843  function modifyExportIdentifier($a_tag, $a_param, $a_value)
844  {
845  if ($a_tag == "Identifier" && $a_param == "Entry")
846  {
847  $a_value = ilUtil::insertInstIntoID($a_value);
848  }
849 
850  return $a_value;
851  }
852 
853 
855  // EDIT METHODS: these methods act on the media alias in the dom
857 
864  function setContainsIntLink($a_contains_link)
865  {
866  $this->contains_int_link = $a_contains_link;
867  }
868 
873  function containsIntLink()
874  {
876  }
877 
881  function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0)
882  {
883  global $ilDB;
884 
885  $q = "DELETE FROM mob_usage WHERE usage_type = ".
886  $ilDB->quote($a_type, "text").
887  " AND usage_id= ".$ilDB->quote($a_id, "integer").
888  " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
889  $ilDB->manipulate($q);
890  }
891 
895  function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0)
896  {
897  global $ilDB;
898 
899  $q = "SELECT * FROM mob_usage WHERE ".
900  "usage_type = ".$ilDB->quote($a_type, "text")." AND ".
901  "usage_id = ".$ilDB->quote($a_id, "integer")." AND ".
902  "usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
903  $mobs = array();
904  $mob_set = $ilDB->query($q);
905  while($mob_rec = $ilDB->fetchAssoc($mob_set))
906  {
907  if (ilObject::_lookupType($mob_rec["id"]) == "mob")
908  {
909  $mobs[$mob_rec["id"]] = $mob_rec["id"];
910  }
911  }
912 
913  return $mobs;
914  }
915 
919  function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
920  {
921  global $ilDB;
922 
923  $q = "DELETE FROM mob_usage WHERE ".
924  " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
925  " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
926  " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
927  " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
928  $ilDB->manipulate($q);
929  $q = "INSERT INTO mob_usage (id, usage_type, usage_id, usage_hist_nr) VALUES".
930  " (".$ilDB->quote((int) $a_mob_id, "integer").",".
931  $ilDB->quote($a_type, "text").",".
932  $ilDB->quote((int) $a_id, "integer").",".
933  $ilDB->quote((int) $a_usage_hist_nr, "integer").")";
934  $ilDB->manipulate($q);
935  }
936 
940  function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
941  {
942  global $ilDB;
943 
944  $q = "DELETE FROM mob_usage WHERE ".
945  " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
946  " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
947  " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
948  " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
949  $ilDB->manipulate($q);
950  }
951 
955  function getUsages($a_include_history = true)
956  {
957  return $this->lookupUsages($this->getId(), $a_include_history);
958  }
959 
965  function lookupUsages($a_id, $a_include_history = true)
966  {
967  global $ilDB;
968 
969  $hist_str = "";
970  if ($a_include_history)
971  {
972  $hist_str = ", usage_hist_nr";
973  }
974 
975  // get usages in pages
976  $q = "SELECT DISTINCT usage_type, usage_id".$hist_str." FROM mob_usage WHERE id = ".
977  $ilDB->quote($a_id, "integer");
978 
979  $us_set = $ilDB->query($q);
980  $ret = array();
981  while($us_rec = $ilDB->fetchAssoc($us_set))
982  {
983  $ut = "";
984  if(is_int(strpos($us_rec["usage_type"], ":")))
985  {
986  $us_arr = explode(":", $us_rec["usage_type"]);
987  $ut = $us_arr[1];
988  $ct = $us_arr[0];
989  }
990 
991  // check whether page exists
992  $skip = false;
993  if ($ut == "pg")
994  {
995  include_once("./Services/COPage/classes/class.ilPageObject.php");
996  if (!ilPageObject::_exists($ct, $us_rec["usage_id"]))
997  {
998  $skip = true;
999  }
1000  }
1001 
1002  if (!$skip)
1003  {
1004  $ret[] = array("type" => $us_rec["usage_type"],
1005  "id" => $us_rec["usage_id"],
1006  "hist_nr" => $us_rec["usage_hist_nr"]);
1007  }
1008  }
1009 
1010  // get usages in media pools
1011  $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = ".
1012  $ilDB->quote($a_id, "integer")." AND mep_item.type = ".$ilDB->quote("mob", "text");
1013  $us_set = $ilDB->query($q);
1014  while($us_rec = $ilDB->fetchAssoc($us_set))
1015  {
1016  $ret[] = array("type" => "mep",
1017  "id" => $us_rec["mep_id"]);
1018  }
1019 
1020  // get usages in news items (media casts)
1021  include_once("./Services/News/classes/class.ilNewsItem.php");
1022  $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
1023  foreach($news_usages as $nu)
1024  {
1025  $ret[] = $nu;
1026  }
1027 
1028 
1029  // get usages in map areas
1030  $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area ".
1031  " WHERE area.item_id = it.id ".
1032  " AND area.link_type = ".$ilDB->quote("int", "text")." ".
1033  " AND area.target = ".$ilDB->quote("il__mob_".$a_id, "text");
1034  $us_set = $ilDB->query($q);
1035  while($us_rec = $ilDB->fetchAssoc($us_set))
1036  {
1037  $ret[] = array("type" => "map",
1038  "id" => $us_rec["mob_id"]);
1039  }
1040 
1041  // get usages in personal clipboards
1042  $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
1043  foreach ($users as $user)
1044  {
1045  $ret[] = array("type" => "clip",
1046  "id" => $user);
1047  }
1048 
1049  return $ret;
1050  }
1051 
1055  function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
1056  {
1057  if(is_int(strpos($a_usage["type"], ":")))
1058  {
1059  $us_arr = explode(":", $a_usage["type"]);
1060  $type = $us_arr[1];
1061  $cont_type = $us_arr[0];
1062  }
1063  else
1064  {
1065  $type = $a_usage["type"];
1066  }
1067 
1068  $id = $a_usage["id"];
1069  $obj_id = false;
1070 
1071  switch($type)
1072  {
1073  case "html": // "old" category pages
1074  if ($cont_type == "cat")
1075  {
1076  $obj_id = $id;
1077  }
1078  // Test InfoScreen Text
1079  if ($cont_type == "tst")
1080  {
1081  $obj_id = $id;
1082  //var_dump($qinfo);
1083  }
1084  // Question Pool *Question* Text
1085  if ($cont_type == "qpl")
1086  {
1087  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1089  if ($qinfo["original_id"] > 0)
1090  {
1091  include_once("./Modules/Test/classes/class.ilObjTest.php");
1092  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1093  }
1094  else
1095  {
1096  $obj_id = $qinfo["obj_fi"]; // usage in pool
1097  }
1098  }
1099 
1100  // Forum
1101  if ($cont_type == "frm")
1102  {
1103  $post_pk = $a_usage['id'];
1104  include_once 'Modules/Forum/classes/class.ilForumPost.php';
1105  include_once 'Modules/Forum/classes/class.ilForum.php';
1106  $oPost = new ilForumPost($post_pk);
1107  $frm_pk = $oPost->getForumId();
1108 
1109  $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1110  }
1111 
1112  if ($cont_type == 'frm~')
1113  {
1114  $obj_id = $a_usage['id'];
1115  }
1116 
1117  break;
1118 
1119  case "pg":
1120 
1121  // Question Pool Question Pages
1122  if ($cont_type == "qpl")
1123  {
1124  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1126  if ($qinfo["original_id"] > 0)
1127  {
1128  include_once("./Modules/Test/classes/class.ilObjTest.php");
1129  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1130  }
1131  else
1132  {
1133  $obj_id = $qinfo["obj_fi"]; // usage in pool
1134  }
1135  }
1136 
1137  // learning modules
1138  if ($cont_type == "lm" || $cont_type == "dbk")
1139  {
1140  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1141  $obj_id = ilLMObject::_lookupContObjID($id);
1142  }
1143 
1144  // glossary definition
1145  if ($cont_type == "gdf")
1146  {
1147  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1148  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1150  $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1151  }
1152 
1153  // wiki page
1154  if ($cont_type == 'wpg')
1155  {
1156  include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
1158  }
1159 
1160  // sahs page
1161  if ($cont_type == 'sahs')
1162  {
1163  // can this implementation be used for other content types, too?
1164  include_once('./Services/COPage/classes/class.ilPageObject.php');
1165  $obj_id = ilPageObject::lookupParentId($id, 'sahs');
1166  }
1167 
1168  // repository pages
1169  if (in_array($cont_type, array("crs", "grp", "cat", "fold", "root")))
1170  {
1171  $obj_id = $id;
1172  }
1173  break;
1174 
1175  // Media Pool
1176  case "mep":
1177  $obj_id = $id;
1178  break;
1179 
1180  // News Context Object (e.g. MediaCast)
1181  case "news":
1182  include_once("./Services/News/classes/class.ilNewsItem.php");
1184  break;
1185  }
1186 
1187  return $obj_id;
1188  }
1189 
1197  function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1198  {
1199  $file_path = pathinfo($a_file);
1200  $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
1201  strlen($file_path["extension"]) - 1)."_".
1202  $a_width."_".
1203  $a_height.".".$file_path["extension"];
1204  $target_file = $file_path["dirname"]."/".
1205  $location;
1206  ilUtil::resizeImage($a_file, $target_file,
1207  (int) $a_width, (int) $a_height, $a_constrain_prop);
1208 
1209  return $location;
1210  }
1211 
1219  static function getMimeType ($a_file)
1220  {
1221  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1222  $mime = ilMimeTypeUtil::getMimeType($a_file);
1223  return $mime;
1224 /*
1225  // check if mimetype detection enabled in php.ini
1226  $set = ini_get("mime_magic.magicfile");
1227  // get mimetype
1228  if ($set <> "")
1229  {
1230  $mime = @mime_content_type($a_file);
1231  }
1232 
1233  // some php installations return always
1234  // text/plain, so we make our own detection in this case, too
1235  if (empty($mime) || $mime == "text/plain")
1236  {
1237  $path = pathinfo($a_file);
1238  $ext = ".".strtolower($path["extension"]);
1239 
1240  $types_map = ilObjMediaObject::getExt2MimeMap();
1241  $mime = $types_map[$ext];
1242  }
1243 
1244  // set default if mimetype detection failed or not possible (e.g. remote file)
1245  if (empty($mime))
1246  {
1247  $mime = "application/octet-stream";
1248  }
1249 
1250  return $mime;
1251 */
1252  }
1253 
1257  static function _determineWidthHeight($a_def_width, $a_def_height, $a_format, $a_type,
1258  $a_file, $a_reference, $a_constrain_proportions, $a_use_original,
1259  $a_user_width, $a_user_height)
1260  {
1261  global $lng;
1262 
1263  // determine width and height of known image types
1264  $width = $a_def_width;
1265  $height = $a_def_height;
1266  $info = "";
1267 
1268  if ($a_format == "audio/mpeg")
1269  {
1270  $width = 300;
1271  $height = 20;
1272  }
1273 
1274  if (ilUtil::deducibleSize($a_format))
1275  {
1276  if ($a_type == "File")
1277  {
1278  $size = @getimagesize($a_file);
1279  }
1280  else
1281  {
1282  $size = @getimagesize($a_reference);
1283  }
1284  }
1285 
1286  if ($a_use_original)
1287  {
1288  if ($size[0] > 0 && $size[1] > 0)
1289  {
1290  $width = $size[0];
1291  $height = $size[1];
1292  }
1293  else
1294  {
1295  $info = $lng->txt("cont_could_not_determine_resource_size");
1296  }
1297  }
1298  else
1299  {
1300  $w = (int) $a_user_width;
1301  $h = (int) $a_user_height;
1302  $width = $w;
1303  $height = $h;
1304 //echo "<br>C-$width-$height-";
1305  if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions)
1306  {
1307  if ($size[0] > 0 && $size[1] > 0)
1308  {
1309  if ($w > 0)
1310  {
1311  $wr = $size[0] / $w;
1312  }
1313  if ($h > 0)
1314  {
1315  $hr = $size[1] / $h;
1316  }
1317 //echo "<br>+".$wr."+".$size[0]."+".$w."+";
1318 //echo "<br>+".$hr."+".$size[1]."+".$h."+";
1319  $r = max($wr, $hr);
1320  if ($r > 0)
1321  {
1322  $width = (int) ($size[0]/$r);
1323  $height = (int) ($size[1]/$r);
1324  }
1325  }
1326  }
1327 //echo "<br>D-$width-$height-";
1328  }
1329 //echo "<br>E-$width-$height-";
1330  return array("width" => $width, "height" => $height, "info" => $info);
1331  }
1332 
1336  function getExt2MimeMap()
1337  {
1338  $types_map = array (
1339  '.a' => 'application/octet-stream',
1340  '.ai' => 'application/postscript',
1341  '.aif' => 'audio/x-aiff',
1342  '.aifc' => 'audio/x-aiff',
1343  '.aiff' => 'audio/x-aiff',
1344  '.asd' => 'application/astound',
1345  '.asf' => 'video/x-ms-asf',
1346  '.asn' => 'application/astound',
1347  '.asx' => 'video/x-ms-asf',
1348  '.au' => 'audio/basic',
1349  '.avi' => 'video/x-msvideo',
1350  '.bat' => 'text/plain',
1351  '.bcpio' => 'application/x-bcpio',
1352  '.bin' => 'application/octet-stream',
1353  '.bmp' => 'image/x-ms-bmp',
1354  '.c' => 'text/plain',
1355  '.cdf' => 'application/x-cdf',
1356  '.class' => 'application/x-java-applet',
1357  '.com' => 'application/octet-stream',
1358  '.cpio' => 'application/x-cpio',
1359  '.csh' => 'application/x-csh',
1360  '.css' => 'text/css',
1361  '.csv' => 'text/comma-separated-values',
1362  '.dcr' => 'application/x-director',
1363  '.dir' => 'application/x-director',
1364  '.dll' => 'application/octet-stream',
1365  '.doc' => 'application/msword',
1366  '.dot' => 'application/msword',
1367  '.dvi' => 'application/x-dvi',
1368  '.dwg' => 'application/acad',
1369  '.dxf' => 'application/dxf',
1370  '.dxr' => 'application/x-director',
1371  '.eml' => 'message/rfc822',
1372  '.eps' => 'application/postscript',
1373  '.etx' => 'text/x-setext',
1374  '.exe' => 'application/octet-stream',
1375  '.flv' => 'video/x-flv',
1376  '.gif' => 'image/gif',
1377  '.gtar' => 'application/x-gtar',
1378  '.gz' => 'application/gzip',
1379  '.h' => 'text/plain',
1380  '.hdf' => 'application/x-hdf',
1381  '.htm' => 'text/html',
1382  '.html' => 'text/html',
1383  '.ief' => 'image/ief',
1384  '.iff' => 'image/iff',
1385  '.jar' => 'application/x-java-applet',
1386  '.jpe' => 'image/jpeg',
1387  '.jpeg' => 'image/jpeg',
1388  '.jpg' => 'image/jpeg',
1389  '.js' => 'application/x-javascript',
1390  '.ksh' => 'text/plain',
1391  '.latex' => 'application/x-latex',
1392  '.m1v' => 'video/mpeg',
1393  '.man' => 'application/x-troff-man',
1394  '.me' => 'application/x-troff-me',
1395  '.mht' => 'message/rfc822',
1396  '.mhtml' => 'message/rfc822',
1397  '.mid' => 'audio/x-midi',
1398  '.midi' => 'audio/x-midi',
1399  '.mif' => 'application/x-mif',
1400  '.mov' => 'video/quicktime',
1401  '.movie' => 'video/x-sgi-movie',
1402  '.mp2' => 'audio/mpeg',
1403  '.mp3' => 'audio/mpeg',
1404  '.mpa' => 'video/mpeg',
1405  '.mpe' => 'video/mpeg',
1406  '.mpeg' => 'video/mpeg',
1407  '.mpg' => 'video/mpeg',
1408  '.mp4' => 'video/mp4',
1409  '.mv4' => 'video/mp4',
1410  '.ms' => 'application/x-troff-ms',
1411  '.nc' => 'application/x-netcdf',
1412  '.nws' => 'message/rfc822',
1413  '.o' => 'application/octet-stream',
1414  '.ogg' => 'application/ogg',
1415  '.obj' => 'application/octet-stream',
1416  '.oda' => 'application/oda',
1417  '.p12' => 'application/x-pkcs12',
1418  '.p7c' => 'application/pkcs7-mime',
1419  '.pbm' => 'image/x-portable-bitmap',
1420  '.pdf' => 'application/pdf',
1421  '.pfx' => 'application/x-pkcs12',
1422  '.pgm' => 'image/x-portable-graymap',
1423  '.php' => 'application/x-httpd-php',
1424  '.phtml' => 'application/x-httpd-php',
1425  '.pl' => 'text/plain',
1426  '.png' => 'image/png',
1427  '.pnm' => 'image/x-portable-anymap',
1428  '.pot' => 'application/vnd.ms-powerpoint',
1429  '.ppa' => 'application/vnd.ms-powerpoint',
1430  '.ppm' => 'image/x-portable-pixmap',
1431  '.pps' => 'application/vnd.ms-powerpoint',
1432  '.ppt' => 'application/vnd.ms-powerpoint',
1433  '.ps' => 'application/postscript',
1434  '.psd' => 'image/psd',
1435  '.pwz' => 'application/vnd.ms-powerpoint',
1436  '.py' => 'text/x-python',
1437  '.pyc' => 'application/x-python-code',
1438  '.pyo' => 'application/x-python-code',
1439  '.qt' => 'video/quicktime',
1440  '.ra' => 'audio/x-pn-realaudio',
1441  '.ram' => 'application/x-pn-realaudio',
1442  '.ras' => 'image/x-cmu-raster',
1443  '.rdf' => 'application/xml',
1444  '.rgb' => 'image/x-rgb',
1445  '.roff' => 'application/x-troff',
1446  '.rpm' => 'audio/x-pn-realaudio-plugin',
1447  '.rtf' => 'application/rtf',
1448  '.rtx' => 'text/richtext',
1449  '.sgm' => 'text/x-sgml',
1450  '.sgml' => 'text/x-sgml',
1451  '.sh' => 'application/x-sh',
1452  '.shar' => 'application/x-shar',
1453  '.sit' => 'application/x-stuffit',
1454  '.snd' => 'audio/basic',
1455  '.so' => 'application/octet-stream',
1456  '.spc' => 'text/x-speech',
1457  '.src' => 'application/x-wais-source',
1458  '.sv4cpio'=> 'application/x-sv4cpio',
1459  '.sv4crc' => 'application/x-sv4crc',
1460  '.svg' => 'image/svg+xml',
1461  '.swf' => 'application/x-shockwave-flash',
1462  '.t' => 'application/x-troff',
1463  '.tar' => 'application/x-tar',
1464  '.talk' => 'text/x-speech',
1465  '.tbk' => 'application/toolbook',
1466  '.tcl' => 'application/x-tcl',
1467  '.tex' => 'application/x-tex',
1468  '.texi' => 'application/x-texinfo',
1469  '.texinfo'=> 'application/x-texinfo',
1470  '.tif' => 'image/tiff',
1471  '.tiff' => 'image/tiff',
1472  '.tr' => 'application/x-troff',
1473  '.tsv' => 'text/tab-separated-values',
1474  '.tsp' => 'application/dsptype',
1475  '.txt' => 'text/plain',
1476  '.ustar' => 'application',
1477  '.vcf' => 'text/x-vcard',
1478  '.vox' => 'audio/voxware',
1479  '.wav' => 'audio/x-wav',
1480  '.wax' => 'audio/x-ms-wax',
1481  '.wiz' => 'application/msword',
1482  '.wm' => 'video/x-ms-wm',
1483  '.wma' => 'audio/x-ms-wma',
1484  '.wmd' => 'video/x-ms-wmd',
1485  '.wml' => 'text/vnd.wap.wml',
1486  '.wmlc' => 'application/vnd.wap.wmlc',
1487  '.wmls' => 'text/vnd.wap.wmlscript',
1488  '.wmlsc' => 'application/vnd.wap.wmlscriptc',
1489  '.wmv' => 'video/x-ms-wmv',
1490  '.wmx' => 'video/x-ms-wmx',
1491  '.wmz' => 'video/x-ms-wmz',
1492  '.wvx' => 'video/x-ms-wvx',
1493  '.wrl' => 'x-world/x-vrml',
1494  '.xbm' => 'image/x-xbitmap',
1495  '.xla' => 'application/msexcel',
1496  '.xlb' => 'application/vnd.ms-excel',
1497  '.xls' => 'application/msexcel',
1498  '.xml' => 'text/xml',
1499  '.xpm' => 'image/x-xpixmap',
1500  '.xsl' => 'application/xml',
1501  '.xwd' => 'image/x-xwindowdump',
1502  '.zip' => 'application/zip');
1503 
1504  return $types_map;
1505  }
1506 
1511  static function _getSimpleMimeTypes()
1512  {
1513  return array("image/x-ms-bmp", "image/gif", "image/jpeg", "image/x-portable-bitmap",
1514  "image/png", "image/psd", "image/tiff", "application/pdf");
1515  }
1516 
1517  function getDataDirectory()
1518  {
1519  return ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1520  }
1521 
1528  static function _useAutoStartParameterOnly($a_loc, $a_format)
1529  {
1530  $lpath = pathinfo($a_loc);
1531  if ($lpath["extension"] == "mp3" && $a_format == "audio/mpeg")
1532  {
1533  return true;
1534  }
1535  if ($lpath["extension"] == "flv")
1536  {
1537  return true;
1538  }
1539  return false;
1540  }
1541 
1545  function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
1546  {
1547  // create dummy object in db (we need an id)
1548  $media_object = new ilObjMediaObject();
1549  $media_object->setTitle($name);
1550  $media_object->setDescription("");
1551  $media_object->create();
1552 
1553  // determine and create mob directory, move uploaded file to directory
1554  $media_object->createDirectory();
1555  $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1556 
1557  $media_item =& new ilMediaItem();
1558  $media_object->addMediaItem($media_item);
1559  $media_item->setPurpose("Standard");
1560 
1561  $file = $mob_dir."/".$name;
1562  if ($upload)
1563  {
1564  ilUtil::moveUploadedFile($tmp_name,$name, $file);
1565  }
1566  else
1567  {
1568  copy($tmp_name, $file);
1569  }
1570  // get mime type
1572  $location = $name;
1573  // set real meta and object data
1574  $media_item->setFormat($format);
1575  $media_item->setLocation($location);
1576  $media_item->setLocationType("LocalFile");
1577  $media_object->setTitle($name);
1578  $media_object->setDescription($format);
1579 
1580  if (ilUtil::deducibleSize($format))
1581  {
1582  $size = getimagesize($file);
1583  $media_item->setWidth($size[0]);
1584  $media_item->setHeight($size[1]);
1585  }
1586  $media_item->setHAlign("Left");
1587 
1588  ilUtil::renameExecutables($mob_dir);
1589  $media_object->update();
1590 
1591  return $media_object;
1592  }
1593 
1597  function getLinkedMediaObjects($a_ignore = "")
1598  {
1599  $linked = array();
1600 
1601  if (!is_array($a_ignore))
1602  {
1603  $a_ignore = array();
1604  }
1605 
1606  // get linked media objects (map areas)
1607  $med_items = $this->getMediaItems();
1608 
1609  foreach($med_items as $med_item)
1610  {
1611  $int_links = ilMapArea::_getIntLinks($med_item->getId());
1612  foreach ($int_links as $k => $int_link)
1613  {
1614  if ($int_link["Type"] == "MediaObject")
1615  {
1616  include_once("./Services/COPage/classes/class.ilInternalLink.php");
1617  $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1618  if (ilObject::_exists($l_id))
1619  {
1620  if (!in_array($l_id, $linked) &&
1621  !in_array($l_id, $a_ignore))
1622  {
1623  $linked[] = $l_id;
1624  }
1625  }
1626  }
1627  }
1628  }
1629 //var_dump($linked);
1630  return $linked;
1631  }
1632 }
1633 ?>