ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
4 require_once("Services/MediaObjects/classes/class.ilMapArea.php");
5 
17 {
18  var $id;
19  var $purpose;
20  var $location;
22  var $format;
23  var $width;
24  var $height;
25  var $caption;
26  var $halign;
28  var $mob_id;
29  var $nr;
30  var $mapareas;
31  var $map_cnt;
32  var $map_image; // image map work copy image
33  var $color1; // map area line color 1
34  var $color2; // map area line color 2
35 
36  function ilMediaItem($a_id = 0)
37  {
38  $this->parameters = array();
39  $this->mapareas = array();
40  $this->map_cnt = 0;
41 
42  if ($a_id != 0)
43  {
44  $this->setId($a_id);
45  $this->read();
46  }
47  }
48 
54  function setId($a_id)
55  {
56  $this->id = $a_id;
57  }
58 
64  function getId()
65  {
66  return $this->id;
67  }
68 
74  function setMobId($a_mob_id)
75  {
76  $this->mob_id = $a_mob_id;
77  }
78 
84  function getMobId()
85  {
86  return $this->mob_id;
87  }
88 
92  function setNr($a_nr)
93  {
94  $this->nr = $a_nr;
95  }
96 
97  function getNr()
98  {
99  return $this->nr;
100  }
101 
107  function setTextRepresentation($a_val)
108  {
109  $this->text_representation = $a_val;
110  }
111 
118  {
119  return $this->text_representation;
120  }
121 
122 
126  function create()
127  {
128  global $ilDB;
129 
130  $item_id = $ilDB->nextId("media_item");
131  $query = "INSERT INTO media_item (id,mob_id, purpose, location, ".
132  "location_type, format, width, ".
133  "height, halign, caption, nr, text_representation) VALUES ".
134  "(".
135  $ilDB->quote($item_id, "integer").",".
136  $ilDB->quote($this->getMobId(), "integer").",".
137  $ilDB->quote($this->getPurpose(), "text").",".
138  $ilDB->quote($this->getLocation(), "text").",".
139  $ilDB->quote($this->getLocationType(), "text").",".
140  $ilDB->quote($this->getFormat(), "text").",".
141  $ilDB->quote($this->getWidth(), "text").",".
142  $ilDB->quote($this->getHeight(), "text").",".
143  $ilDB->quote($this->getHAlign(), "text").",".
144  $ilDB->quote($this->getCaption(), "text").",".
145  $ilDB->quote($this->getNr(), "integer").",".
146  $ilDB->quote($this->getTextRepresentation(), "text").")";
147  $ilDB->manipulate($query);
148 
149  $this->setId($item_id);
150 
151  // create mob parameters
152  $params = $this->getParameters();
153  foreach($params as $name => $value)
154  {
155  $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES ".
156  "(".$ilDB->quote($item_id, "integer").",".
157  $ilDB->quote($name, "text").",".
158  $ilDB->quote($value, "text").")";
159  $ilDB->manipulate($query);
160  }
161 
162  // create map areas
163  for ($i=0; $i < count($this->mapareas); $i++)
164  {
165  if (is_object($this->mapareas[$i]))
166  {
167  $this->mapareas[$i]->setItemId($this->getId());
168  $this->mapareas[$i]->setNr($i + 1);
169  $this->mapareas[$i]->create();
170  }
171  }
172  }
173 
177  function update()
178  {
179  global $ilDB;
180 
181  $query = "UPDATE media_item SET ".
182  " mob_id = ".$ilDB->quote($this->getMobId(), "integer").",".
183  " purpose = ".$ilDB->quote($this->getPurpose(), "text").",".
184  " location = ".$ilDB->quote($this->getLocation(), "text").",".
185  " location_type = ".$ilDB->quote($this->getLocationType(), "text").",".
186  " format = ".$ilDB->quote($this->getFormat(), "text").",".
187  " width = ".$ilDB->quote($this->getWidth(), "text").",".
188  " height = ".$ilDB->quote($this->getHeight(), "text").",".
189  " halign = ".$ilDB->quote($this->getHAlign(), "text").",".
190  " caption = ".$ilDB->quote($this->getCaption(), "text").",".
191  " nr = ".$ilDB->quote($this->getNr(), "integer").",".
192  " text_representation = ".$ilDB->quote($this->getTextRepresentation(), "text").
193  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
194  $ilDB->manipulate($query);
195 
196  // delete mob parameters
197  $query = "DELETE FROM mob_parameter WHERE med_item_id = ".
198  $ilDB->quote($this->getId(), "integer");
199 
200  // create mob parameters
201  $params = $this->getParameters();
202  foreach($params as $name => $value)
203  {
204  $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES ".
205  "(".$ilDB->quote($this->getId(), "integer").",".
206  $ilDB->quote($name, "text").",".
207  $ilDB->quote($value, "text").")";
208  $ilDB->manipulate($query);
209  }
210  }
211 
218  function writeParameter($a_name, $a_value)
219  {
220  global $ilDB;
221 
222  $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES ".
223  "(".$ilDB->quote($this->getId(), "integer").",".
224  $ilDB->quote($a_name, "text").",".
225  $ilDB->quote($a_value, "text").")";
226  $ilDB->manipulate($query);
227  }
228 
232  function read()
233  {
234  global $ilDB;
235 
236  $item_id = $this->getId();
237  $mob_id = $this->getMobId();
238  $nr = $this->getNr();
239  $query = "";
240  if($item_id > 0)
241  {
242  $query = "SELECT * FROM media_item WHERE id = ".
243  $ilDB->quote($this->getId(), "integer");
244  }
245  else if ($mob_id > 0 && $nr > 0)
246  {
247  $query = "SELECT * FROM media_item WHERE mob_id = ".
248  $ilDB->quote($this->getMobId(), "integer")." ".
249  "AND nr=".$ilDB->quote($this->getNr(), "integer");
250  }
251  if ($query != "")
252  {
253  $item_set = $ilDB->query($query);
254  $item_rec = $ilDB->fetchAssoc($item_set);
255 
256  $this->setLocation($item_rec["location"]);
257  $this->setLocationType($item_rec["location_type"]);
258  $this->setFormat($item_rec["format"]);
259  $this->setWidth($item_rec["width"]);
260  $this->setHeight($item_rec["height"]);
261  $this->setHAlign($item_rec["halign"]);
262  $this->setCaption($item_rec["caption"]);
263  $this->setPurpose($item_rec["purpose"]);
264  $this->setNr($item_rec["nr"]);
265  $this->setMobId($item_rec["mob_id"]);
266  $this->setId($item_rec["id"]);
267  $this->setThumbTried($item_rec["tried_thumb"]);
268  $this->setTextRepresentation($item_rec["text_representation"]);
269 
270  // get item parameter
271  $query = "SELECT * FROM mob_parameter WHERE med_item_id = ".
272  $ilDB->quote($this->getId(), "integer");
273  $par_set = $ilDB->query($query);
274  while ($par_rec = $ilDB->fetchAssoc($par_set))
275  {
276  $this->setParameter($par_rec["name"], $par_rec["value"]);
277  }
278 
279  // get item map areas
280  $max = ilMapArea::_getMaxNr($this->getId());
281  for ($i = 1; $i <= $max; $i++)
282  {
283  $area =& new ilMapArea($this->getId(), $i);
284  $this->addMapArea($area);
285  }
286  }
287 
288  }
289 
293  function writeThumbTried($a_tried)
294  {
295  global $ilDB;
296 
297  $q = "UPDATE media_item SET tried_thumb = ".
298  $ilDB->quote($a_tried, "text").
299  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
300 
301  $ilDB->manipulate($q);
302  }
303 
310  static function _lookupLocationForMobId($a_mob_id, $a_purpose)
311  {
312  global $ilDB;
313 
314  // read media_object record
315  $query = "SELECT * FROM media_item WHERE mob_id = ".
316  $ilDB->quote($a_mob_id, "integer")." ".
317  "AND purpose = ".$ilDB->quote($a_purpose, "text");
318  $set = $ilDB->query($query);
319  if ($rec = $ilDB->fetchAssoc($set))
320  {
321  return $rec["location"];
322  }
323 
324  return "";
325  }
326 
332  static function _lookupMobId($a_med_id)
333  {
334  global $ilDB;
335 
336  // read media_object record
337  $query = "SELECT * FROM media_item WHERE id = ".
338  $ilDB->quote($a_med_id, "integer");
339  $set = $ilDB->query($query);
340  if ($rec = $ilDB->fetchAssoc($set))
341  {
342  return $rec["mob_id"];
343  }
344 
345  return "";
346  }
347 
348  /* read media item with specific purpose and mobId
349  *
350  * @param integer $a_mobId media object id
351  * @param string $a_purpose media object purpose
352  * @return array $mob media object
353  */
354  function _getMediaItemsOfMObId($a_mobId, $a_purpose)
355  {
356  global $ilDB;
357 
358  // read media_object record
359  $query = "SELECT * FROM media_item WHERE mob_id = ".
360  $ilDB->quote($a_mobId, "integer")." ".
361  "AND purpose=" . $ilDB->quote($a_purpose, "text")." ORDER BY nr";
362  $item_set = $ilDB->query($query);
363 
364  while ($item_rec = $ilDB->fetchAssoc($item_set))
365  {
366  return $item_rec;
367  }
368  return false;
369  }
370 
376  function _getMediaItemsOfMOb(&$a_mob)
377  {
378  global $ilDB;
379 
380  // read media_object record
381  $query = "SELECT * FROM media_item WHERE mob_id = ".
382  $ilDB->quote($a_mob->getId(), "integer")." ".
383  "ORDER BY nr";
384  $item_set = $ilDB->query($query);
385  while ($item_rec = $ilDB->fetchAssoc($item_set))
386  {
387  $media_item =& new ilMediaItem();
388  $media_item->setNr($item_rec["nr"]);
389  $media_item->setId($item_rec["id"]);
390  $media_item->setLocation($item_rec["location"]);
391  $media_item->setLocationType($item_rec["location_type"]);
392  $media_item->setFormat($item_rec["format"]);
393  $media_item->setWidth($item_rec["width"]);
394  $media_item->setHeight($item_rec["height"]);
395  $media_item->setHAlign($item_rec["halign"]);
396  $media_item->setCaption($item_rec["caption"]);
397  $media_item->setPurpose($item_rec["purpose"]);
398  $media_item->setMobId($item_rec["mob_id"]);
399  $media_item->setThumbTried($item_rec["tried_thumb"]);
400  $media_item->setTextRepresentation($item_rec["text_representation"]);
401 
402  // get item parameter
403  $query = "SELECT * FROM mob_parameter WHERE med_item_id = ".
404  $ilDB->quote($item_rec["id"], "integer");
405  $par_set = $ilDB->query($query);
406  while ($par_rec = $ilDB->fetchAssoc($par_set))
407  {
408  $media_item->setParameter($par_rec["name"], $par_rec["value"]);
409  }
410 
411  // get item map areas
412  $max = ilMapArea::_getMaxNr($media_item->getId());
413  for ($i = 1; $i <= $max; $i++)
414  {
415  $area =& new ilMapArea($media_item->getId(), $i);
416  $media_item->addMapArea($area);
417  }
418 
419  // add media item to media object
420  $a_mob->addMediaItem($media_item);
421  }
422  }
423 
427  function deleteAllItemsOfMob($a_mob_id)
428  {
429  global $ilDB;
430 
431  // iterate all media items ob mob
432  $query = "SELECT * FROM media_item WHERE mob_id = ".
433  $ilDB->quote($a_mob_id, "integer");
434  $item_set = $ilDB->query($query);
435  while ($item_rec = $ilDB->fetchAssoc($item_set))
436  {
437  // delete all parameters of media item
438  $query = "DELETE FROM mob_parameter WHERE med_item_id = ".
439  $ilDB->quote($item_rec["id"], "integer");
440  $ilDB->manipulate($query);
441 
442  // delete all map areas of media item
443  $query = "DELETE FROM map_area WHERE item_id = ".
444  $ilDB->quote($item_rec["id"], "integer");
445  $ilDB->manipulate($query);
446  }
447 
448  // delete media items
449  $query = "DELETE FROM media_item WHERE mob_id = ".
450  $ilDB->quote($a_mob_id, "integer");
451  $ilDB->manipulate($query);
452  }
453 
454  function setPurpose($a_purpose)
455  {
456  $this->purpose = $a_purpose;
457  }
458 
459  function getPurpose()
460  {
461  return $this->purpose;
462  }
463 
464  function setLocation($a_location)
465  {
466  $this->location = $a_location;
467  }
468 
469  function getLocation()
470  {
471  return $this->location;
472  }
473 
474  function setLocationType($a_type)
475  {
476  $this->location_type = $a_type;
477  }
478 
479  function getLocationType()
480  {
481  return $this->location_type;
482  }
483 
484  function setFormat($a_format)
485  {
486  $this->format = $a_format;
487  }
488 
489  function getFormat()
490  {
491  return $this->format;
492  }
493 
494  function setThumbTried($a_tried)
495  {
496  $this->tried_thumb = $a_tried;
497  }
498 
499  function getThumbTried()
500  {
501  return $this->tried_thumb;
502  }
503 
504  function addMapArea(&$a_map_area)
505  {
506  $this->mapareas[$this->map_cnt] =& $a_map_area;
507  $this->map_cnt++;
508  }
509 
513  function deleteMapArea($nr)
514  {
515  for ($i=1; $i<=$this->map_cnt; $i++)
516  {
517  if($i > $nr)
518  {
519  $this->mapareas[$i-2] =& $this->mapareas[$i-1];
520  $this->mapareas[$i-2]->setNr($i-1);
521  }
522  }
523  if($nr <= $this->map_cnt)
524  {
525  unset($this->mapareas[$this->map_cnt - 1]);
526  $this->map_cnt--;
527  }
528  }
529 
533  function &getMapArea($nr)
534  {
535  return $this->mapareas[$nr-1];
536  }
537 
541  function getMapAreas()
542  {
543  return $this->mapareas;
544  }
545 
549  function getWidth()
550  {
551  return $this->width;
552  }
553 
557  function setWidth($a_width)
558  {
559  $this->width = $a_width;
560  }
561 
565  function getHeight()
566  {
567  return $this->height;
568  }
569 
573  function setHeight($a_height)
574  {
575  $this->height = $a_height;
576  }
577 
581  function getOriginalSize()
582  {
583  $mob_dir = ilObjMediaObject::_getDirectory($this->getMobId());
584 
585  if (ilUtil::deducibleSize($this->getFormat()))
586  {
587  if ($this->getLocationType() == "LocalFile")
588  {
589  $loc = $mob_dir."/".$this->getLocation();
590  }
591  else
592  {
593  $loc = $this->getLocation();
594  }
595 
596  include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
598  if ($size[0] > 0 && $size[1] > 0)
599  {
600  return array("width" => $size[0], "height" => $size[1]);
601  }
602  }
603 
604  return false;
605  }
606 
610  function setCaption($a_caption)
611  {
612  $this->caption = $a_caption;
613  }
614 
618  function getCaption()
619  {
620  return $this->caption;
621  }
622 
626  function setHAlign($a_halign)
627  {
628  $this->halign = $a_halign;
629  }
630 
634  function getHAlign()
635  {
636  return $this->halign;
637  }
638 
639 
646  function setParameter($a_name, $a_value)
647  {
648  if (self::checkParameter($a_name, $a_value))
649  {
650  $this->parameters[$a_name] = $a_value;
651  }
652  }
653 
657  function resetParameters()
658  {
659  $this->parameters = array();
660  }
661 
667  function setParameters($a_par)
668  {
669  $this->resetParameters();
670  $par_arr = ilUtil::extractParameterString($a_par);
671  if(is_array($par_arr))
672  {
673  foreach($par_arr as $par => $val)
674  {
675  $this->setParameter($par, $val);
676  }
677  }
678  }
679 
687  static function checkParameter($a_par, $a_val)
688  {
689  // do not allow event attributes
690  if (substr(strtolower(trim($a_par)), 0, 2) == "on")
691  {
692  return false;
693  }
694  // no javascript in value
695  if (is_int(strpos(strtolower($a_val), "javascript")))
696  {
697  return false;
698  }
699  // do not allow to change the src attribute
700  if (in_array(strtolower(trim($a_par)), array("src")))
701  {
702  return false;
703  }
704 
705  return true;
706  }
707 
708 
712  function getParameters()
713  {
714  return $this->parameters;
715  }
716 
717 
722  {
723  return ilUtil::assembleParameterString($this->parameters);
724  }
725 
726 
730  function getParameter($a_name)
731  {
732  return $this->parameters[$a_name];
733  }
734 
738  function getWorkDirectory()
739  {
740  return ilUtil::getDataDir()."/map_workfiles/item_".$this->getId();
741  }
742 
747  {
748  if(!@is_dir(ilUtil::getDataDir()."/map_workfiles"))
749  {
750  ilUtil::createDirectory(ilUtil::getDataDir()."/map_workfiles");
751  }
752  $work_dir = $this->getWorkDirectory();
753  if(!@is_dir($work_dir))
754  {
755  ilUtil::createDirectory($work_dir);
756  }
757  }
758 
762  function getSuffix()
763  {
764  $loc_arr = explode(".", $this->getLocation());
765 
766  return $loc_arr[count($loc_arr) - 1];
767  }
768 
773  {
775  }
776 
782  function getMapWorkCopyName($a_reference_copy = false)
783  {
784  $file_arr = explode("/", $this->getLocation());
785  $o_file = $file_arr[count($file_arr) - 1];
786  $file_arr = explode(".", $o_file);
787  unset($file_arr[count($file_arr) - 1]);
788  $file = implode($file_arr, ".");
789 
790  if (!$a_reference_copy)
791  {
792  return $this->getWorkDirectory()."/".$file.".".$this->getMapWorkCopyType();
793  }
794  else
795  {
796  return $this->getWorkDirectory()."/l_copy_".$o_file;
797  }
798  }
799 
803  function getDirectory()
804  {
805  return ilObjMediaObject::_getDirectory($this->getMobId());
806  }
807 
811  function getThumbnailDirectory($a_mode = "filesystem")
812  {
813  return ilObjMediaObject::_getThumbnailDirectory($this->getMobId(), $a_mode);
814  }
815 
819  function getThumbnailTarget($a_size = "")
820  {
821  if (is_int(strpos($this->getFormat(), "image")))
822  {
823  $thumb_file = $this->getThumbnailDirectory()."/".
824  $this->getPurpose().".jpeg";
825 
826  $thumb_file_small = $this->getThumbnailDirectory()."/".
827  $this->getPurpose()."_small.jpeg";
828 
829  // generate thumbnail (if not tried before)
830  if ($this->getThumbTried() == "n" && $this->getLocationType() == "LocalFile")
831  {
832  if (is_file($thumb_file))
833  {
834  unlink($thumb_file);
835  }
836  if (is_file($thumb_file_small))
837  {
838  unlink($thumb_file_small);
839  }
840  $this->writeThumbTried("y");
842  $med_file = $this->getDirectory()."/".$this->getLocation();
843 
844  if (is_file($med_file))
845  {
846  ilUtil::convertImage($med_file, $thumb_file, "jpeg", "80");
847  ilUtil::convertImage($med_file, $thumb_file_small, "jpeg", "40");
848  }
849  }
850 
851  if ($a_size == "small")
852  {
853  if (is_file($thumb_file_small))
854  {
855  return $this->getThumbnailDirectory("output")."/".
856  $this->getPurpose()."_small.jpeg?dummy=".rand(1, 999999);
857  }
858  }
859  else
860  {
861  if (is_file($thumb_file))
862  {
863  return $this->getThumbnailDirectory("output")."/".
864  $this->getPurpose().".jpeg?dummy=".rand(1, 999999);
865  }
866  }
867  }
868 
869  return "";
870  }
871 
872 
876  function copyOriginal()
877  {
878  global $lng;
879  $this->createWorkDirectory();
880 
881  if ($this->getLocationType() != "Reference")
882  {
883  ilUtil::convertImage($this->getDirectory()."/".$this->getLocation(),
884  $this->getMapWorkCopyName(),
885  $this->getMapWorkCopyType());
886  }
887  else
888  {
889  // first copy the external file, if necessary
890  if (!is_file($this->getMapWorkCopyName(true)) || (filesize($this->getMapWorkCopyName(true)) == 0))
891  {
892  $handle = @fopen($this->getLocation(), "r");
893  $lcopy = fopen($this->getMapWorkCopyName(true), "w");
894  if ($handle && $lcopy)
895  {
896  while (!feof($handle))
897  {
898  $content = fread($handle, 4096);
899  fwrite($lcopy, $content);
900  }
901  }
902  @fclose($lcopy);
903  @fclose($handle);
904  }
905 
906  // now, create working copy
908  $this->getMapWorkCopyName(),
909  $this->getMapWorkCopyType());
910  }
911 
912  if (!is_file($this->getMapWorkCopyName()))
913  {
914 
915  ilUtil::sendFailure($lng->txt("cont_map_file_not_generated"));
916  return false;
917  }
918  return true;
919  }
920 
927  function makeMapWorkCopy($a_area_nr = 0, $a_exclude = false)
928  {
929  global $lng;
930 
931  if (!$this->copyOriginal())
932  {
933  return false;
934  }
935  $this->buildMapWorkImage();
936 
937  // determine ratios
938  $size = @getimagesize($this->getMapWorkCopyName());
939  $x_ratio = 1;
940  if ($size[0] > 0 && $this->getWidth() > 0)
941  {
942  $x_ratio = $this->getWidth() / $size[0];
943  }
944  $y_ratio = 1;
945  if ($size[1] > 0 && $this->getHeight() > 0)
946  {
947  $y_ratio = $this->getHeight() / $size[1];
948  }
949 
950  // draw map areas
951  for ($i=0; $i < count($this->mapareas); $i++)
952  {
953  if ( ((($i+1) == $a_area_nr) && !$a_exclude) ||
954  ((($i+1) != $a_area_nr) && $a_exclude) ||
955  ($a_area_nr == 0)
956  )
957  {
958  $area =& $this->mapareas[$i];
959  $area->draw($this->getMapWorkImage(), $this->color1, $this->color2, true,
960  $x_ratio, $y_ratio);
961  }
962  }
963 
964  $this->saveMapWorkImage();
965 
966  return true;
967  }
968 
969 
976  function addAreaToMapWorkCopy($a_shape, $a_coords)
977  {
978  $this->buildMapWorkImage();
979 
980  // determine ratios
981  $size = @getimagesize($this->getMapWorkCopyName());
982  $x_ratio = 1;
983  if ($size[0] > 0 && $this->getWidth() > 0)
984  {
985  $x_ratio = $this->getWidth() / $size[0];
986  }
987  $y_ratio = 1;
988  if ($size[1] > 0 && $this->getHeight() > 0)
989  {
990  $y_ratio = $this->getHeight() / $size[1];
991  }
992 
993  // add new area to work image
994  $area = new ilMapArea();
995  $area->setShape($a_shape);
996  $area->setCoords($a_coords);
997  $area->draw($this->getMapWorkImage(), $this->color1, $this->color2, false,
998  $x_ratio, $y_ratio);
999 
1000  $this->saveMapWorkImage();
1001  }
1002 
1007  {
1008  if ($this->getMapWorkCopyType() != "")
1009  {
1010  header("Pragma: no-cache");
1011  header("Expires: 0");
1012  header("Content-type: image/".strtolower($this->getMapWorkCopyType()));
1013  readfile($this->getMapWorkCopyName());
1014  }
1015  exit;
1016  }
1017 
1022  {
1023  $im_type = strtolower($this->getMapWorkCopyType());
1024 
1025  switch ($im_type)
1026  {
1027  case "gif":
1028  $this->map_image = ImageCreateFromGIF($this->getMapWorkCopyName());
1029  break;
1030 
1031  case "jpg":
1032  case "jpeg":
1033  $this->map_image = ImageCreateFromJPEG($this->getMapWorkCopyName());
1034  break;
1035 
1036  case "png":
1037  $this->map_image = ImageCreateFromPNG($this->getMapWorkCopyName());
1038  break;
1039  }
1040 
1041  // try to allocate black and white as color. if this is not possible, get the closest colors
1042  if (imagecolorstotal($this->map_image) > 250)
1043  {
1044  $this->color1 = imagecolorclosest($this->map_image, 0, 0, 0);
1045  $this->color2 = imagecolorclosest($this->map_image, 255, 255, 255);
1046  }
1047  else
1048  {
1049  $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
1050  $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
1051  }
1052  }
1053 
1057  function saveMapWorkImage()
1058  {
1059  $im_type = strtolower($this->getMapWorkCopyType());
1060 
1061  // save image work-copy and free memory
1062  switch ($im_type)
1063  {
1064  case "gif":
1065  ImageGIF($this->map_image, $this->getMapWorkCopyName());
1066  break;
1067 
1068  case "jpg":
1069  case "jpeg":
1070  ImageJPEG($this->map_image, $this->getMapWorkCopyName());
1071  break;
1072 
1073  case "png":
1074  ImagePNG($this->map_image, $this->getMapWorkCopyName());
1075  break;
1076  }
1077 
1078  ImageDestroy($this->map_image);
1079  }
1080 
1084  function &getMapWorkImage()
1085  {
1086  return $this->map_image;
1087  }
1088 
1089 
1093  function getMapAreasXML($a_insert_inst = false, $a_inst = 0)
1094  {
1095  $xml = "";
1096 
1097  // build xml of map areas
1098  for ($i=0; $i < count($this->mapareas); $i++)
1099  {
1100  $area =& $this->mapareas[$i];
1101 
1102  // highlight mode
1103  $hm = "";
1104  if ($area->getHighlightMode() != "")
1105  {
1106  $hm = ' HighlightMode="'.$area->getHighlightMode().'" ';
1107  $hcl = ($area->getHighlightClass() != "")
1108  ? $area->getHighlightClass()
1109  : "Accented";
1110  $hm.= 'HighlightClass="'.$hcl.'" ';
1111  }
1112 
1113  $xml .= "<MapArea Shape=\"".$area->getShape()."\" Coords=\"".$area->getCoords()."\" ".$hm.">";
1114  if ($area->getLinkType() == IL_INT_LINK)
1115  {
1116  $target_frame = $area->getTargetFrame();
1117 
1118  if ($area->getType() == "GlossaryItem" && $target_frame == "")
1119  {
1120  $target_frame = "Glossary";
1121  }
1122 
1123  $tf_str = ($target_frame == "")
1124  ? ""
1125  : "TargetFrame=\"".$target_frame."\"";
1126 
1127  $xml .= "<IntLink Target=\"".$area->getTarget($a_insert_inst, $a_inst)."\" Type=\"".
1128  $area->getType()."\" $tf_str>";
1129  // see bug 17893 and http://stackoverflow.com/questions/4026502/xml-error-at-ampersand
1130  $xml .= htmlspecialchars($area->getTitle(), ENT_QUOTES);
1131  $xml .="</IntLink>";
1132  }
1133  else
1134  {
1135  $xml .= "<ExtLink Href=\"".str_replace("&", "&amp;",$area->getHref())."\" Title=\"".
1136  $area->getExtTitle()."\">";
1137  $xml .= $area->getTitle();
1138  $xml .="</ExtLink>";
1139  }
1140  $xml .= "</MapArea>";
1141  }
1142 
1143  return $xml;
1144  }
1145 
1146 
1152  function _resolveMapAreaLinks($a_mob_id)
1153  {
1154  global $ilDB;
1155 
1156 //echo "mediaItems::resolve<br>";
1157  // read media_object record
1158  $query = "SELECT * FROM media_item WHERE mob_id = ".
1159  $ilDB->quote($a_mob_id, "integer")." ".
1160  "ORDER BY nr";
1161  $item_set = $ilDB->query($query);
1162  while ($item_rec = $ilDB->fetchAssoc($item_set))
1163  {
1164  ilMapArea::_resolveIntLinks($item_rec["id"]);
1165  }
1166  }
1167 
1173  function _getMapAreasIntLinks($a_mob_id)
1174  {
1175  global $ilDB;
1176 
1177  // read media_items records
1178  $query = "SELECT * FROM media_item WHERE mob_id = ".
1179  $ilDB->quote($a_mob_id, "integer")." ORDER BY nr";
1180 
1181  $item_set = $ilDB->query($query);
1182  $links = array();
1183  while ($item_rec = $ilDB->fetchAssoc($item_set))
1184  {
1185  $map_links = ilMapArea::_getIntLinks($item_rec["id"]);
1186  foreach($map_links as $key => $map_link)
1187  {
1188  $links[$key] = $map_link;
1189  }
1190  }
1191  return $links;
1192  }
1193 
1198  {
1199  include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
1201  $this->getLocation(), $this->getParameters());
1202  foreach ($par as $k => $v)
1203  {
1204  $this->setParameter($k, $v);
1205  }
1206  }
1207 }
1208 ?>
setCaption($a_caption)
set caption
print $file
getId()
get media item id
static _lookupLocationForMobId($a_mob_id, $a_purpose)
Lookup location for mob id.
getSuffix()
get location suffix
static extractUrlParameters($a_location, $a_parameter)
Extract URL information to parameter array.
$size
Definition: RandomTest.php:79
exit
Definition: login.php:54
getMapWorkCopyType()
get image type of image map work copy
getWidth()
get width
static getImageSize($a_location)
Get image size from location.
_resolveMapAreaLinks($a_mob_id)
resolve internal links of all media items of a media object
_getMediaItemsOfMObId($a_mobId, $a_purpose)
setId($a_id)
set media item id
addAreaToMapWorkCopy($a_shape, $a_coords)
draw a new area in work image
getWorkDirectory()
get work directory for image map editing
setThumbTried($a_tried)
copyOriginal()
Copy the orginal file.
read()
read media item data (item id or (mob_id and nr) must be set)
makeMapWorkCopy($a_area_nr=0, $a_exclude=false)
make map work copy of image
buildMapWorkImage()
build image map work image
setLocation($a_location)
setHeight($a_height)
set height
getMobId()
get id of parent media object
& getMapWorkImage()
get image map work image
static assembleParameterString($a_par_arr)
getMapAreasXML($a_insert_inst=false, $a_inst=0)
get xml code of media items&#39; areas
static deducibleSize($a_mime)
checks if mime type is provided by getimagesize()
setNr($a_nr)
set number of media item within media object
getMapWorkCopyName($a_reference_copy=false)
Get name of image map work copy file.
_createThumbnailDirectory($a_obj_id)
Create thumbnail directory.
getThumbnailDirectory($a_mode="filesystem")
get media file directory
getOriginalSize()
get original size
addMapArea(&$a_map_area)
static checkParameter($a_par, $a_val)
Check parameter (filter javascript related and other unsafe parameters/values)
setPurpose($a_purpose)
const IL_INT_LINK
getParameterString()
get all parameters (as string)
getDirectory()
get media file directory
& getMapArea($nr)
get map area
Class ilMediaItem.
_getMaxNr($a_item_id)
get maximum nr of media item (static)
static getGDSupportedImageType($a_desired_type)
returns the best supported image type by this PHP build
static createDirectory($a_dir, $a_mod=0755)
create directory
static _lookupMobId($a_med_id)
Lookup Mob ID.
_getMapAreasIntLinks($a_mob_id)
get all internal links of map areas of a mob
extractUrlParameters()
Extract parameters of special external references to parameter array.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
setMobId($a_mob_id)
set id of parent media object
createWorkDirectory()
create work directory for image map editing
saveMapWorkImage()
save image map work image
resetParameters()
reset parameters
setHAlign($a_halign)
set horizontal align
writeParameter($a_name, $a_value)
Write parameter.
setTextRepresentation($a_val)
Set text representation.
deleteAllItemsOfMob($a_mob_id)
static
Class ilMapArea.
static getDataDir()
get data directory (outside webspace)
_getThumbnailDirectory($a_mob_id, $a_mode="filesystem")
get directory for files of media object (static)
ilMediaItem($a_id=0)
static convertImage($a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
update()
update media item data (without map areas!)
global $lng
Definition: privfeed.php:40
global $ilDB
getCaption()
get caption
getParameters()
get all parameters (in array)
getHAlign()
get horizontal align
_getMediaItemsOfMOb(&$a_mob)
read media items into media objects (static)
setFormat($a_format)
getTextRepresentation()
Get text representation.
_getIntLinks($a_item_id)
get all internal links of a media items map areas
outputMapWorkCopy()
output raw map work copy file
getHeight()
get height
_resolveIntLinks($a_item_id)
resolve internal links of an item id
writeThumbTried($a_tried)
write thumbnail creation try data ("y"/"n")
getThumbnailTarget($a_size="")
get thumbnail target
static extractParameterString($a_parstr)
extracts parameter value pairs from a string into an array
setWidth($a_width)
set width
setParameters($a_par)
set alle parameters via parameter string (format: par1="value1", par2="value2", ...)
deleteMapArea($nr)
delete map area
create()
create persistent media item
getParameter($a_name)
get a single parameter
getMapAreas()
get map areas
_getDirectory($a_mob_id)
get directory for files of media object (static)
setParameter($a_name, $a_value)
set parameter
setLocationType($a_type)