ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMediaItem.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("Services/MediaObjects/classes/class.ilMapArea.php");
5
17{
21 protected $db;
22
26 protected $lng;
27
28 public $id;
29 public $purpose;
30 public $location;
32 public $format;
33 public $width;
34 public $height;
35 public $caption;
36 public $halign;
38 public $mob_id;
39 public $nr;
40 public $mapareas;
41 public $map_cnt;
42 public $map_image; // image map work copy image
43 public $color1; // map area line color 1
44 public $color2; // map area line color 2
45
49 protected $upload_hash;
50
51 public function __construct($a_id = 0)
52 {
53 global $DIC;
54
55 $this->db = $DIC->database();
56 $this->lng = $DIC->language();
57 $this->parameters = array();
58 $this->mapareas = array();
59 $this->map_cnt = 0;
60
61 if ($a_id != 0) {
62 $this->setId($a_id);
63 $this->read();
64 }
65 }
66
72 public function setId($a_id)
73 {
74 $this->id = $a_id;
75 }
76
82 public function getId()
83 {
84 return $this->id;
85 }
86
92 public function setMobId($a_mob_id)
93 {
94 $this->mob_id = $a_mob_id;
95 }
96
102 public function getMobId()
103 {
104 return $this->mob_id;
105 }
106
110 public function setNr($a_nr)
111 {
112 $this->nr = $a_nr;
113 }
114
115 public function getNr()
116 {
117 return $this->nr;
118 }
119
125 public function setTextRepresentation($a_val)
126 {
127 $this->text_representation = $a_val;
128 }
129
135 public function getTextRepresentation()
136 {
137 return $this->text_representation;
138 }
139
145 public function setUploadHash($a_val)
146 {
147 $this->upload_hash = $a_val;
148 }
149
155 public function getUploadHash()
156 {
157 return $this->upload_hash;
158 }
159
160
164 public function create()
165 {
167
168 $item_id = $ilDB->nextId("media_item");
169 $query = "INSERT INTO media_item (id,mob_id, purpose, location, " .
170 "location_type, format, width, " .
171 "height, halign, caption, nr, text_representation, upload_hash) VALUES " .
172 "(" .
173 $ilDB->quote($item_id, "integer") . "," .
174 $ilDB->quote($this->getMobId(), "integer") . "," .
175 $ilDB->quote($this->getPurpose(), "text") . "," .
176 $ilDB->quote($this->getLocation(), "text") . "," .
177 $ilDB->quote($this->getLocationType(), "text") . "," .
178 $ilDB->quote($this->getFormat(), "text") . "," .
179 $ilDB->quote($this->getWidth(), "text") . "," .
180 $ilDB->quote($this->getHeight(), "text") . "," .
181 $ilDB->quote($this->getHAlign(), "text") . "," .
182 $ilDB->quote($this->getCaption(), "text") . "," .
183 $ilDB->quote($this->getNr(), "integer") . "," .
184 $ilDB->quote($this->getTextRepresentation(), "text") . "," .
185 $ilDB->quote($this->getUploadHash(), "text") .
186 ")";
187 $ilDB->manipulate($query);
188
189 $this->setId($item_id);
190
191 // create mob parameters
192 $params = $this->getParameters();
193 foreach ($params as $name => $value) {
194 $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
195 "(" . $ilDB->quote($item_id, "integer") . "," .
196 $ilDB->quote($name, "text") . "," .
197 $ilDB->quote($value, "text") . ")";
198 $ilDB->manipulate($query);
199 }
200
201 // create map areas
202 for ($i = 0; $i < count($this->mapareas); $i++) {
203 if (is_object($this->mapareas[$i])) {
204 $this->mapareas[$i]->setItemId($this->getId());
205 $this->mapareas[$i]->setNr($i + 1);
206 $this->mapareas[$i]->create();
207 }
208 }
209 }
210
214 public function update()
215 {
217
218 $query = "UPDATE media_item SET " .
219 " mob_id = " . $ilDB->quote($this->getMobId(), "integer") . "," .
220 " purpose = " . $ilDB->quote($this->getPurpose(), "text") . "," .
221 " location = " . $ilDB->quote($this->getLocation(), "text") . "," .
222 " location_type = " . $ilDB->quote($this->getLocationType(), "text") . "," .
223 " format = " . $ilDB->quote($this->getFormat(), "text") . "," .
224 " width = " . $ilDB->quote($this->getWidth(), "text") . "," .
225 " height = " . $ilDB->quote($this->getHeight(), "text") . "," .
226 " halign = " . $ilDB->quote($this->getHAlign(), "text") . "," .
227 " caption = " . $ilDB->quote($this->getCaption(), "text") . "," .
228 " nr = " . $ilDB->quote($this->getNr(), "integer") . "," .
229 " text_representation = " . $ilDB->quote($this->getTextRepresentation(), "text") . "," .
230 " upload_hash = " . $ilDB->quote($this->getUploadHash(), "text") .
231 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
232 $ilDB->manipulate($query);
233
234 // delete mob parameters
235 $query = "DELETE FROM mob_parameter WHERE med_item_id = " .
236 $ilDB->quote($this->getId(), "integer");
237
238 // create mob parameters
239 $params = $this->getParameters();
240 foreach ($params as $name => $value) {
241 $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
242 "(" . $ilDB->quote($this->getId(), "integer") . "," .
243 $ilDB->quote($name, "text") . "," .
244 $ilDB->quote($value, "text") . ")";
245 $ilDB->manipulate($query);
246 }
247 }
248
255 public function writeParameter($a_name, $a_value)
256 {
258
259 $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
260 "(" . $ilDB->quote($this->getId(), "integer") . "," .
261 $ilDB->quote($a_name, "text") . "," .
262 $ilDB->quote($a_value, "text") . ")";
263 $ilDB->manipulate($query);
264 }
265
269 public function read()
270 {
272
273 $item_id = $this->getId();
274 $mob_id = $this->getMobId();
275 $nr = $this->getNr();
276 $query = "";
277 if ($item_id > 0) {
278 $query = "SELECT * FROM media_item WHERE id = " .
279 $ilDB->quote($this->getId(), "integer");
280 } elseif ($mob_id > 0 && $nr > 0) {
281 $query = "SELECT * FROM media_item WHERE mob_id = " .
282 $ilDB->quote($this->getMobId(), "integer") . " " .
283 "AND nr=" . $ilDB->quote($this->getNr(), "integer");
284 }
285 if ($query != "") {
286 $item_set = $ilDB->query($query);
287 $item_rec = $ilDB->fetchAssoc($item_set);
288
289 $this->setLocation($item_rec["location"]);
290 $this->setLocationType($item_rec["location_type"]);
291 $this->setFormat($item_rec["format"]);
292 $this->setWidth($item_rec["width"]);
293 $this->setHeight($item_rec["height"]);
294 $this->setHAlign($item_rec["halign"]);
295 $this->setCaption($item_rec["caption"]);
296 $this->setPurpose($item_rec["purpose"]);
297 $this->setNr($item_rec["nr"]);
298 $this->setMobId($item_rec["mob_id"]);
299 $this->setId($item_rec["id"]);
300 $this->setThumbTried($item_rec["tried_thumb"]);
301 $this->setTextRepresentation($item_rec["text_representation"]);
302 $this->setUploadHash($item_rec["upload_hash"]);
303
304 // get item parameter
305 $query = "SELECT * FROM mob_parameter WHERE med_item_id = " .
306 $ilDB->quote($this->getId(), "integer");
307 $par_set = $ilDB->query($query);
308 while ($par_rec = $ilDB->fetchAssoc($par_set)) {
309 $this->setParameter($par_rec["name"], $par_rec["value"]);
310 }
311
312 // get item map areas
313 $max = ilMapArea::_getMaxNr($this->getId());
314 for ($i = 1; $i <= $max; $i++) {
315 $area = new ilMapArea($this->getId(), $i);
316 $this->addMapArea($area);
317 }
318 }
319 }
320
324 public function writeThumbTried($a_tried)
325 {
327
328 $q = "UPDATE media_item SET tried_thumb = " .
329 $ilDB->quote($a_tried, "text") .
330 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
331
332 $ilDB->manipulate($q);
333 }
334
341 public static function _lookupLocationForMobId($a_mob_id, $a_purpose)
342 {
343 global $DIC;
344
345 $ilDB = $DIC->database();
346
347 // read media_object record
348 $query = "SELECT * FROM media_item WHERE mob_id = " .
349 $ilDB->quote($a_mob_id, "integer") . " " .
350 "AND purpose = " . $ilDB->quote($a_purpose, "text");
351 $set = $ilDB->query($query);
352 if ($rec = $ilDB->fetchAssoc($set)) {
353 return $rec["location"];
354 }
355
356 return "";
357 }
358
364 public static function _lookupMobId($a_med_id)
365 {
366 global $DIC;
367
368 $ilDB = $DIC->database();
369
370 // read media_object record
371 $query = "SELECT * FROM media_item WHERE id = " .
372 $ilDB->quote($a_med_id, "integer");
373 $set = $ilDB->query($query);
374 if ($rec = $ilDB->fetchAssoc($set)) {
375 return $rec["mob_id"];
376 }
377
378 return "";
379 }
380
381 /* read media item with specific purpose and mobId
382 *
383 * @param integer $a_mobId media object id
384 * @param string $a_purpose media object purpose
385 * @return array $mob media object
386 */
387 public static function _getMediaItemsOfMObId($a_mobId, $a_purpose)
388 {
389 global $DIC;
390
391 $ilDB = $DIC->database();
392
393 // read media_object record
394 $query = "SELECT * FROM media_item WHERE mob_id = " .
395 $ilDB->quote($a_mobId, "integer") . " " .
396 "AND purpose=" . $ilDB->quote($a_purpose, "text") . " ORDER BY nr";
397 $item_set = $ilDB->query($query);
398
399 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
400 return $item_rec;
401 }
402 return false;
403 }
404
410 public static function _getMediaItemsOfMOb(&$a_mob)
411 {
412 global $DIC;
413
414 $ilDB = $DIC->database();
415
416 // read media_object record
417 $query = "SELECT * FROM media_item WHERE mob_id = " .
418 $ilDB->quote($a_mob->getId(), "integer") . " " .
419 "ORDER BY nr";
420 $item_set = $ilDB->query($query);
421 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
422 $media_item = new ilMediaItem();
423 $media_item->setNr($item_rec["nr"]);
424 $media_item->setId($item_rec["id"]);
425 $media_item->setLocation($item_rec["location"]);
426 $media_item->setLocationType($item_rec["location_type"]);
427 $media_item->setFormat($item_rec["format"]);
428 $media_item->setWidth($item_rec["width"]);
429 $media_item->setHeight($item_rec["height"]);
430 $media_item->setHAlign($item_rec["halign"]);
431 $media_item->setCaption($item_rec["caption"]);
432 $media_item->setPurpose($item_rec["purpose"]);
433 $media_item->setMobId($item_rec["mob_id"]);
434 $media_item->setThumbTried($item_rec["tried_thumb"]);
435 $media_item->setTextRepresentation($item_rec["text_representation"]);
436 $media_item->setUploadHash($item_rec["upload_hash"]);
437
438 // get item parameter
439 $query = "SELECT * FROM mob_parameter WHERE med_item_id = " .
440 $ilDB->quote($item_rec["id"], "integer");
441 $par_set = $ilDB->query($query);
442 while ($par_rec = $ilDB->fetchAssoc($par_set)) {
443 $media_item->setParameter($par_rec["name"], $par_rec["value"]);
444 }
445
446 // get item map areas
447 $max = ilMapArea::_getMaxNr($media_item->getId());
448 for ($i = 1; $i <= $max; $i++) {
449 $area = new ilMapArea($media_item->getId(), $i);
450 $media_item->addMapArea($area);
451 }
452
453 // add media item to media object
454 $a_mob->addMediaItem($media_item);
455 }
456 }
457
463 public static function deleteAllItemsOfMob($a_mob_id)
464 {
465 global $DIC;
466
467 $ilDB = $DIC->database();
468
469 // iterate all media items ob mob
470 $query = "SELECT * FROM media_item WHERE mob_id = " .
471 $ilDB->quote($a_mob_id, "integer");
472 $item_set = $ilDB->query($query);
473 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
474 // delete all parameters of media item
475 $query = "DELETE FROM mob_parameter WHERE med_item_id = " .
476 $ilDB->quote($item_rec["id"], "integer");
477 $ilDB->manipulate($query);
478
479 // delete all map areas of media item
480 $query = "DELETE FROM map_area WHERE item_id = " .
481 $ilDB->quote($item_rec["id"], "integer");
482 $ilDB->manipulate($query);
483 }
484
485 // delete media items
486 $query = "DELETE FROM media_item WHERE mob_id = " .
487 $ilDB->quote($a_mob_id, "integer");
488 $ilDB->manipulate($query);
489 }
490
491 public function setPurpose($a_purpose)
492 {
493 $this->purpose = $a_purpose;
494 }
495
496 public function getPurpose()
497 {
498 return $this->purpose;
499 }
500
501 public function setLocation($a_location)
502 {
503 $this->location = $a_location;
504 }
505
506 public function getLocation()
507 {
508 return $this->location;
509 }
510
511 public function setLocationType($a_type)
512 {
513 $this->location_type = $a_type;
514 }
515
516 public function getLocationType()
517 {
519 }
520
521 public function setFormat($a_format)
522 {
523 $this->format = $a_format;
524 }
525
526 public function getFormat()
527 {
528 return $this->format;
529 }
530
531 public function setThumbTried($a_tried)
532 {
533 $this->tried_thumb = $a_tried;
534 }
535
536 public function getThumbTried()
537 {
538 return $this->tried_thumb;
539 }
540
541 public function addMapArea(&$a_map_area)
542 {
543 $this->mapareas[$this->map_cnt] = $a_map_area;
544 $this->map_cnt++;
545 }
546
550 public function deleteMapArea($nr)
551 {
552 for ($i = 1; $i <= $this->map_cnt; $i++) {
553 if ($i > $nr) {
554 $this->mapareas[$i - 2] = $this->mapareas[$i - 1];
555 $this->mapareas[$i - 2]->setNr($i - 1);
556 }
557 }
558 if ($nr <= $this->map_cnt) {
559 unset($this->mapareas[$this->map_cnt - 1]);
560 $this->map_cnt--;
561 }
562 }
563
567 public function &getMapArea($nr)
568 {
569 return $this->mapareas[$nr - 1];
570 }
571
575 public function getMapAreas()
576 {
577 return $this->mapareas;
578 }
579
583 public function getWidth()
584 {
585 return $this->width;
586 }
587
591 public function setWidth($a_width)
592 {
593 $this->width = $a_width;
594 }
595
599 public function getHeight()
600 {
601 return $this->height;
602 }
603
607 public function setHeight($a_height)
608 {
609 $this->height = $a_height;
610 }
611
615 public function getOriginalSize()
616 {
617 $mob_dir = ilObjMediaObject::_getDirectory($this->getMobId());
618
619 if (ilUtil::deducibleSize($this->getFormat())) {
620 if ($this->getLocationType() == "LocalFile") {
621 $loc = $mob_dir . "/" . $this->getLocation();
622 } else {
623 $loc = $this->getLocation();
624 }
625
626 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
628 if ($size[0] > 0 && $size[1] > 0) {
629 return array("width" => $size[0], "height" => $size[1]);
630 }
631 }
632
633 return false;
634 }
635
639 public function setCaption($a_caption)
640 {
641 $this->caption = $a_caption;
642 }
643
647 public function getCaption()
648 {
649 return $this->caption;
650 }
651
655 public function setHAlign($a_halign)
656 {
657 $this->halign = $a_halign;
658 }
659
663 public function getHAlign()
664 {
665 return $this->halign;
666 }
667
668
675 public function setParameter($a_name, $a_value)
676 {
677 if (self::checkParameter($a_name, $a_value)) {
678 $this->parameters[$a_name] = $a_value;
679 }
680 }
681
685 public function resetParameters()
686 {
687 $this->parameters = array();
688 }
689
695 public function setParameters($a_par)
696 {
697 $this->resetParameters();
698 $par_arr = ilUtil::extractParameterString($a_par);
699 if (is_array($par_arr)) {
700 foreach ($par_arr as $par => $val) {
701 $this->setParameter($par, $val);
702 }
703 }
704 }
705
713 public static function checkParameter($a_par, $a_val)
714 {
715 // do not allow event attributes
716 if (substr(strtolower(trim($a_par)), 0, 2) == "on") {
717 return false;
718 }
719 // no javascript in value
720 if (is_int(strpos(strtolower($a_val), "javascript"))) {
721 return false;
722 }
723 // do not allow to change the src attribute
724 if (in_array(strtolower(trim($a_par)), array("src"))) {
725 return false;
726 }
727
728 return true;
729 }
730
731
735 public function getParameters()
736 {
737 return $this->parameters;
738 }
739
740
744 public function getParameterString()
745 {
746 return ilUtil::assembleParameterString($this->parameters);
747 }
748
749
753 public function getParameter($a_name)
754 {
755 return $this->parameters[$a_name];
756 }
757
761 public function getWorkDirectory()
762 {
763 return ilUtil::getDataDir() . "/map_workfiles/item_" . $this->getId();
764 }
765
769 public function createWorkDirectory()
770 {
771 if (!@is_dir(ilUtil::getDataDir() . "/map_workfiles")) {
772 ilUtil::createDirectory(ilUtil::getDataDir() . "/map_workfiles");
773 }
774 $work_dir = $this->getWorkDirectory();
775 if (!@is_dir($work_dir)) {
776 ilUtil::createDirectory($work_dir);
777 }
778 }
779
783 public function getSuffix()
784 {
785 $loc_arr = explode(".", $this->getLocation());
786
787 return $loc_arr[count($loc_arr) - 1];
788 }
789
793 public function getMapWorkCopyType()
794 {
796 }
797
803 public function getMapWorkCopyName($a_reference_copy = false)
804 {
805 $file_arr = explode("/", $this->getLocation());
806 $o_file = $file_arr[count($file_arr) - 1];
807 $file_arr = explode(".", $o_file);
808 unset($file_arr[count($file_arr) - 1]);
809 $file = implode($file_arr, ".");
810
811 if (!$a_reference_copy) {
812 return $this->getWorkDirectory() . "/" . $file . "." . $this->getMapWorkCopyType();
813 } else {
814 return $this->getWorkDirectory() . "/l_copy_" . $o_file;
815 }
816 }
817
821 public function getDirectory()
822 {
824 }
825
829 public function getThumbnailDirectory($a_mode = "filesystem")
830 {
831 return ilObjMediaObject::_getThumbnailDirectory($this->getMobId(), $a_mode);
832 }
833
837 public function getThumbnailTarget($a_size = "")
838 {
839 $jpeg_file = $this->getThumbnailDirectory() . "/" .
840 $this->getPurpose() . ".jpeg";
841 $format = "png";
842 if (is_file($jpeg_file)) {
843 $format = "jpeg";
844 }
845
846 if (is_int(strpos($this->getFormat(), "image"))) {
847 $thumb_file = $this->getThumbnailDirectory() . "/" .
848 $this->getPurpose() . ".".$format;
849
850 $thumb_file_small = $this->getThumbnailDirectory() . "/" .
851 $this->getPurpose() . "_small.".$format;
852 // generate thumbnail (if not tried before)
853 if ($this->getThumbTried() == "n" && $this->getLocationType() == "LocalFile") {
854 if (is_file($thumb_file)) {
855 unlink($thumb_file);
856 }
857 if (is_file($thumb_file_small)) {
858 unlink($thumb_file_small);
859 }
860 $this->writeThumbTried("y");
862 $med_file = $this->getDirectory() . "/" . $this->getLocation();
863
864 if (is_file($med_file)) {
865 ilUtil::convertImage($med_file, $thumb_file, $format, "80");
866 ilUtil::convertImage($med_file, $thumb_file_small, $format, "40");
867 }
868 }
869 if ($a_size == "small") {
870 if (is_file($thumb_file_small)) {
871 $random = new \ilRandom();
872 return $this->getThumbnailDirectory("output") . "/" .
873 $this->getPurpose() . "_small.".$format."?dummy=" . $random->int(1, 999999);
874 }
875 } else {
876 if (is_file($thumb_file)) {
877 $random = new \ilRandom();
878 return $this->getThumbnailDirectory("output") . "/" .
879 $this->getPurpose() . ".".$format."?dummy=" . $random->int(1, 999999);
880 }
881 }
882 }
883
884 return "";
885 }
886
887
891 public function copyOriginal()
892 {
894 $this->createWorkDirectory();
895
896 $geom = ($this->getWidth() != "" && $this->getHeight() != "")
897 ? $this->getWidth() . "x" . $this->getHeight()
898 : "";
899
900 if ($this->getLocationType() != "Reference") {
902 $this->getDirectory() . "/" . $this->getLocation(),
903 $this->getMapWorkCopyName(),
904 $this->getMapWorkCopyType(),
905 $geom
906 );
907 } else {
908 // first copy the external file, if necessary
909 if (!is_file($this->getMapWorkCopyName(true)) || (filesize($this->getMapWorkCopyName(true)) == 0)) {
910 $handle = @fopen($this->getLocation(), "r");
911 $lcopy = fopen($this->getMapWorkCopyName(true), "w");
912 if ($handle && $lcopy) {
913 while (!feof($handle)) {
914 $content = fread($handle, 4096);
915 fwrite($lcopy, $content);
916 }
917 }
918 @fclose($lcopy);
919 @fclose($handle);
920 }
921
922 // now, create working copy
924 $this->getMapWorkCopyName(true),
925 $this->getMapWorkCopyName(),
926 $this->getMapWorkCopyType(),
927 $geom
928 );
929 }
930
931 if (!is_file($this->getMapWorkCopyName())) {
932 ilUtil::sendFailure($lng->txt("cont_map_file_not_generated"));
933 return false;
934 }
935 return true;
936 }
937
944 public function makeMapWorkCopy($a_area_nr = 0, $a_exclude = false)
945 {
947
948 if (!$this->copyOriginal()) {
949 return false;
950 }
951 $this->buildMapWorkImage();
952
953 // determine ratios
954 $size = @getimagesize($this->getMapWorkCopyName());
955 $x_ratio = 1;
956 if ($size[0] > 0 && $this->getWidth() > 0) {
957 $x_ratio = $this->getWidth() / $size[0];
958 }
959 $y_ratio = 1;
960 if ($size[1] > 0 && $this->getHeight() > 0) {
961 $y_ratio = $this->getHeight() / $size[1];
962 }
963
964 // draw map areas
965 for ($i = 0; $i < count($this->mapareas); $i++) {
966 if (((($i + 1) == $a_area_nr) && !$a_exclude) ||
967 ((($i + 1) != $a_area_nr) && $a_exclude) ||
968 ($a_area_nr == 0)
969 ) {
970 $area = $this->mapareas[$i];
971 $area->draw(
972 $this->getMapWorkImage(),
975 true,
976 $x_ratio,
977 $y_ratio
978 );
979 }
980 }
981
982 $this->saveMapWorkImage();
983
984 return true;
985 }
986
987
994 public function addAreaToMapWorkCopy($a_shape, $a_coords)
995 {
996 $this->buildMapWorkImage();
997
998 // determine ratios
999 $size = @getimagesize($this->getMapWorkCopyName());
1000 $x_ratio = 1;
1001 if ($size[0] > 0 && $this->getWidth() > 0) {
1002 $x_ratio = $this->getWidth() / $size[0];
1003 }
1004 $y_ratio = 1;
1005 if ($size[1] > 0 && $this->getHeight() > 0) {
1006 $y_ratio = $this->getHeight() / $size[1];
1007 }
1008
1009 // add new area to work image
1010 $area = new ilMapArea();
1011 $area->setShape($a_shape);
1012 $area->setCoords($a_coords);
1013 $area->draw(
1014 $this->getMapWorkImage(),
1015 $this->color1,
1016 $this->color2,
1017 false,
1018 $x_ratio,
1019 $y_ratio
1020 );
1021
1022 $this->saveMapWorkImage();
1023 }
1024
1028 public function outputMapWorkCopy()
1029 {
1030 if ($this->getMapWorkCopyType() != "") {
1031 header("Pragma: no-cache");
1032 header("Expires: 0");
1033 header("Content-type: image/" . strtolower($this->getMapWorkCopyType()));
1034 readfile($this->getMapWorkCopyName());
1035 }
1036 exit;
1037 }
1038
1042 public function buildMapWorkImage()
1043 {
1044 $im_type = strtolower($this->getMapWorkCopyType());
1045
1046 switch ($im_type) {
1047 case "gif":
1048 $this->map_image = ImageCreateFromGIF($this->getMapWorkCopyName());
1049 break;
1050
1051 case "jpg":
1052 case "jpeg":
1053 $this->map_image = ImageCreateFromJPEG($this->getMapWorkCopyName());
1054 break;
1055
1056 case "png":
1057 $this->map_image = ImageCreateFromPNG($this->getMapWorkCopyName());
1058 break;
1059 }
1060
1061 // try to allocate black and white as color. if this is not possible, get the closest colors
1062 if (imagecolorstotal($this->map_image) > 250) {
1063 $this->color1 = imagecolorclosest($this->map_image, 0, 0, 0);
1064 $this->color2 = imagecolorclosest($this->map_image, 255, 255, 255);
1065 } else {
1066 $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
1067 $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
1068 }
1069 }
1070
1074 public function saveMapWorkImage()
1075 {
1076 $im_type = strtolower($this->getMapWorkCopyType());
1077
1078 // save image work-copy and free memory
1079 switch ($im_type) {
1080 case "gif":
1081 ImageGIF($this->map_image, $this->getMapWorkCopyName());
1082 break;
1083
1084 case "jpg":
1085 case "jpeg":
1086 ImageJPEG($this->map_image, $this->getMapWorkCopyName());
1087 break;
1088
1089 case "png":
1090 ImagePNG($this->map_image, $this->getMapWorkCopyName());
1091 break;
1092 }
1093
1094 ImageDestroy($this->map_image);
1095 }
1096
1100 public function &getMapWorkImage()
1101 {
1102 return $this->map_image;
1103 }
1104
1105
1109 public function getMapAreasXML($a_insert_inst = false, $a_inst = 0)
1110 {
1111 $xml = "";
1112
1113 // build xml of map areas
1114 for ($i = 0; $i < count($this->mapareas); $i++) {
1115 $area = $this->mapareas[$i];
1116
1117 // highlight mode
1118 $hm = "";
1119 if ($area->getHighlightMode() != "") {
1120 $hm = ' HighlightMode="' . $area->getHighlightMode() . '" ';
1121 $hcl = ($area->getHighlightClass() != "")
1122 ? $area->getHighlightClass()
1123 : "Accented";
1124 $hm .= 'HighlightClass="' . $hcl . '" ';
1125 }
1126
1127 $xml .= "<MapArea Shape=\"" . $area->getShape() . "\" Coords=\"" . $area->getCoords() . "\" " . $hm . ">";
1128 if ($area->getLinkType() == IL_INT_LINK) {
1129 $target_frame = $area->getTargetFrame();
1130
1131 if ($area->getType() == "GlossaryItem" && $target_frame == "") {
1132 $target_frame = "Glossary";
1133 }
1134
1135 $tf_str = ($target_frame == "")
1136 ? ""
1137 : "TargetFrame=\"" . $target_frame . "\"";
1138
1139 $xml .= "<IntLink Target=\"" . $area->getTarget($a_insert_inst, $a_inst) . "\" Type=\"" .
1140 $area->getType() . "\" $tf_str>";
1141 // see bug 17893 and http://stackoverflow.com/questions/4026502/xml-error-at-ampersand
1142 $xml .= htmlspecialchars($area->getTitle(), ENT_QUOTES);
1143 $xml .= "</IntLink>";
1144 } else {
1145 $xml .= "<ExtLink Href=\"" . str_replace("&", "&amp;", $area->getHref()) . "\" Title=\"" .
1146 str_replace("&", "&amp;", $area->getExtTitle()) . "\">";
1147 $xml .= str_replace("&", "&amp;", $area->getTitle());
1148 $xml .= "</ExtLink>";
1149 }
1150 $xml .= "</MapArea>";
1151 }
1152 return $xml;
1153 }
1154
1155
1161 public static function _resolveMapAreaLinks($a_mob_id)
1162 {
1163 global $DIC;
1164
1165 $ilDB = $DIC->database();
1166
1167 //echo "mediaItems::resolve<br>";
1168 // read media_object record
1169 $query = "SELECT * FROM media_item WHERE mob_id = " .
1170 $ilDB->quote($a_mob_id, "integer") . " " .
1171 "ORDER BY nr";
1172 $item_set = $ilDB->query($query);
1173 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
1174 ilMapArea::_resolveIntLinks($item_rec["id"]);
1175 }
1176 }
1177
1183 public static function _getMapAreasIntLinks($a_mob_id)
1184 {
1185 global $DIC;
1186
1187 $ilDB = $DIC->database();
1188
1189 // read media_items records
1190 $query = "SELECT * FROM media_item WHERE mob_id = " .
1191 $ilDB->quote($a_mob_id, "integer") . " ORDER BY nr";
1192
1193 $item_set = $ilDB->query($query);
1194 $links = array();
1195 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
1196 $map_links = ilMapArea::_getIntLinks($item_rec["id"]);
1197 foreach ($map_links as $key => $map_link) {
1198 $links[$key] = $map_link;
1199 }
1200 }
1201 return $links;
1202 }
1203
1207 public function extractUrlParameters()
1208 {
1209 include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
1211 $this->getLocation(),
1212 $this->getParameters()
1213 );
1214 foreach ($par as $k => $v) {
1215 $this->setParameter($k, $v);
1216 }
1217 }
1218
1225 public static function getMediaItemsForUploadHash($a_hash)
1226 {
1227 global $DIC;
1228
1229 $db = $DIC->database();
1230
1231 $set = $db->queryF(
1232 "SELECT * FROM media_item " .
1233 " WHERE upload_hash = %s ",
1234 array("text"),
1235 array($a_hash)
1236 );
1237 $media_items = array();
1238 while ($rec = $db->fetchAssoc($set)) {
1239 $media_items[] = $rec;
1240 }
1241 return $media_items;
1242 }
1243}
$size
Definition: RandomTest.php:84
exit
Definition: backend.php:16
An exception for terminatinating execution or to throw for unit testing.
const IL_INT_LINK
static extractUrlParameters($a_location, $a_parameter)
Extract URL information to parameter array.
Class ilMapArea.
static _resolveIntLinks($a_item_id)
resolve internal links of an item id
static _getIntLinks($a_item_id)
get all internal links of a media items map areas
static _getMaxNr($a_item_id)
get maximum nr of media item (static)
static getImageSize($a_location)
Get image size from location.
Class ilMediaItem.
static _resolveMapAreaLinks($a_mob_id)
resolve internal links of all media items of a media object
setMobId($a_mob_id)
set id of parent media object
setPurpose($a_purpose)
setId($a_id)
set media item id
addMapArea(&$a_map_area)
setNr($a_nr)
set number of media item within media object
static deleteAllItemsOfMob($a_mob_id)
Delete all items of a mob.
getWorkDirectory()
get work directory for image map editing
outputMapWorkCopy()
output raw map work copy file
getCaption()
get caption
setWidth($a_width)
set width
getParameter($a_name)
get a single parameter
setParameters($a_par)
set alle parameters via parameter string (format: par1="value1", par2="value2", .....
getThumbnailTarget($a_size="")
get thumbnail target
static _lookupMobId($a_med_id)
Lookup Mob ID.
setParameter($a_name, $a_value)
set parameter
setHAlign($a_halign)
set horizontal align
static checkParameter($a_par, $a_val)
Check parameter (filter javascript related and other unsafe parameters/values)
extractUrlParameters()
Extract parameters of special external references to parameter array.
saveMapWorkImage()
save image map work image
createWorkDirectory()
create work directory for image map editing
getSuffix()
get location suffix
deleteMapArea($nr)
delete map area
getId()
get media item id
getHAlign()
get horizontal align
writeThumbTried($a_tried)
write thumbnail creation try data ("y"/"n")
update()
update media item data (without map areas!)
static _getMediaItemsOfMOb(&$a_mob)
read media items into media objects (static)
static _getMapAreasIntLinks($a_mob_id)
get all internal links of map areas of a mob
getMapWorkCopyName($a_reference_copy=false)
Get name of image map work copy file.
resetParameters()
reset parameters
getDirectory()
get media file directory
setTextRepresentation($a_val)
Set text representation.
static _lookupLocationForMobId($a_mob_id, $a_purpose)
Lookup location for mob id.
getMapWorkCopyType()
get image type of image map work copy
buildMapWorkImage()
build image map work image
read()
read media item data (item id or (mob_id and nr) must be set)
__construct($a_id=0)
getHeight()
get height
setFormat($a_format)
static _getMediaItemsOfMObId($a_mobId, $a_purpose)
& getMapWorkImage()
get image map work image
makeMapWorkCopy($a_area_nr=0, $a_exclude=false)
make map work copy of image
setLocation($a_location)
getMapAreas()
get map areas
setUploadHash($a_val)
Set upload hash.
getWidth()
get width
static getMediaItemsForUploadHash($a_hash)
Get media items for upload hash.
getUploadHash()
Get upload hash.
setLocationType($a_type)
setCaption($a_caption)
set caption
copyOriginal()
Copy the orginal file.
getParameterString()
get all parameters (as string)
addAreaToMapWorkCopy($a_shape, $a_coords)
draw a new area in work image
setThumbTried($a_tried)
writeParameter($a_name, $a_value)
Write parameter.
& getMapArea($nr)
get map area
getThumbnailDirectory($a_mode="filesystem")
get media file directory
getParameters()
get all parameters (in array)
getMobId()
get id of parent media object
getMapAreasXML($a_insert_inst=false, $a_inst=0)
get xml code of media items' areas
setHeight($a_height)
set height
getTextRepresentation()
Get text representation.
create()
create persistent media item
getOriginalSize()
get original size
static _getThumbnailDirectory($a_mob_id, $a_mode="filesystem")
get directory for files of media object (static)
static _getDirectory($a_mob_id)
Get absolute directory.
static _createThumbnailDirectory($a_obj_id)
Create thumbnail directory.
static getDataDir()
get data directory (outside webspace)
static convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
static assembleParameterString($a_par_arr)
static getGDSupportedImageType($a_desired_type)
returns the best supported image type by this PHP build
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static extractParameterString($a_parstr)
extracts parameter value pairs from a string into an array
static deducibleSize($a_mime)
checks if mime type is provided by getimagesize()
static createDirectory($a_dir, $a_mod=0755)
create directory
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
$links
$query
global $DIC
Definition: saml.php:7
global $ilDB
$a_type
Definition: workflow.php:92