ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilImagemapPreview Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilImagemapPreview:

Public Member Functions

 __construct ($imagemap_filename="")
 ilImagemapPreview constructor More...
 
 getAreaCount ()
 
 getPointCount ()
 
 addArea ( $index, $shape, $coords, $title="", $href="", $target="", $visible=true, $linecolor="red", $bordercolor="white", $fillcolor="#FFFFFFA0")
 
 addPoint ( $index, $coords, $visible=true, $linecolor="red", $bordercolor="white", $fillcolor="#FFFFFFA0")
 
 getAreaIdent ()
 
 createPreview ()
 
 getPreviewFilename ($imagePath, $baseFileName)
 
 getImagemap ($title)
 get imagemap html code note: html code should be placed in template files More...
 

Static Public Member Functions

static escapeShellCmd ($a_arg)
 
static execQuoted ($cmd, $args=null)
 

Data Fields

 $imagemap_filename
 
 $preview_filename
 
 $areas
 
 $points
 
 $linewidth_outer
 
 $linewidth_inner
 
 $lng
 

Private Attributes

ilGlobalTemplateInterface $main_tpl
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Image map image preview creator

Takes an image and imagemap areas and creates a preview image containing the imagemap areas.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 31 of file class.ilImagemapPreview.php.

Constructor & Destructor Documentation

◆ __construct()

ilImagemapPreview::__construct (   $imagemap_filename = "")

ilImagemapPreview constructor

Creates an instance of the ilImagemapPreview class

Parameters
integer$idThe database id of a image map question object public

Definition at line 50 of file class.ilImagemapPreview.php.

References $DIC, $imagemap_filename, $lng, ilFileUtils\ilTempnam(), and ILIAS\Repository\lng().

51  {
52  global $DIC;
53  $this->main_tpl = $DIC->ui()->mainTemplate();
54  $lng = $DIC['lng'];
55  $this->lng = &$lng;
56  $this->imagemap_filename = $imagemap_filename;
57 
58  if (!@is_file($this->preview_filename)) {
59  $extension = ".jpg";
60  if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches)) {
61  $extension = "." . $matches[1];
62  }
63  include_once "./Services/Utilities/classes/class.ilUtil.php";
64  $this->preview_filename = ilFileUtils::ilTempnam() . $extension;
65  }
66  $this->areas = array();
67  $this->points = array();
68  $this->linewidth_outer = 4;
69  $this->linewidth_inner = 2;
70  }
global $DIC
Definition: feed.php:28
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
+ Here is the call graph for this function:

Member Function Documentation

◆ addArea()

ilImagemapPreview::addArea (   $index,
  $shape,
  $coords,
  $title = "",
  $href = "",
  $target = "",
  $visible = true,
  $linecolor = "red",
  $bordercolor = "white",
  $fillcolor = "#FFFFFFA0" 
)

Definition at line 82 of file class.ilImagemapPreview.php.

References $index.

93  : void {
94  if (ini_get("safe_mode")) {
95  if ((strpos($fillcolor, "#") !== false) || (strpos($fillcolor, "rgb") !== false)) {
96  $fillcolor = str_replace("\"", "", $fillcolor);
97  }
98  }
99  $this->areas[$index] = array(
100  "shape" => "$shape",
101  "coords" => "$coords",
102  "title" => htmlspecialchars($title),
103  "href" => "$href",
104  "target" => "$target",
105  "linecolor" => '"' . $linecolor . '"',
106  "fillcolor" => '"' . $fillcolor . '"',
107  "bordercolor" => '"' . $bordercolor . '"',
108  "visible" => (int) $visible
109  );
110  }
$index
Definition: metadata.php:145

◆ addPoint()

ilImagemapPreview::addPoint (   $index,
  $coords,
  $visible = true,
  $linecolor = "red",
  $bordercolor = "white",
  $fillcolor = "#FFFFFFA0" 
)

Definition at line 112 of file class.ilImagemapPreview.php.

References $index.

119  : void {
120  $this->points[$index] = array(
121  "coords" => "$coords",
122  "linecolor" => '"' . $linecolor . '"',
123  "fillcolor" => '"' . $fillcolor . '"',
124  "bordercolor" => '"' . $bordercolor . '"',
125  "visible" => (int) $visible
126  );
127  }
$index
Definition: metadata.php:145

