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 include_once "./classes/class.ilUtil.php";
00068 $this->preview_filename = ilUtil::ilTempnam() . $extension;
00069 }
00070 $this->areas = array();
00071 $this->linewidth_outer = 4;
00072 $this->linewidth_inner = 2;
00073 }
00074
00075 function addArea(
00076 $shape,
00077 $coords,
00078 $title = "",
00079 $href = "",
00080 $target = "",
00081 $visible = true,
00082 $linecolor = "red",
00083 $bordercolor = "white",
00084 $fillcolor = "\"#FFFFFFC0\""
00085 )
00086 {
00087 array_push($this->areas, array(
00088 "shape" => "$shape",
00089 "coords" => "$coords",
00090 "title" => "$title",
00091 "href" => "$href",
00092 "target" => "$target",
00093 "linecolor" => "$linecolor",
00094 "fillcolor" => "$fillcolor",
00095 "bordercolor" => "$bordercolor",
00096 "visible" => (int)$visible
00097 ));
00098 }
00099
00100 function deleteArea($key, $value)
00101 {
00102 foreach ($this->areas as $areakey => $areavalue)
00103 {
00104 if (strcmp($value, $areavalue[$key]) == 0)
00105 {
00106 unset($this->areas[$areakey]);
00107 }
00108 }
00109 $this->areas = array_values($this->areas);
00110 }
00111
00112 function createPreview()
00113 {
00114 if (!count($this->areas)) return;
00115 $convert_prefix = ilUtil::getConvertCmd() . " -quality 100 ";
00116 foreach ($this->areas as $area)
00117 {
00118 if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0)
00119 {
00120 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00121 $x0 = $matches[1];
00122 $y0 = $matches[2];
00123 $x1 = $matches[3];
00124 $y1 = $matches[4];
00125
00126 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
00127 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
00128 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
00129 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
00130 }
00131 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0)
00132 {
00133 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00134 $x = $matches[1];
00135 $y = $matches[2];
00136 $r = $matches[3];
00137
00138 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
00139 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" " .
00140 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
00141 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" ";
00142 }
00143 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0)
00144 {
00145
00146 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"polygon ";
00147 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00148 for ($i = 0; $i < count($matches[0]); $i++)
00149 {
00150 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00151 }
00152 $convert_cmd .= "\" ";
00153 $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"polygon ";
00154 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00155 for ($i = 0; $i < count($matches[0]); $i++)
00156 {
00157 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00158 }
00159 $convert_cmd .= "\" ";
00160 }
00161 }
00162 $convert_cmd = $convert_prefix . $convert_cmd . escapeshellarg($this->imagemap_filename) ." " . escapeshellarg($this->preview_filename);
00163 system($convert_cmd);
00164 }
00165
00166 function getPreviewFilename()
00167 {
00168
00169 return basename($this->preview_filename);
00170 }
00171
00176 function getImagemap($title)
00177 {
00178 $map = "<map name=\"$title\"> ";
00179 foreach ($this->areas as $area)
00180 {
00181 $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
00182 $map .= "shape=\"" . $area["shape"] . "\" ";
00183 $map .= "coords=\"" . $area["coords"] . "\" ";
00184 if ($area["href"])
00185 {
00186 $map .= "href=\"" . $area["href"] . "\" ";
00187 if ($area["target"])
00188 {
00189 $map .= "target=\"" . $area["target"] . "\" ";
00190 }
00191 $map .= "/>\n";
00192 }
00193 else
00194 {
00195 $map .= "nohref />\n";
00196 }
00197 }
00198 $map .= "</map>";
00199 return $map;
00200 }
00201
00202 }
00203 ?>