19 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
53 $this->main_tpl = $DIC->ui()->mainTemplate();
58 if (!@is_file($this->preview_filename)) {
60 if (preg_match(
"/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches)) {
61 $extension =
"." . $matches[1];
65 $this->areas = array();
66 $this->points = array();
67 $this->linewidth_outer = 4;
68 $this->linewidth_inner = 2;
73 return count($this->areas);
78 return count($this->points);
90 $bordercolor =
"white",
91 $fillcolor =
"#FFFFFFA0" 93 if (ini_get(
"safe_mode")) {
94 if ((strpos($fillcolor,
"#") !==
false) || (strpos($fillcolor,
"rgb") !==
false)) {
95 $fillcolor = str_replace(
"\"",
"", $fillcolor);
98 $this->areas[$index] = array(
100 "coords" =>
"$coords",
101 "title" => htmlspecialchars($title),
103 "target" =>
"$target",
104 "linecolor" =>
'"' . $linecolor .
'"',
105 "fillcolor" =>
'"' . $fillcolor .
'"',
106 "bordercolor" =>
'"' . $bordercolor .
'"',
107 "visible" => (
int) $visible
116 $bordercolor =
"white",
117 $fillcolor =
"#FFFFFFA0" 119 $this->points[$index] = array(
120 "coords" =>
"$coords",
121 "linecolor" =>
'"' . $linecolor .
'"',
122 "fillcolor" =>
'"' . $fillcolor .
'"',
123 "bordercolor" =>
'"' . $bordercolor .
'"',
124 "visible" => (
int) $visible
130 if (count($this->areas) + count($this->points) > 0) {
131 $arr = array_merge(array_keys($this->areas), array_keys($this->points));
132 sort($arr, SORT_NUMERIC);
134 $inner = join(
"_", $arr);
135 if (strlen($inner) > 32) {
136 $inner = md5($inner);
138 return "preview_" . $inner .
"_";
146 if (count($this->areas) + count($this->points) == 0) {
149 $convert_cmd =
"-quality 100 ";
150 foreach ($this->points as $point) {
151 if ($point[
"visible"]) {
152 preg_match(
"/(\d+)\s*,\s*(\d+)/", $point[
"coords"], $matches);
157 $convert_cmd .=
"-stroke " . $point[
"bordercolor"] .
" -fill " . $point[
"fillcolor"] .
" -strokewidth $this->linewidth_outer -draw \"line " .
158 ($x -
$r) .
"," . ($y -
$r) .
" " . ($x +
$r) .
"," . ($y +
$r) .
"\" " .
159 "-stroke " . $point[
"bordercolor"] .
" -fill " . $point[
"fillcolor"] .
" -strokewidth $this->linewidth_outer -draw \"line " .
160 ($x +
$r) .
"," . ($y -
$r) .
" " . ($x -
$r) .
"," . ($y +
$r) .
"\" " .
161 "-stroke " . $point[
"linecolor"] .
" -fill " . $point[
"fillcolor"] .
" -strokewidth $this->linewidth_inner -draw \"line " .
162 ($x -
$r) .
"," . ($y -
$r) .
" " . ($x +
$r) .
"," . ($y +
$r) .
"\" " .
163 "-stroke " . $point[
"linecolor"] .
" -fill " . $point[
"fillcolor"] .
" -strokewidth $this->linewidth_inner -draw \"line " .
164 ($x +
$r) .
"," . ($y -
$r) .
" " . ($x -
$r) .
"," . ($y +
$r) .
"\" ";
167 foreach ($this->areas as $area) {
168 if ($area[
"visible"] and strcmp(strtolower($area[
"shape"]),
"rect") == 0) {
169 preg_match(
"/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area[
"coords"], $matches);
175 $convert_cmd .=
"-stroke " . $area[
"bordercolor"] .
" -fill " . $area[
"fillcolor"] .
" -strokewidth $this->linewidth_outer -draw \"rectangle " .
176 $x0 .
"," . $y0 .
" " . ($x1) .
"," . $y1 .
"\" " .
177 "-stroke " . $area[
"linecolor"] .
" -fill " . $area[
"fillcolor"] .
" -strokewidth $this->linewidth_inner -draw \"rectangle " .
178 $x0 .
"," . $y0 .
" " . ($x1) .
"," . $y1 .
"\" ";
179 } elseif ($area[
"visible"] and strcmp(strtolower($area[
"shape"]),
"circle") == 0) {
180 preg_match(
"/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area[
"coords"], $matches);
185 $convert_cmd .=
"-stroke " . $area[
"bordercolor"] .
" -fill " . $area[
"fillcolor"] .
" -strokewidth $this->linewidth_outer -draw \"circle " .
186 $x .
"," . $y .
" " . ($x +
$r) .
"," . $y .
"\" " .
187 "-stroke " . $area[
"linecolor"] .
" -fill " . $area[
"fillcolor"] .
" -strokewidth $this->linewidth_inner -draw \"circle " .
188 $x .
"," . $y .
" " . ($x +
$r) .
"," . $y .
"\" ";
189 } elseif ($area[
"visible"] and strcmp(strtolower($area[
"shape"]),
"poly") == 0) {
192 preg_match_all(
"/(\d+)\s*,\s*(\d+)/", $area[
"coords"], $matches, PREG_PATTERN_ORDER);
193 if (count($matches[0]) == 2) {
196 $convert_cmd .=
"-stroke " . $area[
"bordercolor"] .
" -fill " . $area[
"fillcolor"] .
" -strokewidth $this->linewidth_outer -draw \"$obj ";
197 for ($i = 0; $i < count($matches[0]); $i++) {
198 $convert_cmd .= $matches[1][$i] .
"," . $matches[2][$i] .
" ";
200 $convert_cmd .=
"\" ";
201 $convert_cmd .=
"-stroke " . $area[
"linecolor"] .
" -fill " . $area[
"fillcolor"] .
" -strokewidth $this->linewidth_inner -draw \"$obj ";
202 preg_match_all(
"/(\d+)\s*,\s*(\d+)/", $area[
"coords"], $matches, PREG_PATTERN_ORDER);
203 for ($i = 0; $i < count($matches[0]); $i++) {
204 $convert_cmd .= $matches[1][$i] .
"," . $matches[2][$i] .
" ";
206 $convert_cmd .=
"\" ";
213 $convert_cmd = preg_replace(
'/\\\\(#([a-fA-F0-9]{3}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8}))/',
'${1}', $convert_cmd);
214 $convert_cmd = $source .
"[0] " . $convert_cmd .
" " . $target;
215 $this->
execQuoted(PATH_TO_CONVERT, $convert_cmd);
220 if (ini_get(
'safe_mode') == 1) {
223 setlocale(LC_CTYPE,
"UTF8",
"en_US.UTF-8");
224 return escapeshellcmd($a_arg);
231 if (
ilUtil::isWindows() && strpos($cmd,
" ") !==
false && substr($cmd, 0, 1) !==
'"') {
232 $cmd =
'"' . $cmd .
'"';
241 $DIC->logger()->root()->debug(
"ilUtil::execQuoted: " . $cmd .
".");
249 if (count($this->areas) + count($this->points) > 0) {
251 if (is_file($pfile)) {
253 $previewfile = $imagePath . $ident . $baseFileName;
254 if (@md5_file($previewfile) != @md5_file($pfile)) {
255 if (strlen($ident) > 0) {
256 @copy($pfile, $previewfile);
260 if (strlen($pfile) == 0) {
261 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"qpl_imagemap_preview_missing"));
266 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"qpl_imagemap_preview_missing"));
278 $map =
"<map name=\"$title\"> ";
279 foreach ($this->areas as $area) {
280 $map .=
"<area alt=\"" . $area[
"title"] .
"\" title=\"" . $area[
"title"] .
"\" ";
281 $map .=
"shape=\"" . $area[
"shape"] .
"\" ";
282 $map .=
"coords=\"" . $area[
"coords"] .
"\" ";
284 $map .=
"href=\"" . $area[
"href"] .
"\" ";
285 if ($area[
"target"]) {
286 $map .=
"target=\"" . $area[
"target"] .
"\" ";
290 $map .=
"nohref />\n";
getPreviewFilename($imagePath, $baseFileName)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $main_tpl
static execQuoted($cmd, $args=null)
getImagemap($title)
get imagemap html code note: html code should be placed in template files
static escapeShellCmd($a_arg)
__construct($imagemap_filename="")
ilImagemapPreview constructor
addPoint( $index, $coords, $visible=true, $linecolor="red", $bordercolor="white", $fillcolor="#FFFFFFA0")
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
addArea( $index, $shape, $coords, $title="", $href="", $target="", $visible=true, $linecolor="red", $bordercolor="white", $fillcolor="#FFFFFFA0")