ILIAS  Release_4_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 "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()
459  {
460  $this->updateMetaData();
461  parent::update();
462 
464 
465  // iterate all items
466  $media_items =& $this->getMediaItems();
467  $j = 1;
468  foreach($media_items as $key => $val)
469  {
470  $item =& $media_items[$key];
471  if (is_object($item))
472  {
473  $item->setMobId($this->getId());
474  $item->setNr($j);
475  if ($item->getLocationType() == "Reference")
476  {
477  $item->extractUrlParameters();
478  }
479  $item->create();
480  $j++;
481  }
482  }
483  }
484 
490  function _getDirectory($a_mob_id)
491  {
492  return ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
493  }
494 
500  function _getURL($a_mob_id)
501  {
502  return ilUtil::getHtmlPath(ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id);
503  }
504 
510  function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
511  {
512  return ilUtil::getWebspaceDir($a_mode)."/thumbs/mm_".$a_mob_id;
513  }
514 
520  static function _lookupStandardItemPath($a_mob_id, $a_url_encode = false,
521  $a_web = true)
522  {
523  return ilObjMediaObject::_lookupItemPath($a_mob_id, $a_url_encode, $a_web, "Standard");
524  }
525 
531  static function _lookupItemPath($a_mob_id, $a_url_encode = false,
532  $a_web = true, $a_purpose = "")
533  {
534  if ($a_purpose == "")
535  {
536  $a_purpose = "Standard";
537  }
538  $location = ilMediaItem::_lookupLocationForMobId($a_mob_id, $a_purpose);
539  if (preg_match("/https?\:/i",$location))
540  return $location;
541 
542  if ($a_url_encode)
543  $location = rawurlencode($location);
544 
545  $path = ($a_web)
546  ? ILIAS_HTTP_PATH
547  : ".";
548 
549  return $path."/data/".CLIENT_ID."/mobs/mm_".$a_mob_id."/".$location;
550  }
551 
555  function createDirectory()
556  {
558  }
559 
563  function _createThumbnailDirectory($a_obj_id)
564  {
566  ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs/mm_".$a_obj_id);
567  }
568 
573  function getXML($a_mode = IL_MODE_FULL, $a_inst = 0)
574  {
575  // TODO: full implementation of all parameters
576 //echo "-".$a_mode."-";
577  switch ($a_mode)
578  {
579  case IL_MODE_ALIAS:
580  $xml = "<MediaObject>";
581  $xml .= "<MediaAlias OriginId=\"il__mob_".$this->getId()."\"/>";
582  $media_items =& $this->getMediaItems();
583  for($i=0; $i<count($media_items); $i++)
584  {
585  $item =& $media_items[$i];
586  $xml .= "<MediaAliasItem Purpose=\"".$item->getPurpose()."\">";
587 
588  // Layout
589  $width = ($item->getWidth() != "")
590  ? "Width=\"".$item->getWidth()."\""
591  : "";
592  $height = ($item->getHeight() != "")
593  ? "Height=\"".$item->getHeight()."\""
594  : "";
595  $halign = ($item->getHAlign() != "")
596  ? "HorizontalAlign=\"".$item->getHAlign()."\""
597  : "";
598  $xml .= "<Layout $width $height $halign />";
599 
600  // Caption
601  if ($item->getCaption() != "")
602  {
603  $xml .= "<Caption Align=\"bottom\">".
604  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
605  }
606 
607  // Text Representation
608  if ($item->getTextRepresentation() != "")
609  {
610  $xml .= "<TextRepresentation>".
611  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
612  }
613 
614  // Parameter
615  $parameters = $item->getParameters();
616  foreach ($parameters as $name => $value)
617  {
618  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
619  }
620  $xml .= "</MediaAliasItem>";
621  }
622  break;
623 
624  // for output we need technical sections of meta data
625  case IL_MODE_OUTPUT:
626 
627  // get first technical section
628 // $meta =& $this->getMetaData();
629  $xml = "<MediaObject Id=\"il__mob_".$this->getId()."\">";
630 
631  $media_items =& $this->getMediaItems();
632  for($i=0; $i<count($media_items); $i++)
633  {
634  $item =& $media_items[$i];
635  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
636 
637  // Location
638  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
639  $this->handleAmps($item->getLocation())."</Location>";
640 
641  // Format
642  $xml.= "<Format>".$item->getFormat()."</Format>";
643 
644  // Layout
645  $width = ($item->getWidth() != "")
646  ? "Width=\"".$item->getWidth()."\""
647  : "";
648  $height = ($item->getHeight() != "")
649  ? "Height=\"".$item->getHeight()."\""
650  : "";
651  $halign = ($item->getHAlign() != "")
652  ? "HorizontalAlign=\"".$item->getHAlign()."\""
653  : "";
654  $xml .= "<Layout $width $height $halign />";
655 
656  // Caption
657  if ($item->getCaption() != "")
658  {
659  $xml .= "<Caption Align=\"bottom\">".
660  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
661  }
662 
663  // Text Representation
664  if ($item->getTextRepresentation() != "")
665  {
666  $xml .= "<TextRepresentation>".
667  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
668  }
669 
670  // Parameter
671  $parameters = $item->getParameters();
672  foreach ($parameters as $name => $value)
673  {
674  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
675  }
676  $xml .= $item->getMapAreasXML();
677  $xml .= "</MediaItem>";
678  }
679  break;
680 
681  // full xml for export
682  case IL_MODE_FULL:
683 
684 // $meta =& $this->getMetaData();
685  $xml = "<MediaObject>";
686 
687  // meta data
688  include_once("Services/MetaData/classes/class.ilMD2XML.php");
689  $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
690  $md2xml->setExportMode(true);
691  $md2xml->startExport();
692  $xml.= $md2xml->getXML();
693 
694  $media_items =& $this->getMediaItems();
695  for($i=0; $i<count($media_items); $i++)
696  {
697  $item =& $media_items[$i];
698  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
699 
700  // Location
701  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
702  $this->handleAmps($item->getLocation())."</Location>";
703 
704  // Format
705  $xml.= "<Format>".$item->getFormat()."</Format>";
706 
707  // Layout
708  $width = ($item->getWidth() != "")
709  ? "Width=\"".$item->getWidth()."\""
710  : "";
711  $height = ($item->getHeight() != "")
712  ? "Height=\"".$item->getHeight()."\""
713  : "";
714  $halign = ($item->getHAlign() != "")
715  ? "HorizontalAlign=\"".$item->getHAlign()."\""
716  : "";
717  $xml .= "<Layout $width $height $halign />";
718 
719  // Caption
720  if ($item->getCaption() != "")
721  {
722  $xml .= "<Caption Align=\"bottom\">".
723  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
724  }
725 
726  // Text Representation
727  if ($item->getTextRepresentation() != "")
728  {
729  $xml .= "<TextRepresentation>".
730  str_replace("&", "&amp;", $item->getTextRepresentation())."</TextRepresentation>";
731  }
732 
733  // Parameter
734  $parameters = $item->getParameters();
735  foreach ($parameters as $name => $value)
736  {
737  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
738  }
739  $xml .= $item->getMapAreasXML(true, $a_inst);
740  $xml .= "</MediaItem>";
741  }
742  break;
743  }
744  $xml .= "</MediaObject>";
745  return $xml;
746  }
747 
751  function handleAmps($a_str)
752  {
753  $a_str = str_replace("&amp;", "&", $a_str);
754  $a_str = str_replace("&", "&amp;", $a_str);
755  return $a_str;
756  }
757 
761  function exportXML(&$a_xml_writer, $a_inst = 0)
762  {
763  $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
764  }
765 
766 
774  function exportFiles($a_target_dir)
775  {
776  $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
777  ilUtil::makeDir($a_target_dir."/objects/".$subdir);
778 
779  $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
780  ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
781 //echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
782  }
783 
784 
785  function modifyExportIdentifier($a_tag, $a_param, $a_value)
786  {
787  if ($a_tag == "Identifier" && $a_param == "Entry")
788  {
789  $a_value = ilUtil::insertInstIntoID($a_value);
790  }
791 
792  return $a_value;
793  }
794 
795 
797  // EDIT METHODS: these methods act on the media alias in the dom
799 
806  function setContainsIntLink($a_contains_link)
807  {
808  $this->contains_int_link = $a_contains_link;
809  }
810 
815  function containsIntLink()
816  {
818  }
819 
823  function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0)
824  {
825  global $ilDB;
826 
827  $q = "DELETE FROM mob_usage WHERE usage_type = ".
828  $ilDB->quote($a_type, "text").
829  " AND usage_id= ".$ilDB->quote($a_id, "integer").
830  " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
831  $ilDB->manipulate($q);
832  }
833 
837  function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0)
838  {
839  global $ilDB;
840 
841  $q = "SELECT * FROM mob_usage WHERE ".
842  "usage_type = ".$ilDB->quote($a_type, "text")." AND ".
843  "usage_id = ".$ilDB->quote($a_id, "integer")." AND ".
844  "usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr, "integer");
845  $mobs = array();
846  $mob_set = $ilDB->query($q);
847  while($mob_rec = $ilDB->fetchAssoc($mob_set))
848  {
849  if (ilObject::_lookupType($mob_rec["id"]) == "mob")
850  {
851  $mobs[$mob_rec["id"]] = $mob_rec["id"];
852  }
853  }
854 
855  return $mobs;
856  }
857 
861  function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
862  {
863  global $ilDB;
864 
865  $q = "DELETE FROM mob_usage WHERE ".
866  " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
867  " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
868  " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
869  " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
870  $ilDB->manipulate($q);
871  $q = "INSERT INTO mob_usage (id, usage_type, usage_id, usage_hist_nr) VALUES".
872  " (".$ilDB->quote((int) $a_mob_id, "integer").",".
873  $ilDB->quote($a_type, "text").",".
874  $ilDB->quote((int) $a_id, "integer").",".
875  $ilDB->quote((int) $a_usage_hist_nr, "integer").")";
876  $ilDB->manipulate($q);
877  }
878 
882  function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
883  {
884  global $ilDB;
885 
886  $q = "DELETE FROM mob_usage WHERE ".
887  " id = ".$ilDB->quote((int) $a_mob_id, "integer")." AND ".
888  " usage_type = ".$ilDB->quote($a_type, "text")." AND ".
889  " usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
890  " usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
891  $ilDB->manipulate($q);
892  }
893 
897  function getUsages($a_include_history = true)
898  {
899  return $this->lookupUsages($this->getId(), $a_include_history);
900  }
901 
907  function lookupUsages($a_id, $a_include_history = true)
908  {
909  global $ilDB;
910 
911  $hist_str = "";
912  if ($a_include_history)
913  {
914  $hist_str = ", usage_hist_nr";
915  }
916 
917  // get usages in pages
918  $q = "SELECT DISTINCT usage_type, usage_id".$hist_str." FROM mob_usage WHERE id = ".
919  $ilDB->quote($a_id, "integer");
920 
921  $us_set = $ilDB->query($q);
922  $ret = array();
923  while($us_rec = $ilDB->fetchAssoc($us_set))
924  {
925  $ut = "";
926  if(is_int(strpos($us_rec["usage_type"], ":")))
927  {
928  $us_arr = explode(":", $us_rec["usage_type"]);
929  $ut = $us_arr[1];
930  $ct = $us_arr[0];
931  }
932 
933  // check whether page exists
934  $skip = false;
935  if ($ut == "pg")
936  {
937  include_once("./Services/COPage/classes/class.ilPageObject.php");
938  if (!ilPageObject::_exists($ct, $us_rec["usage_id"]))
939  {
940  $skip = true;
941  }
942  }
943 
944  if (!$skip)
945  {
946  $ret[] = array("type" => $us_rec["usage_type"],
947  "id" => $us_rec["usage_id"],
948  "hist_nr" => $us_rec["usage_hist_nr"]);
949  }
950  }
951 
952  // get usages in media pools
953  $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = ".
954  $ilDB->quote($a_id, "integer")." AND mep_item.type = ".$ilDB->quote("mob", "text");
955  $us_set = $ilDB->query($q);
956  while($us_rec = $ilDB->fetchAssoc($us_set))
957  {
958  $ret[] = array("type" => "mep",
959  "id" => $us_rec["mep_id"]);
960  }
961 
962  // get usages in news items (media casts)
963  include_once("./Services/News/classes/class.ilNewsItem.php");
964  $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
965  foreach($news_usages as $nu)
966  {
967  $ret[] = $nu;
968  }
969 
970 
971  // get usages in map areas
972  $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area ".
973  " WHERE area.item_id = it.id ".
974  " AND area.link_type = ".$ilDB->quote("int", "text")." ".
975  " AND area.target = ".$ilDB->quote("il__mob_".$a_id, "text");
976  $us_set = $ilDB->query($q);
977  while($us_rec = $ilDB->fetchAssoc($us_set))
978  {
979  $ret[] = array("type" => "map",
980  "id" => $us_rec["mob_id"]);
981  }
982 
983  // get usages in personal clipboards
984  $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
985  foreach ($users as $user)
986  {
987  $ret[] = array("type" => "clip",
988  "id" => $user);
989  }
990 
991  return $ret;
992  }
993 
997  function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
998  {
999  if(is_int(strpos($a_usage["type"], ":")))
1000  {
1001  $us_arr = explode(":", $a_usage["type"]);
1002  $type = $us_arr[1];
1003  $cont_type = $us_arr[0];
1004  }
1005  else
1006  {
1007  $type = $a_usage["type"];
1008  }
1009 
1010  $id = $a_usage["id"];
1011  $obj_id = false;
1012 
1013  switch($type)
1014  {
1015  case "html": // "old" category pages
1016  if ($cont_type == "cat")
1017  {
1018  $obj_id = $id;
1019  }
1020  // Test InfoScreen Text
1021  if ($cont_type == "tst")
1022  {
1023  $obj_id = $id;
1024  //var_dump($qinfo);
1025  }
1026  // Question Pool *Question* Text
1027  if ($cont_type == "qpl")
1028  {
1029  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1031  if ($qinfo["original_id"] > 0)
1032  {
1033  include_once("./Modules/Test/classes/class.ilObjTest.php");
1034  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1035  }
1036  else
1037  {
1038  $obj_id = $qinfo["obj_fi"]; // usage in pool
1039  }
1040  }
1041 
1042  // Forum
1043  if ($cont_type == "frm")
1044  {
1045  $post_pk = $a_usage['id'];
1046  include_once 'Modules/Forum/classes/class.ilForumPost.php';
1047  include_once 'Modules/Forum/classes/class.ilForum.php';
1048  $oPost = new ilForumPost($post_pk);
1049  $frm_pk = $oPost->getForumId();
1050 
1051  $obj_id = ilForum::_lookupObjIdForForumId($frm_pk);
1052  }
1053 
1054  if ($cont_type == 'frm~')
1055  {
1056  $obj_id = $a_usage['id'];
1057  }
1058 
1059  break;
1060 
1061  case "pg":
1062 
1063  // Question Pool Question Pages
1064  if ($cont_type == "qpl")
1065  {
1066  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1068  if ($qinfo["original_id"] > 0)
1069  {
1070  include_once("./Modules/Test/classes/class.ilObjTest.php");
1071  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1072  }
1073  else
1074  {
1075  $obj_id = $qinfo["obj_fi"]; // usage in pool
1076  }
1077  }
1078 
1079  // learning modules
1080  if ($cont_type == "lm" || $cont_type == "dbk")
1081  {
1082  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1083  $obj_id = ilLMObject::_lookupContObjID($id);
1084  }
1085 
1086  // glossary definition
1087  if ($cont_type == "gdf")
1088  {
1089  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1090  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1092  $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1093  }
1094 
1095  // wiki page
1096  if ($cont_type == 'wpg')
1097  {
1098  include_once 'Modules/Wiki/classes/class.ilWikiPage.php';
1100  }
1101 
1102  // sahs page
1103  if ($cont_type == 'sahs')
1104  {
1105  // can this implementation be used for other content types, too?
1106  include_once('./Services/COPage/classes/class.ilPageObject.php');
1107  $obj_id = ilPageObject::lookupParentId($id, 'sahs');
1108  }
1109 
1110  break;
1111 
1112  // Media Pool
1113  case "mep":
1114  $obj_id = $id;
1115  break;
1116 
1117  // News Context Object (e.g. MediaCast)
1118  case "news":
1119  include_once("./Services/News/classes/class.ilNewsItem.php");
1121  break;
1122  }
1123 
1124  return $obj_id;
1125  }
1126 
1134  function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1135  {
1136  $file_path = pathinfo($a_file);
1137  $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
1138  strlen($file_path["extension"]) - 1)."_".
1139  $a_width."_".
1140  $a_height.".".$file_path["extension"];
1141  $target_file = $file_path["dirname"]."/".
1142  $location;
1143  ilUtil::resizeImage($a_file, $target_file,
1144  (int) $a_width, (int) $a_height, $a_constrain_prop);
1145 
1146  return $location;
1147  }
1148 
1156  static function getMimeType ($a_file)
1157  {
1158  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1159  $mime = ilMimeTypeUtil::getMimeType($a_file);
1160  return $mime;
1161 /*
1162  // check if mimetype detection enabled in php.ini
1163  $set = ini_get("mime_magic.magicfile");
1164  // get mimetype
1165  if ($set <> "")
1166  {
1167  $mime = @mime_content_type($a_file);
1168  }
1169 
1170  // some php installations return always
1171  // text/plain, so we make our own detection in this case, too
1172  if (empty($mime) || $mime == "text/plain")
1173  {
1174  $path = pathinfo($a_file);
1175  $ext = ".".strtolower($path["extension"]);
1176 
1177  $types_map = ilObjMediaObject::getExt2MimeMap();
1178  $mime = $types_map[$ext];
1179  }
1180 
1181  // set default if mimetype detection failed or not possible (e.g. remote file)
1182  if (empty($mime))
1183  {
1184  $mime = "application/octet-stream";
1185  }
1186 
1187  return $mime;
1188 */
1189  }
1190 
1194  static function _determineWidthHeight($a_def_width, $a_def_height, $a_format, $a_type,
1195  $a_file, $a_reference, $a_constrain_proportions, $a_use_original,
1196  $a_user_width, $a_user_height)
1197  {
1198  global $lng;
1199 
1200  // determine width and height of known image types
1201  $width = $a_def_width;
1202  $height = $a_def_height;
1203  $info = "";
1204 
1205  if ($a_format == "audio/mpeg")
1206  {
1207  $width = 300;
1208  $height = 20;
1209  }
1210 
1211  if (ilUtil::deducibleSize($a_format))
1212  {
1213  if ($a_type == "File")
1214  {
1215  $size = @getimagesize($a_file);
1216  }
1217  else
1218  {
1219  $size = @getimagesize($a_reference);
1220  }
1221  }
1222 
1223  if ($a_use_original)
1224  {
1225  if ($size[0] > 0 && $size[1] > 0)
1226  {
1227  $width = $size[0];
1228  $height = $size[1];
1229  }
1230  else
1231  {
1232  $info = $lng->txt("cont_could_not_determine_resource_size");
1233  }
1234  }
1235  else
1236  {
1237  $w = (int) $a_user_width;
1238  $h = (int) $a_user_height;
1239  $width = $w;
1240  $height = $h;
1241 //echo "<br>C-$width-$height-";
1242  if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions)
1243  {
1244  if ($size[0] > 0 && $size[1] > 0)
1245  {
1246  if ($w > 0)
1247  {
1248  $wr = $size[0] / $w;
1249  }
1250  if ($h > 0)
1251  {
1252  $hr = $size[1] / $h;
1253  }
1254 //echo "<br>+".$wr."+".$size[0]."+".$w."+";
1255 //echo "<br>+".$hr."+".$size[1]."+".$h."+";
1256  $r = max($wr, $hr);
1257  if ($r > 0)
1258  {
1259  $width = (int) ($size[0]/$r);
1260  $height = (int) ($size[1]/$r);
1261  }
1262  }
1263  }
1264 //echo "<br>D-$width-$height-";
1265  }
1266 //echo "<br>E-$width-$height-";
1267  return array("width" => $width, "height" => $height, "info" => $info);
1268  }
1269 
1273  function getExt2MimeMap()
1274  {
1275  $types_map = array (
1276  '.a' => 'application/octet-stream',
1277  '.ai' => 'application/postscript',
1278  '.aif' => 'audio/x-aiff',
1279  '.aifc' => 'audio/x-aiff',
1280  '.aiff' => 'audio/x-aiff',
1281  '.asd' => 'application/astound',
1282  '.asf' => 'video/x-ms-asf',
1283  '.asn' => 'application/astound',
1284  '.asx' => 'video/x-ms-asf',
1285  '.au' => 'audio/basic',
1286  '.avi' => 'video/x-msvideo',
1287  '.bat' => 'text/plain',
1288  '.bcpio' => 'application/x-bcpio',
1289  '.bin' => 'application/octet-stream',
1290  '.bmp' => 'image/x-ms-bmp',
1291  '.c' => 'text/plain',
1292  '.cdf' => 'application/x-cdf',
1293  '.class' => 'application/x-java-applet',
1294  '.com' => 'application/octet-stream',
1295  '.cpio' => 'application/x-cpio',
1296  '.csh' => 'application/x-csh',
1297  '.css' => 'text/css',
1298  '.csv' => 'text/comma-separated-values',
1299  '.dcr' => 'application/x-director',
1300  '.dir' => 'application/x-director',
1301  '.dll' => 'application/octet-stream',
1302  '.doc' => 'application/msword',
1303  '.dot' => 'application/msword',
1304  '.dvi' => 'application/x-dvi',
1305  '.dwg' => 'application/acad',
1306  '.dxf' => 'application/dxf',
1307  '.dxr' => 'application/x-director',
1308  '.eml' => 'message/rfc822',
1309  '.eps' => 'application/postscript',
1310  '.etx' => 'text/x-setext',
1311  '.exe' => 'application/octet-stream',
1312  '.flv' => 'video/x-flv',
1313  '.gif' => 'image/gif',
1314  '.gtar' => 'application/x-gtar',
1315  '.gz' => 'application/gzip',
1316  '.h' => 'text/plain',
1317  '.hdf' => 'application/x-hdf',
1318  '.htm' => 'text/html',
1319  '.html' => 'text/html',
1320  '.ief' => 'image/ief',
1321  '.iff' => 'image/iff',
1322  '.jar' => 'application/x-java-applet',
1323  '.jpe' => 'image/jpeg',
1324  '.jpeg' => 'image/jpeg',
1325  '.jpg' => 'image/jpeg',
1326  '.js' => 'application/x-javascript',
1327  '.ksh' => 'text/plain',
1328  '.latex' => 'application/x-latex',
1329  '.m1v' => 'video/mpeg',
1330  '.man' => 'application/x-troff-man',
1331  '.me' => 'application/x-troff-me',
1332  '.mht' => 'message/rfc822',
1333  '.mhtml' => 'message/rfc822',
1334  '.mid' => 'audio/x-midi',
1335  '.midi' => 'audio/x-midi',
1336  '.mif' => 'application/x-mif',
1337  '.mov' => 'video/quicktime',
1338  '.movie' => 'video/x-sgi-movie',
1339  '.mp2' => 'audio/mpeg',
1340  '.mp3' => 'audio/mpeg',
1341  '.mpa' => 'video/mpeg',
1342  '.mpe' => 'video/mpeg',
1343  '.mpeg' => 'video/mpeg',
1344  '.mpg' => 'video/mpeg',
1345  '.mp4' => 'video/mp4',
1346  '.mv4' => 'video/mp4',
1347  '.ms' => 'application/x-troff-ms',
1348  '.nc' => 'application/x-netcdf',
1349  '.nws' => 'message/rfc822',
1350  '.o' => 'application/octet-stream',
1351  '.ogg' => 'application/ogg',
1352  '.obj' => 'application/octet-stream',
1353  '.oda' => 'application/oda',
1354  '.p12' => 'application/x-pkcs12',
1355  '.p7c' => 'application/pkcs7-mime',
1356  '.pbm' => 'image/x-portable-bitmap',
1357  '.pdf' => 'application/pdf',
1358  '.pfx' => 'application/x-pkcs12',
1359  '.pgm' => 'image/x-portable-graymap',
1360  '.php' => 'application/x-httpd-php',
1361  '.phtml' => 'application/x-httpd-php',
1362  '.pl' => 'text/plain',
1363  '.png' => 'image/png',
1364  '.pnm' => 'image/x-portable-anymap',
1365  '.pot' => 'application/vnd.ms-powerpoint',
1366  '.ppa' => 'application/vnd.ms-powerpoint',
1367  '.ppm' => 'image/x-portable-pixmap',
1368  '.pps' => 'application/vnd.ms-powerpoint',
1369  '.ppt' => 'application/vnd.ms-powerpoint',
1370  '.ps' => 'application/postscript',
1371  '.psd' => 'image/psd',
1372  '.pwz' => 'application/vnd.ms-powerpoint',
1373  '.py' => 'text/x-python',
1374  '.pyc' => 'application/x-python-code',
1375  '.pyo' => 'application/x-python-code',
1376  '.qt' => 'video/quicktime',
1377  '.ra' => 'audio/x-pn-realaudio',
1378  '.ram' => 'application/x-pn-realaudio',
1379  '.ras' => 'image/x-cmu-raster',
1380  '.rdf' => 'application/xml',
1381  '.rgb' => 'image/x-rgb',
1382  '.roff' => 'application/x-troff',
1383  '.rpm' => 'audio/x-pn-realaudio-plugin',
1384  '.rtf' => 'application/rtf',
1385  '.rtx' => 'text/richtext',
1386  '.sgm' => 'text/x-sgml',
1387  '.sgml' => 'text/x-sgml',
1388  '.sh' => 'application/x-sh',
1389  '.shar' => 'application/x-shar',
1390  '.sit' => 'application/x-stuffit',
1391  '.snd' => 'audio/basic',
1392  '.so' => 'application/octet-stream',
1393  '.spc' => 'text/x-speech',
1394  '.src' => 'application/x-wais-source',
1395  '.sv4cpio'=> 'application/x-sv4cpio',
1396  '.sv4crc' => 'application/x-sv4crc',
1397  '.svg' => 'image/svg+xml',
1398  '.swf' => 'application/x-shockwave-flash',
1399  '.t' => 'application/x-troff',
1400  '.tar' => 'application/x-tar',
1401  '.talk' => 'text/x-speech',
1402  '.tbk' => 'application/toolbook',
1403  '.tcl' => 'application/x-tcl',
1404  '.tex' => 'application/x-tex',
1405  '.texi' => 'application/x-texinfo',
1406  '.texinfo'=> 'application/x-texinfo',
1407  '.tif' => 'image/tiff',
1408  '.tiff' => 'image/tiff',
1409  '.tr' => 'application/x-troff',
1410  '.tsv' => 'text/tab-separated-values',
1411  '.tsp' => 'application/dsptype',
1412  '.txt' => 'text/plain',
1413  '.ustar' => 'application',
1414  '.vcf' => 'text/x-vcard',
1415  '.vox' => 'audio/voxware',
1416  '.wav' => 'audio/x-wav',
1417  '.wax' => 'audio/x-ms-wax',
1418  '.wiz' => 'application/msword',
1419  '.wm' => 'video/x-ms-wm',
1420  '.wma' => 'audio/x-ms-wma',
1421  '.wmd' => 'video/x-ms-wmd',
1422  '.wml' => 'text/vnd.wap.wml',
1423  '.wmlc' => 'application/vnd.wap.wmlc',
1424  '.wmls' => 'text/vnd.wap.wmlscript',
1425  '.wmlsc' => 'application/vnd.wap.wmlscriptc',
1426  '.wmv' => 'video/x-ms-wmv',
1427  '.wmx' => 'video/x-ms-wmx',
1428  '.wmz' => 'video/x-ms-wmz',
1429  '.wvx' => 'video/x-ms-wvx',
1430  '.wrl' => 'x-world/x-vrml',
1431  '.xbm' => 'image/x-xbitmap',
1432  '.xla' => 'application/msexcel',
1433  '.xlb' => 'application/vnd.ms-excel',
1434  '.xls' => 'application/msexcel',
1435  '.xml' => 'text/xml',
1436  '.xpm' => 'image/x-xpixmap',
1437  '.xsl' => 'application/xml',
1438  '.xwd' => 'image/x-xwindowdump',
1439  '.zip' => 'application/zip');
1440 
1441  return $types_map;
1442  }
1443 
1448  static function _getSimpleMimeTypes()
1449  {
1450  return array("image/x-ms-bmp", "image/gif", "image/jpeg", "image/x-portable-bitmap",
1451  "image/png", "image/psd", "image/tiff", "application/pdf");
1452  }
1453 
1454  function getDataDirectory()
1455  {
1456  return ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1457  }
1458 
1465  static function _useAutoStartParameterOnly($a_loc, $a_format)
1466  {
1467  $lpath = pathinfo($a_loc);
1468  if ($lpath["extension"] == "mp3" && $a_format == "audio/mpeg")
1469  {
1470  return true;
1471  }
1472  if ($lpath["extension"] == "flv")
1473  {
1474  return true;
1475  }
1476  return false;
1477  }
1478 
1482  function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
1483  {
1484  // create dummy object in db (we need an id)
1485  $media_object = new ilObjMediaObject();
1486  $media_object->setTitle($name);
1487  $media_object->setDescription("");
1488  $media_object->create();
1489 
1490  // determine and create mob directory, move uploaded file to directory
1491  $media_object->createDirectory();
1492  $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1493 
1494  $media_item =& new ilMediaItem();
1495  $media_object->addMediaItem($media_item);
1496  $media_item->setPurpose("Standard");
1497 
1498  $file = $mob_dir."/".$name;
1499  if ($upload)
1500  {
1501  ilUtil::moveUploadedFile($tmp_name,$name, $file);
1502  }
1503  else
1504  {
1505  copy($tmp_name, $file);
1506  }
1507  // get mime type
1509  $location = $name;
1510  // set real meta and object data
1511  $media_item->setFormat($format);
1512  $media_item->setLocation($location);
1513  $media_item->setLocationType("LocalFile");
1514  $media_object->setTitle($name);
1515  $media_object->setDescription($format);
1516 
1517  if (ilUtil::deducibleSize($format))
1518  {
1519  $size = getimagesize($file);
1520  $media_item->setWidth($size[0]);
1521  $media_item->setHeight($size[1]);
1522  }
1523  $media_item->setHAlign("Left");
1524 
1525  ilUtil::renameExecutables($mob_dir);
1526  $media_object->update();
1527 
1528  return $media_object;
1529  }
1530 
1534  function getLinkedMediaObjects($a_ignore = "")
1535  {
1536  $linked = array();
1537 
1538  if (!is_array($a_ignore))
1539  {
1540  $a_ignore = array();
1541  }
1542 
1543  // get linked media objects (map areas)
1544  $med_items = $this->getMediaItems();
1545 
1546  foreach($med_items as $med_item)
1547  {
1548  $int_links = ilMapArea::_getIntLinks($med_item->getId());
1549  foreach ($int_links as $k => $int_link)
1550  {
1551  if ($int_link["Type"] == "MediaObject")
1552  {
1553  include_once("./Services/COPage/classes/class.ilInternalLink.php");
1554  $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1555  if (ilObject::_exists($l_id))
1556  {
1557  if (!in_array($l_id, $linked) &&
1558  !in_array($l_id, $a_ignore))
1559  {
1560  $linked[] = $l_id;
1561  }
1562  }
1563  }
1564  }
1565  }
1566 //var_dump($linked);
1567  return $linked;
1568  }
1569 }
1570 ?>