◆ createPreview()

ilImagemapPreview::createPreview ( )

Definition at line 145 of file class.ilImagemapPreview.php.

References $i, $source, escapeShellCmd(), and execQuoted().

145  : void
146  {
147  if (count($this->areas) + count($this->points) == 0) {
148  return;
149  }
150  include_once "./Services/Utilities/classes/class.ilUtil.php";
151  $convert_cmd = "-quality 100 ";
152  foreach ($this->points as $point) {
153  if ($point["visible"]) {
154  preg_match("/(\d+)\s*,\s*(\d+)/", $point["coords"], $matches);
155  $x = $matches[1];
156  $y = $matches[2];
157  $r = 6;
158  // draw a circle at the point
159  $convert_cmd .= "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
160  ($x - $r) . "," . ($y - $r) . " " . ($x + $r) . "," . ($y + $r) . "\" " .
161  "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -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) . "\" " .
165  "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
166  ($x + $r) . "," . ($y - $r) . " " . ($x - $r) . "," . ($y + $r) . "\" ";
167  }
168  }
169  foreach ($this->areas as $area) {
170  if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0) {
171  preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
172  $x0 = $matches[1];
173  $y0 = $matches[2];
174  $x1 = $matches[3];
175  $y1 = $matches[4];
176  // draw a rect around the selection
177  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
178  $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
179  "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
180  $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
181  } elseif ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0) {
182  preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
183  $x = $matches[1];
184  $y = $matches[2];
185  $r = $matches[3];
186  // draw a circle around the selection
187  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
188  $x . "," . $y . " " . ($x + $r) . "," . $y . "\" " .
189  "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
190  $x . "," . $y . " " . ($x + $r) . "," . $y . "\" ";
191  } elseif ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0) {
192  $obj = "polygon";
193  // draw a polygon around the selection
194  preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
195  if (count($matches[0]) == 2) {
196  $obj = "line";
197  }
198  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"$obj ";
199  for ($i = 0; $i < count($matches[0]); $i++) {
200  $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
201  }
202  $convert_cmd .= "\" ";
203  $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"$obj ";
204  preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
205  for ($i = 0; $i < count($matches[0]); $i++) {
206  $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
207  }
208  $convert_cmd .= "\" ";
209  }
210  }
211 
212  $source = $this->escapeShellCmd($this->imagemap_filename);
213  $target = $this->escapeShellCmd($this->preview_filename);
214  $convert_cmd = $this->escapeShellCmd($convert_cmd);
215  $convert_cmd = preg_replace('/\\\\(#([a-fA-F0-9]{3}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8}))/', '${1}', $convert_cmd);
216  $convert_cmd = $source . "[0] " . $convert_cmd . " " . $target;
217  $this->execQuoted(PATH_TO_CONVERT, $convert_cmd);
218  }
static execQuoted($cmd, $args=null)
$source
Definition: metadata.php:93
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

◆ escapeShellCmd()

static ilImagemapPreview::escapeShellCmd (   $a_arg)
static

Definition at line 220 of file class.ilImagemapPreview.php.

Referenced by createPreview().

221  {
222  if (ini_get('safe_mode') == 1) {
223  return $a_arg;
224  }
225  setlocale(LC_CTYPE, "UTF8", "en_US.UTF-8"); // fix for PHP escapeshellcmd bug. See: http://bugs.php.net/bug.php?id=45132
226  return escapeshellcmd($a_arg);
227  }
+ Here is the caller graph for this function:

◆ execQuoted()

static ilImagemapPreview::execQuoted (   $cmd,
  $args = null 
)
static

Definition at line 229 of file class.ilImagemapPreview.php.

References $DIC, and ilUtil\isWindows().

Referenced by createPreview().

230  {
231  global $DIC;
232 
233  if (ilUtil::isWindows() && strpos($cmd, " ") !== false && substr($cmd, 0, 1) !== '"') {
234  $cmd = '"' . $cmd . '"';
235  if ($args) {
236  $cmd .= " " . $args;
237  }
238  } elseif ($args) {
239  $cmd .= " " . $args;
240  }
241  exec($cmd, $arr);
242 
243  $DIC->logger()->root()->debug("ilUtil::execQuoted: " . $cmd . ".");
244 
245  return $arr;
246  }
static isWindows()
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAreaCount()

