63 $this->db =
$DIC->database();
64 $this->
lng = $DIC->language();
65 $this->image_converter =
$DIC->fileConverters()->legacyImages();
67 $this->mapareas = array();
74 $this->mob_manager =
$DIC->mediaObjects()->internal()->domain()->mediaObject();
80 public function setId(
int $a_id): void
95 $this->mob_id = $a_mob_id;
106 public function setNr(
int $a_nr): void
125 $a_desired_type = strtolower($a_desired_type);
127 $im_types = ImageTypes();
129 switch ($a_desired_type) {
132 if ($im_types & IMG_JPG) {
135 if ($im_types & IMG_GIF) {
138 if ($im_types & IMG_PNG) {
144 if ($im_types & IMG_GIF) {
147 if ($im_types & IMG_JPG) {
150 if ($im_types & IMG_PNG) {
157 if ($im_types & IMG_PNG) {
160 if ($im_types & IMG_JPG) {
163 if ($im_types & IMG_GIF) {
174 $this->duration = $a_val;
184 $this->text_representation = $a_val;
194 $this->upload_hash = $a_val;
206 $item_id =
$ilDB->nextId(
"media_item");
207 $query =
"INSERT INTO media_item (id,mob_id, purpose, location, " .
208 "location_type, format, width, " .
209 "height, halign, caption, nr, text_representation, upload_hash, duration) VALUES " .
211 $ilDB->quote($item_id,
"integer") .
"," .
221 $ilDB->quote($this->
getNr(),
"integer") .
"," .
226 $ilDB->manipulate($query);
228 $this->
setId($item_id);
232 foreach (
$params as $name => $value) {
233 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
234 "(" .
$ilDB->quote($item_id,
"integer") .
"," .
235 $ilDB->quote($name,
"text") .
"," .
236 $ilDB->quote($value,
"text") .
")";
237 $ilDB->manipulate($query);
241 for ($i = 0; $i < count($this->mapareas); $i++) {
242 if (is_object($this->mapareas[$i])) {
243 $this->mapareas[$i]->setItemId($this->
getId());
244 $this->mapareas[$i]->setNr($i + 1);
245 $this->mapareas[$i]->create();
254 $query =
"UPDATE media_item SET " .
255 " mob_id = " .
$ilDB->quote($this->
getMobId(),
"integer") .
"," .
260 " width = " .
$ilDB->quote($this->
getWidth(),
"text") .
"," .
264 " nr = " .
$ilDB->quote($this->
getNr(),
"integer") .
"," .
268 " WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
269 $ilDB->manipulate($query);
272 $query =
"DELETE FROM mob_parameter WHERE med_item_id = " .
274 $ilDB->manipulate($query);
278 foreach (
$params as $name => $value) {
279 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
280 "(" .
$ilDB->quote($this->
getId(),
"integer") .
"," .
281 $ilDB->quote($name,
"text") .
"," .
282 $ilDB->quote($value,
"text") .
")";
283 $ilDB->manipulate($query);
293 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
294 "(" .
$ilDB->quote($this->
getId(),
"integer") .
"," .
295 $ilDB->quote($a_name,
"text") .
"," .
296 $ilDB->quote($a_value,
"text") .
")";
297 $ilDB->manipulate($query);
307 $item_id = $this->
getId();
308 $mob_id = $this->getMobId();
309 $nr = $this->getNr();
312 $query =
"SELECT * FROM media_item WHERE id = " .
314 } elseif ($mob_id > 0 && $nr > 0) {
315 $query =
"SELECT * FROM media_item WHERE mob_id = " .
316 $ilDB->quote($this->getMobId(),
"integer") .
" " .
317 "AND nr=" .
$ilDB->quote($this->getNr(),
"integer");
320 $item_set =
$ilDB->query($query);
321 $item_rec =
$ilDB->fetchAssoc($item_set);
323 $this->setLocation((
string) $item_rec[
"location"]);
324 $this->setLocationType((
string) $item_rec[
"location_type"]);
325 $this->setFormat((
string) $item_rec[
"format"]);
326 $this->setWidth((
string) $item_rec[
"width"]);
327 $this->setHeight((
string) $item_rec[
"height"]);
328 $this->setHAlign((
string) $item_rec[
"halign"]);
329 $this->setCaption((
string) $item_rec[
"caption"]);
330 $this->setPurpose((
string) $item_rec[
"purpose"]);
331 $this->setNr((
int) $item_rec[
"nr"]);
332 $this->setMobId((
int) $item_rec[
"mob_id"]);
333 $this->setId((
int) $item_rec[
"id"]);
334 $this->setThumbTried((
string) $item_rec[
"tried_thumb"]);
335 $this->setTextRepresentation((
string) $item_rec[
"text_representation"]);
336 $this->setUploadHash((
string) $item_rec[
"upload_hash"]);
337 $this->setDuration((
int) $item_rec[
"duration"]);
340 $query =
"SELECT * FROM mob_parameter WHERE med_item_id = " .
342 $par_set =
$ilDB->query($query);
343 while ($par_rec =
$ilDB->fetchAssoc($par_set)) {
344 $this->setParameter($par_rec[
"name"], $par_rec[
"value"]);
349 for ($i = 1; $i <= $max; $i++) {
351 $this->addMapArea($area);
363 $q =
"UPDATE media_item SET tried_thumb = " .
364 $ilDB->quote($a_tried,
"text") .
365 " WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
379 $query =
"SELECT * FROM media_item WHERE mob_id = " .
380 $ilDB->quote($a_mob_id,
"integer") .
" " .
381 "AND purpose = " .
$ilDB->quote($a_purpose,
"text");
382 $set =
$ilDB->query($query);
383 if ($rec =
$ilDB->fetchAssoc($set)) {
384 return $rec[
"location"];
398 $query =
"SELECT * FROM media_item WHERE id = " .
399 $ilDB->quote($a_med_id,
"integer");
400 $set =
$ilDB->query($query);
401 if ($rec =
$ilDB->fetchAssoc($set)) {
402 return (
int) $rec[
"mob_id"];
423 $query =
"SELECT * FROM media_item WHERE mob_id = " .
424 $ilDB->quote($a_mobId,
"integer") .
" " .
425 "AND purpose=" .
$ilDB->quote($a_purpose,
"text") .
" ORDER BY nr";
426 $item_set =
$ilDB->query($query);
428 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
445 $query =
"SELECT * FROM media_item WHERE mob_id = " .
446 $ilDB->quote($a_mob->
getId(),
"integer") .
" " .
448 $item_set =
$ilDB->query($query);
449 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
451 $media_item->setNr((
int) $item_rec[
"nr"]);
452 $media_item->setId((
int) $item_rec[
"id"]);
453 $media_item->setLocation((
string) $item_rec[
"location"]);
454 $media_item->setLocationType((
string) $item_rec[
"location_type"]);
455 $media_item->setFormat((
string) $item_rec[
"format"]);
456 $media_item->setWidth((
string) $item_rec[
"width"]);
457 $media_item->setHeight((
string) $item_rec[
"height"]);
458 $media_item->setHAlign((
string) $item_rec[
"halign"]);
459 $media_item->setCaption((
string) $item_rec[
"caption"]);
460 $media_item->setPurpose((
string) $item_rec[
"purpose"]);
461 $media_item->setMobId((
int) $item_rec[
"mob_id"]);
462 $media_item->setThumbTried((
string) $item_rec[
"tried_thumb"]);
463 $media_item->setTextRepresentation((
string) $item_rec[
"text_representation"]);
464 $media_item->setUploadHash((
string) $item_rec[
"upload_hash"]);
465 $media_item->setDuration((
int) $item_rec[
"duration"]);
468 $query =
"SELECT * FROM mob_parameter WHERE med_item_id = " .
469 $ilDB->quote($item_rec[
"id"],
"integer");
470 $par_set =
$ilDB->query($query);
471 while ($par_rec =
$ilDB->fetchAssoc($par_set)) {
472 $media_item->setParameter($par_rec[
"name"], $par_rec[
"value"]);
477 for ($i = 1; $i <= $max; $i++) {
478 $area =
new ilMapArea($media_item->getId(), $i);
479 $media_item->addMapArea($area);
494 $query =
"SELECT * FROM media_item WHERE mob_id = " .
495 $ilDB->quote($a_mob_id,
"integer");
496 $item_set =
$ilDB->query($query);
497 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
499 $query =
"DELETE FROM mob_parameter WHERE med_item_id = " .
500 $ilDB->quote($item_rec[
"id"],
"integer");
501 $ilDB->manipulate($query);
504 $query =
"DELETE FROM map_area WHERE item_id = " .
505 $ilDB->quote($item_rec[
"id"],
"integer");
506 $ilDB->manipulate($query);
510 $query =
"DELETE FROM media_item WHERE mob_id = " .
511 $ilDB->quote($a_mob_id,
"integer");
512 $ilDB->manipulate($query);
517 $this->purpose = $a_purpose;
522 return $this->purpose;
527 $this->location = $a_location;
537 $this->location_type = $a_type;
542 return $this->location_type;
547 $this->format = $a_format;
552 return $this->format;
557 $this->tried_thumb = $a_tried;
562 return $this->tried_thumb;
567 $this->mapareas[$this->map_cnt] = $a_map_area;
573 for ($i = 1; $i <= $this->map_cnt; $i++) {
575 $this->mapareas[$i - 2] = $this->mapareas[$i - 1];
576 $this->mapareas[$i - 2]->setNr($i - 1);
579 if ($nr <= $this->map_cnt) {
580 unset($this->mapareas[$this->map_cnt - 1]);
587 return $this->mapareas[$nr - 1] ??
null;
592 return $this->mapareas;
602 $this->width = $a_width;
607 return $this->height;
612 $this->height = $a_height;
618 $loc = $this->getOriginalSource();
620 if ($size[0] > 0 && $size[1] > 0) {
621 return array(
"width" => $size[0],
"height" => $size[1]);
630 $this->caption = $a_caption;
635 return $this->caption;
643 $this->halign = $a_halign;
648 return $this->halign;
655 if (self::checkParameter($a_name, $a_value)) {
670 $this->resetParameters();
672 if (is_array($par_arr)) {
673 foreach ($par_arr as $par => $val) {
674 $this->setParameter($par, $val);
687 if (substr(strtolower(trim($a_par)), 0, 2) ==
"on") {
691 if (is_int(strpos(strtolower($a_val),
"javascript"))) {
695 if (strtolower(trim($a_par)) ==
"src") {
704 return $this->parameters;
712 $target_arr[] =
"$par=\"$val\"";
714 return implode(
", ", $target_arr);
721 return (
string) ($this->
parameters[$a_name] ??
"");
729 $loc_arr = explode(
".", $this->getLocation());
731 return $loc_arr[count($loc_arr) - 1];
739 return self::getGDSupportedImageType($this->getSuffix());
753 if ($this->getLocationType() !==
"Reference") {
754 return $this->mob_manager->getLocalSrc(
759 return $this->getLocation();
769 bool $a_exclude =
false
771 $this->buildMapWorkImage();
774 $size = getimagesize($this->getOriginalSource());
776 if ($size[0] > 0 && $this->getWidth() > 0) {
777 $x_ratio = $this->getWidth() / $size[0];
780 if ($size[1] > 0 && $this->getHeight() > 0) {
781 $y_ratio = $this->getHeight() / $size[1];
785 for ($i = 0; $i < count($this->mapareas); $i++) {
786 if (((($i + 1) == $a_area_nr) && !$a_exclude) ||
787 ((($i + 1) != $a_area_nr) && $a_exclude) ||
790 $area = $this->mapareas[$i];
792 $this->getMapWorkImage(),
815 $size = getimagesize($this->getOriginalSource());
817 if ($size[0] > 0 && $this->getWidth() > 0) {
818 $x_ratio = $this->getWidth() / $size[0];
821 if ($size[1] > 0 && $this->getHeight() > 0) {
822 $y_ratio = $this->getHeight() / $size[1];
827 $area->setShape($a_shape);
828 $area->setCoords($a_coords);
830 $this->getMapWorkImage(),
844 if ($this->getMapWorkCopyType() !=
"") {
845 header(
"Pragma: no-cache");
847 header(
"Content-type: image/" . strtolower($this->getMapWorkCopyType()));
848 $this->outputWorkImage();
858 $im_type = strtolower($this->getMapWorkCopyType());
862 $this->map_image = imagecreatefromgif($this->getOriginalSource());
867 $this->map_image = imagecreatefromjpeg($this->getOriginalSource());
871 $this->map_image = imagecreatefrompng($this->getOriginalSource());
876 if (imagecolorstotal($this->map_image) > 250) {
877 $this->color1 = imagecolorclosest($this->map_image, 0, 0, 0);
878 $this->color2 = imagecolorclosest($this->map_image, 255, 255, 255);
880 $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
881 $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
887 $im_type = strtolower($this->getMapWorkCopyType());
892 imagegif($this->map_image);
897 imagejpeg($this->map_image);
901 imagepng($this->map_image);
911 return $this->map_image;
918 bool $a_insert_inst =
false,
924 for ($i = 0; $i < count($this->mapareas); $i++) {
925 $area = $this->mapareas[$i];
929 if ($area->getHighlightMode() !=
"") {
930 $hm =
' HighlightMode="' . $area->getHighlightMode() .
'" ';
931 $hcl = ($area->getHighlightClass() !=
"")
932 ? $area->getHighlightClass()
934 $hm .=
'HighlightClass="' . $hcl .
'" ';
937 $xml .=
"<MapArea Shape=\"" . $area->getShape() .
"\" Coords=\"" . $area->getCoords() .
"\" " . $hm .
">";
939 $target_frame = $area->getTargetFrame();
941 if ($area->getType() ==
"GlossaryItem" && $target_frame ==
"") {
942 $target_frame =
"Glossary";
945 $tf_str = ($target_frame ==
"")
947 :
"TargetFrame=\"" . $target_frame .
"\"";
949 $xml .=
"<IntLink Target=\"" . $area->getTarget($a_insert_inst, $a_inst) .
"\" Type=\"" .
950 $area->getType() .
"\" $tf_str>";
952 $xml .= htmlspecialchars($area->getTitle(), ENT_QUOTES);
953 $xml .=
"</IntLink>";
955 $xml .=
"<ExtLink Href=\"" . str_replace(
"&",
"&", $area->getHref()) .
"\" Title=\"" .
956 str_replace(
"&",
"&", $area->getExtTitle()) .
"\">";
957 $xml .= str_replace(
"&",
"&", $area->getTitle());
958 $xml .=
"</ExtLink>";
960 $xml .=
"</MapArea>";
978 $query =
"SELECT * FROM media_item WHERE mob_id = " .
979 $ilDB->quote($a_mob_id,
"integer") .
" " .
981 $item_set =
$ilDB->query($query);
982 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
999 $query =
"SELECT * FROM media_item WHERE mob_id = " .
1000 $ilDB->quote($a_mob_id,
"integer") .
" ORDER BY nr";
1002 $item_set =
$ilDB->query($query);
1004 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
1006 foreach ($map_links as $key => $map_link) {
1007 $links[$key] = $map_link;
1019 $this->getLocation(),
1020 $this->getParameters()
1022 foreach ($par as $k => $v) {
1023 $this->setParameter($k, $v);
1034 if ($meta[
"duration"] > 0) {
1035 $this->setDuration((
int) $meta[
"duration"]);
1038 $file = $this->getLocationSrc();
1041 if (str_starts_with($file,
'http')) {
1047 $localtempfilename = tempnam($tmpdir,
'getID3');
1048 $fp_local = fopen($localtempfilename,
'wb');
1050 $mob_logger->debug(
'Determining duration of file: {file}', [
1056 $curl->setOpt(CURLOPT_VERBOSE,
true);
1057 $curl->setOpt(CURLOPT_FILE, $fp_local);
1058 $curl->setOpt(CURLOPT_FOLLOWLOCATION,
true);
1059 $curl->setOpt(CURLOPT_TIMEOUT_MS, 600000);
1060 $curl->setOpt(CURLOPT_TIMEOUT, 600);
1061 $curl->setOpt(CURLOPT_FAILONERROR,
true);
1062 $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 1);
1063 $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
1065 $success = $curl->exec();
1066 $info = $curl->getInfo();
1068 $mob_logger->debug(
'cURL Info: {info}', [
1069 'info' => print_r(
$info,
true)
1073 $mob_logger->debug(
'Successfully downloaded remote file: {file}', [
1077 $file = $localtempfilename;
1079 $mob_logger->error(
'Could not fetch file: {file}', [
1083 }
catch (Exception
$e) {
1084 $mob_logger->error(
'Could not determine duration: {message}', [
1085 'message' =>
$e->getMessage(),
1087 $mob_logger->error(
$e->getTraceAsString());
1091 $ana->setFile($file);
1092 $ana->analyzeFile();
1093 $this->setDuration($ana->getPlaytimeSeconds());
1094 }
catch (Exception) {
1101 if (strcasecmp(
"Reference", $this->getLocationType()) === 0) {
1102 $src = $this->getLocation();
1103 if ($this->getFormat() ===
"video/vimeo") {
1106 $params =
"&autoplay=1&muted=1";
1109 $src =
"//player.vimeo.com/video/" . $par[
"id"] .
"?api=1" .
$params;
1111 if ($this->getFormat() ===
"video/youtube") {
1114 $params =
"&autoplay=1&muted=1";
1117 $src =
"//www.youtube.com/embed/" . $par[
"v"] .
"?enablejsapi=1" .
$params;
1120 $src = $this->mob_manager->getLocalSrc(
1122 $this->getLocation()
1130 return $this->mob_manager->getLocationStream(
1132 $this->getLocation()
1146 $db =
$DIC->database();
1149 "SELECT * FROM media_item " .
1150 " WHERE upload_hash = %s ",
1154 $media_items = array();
1156 $media_items[] = $rec;
1158 return $media_items;
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static getLogger(string $a_component_id)
Get component logger.
static _resolveIntLinks(int $a_item_id)
resolve internal links of an item id
static _getMaxNr(int $a_item_id)
get maximum nr of media item (static)
static _getIntLinks(int $a_item_id)
get all internal links of a media items map areas
static deducibleSize(string $a_mime)
checks if mime type is provided by getimagesize()
static extractParameterString(string $a_parstr)
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
if(!file_exists('../ilias.ini.php'))