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("./Services/MediaObjects/classes/class.ilMediaItem.php");
00029 include_once "classes/class.ilObject.php";
00030
00046 class ilObjMediaObject extends ilObject
00047 {
00048 var $is_alias;
00049 var $origin_id;
00050 var $id;
00051
00052 var $dom;
00053 var $hier_id;
00054 var $node;
00055 var $mob_node;
00056 var $media_items;
00057 var $contains_int_link;
00058
00063 function ilObjMediaObject($a_id = 0)
00064 {
00065 $this->is_alias = false;
00066 $this->media_items = array();
00067 $this->contains_int_link = false;
00068 $this->type = "mob";
00069
00070 parent::ilObject($a_id, false);
00071
00072
00073
00074
00075
00076
00077
00078
00079 }
00080
00081 function setRefId()
00082 {
00083 $this->ilias->raiseError("Operation ilObjMedia::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
00084 }
00085
00086 function getRefId()
00087 {
00088 $this->ilias->raiseError("Operation ilObjMedia::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
00089 }
00090
00091 function putInTree()
00092 {
00093 $this->ilias->raiseError("Operation ilObjMedia::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
00094 }
00095
00096 function createReference()
00097 {
00098 $this->ilias->raiseError("Operation ilObjMedia::createReference() not allowed.",$this->ilias->error_obj->FATAL);
00099 }
00100
00101 function setTitle($a_title)
00102 {
00103 parent::setTitle($a_title);
00104 }
00105
00106 function getTitle()
00107 {
00108 return parent::getTitle();
00109 }
00110
00118 function _exists($a_id)
00119 {
00120 global $ilDB;
00121
00122 include_once("./Services/COPage/classes/class.ilInternalLink.php");
00123 if (is_int(strpos($a_id, "_")))
00124 {
00125 $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00126 }
00127
00128 return parent::_exists($a_id, false);
00129 }
00130
00134 function delete()
00135 {
00136 if (!($this->getId() > 0))
00137 {
00138 return;
00139 }
00140
00141 $usages = $this->getUsages();
00142
00143 if (count($usages) == 0)
00144 {
00145
00146 ilUtil::delDir(ilObjMediaObject::_getDirectory($this->getId()));
00147
00148
00149 ilUtil::delDir(ilObjMediaObject::_getThumbnailDirectory($this->getId()));
00150
00151
00152 $this->deleteMetaData();
00153
00154
00155 ilMediaItem::deleteAllItemsOfMob($this->getId());
00156
00157
00158 parent::delete();
00159 }
00160 }
00161
00167 function getDescription()
00168 {
00169 return parent::getDescription();
00170 }
00171
00175 function setDescription($a_description)
00176 {
00177 parent::setDescription($a_description);
00178 }
00179
00191 function MDUpdateListener($a_element)
00192 {
00193 include_once 'Services/MetaData/classes/class.ilMD.php';
00194
00195 switch($a_element)
00196 {
00197 case 'General':
00198
00199
00200 $md = new ilMD(0, $this->getId(), $this->getType());
00201 $md_gen = $md->getGeneral();
00202
00203 if (is_object($md_gen))
00204 {
00205 ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
00206 $this->setTitle($md_gen->getTitle());
00207
00208 foreach($md_gen->getDescriptionIds() as $id)
00209 {
00210 $md_des = $md_gen->getDescription($id);
00211 ilObject::_writeDescription($this->getId(),$md_des->getDescription());
00212 $this->setDescription($md_des->getDescription());
00213 break;
00214 }
00215 }
00216
00217 break;
00218
00219 default:
00220 }
00221 return true;
00222 }
00223
00227 function createMetaData()
00228 {
00229 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00230
00231 global $ilUser;
00232
00233 $md_creator = new ilMDCreator(0, $this->getId(), $this->getType());
00234 $md_creator->setTitle($this->getTitle());
00235 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00236 $md_creator->setDescription($this->getDescription());
00237 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00238 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00239 $md_creator->setLanguage($ilUser->getPref('language'));
00240 $md_creator->create();
00241
00242 return true;
00243 }
00244
00248 function updateMetaData()
00249 {
00250 include_once("Services/MetaData/classes/class.ilMD.php");
00251 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00252 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00253
00254 $md =& new ilMD(0, $this->getId(), $this->getType());
00255 $md_gen =& $md->getGeneral();
00256 $md_gen->setTitle($this->getTitle());
00257
00258
00259 $md_des_ids =& $md_gen->getDescriptionIds();
00260 if (count($md_des_ids) > 0)
00261 {
00262 $md_des =& $md_gen->getDescription($md_des_ids[0]);
00263 $md_des->setDescription($this->getDescription());
00264 $md_des->update();
00265 }
00266 $md_gen->update();
00267
00268 }
00269
00273 function deleteMetaData()
00274 {
00275
00276 include_once('Services/MetaData/classes/class.ilMD.php');
00277 $md = new ilMD(0, $this->getId(), $this->getType());
00278 $md->deleteAll();
00279 }
00280
00281
00287 function addMediaItem(&$a_item)
00288 {
00289 $this->media_items[] =& $a_item;
00290 }
00291
00292
00298 function &getMediaItems()
00299 {
00300 return $this->media_items;
00301 }
00302
00303 function &getMediaItem($a_purpose)
00304 {
00305 for($i=0; $i<count($this->media_items); $i++)
00306 {
00307 if($this->media_items[$i]->getPurpose() == $a_purpose)
00308 {
00309 return $this->media_items[$i];
00310 }
00311 }
00312 return false;
00313 }
00314
00315
00319 function removeMediaItem($a_purpose)
00320 {
00321 for($i=0; $i<count($this->media_items); $i++)
00322 {
00323 if($this->media_items[$i]->getPurpose() == $a_purpose)
00324 {
00325 unset($this->media_items[$i]);
00326 }
00327 }
00328 }
00329
00333 function removeAllMediaItems()
00334 {
00335 $this->media_items = array();
00336 }
00337
00338
00339 function getMediaItemNr($a_purpose)
00340 {
00341 for($i=0; $i<count($this->media_items); $i++)
00342 {
00343 if($this->media_items[$i]->getPurpose() == $a_purpose)
00344 {
00345 return $i + 1;
00346 }
00347 }
00348 return false;
00349 }
00350
00351 function hasFullscreenItem()
00352 {
00353 if(is_object($this->getMediaItem("Fullscreen")))
00354 {
00355 return true;
00356 }
00357 else
00358 {
00359 return false;
00360 }
00361 }
00362
00366 function read()
00367 {
00368
00369 parent::read();
00370
00371
00372 ilMediaItem::_getMediaItemsOfMOb($this);
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
00458
00459
00463 function update()
00464 {
00465 $this->updateMetaData();
00466 parent::update();
00467
00468 ilMediaItem::deleteAllItemsOfMob($this->getId());
00469
00470
00471 $media_items =& $this->getMediaItems();
00472 $j = 1;
00473 foreach($media_items as $key => $val)
00474 {
00475 $item =& $media_items[$key];
00476 if (is_object($item))
00477 {
00478 $item->setMobId($this->getId());
00479 $item->setNr($j);
00480 $item->create();
00481 $j++;
00482 }
00483 }
00484 }
00485
00491 function _getDirectory($a_mob_id)
00492 {
00493 return ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
00494 }
00495
00501 function _getURL($a_mob_id)
00502 {
00503 return ilUtil::getHtmlPath(ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id);
00504 }
00505
00511 function _getThumbnailDirectory($a_mob_id, $a_mode = "filesystem")
00512 {
00513 return ilUtil::getWebspaceDir($a_mode)."/thumbs/mm_".$a_mob_id;
00514 }
00515
00521 static function _lookupStandardItemPath($a_mob_id, $a_url_encode = false,
00522 $a_web = true)
00523 {
00524 $location = ($a_url_encode)
00525 ? rawurlencode(ilMediaItem::_lookupLocationForMobId($a_mob_id, "Standard"))
00526 : ilMediaItem::_lookupLocationForMobId($a_mob_id, "Standard");
00527
00528 $path = ($a_web)
00529 ? ILIAS_HTTP_PATH
00530 : ".";
00531
00532 return $path."/data/".CLIENT_ID."/mobs/mm_".$a_mob_id."/".$location;
00533 }
00534
00538 function createDirectory()
00539 {
00540 ilUtil::createDirectory(ilObjMediaObject::_getDirectory($this->getId()));
00541 }
00542
00546 function _createThumbnailDirectory($a_obj_id)
00547 {
00548 ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs");
00549 ilUtil::createDirectory(ilUtil::getWebspaceDir()."/thumbs/mm_".$a_obj_id);
00550 }
00551
00556 function getXML($a_mode = IL_MODE_FULL, $a_inst = 0)
00557 {
00558
00559
00560 switch ($a_mode)
00561 {
00562 case IL_MODE_ALIAS:
00563 $xml = "<MediaObject>";
00564 $xml .= "<MediaAlias OriginId=\"il__mob_".$this->getId()."\"/>";
00565 $media_items =& $this->getMediaItems();
00566
00567 for($i=0; $i<count($media_items); $i++)
00568 {
00569 $item =& $media_items[$i];
00570 $xml .= "<MediaAliasItem Purpose=\"".$item->getPurpose()."\">";
00571
00572
00573 $width = ($item->getWidth() != "")
00574 ? "Width=\"".$item->getWidth()."\""
00575 : "";
00576 $height = ($item->getHeight() != "")
00577 ? "Height=\"".$item->getHeight()."\""
00578 : "";
00579 $halign = ($item->getHAlign() != "")
00580 ? "HorizontalAlign=\"".$item->getHAlign()."\""
00581 : "";
00582 $xml .= "<Layout $width $height $halign />";
00583
00584
00585 if ($item->getCaption() != "")
00586 {
00587 $xml .= "<Caption Align=\"bottom\">".
00588 str_replace("&", "&", $item->getCaption())."</Caption>";
00589 }
00590
00591
00592 $parameters = $item->getParameters();
00593 foreach ($parameters as $name => $value)
00594 {
00595 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
00596 }
00597 $xml .= "</MediaAliasItem>";
00598 }
00599 break;
00600
00601
00602 case IL_MODE_OUTPUT:
00603
00604
00605
00606 $xml = "<MediaObject Id=\"il__mob_".$this->getId()."\">";
00607
00608 $media_items =& $this->getMediaItems();
00609 for($i=0; $i<count($media_items); $i++)
00610 {
00611 $item =& $media_items[$i];
00612 $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
00613
00614
00615 $xml.= "<Location Type=\"".$item->getLocationType()."\">".
00616 $this->handleAmps($item->getLocation())."</Location>";
00617
00618
00619 $xml.= "<Format>".$item->getFormat()."</Format>";
00620
00621
00622 $width = ($item->getWidth() != "")
00623 ? "Width=\"".$item->getWidth()."\""
00624 : "";
00625 $height = ($item->getHeight() != "")
00626 ? "Height=\"".$item->getHeight()."\""
00627 : "";
00628 $halign = ($item->getHAlign() != "")
00629 ? "HorizontalAlign=\"".$item->getHAlign()."\""
00630 : "";
00631 $xml .= "<Layout $width $height $halign />";
00632
00633
00634 if ($item->getCaption() != "")
00635 {
00636 $xml .= "<Caption Align=\"bottom\">".
00637 str_replace("&", "&", $item->getCaption())."</Caption>";
00638 }
00639
00640
00641 $parameters = $item->getParameters();
00642 foreach ($parameters as $name => $value)
00643 {
00644 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
00645 }
00646 $xml .= $item->getMapAreasXML();
00647 $xml .= "</MediaItem>";
00648 }
00649 break;
00650
00651
00652 case IL_MODE_FULL:
00653
00654
00655 $xml = "<MediaObject>";
00656
00657
00658 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00659 $md2xml = new ilMD2XML(0, $this->getId(), $this->getType());
00660 $md2xml->setExportMode(true);
00661 $md2xml->startExport();
00662 $xml.= $md2xml->getXML();
00663
00664 $media_items =& $this->getMediaItems();
00665 for($i=0; $i<count($media_items); $i++)
00666 {
00667 $item =& $media_items[$i];
00668 $xml .= "<MediaItem Purpose=\"".$item->getPurpose()."\">";
00669
00670
00671 $xml.= "<Location Type=\"".$item->getLocationType()."\">".
00672 $item->getLocation()."</Location>";
00673
00674
00675 $xml.= "<Format>".$item->getFormat()."</Format>";
00676
00677
00678 $width = ($item->getWidth() != "")
00679 ? "Width=\"".$item->getWidth()."\""
00680 : "";
00681 $height = ($item->getHeight() != "")
00682 ? "Height=\"".$item->getHeight()."\""
00683 : "";
00684 $halign = ($item->getHAlign() != "")
00685 ? "HorizontalAlign=\"".$item->getHAlign()."\""
00686 : "";
00687 $xml .= "<Layout $width $height $halign />";
00688
00689
00690 if ($item->getCaption() != "")
00691 {
00692 $xml .= "<Caption Align=\"bottom\">".
00693 str_replace("&", "&", $item->getCaption())."</Caption>";
00694 }
00695
00696
00697 $parameters = $item->getParameters();
00698 foreach ($parameters as $name => $value)
00699 {
00700 $xml .= "<Parameter Name=\"$name\" Value=\"$value\"/>";
00701 }
00702 $xml .= $item->getMapAreasXML(true, $a_inst);
00703 $xml .= "</MediaItem>";
00704 }
00705 break;
00706 }
00707 $xml .= "</MediaObject>";
00708 return $xml;
00709 }
00710
00714 function handleAmps($a_str)
00715 {
00716 $a_str = str_replace("&", "&", $a_str);
00717 $a_str = str_replace("&", "&", $a_str);
00718 return $a_str;
00719 }
00720
00724 function exportXML(&$a_xml_writer, $a_inst = 0)
00725 {
00726 $a_xml_writer->appendXML($this->getXML(IL_MODE_FULL, $a_inst));
00727 }
00728
00729
00737 function exportFiles($a_target_dir)
00738 {
00739 $subdir = "il_".IL_INST_ID."_mob_".$this->getId();
00740 ilUtil::makeDir($a_target_dir."/objects/".$subdir);
00741
00742 $mobdir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->getId();
00743 ilUtil::rCopy($mobdir, $a_target_dir."/objects/".$subdir);
00744
00745 }
00746
00747
00748 function modifyExportIdentifier($a_tag, $a_param, $a_value)
00749 {
00750 if ($a_tag == "Identifier" && $a_param == "Entry")
00751 {
00752 $a_value = ilUtil::insertInstIntoID($a_value);
00753 }
00754
00755 return $a_value;
00756 }
00757
00758
00760
00762
00766 function setDom(&$a_dom)
00767 {
00768 $this->dom =& $a_dom;
00769 }
00770
00774 function setNode($a_node)
00775 {
00776 $this->node =& $a_node;
00777 $this->mob_node =& $a_node->first_child();
00778 }
00779
00783 function &getNode()
00784 {
00785 return $this->node;
00786 }
00787
00791 function setHierId($a_hier_id)
00792 {
00793 $this->hier_id = $a_hier_id;
00794 }
00795
00802 function setContainsIntLink($a_contains_link)
00803 {
00804 $this->contains_int_link = $a_contains_link;
00805 }
00806
00811 function containsIntLink()
00812 {
00813 return $this->contains_int_link;
00814 }
00815
00816
00817 function createAlias(&$a_pg_obj, $a_hier_id)
00818 {
00819 $this->node =& $this->dom->create_element("PageContent");
00820 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER);
00821 $this->mob_node =& $this->dom->create_element("MediaObject");
00822 $this->mob_node =& $this->node->append_child($this->mob_node);
00823 $this->mal_node =& $this->dom->create_element("MediaAlias");
00824 $this->mal_node =& $this->mob_node->append_child($this->mal_node);
00825 $this->mal_node->set_attribute("OriginId", "il__mob_".$this->getId());
00826
00827
00828 $item_node =& $this->dom->create_element("MediaAliasItem");
00829 $item_node =& $this->mob_node->append_child($item_node);
00830 $item_node->set_attribute("Purpose", "Standard");
00831 $media_item =& $this->getMediaItem("Standard");
00832
00833 $layout_node =& $this->dom->create_element("Layout");
00834 $layout_node =& $item_node->append_child($layout_node);
00835 if ($media_item->getWidth() > 0)
00836 {
00837 $layout_node->set_attribute("Width", $media_item->getWidth());
00838 }
00839 if ($media_item->getHeight() > 0)
00840 {
00841 $layout_node->set_attribute("Height", $media_item->getHeight());
00842 }
00843 $layout_node->set_attribute("HorizontalAlign", "Left");
00844
00845
00846 if ($media_item->getCaption() != "")
00847 {
00848 $cap_node =& $this->dom->create_element("Caption");
00849 $cap_node =& $item_node->append_child($cap_node);
00850 $cap_node->set_attribute("Align", "bottom");
00851 $cap_node->set_content($media_item->getCaption());
00852 }
00853
00854 $pars = $media_item->getParameters();
00855 foreach($pars as $par => $val)
00856 {
00857 $par_node =& $this->dom->create_element("Parameter");
00858 $par_node =& $item_node->append_child($par_node);
00859 $par_node->set_attribute("Name", $par);
00860 $par_node->set_attribute("Value", $val);
00861 }
00862
00863
00864 $fullscreen_item =& $this->getMediaItem("Fullscreen");
00865 if (is_object($fullscreen_item))
00866 {
00867 $item_node =& $this->dom->create_element("MediaAliasItem");
00868 $item_node =& $this->mob_node->append_child($item_node);
00869 $item_node->set_attribute("Purpose", "Fullscreen");
00870
00871
00872 $layout_node =& $this->dom->create_element("Layout");
00873 $layout_node =& $item_node->append_child($layout_node);
00874 if ($fullscreen_item->getWidth() > 0)
00875 {
00876 $layout_node->set_attribute("Width", $fullscreen_item->getWidth());
00877 }
00878 if ($fullscreen_item->getHeight() > 0)
00879 {
00880 $layout_node->set_attribute("Height", $fullscreen_item->getHeight());
00881 }
00882
00883
00884 if ($fullscreen_item->getCaption() != "")
00885 {
00886 $cap_node =& $this->dom->create_element("Caption");
00887 $cap_node =& $item_node->append_child($cap_node);
00888 $cap_node->set_attribute("Align", "bottom");
00889 $cap_node->set_content($fullscreen_item->getCaption());
00890 }
00891
00892 $pars = $fullscreen_item->getParameters();
00893 foreach($pars as $par => $val)
00894 {
00895 $par_node =& $this->dom->create_element("Parameter");
00896 $par_node =& $item_node->append_child($par_node);
00897 $par_node->set_attribute("Name", $par);
00898 $par_node->set_attribute("Value", $val);
00899 }
00900 }
00901 }
00902
00906 function _deleteAllUsages($a_type, $a_id)
00907 {
00908 global $ilDB;
00909
00910 $q = "DELETE FROM mob_usage WHERE usage_type = ".
00911 $ilDB->quote($a_type)." AND usage_id= ".$ilDB->quote($a_id);
00912 $ilDB->query($q);
00913 }
00914
00918 function _getMobsOfObject($a_type, $a_id)
00919 {
00920 global $ilDB;
00921
00922 $q = "SELECT * FROM mob_usage WHERE ".
00923 "usage_type = ".$ilDB->quote($a_type)." AND ".
00924 "usage_id = ".$ilDB->quote($a_id);
00925 $mobs = array();
00926 $mob_set = $ilDB->query($q);
00927 while($mob_rec = $mob_set->fetchRow(DB_FETCHMODE_ASSOC))
00928 {
00929 $mobs[$mob_rec["id"]] = $mob_rec["id"];
00930 }
00931 return $mobs;
00932 }
00933
00934 function _saveUsage($a_mob_id, $a_type, $a_id)
00935 {
00936 global $ilDB;
00937
00938 $q = "REPLACE INTO mob_usage (id, usage_type, usage_id) VALUES".
00939 " (".$ilDB->quote($a_mob_id).",".
00940 $ilDB->quote($a_type).",".$ilDB->quote($a_id).")";
00941 $ilDB->query($q);
00942 }
00943
00944 function _removeUsage($a_mob_id, $a_type, $a_id)
00945 {
00946 global $ilDB;
00947
00948 $q = "DELETE FROM mob_usage WHERE ".
00949 " id = ".$ilDB->quote($a_mob_id)." AND ".
00950 " usage_type = ".$ilDB->quote($a_type)." AND ".
00951 " usage_id = ".$ilDB->quote($a_id);
00952 $ilDB->query($q);
00953 }
00954
00958 function getUsages()
00959 {
00960 return $this->lookupUsages($this->getId());
00961 }
00962
00968 function lookupUsages($a_id)
00969 {
00970 global $ilDB;
00971
00972
00973 $q = "SELECT * FROM mob_usage WHERE id = ".
00974 $ilDB->quote($a_id);
00975 $us_set = $ilDB->query($q);
00976 $ret = array();
00977 while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
00978 {
00979 $ret[] = array("type" => $us_rec["usage_type"],
00980 "id" => $us_rec["usage_id"]);
00981 }
00982
00983
00984 $q = "SELECT DISTINCT mep_id FROM mep_tree WHERE child = ".
00985 $ilDB->quote($a_id);
00986 $us_set = $ilDB->query($q);
00987 while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
00988 {
00989 $ret[] = array("type" => "mep",
00990 "id" => $us_rec["mep_id"]);
00991 }
00992
00993
00994 include_once("./Services/News/classes/class.ilNewsItem.php");
00995 $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
00996 foreach($news_usages as $nu)
00997 {
00998 $ret[] = $nu;
00999 }
01000
01001
01002
01003 $q = "SELECT DISTINCT mob_id FROM media_item as it, map_area as area ".
01004 " WHERE area.item_id = it.id ".
01005 " AND area.link_type='int' ".
01006 " AND area.target = ".$ilDB->quote("il__mob_".$a_id);
01007 $us_set = $ilDB->query($q);
01008 while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
01009 {
01010 $ret[] = array("type" => "map",
01011 "id" => $us_rec["mob_id"]);
01012 }
01013
01014
01015 $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
01016 foreach ($users as $user)
01017 {
01018 $ret[] = array("type" => "clip",
01019 "id" => $user);
01020 }
01021
01022 return $ret;
01023 }
01024
01028 function getParentObjectIdForUsage($a_usage, $a_include_all_access_obj_ids = false)
01029 {
01030 if(is_int(strpos($a_usage["type"], ":")))
01031 {
01032 $us_arr = explode(":", $a_usage["type"]);
01033 $type = $us_arr[1];
01034 $cont_type = $us_arr[0];
01035 }
01036 else
01037 {
01038 $type = $a_usage["type"];
01039 }
01040
01041 $id = $a_usage["id"];
01042 $obj_id = false;
01043
01044 switch($type)
01045 {
01046 case "html":
01047 if ($cont_type == "cat")
01048 {
01049 $obj_id = $id;
01050 }
01051
01052 if ($cont_type == "tst")
01053 {
01054 $obj_id = $id;
01055
01056 }
01057
01058 if ($cont_type == "qpl")
01059 {
01060 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
01061 $qinfo = assQuestion::_getQuestionInfo($id);
01062 if ($qinfo["original_id"] > 0)
01063 {
01064 include_once("./Modules/Test/classes/class.ilObjTest.php");
01065 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id);
01066 }
01067 else
01068 {
01069 $obj_id = $qinfo["obj_fi"];
01070 }
01071 }
01072 break;
01073
01074 case "pg":
01075
01076
01077 if ($cont_type == "qpl")
01078 {
01079 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
01080 $qinfo = assQuestion::_getQuestionInfo($id);
01081 if ($qinfo["original_id"] > 0)
01082 {
01083 include_once("./Modules/Test/classes/class.ilObjTest.php");
01084 $obj_id = ilObjTest::_lookupTestObjIdForQuestionId($id);
01085 }
01086 else
01087 {
01088 $obj_id = $qinfo["obj_fi"];
01089 }
01090 }
01091
01092
01093 if ($cont_type == "lm" || $cont_type == "dbk")
01094 {
01095 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
01096 $obj_id = ilLMObject::_lookupContObjID($id);
01097 }
01098
01099
01100 if ($cont_type == "gdf")
01101 {
01102 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
01103 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
01104 $term_id = ilGlossaryDefinition::_lookupTermId($id);
01105 $obj_id = ilGlossaryTerm::_lookGlossaryID($term_id);
01106 }
01107
01108 break;
01109
01110
01111 case "mep":
01112 $obj_id = $id;
01113 break;
01114
01115
01116 case "news":
01117 include_once("./Services/News/classes/class.ilNewsItem.php");
01118 $obj_id = ilNewsItem::_lookupContextObjId($id);
01119 break;
01120 }
01121
01122 return $obj_id;
01123 }
01124
01132 function _resizeImage($a_file, $a_width, $a_height)
01133 {
01134 $file_path = pathinfo($a_file);
01135 $location = substr($file_path["basename"],0,strlen($file_path["basename"]) -
01136 strlen($file_path["extension"]) - 1)."_".
01137 $a_width."_".
01138 $a_height.".".$file_path["extension"];
01139 $target_file = $file_path["dirname"]."/".
01140 $location;
01141 ilUtil::resizeImage($a_file, $target_file,
01142 (int) $a_width, (int) $a_height);
01143
01144 return $location;
01145 }
01146
01154 static function getMimeType ($a_file)
01155 {
01156
01157 $set = ini_get("mime_magic.magicfile");
01158
01159 if ($set <> "")
01160 {
01161 $mime = @mime_content_type($a_file);
01162 }
01163
01164
01165
01166 if (empty($mime) || $mime == "text/plain")
01167 {
01168 $path = pathinfo($a_file);
01169 $ext = ".".strtolower($path["extension"]);
01170
01174 $types_map = ilObjMediaObject::getExt2MimeMap();
01175 $mime = $types_map[$ext];
01176 }
01177
01178
01179 if (empty($mime))
01180 {
01181 $mime = "application/octet-stream";
01182 }
01183
01184 return $mime;
01185 }
01186
01187
01191 function getExt2MimeMap()
01192 {
01193 $types_map = array (
01194 '.a' => 'application/octet-stream',
01195 '.ai' => 'application/postscript',
01196 '.aif' => 'audio/x-aiff',
01197 '.aifc' => 'audio/x-aiff',
01198 '.aiff' => 'audio/x-aiff',
01199 '.asd' => 'application/astound',
01200 '.asf' => 'video/x-ms-asf',
01201 '.asn' => 'application/astound',
01202 '.asx' => 'video/x-ms-asf',
01203 '.au' => 'audio/basic',
01204 '.avi' => 'video/x-msvideo',
01205 '.bat' => 'text/plain',
01206 '.bcpio' => 'application/x-bcpio',
01207 '.bin' => 'application/octet-stream',
01208 '.bmp' => 'image/x-ms-bmp',
01209 '.c' => 'text/plain',
01210 '.cdf' => 'application/x-cdf',
01211 '.class' => 'application/x-java-applet',
01212 '.com' => 'application/octet-stream',
01213 '.cpio' => 'application/x-cpio',
01214 '.csh' => 'application/x-csh',
01215 '.css' => 'text/css',
01216 '.csv' => 'text/comma-separated-values',
01217 '.dcr' => 'application/x-director',
01218 '.dir' => 'application/x-director',
01219 '.dll' => 'application/octet-stream',
01220 '.doc' => 'application/msword',
01221 '.dot' => 'application/msword',
01222 '.dvi' => 'application/x-dvi',
01223 '.dwg' => 'application/acad',
01224 '.dxf' => 'application/dxf',
01225 '.dxr' => 'application/x-director',
01226 '.eml' => 'message/rfc822',
01227 '.eps' => 'application/postscript',
01228 '.etx' => 'text/x-setext',
01229 '.exe' => 'application/octet-stream',
01230 '.flv' => 'video/x-flv',
01231 '.gif' => 'image/gif',
01232 '.gtar' => 'application/x-gtar',
01233 '.gz' => 'application/gzip',
01234 '.h' => 'text/plain',
01235 '.hdf' => 'application/x-hdf',
01236 '.htm' => 'text/html',
01237 '.html' => 'text/html',
01238 '.ief' => 'image/ief',
01239 '.iff' => 'image/iff',
01240 '.jar' => 'application/x-java-applet',
01241 '.jpe' => 'image/jpeg',
01242 '.jpeg' => 'image/jpeg',
01243 '.jpg' => 'image/jpeg',
01244 '.js' => 'application/x-javascript',
01245 '.ksh' => 'text/plain',
01246 '.latex' => 'application/x-latex',
01247 '.m1v' => 'video/mpeg',
01248 '.man' => 'application/x-troff-man',
01249 '.me' => 'application/x-troff-me',
01250 '.mht' => 'message/rfc822',
01251 '.mhtml' => 'message/rfc822',
01252 '.mid' => 'audio/x-midi',
01253 '.midi' => 'audio/x-midi',
01254 '.mif' => 'application/x-mif',
01255 '.mov' => 'video/quicktime',
01256 '.movie' => 'video/x-sgi-movie',
01257 '.mp2' => 'audio/mpeg',
01258 '.mp3' => 'audio/mpeg',
01259 '.mpa' => 'video/mpeg',
01260 '.mpe' => 'video/mpeg',
01261 '.mpeg' => 'video/mpeg',
01262 '.mpg' => 'video/mpeg',
01263 '.mp4' => 'video/mp4',
01264 '.mv4' => 'video/mp4',
01265 '.ms' => 'application/x-troff-ms',
01266 '.nc' => 'application/x-netcdf',
01267 '.nws' => 'message/rfc822',
01268 '.o' => 'application/octet-stream',
01269 '.ogg' => 'application/ogg',
01270 '.obj' => 'application/octet-stream',
01271 '.oda' => 'application/oda',
01272 '.p12' => 'application/x-pkcs12',
01273 '.p7c' => 'application/pkcs7-mime',
01274 '.pbm' => 'image/x-portable-bitmap',
01275 '.pdf' => 'application/pdf',
01276 '.pfx' => 'application/x-pkcs12',
01277 '.pgm' => 'image/x-portable-graymap',
01278 '.php' => 'application/x-httpd-php',
01279 '.phtml' => 'application/x-httpd-php',
01280 '.pl' => 'text/plain',
01281 '.png' => 'image/png',
01282 '.pnm' => 'image/x-portable-anymap',
01283 '.pot' => 'application/vnd.ms-powerpoint',
01284 '.ppa' => 'application/vnd.ms-powerpoint',
01285 '.ppm' => 'image/x-portable-pixmap',
01286 '.pps' => 'application/vnd.ms-powerpoint',
01287 '.ppt' => 'application/vnd.ms-powerpoint',
01288 '.ps' => 'application/postscript',
01289 '.psd' => 'image/psd',
01290 '.pwz' => 'application/vnd.ms-powerpoint',
01291 '.py' => 'text/x-python',
01292 '.pyc' => 'application/x-python-code',
01293 '.pyo' => 'application/x-python-code',
01294 '.qt' => 'video/quicktime',
01295 '.ra' => 'audio/x-pn-realaudio',
01296 '.ram' => 'application/x-pn-realaudio',
01297 '.ras' => 'image/x-cmu-raster',
01298 '.rdf' => 'application/xml',
01299 '.rgb' => 'image/x-rgb',
01300 '.roff' => 'application/x-troff',
01301 '.rpm' => 'audio/x-pn-realaudio-plugin',
01302 '.rtf' => 'application/rtf',
01303 '.rtx' => 'text/richtext',
01304 '.sgm' => 'text/x-sgml',
01305 '.sgml' => 'text/x-sgml',
01306 '.sh' => 'application/x-sh',
01307 '.shar' => 'application/x-shar',
01308 '.sit' => 'application/x-stuffit',
01309 '.snd' => 'audio/basic',
01310 '.so' => 'application/octet-stream',
01311 '.spc' => 'text/x-speech',
01312 '.src' => 'application/x-wais-source',
01313 '.sv4cpio'=> 'application/x-sv4cpio',
01314 '.sv4crc' => 'application/x-sv4crc',
01315 '.svg' => 'image/svg+xml',
01316 '.swf' => 'application/x-shockwave-flash',
01317 '.t' => 'application/x-troff',
01318 '.tar' => 'application/x-tar',
01319 '.talk' => 'text/x-speech',
01320 '.tbk' => 'application/toolbook',
01321 '.tcl' => 'application/x-tcl',
01322 '.tex' => 'application/x-tex',
01323 '.texi' => 'application/x-texinfo',
01324 '.texinfo'=> 'application/x-texinfo',
01325 '.tif' => 'image/tiff',
01326 '.tiff' => 'image/tiff',
01327 '.tr' => 'application/x-troff',
01328 '.tsv' => 'text/tab-separated-values',
01329 '.tsp' => 'application/dsptype',
01330 '.txt' => 'text/plain',
01331 '.ustar' => 'application',
01332 '.vcf' => 'text/x-vcard',
01333 '.vox' => 'audio/voxware',
01334 '.wav' => 'audio/x-wav',
01335 '.wax' => 'audio/x-ms-wax',
01336 '.wiz' => 'application/msword',
01337 '.wm' => 'video/x-ms-wm',
01338 '.wma' => 'audio/x-ms-wma',
01339 '.wmd' => 'video/x-ms-wmd',
01340 '.wml' => 'text/vnd.wap.wml',
01341 '.wmlc' => 'application/vnd.wap.wmlc',
01342 '.wmls' => 'text/vnd.wap.wmlscript',
01343 '.wmlsc' => 'application/vnd.wap.wmlscriptc',
01344 '.wmv' => 'video/x-ms-wmv',
01345 '.wmx' => 'video/x-ms-wmx',
01346 '.wmz' => 'video/x-ms-wmz',
01347 '.wvx' => 'video/x-ms-wvx',
01348 '.wrl' => 'x-world/x-vrml',
01349 '.xbm' => 'image/x-xbitmap',
01350 '.xla' => 'application/msexcel',
01351 '.xlb' => 'application/vnd.ms-excel',
01352 '.xls' => 'application/msexcel',
01353 '.xml' => 'text/xml',
01354 '.xpm' => 'image/x-xpixmap',
01355 '.xsl' => 'application/xml',
01356 '.xwd' => 'image/x-xwindowdump',
01357 '.zip' => 'application/zip');
01358
01359 return $types_map;
01360 }
01361
01362 function getDataDirectory()
01363 {
01364 return ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
01365 }
01366
01367
01372 function setEnabled ($value)
01373 {
01374 if (is_object($this->node))
01375 {
01376 $this->node->set_attribute("Enabled", $value);
01377 }
01378 }
01379
01380
01386 function isEnabled ()
01387 {
01388 if (is_object($this->node) && $this->node->has_attribute("Enabled"))
01389 {
01390 $compare = $this->node->get_attribute("Enabled");
01391 }
01392 else $compare = "True";
01393
01394 return $compare == "True";
01395 }
01396
01397
01401 function enable()
01402 {
01403 $this->setEnabled ("True");
01404 }
01405
01409 function disable()
01410 {
01411 $this->setEnabled ("False");
01412 }
01413
01417 function &_saveTempFileAsMediaObject($name, $tmp_name, $upload = TRUE)
01418 {
01419
01420 $media_object = new ilObjMediaObject();
01421 $media_object->setTitle($name);
01422 $media_object->setDescription("");
01423 $media_object->create();
01424
01425
01426 $media_object->createDirectory();
01427 $mob_dir = ilObjMediaObject::_getDirectory($media_object->getId());
01428
01429 $media_item =& new ilMediaItem();
01430 $media_object->addMediaItem($media_item);
01431 $media_item->setPurpose("Standard");
01432
01433 $file = $mob_dir."/".$name;
01434 if ($upload)
01435 {
01436 ilUtil::moveUploadedFile($tmp_name,$name, $file);
01437 }
01438 else
01439 {
01440 copy($tmp_name, $file);
01441 }
01442
01443 $format = ilObjMediaObject::getMimeType($file);
01444 $location = $name;
01445
01446 $media_item->setFormat($format);
01447 $media_item->setLocation($location);
01448 $media_item->setLocationType("LocalFile");
01449 $media_object->setTitle($name);
01450 $media_object->setDescription($format);
01451
01452 if (ilUtil::deducibleSize($format))
01453 {
01454 $size = getimagesize($file);
01455 $media_item->setWidth($size[0]);
01456 $media_item->setHeight($size[1]);
01457 }
01458 $media_item->setHAlign("Left");
01459
01460 ilUtil::renameExecutables($mob_dir);
01461 $media_object->update();
01462
01463 return $media_object;
01464 }
01465
01469 function getLinkedMediaObjects($a_ignore = "")
01470 {
01471 $linked = array();
01472
01473 if (!is_array($a_ignore))
01474 {
01475 $a_ignore = array();
01476 }
01477
01478
01479 $med_items = $this->getMediaItems();
01480
01481 foreach($med_items as $med_item)
01482 {
01483 $int_links = ilMapArea::_getIntLinks($med_item->getId());
01484 foreach ($int_links as $k => $int_link)
01485 {
01486 if ($int_link["Type"] == "MediaObject")
01487 {
01488 include_once("./Services/COPage/classes/class.ilInternalLink.php");
01489 $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
01490 if (ilObject::_exists($l_id))
01491 {
01492 if (!in_array($l_id, $linked) &&
01493 !in_array($l_id, $a_ignore))
01494 {
01495 $linked[] = $l_id;
01496 }
01497 }
01498 }
01499 }
01500 }
01501
01502 return $linked;
01503 }
01504 }
01505 ?>