ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilImagemapPreview Class Reference

Image map image preview creator. 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...
 

Data Fields

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

Detailed Description

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 16 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 34 of file class.ilImagemapPreview.php.

References $DIC, $imagemap_filename, $lng, $preview_filename, and ilUtil\ilTempnam().

35  {
36  global $DIC;
37  $lng = $DIC['lng'];
38  $this->lng = &$lng;
39  $this->imagemap_filename = $imagemap_filename;
40  $this->preview_filename = $preview_filename;
41  if (!@is_file($this->preview_filename)) {
42  $extension = ".jpg";
43  if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches)) {
44  $extension = "." . $matches[1];
45  }
46  include_once "./Services/Utilities/classes/class.ilUtil.php";
47  $this->preview_filename = ilUtil::ilTempnam() . $extension;
48  }
49  $this->areas = array();
50  $this->points = array();
51  $this->linewidth_outer = 4;
52  $this->linewidth_inner = 2;
53  }
global $DIC
Definition: saml.php:7
static ilTempnam($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 65 of file class.ilImagemapPreview.php.

References $index.

76  {
77  if (ini_get("safe_mode")) {
78  if ((strpos($fillcolor, "#") !== false) ||  (strpos($fillcolor, "rgb") !== false)) {
79  $fillcolor = str_replace("\"", "", $fillcolor);
80  }
81  }
82  $this->areas[$index] = array(
83  "shape" => "$shape",
84  "coords" => "$coords",
85  "title" => "$title",
86  "href" => "$href",
87  "target" => "$target",
88  "linecolor" => '"' . $linecolor . '"',
89  "fillcolor" => '"' . $fillcolor . '"',
90  "bordercolor" => '"' . $bordercolor . '"',
91  "visible" => (int) $visible
92  );
93  }
$index
Definition: metadata.php:60

◆ addPoint()

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

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

References $index.

102  {
103  $this->points[$index] = array(
104  "coords" => "$coords",
105  "linecolor" => '"' . $linecolor . '"',
106  "fillcolor" => '"' . $fillcolor . '"',
107  "bordercolor" => '"' . $bordercolor . '"',
108  "visible" => (int) $visible
109  );
110  }
$index
Definition: metadata.php:60

◆ createPreview()

ilImagemapPreview::createPreview ( )

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

References $i, $r, $source, $target, $x, $y, ilUtil\escapeShellCmd(), and ilUtil\execConvert().

129  {
130  if (count($this->areas) + count($this->points) == 0) {
131  return;
132  }
133  include_once "./Services/Utilities/classes/class.ilUtil.php";
134  $convert_cmd = "-quality 100 ";
135  foreach ($this->points as $point) {
136  if ($point["visible"]) {
137  preg_match("/(\d+)\s*,\s*(\d+)/", $point["coords"], $matches);
138  $x = $matches[1];
139  $y = $matches[2];
140  $r = 6;
141  // draw a circle at the point
142  $convert_cmd .= "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
143  ($x - $r) . "," . ($y - $r) . " " . ($x + $r) . "," . ($y + $r) . "\" " .
144  "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
145  ($x + $r) . "," . ($y - $r) . " " . ($x - $r) . "," . ($y + $r) . "\" " .
146  "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
147  ($x - $r) . "," . ($y - $r) . " " . ($x + $r) . "," . ($y + $r) . "\" " .
148  "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
149  ($x + $r) . "," . ($y - $r) . " " . ($x - $r) . "," . ($y + $r) . "\" ";
150  }
151  }
152  foreach ($this->areas as $area) {
153  if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0) {
154  preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
155  $x0 = $matches[1];
156  $y0 = $matches[2];
157  $x1 = $matches[3];
158  $y1 = $matches[4];
159  // draw a rect around the selection
160  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
161  $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
162  "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
163  $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
164  } elseif ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0) {
165  preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
166  $x = $matches[1];
167  $y = $matches[2];
168  $r = $matches[3];
169  // draw a circle around the selection
170  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
171  $x . "," . $y . " " . ($x + $r) . "," . $y . "\" " .
172  "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
173  $x . "," . $y . " " . ($x + $r) . "," . $y . "\" ";
174  } elseif ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0) {
175  $obj = "polygon";
176  // draw a polygon around the selection
177  preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
178  if (count($matches[0]) == 2) {
179  $obj = "line";
180  }
181  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"$obj ";
182  for ($i = 0; $i < count($matches[0]); $i++) {
183  $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
184  }
185  $convert_cmd .= "\" ";
186  $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"$obj ";
187  preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
188  for ($i = 0; $i < count($matches[0]); $i++) {
189  $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
190  }
191  $convert_cmd .= "\" ";
192  }
193  }
194 
195  $source = ilUtil::escapeShellCmd($this->imagemap_filename);
196  $target = ilUtil::escapeShellCmd($this->preview_filename);
197  $convert_cmd = $source . "[0] " . $convert_cmd . " " . $target;
198  ilUtil::execConvert($convert_cmd);
199  }
static escapeShellCmd($a_arg)
escape shell cmd
$r
Definition: example_031.php:79
$y
Definition: example_007.php:83
static execConvert($args)
execute convert command
$i
Definition: disco.tpl.php:19
$source
Definition: linkback.php:22
$target
Definition: test.php:19
$x
Definition: complexTest.php:9
+ Here is the call graph for this function:

