00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once "./classes/class.ilUtil.php";
00025
00037 class ilImagemapPreview
00038 {
00039 var $imagemap_filename;
00040 var $preview_filename;
00041 var $areas;
00042 var $linewidth_outer;
00043 var $linewidth_inner;
00044
00053 function ilImagemapPreview(
00054 $imagemap_filename = "",
00055 $preview_filename = ""
00056 )
00057 {
00058 $this->imagemap_filename = $imagemap_filename;
00059 $this->preview_filename = $preview_filename;
00060 if (!@is_file($this->preview_filename))
00061 {
00062 $extension = ".jpg";
00063 if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches))
00064 {
00065 $extension = "." . $matches[1];
00066 }
00067 $this->preview_filename = ilUtil::ilTempnam() . $extension;
00068 }
00069 $this->areas = array();
00070 $this->linewidth_outer = 4;
00071 $this->linewidth_inner = 2;
00072 }
00073
00074 function addArea(
00075 $shape,
00076 $coords,
00077 $title = "",
00078 $href = "",
00079 $target = "",
00080 $visible = true,
00081 $linecolor = "red",
00082 $bordercolor = "white",
00083 $fillcolor = "\"#FFFFFFC0\""
00084 )
00085 {
00086 array_push($this->areas, array(
00087 "shape" => "$shape",
00088 "coords" => "$coords",
00089 "title" => "$title",
00090 "href" => "$href",
00091 "target" => "$target",
00092 "linecolor" => "$linecolor",
00093 "fillcolor" => "$fillcolor",
00094 "bordercolor" => "$bordercolor",
00095 "visible" => (int)$visible
00096 ));
00097 }
00098
00099 function deleteArea($key, $value)
00100 {
00101 foreach ($this->areas as $areakey => $areavalue)
00102 {
00103 if (strcmp($value, $areavalue[$key]) == 0)
00104 {
00105 unset($this->areas[$areakey]);
00106 }
00107 }
00108 $this->areas = array_values($this->areas);
00109 }
00110
00111 function createPreview()
00112 {
00113 if (!count($this->areas)) return;
00114 $convert_prefix = ilUtil::getConvertCmd() . " -quality 100 ";
00115 foreach ($this->areas as $area)
00116 {
00117 if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0)
00118 {
00119 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00120 $x0 = $matches[1];
00121 $y0 = $matches[2];
00122 $x1 = $matches[3];
00123 $y1 = $matches[4];
00124
00125 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
00126 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
00127 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
00128 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
00129 }
00130 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0)
00131 {
00132 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00133 $x = $matches[1];
00134 $y = $matches[2];
00135 $r = $matches[3];
00136
00137 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
00138 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" " .
00139 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
00140 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" ";
00141 }
00142 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0)
00143 {
00144
00145 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"polygon ";
00146 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00147 for ($i = 0; $i < count($matches[0]); $i++)
00148 {
00149 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00150 }
00151 $convert_cmd .= "\" ";
00152 $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"polygon ";
00153 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00154 for ($i = 0; $i < count($matches[0]); $i++)
00155 {
00156 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00157 }
00158 $convert_cmd .= "\" ";
00159 }
00160 }
00161 $convert_cmd = $convert_prefix . $convert_cmd . escapeshellcmd(str_replace(" ", "\ ", $this->imagemap_filename)) ." " . escapeshellcmd($this->preview_filename);
00162 system($convert_cmd);
00163 }
00164
00165 function getPreviewFilename()
00166 {
00167 if (is_file($this->preview_filename))
00168 {
00169 return basename($this->preview_filename);
00170 }
00171 else
00172 {
00173 return "";
00174 }
00175 }
00176
00181 function getImagemap($title)
00182 {
00183 $map = "<map name=\"$title\"> ";
00184 foreach ($this->areas as $area)
00185 {
00186 $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
00187 $map .= "shape=\"" . $area["shape"] . "\" ";
00188 $map .= "coords=\"" . $area["coords"] . "\" ";
00189 if ($area["href"])
00190 {
00191 $map .= "href=\"" . $area["href"] . "\" ";
00192 if ($area["target"])
00193 {
00194 $map .= "target=\"" . $area["target"] . "\" ";
00195 }
00196 $map .= "/>\n";
00197 }
00198 else
00199 {
00200 $map .= "nohref />\n";
00201 }
00202 }
00203 $map .= "</map>";
00204 return $map;
00205 }
00206
00207 }
00208 ?>