ilImagemapPreview::getAreaCount ( )

Definition at line 72 of file class.ilImagemapPreview.php.

72  : int
73  {
74  return count($this->areas);
75  }

◆ getAreaIdent()

ilImagemapPreview::getAreaIdent ( )

Definition at line 129 of file class.ilImagemapPreview.php.

Referenced by getPreviewFilename().

129  : string
130  {
131  if (count($this->areas) + count($this->points) > 0) {
132  $arr = array_merge(array_keys($this->areas), array_keys($this->points));
133  sort($arr, SORT_NUMERIC);
134 
135  $inner = join("_", $arr);
136  if (strlen($inner) > 32) {
137  $inner = md5($inner);
138  }
139  return "preview_" . $inner . "_";
140  } else {
141  return "";
142  }
143  }
+ Here is the caller graph for this function:

◆ getImagemap()

ilImagemapPreview::getImagemap (   $title)

get imagemap html code note: html code should be placed in template files

Definition at line 278 of file class.ilImagemapPreview.php.

278  : string
279  {
280  $map = "<map name=\"$title\"> ";
281  foreach ($this->areas as $area) {
282  $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
283  $map .= "shape=\"" . $area["shape"] . "\" ";
284  $map .= "coords=\"" . $area["coords"] . "\" ";
285  if ($area["href"]) {
286  $map .= "href=\"" . $area["href"] . "\" ";
287  if ($area["target"]) {
288  $map .= "target=\"" . $area["target"] . "\" ";
289  }
290  $map .= "/>\n";
291  } else {
292  $map .= "nohref />\n";
293  }
294  }
295  $map .= "</map>";
296  return $map;
297  }

◆ getPointCount()

ilImagemapPreview::getPointCount ( )

Definition at line 77 of file class.ilImagemapPreview.php.

77  : int
78  {
79  return count($this->points);
80  }

◆ getPreviewFilename()

ilImagemapPreview::getPreviewFilename (   $imagePath,
  $baseFileName 
)

Definition at line 248 of file class.ilImagemapPreview.php.

References $filename, $preview_filename, getAreaIdent(), and ILIAS\Repository\lng().

249  {
250  $filename = $baseFileName;
251  if (count($this->areas) + count($this->points) > 0) {
252  $pfile = $this->preview_filename;
253  if (is_file($pfile)) {
254  $ident = $this->getAreaIdent();
255  $previewfile = $imagePath . $ident . $baseFileName;
256  if (@md5_file($previewfile) != @md5_file($pfile)) {
257  if (strlen($ident) > 0) {
258  @copy($pfile, $previewfile);
259  }
260  }
261  @unlink($pfile);
262  if (strlen($pfile) == 0) {
263  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("qpl_imagemap_preview_missing"));
264  } else {
265  $filename = basename($previewfile);
266  }
267  } else {
268  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("qpl_imagemap_preview_missing"));
269  }
270  }
271  return $filename;
272  }
$filename
Definition: buildRTE.php:78
+ Here is the call graph for this function:

Field Documentation

◆ $areas

ilImagemapPreview::$areas

Definition at line 35 of file class.ilImagemapPreview.php.

◆ $imagemap_filename

ilImagemapPreview::$imagemap_filename

Definition at line 33 of file class.ilImagemapPreview.php.

Referenced by __construct().

◆ $linewidth_inner

ilImagemapPreview::$linewidth_inner

Definition at line 38 of file class.ilImagemapPreview.php.

◆ $linewidth_outer

ilImagemapPreview::$linewidth_outer

Definition at line 37 of file class.ilImagemapPreview.php.

◆ $lng

ilImagemapPreview::$lng

Definition at line 39 of file class.ilImagemapPreview.php.

Referenced by __construct().

◆ $main_tpl

ilGlobalTemplateInterface ilImagemapPreview::$main_tpl
private

Definition at line 40 of file class.ilImagemapPreview.php.

◆ $points

ilImagemapPreview::$points

Definition at line 36 of file class.ilImagemapPreview.php.

◆ $preview_filename

ilImagemapPreview::$preview_filename

Definition at line 34 of file class.ilImagemapPreview.php.

Referenced by getPreviewFilename().


The documentation for this class was generated from the following file: