ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 (string $image_path, string $base_file_name)
 
 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 29 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 @access public

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

49 {
50 global $DIC;
51 $this->main_tpl = $DIC->ui()->mainTemplate();
52 $lng = $DIC['lng'];
53 $this->lng = &$lng;
54 $this->imagemap_filename = $imagemap_filename;
55
56 if (!@is_file($this->preview_filename)) {
57 $extension = ".jpg";
58 if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches)) {
59 $extension = "." . $matches[1];
60 }
61 $this->preview_filename = ilFileUtils::ilTempnam() . $extension;
62 }
63 $this->areas = [];
64 $this->points = [];
65 $this->linewidth_outer = 4;
66 $this->linewidth_inner = 2;
67 }
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
global $DIC
Definition: shib_login.php:26

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

+ 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 79 of file class.ilImagemapPreview.php.

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

◆ addPoint()

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

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

116 : void {
117 $this->points[$index] = [
118 "coords" => "$coords",
119 "linecolor" => '"' . $linecolor . '"',
120 "fillcolor" => '"' . $fillcolor . '"',
121 "bordercolor" => '"' . $bordercolor . '"',
122 "visible" => (int) $visible
123 ];
124 }

◆ createPreview()

ilImagemapPreview::createPreview ( )

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

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

◆ escapeShellCmd()

static ilImagemapPreview::escapeShellCmd (   $a_arg)
static

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

217 {
218 if (ini_get('safe_mode') == 1) {
219 return $a_arg;
220 }
221 setlocale(LC_CTYPE, "UTF8", "en_US.UTF-8"); // fix for PHP escapeshellcmd bug. See: http://bugs.php.net/bug.php?id=45132
222 return escapeshellcmd($a_arg);
223 }

◆ execQuoted()

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

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

226 {
227 global $DIC;
228
229 if (ilUtil::isWindows() && strpos($cmd, " ") !== false && substr($cmd, 0, 1) !== '"') {
230 $cmd = '"' . $cmd . '"';
231 if ($args) {
232 $cmd .= " " . $args;
233 }
234 } elseif ($args) {
235 $cmd .= " " . $args;
236 }
237 exec($cmd, $arr);
238
239 $DIC->logger()->root()->debug("ilUtil::execQuoted: " . $cmd . ".");
240
241 return $arr;
242 }
static isWindows()

References $DIC, and ilUtil\isWindows().

+ Here is the call graph for this function:

◆ getAreaCount()

ilImagemapPreview::getAreaCount ( )

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

69 : int
70 {
71 return count($this->areas);
72 }

◆ getAreaIdent()

ilImagemapPreview::getAreaIdent ( )

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

126 : string
127 {
128 if (count($this->areas) + count($this->points) > 0) {
129 $arr = array_merge(array_keys($this->areas), array_keys($this->points));
130 sort($arr, SORT_NUMERIC);
131
132 $inner = join("_", $arr);
133 if (strlen($inner) > 32) {
134 $inner = md5($inner);
135 }
136 return "preview_" . $inner . "_";
137 } else {
138 return "";
139 }
140 }

References ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ getImagemap()

ilImagemapPreview::getImagemap (   $title)

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

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

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

◆ getPointCount()

ilImagemapPreview::getPointCount ( )

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

74 : int
75 {
76 return count($this->points);
77 }

◆ getPreviewFilename()

ilImagemapPreview::getPreviewFilename ( string  $image_path,
string  $base_file_name 
)

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

247 : string {
248 if (count($this->areas) + count($this->points) < 1) {
249 return $base_file_name;
250 }
251
252 $preview_file = $this->preview_filename;
253 if (!is_file($preview_file)) {
254 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("qpl_imagemap_preview_missing"));
255 return $base_file_name;
256 }
257
258 $ident = $this->getAreaIdent();
259 $requested_preview_file = $image_path . $ident . $base_file_name;
260 if ((!is_file($requested_preview_file)
261 || md5_file($requested_preview_file) !== md5_file($preview_file))
262 && $ident !== '') {
263 copy($preview_file, $requested_preview_file);
264 }
265 unlink($preview_file);
266 return basename($requested_preview_file);
267 }

Field Documentation

◆ $areas

ilImagemapPreview::$areas

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

◆ $imagemap_filename

ilImagemapPreview::$imagemap_filename

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

Referenced by __construct().

◆ $linewidth_inner

ilImagemapPreview::$linewidth_inner

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

◆ $linewidth_outer

ilImagemapPreview::$linewidth_outer

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

◆ $lng

ilImagemapPreview::$lng

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

Referenced by __construct().

◆ $main_tpl

ilGlobalTemplateInterface ilImagemapPreview::$main_tpl
private

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

◆ $points

ilImagemapPreview::$points

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

◆ $preview_filename

ilImagemapPreview::$preview_filename

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


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