ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilHtmlImageMapFileInputGUI.php
Go to the documentation of this file.
1<?php
2
23{
27 protected $shapes = [];
28
32 public function checkInput(): bool
33 {
37 global $DIC;
38 $lng = $DIC['lng'];
39
40 if (!parent::checkInput()) {
41 return false;
42 }
43
44 $tmp_file_name = $_FILES[$this->getPostVar()]['tmp_name'];
45 if (strlen($tmp_file_name) == 0) {
46 return true;
47 }
48
49 if (!is_readable($tmp_file_name)) {
50 $this->setAlert($lng->txt('ass_imap_map_file_not_readable'));
51 return false;
52 }
53
54 $contents = file_get_contents($tmp_file_name);
55 $matches = null;
56 if (
57 !preg_match_all('/<area(.+)>/siU', $contents, $matches) ||
58 !is_array($matches) ||
59 !isset($matches[1]) ||
60 count($matches[1]) == 0
61 ) {
62 $this->setAlert($lng->txt('ass_imap_no_map_found'));
63 return false;
64 }
65
66 for ($i = 0; $i < count($matches[1]); $i++) {
67 preg_match("/alt\s*=\s*\"(.*)\"\s*/siU", $matches[1][$i], $alt);
68 preg_match("/coords\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $coords);
69 preg_match("/shape\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $shape);
70
71 if (!$this->verifyArea($coords, $shape)) {
72 $this->setAlert($lng->txt('ass_imap_no_map_found'));
73 return false;
74 }
75
76 $this->shapes[] = new ASS_AnswerImagemap($alt[1] ?? '', 0.0, $i, $coords[1], $shape[1]);
77 }
78
79 return true;
80 }
81
82 protected function verifyArea($coords, $shape)
83 {
84 if (!in_array(strtolower($shape[1]), assImagemapQuestion::AVAILABLE_SHAPES)) {
85 return false;
86 }
87
88 $coords_array = explode(',', $coords[1]);
89 foreach ($coords_array as $coord) {
90 if (!is_numeric($coord)) {
91 return false;
92 }
93 }
94
95 return true;
96 }
97
101 public function getShapes(): array
102 {
103 return $this->shapes;
104 }
105}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
checkInput()
Check input, strip slashes etc.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
global $DIC
Definition: shib_login.php:26