◆ getAreaCount()

ilImagemapPreview::getAreaCount ( )

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

56  {
57  return count($this->areas);
58  }

◆ getAreaIdent()

ilImagemapPreview::getAreaIdent ( )

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

Referenced by getPreviewFilename().

113  {
114  if (count($this->areas) + count($this->points) > 0) {
115  $arr = array_merge(array_keys($this->areas), array_keys($this->points));
116  sort($arr, SORT_NUMERIC);
117 
118  $inner = join("_", $arr);
119  if (strlen($inner) > 32) {
120  $inner = md5($inner);
121  }
122  return "preview_" . $inner . "_";
123  } else {
124  return "";
125  }
126  }
+ 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 231 of file class.ilImagemapPreview.php.

References $map.

232  {
233  $map = "<map name=\"$title\"> ";
234  foreach ($this->areas as $area) {
235  $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
236  $map .= "shape=\"" . $area["shape"] . "\" ";
237  $map .= "coords=\"" . $area["coords"] . "\" ";
238  if ($area["href"]) {
239  $map .= "href=\"" . $area["href"] . "\" ";
240  if ($area["target"]) {
241  $map .= "target=\"" . $area["target"] . "\" ";
242  }
243  $map .= "/>\n";
244  } else {
245  $map .= "nohref />\n";
246  }
247  }
248  $map .= "</map>";
249  return $map;
250  }

◆ getPointCount()

ilImagemapPreview::getPointCount ( )

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

61  {
62  return count($this->points);
63  }

◆ getPreviewFilename()

ilImagemapPreview::getPreviewFilename (   $imagePath,
  $baseFileName 
)

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

References $filename, $preview_filename, getAreaIdent(), and ilUtil\sendInfo().

202  {
203  $filename = $baseFileName;
204  if (count($this->areas) + count($this->points) > 0) {
205  $pfile = $this->preview_filename;
206  if (is_file($pfile)) {
207  $ident = $this->getAreaIdent();
208  $previewfile = $imagePath . $ident . $baseFileName;
209  if (@md5_file($previewfile) != @md5_file($pfile)) {
210  if (strlen($ident) > 0) {
211  @copy($pfile, $previewfile);
212  }
213  }
214  @unlink($pfile);
215  if (strlen($pfile) == 0) {
216  ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
217  } else {
218  $filename = basename($previewfile);
219  }
220  } else {
221  ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
222  }
223  }
224  return $filename;
225  }
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$filename
Definition: buildRTE.php:89
+ Here is the call graph for this function:

Field Documentation

◆ $areas

ilImagemapPreview::$areas

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

◆ $imagemap_filename

ilImagemapPreview::$imagemap_filename

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

Referenced by __construct().

◆ $linewidth_inner

ilImagemapPreview::$linewidth_inner

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

◆ $linewidth_outer

ilImagemapPreview::$linewidth_outer

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

◆ $lng

ilImagemapPreview::$lng

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

Referenced by __construct().

◆ $points

ilImagemapPreview::$points

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

◆ $preview_filename

ilImagemapPreview::$preview_filename

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

Referenced by __construct(), and getPreviewFilename().


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