diff --git a/components/ILIAS/COPage/PC/MediaObject/class.ilPCImageMapEditorGUI.php b/components/ILIAS/COPage/PC/MediaObject/class.ilPCImageMapEditorGUI.php index 3d07f07438a1..e4931f43b1ee 100755 --- a/components/ILIAS/COPage/PC/MediaObject/class.ilPCImageMapEditorGUI.php +++ b/components/ILIAS/COPage/PC/MediaObject/class.ilPCImageMapEditorGUI.php @@ -291,7 +291,7 @@ public function makeMapWorkCopy( bool $a_output_new_area = false, string $a_area_type = "", string $a_coords = "" - ): void { + ): ilMediaItem { // old for pc media object // $media_object = $this->media_object->getMediaItem("Standard"); $media_object = $this->content_obj->getMediaObject(); @@ -325,6 +325,8 @@ public function makeMapWorkCopy( $a_coords ); } + + return $st_item; } public function getAliasXML(): string diff --git a/components/ILIAS/COPage/classes/class.ilMediaAliasItem.php b/components/ILIAS/COPage/classes/class.ilMediaAliasItem.php index 653396b9b27f..e24910640991 100755 --- a/components/ILIAS/COPage/classes/class.ilMediaAliasItem.php +++ b/components/ILIAS/COPage/classes/class.ilMediaAliasItem.php @@ -874,7 +874,6 @@ public function makeMapWorkCopy( string $a_area_type, string $a_coords ): bool { - $a_st_item->copyOriginal(); $a_st_item->buildMapWorkImage(); // determine ratios (first see whether the instance has w/h defined) @@ -886,7 +885,7 @@ public function makeMapWorkCopy( $width = $a_st_item->getWidth(); $height = $a_st_item->getHeight(); } - $size = getimagesize($a_st_item->getMapWorkCopyName()); + $size = getimagesize($a_st_item->getOriginalSource()); $x_ratio = 1; if ($size[0] > 0 && $width > 0) { $x_ratio = $width / $size[0]; @@ -931,7 +930,6 @@ public function makeMapWorkCopy( ); } - $a_st_item->saveMapWorkImage(); return true; } diff --git a/components/ILIAS/MediaObjects/ImageMap/class.ImageMapGUIRequest.php b/components/ILIAS/MediaObjects/ImageMap/class.ImageMapGUIRequest.php index b4cc11dd070c..cc1be9bfcfff 100755 --- a/components/ILIAS/MediaObjects/ImageMap/class.ImageMapGUIRequest.php +++ b/components/ILIAS/MediaObjects/ImageMap/class.ImageMapGUIRequest.php @@ -138,4 +138,29 @@ public function getArea(): array { return $this->strArray("area"); } + + public function getOutEditProperty(): string + { + return $this->str("out_edit_property"); + } + + public function getOutAreaNr(): int + { + return $this->int("out_area_nr"); + } + + public function getOutOutputNewArea(): bool + { + return (bool) $this->int("out_output_new_area"); + } + + public function getOutAreaType(): string + { + return $this->str("out_area_type"); + } + + public function getOutCoords(): string + { + return $this->str("out_coords"); + } } diff --git a/components/ILIAS/MediaObjects/ImageMap/class.ilImageMapEditorGUI.php b/components/ILIAS/MediaObjects/ImageMap/class.ilImageMapEditorGUI.php index 423237634994..6d6b0c15ee14 100755 --- a/components/ILIAS/MediaObjects/ImageMap/class.ilImageMapEditorGUI.php +++ b/components/ILIAS/MediaObjects/ImageMap/class.ilImageMapEditorGUI.php @@ -184,7 +184,15 @@ public function handleMapParameters(): void public function showImageMap(): void { - $item = new ilMediaItem($this->request->getItemId()); + $item = $this->makeMapWorkCopy( + $this->request->getOutEditProperty(), + $this->request->getOutAreaNr(), + $this->request->getOutOutputNewArea(), + $this->request->getOutAreaType(), + $this->request->getOutCoords() + ); + + //$item = new ilMediaItem($this->request->getItemId()); $item->outputMapWorkCopy(); } @@ -400,19 +408,18 @@ public function editMapArea( $this->tpl->setVariable("FORM", $form->getHTML()); } - $this->makeMapWorkCopy( - $a_edit_property, - $a_area_nr, - $a_output_new_area, - $area_type, - $coords - ); + $ilCtrl->setParameter($this, "out_edit_property", $a_edit_property); + $ilCtrl->setParameter($this, "out_area_nr", $a_area_nr); + $ilCtrl->setParameter($this, "out_output_new_area", (int) $a_output_new_area); + $ilCtrl->setParameter($this, "out_area_type", $area_type); + $ilCtrl->setParameter($this, "out_coords", $coords); $edit_mode = ($a_get_next_coordinate) ? "get_coords" : (($a_output_new_area) ? "new_area" : ""); + $output = $this->getImageMapOutput($edit_mode); $this->tpl->setVariable("IMAGE_MAP", $output); @@ -512,7 +519,7 @@ public function makeMapWorkCopy( bool $a_output_new_area = false, string $a_area_type = "", string $a_coords = "" - ): void { + ): ilMediaItem { // create/update imagemap work copy $st_item = $this->media_object->getMediaItem("Standard"); @@ -525,6 +532,8 @@ public function makeMapWorkCopy( if ($a_output_new_area) { $st_item->addAreaToMapWorkCopy($a_area_type, $a_coords); } + + return $st_item; } /** diff --git a/components/ILIAS/MediaObjects/classes/class.ilMediaItem.php b/components/ILIAS/MediaObjects/classes/class.ilMediaItem.php index 9fccf113f388..76626225f32b 100755 --- a/components/ILIAS/MediaObjects/classes/class.ilMediaItem.php +++ b/components/ILIAS/MediaObjects/classes/class.ilMediaItem.php @@ -23,6 +23,7 @@ */ class ilMediaItem { + protected \ILIAS\MediaObjects\MediaObjectManager $mob_manager; protected string $tried_thumb = ""; protected string $text_representation = ""; protected ilDBInterface $db; @@ -68,6 +69,7 @@ public function __construct( $this->setId($a_id); $this->read(); } + $this->mob_manager = $DIC->mediaObjects()->internal()->domain()->mediaObject(); } /** @@ -610,14 +612,8 @@ public function setHeight(string $a_height): void public function getOriginalSize(): ?array { - $mob_dir = ilObjMediaObject::_getDirectory($this->getMobId()); - if (ilUtil::deducibleSize($this->getFormat())) { - if ($this->getLocationType() == "LocalFile") { - $loc = $mob_dir . "/" . $this->getLocation(); - } else { - $loc = $this->getLocation(); - } + $loc = $this->getOriginalSize(); $size = ilMediaImageUtil::getImageSize($loc); if ($size[0] > 0 && $size[1] > 0) { @@ -724,28 +720,6 @@ public function getParameter(string $a_name): string return (string) ($this->parameters[$a_name] ?? ""); } - /** - * get work directory for image map editing - */ - public function getWorkDirectory(): string - { - return ilFileUtils::getDataDir() . "/map_workfiles/item_" . $this->getId(); - } - - /** - * create work directory for image map editing - */ - public function createWorkDirectory(): void - { - if (!is_dir(ilFileUtils::getDataDir() . "/map_workfiles")) { - ilFileUtils::createDirectory(ilFileUtils::getDataDir() . "/map_workfiles"); - } - $work_dir = $this->getWorkDirectory(); - if (!is_dir($work_dir)) { - ilFileUtils::createDirectory($work_dir); - } - } - /** * get location suffix */ @@ -764,26 +738,6 @@ public function getMapWorkCopyType(): string return self::getGDSupportedImageType($this->getSuffix()); } - /** - * Get name of image map work copy file - * @param bool $a_reference_copy get name for copy of external referenced image - */ - public function getMapWorkCopyName( - bool $a_reference_copy = false - ): string { - $file_arr = explode("/", $this->getLocation()); - $o_file = $file_arr[count($file_arr) - 1]; - $file_arr = explode(".", $o_file); - unset($file_arr[count($file_arr) - 1]); - $file = implode(".", $file_arr); - - if (!$a_reference_copy) { - return $this->getWorkDirectory() . "/" . $file . "." . $this->getMapWorkCopyType(); - } else { - return $this->getWorkDirectory() . "/l_copy_" . $o_file; - } - } - /** * get media file directory */ @@ -857,51 +811,15 @@ public function getThumbnailTarget( return ""; } - /** - * Copy the original file for map editing - * to the working directory - * @throws ilMapEditingException - */ - public function copyOriginal(): void + public function getOriginalSource(): string { - $lng = $this->lng; - $this->createWorkDirectory(); - if ($this->getLocationType() !== "Reference") { - $this->image_converter->convertToFormat( - $this->getDirectory() . "/" . $this->getLocation(), - $this->getMapWorkCopyName(), - $this->getMapWorkCopyType(), - $this->getWidth() === '' ? null : $this->getWidth(), - $this->getHeight() === '' ? null : $this->getHeight() + return $this->mob_manager->getLocalSrc( + $this->getMobId(), + $this->getLocation() ); - } else { - // first copy the external file, if necessary - if (!is_file($this->getMapWorkCopyName(true)) || (filesize($this->getMapWorkCopyName(true)) == 0)) { - $handle = fopen($this->getLocation(), "r"); - $lcopy = fopen($this->getMapWorkCopyName(true), "w"); - if ($handle && $lcopy) { - while (!feof($handle)) { - $content = fread($handle, 4096); - fwrite($lcopy, $content); - } - } - fclose($lcopy); - fclose($handle); - } - - // now, create working copy - $this->image_converter->convertToFormat( - $this->getMapWorkCopyName(true), - $this->getMapWorkCopyName(), - $this->getMapWorkCopyType(), - $this->getWidth() === '' ? null : $this->getWidth(), - $this->getHeight() === '' ? null : $this->getHeight() - ); - } - if (!is_file($this->getMapWorkCopyName())) { - throw new ilMapEditingException($lng->txt("cont_map_file_not_generated")); } + return $this->getLocation(); } /** @@ -913,13 +831,10 @@ public function makeMapWorkCopy( int $a_area_nr = 0, bool $a_exclude = false ): void { - $lng = $this->lng; - - $this->copyOriginal(); $this->buildMapWorkImage(); // determine ratios - $size = getimagesize($this->getMapWorkCopyName()); + $size = getimagesize($this->getOriginalSource()); $x_ratio = 1; if ($size[0] > 0 && $this->getWidth() > 0) { $x_ratio = $this->getWidth() / $size[0]; @@ -946,8 +861,6 @@ public function makeMapWorkCopy( ); } } - - $this->saveMapWorkImage(); } /** @@ -959,10 +872,10 @@ public function addAreaToMapWorkCopy( string $a_shape, string $a_coords ): void { - $this->buildMapWorkImage(); + // $this->buildMapWorkImage(); // determine ratios - $size = getimagesize($this->getMapWorkCopyName()); + $size = getimagesize($this->getOriginalSource()); $x_ratio = 1; if ($size[0] > 0 && $this->getWidth() > 0) { $x_ratio = $this->getWidth() / $size[0]; @@ -984,8 +897,6 @@ public function addAreaToMapWorkCopy( $x_ratio, $y_ratio ); - - $this->saveMapWorkImage(); } /** @@ -997,7 +908,7 @@ public function outputMapWorkCopy(): void header("Pragma: no-cache"); header("Expires: 0"); header("Content-type: image/" . strtolower($this->getMapWorkCopyType())); - readfile($this->getMapWorkCopyName()); + $this->outputWorkImage(); } exit; } @@ -1011,16 +922,16 @@ public function buildMapWorkImage(): void switch ($im_type) { case "gif": - $this->map_image = imagecreatefromgif($this->getMapWorkCopyName()); + $this->map_image = imagecreatefromgif($this->getOriginalSource()); break; case "jpg": case "jpeg": - $this->map_image = imagecreatefromjpeg($this->getMapWorkCopyName()); + $this->map_image = imagecreatefromjpeg($this->getOriginalSource()); break; case "png": - $this->map_image = imagecreatefrompng($this->getMapWorkCopyName()); + $this->map_image = imagecreatefrompng($this->getOriginalSource()); break; } @@ -1034,30 +945,25 @@ public function buildMapWorkImage(): void } } - /** - * save image map work image as file - */ - public function saveMapWorkImage(): void + public function outputWorkImage(): void { $im_type = strtolower($this->getMapWorkCopyType()); // save image work-copy and free memory switch ($im_type) { case "gif": - imagegif($this->map_image, $this->getMapWorkCopyName()); + imagegif($this->map_image); break; case "jpg": case "jpeg": - imagejpeg($this->map_image, $this->getMapWorkCopyName()); + imagejpeg($this->map_image); break; case "png": - imagepng($this->map_image, $this->getMapWorkCopyName()); + imagepng($this->map_image); break; } - - imagedestroy($this->map_image); } /**