ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
14 {
18  protected $db;
19 
23  protected $lng;
24 
25  public $id;
26  public $purpose;
27  public $location;
29  public $format;
30  public $width;
31  public $height;
32  public $caption;
33  public $halign;
34  public $parameters;
35  public $mob_id;
36  public $nr;
37  public $mapareas;
38  public $map_cnt;
39  public $map_image; // image map work copy image
40  public $color1; // map area line color 1
41  public $color2; // map area line color 2
42 
43  protected $duration = 0;
44 
48  protected $upload_hash;
49 
50  public function __construct($a_id = 0)
51  {
52  global $DIC;
53 
54  $this->db = $DIC->database();
55  $this->lng = $DIC->language();
56  $this->parameters = array();
57  $this->mapareas = array();
58  $this->map_cnt = 0;
59 
60  if ($a_id != 0) {
61  $this->setId($a_id);
62  $this->read();
63  }
64  }
65 
70  public function setId($a_id)
71  {
72  $this->id = $a_id;
73  }
74 
79  public function getId()
80  {
81  return $this->id;
82  }
83 
88  public function setMobId($a_mob_id)
89  {
90  $this->mob_id = $a_mob_id;
91  }
92 
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 
119  public function setDuration($a_val)
120  {
121  $this->duration = $a_val;
122  }
123 
128  public function getDuration()
129  {
130  return $this->duration;
131  }
132 
137  public function setTextRepresentation($a_val)
138  {
139  $this->text_representation = $a_val;
140  }
141 
146  public function getTextRepresentation()
147  {
148  return $this->text_representation;
149  }
150 
155  public function setUploadHash($a_val)
156  {
157  $this->upload_hash = $a_val;
158  }
159 
164  public function getUploadHash()
165  {
166  return $this->upload_hash;
167  }
168 
172  public function create()
173  {
174  $ilDB = $this->db;
175 
176  $item_id = $ilDB->nextId("media_item");
177  $query = "INSERT INTO media_item (id,mob_id, purpose, location, " .
178  "location_type, format, width, " .
179  "height, halign, caption, nr, text_representation, upload_hash, duration) VALUES " .
180  "(" .
181  $ilDB->quote($item_id, "integer") . "," .
182  $ilDB->quote($this->getMobId(), "integer") . "," .
183  $ilDB->quote($this->getPurpose(), "text") . "," .
184  $ilDB->quote($this->getLocation(), "text") . "," .
185  $ilDB->quote($this->getLocationType(), "text") . "," .
186  $ilDB->quote($this->getFormat(), "text") . "," .
187  $ilDB->quote($this->getWidth(), "text") . "," .
188  $ilDB->quote($this->getHeight(), "text") . "," .
189  $ilDB->quote($this->getHAlign(), "text") . "," .
190  $ilDB->quote($this->getCaption(), "text") . "," .
191  $ilDB->quote($this->getNr(), "integer") . "," .
192  $ilDB->quote($this->getTextRepresentation(), "text") . "," .
193  $ilDB->quote($this->getUploadHash(), "text") . "," .
194  $ilDB->quote($this->getDuration(), "integer") .
195  ")";
196  $ilDB->manipulate($query);
197 
198  $this->setId($item_id);
199 
200  // create mob parameters
201  $params = $this->getParameters();
202  foreach ($params as $name => $value) {
203  $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
204  "(" . $ilDB->quote($item_id, "integer") . "," .
205  $ilDB->quote($name, "text") . "," .
206  $ilDB->quote($value, "text") . ")";
207  $ilDB->manipulate($query);
208  }
209 
210  // create map areas
211  for ($i = 0; $i < count($this->mapareas); $i++) {
212  if (is_object($this->mapareas[$i])) {
213  $this->mapareas[$i]->setItemId($this->getId());
214  $this->mapareas[$i]->setNr($i + 1);
215  $this->mapareas[$i]->create();
216  }
217  }
218  }
219 
223  public function update()
224  {
225  $ilDB = $this->db;
226 
227  $query = "UPDATE media_item SET " .
228  " mob_id = " . $ilDB->quote($this->getMobId(), "integer") . "," .
229  " purpose = " . $ilDB->quote($this->getPurpose(), "text") . "," .
230  " location = " . $ilDB->quote($this->getLocation(), "text") . "," .
231  " location_type = " . $ilDB->quote($this->getLocationType(), "text") . "," .
232  " format = " . $ilDB->quote($this->getFormat(), "text") . "," .
233  " width = " . $ilDB->quote($this->getWidth(), "text") . "," .
234  " height = " . $ilDB->quote($this->getHeight(), "text") . "," .
235  " halign = " . $ilDB->quote($this->getHAlign(), "text") . "," .
236  " caption = " . $ilDB->quote($this->getCaption(), "text") . "," .
237  " nr = " . $ilDB->quote($this->getNr(), "integer") . "," .
238  " text_representation = " . $ilDB->quote($this->getTextRepresentation(), "text") . "," .
239  " upload_hash = " . $ilDB->quote($this->getUploadHash(), "text") . "," .
240  " duration = " . $ilDB->quote($this->getDuration(), "integer") .
241  " WHERE id = " . $ilDB->quote($this->getId(), "integer");
242  $ilDB->manipulate($query);
243 
244  // delete mob parameters
245  $query = "DELETE FROM mob_parameter WHERE med_item_id = " .
246  $ilDB->quote($this->getId(), "integer");
247 
248  // create mob parameters
249  $params = $this->getParameters();
250  foreach ($params as $name => $value) {
251  $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
252  "(" . $ilDB->quote($this->getId(), "integer") . "," .
253  $ilDB->quote($name, "text") . "," .
254  $ilDB->quote($value, "text") . ")";
255  $ilDB->manipulate($query);
256  }
257  }
258 
264  public function writeParameter($a_name, $a_value)
265  {
266  $ilDB = $this->db;
267 
268  $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
269  "(" . $ilDB->quote($this->getId(), "integer") . "," .
270  $ilDB->quote($a_name, "text") . "," .
271  $ilDB->quote($a_value, "text") . ")";
272  $ilDB->manipulate($query);
273  }
274 
278  public function read()
279  {
280  $ilDB = $this->db;
281 
282  $item_id = $this->getId();
283  $mob_id = $this->getMobId();
284  $nr = $this->getNr();
285  $query = "";
286  if ($item_id > 0) {
287  $query = "SELECT * FROM media_item WHERE id = " .
288  $ilDB->quote($this->getId(), "integer");
289  } elseif ($mob_id > 0 && $nr > 0) {
290  $query = "SELECT * FROM media_item WHERE mob_id = " .
291  $ilDB->quote($this->getMobId(), "integer") . " " .
292  "AND nr=" . $ilDB->quote($this->getNr(), "integer");
293  }
294  if ($query != "") {
295  $item_set = $ilDB->query($query);
296  $item_rec = $ilDB->fetchAssoc($item_set);
297 
298  $this->setLocation($item_rec["location"]);
299  $this->setLocationType($item_rec["location_type"]);
300  $this->setFormat($item_rec["format"]);
301  $this->setWidth($item_rec["width"]);
302  $this->setHeight($item_rec["height"]);
303  $this->setHAlign($item_rec["halign"]);
304  $this->setCaption($item_rec["caption"]);
305  $this->setPurpose($item_rec["purpose"]);
306  $this->setNr($item_rec["nr"]);
307  $this->setMobId($item_rec["mob_id"]);
308  $this->setId($item_rec["id"]);
309  $this->setThumbTried($item_rec["tried_thumb"]);
310  $this->setTextRepresentation($item_rec["text_representation"]);
311  $this->setUploadHash($item_rec["upload_hash"]);
312  $this->setDuration((int) $item_rec["duration"]);
313 
314  // get item parameter
315  $query = "SELECT * FROM mob_parameter WHERE med_item_id = " .
316  $ilDB->quote($this->getId(), "integer");
317  $par_set = $ilDB->query($query);
318  while ($par_rec = $ilDB->fetchAssoc($par_set)) {
319  $this->setParameter($par_rec["name"], $par_rec["value"]);
320  }
321 
322  // get item map areas
323  $max = ilMapArea::_getMaxNr($this->getId());
324  for ($i = 1; $i <= $max; $i++) {
325  $area = new ilMapArea($this->getId(), $i);
326  $this->addMapArea($area);
327  }
328  }
329  }
330 
334  public function writeThumbTried($a_tried)
335  {
336  $ilDB = $this->db;
337 
338  $q = "UPDATE media_item SET tried_thumb = " .
339  $ilDB->quote($a_tried, "text") .
340  " WHERE id = " . $ilDB->quote($this->getId(), "integer");
341 
342  $ilDB->manipulate($q);
343  }
344 
350  public static function _lookupLocationForMobId($a_mob_id, $a_purpose)
351  {
352  global $DIC;
353 
354  $ilDB = $DIC->database();
355 
356  // read media_object record
357  $query = "SELECT * FROM media_item WHERE mob_id = " .
358  $ilDB->quote($a_mob_id, "integer") . " " .
359  "AND purpose = " . $ilDB->quote($a_purpose, "text");
360  $set = $ilDB->query($query);
361  if ($rec = $ilDB->fetchAssoc($set)) {
362  return $rec["location"];
363  }
364 
365  return "";
366  }
367 
372  public static function _lookupMobId($a_med_id)
373  {
374  global $DIC;
375 
376  $ilDB = $DIC->database();
377 
378  // read media_object record
379  $query = "SELECT * FROM media_item WHERE id = " .
380  $ilDB->quote($a_med_id, "integer");
381  $set = $ilDB->query($query);
382  if ($rec = $ilDB->fetchAssoc($set)) {
383  return $rec["mob_id"];
384  }
385 
386  return "";
387  }
388 
389  /* read media item with specific purpose and mobId
390  *
391  * @param integer $a_mobId media object id
392  * @param string $a_purpose media object purpose
393  * @return array $mob media object
394  */
395  public static function _getMediaItemsOfMObId($a_mobId, $a_purpose)
396  {
397  global $DIC;
398 
399  $ilDB = $DIC->database();
400 
401  // read media_object record
402  $query = "SELECT * FROM media_item WHERE mob_id = " .
403  $ilDB->quote($a_mobId, "integer") . " " .
404  "AND purpose=" . $ilDB->quote($a_purpose, "text") . " ORDER BY nr";
405  $item_set = $ilDB->query($query);
406 
407  while ($item_rec = $ilDB->fetchAssoc($item_set)) {
408  return $item_rec;
409  }
410  return false;
411  }
412 
417  public static function _getMediaItemsOfMOb(&$a_mob)
418  {
419  global $DIC;
420 
421  $ilDB = $DIC->database();
422 
423  // read media_object record
424  $query = "SELECT * FROM media_item WHERE mob_id = " .
425  $ilDB->quote($a_mob->getId(), "integer") . " " .
426  "ORDER BY nr";
427  $item_set = $ilDB->query($query);
428  while ($item_rec = $ilDB->fetchAssoc($item_set)) {
429  $media_item = new ilMediaItem();
430  $media_item->setNr($item_rec["nr"]);
431  $media_item->setId($item_rec["id"]);
432  $media_item->setLocation($item_rec["location"]);
433  $media_item->setLocationType($item_rec["location_type"]);
434  $media_item->setFormat($item_rec["format"]);
435  $media_item->setWidth($item_rec["width"]);
436  $media_item->setHeight($item_rec["height"]);
437  $media_item->setHAlign($item_rec["halign"]);
438  $media_item->setCaption($item_rec["caption"]);
439  $media_item->setPurpose($item_rec["purpose"]);
440  $media_item->setMobId($item_rec["mob_id"]);
441  $media_item->setThumbTried($item_rec["tried_thumb"]);
442  $media_item->setTextRepresentation($item_rec["text_representation"]);
443  $media_item->setUploadHash($item_rec["upload_hash"]);
444  $media_item->setDuration((int) $item_rec["duration"]);
445 
446  // get item parameter
447  $query = "SELECT * FROM mob_parameter WHERE med_item_id = " .
448  $ilDB->quote($item_rec["id"], "integer");
449  $par_set = $ilDB->query($query);
450  while ($par_rec = $ilDB->fetchAssoc($par_set)) {
451  $media_item->setParameter($par_rec["name"], $par_rec["value"]);
452  }
453 
454  // get item map areas
455  $max = ilMapArea::_getMaxNr($media_item->getId());
456  for ($i = 1; $i <= $max; $i++) {
457  $area = new ilMapArea($media_item->getId(), $i);
458  $media_item->addMapArea($area);
459  }
460 
461  // add media item to media object
462  $a_mob->addMediaItem($media_item);
463  }
464  }
465 
470  public static function deleteAllItemsOfMob($a_mob_id)
471  {
472  global $DIC;
473 
474  $ilDB = $DIC->database();
475 
476  // iterate all media items ob mob
477  $query = "SELECT * FROM media_item WHERE mob_id = " .
478  $ilDB->quote($a_mob_id, "integer");
479  $item_set = $ilDB->query($query);
480  while ($item_rec = $ilDB->fetchAssoc($item_set)) {
481  // delete all parameters of media item
482  $query = "DELETE FROM mob_parameter WHERE med_item_id = " .
483  $ilDB->quote($item_rec["id"], "integer");
484  $ilDB->manipulate($query);
485 
486  // delete all map areas of media item
487  $query = "DELETE FROM map_area WHERE item_id = " .
488  $ilDB->quote($item_rec["id"], "integer");
489  $ilDB->manipulate($query);
490  }
491 
492  // delete media items
493  $query = "DELETE FROM media_item WHERE mob_id = " .
494  $ilDB->quote($a_mob_id, "integer");
495  $ilDB->manipulate($query);
496  }
497 
498  public function setPurpose($a_purpose)
499  {
500  $this->purpose = $a_purpose;
501  }
502 
503  public function getPurpose()
504  {
505  return $this->purpose;
506  }
507 
508  public function setLocation($a_location)
509  {
510  $this->location = $a_location;
511  }
512 
513  public function getLocation()
514  {
515  return $this->location;
516  }
517 
518  public function setLocationType($a_type)
519  {
520  $this->location_type = $a_type;
521  }
522 
523  public function getLocationType()
524  {
525  return $this->location_type;
526  }
527 
528  public function setFormat($a_format)
529  {
530  $this->format = $a_format;
531  }
532 
533  public function getFormat()
534  {
535  return $this->format;
536  }
537 
538  public function setThumbTried($a_tried)
539  {
540  $this->tried_thumb = $a_tried;
541  }
542 
543  public function getThumbTried()
544  {
545  return $this->tried_thumb;
546  }
547 
548  public function addMapArea(&$a_map_area)
549  {
550  $this->mapareas[$this->map_cnt] = $a_map_area;
551  $this->map_cnt++;
552  }
553 
557  public function deleteMapArea($nr)
558  {
559  for ($i = 1; $i <= $this->map_cnt; $i++) {
560  if ($i > $nr) {
561  $this->mapareas[$i - 2] = $this->mapareas[$i - 1];
562  $this->mapareas[$i - 2]->setNr($i - 1);
563  }
564  }
565  if ($nr <= $this->map_cnt) {
566  unset($this->mapareas[$this->map_cnt - 1]);
567  $this->map_cnt--;
568  }
569  }
570 
574  public function &getMapArea($nr)
575  {
576  return $this->mapareas[$nr - 1];
577  }
578 
582  public function getMapAreas()
583  {
584  return $this->mapareas;
585  }
586 
590  public function getWidth()
591  {
592  return $this->width;
593  }
594 
598  public function setWidth($a_width)
599  {
600  $this->width = $a_width;
601  }
602 
606  public function getHeight()
607  {
608  return $this->height;
609  }
610 
614  public function setHeight($a_height)
615  {
616  $this->height = $a_height;
617  }
618 
622  public function getOriginalSize()
623  {
624  $mob_dir = ilObjMediaObject::_getDirectory($this->getMobId());
625 
626  if (ilUtil::deducibleSize($this->getFormat())) {
627  if ($this->getLocationType() == "LocalFile") {
628  $loc = $mob_dir . "/" . $this->getLocation();
629  } else {
630  $loc = $this->getLocation();
631  }
632 
633  include_once("./Services/MediaObjects/classes/class.ilMediaImageUtil.php");
635  if ($size[0] > 0 && $size[1] > 0) {
636  return array("width" => $size[0], "height" => $size[1]);
637  }
638  }
639 
640  return false;
641  }
642 
646  public function setCaption($a_caption)
647  {
648  $this->caption = $a_caption;
649  }
650 
654  public function getCaption()
655  {
656  return $this->caption;
657  }
658 
662  public function setHAlign($a_halign)
663  {
664  $this->halign = $a_halign;
665  }
666 
670  public function getHAlign()
671  {
672  return $this->halign;
673  }
674 
680  public function setParameter($a_name, $a_value)
681  {
682  if (self::checkParameter($a_name, $a_value)) {
683  $this->parameters[$a_name] = $a_value;
684  }
685  }
686 
690  public function resetParameters()
691  {
692  $this->parameters = array();
693  }
694 
699  public function setParameters($a_par)
700  {
701  $this->resetParameters();
702  $par_arr = ilUtil::extractParameterString($a_par);
703  if (is_array($par_arr)) {
704  foreach ($par_arr as $par => $val) {
705  $this->setParameter($par, $val);
706  }
707  }
708  }
709 
716  public static function checkParameter($a_par, $a_val)
717  {
718  // do not allow event attributes
719  if (substr(strtolower(trim($a_par)), 0, 2) == "on") {
720  return false;
721  }
722  // no javascript in value
723  if (is_int(strpos(strtolower($a_val), "javascript"))) {
724  return false;
725  }
726  // do not allow to change the src attribute
727  if (in_array(strtolower(trim($a_par)), array("src"))) {
728  return false;
729  }
730 
731  return true;
732  }
733 
737  public function getParameters()
738  {
739  return $this->parameters;
740  }
741 
745  public function getParameterString()
746  {
747  return ilUtil::assembleParameterString($this->parameters);
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 
802  public function getMapWorkCopyName($a_reference_copy = false)
803  {
804  $file_arr = explode("/", $this->getLocation());
805  $o_file = $file_arr[count($file_arr) - 1];
806  $file_arr = explode(".", $o_file);
807  unset($file_arr[count($file_arr) - 1]);
808  $file = implode(".", $file_arr);
809 
810  if (!$a_reference_copy) {
811  return $this->getWorkDirectory() . "/" . $file . "." . $this->getMapWorkCopyType();
812  } else {
813  return $this->getWorkDirectory() . "/l_copy_" . $o_file;
814  }
815  }
816 
820  public function getDirectory()
821  {
822  return ilObjMediaObject::_getDirectory($this->getMobId());
823  }
824 
828  public function getThumbnailDirectory($a_mode = "filesystem")
829  {
830  return ilObjMediaObject::_getThumbnailDirectory($this->getMobId(), $a_mode);
831  }
832 
836  public function getThumbnailTarget($a_size = "")
837  {
838  $jpeg_file = $this->getThumbnailDirectory() . "/" .
839  $this->getPurpose() . ".jpeg";
840  $format = "png";
841  if (is_file($jpeg_file)) {
842  $format = "jpeg";
843  }
844  if (is_int(strpos($this->getFormat(), "image"))) {
845  $thumb_file = $this->getThumbnailDirectory() . "/" .
846  $this->getPurpose() . "." . $format;
847  $thumb_file_small = $this->getThumbnailDirectory() . "/" .
848  $this->getPurpose() . "_small." . $format;
849  // generate thumbnail (if not tried before)
850  if ($this->getThumbTried() == "n" && $this->getLocationType() == "LocalFile" && $this->getFormat() !== "image/svg+xml") {
851  if (is_file($thumb_file)) {
852  unlink($thumb_file);
853  }
854  if (is_file($thumb_file_small)) {
855  unlink($thumb_file_small);
856  }
857  $this->writeThumbTried("y");
859  $med_file = $this->getDirectory() . "/" . $this->getLocation();
860 
861  if (is_file($med_file)) {
862  $mob = new ilObjMediaObject($this->getMobId());
863  $mob->makeThumbnail($this->getLocation(), $this->getPurpose() . "." . $format, $format, "80");
864  $mob->makeThumbnail($this->getLocation(), $this->getPurpose() . "_small." . $format, $format, "40");
865  }
866  }
867  if ($this->getFormat() === "image/svg+xml") {
868  return ilObjMediaObject::_getURL($this->getMobId()) . "/" . $this->getLocation();
869  }
870  if ($a_size == "small") {
871  if (is_file($thumb_file_small)) {
872  $random = new \ilRandom();
873  return $this->getThumbnailDirectory("output") . "/" .
874  $this->getPurpose() . "_small." . $format . "?dummy=" . $random->int(1, 999999);
875  }
876  } else {
877  if (is_file($thumb_file)) {
878  $random = new \ilRandom();
879  return $this->getThumbnailDirectory("output") . "/" .
880  $this->getPurpose() . "." . $format . "?dummy=" . $random->int(1, 999999);
881  }
882  }
883  }
884 
885  return "";
886  }
887 
891  public function copyOriginal()
892  {
893  $lng = $this->lng;
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 
943  public function makeMapWorkCopy($a_area_nr = 0, $a_exclude = false)
944  {
945  $lng = $this->lng;
946 
947  if (!$this->copyOriginal()) {
948  return false;
949  }
950  $this->buildMapWorkImage();
951 
952  // determine ratios
953  $size = @getimagesize($this->getMapWorkCopyName());
954  $x_ratio = 1;
955  if ($size[0] > 0 && $this->getWidth() > 0) {
956  $x_ratio = $this->getWidth() / $size[0];
957  }
958  $y_ratio = 1;
959  if ($size[1] > 0 && $this->getHeight() > 0) {
960  $y_ratio = $this->getHeight() / $size[1];
961  }
962 
963  // draw map areas
964  for ($i = 0; $i < count($this->mapareas); $i++) {
965  if (((($i + 1) == $a_area_nr) && !$a_exclude) ||
966  ((($i + 1) != $a_area_nr) && $a_exclude) ||
967  ($a_area_nr == 0)
968  ) {
969  $area = $this->mapareas[$i];
970  $area->draw(
971  $this->getMapWorkImage(),
972  $this->color1,
973  $this->color2,
974  true,
975  $x_ratio,
976  $y_ratio
977  );
978  }
979  }
980 
981  $this->saveMapWorkImage();
982 
983  return true;
984  }
985 
991  public function addAreaToMapWorkCopy($a_shape, $a_coords)
992  {
993  $this->buildMapWorkImage();
994 
995  // determine ratios
996  $size = @getimagesize($this->getMapWorkCopyName());
997  $x_ratio = 1;
998  if ($size[0] > 0 && $this->getWidth() > 0) {
999  $x_ratio = $this->getWidth() / $size[0];
1000  }
1001  $y_ratio = 1;
1002  if ($size[1] > 0 && $this->getHeight() > 0) {
1003  $y_ratio = $this->getHeight() / $size[1];
1004  }
1005 
1006  // add new area to work image
1007  $area = new ilMapArea();
1008  $area->setShape($a_shape);
1009  $area->setCoords($a_coords);
1010  $area->draw(
1011  $this->getMapWorkImage(),
1012  $this->color1,
1013  $this->color2,
1014  false,
1015  $x_ratio,
1016  $y_ratio
1017  );
1018 
1019  $this->saveMapWorkImage();
1020  }
1021 
1025  public function outputMapWorkCopy()
1026  {
1027  if ($this->getMapWorkCopyType() != "") {
1028  header("Pragma: no-cache");
1029  header("Expires: 0");
1030  header("Content-type: image/" . strtolower($this->getMapWorkCopyType()));
1031  readfile($this->getMapWorkCopyName());
1032  }
1033  exit;
1034  }
1035 
1039  public function buildMapWorkImage()
1040  {
1041  $im_type = strtolower($this->getMapWorkCopyType());
1042 
1043  switch ($im_type) {
1044  case "gif":
1045  $this->map_image = ImageCreateFromGIF($this->getMapWorkCopyName());
1046  break;
1047 
1048  case "jpg":
1049  case "jpeg":
1050  $this->map_image = ImageCreateFromJPEG($this->getMapWorkCopyName());
1051  break;
1052 
1053  case "png":
1054  $this->map_image = ImageCreateFromPNG($this->getMapWorkCopyName());
1055  break;
1056  }
1057 
1058  // try to allocate black and white as color. if this is not possible, get the closest colors
1059  if (imagecolorstotal($this->map_image) > 250) {
1060  $this->color1 = imagecolorclosest($this->map_image, 0, 0, 0);
1061  $this->color2 = imagecolorclosest($this->map_image, 255, 255, 255);
1062  } else {
1063  $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
1064  $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
1065  }
1066  }
1067 
1071  public function saveMapWorkImage()
1072  {
1073  $im_type = strtolower($this->getMapWorkCopyType());
1074 
1075  // save image work-copy and free memory
1076  switch ($im_type) {
1077  case "gif":
1078  ImageGIF($this->map_image, $this->getMapWorkCopyName());
1079  break;
1080 
1081  case "jpg":
1082  case "jpeg":
1083  ImageJPEG($this->map_image, $this->getMapWorkCopyName());
1084  break;
1085 
1086  case "png":
1087  ImagePNG($this->map_image, $this->getMapWorkCopyName());
1088  break;
1089  }
1090 
1091  ImageDestroy($this->map_image);
1092  }
1093 
1097  public function &getMapWorkImage()
1098  {
1099  return $this->map_image;
1100  }
1101 
1105  public function getMapAreasXML($a_insert_inst = false, $a_inst = 0)
1106  {
1107  $xml = "";
1108 
1109  // build xml of map areas
1110  for ($i = 0; $i < count($this->mapareas); $i++) {
1111  $area = $this->mapareas[$i];
1112 
1113  // highlight mode
1114  $hm = "";
1115  if ($area->getHighlightMode() != "") {
1116  $hm = ' HighlightMode="' . $area->getHighlightMode() . '" ';
1117  $hcl = ($area->getHighlightClass() != "")
1118  ? $area->getHighlightClass()
1119  : "Accented";
1120  $hm .= 'HighlightClass="' . $hcl . '" ';
1121  }
1122 
1123  $xml .= "<MapArea Shape=\"" . $area->getShape() . "\" Coords=\"" . $area->getCoords() . "\" " . $hm . ">";
1124  if ($area->getLinkType() == IL_INT_LINK) {
1125  $target_frame = $area->getTargetFrame();
1126 
1127  if ($area->getType() == "GlossaryItem" && $target_frame == "") {
1128  $target_frame = "Glossary";
1129  }
1130 
1131  $tf_str = ($target_frame == "")
1132  ? ""
1133  : "TargetFrame=\"" . $target_frame . "\"";
1134 
1135  $xml .= "<IntLink Target=\"" . $area->getTarget($a_insert_inst, $a_inst) . "\" Type=\"" .
1136  $area->getType() . "\" $tf_str>";
1137  // see bug 17893 and http://stackoverflow.com/questions/4026502/xml-error-at-ampersand
1138  $xml .= htmlspecialchars($area->getTitle(), ENT_QUOTES);
1139  $xml .= "</IntLink>";
1140  } else {
1141  $xml .= "<ExtLink Href=\"" . str_replace("&", "&amp;", $area->getHref()) . "\" Title=\"" .
1142  str_replace("&", "&amp;", $area->getExtTitle()) . "\">";
1143  $xml .= str_replace("&", "&amp;", $area->getTitle());
1144  $xml .= "</ExtLink>";
1145  }
1146  $xml .= "</MapArea>";
1147  }
1148  return $xml;
1149  }
1150 
1155  public static function _resolveMapAreaLinks($a_mob_id)
1156  {
1157  global $DIC;
1158 
1159  $ilDB = $DIC->database();
1160 
1161  //echo "mediaItems::resolve<br>";
1162  // read media_object record
1163  $query = "SELECT * FROM media_item WHERE mob_id = " .
1164  $ilDB->quote($a_mob_id, "integer") . " " .
1165  "ORDER BY nr";
1166  $item_set = $ilDB->query($query);
1167  while ($item_rec = $ilDB->fetchAssoc($item_set)) {
1168  ilMapArea::_resolveIntLinks($item_rec["id"]);
1169  }
1170  }
1171 
1176  public static function _getMapAreasIntLinks($a_mob_id)
1177  {
1178  global $DIC;
1179 
1180  $ilDB = $DIC->database();
1181 
1182  // read media_items records
1183  $query = "SELECT * FROM media_item WHERE mob_id = " .
1184  $ilDB->quote($a_mob_id, "integer") . " ORDER BY nr";
1185 
1186  $item_set = $ilDB->query($query);
1187  $links = array();
1188  while ($item_rec = $ilDB->fetchAssoc($item_set)) {
1189  $map_links = ilMapArea::_getIntLinks($item_rec["id"]);
1190  foreach ($map_links as $key => $map_link) {
1191  $links[$key] = $map_link;
1192  }
1193  }
1194  return $links;
1195  }
1196 
1200  public function extractUrlParameters()
1201  {
1202  include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
1204  $this->getLocation(),
1205  $this->getParameters()
1206  );
1207  foreach ($par as $k => $v) {
1208  $this->setParameter($k, $v);
1209  }
1210  }
1211 
1212  public function determineDuration()
1213  {
1214  $ana = new ilMediaAnalyzer();
1215  $ana->setFile(ilObjMediaObject::_getDirectory($this->getMobId()) . "/" . $this->getLocation());
1216  $ana->analyzeFile();
1217  $this->setDuration((int) $ana->getPlaytimeSeconds());
1218  }
1219 
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 }
getDuration()
Get duration.
setCaption($a_caption)
set caption
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.
static _getThumbnailDirectory($a_mob_id, $a_mode="filesystem")
get directory for files of media object (static)
$size
Definition: RandomTest.php:84
static deleteAllItemsOfMob($a_mob_id)
Delete all items of a mob.
exit
Definition: login.php:29
static _getMapAreasIntLinks($a_mob_id)
get all internal links of map areas of a mob
getMapWorkCopyType()
get image type of image map work copy
getWidth()
get width
static getImageSize($a_location)
Get image size from location.
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)
setUploadHash($a_val)
Set upload hash.
setDuration($a_val)
Set duration.
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
static _resolveMapAreaLinks($a_mob_id)
resolve internal links of all media items of a 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.
static _getURL($a_mob_id)
get directory for files of media object (static)
getThumbnailDirectory($a_mode="filesystem")
get media file directory
static _getDirectory($a_mob_id)
Get absolute 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)
static _getIntLinks($a_item_id)
get all internal links of a media items map areas
if($format !==null) $name
Definition: metadata.php:230
setPurpose($a_purpose)
const IL_INT_LINK
static _resolveIntLinks($a_item_id)
resolve internal links of an item id
getParameterString()
get all parameters (as string)
getDirectory()
get media file directory
& getMapArea($nr)
get map area
global $DIC
Definition: goto.php:24
Class ilMediaItem Media Item, component of a media object (file or reference)
static convertImage( $a_from, $a_to, $a_target_format="", $a_geometry="", $a_background_color="")
convert image
__construct($a_id=0)
static getGDSupportedImageType($a_desired_type)
returns the best supported image type by this PHP build
getUploadHash()
Get upload hash.
$xml
Definition: metadata.php:332
static createDirectory($a_dir, $a_mod=0755)
create directory
Class ilObjMediaObject.
$query
static _lookupMobId($a_med_id)
Lookup Mob ID.
static _getMediaItemsOfMOb(&$a_mob)
read media items into media objects (static)
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
static getMediaItemsForUploadHash($a_hash)
Get media items for upload hash.
writeParameter($a_name, $a_value)
Write parameter.
static _createThumbnailDirectory($a_obj_id)
Create thumbnail directory.
setTextRepresentation($a_val)
Set text representation.
Class ilMapArea.
static getDataDir()
get data directory (outside webspace)
static _getMediaItemsOfMObId($a_mobId, $a_purpose)
Analyzes media files.
update()
update media item data (without map areas!)
static _getMaxNr($a_item_id)
get maximum nr of media item (static)
global $ilDB
getCaption()
get caption
getParameters()
get all parameters (in array)
getHAlign()
get horizontal align
setFormat($a_format)
getTextRepresentation()
Get text representation.
outputMapWorkCopy()
output raw map work copy file
getHeight()
get height
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
$i
Definition: metadata.php:24
setParameter($a_name, $a_value)
set parameter
setLocationType($a_type)