ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMediaObject.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 define ("IL_MODE_ALIAS", 1);
25 define ("IL_MODE_OUTPUT", 2);
26 define ("IL_MODE_FULL", 3);
27 
28 require_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
29 include_once "classes/class.ilObject.php";
30 
47 {
48  var $is_alias;
50  var $id;
53 
58  function ilObjMediaObject($a_id = 0)
59  {
60  $this->is_alias = false;
61  $this->media_items = array();
62  $this->contains_int_link = false;
63  $this->type = "mob";
64  parent::ilObject($a_id, false);
65  }
66 
67  function setRefId()
68  {
69  $this->ilias->raiseError("Operation ilObjMedia::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
70  }
71 
72  function getRefId()
73  {
74  $this->ilias->raiseError("Operation ilObjMedia::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
75  }
76 
77  function putInTree()
78  {
79  $this->ilias->raiseError("Operation ilObjMedia::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
80  }
81 
82  function createReference()
83  {
84  $this->ilias->raiseError("Operation ilObjMedia::createReference() not allowed.",$this->ilias->error_obj->FATAL);
85  }
86 
87  function setTitle($a_title)
88  {
89  parent::setTitle($a_title);
90  }
91 
92  function getTitle()
93  {
94  return parent::getTitle();
95  }
96 
104  function _exists($a_id)
105  {
106  global $ilDB;
107 
108  include_once("./Services/COPage/classes/class.ilInternalLink.php");
109  if (is_int(strpos($a_id, "_")))
110  {
112  }
113 
114  return parent::_exists($a_id, false);
115  }
116 
120  function delete()
121  {
122  if (!($this->getId() > 0))
123  {
124  return;
125  }
126 
127  $usages = $this->getUsages();
128 
129  if (count($usages) == 0)
130  {
131  // remove directory
133 
134  // remove thumbnail directory
136 
137  // delete meta data of mob
138  $this->deleteMetaData();
139 
140  // delete media items
142 
143  // delete object
144  parent::delete();
145  }
146  }
147 
153  function getDescription()
154  {
155  return parent::getDescription();
156  }
157 
161  function setDescription($a_description)
162  {
163  parent::setDescription($a_description);
164  }
165 
177  function MDUpdateListener($a_element)
178  {
179  include_once 'Services/MetaData/classes/class.ilMD.php';
180 
181  switch($a_element)
182  {
183  case 'General':
184 
185  // Update Title and description
186  $md = new ilMD(0, $this->getId(), $this->getType());
187  $md_gen = $md->getGeneral();
188 
189  if (is_object($md_gen))
190  {
191  ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
192  $this->setTitle($md_gen->getTitle());
193 
194  foreach($md_gen->getDescriptionIds() as $id)
195  {
196  $md_des = $md_gen->getDescription($id);
197  ilObject::_writeDescription($this->getId(),$md_des->getDescription());
198  $this->setDescription($md_des->getDescription());
199  break;
200  }
201  }
202 
203  break;
204 
205  default:
206  }
207  return true;
208  }
209 
213  function createMetaData()
214  {
215  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
216 
217  global $ilUser;
218 
219  $md_creator = new ilMDCreator(0, $this->getId(), $this->getType());
220  $md_creator->setTitle($this->getTitle());
221  $md_creator->setTitleLanguage($ilUser->getPref('language'));
222  $md_creator->setDescription($this->getDescription());
223  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
224  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
225  $md_creator->setLanguage($ilUser->getPref('language'));
226  $md_creator->create();
227 
228  return true;
229  }
230 
234  function updateMetaData()
235  {
236  include_once("Services/MetaData/classes/class.ilMD.php");
237  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
238  include_once("Services/MetaData/classes/class.ilMDDescription.php");
239 
240  $md =& new ilMD(0, $this->getId(), $this->getType());
241  $md_gen =& $md->getGeneral();
242  $md_gen->setTitle($this->getTitle());
243 
244  // sets first description (maybe not appropriate)
245  $md_des_ids =& $md_gen->getDescriptionIds();
246  if (count($md_des_ids) > 0)
247  {
248  $md_des =& $md_gen->getDescription($md_des_ids[0]);
249  $md_des->setDescription($this->getDescription());
250  $md_des->update();
251  }
252  $md_gen->update();
253 
254  }
255 
259  function deleteMetaData()
260  {
261  // Delete meta data
262  include_once('Services/MetaData/classes/class.ilMD.php');
263  $md = new ilMD(0, $this->getId(), $this->getType());
264  $md->deleteAll();
265  }
266 
267 
273  function addMediaItem(&$a_item)
274  {
275  $this->media_items[] =& $a_item;
276  }
277 
278 
284  function &getMediaItems()
285  {
286  return $this->media_items;
287  }
288 
295  function &getMediaItem($a_purpose)
296  {
297  foreach ($this->media_items as $media_item)
298  {
299  if($media_item->getPurpose() == $a_purpose)
300  {
301  return $media_item;
302  }
303  }
304  return false;
305  }
306 
307 
311  function removeMediaItem($a_purpose)
312  {
313  foreach ($this->media_items as $key => $media_item)
314  {
315  if($media_item->getPurpose() == $a_purpose)
316  {
317  unset($this->media_items[$key]);
318  }
319  }
320  // update numbers and keys
321  $i = 1;
322  $media_items = array();
323  foreach ($this->media_items as $media_item)
324  {
325  $media_items [$i] = $media_item;
326  $media_item->setMobId($this->getId());
327  $media_item->setNr($i);
328  $i++;
329  }
330  $this->media_items = $media_items;
331  }
332 
337  {
338  $this->media_items = array();
339  }
340 
341 
342  function getMediaItemNr($a_purpose)
343  {
344  for($i=0; $i<count($this->media_items); $i++)
345  {
346  if($this->media_items[$i]->getPurpose() == $a_purpose)
347  {
348  return $i + 1;
349  }
350  }
351  return false;
352  }
353 
354 
355  function hasFullscreenItem()
356  {
357  return $this->hasPurposeItem("Fullscreen");
358  }
359 
366  function hasPurposeItem($purpose)
367  {
368  if(is_object($this->getMediaItem($purpose)))
369  {
370  return true;
371  }
372  else
373  {
374  return false;
375  }
376  }
377 
378 
379 
383  function read()
384  {
385 //echo "<br>ilObjMediaObject:read";
386  parent::read();
387 
388  // get media items
390  }
391 
395  function setId($a_id)
396  {
397  $this->id = $a_id;
398  }
399 
400  function getId()
401  {
402  return $this->id;
403  }
404 
408  function setAlias($a_is_alias)
409  {
410  $this->is_alias = $a_is_alias;
411  }
412 
413  function isAlias()
414  {
415  return $this->is_alias;
416  }
417 
418  function setOriginID($a_id)
419  {
420  return $this->origin_id = $a_id;
421  }
422 
423  function getOriginID()
424  {
425  return $this->origin_id;
426  }
427 
428  /*
429  function getimportId()
430  {
431  return $this->meta_data->getImportIdentifierEntryID();
432  }*/
433 
434 
438  function getImportId()
439  {
440  return $this->import_id;
441  }
442 
443  function setImportId($a_id)
444  {
445  $this->import_id = $a_id;
446  }
447 
451  function create($a_upload = false, $a_save_media_items = true)
452  {
453  parent::create();
454 
455  if (!$a_upload)
456  {
457  $this->createMetaData();
458  }
459 
460  if ($a_save_media_items)
461  {
462  $media_items =& $this->getMediaItems();
463  for($i=0; $i<count($media_items); $i++)
464  {
465  $item =& $media_items[$i];
466  $item->setMobId($this->getId());
467  $item->setNr($i+1);
468  $item->create();
469  }
470  }
471 
472  }
473 
474 
478  function update()
479  {
480  $this->updateMetaData();
481  parent::update();
482 
484 
485  // iterate all items
486  $media_items =& $this->getMediaItems();
487  $j = 1;
488  foreach($media_items as $key => $val)
489  {
490  $item =& $media_items[$key];
491  if (is_object($item))
492  {
493  $item->setMobId($this->getId());
494  $item->setNr($j);
495  if ($item->getLocationType() == "Reference")
496  {
497  $item->extractUrlParameters();
498  }
499  $item->create();
500  $j++;
501  }
502  }
503  }
504 
510  function _getDirectory($a_mob_id)
511  {
512  return ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
513  }
514 
520  function _getURL($a_mob_id)
521  {
522  return ilUtil::getHtmlPath(ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id);
523  }
524 
530  function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
531  {
532  return ilUtil::getWebspaceDir($a_mode)."/thumbs/mm_".$a_mob_id;
533  }
534 
540  static function _lookupStandardItemPath($a_mob_id, $a_url_encode = false,
541  $a_web = true)
542  {
543  return ilObjMediaObject::_lookupItemPath($a_mob_id, $a_url_encode, $a_web, "Standard");
544  }
545 
551  static function _lookupItemPath($a_mob_id, $a_url_encode = false,
552  $a_web = true, $a_purpose = "")
553  {
554  if ($a_purpose == "")
555  {
556  $a_purpose = "Standard";
557  }
558  $location = ilMediaItem::_lookupLocationForMobId($a_mob_id, $a_purpose);
559  if (preg_match("/https?\:/i",$location))
560  return $location;
561 
562  if ($a_url_encode)
563  $location = rawurlencode($location);
564 
565  $path = ($a_web)
566  ? ILIAS_HTTP_PATH
567  : ".";
568 
569  return $path."/data/".CLIENT_ID."/mobs/mm_".$a_mob_id."/".$location;
570  }
571 
575  function createDirectory()
576  {
578  }
579 
583  function _createThumbnailDirectory($a_obj_id)
584  {
586  ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs/mm_".$a_obj_id);
587  }
588 
593  function getXML($a_mode = IL_MODE_FULL, $a_inst = 0)
594  {
595  // TODO: full implementation of all parameters
596 //echo "-".$a_mode."-";
597  switch ($a_mode)
598  {
599  case IL_MODE_ALIAS:
600  $xml = "<MediaObject>";
601  $xml .= "<MediaAlias OriginId=\"il__mob_".$this->getId()."\"/>";
602  $media_items =& $this->getMediaItems();
603  for($i=0; $i<count($media_items); $i++)
604  {
605  $item =& $media_items[$i];
606  $xml .= "<MediaAliasItem Purpose=\"".$item->getPurpose()."\">";
607 
608  // Layout
609  $width = ($item->getWidth() != "")
610  ? "Width=\"".$item->getWidth()."\""
611  : "";
612  $height = ($item->getHeight() != "")
613  ? "Height=\"".$item->getHeight()."\""
614  : "";
615  $halign = ($item->getHAlign() != "")
616  ? "HorizontalAlign=\"".$item->getHAlign()."\""
617  : "";
618  $xml .= "<Layout $width $height $halign />";
619 
620  // Caption
621  if ($item->getCaption() != "")
622  {
623  $xml .= "<Caption Align=\"bottom\">".
624  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
625  }
626 
627  // Parameter
628  $parameters = $item->getParameters();
629  foreach ($parameters as $name => $value)
630  {
631  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
632  }
633  $xml .= "</MediaAliasItem>";
634  }
635  break;
636 
637  // for output we need technical sections of meta data
638  case IL_MODE_OUTPUT:
639 
640  // get first technical section
641 // $meta =& $this->getMetaData();
642  $xml = "<MediaObject Id=\"il__mob_".$this->getId()."\">";
643 
644  $media_items =& $this->getMediaItems();
645  for($i=0; $i<count($media_items); $i++)
646  {
647  $item =& $media_items[$i];
648  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
649 
650  // Location
651  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
652  $this->handleAmps($item->getLocation())."</Location>";
653 
654  // Format
655  $xml.= "<Format>".$item->getFormat()."</Format>";
656 
657  // Layout
658  $width = ($item->getWidth() != "")
659  ? "Width=\"".$item->getWidth()."\""
660  : "";
661  $height = ($item->getHeight() != "")
662  ? "Height=\"".$item->getHeight()."\""
663  : "";
664  $halign = ($item->getHAlign() != "")
665  ? "HorizontalAlign=\"".$item->getHAlign()."\""
666  : "";
667  $xml .= "<Layout $width $height $halign />";
668 
669  // Caption
670  if ($item->getCaption() != "")
671  {
672  $xml .= "<Caption Align=\"bottom\">".
673  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
674  }
675 
676  // Parameter
677  $parameters = $item->getParameters();
678  foreach ($parameters as $name => $value)
679  {
680  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
681  }
682  $xml .= $item->getMapAreasXML();
683  $xml .= "</MediaItem>";
684  }
685  break;
686 
687  // full xml for export
688  case IL_MODE_FULL:
689 
690 // $meta =& $this->getMetaData();
691  $xml = "<MediaObject>";
692 
693  // meta data
694  include_once("Services/MetaData/classes/class.ilMD2XML.php");
695  $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
696  $md2xml->setExportMode(true);
697  $md2xml->startExport();
698  $xml.= $md2xml->getXML();
699 
700  $media_items =& $this->getMediaItems();
701  for($i=0; $i<count($media_items); $i++)
702  {
703  $item =& $media_items[$i];
704  $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
705 
706  // Location
707  $xml.= "<Location Type=\"".$item->getLocationType()."\">".
708  $this->handleAmps($item->getLocation())."</Location>";
709 
710  // Format
711  $xml.= "<Format>".$item->getFormat()."</Format>";
712 
713  // Layout
714  $width = ($item->getWidth() != "")
715  ? "Width=\"".$item->getWidth()."\""
716  : "";
717  $height = ($item->getHeight() != "")
718  ? "Height=\"".$item->getHeight()."\""
719  : "";
720  $halign = ($item->getHAlign() != "")
721  ? "HorizontalAlign=\"".$item->getHAlign()."\""
722  : "";
723  $xml .= "<Layout $width $height $halign />";
724 
725  // Caption
726  if ($item->getCaption() != "")
727  {
728  $xml .= "<Caption Align=\"bottom\">".
729  str_replace("&", "&amp;", $item->getCaption())."</Caption>";
730  }
731 
732  // Parameter
733  $parameters = $item->getParameters();
734  foreach ($parameters as $name => $value)
735  {
736  $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
737  }
738  $xml .= $item->getMapAreasXML(true, $a_inst);
739  $xml .= "</MediaItem>";
740  }
741  break;
742  }
743  $xml .= "</MediaObject>";
744  return $xml;
745  }
746 
750  function handleAmps($a_str)
751  {
752  $a_str = str_replace("&amp;", "&", $a_str);
753  $a_str = str_replace("&", "&amp;", $a_str);
754  return $a_str;
755  }
756 
760  function exportXML(&$a_xml_writer, $a_inst = 0)
761  {
762  $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
763  }
764 
765 
773  function exportFiles($a_target_dir)
774  {
775  $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
776  ilUtil::makeDir($a_target_dir."/objects/".$subdir);
777 
778  $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
779  ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
780 //echo "from:$mobdir:to:".$a_target_dir."/objects/".$subdir.":<br>";
781  }
782 
783 
784  function modifyExportIdentifier($a_tag, $a_param, $a_value)
785  {
786  if ($a_tag == "Identifier" && $a_param == "Entry")
787  {
788  $a_value = ilUtil::insertInstIntoID($a_value);
789  }
790 
791  return $a_value;
792  }
793 
794 
796  // EDIT METHODS: these methods act on the media alias in the dom
798 
805  function setContainsIntLink($a_contains_link)
806  {
807  $this->contains_int_link = $a_contains_link;
808  }
809 
814  function containsIntLink()
815  {
817  }
818 
822  function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0)
823  {
824  global $ilDB;
825 
826  $q = "DELETE FROM mob_usage WHERE usage_type = ".
827  $ilDB->quote($a_type)." AND usage_id= ".$ilDB->quote($a_id).
828  " AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr);
829  $ilDB->query($q);
830  }
831 
835  function _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr = 0)
836  {
837  global $ilDB;
838 
839  $q = "SELECT * FROM mob_usage WHERE ".
840  "usage_type = ".$ilDB->quote($a_type)." AND ".
841  "usage_id = ".$ilDB->quote($a_id)." AND ".
842  "usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr);
843  $mobs = array();
844  $mob_set = $ilDB->query($q);
845  while($mob_rec = $mob_set->fetchRow(DB_FETCHMODE_ASSOC))
846  {
847  if (ilObject::_lookupType($mob_rec["id"]) == "mob")
848  {
849  $mobs[$mob_rec["id"]] = $mob_rec["id"];
850  }
851  }
852 
853  return $mobs;
854  }
855 
859  function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
860  {
861  global $ilDB;
862 
863  $q = "REPLACE INTO mob_usage (id, usage_type, usage_id, usage_hist_nr) VALUES".
864  " (".$ilDB->quote($a_mob_id).",".
865  $ilDB->quote($a_type).",".$ilDB->quote($a_id).",".
866  $ilDB->quote($a_usage_hist_nr).")";
867  $ilDB->query($q);
868  }
869 
873  function _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
874  {
875  global $ilDB;
876 
877  $q = "DELETE FROM mob_usage WHERE ".
878  " id = ".$ilDB->quote($a_mob_id)." AND ".
879  " usage_type = ".$ilDB->quote($a_type)." AND ".
880  " usage_id = ".$ilDB->quote($a_id)." AND ".
881  " usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr);
882  $ilDB->query($q);
883  }
884 
888  function getUsages()
889  {
890  return $this->lookupUsages($this->getId());
891  }
892 
898  function lookupUsages($a_id)
899  {
900  global $ilDB;
901 
902  // get usages in learning modules
903  $q = "SELECT * FROM mob_usage WHERE id = ".
904  $ilDB->quote($a_id);
905  $us_set = $ilDB->query($q);
906  $ret = array();
907  while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
908  {
909  $ret[] = array("type" => $us_rec["usage_type"],
910  "id" => $us_rec["usage_id"],
911  "hist_nr" => $us_rec["usage_hist_nr"]);
912  }
913 
914  // get usages in media pools
915  $q = "SELECT DISTINCT mep_id FROM mep_tree WHERE child = ".
916  $ilDB->quote($a_id);
917  $us_set = $ilDB->query($q);
918  while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
919  {
920  $ret[] = array("type" => "mep",
921  "id" => $us_rec["mep_id"]);
922  }
923 
924  // get usages in news items (media casts)
925  include_once("./Services/News/classes/class.ilNewsItem.php");
926  $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
927  foreach($news_usages as $nu)
928  {
929  $ret[] = $nu;
930  }
931 
932 
933  // get usages in map areas
934  $q = "SELECT DISTINCT mob_id FROM media_item as it, map_area as area ".
935  " WHERE area.item_id = it.id ".
936  " AND area.link_type='int' ".
937  " AND area.target = ".$ilDB->quote("il__mob_".$a_id);
938  $us_set = $ilDB->query($q);
939  while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
940  {
941  $ret[] = array("type" => "map",
942  "id" => $us_rec["mob_id"]);
943  }
944 
945  // get usages in personal clipboards
946  $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
947  foreach ($users as $user)
948  {
949  $ret[] = array("type" => "clip",
950  "id" => $user);
951  }
952 
953  return $ret;
954  }
955 
959  function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
960  {
961  if(is_int(strpos($a_usage["type"], ":")))
962  {
963  $us_arr = explode(":", $a_usage["type"]);
964  $type = $us_arr[1];
965  $cont_type = $us_arr[0];
966  }
967  else
968  {
969  $type = $a_usage["type"];
970  }
971 
972  $id = $a_usage["id"];
973  $obj_id = false;
974 
975  switch($type)
976  {
977  case "html": // "old" category pages
978  if ($cont_type == "cat")
979  {
980  $obj_id = $id;
981  }
982  // Test InfoScreen Text
983  if ($cont_type == "tst")
984  {
985  $obj_id = $id;
986  //var_dump($qinfo);
987  }
988  // Question Pool *Question* Text
989  if ($cont_type == "qpl")
990  {
991  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
993  if ($qinfo["original_id"] > 0)
994  {
995  include_once("./Modules/Test/classes/class.ilObjTest.php");
996  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
997  }
998  else
999  {
1000  $obj_id = $qinfo["obj_fi"]; // usage in pool
1001  }
1002  }
1003  break;
1004 
1005  case "pg":
1006 
1007  // Question Pool Question Pages
1008  if ($cont_type == "qpl")
1009  {
1010  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
1012  if ($qinfo["original_id"] > 0)
1013  {
1014  include_once("./Modules/Test/classes/class.ilObjTest.php");
1015  $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id); // usage in test
1016  }
1017  else
1018  {
1019  $obj_id = $qinfo["obj_fi"]; // usage in pool
1020  }
1021  }
1022 
1023  // learning modules
1024  if ($cont_type == "lm" || $cont_type == "dbk")
1025  {
1026  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
1027  $obj_id = ilLMObject::_lookupContObjID($id);
1028  }
1029 
1030  // glossary definition
1031  if ($cont_type == "gdf")
1032  {
1033  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1034  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1036  $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
1037  }
1038 
1039  break;
1040 
1041  // Media Pool
1042  case "mep":
1043  $obj_id = $id;
1044  break;
1045 
1046  // News Context Object (e.g. MediaCast)
1047  case "news":
1048  include_once("./Services/News/classes/class.ilNewsItem.php");
1050  break;
1051  }
1052 
1053  return $obj_id;
1054  }
1055 
1063  function _resizeImage($a_file, $a_width, $a_height)
1064  {
1065  $file_path = pathinfo($a_file);
1066  $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
1067  strlen($file_path["extension"]) - 1)."_".
1068  $a_width."_".
1069  $a_height.".".$file_path["extension"];
1070  $target_file = $file_path["dirname"]."/".
1071  $location;
1072  ilUtil::resizeImage($a_file, $target_file,
1073  (int) $a_width, (int) $a_height);
1074 
1075  return $location;
1076  }
1077 
1085  static function getMimeType ($a_file)
1086  {
1087  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1088  $mime = ilMimeTypeUtil::getMimeType($a_file);
1089  return $mime;
1090 /*
1091  // check if mimetype detection enabled in php.ini
1092  $set = ini_get("mime_magic.magicfile");
1093  // get mimetype
1094  if ($set <> "")
1095  {
1096  $mime = @mime_content_type($a_file);
1097  }
1098 
1099  // some php installations return always
1100  // text/plain, so we make our own detection in this case, too
1101  if (empty($mime) || $mime == "text/plain")
1102  {
1103  $path = pathinfo($a_file);
1104  $ext = ".".strtolower($path["extension"]);
1105 
1106  $types_map = ilObjMediaObject::getExt2MimeMap();
1107  $mime = $types_map[$ext];
1108  }
1109 
1110  // set default if mimetype detection failed or not possible (e.g. remote file)
1111  if (empty($mime))
1112  {
1113  $mime = "application/octet-stream";
1114  }
1115 
1116  return $mime;
1117 */
1118  }
1119 
1120 
1124  function getExt2MimeMap()
1125  {
1126  $types_map = array (
1127  '.a' => 'application/octet-stream',
1128  '.ai' => 'application/postscript',
1129  '.aif' => 'audio/x-aiff',
1130  '.aifc' => 'audio/x-aiff',
1131  '.aiff' => 'audio/x-aiff',
1132  '.asd' => 'application/astound',
1133  '.asf' => 'video/x-ms-asf',
1134  '.asn' => 'application/astound',
1135  '.asx' => 'video/x-ms-asf',
1136  '.au' => 'audio/basic',
1137  '.avi' => 'video/x-msvideo',
1138  '.bat' => 'text/plain',
1139  '.bcpio' => 'application/x-bcpio',
1140  '.bin' => 'application/octet-stream',
1141  '.bmp' => 'image/x-ms-bmp',
1142  '.c' => 'text/plain',
1143  '.cdf' => 'application/x-cdf',
1144  '.class' => 'application/x-java-applet',
1145  '.com' => 'application/octet-stream',
1146  '.cpio' => 'application/x-cpio',
1147  '.csh' => 'application/x-csh',
1148  '.css' => 'text/css',
1149  '.csv' => 'text/comma-separated-values',
1150  '.dcr' => 'application/x-director',
1151  '.dir' => 'application/x-director',
1152  '.dll' => 'application/octet-stream',
1153  '.doc' => 'application/msword',
1154  '.dot' => 'application/msword',
1155  '.dvi' => 'application/x-dvi',
1156  '.dwg' => 'application/acad',
1157  '.dxf' => 'application/dxf',
1158  '.dxr' => 'application/x-director',
1159  '.eml' => 'message/rfc822',
1160  '.eps' => 'application/postscript',
1161  '.etx' => 'text/x-setext',
1162  '.exe' => 'application/octet-stream',
1163  '.flv' => 'video/x-flv',
1164  '.gif' => 'image/gif',
1165  '.gtar' => 'application/x-gtar',
1166  '.gz' => 'application/gzip',
1167  '.h' => 'text/plain',
1168  '.hdf' => 'application/x-hdf',
1169  '.htm' => 'text/html',
1170  '.html' => 'text/html',
1171  '.ief' => 'image/ief',
1172  '.iff' => 'image/iff',
1173  '.jar' => 'application/x-java-applet',
1174  '.jpe' => 'image/jpeg',
1175  '.jpeg' => 'image/jpeg',
1176  '.jpg' => 'image/jpeg',
1177  '.js' => 'application/x-javascript',
1178  '.ksh' => 'text/plain',
1179  '.latex' => 'application/x-latex',
1180  '.m1v' => 'video/mpeg',
1181  '.man' => 'application/x-troff-man',
1182  '.me' => 'application/x-troff-me',
1183  '.mht' => 'message/rfc822',
1184  '.mhtml' => 'message/rfc822',
1185  '.mid' => 'audio/x-midi',
1186  '.midi' => 'audio/x-midi',
1187  '.mif' => 'application/x-mif',
1188  '.mov' => 'video/quicktime',
1189  '.movie' => 'video/x-sgi-movie',
1190  '.mp2' => 'audio/mpeg',
1191  '.mp3' => 'audio/mpeg',
1192  '.mpa' => 'video/mpeg',
1193  '.mpe' => 'video/mpeg',
1194  '.mpeg' => 'video/mpeg',
1195  '.mpg' => 'video/mpeg',
1196  '.mp4' => 'video/mp4',
1197  '.mv4' => 'video/mp4',
1198  '.ms' => 'application/x-troff-ms',
1199  '.nc' => 'application/x-netcdf',
1200  '.nws' => 'message/rfc822',
1201  '.o' => 'application/octet-stream',
1202  '.ogg' => 'application/ogg',
1203  '.obj' => 'application/octet-stream',
1204  '.oda' => 'application/oda',
1205  '.p12' => 'application/x-pkcs12',
1206  '.p7c' => 'application/pkcs7-mime',
1207  '.pbm' => 'image/x-portable-bitmap',
1208  '.pdf' => 'application/pdf',
1209  '.pfx' => 'application/x-pkcs12',
1210  '.pgm' => 'image/x-portable-graymap',
1211  '.php' => 'application/x-httpd-php',
1212  '.phtml' => 'application/x-httpd-php',
1213  '.pl' => 'text/plain',
1214  '.png' => 'image/png',
1215  '.pnm' => 'image/x-portable-anymap',
1216  '.pot' => 'application/vnd.ms-powerpoint',
1217  '.ppa' => 'application/vnd.ms-powerpoint',
1218  '.ppm' => 'image/x-portable-pixmap',
1219  '.pps' => 'application/vnd.ms-powerpoint',
1220  '.ppt' => 'application/vnd.ms-powerpoint',
1221  '.ps' => 'application/postscript',
1222  '.psd' => 'image/psd',
1223  '.pwz' => 'application/vnd.ms-powerpoint',
1224  '.py' => 'text/x-python',
1225  '.pyc' => 'application/x-python-code',
1226  '.pyo' => 'application/x-python-code',
1227  '.qt' => 'video/quicktime',
1228  '.ra' => 'audio/x-pn-realaudio',
1229  '.ram' => 'application/x-pn-realaudio',
1230  '.ras' => 'image/x-cmu-raster',
1231  '.rdf' => 'application/xml',
1232  '.rgb' => 'image/x-rgb',
1233  '.roff' => 'application/x-troff',
1234  '.rpm' => 'audio/x-pn-realaudio-plugin',
1235  '.rtf' => 'application/rtf',
1236  '.rtx' => 'text/richtext',
1237  '.sgm' => 'text/x-sgml',
1238  '.sgml' => 'text/x-sgml',
1239  '.sh' => 'application/x-sh',
1240  '.shar' => 'application/x-shar',
1241  '.sit' => 'application/x-stuffit',
1242  '.snd' => 'audio/basic',
1243  '.so' => 'application/octet-stream',
1244  '.spc' => 'text/x-speech',
1245  '.src' => 'application/x-wais-source',
1246  '.sv4cpio'=> 'application/x-sv4cpio',
1247  '.sv4crc' => 'application/x-sv4crc',
1248  '.svg' => 'image/svg+xml',
1249  '.swf' => 'application/x-shockwave-flash',
1250  '.t' => 'application/x-troff',
1251  '.tar' => 'application/x-tar',
1252  '.talk' => 'text/x-speech',
1253  '.tbk' => 'application/toolbook',
1254  '.tcl' => 'application/x-tcl',
1255  '.tex' => 'application/x-tex',
1256  '.texi' => 'application/x-texinfo',
1257  '.texinfo'=> 'application/x-texinfo',
1258  '.tif' => 'image/tiff',
1259  '.tiff' => 'image/tiff',
1260  '.tr' => 'application/x-troff',
1261  '.tsv' => 'text/tab-separated-values',
1262  '.tsp' => 'application/dsptype',
1263  '.txt' => 'text/plain',
1264  '.ustar' => 'application',
1265  '.vcf' => 'text/x-vcard',
1266  '.vox' => 'audio/voxware',
1267  '.wav' => 'audio/x-wav',
1268  '.wax' => 'audio/x-ms-wax',
1269  '.wiz' => 'application/msword',
1270  '.wm' => 'video/x-ms-wm',
1271  '.wma' => 'audio/x-ms-wma',
1272  '.wmd' => 'video/x-ms-wmd',
1273  '.wml' => 'text/vnd.wap.wml',
1274  '.wmlc' => 'application/vnd.wap.wmlc',
1275  '.wmls' => 'text/vnd.wap.wmlscript',
1276  '.wmlsc' => 'application/vnd.wap.wmlscriptc',
1277  '.wmv' => 'video/x-ms-wmv',
1278  '.wmx' => 'video/x-ms-wmx',
1279  '.wmz' => 'video/x-ms-wmz',
1280  '.wvx' => 'video/x-ms-wvx',
1281  '.wrl' => 'x-world/x-vrml',
1282  '.xbm' => 'image/x-xbitmap',
1283  '.xla' => 'application/msexcel',
1284  '.xlb' => 'application/vnd.ms-excel',
1285  '.xls' => 'application/msexcel',
1286  '.xml' => 'text/xml',
1287  '.xpm' => 'image/x-xpixmap',
1288  '.xsl' => 'application/xml',
1289  '.xwd' => 'image/x-xwindowdump',
1290  '.zip' => 'application/zip');
1291 
1292  return $types_map;
1293  }
1294 
1295  function getDataDirectory()
1296  {
1297  return ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1298  }
1299 
1303  function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
1304  {
1305  // create dummy object in db (we need an id)
1306  $media_object = new ilObjMediaObject();
1307  $media_object->setTitle($name);
1308  $media_object->setDescription("");
1309  $media_object->create();
1310 
1311  // determine and create mob directory, move uploaded file to directory
1312  $media_object->createDirectory();
1313  $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
1314 
1315  $media_item =& new ilMediaItem();
1316  $media_object->addMediaItem($media_item);
1317  $media_item->setPurpose("Standard");
1318 
1319  $file = $mob_dir."/".$name;
1320  if ($upload)
1321  {
1322  ilUtil::moveUploadedFile($tmp_name,$name, $file);
1323  }
1324  else
1325  {
1326  copy($tmp_name, $file);
1327  }
1328  // get mime type
1330  $location = $name;
1331  // set real meta and object data
1332  $media_item->setFormat($format);
1333  $media_item->setLocation($location);
1334  $media_item->setLocationType("LocalFile");
1335  $media_object->setTitle($name);
1336  $media_object->setDescription($format);
1337 
1338  if (ilUtil::deducibleSize($format))
1339  {
1340  $size = getimagesize($file);
1341  $media_item->setWidth($size[0]);
1342  $media_item->setHeight($size[1]);
1343  }
1344  $media_item->setHAlign("Left");
1345 
1346  ilUtil::renameExecutables($mob_dir);
1347  $media_object->update();
1348 
1349  return $media_object;
1350  }
1351 
1355  function getLinkedMediaObjects($a_ignore = "")
1356  {
1357  $linked = array();
1358 
1359  if (!is_array($a_ignore))
1360  {
1361  $a_ignore = array();
1362  }
1363 
1364  // get linked media objects (map areas)
1365  $med_items = $this->getMediaItems();
1366 
1367  foreach($med_items as $med_item)
1368  {
1369  $int_links = ilMapArea::_getIntLinks($med_item->getId());
1370  foreach ($int_links as $k => $int_link)
1371  {
1372  if ($int_link["Type"] == "MediaObject")
1373  {
1374  include_once("./Services/COPage/classes/class.ilInternalLink.php");
1375  $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
1376  if (ilObject::_exists($l_id))
1377  {
1378  if (!in_array($l_id, $linked) &&
1379  !in_array($l_id, $a_ignore))
1380  {
1381  $linked[] = $l_id;
1382  }
1383  }
1384  }
1385  }
1386  }
1387 //var_dump($linked);
1388  return $linked;
1389  }
1390 }
1391 ?>