ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMediaItem.php
Go to the documentation of this file.
1<?php
2
20
27{
28 protected \ILIAS\MediaObjects\MediaObjectManager $mob_manager;
29 protected string $tried_thumb = "";
30 protected string $text_representation = "";
31 protected ilDBInterface $db;
32 protected ilLanguage $lng;
33 protected \ILIAS\Filesystem\Util\Convert\LegacyImages $image_converter;
34
35 public int $id = 0;
36 public string $purpose = "";
37 public string $location = "";
38 public string $location_type = "";
39 public string $format = "";
40 public string $width = "";
41 public string $height = "";
42 public string $caption = "";
43 public string $halign = "";
44 public array $parameters = [];
45 public int $mob_id = 0;
46 public int $nr = 0;
47 public array $mapareas = [];
48 public int $map_cnt = 0;
52 public $map_image = null; // image map work copy image
53 public int $color1; // map area line color 1
54 public int $color2; // map area line color 2
55 protected int $duration = 0;
56 protected string $upload_hash = '';
57
58 public function __construct(
59 int $a_id = 0
60 ) {
61 global $DIC;
62
63 $this->db = $DIC->database();
64 $this->lng = $DIC->language();
65 $this->image_converter = $DIC->fileConverters()->legacyImages();
66 $this->parameters = array();
67 $this->mapareas = array();
68 $this->map_cnt = 0;
69
70 if ($a_id != 0) {
71 $this->setId($a_id);
72 $this->read();
73 }
74 $this->mob_manager = $DIC->mediaObjects()->internal()->domain()->mediaObject();
75 }
76
80 public function setId(int $a_id): void
81 {
82 $this->id = $a_id;
83 }
84
85 public function getId(): int
86 {
87 return $this->id;
88 }
89
93 public function setMobId(int $a_mob_id): void
94 {
95 $this->mob_id = $a_mob_id;
96 }
97
98 public function getMobId(): int
99 {
100 return $this->mob_id;
101 }
102
106 public function setNr(int $a_nr): void
107 {
108 $this->nr = $a_nr;
109 }
110
111 public function getNr(): int
112 {
113 return $this->nr;
114 }
115
123 private static function getGDSupportedImageType(string $a_desired_type): string
124 {
125 $a_desired_type = strtolower($a_desired_type);
126 // get supported Image Types
127 $im_types = ImageTypes();
128
129 switch ($a_desired_type) {
130 case "jpg":
131 case "jpeg":
132 if ($im_types & IMG_JPG) {
133 return "jpg";
134 }
135 if ($im_types & IMG_GIF) {
136 return "gif";
137 }
138 if ($im_types & IMG_PNG) {
139 return "png";
140 }
141 break;
142
143 case "gif":
144 if ($im_types & IMG_GIF) {
145 return "gif";
146 }
147 if ($im_types & IMG_JPG) {
148 return "jpg";
149 }
150 if ($im_types & IMG_PNG) {
151 return "png";
152 }
153 break;
154
155 case "svg":
156 case "png":
157 if ($im_types & IMG_PNG) {
158 return "png";
159 }
160 if ($im_types & IMG_JPG) {
161 return "jpg";
162 }
163 if ($im_types & IMG_GIF) {
164 return "gif";
165 }
166 break;
167 }
168
169 return "";
170 }
171
172 public function setDuration(int $a_val): void
173 {
174 $this->duration = $a_val;
175 }
176
177 public function getDuration(): int
178 {
179 return $this->duration;
180 }
181
182 public function setTextRepresentation(string $a_val): void
183 {
184 $this->text_representation = $a_val;
185 }
186
187 public function getTextRepresentation(): string
188 {
190 }
191
192 public function setUploadHash(string $a_val): void
193 {
194 $this->upload_hash = $a_val;
195 }
196
197 public function getUploadHash(): string
198 {
199 return $this->upload_hash;
200 }
201
202 public function create(): void
203 {
205
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 " .
210 "(" .
211 $ilDB->quote($item_id, "integer") . "," .
212 $ilDB->quote($this->getMobId(), "integer") . "," .
213 $ilDB->quote($this->getPurpose(), "text") . "," .
214 $ilDB->quote($this->getLocation(), "text") . "," .
215 $ilDB->quote($this->getLocationType(), "text") . "," .
216 $ilDB->quote($this->getFormat(), "text") . "," .
217 $ilDB->quote($this->getWidth(), "text") . "," .
218 $ilDB->quote($this->getHeight(), "text") . "," .
219 $ilDB->quote($this->getHAlign(), "text") . "," .
220 $ilDB->quote($this->getCaption(), "text") . "," .
221 $ilDB->quote($this->getNr(), "integer") . "," .
222 $ilDB->quote($this->getTextRepresentation(), "text") . "," .
223 $ilDB->quote($this->getUploadHash(), "text") . "," .
224 $ilDB->quote($this->getDuration(), "integer") .
225 ")";
226 $ilDB->manipulate($query);
227
228 $this->setId($item_id);
229
230 // create mob parameters
231 $params = $this->getParameters();
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);
238 }
239
240 // create map areas
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();
246 }
247 }
248 }
249
250 public function update(): void
251 {
253
254 $query = "UPDATE media_item SET " .
255 " mob_id = " . $ilDB->quote($this->getMobId(), "integer") . "," .
256 " purpose = " . $ilDB->quote($this->getPurpose(), "text") . "," .
257 " location = " . $ilDB->quote($this->getLocation(), "text") . "," .
258 " location_type = " . $ilDB->quote($this->getLocationType(), "text") . "," .
259 " format = " . $ilDB->quote($this->getFormat(), "text") . "," .
260 " width = " . $ilDB->quote($this->getWidth(), "text") . "," .
261 " height = " . $ilDB->quote($this->getHeight(), "text") . "," .
262 " halign = " . $ilDB->quote($this->getHAlign(), "text") . "," .
263 " caption = " . $ilDB->quote($this->getCaption(), "text") . "," .
264 " nr = " . $ilDB->quote($this->getNr(), "integer") . "," .
265 " text_representation = " . $ilDB->quote($this->getTextRepresentation(), "text") . "," .
266 " upload_hash = " . $ilDB->quote($this->getUploadHash(), "text") . "," .
267 " duration = " . $ilDB->quote($this->getDuration(), "integer") .
268 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
269 $ilDB->manipulate($query);
270
271 // delete mob parameters
272 $query = "DELETE FROM mob_parameter WHERE med_item_id = " .
273 $ilDB->quote($this->getId(), "integer");
274 $ilDB->manipulate($query);
275
276 // create mob parameters
277 $params = $this->getParameters();
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);
284 }
285 }
286
287 public function writeParameter(
288 string $a_name,
289 string $a_value
290 ): void {
291 $ilDB = $this->db;
292
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);
298 }
299
303 public function read(): void
304 {
305 $ilDB = $this->db;
306
307 $item_id = $this->getId();
308 $mob_id = $this->getMobId();
309 $nr = $this->getNr();
310 $query = "";
311 if ($item_id > 0) {
312 $query = "SELECT * FROM media_item WHERE id = " .
313 $ilDB->quote($this->getId(), "integer");
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");
318 }
319 if ($query != "") {
320 $item_set = $ilDB->query($query);
321 $item_rec = $ilDB->fetchAssoc($item_set);
322
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"]);
338
339 // get item parameter
340 $query = "SELECT * FROM mob_parameter WHERE med_item_id = " .
341 $ilDB->quote($this->getId(), "integer");
342 $par_set = $ilDB->query($query);
343 while ($par_rec = $ilDB->fetchAssoc($par_set)) {
344 $this->setParameter($par_rec["name"], $par_rec["value"]);
345 }
346
347 // get item map areas
348 $max = ilMapArea::_getMaxNr($this->getId());
349 for ($i = 1; $i <= $max; $i++) {
350 $area = new ilMapArea($this->getId(), $i);
351 $this->addMapArea($area);
352 }
353 }
354 }
355
359 public function writeThumbTried(string $a_tried): void
360 {
361 $ilDB = $this->db;
362
363 $q = "UPDATE media_item SET tried_thumb = " .
364 $ilDB->quote($a_tried, "text") .
365 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
366
367 $ilDB->manipulate($q);
368 }
369
370 public static function _lookupLocationForMobId(
371 int $a_mob_id,
372 string $a_purpose
373 ): string {
374 global $DIC;
375
376 $ilDB = $DIC->database();
377
378 // read media_object record
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"];
385 }
386
387 return "";
388 }
389
390 public static function _lookupMobId(
391 int $a_med_id
392 ): int {
393 global $DIC;
394
395 $ilDB = $DIC->database();
396
397 // read media_object record
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"];
403 }
404
405 return 0;
406 }
407
414 public static function _getMediaItemsOfMObId(
415 int $a_mobId,
416 string $a_purpose
417 ): ?array {
418 global $DIC;
419
420 $ilDB = $DIC->database();
421
422 // read media_object record
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);
427
428 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
429 return $item_rec;
430 }
431 return null;
432 }
433
437 public static function _getMediaItemsOfMOb(
438 ilObjMediaObject $a_mob
439 ): void {
440 global $DIC;
441
442 $ilDB = $DIC->database();
443
444 // read media_object record
445 $query = "SELECT * FROM media_item WHERE mob_id = " .
446 $ilDB->quote($a_mob->getId(), "integer") . " " .
447 "ORDER BY nr";
448 $item_set = $ilDB->query($query);
449 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
450 $media_item = new ilMediaItem();
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"]);
466
467 // get item parameter
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"]);
473 }
474
475 // get item map areas
476 $max = ilMapArea::_getMaxNr($media_item->getId());
477 for ($i = 1; $i <= $max; $i++) {
478 $area = new ilMapArea($media_item->getId(), $i);
479 $media_item->addMapArea($area);
480 }
481
482 // add media item to media object
483 $a_mob->addMediaItem($media_item);
484 }
485 }
486
487 public static function deleteAllItemsOfMob(int $a_mob_id): void
488 {
489 global $DIC;
490
491 $ilDB = $DIC->database();
492
493 // iterate all media items ob mob
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)) {
498 // delete all parameters of media item
499 $query = "DELETE FROM mob_parameter WHERE med_item_id = " .
500 $ilDB->quote($item_rec["id"], "integer");
501 $ilDB->manipulate($query);
502
503 // delete all map areas of media item
504 $query = "DELETE FROM map_area WHERE item_id = " .
505 $ilDB->quote($item_rec["id"], "integer");
506 $ilDB->manipulate($query);
507 }
508
509 // delete media items
510 $query = "DELETE FROM media_item WHERE mob_id = " .
511 $ilDB->quote($a_mob_id, "integer");
512 $ilDB->manipulate($query);
513 }
514
515 public function setPurpose(string $a_purpose): void
516 {
517 $this->purpose = $a_purpose;
518 }
519
520 public function getPurpose(): string
521 {
522 return $this->purpose;
523 }
524
525 public function setLocation(string $a_location): void
526 {
527 $this->location = $a_location;
528 }
529
530 public function getLocation(): string
531 {
532 return $this->location;
533 }
534
535 public function setLocationType(string $a_type): void
536 {
537 $this->location_type = $a_type;
538 }
539
540 public function getLocationType(): string
541 {
542 return $this->location_type;
543 }
544
545 public function setFormat(string $a_format): void
546 {
547 $this->format = $a_format;
548 }
549
550 public function getFormat(): string
551 {
552 return $this->format;
553 }
554
555 public function setThumbTried(string $a_tried): void
556 {
557 $this->tried_thumb = $a_tried;
558 }
559
560 public function getThumbTried(): string
561 {
562 return $this->tried_thumb;
563 }
564
565 public function addMapArea(ilMapArea $a_map_area): void
566 {
567 $this->mapareas[$this->map_cnt] = $a_map_area;
568 $this->map_cnt++;
569 }
570
571 public function deleteMapArea(int $nr): void
572 {
573 for ($i = 1; $i <= $this->map_cnt; $i++) {
574 if ($i > $nr) {
575 $this->mapareas[$i - 2] = $this->mapareas[$i - 1];
576 $this->mapareas[$i - 2]->setNr($i - 1);
577 }
578 }
579 if ($nr <= $this->map_cnt) {
580 unset($this->mapareas[$this->map_cnt - 1]);
581 $this->map_cnt--;
582 }
583 }
584
585 public function getMapArea(int $nr): ?ilMapArea
586 {
587 return $this->mapareas[$nr - 1] ?? null;
588 }
589
590 public function getMapAreas(): array
591 {
592 return $this->mapareas;
593 }
594
595 public function getWidth(): string
596 {
597 return $this->width;
598 }
599
600 public function setWidth(string $a_width): void
601 {
602 $this->width = $a_width;
603 }
604
605 public function getHeight(): string
606 {
607 return $this->height;
608 }
609
610 public function setHeight(string $a_height): void
611 {
612 $this->height = $a_height;
613 }
614
615 public function getOriginalSize(): ?array
616 {
617 if (ilUtil::deducibleSize($this->getFormat())) {
618 $loc = $this->getOriginalSource();
619 $size = ilMediaImageUtil::getImageSize($loc);
620 if ($size[0] > 0 && $size[1] > 0) {
621 return array("width" => $size[0], "height" => $size[1]);
622 }
623 }
624
625 return null;
626 }
627
628 public function setCaption(string $a_caption): void
629 {
630 $this->caption = $a_caption;
631 }
632
633 public function getCaption(): string
634 {
635 return $this->caption;
636 }
637
641 public function setHAlign(string $a_halign): void
642 {
643 $this->halign = $a_halign;
644 }
645
646 public function getHAlign(): string
647 {
648 return $this->halign;
649 }
650
651 public function setParameter(
652 string $a_name,
653 string $a_value
654 ): void {
655 if (self::checkParameter($a_name, $a_value)) {
656 $this->parameters[$a_name] = $a_value;
657 }
658 }
659
660 public function resetParameters(): void
661 {
662 $this->parameters = [];
663 }
664
668 public function setParameters(string $a_par): void
669 {
670 $this->resetParameters();
671 $par_arr = ilUtil::extractParameterString($a_par);
672 if (is_array($par_arr)) {
673 foreach ($par_arr as $par => $val) {
674 $this->setParameter($par, $val);
675 }
676 }
677 }
678
682 public static function checkParameter(
683 string $a_par,
684 string $a_val
685 ): bool {
686 // do not allow event attributes
687 if (substr(strtolower(trim($a_par)), 0, 2) == "on") {
688 return false;
689 }
690 // no javascript in value
691 if (is_int(strpos(strtolower($a_val), "javascript"))) {
692 return false;
693 }
694 // do not allow to change the src attribute
695 if (strtolower(trim($a_par)) == "src") {
696 return false;
697 }
698
699 return true;
700 }
701
702 public function getParameters(): array
703 {
704 return $this->parameters;
705 }
706
707 public function getParameterString(): string
708 {
709 if (is_array($this->parameters)) {
710 $target_arr = [];
711 foreach ($this->parameters as $par => $val) {
712 $target_arr[] = "$par=\"$val\"";
713 }
714 return implode(", ", $target_arr);
715 }
716 return "";
717 }
718
719 public function getParameter(string $a_name): string
720 {
721 return (string) ($this->parameters[$a_name] ?? "");
722 }
723
727 public function getSuffix(): string
728 {
729 $loc_arr = explode(".", $this->getLocation());
730
731 return $loc_arr[count($loc_arr) - 1];
732 }
733
737 public function getMapWorkCopyType(): string
738 {
739 return self::getGDSupportedImageType($this->getSuffix());
740 }
741
745 public function getDirectory(): string
746 {
747 return ilObjMediaObject::_getDirectory($this->getMobId());
748 }
749
750
751 public function getOriginalSource(): string
752 {
753 if ($this->getLocationType() !== "Reference") {
754 return $this->mob_manager->getLocalSrc(
755 $this->getMobId(),
756 $this->getLocation()
757 );
758 }
759 return $this->getLocation();
760 }
761
767 public function makeMapWorkCopy(
768 int $a_area_nr = 0,
769 bool $a_exclude = false
770 ): void {
771 $this->buildMapWorkImage();
772
773 // determine ratios
774 $size = getimagesize($this->getOriginalSource());
775 $x_ratio = 1;
776 if ($size[0] > 0 && $this->getWidth() > 0) {
777 $x_ratio = $this->getWidth() / $size[0];
778 }
779 $y_ratio = 1;
780 if ($size[1] > 0 && $this->getHeight() > 0) {
781 $y_ratio = $this->getHeight() / $size[1];
782 }
783
784 // draw map areas
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) ||
788 ($a_area_nr == 0)
789 ) {
790 $area = $this->mapareas[$i];
791 $area->draw(
792 $this->getMapWorkImage(),
793 $this->color1,
794 $this->color2,
795 true,
796 $x_ratio,
797 $y_ratio
798 );
799 }
800 }
801 }
802
808 public function addAreaToMapWorkCopy(
809 string $a_shape,
810 string $a_coords
811 ): void {
812 // $this->buildMapWorkImage();
813
814 // determine ratios
815 $size = getimagesize($this->getOriginalSource());
816 $x_ratio = 1;
817 if ($size[0] > 0 && $this->getWidth() > 0) {
818 $x_ratio = $this->getWidth() / $size[0];
819 }
820 $y_ratio = 1;
821 if ($size[1] > 0 && $this->getHeight() > 0) {
822 $y_ratio = $this->getHeight() / $size[1];
823 }
824
825 // add new area to work image
826 $area = new ilMapArea();
827 $area->setShape($a_shape);
828 $area->setCoords($a_coords);
829 $area->draw(
830 $this->getMapWorkImage(),
831 $this->color1,
832 $this->color2,
833 false,
834 $x_ratio,
835 $y_ratio
836 );
837 }
838
842 public function outputMapWorkCopy(): void
843 {
844 if ($this->getMapWorkCopyType() != "") {
845 header("Pragma: no-cache");
846 header("Expires: 0");
847 header("Content-type: image/" . strtolower($this->getMapWorkCopyType()));
848 $this->outputWorkImage();
849 }
850 exit;
851 }
852
856 public function buildMapWorkImage(): void
857 {
858 $im_type = strtolower($this->getMapWorkCopyType());
859
860 switch ($im_type) {
861 case "gif":
862 $this->map_image = imagecreatefromgif($this->getOriginalSource());
863 break;
864
865 case "jpg":
866 case "jpeg":
867 $this->map_image = imagecreatefromjpeg($this->getOriginalSource());
868 break;
869
870 case "png":
871 $this->map_image = imagecreatefrompng($this->getOriginalSource());
872 break;
873 }
874
875 // try to allocate black and white as color. if this is not possible, get the closest colors
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);
879 } else {
880 $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
881 $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
882 }
883 }
884
885 public function outputWorkImage(): void
886 {
887 $im_type = strtolower($this->getMapWorkCopyType());
888
889 // save image work-copy and free memory
890 switch ($im_type) {
891 case "gif":
892 imagegif($this->map_image);
893 break;
894
895 case "jpg":
896 case "jpeg":
897 imagejpeg($this->map_image);
898 break;
899
900 case "png":
901 imagepng($this->map_image);
902 break;
903 }
904 }
905
909 public function getMapWorkImage()
910 {
911 return $this->map_image;
912 }
913
917 public function getMapAreasXML(
918 bool $a_insert_inst = false,
919 int $a_inst = 0
920 ): string {
921 $xml = "";
922
923 // build xml of map areas
924 for ($i = 0; $i < count($this->mapareas); $i++) {
925 $area = $this->mapareas[$i];
926
927 // highlight mode
928 $hm = "";
929 if ($area->getHighlightMode() != "") {
930 $hm = ' HighlightMode="' . $area->getHighlightMode() . '" ';
931 $hcl = ($area->getHighlightClass() != "")
932 ? $area->getHighlightClass()
933 : "Accented";
934 $hm .= 'HighlightClass="' . $hcl . '" ';
935 }
936
937 $xml .= "<MapArea Shape=\"" . $area->getShape() . "\" Coords=\"" . $area->getCoords() . "\" " . $hm . ">";
938 if ($area->getLinkType() == IL_INT_LINK) {
939 $target_frame = $area->getTargetFrame();
940
941 if ($area->getType() == "GlossaryItem" && $target_frame == "") {
942 $target_frame = "Glossary";
943 }
944
945 $tf_str = ($target_frame == "")
946 ? ""
947 : "TargetFrame=\"" . $target_frame . "\"";
948
949 $xml .= "<IntLink Target=\"" . $area->getTarget($a_insert_inst, $a_inst) . "\" Type=\"" .
950 $area->getType() . "\" $tf_str>";
951 // see bug 17893 and http://stackoverflow.com/questions/4026502/xml-error-at-ampersand
952 $xml .= htmlspecialchars($area->getTitle(), ENT_QUOTES);
953 $xml .= "</IntLink>";
954 } else {
955 $xml .= "<ExtLink Href=\"" . str_replace("&", "&amp;", $area->getHref()) . "\" Title=\"" .
956 str_replace("&", "&amp;", $area->getExtTitle()) . "\">";
957 $xml .= str_replace("&", "&amp;", $area->getTitle());
958 $xml .= "</ExtLink>";
959 }
960 $xml .= "</MapArea>";
961 }
962 return $xml;
963 }
964
969 public static function _resolveMapAreaLinks(
970 int $a_mob_id
971 ): void {
972 global $DIC;
973
974 $ilDB = $DIC->database();
975
976 //echo "mediaItems::resolve<br>";
977 // read media_object record
978 $query = "SELECT * FROM media_item WHERE mob_id = " .
979 $ilDB->quote($a_mob_id, "integer") . " " .
980 "ORDER BY nr";
981 $item_set = $ilDB->query($query);
982 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
983 ilMapArea::_resolveIntLinks($item_rec["id"]);
984 }
985 }
986
991 public static function _getMapAreasIntLinks(
992 int $a_mob_id
993 ): array {
994 global $DIC;
995
996 $ilDB = $DIC->database();
997
998 // read media_items records
999 $query = "SELECT * FROM media_item WHERE mob_id = " .
1000 $ilDB->quote($a_mob_id, "integer") . " ORDER BY nr";
1001
1002 $item_set = $ilDB->query($query);
1003 $links = array();
1004 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
1005 $map_links = ilMapArea::_getIntLinks($item_rec["id"]);
1006 foreach ($map_links as $key => $map_link) {
1007 $links[$key] = $map_link;
1008 }
1009 }
1010 return $links;
1011 }
1012
1016 public function extractUrlParameters(): void
1017 {
1019 $this->getLocation(),
1020 $this->getParameters()
1021 );
1022 foreach ($par as $k => $v) {
1023 $this->setParameter($k, $v);
1024 }
1025 }
1026
1027 public function determineDuration(): void
1028 {
1029 $ana = new ilMediaAnalyzer();
1030
1031 if (ilExternalMediaAnalyzer::isVimeo($this->getLocation())) {
1032 $par = ilExternalMediaAnalyzer::extractVimeoParameters($this->getLocation());
1034 if ($meta["duration"] > 0) {
1035 $this->setDuration((int) $meta["duration"]);
1036 }
1037 } else {
1038 $file = $this->getLocationSrc();
1039
1040 try {
1041 if (str_starts_with($file, 'http')) {
1042 $mob_logger = ilLoggerFactory::getLogger('mob');
1043
1044 try {
1045 $tmpdir = ilFileUtils::ilTempnam();
1046 ilFileUtils::makeDir($tmpdir);
1047 $localtempfilename = tempnam($tmpdir, 'getID3');
1048 $fp_local = fopen($localtempfilename, 'wb');
1049
1050 $mob_logger->debug('Determining duration of file: {file}', [
1051 'file' => $file,
1052 ]);
1053
1054 $curl = new ilCurlConnection($file);
1055 $curl->init(true);
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);
1064
1065 $success = $curl->exec();
1066 $info = $curl->getInfo();
1067
1068 $mob_logger->debug('cURL Info: {info}', [
1069 'info' => print_r($info, true)
1070 ]);
1071
1072 if ($success) {
1073 $mob_logger->debug('Successfully downloaded remote file: {file}', [
1074 'file' => $file,
1075 ]);
1076
1077 $file = $localtempfilename;
1078 } else {
1079 $mob_logger->error('Could not fetch file: {file}', [
1080 'file' => $file,
1081 ]);
1082 }
1083 } catch (Exception $e) {
1084 $mob_logger->error('Could not determine duration: {message}', [
1085 'message' => $e->getMessage(),
1086 ]);
1087 $mob_logger->error($e->getTraceAsString());
1088 }
1089 }
1090
1091 $ana->setFile($file);
1092 $ana->analyzeFile();
1093 $this->setDuration($ana->getPlaytimeSeconds());
1094 } catch (Exception) {
1095 }
1096 }
1097 }
1098
1099 public function getLocationSrc(bool $autoplay = false): string
1100 {
1101 if (strcasecmp("Reference", $this->getLocationType()) === 0) {
1102 $src = $this->getLocation();
1103 if ($this->getFormat() === "video/vimeo") {
1104 $params = "";
1105 if ($autoplay) {
1106 $params = "&autoplay=1&muted=1";
1107 }
1109 $src = "//player.vimeo.com/video/" . $par["id"] . "?api=1" . $params;
1110 }
1111 if ($this->getFormat() === "video/youtube") {
1112 $params = "";
1113 if ($autoplay) {
1114 $params = "&autoplay=1&muted=1";
1115 }
1117 $src = "//www.youtube.com/embed/" . $par["v"] . "?enablejsapi=1" . $params;
1118 }
1119 } else {
1120 $src = $this->mob_manager->getLocalSrc(
1121 $this->getMobId(),
1122 $this->getLocation()
1123 );
1124 }
1125 return $src;
1126 }
1127
1128 public function getLocationStream(): ZIPStream
1129 {
1130 return $this->mob_manager->getLocationStream(
1131 $this->getMobId(),
1132 $this->getLocation()
1133 );
1134 }
1135
1141 public static function getMediaItemsForUploadHash(
1142 string $a_hash
1143 ): array {
1144 global $DIC;
1145
1146 $db = $DIC->database();
1147
1148 $set = $db->queryF(
1149 "SELECT * FROM media_item " .
1150 " WHERE upload_hash = %s ",
1151 array("text"),
1152 array($a_hash)
1153 );
1154 $media_items = array();
1155 while ($rec = $db->fetchAssoc($set)) {
1156 $media_items[] = $rec;
1157 }
1158 return $media_items;
1159 }
1160}
$location
Definition: buildRTE.php:22
const IL_INT_LINK
static extractYouTubeParameters(string $a_location)
Extract YouTube Parameter.
static isVimeo(string $a_location)
Identify Vimeo links.
static extractVimeoParameters(string $a_location)
Extract Vimeo Parameter.
static extractUrlParameters(string $a_location, array $a_parameter)
Extract URL information to parameter array.
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.
language handling
static getLogger(string $a_component_id)
Get component logger.
Class ilMapArea.
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImageSize(string $a_location)
Get image size from location.
Class ilMediaItem Media Item, component of a media object (file or reference)
setLocationType(string $a_type)
setNr(int $a_nr)
set number of media item within media object
addAreaToMapWorkCopy(string $a_shape, string $a_coords)
draw a new area in work image
setUploadHash(string $a_val)
static _getMediaItemsOfMOb(ilObjMediaObject $a_mob)
Read media items into(!) media object (static)
setWidth(string $a_width)
static _getMapAreasIntLinks(int $a_mob_id)
get all internal links of map areas of a mob
outputMapWorkCopy()
output raw map work copy file
addMapArea(ilMapArea $a_map_area)
string $text_representation
setDuration(int $a_val)
ilLanguage $lng
extractUrlParameters()
Extract parameters of special external references to parameter array.
getSuffix()
get location suffix
makeMapWorkCopy(int $a_area_nr=0, bool $a_exclude=false)
make map work copy of image
static deleteAllItemsOfMob(int $a_mob_id)
setThumbTried(string $a_tried)
setLocation(string $a_location)
static checkParameter(string $a_par, string $a_val)
Check parameter (filter javascript related and other unsafe parameters/values)
getMapAreasXML(bool $a_insert_inst=false, int $a_inst=0)
get xml code of media items' areas
static _resolveMapAreaLinks(int $a_mob_id)
resolve internal links of all media items of a media object
getDirectory()
get media file directory
ILIAS MediaObjects MediaObjectManager $mob_manager
setCaption(string $a_caption)
getMapWorkCopyType()
get image type of image map work copy
ILIAS Filesystem Util Convert LegacyImages $image_converter
buildMapWorkImage()
build image map work image
read()
read media item data (item id or (mob_id and nr) must be set)
setHeight(string $a_height)
setParameter(string $a_name, string $a_value)
static getGDSupportedImageType(string $a_desired_type)
returns the best supported image type by this PHP build
setParameters(string $a_par)
set all parameters via parameter string (format: par1="value1", par2="value2", ......
deleteMapArea(int $nr)
static getMediaItemsForUploadHash(string $a_hash)
Get media items for upload hash.
__construct(int $a_id=0)
ilDBInterface $db
getParameter(string $a_name)
setId(int $a_id)
set media item id
setTextRepresentation(string $a_val)
static _getMediaItemsOfMObId(int $a_mobId, string $a_purpose)
read media item with specific purpose and mobId
writeParameter(string $a_name, string $a_value)
setFormat(string $a_format)
static _lookupLocationForMobId(int $a_mob_id, string $a_purpose)
setHAlign(string $a_halign)
set horizontal align
getLocationSrc(bool $autoplay=false)
setPurpose(string $a_purpose)
static _lookupMobId(int $a_med_id)
writeThumbTried(string $a_tried)
write thumbnail creation try data ("y"/"n")
setMobId(int $a_mob_id)
set id of parent media object
addMediaItem(ilMediaItem $a_item)
static _getDirectory(int $a_mob_id)
Get absolute directory.
static deducibleSize(string $a_mime)
checks if mime type is provided by getimagesize()
static extractParameterString(string $a_parstr)
exit
$info
Definition: entry_point.php:21
Interface ilDBInterface.
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23