ILIAS  eassessment Revision 61809
 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  break;
1101 
1102  case "pg":
1103 
1104  // Question Pool Question Pages
1105  if ($cont_type == "qpl")
1106  {
1107  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1109  if ($qinfo["original_id"] > 0)
1110  {
1111  include_once("./Modules/Test/classes/class.ilObjTest.php");
1112  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1113  }
1114  else
1115  {
1116  $obj_id = $qinfo["obj_fi"]; // usage in pool
1117  }
1118  }
1119 
1120  // learning modules
1121  if ($cont_type == "lm" || $cont_type == "dbk")
1122  {
1123  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1124  $obj_id = ilLMObject::_lookupContObjID($id);
1125  }
1126 
1127  // glossary definition
1128  if ($cont_type == "gdf")
1129  {
1130  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1131  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1133  $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1134  }
1135 
1136  // Media Pool
1137  case "mep":
1138  $obj_id = $id;
1139  break;
1140 
1141  // News Context Object (e.g. MediaCast)
1142  case "news":
1143  include_once("./Services/News/classes/class.ilNewsItem.php");
1145  break;
1146  }
1147 
1148  return $obj_id;
1149  }
1150 
1158  function _resizeImage($a_file, $a_width, $a_height, $a_constrain_prop = false)
1159  {
1160  $file_path = pathinfo($a_file);
1161  $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
1162  strlen($file_path["extension"]) - 1)."_".
1163  $a_width."_".
1164  $a_height.".".$file_path["extension"];
1165  $target_file = $file_path["dirname"]."/".
1166  $location;
1167  ilUtil::resizeImage($a_file, $target_file,
1168  (int) $a_width, (int) $a_height, $a_constrain_prop);
1169 
1170  return $location;
1171  }
1172 
1180  static function getMimeType ($a_file)
1181  {
1182  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1183  $mime = ilMimeTypeUtil::getMimeType($a_file);
1184  return $mime;
1185 /*
1186  // check if mimetype detection enabled in php.ini
1187  $set = ini_get("mime_magic.magicfile");
1188  // get mimetype
1189  if ($set <> "")
1190  {
1191  $mime = @mime_content_type($a_file);
1192  }
1193 
1194  // some php installations return always
1195  // text/plain, so we make our own detection in this case, too
1196  if (empty($mime) || $mime == "text/plain")
1197  {
1198  $path = pathinfo($a_file);
1199  $ext = ".".strtolower($path["extension"]);
1200 
1201  $types_map = ilObjMediaObject::getExt2MimeMap();
1202  $mime = $types_map[$ext];
1203  }
1204 
1205  // set default if mimetype detection failed or not possible (e.g. remote file)
1206  if (empty($mime))
1207  {
1208  $mime = "application/octet-stream";
1209  }
1210 
1211  return $mime;
1212 */
1213  }
1214 
1218  static function _determineWidthHeight($a_def_width, $a_def_height, $a_format, $a_type,
1219  $a_file, $a_reference, $a_constrain_proportions, $a_use_original,
1220  $a_user_width, $a_user_height)
1221  {
1222  global $lng;
1223 
1224  // determine width and height of known image types
1225  $width = $a_def_width;
1226  $height = $a_def_height;
1227  $info = "";
1228 
1229  if ($a_format == "audio/mpeg")
1230  {
1231  $width = 300;
1232  $height = 20;
1233  }
1234 
1235  if (ilUtil::deducibleSize($a_format))
1236  {
1237  if ($a_type == "File")
1238  {
1239  $size = @getimagesize($a_file);
1240  }
1241  else
1242  {
1243  $size = @getimagesize($a_reference);
1244  }
1245  }
1246 
1247  if ($a_use_original)
1248  {
1249  if ($size[0] > 0 && $size[1] > 0)
1250  {
1251  $width = $size[0];
1252  $height = $size[1];
1253  }
1254  else
1255  {
1256  $info = $lng->txt("cont_could_not_determine_resource_size");
1257  }
1258  }
1259  else
1260  {
1261  $w = (int) $a_user_width;
1262  $h = (int) $a_user_height;
1263  $width = $w;
1264  $height = $h;
1265 //echo "<br>C-$width-$height-";
1266  if (ilUtil::deducibleSize($a_format) && $a_constrain_proportions)
1267  {
1268  if ($size[0] > 0 && $size[1] > 0)
1269  {
1270  if ($w > 0)
1271  {
1272  $wr = $size[0] / $w;
1273  }
1274  if ($h > 0)
1275  {
1276  $hr = $size[1] / $h;
1277  }
1278 //echo "<br>+".$wr."+".$size[0]."+".$w."+";
1279 //echo "<br>+".$hr."+".$size[1]."+".$h."+";
1280  $r = max($wr, $hr);
1281  if ($r > 0)
1282  {
1283  $width = (int) ($size[0]/$r);
1284  $height = (int) ($size[1]/$r);
1285  }
1286  }
1287  }
1288 //echo "<br>D-$width-$height-";
1289  }
1290 //echo "<br>E-$width-$height-";
1291  return array("width" => $width, "height" => $height, "info" => $info);
1292  }
1293 
1297  function getExt2MimeMap()
1298  {
1299  $types_map = array (
1300  '.a' => 'application/octet-stream',
1301  '.ai' => 'application/postscript',
1302  '.aif' => 'audio/x-aiff',
1303  '.aifc' => 'audio/x-aiff',
1304  '.aiff' => 'audio/x-aiff',
1305  '.asd' => 'application/astound',
1306  '.asf' => 'video/x-ms-asf',
1307  '.asn' => 'application/astound',
1308  '.asx' => 'video/x-ms-asf',
1309  '.au' => 'audio/basic',
1310  '.avi' => 'video/x-msvideo',
1311  '.bat' => 'text/plain',
1312  '.bcpio' => 'application/x-bcpio',
1313  '.bin' => 'application/octet-stream',
1314  '.bmp' => 'image/x-ms-bmp',
1315  '.c' => 'text/plain',
1316  '.cdf' => 'application/x-cdf',
1317  '.class' => 'application/x-java-applet',
1318  '.com' => 'application/octet-stream',
1319  '.cpio' => 'application/x-cpio',
1320  '.csh' => 'application/x-csh',
1321  '.css' => 'text/css',
1322  '.csv' => 'text/comma-separated-values',
1323  '.dcr' => 'application/x-director',
1324  '.dir' => 'application/x-director',
1325  '.dll' => 'application/octet-stream',
1326  '.doc' => 'application/msword',
1327  '.dot' => 'application/msword',
1328  '.dvi' => 'application/x-dvi',
1329  '.dwg' => 'application/acad',
1330  '.dxf' => 'application/dxf',
1331  '.dxr' => 'application/x-director',
1332  '.eml' => 'message/rfc822',
1333  '.eps' => 'application/postscript',
1334  '.etx' => 'text/x-setext',
1335  '.exe' => 'application/octet-stream',
1336  '.flv' => 'video/x-flv',
1337  '.gif' => 'image/gif',
1338  '.gtar' => 'application/x-gtar',
1339  '.gz' => 'application/gzip',
1340  '.h' => 'text/plain',
1341  '.hdf' => 'application/x-hdf',
1342  '.htm' => 'text/html',
1343  '.html' => 'text/html',
1344  '.ief' => 'image/ief',
1345  '.iff' => 'image/iff',
1346  '.jar' => 'application/x-java-applet',
1347  '.jpe' => 'image/jpeg',
1348  '.jpeg' => 'image/jpeg',
1349  '.jpg' => 'image/jpeg',
1350  '.js' => 'application/x-javascript',
1351  '.ksh' => 'text/plain',
1352  '.latex' => 'application/x-latex',
1353  '.m1v' => 'video/mpeg',
1354  '.man' => 'application/x-troff-man',
1355  '.me' => 'application/x-troff-me',
1356  '.mht' => 'message/rfc822',
1357  '.mhtml' => 'message/rfc822',
1358  '.mid' => 'audio/x-midi',
1359  '.midi' => 'audio/x-midi',
1360  '.mif' => 'application/x-mif',
1361  '.mov' => 'video/quicktime',
1362  '.movie' => 'video/x-sgi-movie',
1363  '.mp2' => 'audio/mpeg',
1364  '.mp3' => 'audio/mpeg',
1365  '.mpa' => 'video/mpeg',
1366  '.mpe' => 'video/mpeg',
1367  '.mpeg' => 'video/mpeg',
1368  '.mpg' => 'video/mpeg',
1369  '.mp4' => 'video/mp4',
1370  '.mv4' => 'video/mp4',
1371  '.ms' => 'application/x-troff-ms',
1372  '.nc' => 'application/x-netcdf',
1373  '.nws' => 'message/rfc822',
1374  '.o' => 'application/octet-stream',
1375  '.ogg' => 'application/ogg',
1376  '.obj' => 'application/octet-stream',
1377  '.oda' => 'application/oda',
1378  '.p12' => 'application/x-pkcs12',
1379  '.p7c' => 'application/pkcs7-mime',
1380  '.pbm' => 'image/x-portable-bitmap',
1381  '.pdf' => 'application/pdf',
1382  '.pfx' => 'application/x-pkcs12',
1383  '.pgm' => 'image/x-portable-graymap',
1384  '.php' => 'application/x-httpd-php',
1385  '.phtml' => 'application/x-httpd-php',
1386  '.pl' => 'text/plain',
1387  '.png' => 'image/png',
1388  '.pnm' => 'image/x-portable-anymap',
1389  '.pot' => 'application/vnd.ms-powerpoint',
1390  '.ppa' => 'application/vnd.ms-powerpoint',
1391  '.ppm' => 'image/x-portable-pixmap',
1392  '.pps' => 'application/vnd.ms-powerpoint',
1393  '.ppt' => 'application/vnd.ms-powerpoint',
1394  '.ps' => 'application/postscript',
1395  '.psd' => 'image/psd',
1396  '.pwz' => 'application/vnd.ms-powerpoint',
1397  '.py' => 'text/x-python',
1398  '.pyc' => 'application/x-python-code',
1399  '.pyo' => 'application/x-python-code',
1400  '.qt' => 'video/quicktime',
1401  '.ra' => 'audio/x-pn-realaudio',
1402  '.ram' => 'application/x-pn-realaudio',
1403  '.ras' => 'image/x-cmu-raster',
1404  '.rdf' => 'application/xml',
1405  '.rgb' => 'image/x-rgb',
1406  '.roff' => 'application/x-troff',
1407  '.rpm' => 'audio/x-pn-realaudio-plugin',
1408  '.rtf' => 'application/rtf',
1409  '.rtx' => 'text/richtext',
1410  '.sgm' => 'text/x-sgml',
1411  '.sgml' => 'text/x-sgml',
1412  '.sh' => 'application/x-sh',
1413  '.shar' => 'application/x-shar',
1414  '.sit' => 'application/x-stuffit',
1415  '.snd' => 'audio/basic',
1416  '.so' => 'application/octet-stream',
1417  '.spc' => 'text/x-speech',
1418  '.src' => 'application/x-wais-source',
1419  '.sv4cpio'=> 'application/x-sv4cpio',
1420  '.sv4crc' => 'application/x-sv4crc',
1421  '.svg' => 'image/svg+xml',
1422  '.swf' => 'application/x-shockwave-flash',
1423  '.t' => 'application/x-troff',
1424  '.tar' => 'application/x-tar',
1425  '.talk' => 'text/x-speech',
1426  '.tbk' => 'application/toolbook',
1427  '.tcl' => 'application/x-tcl',
1428  '.tex' => 'application/x-tex',
1429  '.texi' => 'application/x-texinfo',
1430  '.texinfo'=> 'application/x-texinfo',
1431  '.tif' => 'image/tiff',
1432  '.tiff' => 'image/tiff',
1433  '.tr' => 'application/x-troff',
1434  '.tsv' => 'text/tab-separated-values',
1435  '.tsp' => 'application/dsptype',
1436  '.txt' => 'text/plain',
1437  '.ustar' => 'application',
1438  '.vcf' => 'text/x-vcard',
1439  '.vox' => 'audio/voxware',
1440  '.wav' => 'audio/x-wav',
1441  '.wax' => 'audio/x-ms-wax',
1442  '.wiz' => 'application/msword',
1443  '.wm' => 'video/x-ms-wm',
1444  '.wma' => 'audio/x-ms-wma',
1445  '.wmd' => 'video/x-ms-wmd',
1446  '.wml' => 'text/vnd.wap.wml',
1447  '.wmlc' => 'application/vnd.wap.wmlc',
1448  '.wmls' => 'text/vnd.wap.wmlscript',
1449  '.wmlsc' => 'application/vnd.wap.wmlscriptc',
1450  '.wmv' => 'video/x-ms-wmv',
1451  '.wmx' => 'video/x-ms-wmx',
1452  '.wmz' => 'video/x-ms-wmz',
1453  '.wvx' => 'video/x-ms-wvx',
1454  '.wrl' => 'x-world/x-vrml',
1455  '.xbm' => 'image/x-xbitmap',
1456  '.xla' => 'application/msexcel',
1457  '.xlb' => 'application/vnd.ms-excel',
1458  '.xls' => 'application/msexcel',
1459  '.xml' => 'text/xml',
1460  '.xpm' => 'image/x-xpixmap',
1461  '.xsl' => 'application/xml',
1462  '.xwd' => 'image/x-xwindowdump',
1463  '.zip' => 'application/zip');
1464 
1465  return $types_map;
1466  }
1467 
1472  static function _getSimpleMimeTypes()
1473  {
1474  return array("image/x-ms-bmp", "image/gif", "image/jpeg", "image/x-portable-bitmap",
1475  "image/png", "image/psd", "image/tiff", "application/pdf");
1476  }
1477 
1478  function getDataDirectory()
1479  {
1480  return ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1481  }
1482 
1489  static function _useAutoStartParameterOnly($a_loc, $a_format)
1490  {
1491  $lpath = pathinfo($a_loc);
1492  if ($lpath["extension"] == "mp3" && $a_format == "audio/mpeg")
1493  {
1494  return true;
1495  }
1496  if ($lpath["extension"] == "flv")
1497  {
1498  return true;
1499  }
1500  return false;
1501  }
1502 
1506  function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
1507  {
1508  // create dummy object in db (we need an id)
1509  $media_object = new ilObjMediaObject();
1510  $media_object->setTitle($name);
1511  $media_object->setDescription("");
1512  $media_object->create();
1513 
1514  // determine and create mob directory, move uploaded file to directory
1515  $media_object->createDirectory();
1516  $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1517 
1518  $media_item =& new ilMediaItem();
1519  $media_object->addMediaItem($media_item);
1520  $media_item->setPurpose("Standard");
1521 
1522  $file = $mob_dir."/".$name;
1523  if ($upload)
1524  {
1525  ilUtil::moveUploadedFile($tmp_name,$name, $file);
1526  }
1527  else
1528  {
1529  copy($tmp_name, $file);
1530  }
1531  // get mime type
1533  $location = $name;
1534  // set real meta and object data
1535  $media_item->setFormat($format);
1536  $media_item->setLocation($location);
1537  $media_item->setLocationType("LocalFile");
1538  $media_object->setTitle($name);
1539  $media_object->setDescription($format);
1540 
1541  if (ilUtil::deducibleSize($format))
1542  {
1543  $size = getimagesize($file);
1544  $media_item->setWidth($size[0]);
1545  $media_item->setHeight($size[1]);
1546  }
1547  $media_item->setHAlign("Left");
1548 
1549  ilUtil::renameExecutables($mob_dir);
1550  $media_object->update();
1551 
1552  return $media_object;
1553  }
1554 
1558  function getLinkedMediaObjects($a_ignore = "")
1559  {
1560  $linked = array();
1561 
1562  if (!is_array($a_ignore))
1563  {
1564  $a_ignore = array();
1565  }
1566 
1567  // get linked media objects (map areas)
1568  $med_items = $this->getMediaItems();
1569 
1570  foreach($med_items as $med_item)
1571  {
1572  $int_links = ilMapArea::_getIntLinks($med_item->getId());
1573  foreach ($int_links as $k => $int_link)
1574  {
1575  if ($int_link["Type"] == "MediaObject")
1576  {
1577  include_once("./Services/COPage/classes/class.ilInternalLink.php");
1578  $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1579  if (ilObject::_exists($l_id))
1580  {
1581  if (!in_array($l_id, $linked) &&
1582  !in_array($l_id, $a_ignore))
1583  {
1584  $linked[] = $l_id;
1585  }
1586  }
1587  }
1588  }
1589  }
1590 //var_dump($linked);
1591  return $linked;
1592  }
1593 }
1594 ?>