ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
46 public function __construct($a_id = 0)
47 {
48 global $DIC;
49
50 $this->db = $DIC->database();
51 $this->lng = $DIC->language();
52 $this->parameters = array();
53 $this->mapareas = array();
54 $this->map_cnt = 0;
55
56 if ($a_id != 0) {
57 $this->setId($a_id);
58 $this->read();
59 }
60 }
61
67 public function setId($a_id)
68 {
69 $this->id = $a_id;
70 }
71
77 public function getId()
78 {
79 return $this->id;
80 }
81
87 public function setMobId($a_mob_id)
88 {
89 $this->mob_id = $a_mob_id;
90 }
91
97 public function getMobId()
98 {
99 return $this->mob_id;
100 }
101
105 public function setNr($a_nr)
106 {
107 $this->nr = $a_nr;
108 }
109
110 public function getNr()
111 {
112 return $this->nr;
113 }
114
120 public function setTextRepresentation($a_val)
121 {
122 $this->text_representation = $a_val;
123 }
124
130 public function getTextRepresentation()
131 {
132 return $this->text_representation;
133 }
134
135
139 public function create()
140 {
142
143 $item_id = $ilDB->nextId("media_item");
144 $query = "INSERT INTO media_item (id,mob_id, purpose, location, " .
145 "location_type, format, width, " .
146 "height, halign, caption, nr, text_representation) VALUES " .
147 "(" .
148 $ilDB->quote($item_id, "integer") . "," .
149 $ilDB->quote($this->getMobId(), "integer") . "," .
150 $ilDB->quote($this->getPurpose(), "text") . "," .
151 $ilDB->quote($this->getLocation(), "text") . "," .
152 $ilDB->quote($this->getLocationType(), "text") . "," .
153 $ilDB->quote($this->getFormat(), "text") . "," .
154 $ilDB->quote($this->getWidth(), "text") . "," .
155 $ilDB->quote($this->getHeight(), "text") . "," .
156 $ilDB->quote($this->getHAlign(), "text") . "," .
157 $ilDB->quote($this->getCaption(), "text") . "," .
158 $ilDB->quote($this->getNr(), "integer") . "," .
159 $ilDB->quote($this->getTextRepresentation(), "text") . ")";
160 $ilDB->manipulate($query);
161
162 $this->setId($item_id);
163
164 // create mob parameters
165 $params = $this->getParameters();
166 foreach ($params as $name => $value) {
167 $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
168 "(" . $ilDB->quote($item_id, "integer") . "," .
169 $ilDB->quote($name, "text") . "," .
170 $ilDB->quote($value, "text") . ")";
171 $ilDB->manipulate($query);
172 }
173
174 // create map areas
175 for ($i=0; $i < count($this->mapareas); $i++) {
176 if (is_object($this->mapareas[$i])) {
177 $this->mapareas[$i]->setItemId($this->getId());
178 $this->mapareas[$i]->setNr($i + 1);
179 $this->mapareas[$i]->create();
180 }
181 }
182 }
183
187 public function update()
188 {
190
191 $query = "UPDATE media_item SET " .
192 " mob_id = " . $ilDB->quote($this->getMobId(), "integer") . "," .
193 " purpose = " . $ilDB->quote($this->getPurpose(), "text") . "," .
194 " location = " . $ilDB->quote($this->getLocation(), "text") . "," .
195 " location_type = " . $ilDB->quote($this->getLocationType(), "text") . "," .
196 " format = " . $ilDB->quote($this->getFormat(), "text") . "," .
197 " width = " . $ilDB->quote($this->getWidth(), "text") . "," .
198 " height = " . $ilDB->quote($this->getHeight(), "text") . "," .
199 " halign = " . $ilDB->quote($this->getHAlign(), "text") . "," .
200 " caption = " . $ilDB->quote($this->getCaption(), "text") . "," .
201 " nr = " . $ilDB->quote($this->getNr(), "integer") . "," .
202 " text_representation = " . $ilDB->quote($this->getTextRepresentation(), "text") .
203 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
204 $ilDB->manipulate($query);
205
206 // delete mob parameters
207 $query = "DELETE FROM mob_parameter WHERE med_item_id = " .
208 $ilDB->quote($this->getId(), "integer");
209
210 // create mob parameters
211 $params = $this->getParameters();
212 foreach ($params as $name => $value) {
213 $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
214 "(" . $ilDB->quote($this->getId(), "integer") . "," .
215 $ilDB->quote($name, "text") . "," .
216 $ilDB->quote($value, "text") . ")";
217 $ilDB->manipulate($query);
218 }
219 }
220
227 public function writeParameter($a_name, $a_value)
228 {
230
231 $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
232 "(" . $ilDB->quote($this->getId(), "integer") . "," .
233 $ilDB->quote($a_name, "text") . "," .
234 $ilDB->quote($a_value, "text") . ")";
235 $ilDB->manipulate($query);
236 }
237
241 public function read()
242 {
244
245 $item_id = $this->getId();
246 $mob_id = $this->getMobId();
247 $nr = $this->getNr();
248 $query = "";
249 if ($item_id > 0) {
250 $query = "SELECT * FROM media_item WHERE id = " .
251 $ilDB->quote($this->getId(), "integer");
252 } elseif ($mob_id > 0 && $nr > 0) {
253 $query = "SELECT * FROM media_item WHERE mob_id = " .
254 $ilDB->quote($this->getMobId(), "integer") . " " .
255 "AND nr=" . $ilDB->quote($this->getNr(), "integer");
256 }
257 if ($query != "") {
258 $item_set = $ilDB->query($query);
259 $item_rec = $ilDB->fetchAssoc($item_set);
260
261 $this->setLocation($item_rec["location"]);
262 $this->setLocationType($item_rec["location_type"]);
263 $this->setFormat($item_rec["format"]);
264 $this->setWidth($item_rec["width"]);
265 $this->setHeight($item_rec["height"]);
266 $this->setHAlign($item_rec["halign"]);
267 $this->setCaption($item_rec["caption"]);
268 $this->setPurpose($item_rec["purpose"]);
269 $this->setNr($item_rec["nr"]);
270 $this->setMobId($item_rec["mob_id"]);
271 $this->setId($item_rec["id"]);
272 $this->setThumbTried($item_rec["tried_thumb"]);
273 $this->setTextRepresentation($item_rec["text_representation"]);
274
275 // get item parameter
276 $query = "SELECT * FROM mob_parameter WHERE med_item_id = " .
277 $ilDB->quote($this->getId(), "integer");
278 $par_set = $ilDB->query($query);
279 while ($par_rec = $ilDB->fetchAssoc($par_set)) {
280 $this->setParameter($par_rec["name"], $par_rec["value"]);
281 }
282
283 // get item map areas
284 $max = ilMapArea::_getMaxNr($this->getId());
285 for ($i = 1; $i <= $max; $i++) {
286 $area = new ilMapArea($this->getId(), $i);
287 $this->addMapArea($area);
288 }
289 }
290 }
291
295 public function writeThumbTried($a_tried)
296 {
298
299 $q = "UPDATE media_item SET tried_thumb = " .
300 $ilDB->quote($a_tried, "text") .
301 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
302
303 $ilDB->manipulate($q);
304 }
305
312 public static function _lookupLocationForMobId($a_mob_id, $a_purpose)
313 {
314 global $DIC;
315
316 $ilDB = $DIC->database();
317
318 // read media_object record
319 $query = "SELECT * FROM media_item WHERE mob_id = " .
320 $ilDB->quote($a_mob_id, "integer") . " " .
321 "AND purpose = " . $ilDB->quote($a_purpose, "text");
322 $set = $ilDB->query($query);
323 if ($rec = $ilDB->fetchAssoc($set)) {
324 return $rec["location"];
325 }
326
327 return "";
328 }
329
335 public static function _lookupMobId($a_med_id)
336 {
337 global $DIC;
338
339 $ilDB = $DIC->database();
340
341 // read media_object record
342 $query = "SELECT * FROM media_item WHERE id = " .
343 $ilDB->quote($a_med_id, "integer");
344 $set = $ilDB->query($query);
345 if ($rec = $ilDB->fetchAssoc($set)) {
346 return $rec["mob_id"];
347 }
348
349 return "";
350 }
351
352 /* read media item with specific purpose and mobId
353 *
354 * @param integer $a_mobId media object id
355 * @param string $a_purpose media object purpose
356 * @return array $mob media object
357 */
358 public static function _getMediaItemsOfMObId($a_mobId, $a_purpose)
359 {
360 global $DIC;
361
362 $ilDB = $DIC->database();
363
364 // read media_object record
365 $query = "SELECT * FROM media_item WHERE mob_id = " .
366 $ilDB->quote($a_mobId, "integer") . " " .
367 "AND purpose=" . $ilDB->quote($a_purpose, "text") . " ORDER BY nr";
368 $item_set = $ilDB->query($query);
369
370 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
371 return $item_rec;
372 }
373 return false;
374 }
375
381 public static function _getMediaItemsOfMOb(&$a_mob)
382 {
383 global $DIC;
384
385 $ilDB = $DIC->database();
386
387 // read media_object record
388 $query = "SELECT * FROM media_item WHERE mob_id = " .
389 $ilDB->quote($a_mob->getId(), "integer") . " " .
390 "ORDER BY nr";
391 $item_set = $ilDB->query($query);
392 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
393 $media_item = new ilMediaItem();
394 $media_item->setNr($item_rec["nr"]);
395 $media_item->setId($item_rec["id"]);
396 $media_item->setLocation($item_rec["location"]);
397 $media_item->setLocationType($item_rec["location_type"]);
398 $media_item->setFormat($item_rec["format"]);
399 $media_item->setWidth($item_rec["width"]);
400 $media_item->setHeight($item_rec["height"]);
401 $media_item->setHAlign($item_rec["halign"]);
402 $media_item->setCaption($item_rec["caption"]);
403 $media_item->setPurpose($item_rec["purpose"]);
404 $media_item->setMobId($item_rec["mob_id"]);
405 $media_item->setThumbTried($item_rec["tried_thumb"]);
406 $media_item->setTextRepresentation($item_rec["text_representation"]);
407
408 // get item parameter
409 $query = "SELECT * FROM mob_parameter WHERE med_item_id = " .
410 $ilDB->quote($item_rec["id"], "integer");
411 $par_set = $ilDB->query($query);
412 while ($par_rec = $ilDB->fetchAssoc($par_set)) {
413 $media_item->setParameter($par_rec["name"], $par_rec["value"]);
414 }
415
416 // get item map areas
417 $max = ilMapArea::_getMaxNr($media_item->getId());
418 for ($i = 1; $i <= $max; $i++) {
419 $area = new ilMapArea($media_item->getId(), $i);
420 $media_item->addMapArea($area);
421 }
422
423 // add media item to media object
424 $a_mob->addMediaItem($media_item);
425 }
426 }
427
433 public static function deleteAllItemsOfMob($a_mob_id)
434 {
435 global $DIC;
436
437 $ilDB = $DIC->database();
438
439 // iterate all media items ob mob
440 $query = "SELECT * FROM media_item WHERE mob_id = " .
441 $ilDB->quote($a_mob_id, "integer");
442 $item_set = $ilDB->query($query);
443 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
444 // delete all parameters of media item
445 $query = "DELETE FROM mob_parameter WHERE med_item_id = " .
446 $ilDB->quote($item_rec["id"], "integer");
447 $ilDB->manipulate($query);
448
449 // delete all map areas of media item
450 $query = "DELETE FROM map_area WHERE item_id = " .
451 $ilDB->quote($item_rec["id"], "integer");
452 $ilDB->manipulate($query);
453 }
454
455 // delete media items
456 $query = "DELETE FROM media_item WHERE mob_id = " .
457 $ilDB->quote($a_mob_id, "integer");
458 $ilDB->manipulate($query);
459 }
460
461 public function setPurpose($a_purpose)
462 {
463 $this->purpose = $a_purpose;
464 }
465
466 public function getPurpose()
467 {
468 return $this->purpose;
469 }
470
471 public function setLocation($a_location)
472 {
473 $this->location = $a_location;
474 }
475
476 public function getLocation()
477 {
478 return $this->location;
479 }
480
481 public function setLocationType($a_type)
482 {
483 $this->location_type = $a_type;
484 }
485
486 public function getLocationType()
487 {
489 }
490
491 public function setFormat($a_format)
492 {
493 $this->format = $a_format;
494 }
495
496 public function getFormat()
497 {
498 return $this->format;
499 }
500
501 public function setThumbTried($a_tried)
502 {
503 $this->tried_thumb = $a_tried;
504 }
505
506 public function getThumbTried()
507 {
508 return $this->tried_thumb;
509 }
510
511 public function addMapArea(&$a_map_area)
512 {
513 $this->mapareas[$this->map_cnt] = $a_map_area;
514 $this->map_cnt++;
515 }
516
520 public function deleteMapArea($nr)
521 {
522 for ($i=1; $i<=$this->map_cnt; $i++) {
523 if ($i > $nr) {
524 $this->mapareas[$i-2] = $this->mapareas[$i-1];
525 $this->mapareas[$i-2]->setNr($i-1);
526 }
527 }
528 if ($nr <= $this->map_cnt) {
529 unset($this->mapareas[$this->map_cnt - 1]);
530 $this->map_cnt--;
531 }
532 }
533
537 public function &getMapArea($nr)
538 {
539 return $this->mapareas[$nr-1];
540 }
541
545 public function getMapAreas()
546 {
547 return $this->mapareas;
548 }
549
553 public function getWidth()
554 {
555 return $this->width;
556 }
557
561 public function setWidth($a_width)
562 {
563 $this->width = $a_width;
564 }
565
569 public function getHeight()
570 {
571 return $this->height;
572 }
573
577 public function setHeight($a_height)
578 {
579 $this->height = $a_height;
580 }
581
585 public function getOriginalSize()
586 {
587 $mob_dir = ilObjMediaObject::_getDirectory($this->getMobId());
588
589 if (ilUtil::deducibleSize($this->getFormat())) {
590 if ($this->getLocationType() == "LocalFile") {
591 $loc = $mob_dir . "/" . $this->getLocation();
592 } else {
593 $loc = $this->getLocation();
594 }
595
596 include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
598 if ($size[0] > 0 && $size[1] > 0) {
599 return array("width" => $size[0], "height" => $size[1]);
600 }
601 }
602
603 return false;
604 }
605
609 public function setCaption($a_caption)
610 {
611 $this->caption = $a_caption;
612 }
613
617 public function getCaption()
618 {
619 return $this->caption;
620 }
621
625 public function setHAlign($a_halign)
626 {
627 $this->halign = $a_halign;
628 }
629
633 public function getHAlign()
634 {
635 return $this->halign;
636 }
637
638
645 public function setParameter($a_name, $a_value)
646 {
647 if (self::checkParameter($a_name, $a_value)) {
648 $this->parameters[$a_name] = $a_value;
649 }
650 }
651
655 public function resetParameters()
656 {
657 $this->parameters = array();
658 }
659
665 public function setParameters($a_par)
666 {
667 $this->resetParameters();
668 $par_arr = ilUtil::extractParameterString($a_par);
669 if (is_array($par_arr)) {
670 foreach ($par_arr as $par => $val) {
671 $this->setParameter($par, $val);
672 }
673 }
674 }
675
683 public static function checkParameter($a_par, $a_val)
684 {
685 // do not allow event attributes
686 if (substr(strtolower(trim($a_par)), 0, 2) == "on") {
687 return false;
688 }
689 // no javascript in value
690 if (is_int(strpos(strtolower($a_val), "javascript"))) {
691 return false;
692 }
693 // do not allow to change the src attribute
694 if (in_array(strtolower(trim($a_par)), array("src"))) {
695 return false;
696 }
697
698 return true;
699 }
700
701
705 public function getParameters()
706 {
707 return $this->parameters;
708 }
709
710
714 public function getParameterString()
715 {
716 return ilUtil::assembleParameterString($this->parameters);
717 }
718
719
723 public function getParameter($a_name)
724 {
725 return $this->parameters[$a_name];
726 }
727
731 public function getWorkDirectory()
732 {
733 return ilUtil::getDataDir() . "/map_workfiles/item_" . $this->getId();
734 }
735
739 public function createWorkDirectory()
740 {
741 if (!@is_dir(ilUtil::getDataDir() . "/map_workfiles")) {
742 ilUtil::createDirectory(ilUtil::getDataDir() . "/map_workfiles");
743 }
744 $work_dir = $this->getWorkDirectory();
745 if (!@is_dir($work_dir)) {
746 ilUtil::createDirectory($work_dir);
747 }
748 }
749
753 public function getSuffix()
754 {
755 $loc_arr = explode(".", $this->getLocation());
756
757 return $loc_arr[count($loc_arr) - 1];
758 }
759
763 public function getMapWorkCopyType()
764 {
766 }
767
773 public function getMapWorkCopyName($a_reference_copy = false)
774 {
775 $file_arr = explode("/", $this->getLocation());
776 $o_file = $file_arr[count($file_arr) - 1];
777 $file_arr = explode(".", $o_file);
778 unset($file_arr[count($file_arr) - 1]);
779 $file = implode($file_arr, ".");
780
781 if (!$a_reference_copy) {
782 return $this->getWorkDirectory() . "/" . $file . "." . $this->getMapWorkCopyType();
783 } else {
784 return $this->getWorkDirectory() . "/l_copy_" . $o_file;
785 }
786 }
787
791 public function getDirectory()
792 {
794 }
795
799 public function getThumbnailDirectory($a_mode = "filesystem")
800 {
801 return ilObjMediaObject::_getThumbnailDirectory($this->getMobId(), $a_mode);
802 }
803
807 public function getThumbnailTarget($a_size = "")
808 {
809 if (is_int(strpos($this->getFormat(), "image"))) {
810 $thumb_file = $this->getThumbnailDirectory() . "/" .
811 $this->getPurpose() . ".jpeg";
812
813 $thumb_file_small = $this->getThumbnailDirectory() . "/" .
814 $this->getPurpose() . "_small.jpeg";
815
816 // generate thumbnail (if not tried before)
817 if ($this->getThumbTried() == "n" && $this->getLocationType() == "LocalFile") {
818 if (is_file($thumb_file)) {
819 unlink($thumb_file);
820 }
821 if (is_file($thumb_file_small)) {
822 unlink($thumb_file_small);
823 }
824 $this->writeThumbTried("y");
826 $med_file = $this->getDirectory() . "/" . $this->getLocation();
827
828 if (is_file($med_file)) {
829 ilUtil::convertImage($med_file, $thumb_file, "jpeg", "80");
830 ilUtil::convertImage($med_file, $thumb_file_small, "jpeg", "40");
831 }
832 }
833
834 if ($a_size == "small") {
835 if (is_file($thumb_file_small)) {
836 $random = new \ilRandom();
837 return $this->getThumbnailDirectory("output") . "/" .
838 $this->getPurpose() . "_small.jpeg?dummy=" . $random->int(1, 999999);
839 }
840 } else {
841 if (is_file($thumb_file)) {
842 $random = new \ilRandom();
843 return $this->getThumbnailDirectory("output") . "/" .
844 $this->getPurpose() . ".jpeg?dummy=" . $random->int(1, 999999);
845 }
846 }
847 }
848
849 return "";
850 }
851
852
856 public function copyOriginal()
857 {
859 $this->createWorkDirectory();
860
861 $geom = ($this->getWidth() != "" && $this->getHeight() != "")
862 ? $this->getWidth() . "x" . $this->getHeight()
863 : "";
864
865 if ($this->getLocationType() != "Reference") {
867 $this->getDirectory() . "/" . $this->getLocation(),
868 $this->getMapWorkCopyName(),
869 $this->getMapWorkCopyType(),
870 $geom
871 );
872 } else {
873 // first copy the external file, if necessary
874 if (!is_file($this->getMapWorkCopyName(true)) || (filesize($this->getMapWorkCopyName(true)) == 0)) {
875 $handle = @fopen($this->getLocation(), "r");
876 $lcopy = fopen($this->getMapWorkCopyName(true), "w");
877 if ($handle && $lcopy) {
878 while (!feof($handle)) {
879 $content = fread($handle, 4096);
880 fwrite($lcopy, $content);
881 }
882 }
883 @fclose($lcopy);
884 @fclose($handle);
885 }
886
887 // now, create working copy
889 $this->getMapWorkCopyName(true),
890 $this->getMapWorkCopyName(),
891 $this->getMapWorkCopyType(),
892 $geom
893 );
894 }
895
896 if (!is_file($this->getMapWorkCopyName())) {
897 ilUtil::sendFailure($lng->txt("cont_map_file_not_generated"));
898 return false;
899 }
900 return true;
901 }
902
909 public function makeMapWorkCopy($a_area_nr = 0, $a_exclude = false)
910 {
912
913 if (!$this->copyOriginal()) {
914 return false;
915 }
916 $this->buildMapWorkImage();
917
918 // determine ratios
919 $size = @getimagesize($this->getMapWorkCopyName());
920 $x_ratio = 1;
921 if ($size[0] > 0 && $this->getWidth() > 0) {
922 $x_ratio = $this->getWidth() / $size[0];
923 }
924 $y_ratio = 1;
925 if ($size[1] > 0 && $this->getHeight() > 0) {
926 $y_ratio = $this->getHeight() / $size[1];
927 }
928
929 // draw map areas
930 for ($i=0; $i < count($this->mapareas); $i++) {
931 if (((($i+1) == $a_area_nr) && !$a_exclude) ||
932 ((($i+1) != $a_area_nr) && $a_exclude) ||
933 ($a_area_nr == 0)
934 ) {
935 $area = $this->mapareas[$i];
936 $area->draw(
937 $this->getMapWorkImage(),
940 true,
941 $x_ratio,
942 $y_ratio
943 );
944 }
945 }
946
947 $this->saveMapWorkImage();
948
949 return true;
950 }
951
952
959 public function addAreaToMapWorkCopy($a_shape, $a_coords)
960 {
961 $this->buildMapWorkImage();
962
963 // determine ratios
964 $size = @getimagesize($this->getMapWorkCopyName());
965 $x_ratio = 1;
966 if ($size[0] > 0 && $this->getWidth() > 0) {
967 $x_ratio = $this->getWidth() / $size[0];
968 }
969 $y_ratio = 1;
970 if ($size[1] > 0 && $this->getHeight() > 0) {
971 $y_ratio = $this->getHeight() / $size[1];
972 }
973
974 // add new area to work image
975 $area = new ilMapArea();
976 $area->setShape($a_shape);
977 $area->setCoords($a_coords);
978 $area->draw(
979 $this->getMapWorkImage(),
980 $this->color1,
981 $this->color2,
982 false,
983 $x_ratio,
984 $y_ratio
985 );
986
987 $this->saveMapWorkImage();
988 }
989
993 public function outputMapWorkCopy()
994 {
995 if ($this->getMapWorkCopyType() != "") {
996 header("Pragma: no-cache");
997 header("Expires: 0");
998 header("Content-type: image/" . strtolower($this->getMapWorkCopyType()));
999 readfile($this->getMapWorkCopyName());
1000 }
1001 exit;
1002 }
1003
1007 public function buildMapWorkImage()
1008 {
1009 $im_type = strtolower($this->getMapWorkCopyType());
1010
1011 switch ($im_type) {
1012 case "gif":
1013 $this->map_image = ImageCreateFromGIF($this->getMapWorkCopyName());
1014 break;
1015
1016 case "jpg":
1017 case "jpeg":
1018 $this->map_image = ImageCreateFromJPEG($this->getMapWorkCopyName());
1019 break;
1020
1021 case "png":
1022 $this->map_image = ImageCreateFromPNG($this->getMapWorkCopyName());
1023 break;
1024 }
1025
1026 // try to allocate black and white as color. if this is not possible, get the closest colors
1027 if (imagecolorstotal($this->map_image) > 250) {
1028 $this->color1 = imagecolorclosest($this->map_image, 0, 0, 0);
1029 $this->color2 = imagecolorclosest($this->map_image, 255, 255, 255);
1030 } else {
1031 $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
1032 $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
1033 }
1034 }
1035
1039 public function saveMapWorkImage()
1040 {
1041 $im_type = strtolower($this->getMapWorkCopyType());
1042
1043 // save image work-copy and free memory
1044 switch ($im_type) {
1045 case "gif":
1046 ImageGIF($this->map_image, $this->getMapWorkCopyName());
1047 break;
1048
1049 case "jpg":
1050 case "jpeg":
1051 ImageJPEG($this->map_image, $this->getMapWorkCopyName());
1052 break;
1053
1054 case "png":
1055 ImagePNG($this->map_image, $this->getMapWorkCopyName());
1056 break;
1057 }
1058
1059 ImageDestroy($this->map_image);
1060 }
1061
1065 public function &getMapWorkImage()
1066 {
1067 return $this->map_image;
1068 }
1069
1070
1074 public function getMapAreasXML($a_insert_inst = false, $a_inst = 0)
1075 {
1076 $xml = "";
1077
1078 // build xml of map areas
1079 for ($i=0; $i < count($this->mapareas); $i++) {
1080 $area = $this->mapareas[$i];
1081
1082 // highlight mode
1083 $hm = "";
1084 if ($area->getHighlightMode() != "") {
1085 $hm = ' HighlightMode="' . $area->getHighlightMode() . '" ';
1086 $hcl = ($area->getHighlightClass() != "")
1087 ? $area->getHighlightClass()
1088 : "Accented";
1089 $hm.= 'HighlightClass="' . $hcl . '" ';
1090 }
1091
1092 $xml .= "<MapArea Shape=\"" . $area->getShape() . "\" Coords=\"" . $area->getCoords() . "\" " . $hm . ">";
1093 if ($area->getLinkType() == IL_INT_LINK) {
1094 $target_frame = $area->getTargetFrame();
1095
1096 if ($area->getType() == "GlossaryItem" && $target_frame == "") {
1097 $target_frame = "Glossary";
1098 }
1099
1100 $tf_str = ($target_frame == "")
1101 ? ""
1102 : "TargetFrame=\"" . $target_frame . "\"";
1103
1104 $xml .= "<IntLink Target=\"" . $area->getTarget($a_insert_inst, $a_inst) . "\" Type=\"" .
1105 $area->getType() . "\" $tf_str>";
1106 // see bug 17893 and http://stackoverflow.com/questions/4026502/xml-error-at-ampersand
1107 $xml .= htmlspecialchars($area->getTitle(), ENT_QUOTES);
1108 $xml .="</IntLink>";
1109 } else {
1110 $xml .= "<ExtLink Href=\"" . str_replace("&", "&amp;", $area->getHref()) . "\" Title=\"" .
1111 str_replace("&", "&amp;", $area->getExtTitle()) . "\">";
1112 $xml .= str_replace("&", "&amp;", $area->getTitle());
1113 $xml .="</ExtLink>";
1114 }
1115 $xml .= "</MapArea>";
1116 }
1117 return $xml;
1118 }
1119
1120
1126 public static function _resolveMapAreaLinks($a_mob_id)
1127 {
1128 global $DIC;
1129
1130 $ilDB = $DIC->database();
1131
1132 //echo "mediaItems::resolve<br>";
1133 // read media_object record
1134 $query = "SELECT * FROM media_item WHERE mob_id = " .
1135 $ilDB->quote($a_mob_id, "integer") . " " .
1136 "ORDER BY nr";
1137 $item_set = $ilDB->query($query);
1138 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
1139 ilMapArea::_resolveIntLinks($item_rec["id"]);
1140 }
1141 }
1142
1148 public static function _getMapAreasIntLinks($a_mob_id)
1149 {
1150 global $DIC;
1151
1152 $ilDB = $DIC->database();
1153
1154 // read media_items records
1155 $query = "SELECT * FROM media_item WHERE mob_id = " .
1156 $ilDB->quote($a_mob_id, "integer") . " ORDER BY nr";
1157
1158 $item_set = $ilDB->query($query);
1159 $links = array();
1160 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
1161 $map_links = ilMapArea::_getIntLinks($item_rec["id"]);
1162 foreach ($map_links as $key => $map_link) {
1163 $links[$key] = $map_link;
1164 }
1165 }
1166 return $links;
1167 }
1168
1172 public function extractUrlParameters()
1173 {
1174 include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
1176 $this->getLocation(),
1177 $this->getParameters()
1178 );
1179 foreach ($par as $k => $v) {
1180 $this->setParameter($k, $v);
1181 }
1182 }
1183}
$size
Definition: RandomTest.php:84
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
getWidth()
get width
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 directory for files of media object (static)
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
if($format !==null) $name
Definition: metadata.php:146
$xml
Definition: metadata.php:240
$query
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC
Definition: saml.php:7
global $ilDB
$a_type
Definition: workflow.php:92
$params
Definition: disable.php:11