00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 define ("IL_MODE_ALIAS", 1);
00025 define ("IL_MODE_OUTPUT", 2);
00026 define ("IL_MODE_FULL", 3);
00027
00028 require_once("content/classes/Media/class.ilMediaItem.php");
00029 include_once "classes/class.ilObject.php";
00030
00043 class ilObjMediaObject extends ilObject
00044 {
00045 var $is_alias;
00046 var $origin_id;
00047 var $id;
00048
00049 var $dom;
00050 var $hier_id;
00051 var $node;
00052 var $mob_node;
00053 var $media_items;
00054 var $contains_int_link;
00055
00060 function ilObjMediaObject($a_id = 0)
00061 {
00062 $this->is_alias = false;
00063 $this->media_items = array();
00064 $this->contains_int_link = false;
00065 $this->type = "mob";
00066
00067 parent::ilObject($a_id, false);
00068
00069
00070
00071
00072
00073
00074
00075
00076 }
00077
00078 function setRefId()
00079 {
00080 $this->ilias->raiseError("Operation ilObjMedia::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
00081 }
00082
00083 function getRefId()
00084 {
00085 $this->ilias->raiseError("Operation ilObjMedia::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
00086 }
00087
00088 function putInTree()
00089 {
00090 $this->ilias->raiseError("Operation ilObjMedia::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
00091 }
00092
00093 function createReference()
00094 {
00095 $this->ilias->raiseError("Operation ilObjMedia::createReference() not allowed.",$this->ilias->error_obj->FATAL);
00096 }
00097
00098 function setTitle($a_title)
00099 {
00100 parent::setTitle($a_title);
00101 }
00102
00103 function getTitle()
00104 {
00105 return parent::getTitle();
00106 }
00107
00115 function _exists($a_id)
00116 {
00117 global $ilDB;
00118
00119 include_once("content/classes/Pages/class.ilInternalLink.php");
00120 if (is_int(strpos($a_id, "_")))
00121 {
00122 $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00123 }
00124
00125 return parent::_exists($a_id, false);
00126 }
00127
00131 function delete()
00132 {
00133 if (!($this->getId() > 0))
00134 {
00135 return;
00136 }
00137
00138 $usages = $this->getUsages();
00139
00140 if (count($usages) == 0)
00141 {
00142
00143 ilUtil::delDir(ilObjMediaObject::_getDirectory($this->getId()));
00144
00145
00146 ilUtil::delDir(ilObjMediaObject::_getThumbnailDirectory($this->getId()));
00147
00148
00149 $this->deleteMetaData();
00150
00151
00152 ilMediaItem::deleteAllItemsOfMob($this->getId());
00153
00154
00155 parent::delete();
00156 }
00157 }
00158
00164 function getDescription()
00165 {
00166 return parent::getDescription();
00167 }
00168
00172 function setDescription($a_description)
00173 {
00174 parent::setDescription($a_description);
00175 }
00176
00188 function MDUpdateListener($a_element)
00189 {
00190 include_once 'Services/MetaData/classes/class.ilMD.php';
00191
00192 switch($a_element)
00193 {
00194 case 'General':
00195
00196
00197 $md = new ilMD(0, $this->getId(), $this->getType());
00198 $md_gen = $md->getGeneral();
00199
00200 if (is_object($md_gen))
00201 {
00202 ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
00203 $this->setTitle($md_gen->getTitle());
00204
00205 foreach($md_gen->getDescriptionIds() as $id)
00206 {
00207 $md_des = $md_gen->getDescription($id);
00208 ilObject::_writeDescription($this->getId(),$md_des->getDescription());
00209 $this->setDescription($md_des->getDescription());
00210 break;
00211 }
00212 }
00213
00214 break;
00215
00216 default:
00217 }
00218 return true;
00219 }
00220
00224 function createMetaData()
00225 {
00226 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00227
00228 global $ilUser;
00229
00230 $md_creator = new ilMDCreator(0, $this->getId(), $this->getType());
00231 $md_creator->setTitle($this->getTitle());
00232 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00233 $md_creator->setDescription($this->getDescription());
00234 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00235 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00236 $md_creator->setLanguage($ilUser->getPref('language'));
00237 $md_creator->create();
00238
00239 return true;
00240 }
00241
00245 function updateMetaData()
00246 {
00247 include_once("Services/MetaData/classes/class.ilMD.php");
00248 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00249 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00250
00251 $md =& new ilMD(0, $this->getId(), $this->getType());
00252 $md_gen =& $md->getGeneral();
00253 $md_gen->setTitle($this->getTitle());
00254
00255
00256 $md_des_ids =& $md_gen->getDescriptionIds();
00257 if (count($md_des_ids) > 0)
00258 {
00259 $md_des =& $md_gen->getDescription($md_des_ids[0]);
00260 $md_des->setDescription($this->getDescription());
00261 $md_des->update();
00262 }
00263 $md_gen->update();
00264
00265 }
00266
00270 function deleteMetaData()
00271 {
00272
00273 include_once('Services/MetaData/classes/class.ilMD.php');
00274 $md = new ilMD(0, $this->getId(), $this->getType());
00275 $md->deleteAll();
00276 }
00277
00278
00284 function addMediaItem(&$a_item)
00285 {
00286 $this->media_items[] =& $a_item;
00287 }
00288
00289
00295 function &getMediaItems()
00296 {
00297 return $this->media_items;
00298 }
00299
00300 function &getMediaItem($a_purpose)
00301 {
00302 for($i=0; $i<count($this->media_items); $i++)
00303 {
00304 if($this->media_items[$i]->getPurpose() == $a_purpose)
00305 {
00306 return $this->media_items[$i];
00307 }
00308 }
00309 return false;
00310 }
00311
00312
00316 function removeMediaItem($a_purpose)
00317 {
00318 for($i=0; $i<count($this->media_items); $i++)
00319 {
00320 if($this->media_items[$i]->getPurpose() == $a_purpose)
00321 {
00322 unset($this->media_items[$i]);
00323 }
00324 }
00325 }
00326
00330 function removeAllMediaItems()
00331 {
00332 $this->media_items = array();
00333 }
00334
00335
00336 function getMediaItemNr($a_purpose)
00337 {
00338 for($i=0; $i<count($this->media_items); $i++)
00339 {
00340 if($this->media_items[$i]->getPurpose() == $a_purpose)
00341 {
00342 return $i + 1;
00343 }
00344 }
00345 return false;
00346 }
00347
00348 function hasFullscreenItem()
00349 {
00350 if(is_object($this->getMediaItem("Fullscreen")))
00351 {
00352 return true;
00353 }
00354 else
00355 {
00356 return false;
00357 }
00358 }
00359
00363 function read()
00364 {
00365
00366 parent::read();
00367
00368
00369 ilMediaItem::_getMediaItemsOfMOb($this);
00370
00371
00372
00373 }
00374
00378 function setId($a_id)
00379 {
00380 $this->id = $a_id;
00381 }
00382
00383 function getId()
00384 {
00385 return $this->id;
00386 }
00387
00391 function setAlias($a_is_alias)
00392 {
00393 $this->is_alias = $a_is_alias;
00394 }
00395
00396 function isAlias()
00397 {
00398 return $this->is_alias;
00399 }
00400
00401 function setOriginID($a_id)
00402 {
00403 return $this->origin_id = $a_id;
00404 }
00405
00406 function getOriginID()
00407 {
00408 return $this->origin_id;
00409 }
00410
00411
00412
00413
00414
00415
00416
00417
00421 function getImportId()
00422 {
00423 return $this->import_id;
00424 }
00425
00426 function setImportId($a_id)
00427 {
00428 $this->import_id = $a_id;
00429 }
00430
00434 function create($a_upload = false, $a_save_media_items = true)
00435 {
00436 parent::create();
00437
00438 if (!$a_upload)
00439 {
00440 $this->createMetaData();
00441 }
00442
00443 if ($a_save_media_items)
00444 {
00445 $media_items =& $this->getMediaItems();
00446 for($i=0; $i<count($media_items); $i++)
00447 {
00448 $item =& $media_items[$i];
00449 $item->setMobId($this->getId());
00450 $item->setNr($i+1);
00451 $item->create();
00452 }
00453 }
00454
00455 }
00456
00457
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00508 function update()
00509 {
00510 $this->updateMetaData();
00511 parent::update();
00512
00513 ilMediaItem::deleteAllItemsOfMob($this->getId());
00514
00515
00516 $media_items =& $this->getMediaItems();
00517 $j = 1;
00518 foreach($media_items as $key => $val)
00519 {
00520 $item =& $media_items[$key];
00521 if (is_object($item))
00522 {
00523 $item->setMobId($this->getId());
00524 $item->setNr($j);
00525 $item->create();
00526 $j++;
00527 }
00528 }
00529 }
00530
00536 function _getDirectory($a_mob_id)
00537 {
00538 return ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
00539 }
00540
00546 function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
00547 {
00548 return ilUtil::getWebspaceDir($a_mode)."/thumbs/mm_".$a_mob_id;
00549 }
00550
00554 function createDirectory()
00555 {
00556 ilUtil::createDirectory(ilObjMediaObject::_getDirectory($this->getId()));
00557 }
00558
00562 function _createThumbnailDirectory($a_obj_id)
00563 {
00564 ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs");
00565 ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs/mm_".$a_obj_id);
00566 }
00567
00572 function getXML($a_mode = IL_MODE_FULL, $a_inst = 0)
00573 {
00574
00575
00576 switch ($a_mode)
00577 {
00578 case IL_MODE_ALIAS:
00579 $xml = "<MediaObject>";
00580 $xml .= "<MediaAlias OriginId=\"il__mob_".$this->getId()."\"/>";
00581 $media_items =& $this->getMediaItems();
00582
00583 for($i=0; $i<count($media_items); $i++)
00584 {
00585 $item =& $media_items[$i];
00586 $xml .= "<MediaAliasItem Purpose=\"".$item->getPurpose()."\">";
00587
00588
00589 $width = ($item->getWidth() != "")
00590 ? "Width=\"".$item->getWidth()."\""
00591 : "";
00592 $height = ($item->getHeight() != "")
00593 ? "Height=\"".$item->getHeight()."\""
00594 : "";
00595 $halign = ($item->getHAlign() != "")
00596 ? "HorizontalAlign=\"".$item->getHAlign()."\""
00597 : "";
00598 $xml .= "<Layout $width $height $halign />";
00599
00600
00601 if ($item->getCaption() != "")
00602 {
00603 $xml .= "<Caption Align=\"bottom\">".
00604 str_replace("&", "&", $item->getCaption())."</Caption>";
00605 }
00606
00607
00608 $parameters = $item->getParameters();
00609 foreach ($parameters as $name => $value)
00610 {
00611 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
00612 }
00613 $xml .= "</MediaAliasItem>";
00614 }
00615 break;
00616
00617
00618 case IL_MODE_OUTPUT:
00619
00620
00621
00622 $xml = "<MediaObject Id=\"il__mob_".$this->getId()."\">";
00623
00624 $media_items =& $this->getMediaItems();
00625 for($i=0; $i<count($media_items); $i++)
00626 {
00627 $item =& $media_items[$i];
00628 $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
00629
00630
00631 $xml.= "<Location Type=\"".$item->getLocationType()."\">".
00632 $item->getLocation()."</Location>";
00633
00634
00635 $xml.= "<Format>".$item->getFormat()."</Format>";
00636
00637
00638 $width = ($item->getWidth() != "")
00639 ? "Width=\"".$item->getWidth()."\""
00640 : "";
00641 $height = ($item->getHeight() != "")
00642 ? "Height=\"".$item->getHeight()."\""
00643 : "";
00644 $halign = ($item->getHAlign() != "")
00645 ? "HorizontalAlign=\"".$item->getHAlign()."\""
00646 : "";
00647 $xml .= "<Layout $width $height $halign />";
00648
00649
00650 if ($item->getCaption() != "")
00651 {
00652 $xml .= "<Caption Align=\"bottom\">".
00653 str_replace("&", "&", $item->getCaption())."</Caption>";
00654 }
00655
00656
00657 $parameters = $item->getParameters();
00658 foreach ($parameters as $name => $value)
00659 {
00660 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
00661 }
00662 $xml .= $item->getMapAreasXML();
00663 $xml .= "</MediaItem>";
00664 }
00665 break;
00666
00667
00668 case IL_MODE_FULL:
00669
00670
00671 $xml = "<MediaObject>";
00672
00673
00674 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00675 $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
00676 $md2xml->setExportMode(true);
00677 $md2xml->startExport();
00678 $xml.= $md2xml->getXML();
00679
00680 $media_items =& $this->getMediaItems();
00681 for($i=0; $i<count($media_items); $i++)
00682 {
00683 $item =& $media_items[$i];
00684 $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
00685
00686
00687 $xml.= "<Location Type=\"".$item->getLocationType()."\">".
00688 $item->getLocation()."</Location>";
00689
00690
00691 $xml.= "<Format>".$item->getFormat()."</Format>";
00692
00693
00694 $width = ($item->getWidth() != "")
00695 ? "Width=\"".$item->getWidth()."\""
00696 : "";
00697 $height = ($item->getHeight() != "")
00698 ? "Height=\"".$item->getHeight()."\""
00699 : "";
00700 $halign = ($item->getHAlign() != "")
00701 ? "HorizontalAlign=\"".$item->getHAlign()."\""
00702 : "";
00703 $xml .= "<Layout $width $height $halign />";
00704
00705
00706 if ($item->getCaption() != "")
00707 {
00708 $xml .= "<Caption Align=\"bottom\">".
00709 str_replace("&", "&", $item->getCaption())."</Caption>";
00710 }
00711
00712
00713 $parameters = $item->getParameters();
00714 foreach ($parameters as $name => $value)
00715 {
00716 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
00717 }
00718 $xml .= $item->getMapAreasXML(true, $a_inst);
00719 $xml .= "</MediaItem>";
00720 }
00721 break;
00722 }
00723 $xml .= "</MediaObject>";
00724 return $xml;
00725 }
00726
00727
00731 function exportXML(&$a_xml_writer, $a_inst = 0)
00732 {
00733 $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
00734 }
00735
00736
00744 function exportFiles($a_target_dir)
00745 {
00746 $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
00747 ilUtil::makeDir($a_target_dir."/objects/".$subdir);
00748
00749 $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
00750 ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
00751
00752 }
00753
00754
00755 function modifyExportIdentifier($a_tag, $a_param, $a_value)
00756 {
00757 if ($a_tag == "Identifier" && $a_param == "Entry")
00758 {
00759 $a_value = ilUtil::insertInstIntoID($a_value);
00760 }
00761
00762 return $a_value;
00763 }
00764
00765
00767
00769
00773 function setDom(&$a_dom)
00774 {
00775 $this->dom =& $a_dom;
00776 }
00777
00781 function setNode($a_node)
00782 {
00783 $this->node =& $a_node;
00784 $this->mob_node =& $a_node->first_child();
00785 }
00786
00790 function &getNode()
00791 {
00792 return $this->node;
00793 }
00794
00798 function setHierId($a_hier_id)
00799 {
00800 $this->hier_id = $a_hier_id;
00801 }
00802
00809 function setContainsIntLink($a_contains_link)
00810 {
00811 $this->contains_int_link = $a_contains_link;
00812 }
00813
00818 function containsIntLink()
00819 {
00820 return $this->contains_int_link;
00821 }
00822
00823
00824 function createAlias(&$a_pg_obj, $a_hier_id)
00825 {
00826 $this->node =& $this->dom->create_element("PageContent");
00827 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER);
00828 $this->mob_node =& $this->dom->create_element("MediaObject");
00829 $this->mob_node =& $this->node->append_child($this->mob_node);
00830 $this->mal_node =& $this->dom->create_element("MediaAlias");
00831 $this->mal_node =& $this->mob_node->append_child($this->mal_node);
00832 $this->mal_node->set_attribute("OriginId", "il__mob_".$this->getId());
00833
00834
00835 $item_node =& $this->dom->create_element("MediaAliasItem");
00836 $item_node =& $this->mob_node->append_child($item_node);
00837 $item_node->set_attribute("Purpose", "Standard");
00838 $media_item =& $this->getMediaItem("Standard");
00839
00840 $layout_node =& $this->dom->create_element("Layout");
00841 $layout_node =& $item_node->append_child($layout_node);
00842 if ($media_item->getWidth() > 0)
00843 {
00844 $layout_node->set_attribute("Width", $media_item->getWidth());
00845 }
00846 if ($media_item->getHeight() > 0)
00847 {
00848 $layout_node->set_attribute("Height", $media_item->getHeight());
00849 }
00850 $layout_node->set_attribute("HorizontalAlign", "Left");
00851
00852
00853 if ($media_item->getCaption() != "")
00854 {
00855 $cap_node =& $this->dom->create_element("Caption");
00856 $cap_node =& $item_node->append_child($cap_node);
00857 $cap_node->set_attribute("Align", "bottom");
00858 $cap_node->set_content($media_item->getCaption());
00859 }
00860
00861 $pars = $media_item->getParameters();
00862 foreach($pars as $par => $val)
00863 {
00864 $par_node =& $this->dom->create_element("Parameter");
00865 $par_node =& $item_node->append_child($par_node);
00866 $par_node->set_attribute("Name", $par);
00867 $par_node->set_attribute("Value", $val);
00868 }
00869
00870
00871 $fullscreen_item =& $this->getMediaItem("Fullscreen");
00872 if (is_object($fullscreen_item))
00873 {
00874 $item_node =& $this->dom->create_element("MediaAliasItem");
00875 $item_node =& $this->mob_node->append_child($item_node);
00876 $item_node->set_attribute("Purpose", "Fullscreen");
00877
00878
00879 $layout_node =& $this->dom->create_element("Layout");
00880 $layout_node =& $item_node->append_child($layout_node);
00881 if ($fullscreen_item->getWidth() > 0)
00882 {
00883 $layout_node->set_attribute("Width", $fullscreen_item->getWidth());
00884 }
00885 if ($fullscreen_item->getHeight() > 0)
00886 {
00887 $layout_node->set_attribute("Height", $fullscreen_item->getHeight());
00888 }
00889
00890
00891 if ($fullscreen_item->getCaption() != "")
00892 {
00893 $cap_node =& $this->dom->create_element("Caption");
00894 $cap_node =& $item_node->append_child($cap_node);
00895 $cap_node->set_attribute("Align", "bottom");
00896 $cap_node->set_content($fullscreen_item->getCaption());
00897 }
00898
00899 $pars = $fullscreen_item->getParameters();
00900 foreach($pars as $par => $val)
00901 {
00902 $par_node =& $this->dom->create_element("Parameter");
00903 $par_node =& $item_node->append_child($par_node);
00904 $par_node->set_attribute("Name", $par);
00905 $par_node->set_attribute("Value", $val);
00906 }
00907 }
00908 }
00909
00913 function _deleteAllUsages($a_type, $a_id)
00914 {
00915 global $ilDB;
00916
00917 $q = "DELETE FROM mob_usage WHERE usage_type='$a_type' AND usage_id='$a_id'";
00918 $ilDB->query($q);
00919 }
00920
00924 function _getMobsOfObject($a_type, $a_id)
00925 {
00926 global $ilDB;
00927
00928 $q = "SELECT * FROM mob_usage WHERE ".
00929 "usage_type = ".$ilDB->quote($a_type)." AND ".
00930 "usage_id = ".$ilDB->quote($a_id);
00931 $mobs = array();
00932 $mob_set = $ilDB->query($q);
00933 while($mob_rec = $mob_set->fetchRow(DB_FETCHMODE_ASSOC))
00934 {
00935 $mobs[$mob_rec["id"]] = $mob_rec["id"];
00936 }
00937 return $mobs;
00938 }
00939
00940 function _saveUsage($a_mob_id, $a_type, $a_id)
00941 {
00942 global $ilDB;
00943
00944 $q = "REPLACE INTO mob_usage (id, usage_type, usage_id) VALUES".
00945 " ('$a_mob_id', '$a_type', '$a_id')";
00946 $ilDB->query($q);
00947 }
00948
00949 function _removeUsage($a_mob_id, $a_type, $a_id)
00950 {
00951 global $ilDB;
00952
00953 $q = "DELETE FROM mob_usage WHERE ".
00954 " id = ".$ilDB->quote($a_mob_id)." AND ".
00955 " usage_type = ".$ilDB->quote($a_type)." AND ".
00956 " usage_id = ".$ilDB->quote($a_id);
00957 $ilDB->query($q);
00958 }
00959
00963 function getUsages()
00964 {
00965 global $ilDB;
00966
00967
00968 $q = "SELECT * FROM mob_usage WHERE id = '".$this->getId()."'";
00969 $us_set = $ilDB->query($q);
00970 $ret = array();
00971 while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
00972 {
00973 $ret[] = array("type" => $us_rec["usage_type"],
00974 "id" => $us_rec["usage_id"]);
00975 }
00976
00977
00978 $q = "SELECT DISTINCT mep_id FROM mep_tree WHERE child = '".$this->getId()."'";
00979 $us_set = $ilDB->query($q);
00980 while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
00981 {
00982 $ret[] = array("type" => "mep",
00983 "id" => $us_rec["mep_id"]);
00984 }
00985
00986
00987 $q = "SELECT DISTINCT mob_id FROM media_item as it, map_area as area ".
00988 " WHERE area.item_id = it.id ".
00989 " AND area.link_type='int' ".
00990 " AND area.target = 'il__mob_".$this->getId()."'";
00991 $us_set = $ilDB->query($q);
00992 while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
00993 {
00994 $ret[] = array("type" => "map",
00995 "id" => $us_rec["mob_id"]);
00996 }
00997
00998
00999 $users = ilObjUser::_getUsersForClipboadObject("mob", $this->getId());
01000 foreach ($users as $user)
01001 {
01002 $ret[] = array("type" => "clip",
01003 "id" => $user);
01004 }
01005
01006 return $ret;
01007 }
01008
01016 function _resizeImage($a_file, $a_width, $a_height)
01017 {
01018 $file_path = pathinfo($a_file);
01019 $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
01020 strlen($file_path["extension"]) - 1)."_".
01021 $a_width."_".
01022 $a_height.".".$file_path["extension"];
01023 $target_file = $file_path["dirname"]."/".
01024 $location;
01025 ilUtil::resizeImage($a_file, $target_file,
01026 (int) $a_width, (int) $a_height);
01027
01028 return $location;
01029 }
01030
01038 function getMimeType ($a_file)
01039 {
01040
01041 $set = ini_get("mime_magic.magicfile");
01042
01043 if ($set <> "")
01044 {
01045 $mime = @mime_content_type($a_file);
01046 }
01047
01048
01049
01050 if (empty($mime) || $mime == "text/plain")
01051 {
01052 $path = pathinfo($a_file);
01053 $ext = ".".strtolower($path["extension"]);
01054
01058 $types_map = ilObjMediaObject::getExt2MimeMap();
01059 $mime = $types_map[$ext];
01060 }
01061
01062
01063 if (empty($mime))
01064 {
01065 $mime = "application/octet-stream";
01066 }
01067
01068 return $mime;
01069 }
01070
01071
01075 function getExt2MimeMap()
01076 {
01077 $types_map = array (
01078 '.a' => 'application/octet-stream',
01079 '.ai' => 'application/postscript',
01080 '.aif' => 'audio/x-aiff',
01081 '.aifc' => 'audio/x-aiff',
01082 '.aiff' => 'audio/x-aiff',
01083 '.asd' => 'application/astound',
01084 '.asf' => 'video/x-ms-asf',
01085 '.asn' => 'application/astound',
01086 '.asx' => 'video/x-ms-asf',
01087 '.au' => 'audio/basic',
01088 '.avi' => 'video/x-msvideo',
01089 '.bat' => 'text/plain',
01090 '.bcpio' => 'application/x-bcpio',
01091 '.bin' => 'application/octet-stream',
01092 '.bmp' => 'image/x-ms-bmp',
01093 '.c' => 'text/plain',
01094 '.cdf' => 'application/x-cdf',
01095 '.class' => 'application/x-java-applet',
01096 '.com' => 'application/octet-stream',
01097 '.cpio' => 'application/x-cpio',
01098 '.csh' => 'application/x-csh',
01099 '.css' => 'text/css',
01100 '.csv' => 'text/comma-separated-values',
01101 '.dcr' => 'application/x-director',
01102 '.dir' => 'application/x-director',
01103 '.dll' => 'application/octet-stream',
01104 '.doc' => 'application/msword',
01105 '.dot' => 'application/msword',
01106 '.dvi' => 'application/x-dvi',
01107 '.dwg' => 'application/acad',
01108 '.dxf' => 'application/dxf',
01109 '.dxr' => 'application/x-director',
01110 '.eml' => 'message/rfc822',
01111 '.eps' => 'application/postscript',
01112 '.etx' => 'text/x-setext',
01113 '.exe' => 'application/octet-stream',
01114 '.gif' => 'image/gif',
01115 '.gtar' => 'application/x-gtar',
01116 '.gz' => 'application/gzip',
01117 '.h' => 'text/plain',
01118 '.hdf' => 'application/x-hdf',
01119 '.htm' => 'text/html',
01120 '.html' => 'text/html',
01121 '.ief' => 'image/ief',
01122 '.iff' => 'image/iff',
01123 '.jar' => 'application/x-java-applet',
01124 '.jpe' => 'image/jpeg',
01125 '.jpeg' => 'image/jpeg',
01126 '.jpg' => 'image/jpeg',
01127 '.js' => 'application/x-javascript',
01128 '.ksh' => 'text/plain',
01129 '.latex' => 'application/x-latex',
01130 '.m1v' => 'video/mpeg',
01131 '.man' => 'application/x-troff-man',
01132 '.me' => 'application/x-troff-me',
01133 '.mht' => 'message/rfc822',
01134 '.mhtml' => 'message/rfc822',
01135 '.mid' => 'audio/x-midi',
01136 '.midi' => 'audio/x-midi',
01137 '.mif' => 'application/x-mif',
01138 '.mov' => 'video/quicktime',
01139 '.movie' => 'video/x-sgi-movie',
01140 '.mp2' => 'audio/mpeg',
01141 '.mp3' => 'audio/mpeg',
01142 '.mpa' => 'video/mpeg',
01143 '.mpe' => 'video/mpeg',
01144 '.mpeg' => 'video/mpeg',
01145 '.mpg' => 'video/mpeg',
01146 '.ms' => 'application/x-troff-ms',
01147 '.nc' => 'application/x-netcdf',
01148 '.nws' => 'message/rfc822',
01149 '.o' => 'application/octet-stream',
01150 '.obj' => 'application/octet-stream',
01151 '.oda' => 'application/oda',
01152 '.p12' => 'application/x-pkcs12',
01153 '.p7c' => 'application/pkcs7-mime',
01154 '.pbm' => 'image/x-portable-bitmap',
01155 '.pdf' => 'application/pdf',
01156 '.pfx' => 'application/x-pkcs12',
01157 '.pgm' => 'image/x-portable-graymap',
01158 '.php' => 'application/x-httpd-php',
01159 '.phtml' => 'application/x-httpd-php',
01160 '.pl' => 'text/plain',
01161 '.png' => 'image/png',
01162 '.pnm' => 'image/x-portable-anymap',
01163 '.pot' => 'application/vnd.ms-powerpoint',
01164 '.ppa' => 'application/vnd.ms-powerpoint',
01165 '.ppm' => 'image/x-portable-pixmap',
01166 '.pps' => 'application/vnd.ms-powerpoint',
01167 '.ppt' => 'application/vnd.ms-powerpoint',
01168 '.ps' => 'application/postscript',
01169 '.psd' => 'image/psd',
01170 '.pwz' => 'application/vnd.ms-powerpoint',
01171 '.py' => 'text/x-python',
01172 '.pyc' => 'application/x-python-code',
01173 '.pyo' => 'application/x-python-code',
01174 '.qt' => 'video/quicktime',
01175 '.ra' => 'audio/x-pn-realaudio',
01176 '.ram' => 'application/x-pn-realaudio',
01177 '.ras' => 'image/x-cmu-raster',
01178 '.rdf' => 'application/xml',
01179 '.rgb' => 'image/x-rgb',
01180 '.roff' => 'application/x-troff',
01181 '.rpm' => 'audio/x-pn-realaudio-plugin',
01182 '.rtf' => 'application/rtf',
01183 '.rtx' => 'text/richtext',
01184 '.sgm' => 'text/x-sgml',
01185 '.sgml' => 'text/x-sgml',
01186 '.sh' => 'application/x-sh',
01187 '.shar' => 'application/x-shar',
01188 '.sit' => 'application/x-stuffit',
01189 '.snd' => 'audio/basic',
01190 '.so' => 'application/octet-stream',
01191 '.spc' => 'text/x-speech',
01192 '.src' => 'application/x-wais-source',
01193 '.sv4cpio'=> 'application/x-sv4cpio',
01194 '.sv4crc' => 'application/x-sv4crc',
01195 '.svg' => 'image/svg+xml',
01196 '.swf' => 'application/x-shockwave-flash',
01197 '.t' => 'application/x-troff',
01198 '.tar' => 'application/x-tar',
01199 '.talk' => 'text/x-speech',
01200 '.tbk' => 'application/toolbook',
01201 '.tcl' => 'application/x-tcl',
01202 '.tex' => 'application/x-tex',
01203 '.texi' => 'application/x-texinfo',
01204 '.texinfo'=> 'application/x-texinfo',
01205 '.tif' => 'image/tiff',
01206 '.tiff' => 'image/tiff',
01207 '.tr' => 'application/x-troff',
01208 '.tsv' => 'text/tab-separated-values',
01209 '.tsp' => 'application/dsptype',
01210 '.txt' => 'text/plain',
01211 '.ustar' => 'application',
01212 '.vcf' => 'text/x-vcard',
01213 '.vox' => 'audio/voxware',
01214 '.wav' => 'audio/x-wav',
01215 '.wax' => 'audio/x-ms-wax',
01216 '.wiz' => 'application/msword',
01217 '.wm' => 'video/x-ms-wm',
01218 '.wma' => 'audio/x-ms-wma',
01219 '.wmd' => 'video/x-ms-wmd',
01220 '.wml' => 'text/vnd.wap.wml',
01221 '.wmlc' => 'application/vnd.wap.wmlc',
01222 '.wmls' => 'text/vnd.wap.wmlscript',
01223 '.wmlsc' => 'application/vnd.wap.wmlscriptc',
01224 '.wmv' => 'video/x-ms-wmv',
01225 '.wmx' => 'video/x-ms-wmx',
01226 '.wmz' => 'video/x-ms-wmz',
01227 '.wvx' => 'video/x-ms-wvx',
01228 '.wrl' => 'x-world/x-vrml',
01229 '.xbm' => 'image/x-xbitmap',
01230 '.xla' => 'application/msexcel',
01231 '.xlb' => 'application/vnd.ms-excel',
01232 '.xls' => 'application/msexcel',
01233 '.xml' => 'text/xml',
01234 '.xpm' => 'image/x-xpixmap',
01235 '.xsl' => 'application/xml',
01236 '.xwd' => 'image/x-xwindowdump',
01237 '.zip' => 'application/zip');
01238
01239 return $types_map;
01240 }
01241
01242 function getDataDirectory()
01243 {
01244 return ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
01245 }
01246
01247
01252 function setEnabled ($value)
01253 {
01254 if (is_object($this->node))
01255 {
01256 $this->node->set_attribute("Enabled", $value);
01257 }
01258 }
01259
01260
01266 function isEnabled ()
01267 {
01268 if (is_object($this->node) && $this->node->has_attribute("Enabled"))
01269 {
01270 $compare = $this->node->get_attribute("Enabled");
01271 }
01272 else $compare = "True";
01273
01274 return $compare == "True";
01275 }
01276
01277
01281 function enable()
01282 {
01283 $this->setEnabled ("True");
01284 }
01285
01289 function disable()
01290 {
01291 $this->setEnabled ("False");
01292 }
01293
01297 function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
01298 {
01299
01300 $media_object = new ilObjMediaObject();
01301 $media_object->setTitle($name);
01302 $media_object->setDescription("");
01303 $media_object->create();
01304
01305
01306 $media_object->createDirectory();
01307 $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
01308
01309 $media_item =& new ilMediaItem();
01310 $media_object->addMediaItem($media_item);
01311 $media_item->setPurpose("Standard");
01312
01313 $file = $mob_dir."/".$name;
01314 if ($upload)
01315 {
01316 ilUtil::moveUploadedFile($tmp_name,$name, $file);
01317 }
01318 else
01319 {
01320 copy($tmp_name, $file);
01321 }
01322
01323 $format = ilObjMediaObject::getMimeType($file);
01324 $location = $name;
01325
01326 $media_item->setFormat($format);
01327 $media_item->setLocation($location);
01328 $media_item->setLocationType("LocalFile");
01329 $media_object->setTitle($name);
01330 $media_object->setDescription($format);
01331
01332 if (ilUtil::deducibleSize($format))
01333 {
01334 $size = getimagesize($file);
01335 $media_item->setWidth($size[0]);
01336 $media_item->setHeight($size[1]);
01337 }
01338 $media_item->setHAlign("Left");
01339
01340 ilUtil::renameExecutables($mob_dir);
01341 $media_object->update();
01342
01343 return $media_object;
01344 }
01345
01346 }
01347 ?>