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 include_once "./assessment/classes/inc.AssessmentConstants.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 if (ini_get("safe_mode"))
00088 {
00089 if ((strpos($fillcolor, "#") !== false) || (strpos($fillcolor, "rgb") !== false))
00090 {
00091 $fillcolor = str_replace("\"", "", $fillcolor);
00092 }
00093 }
00094 array_push($this->areas, array(
00095 "shape" => "$shape",
00096 "coords" => "$coords",
00097 "title" => "$title",
00098 "href" => "$href",
00099 "target" => "$target",
00100 "linecolor" => "$linecolor",
00101 "fillcolor" => "$fillcolor",
00102 "bordercolor" => "$bordercolor",
00103 "visible" => (int)$visible
00104 ));
00105 }
00106
00107 function deleteArea($key, $value)
00108 {
00109 foreach ($this->areas as $areakey => $areavalue)
00110 {
00111 if (strcmp($value, $areavalue[$key]) == 0)
00112 {
00113 unset($this->areas[$areakey]);
00114 }
00115 }
00116 $this->areas = array_values($this->areas);
00117 }
00118
00119 function createPreview()
00120 {
00121 if (!count($this->areas)) return;
00122 include_once "./classes/class.ilUtil.php";
00123 $convert_prefix = ilUtil::getConvertCmd() . " -quality 100 ";
00124 foreach ($this->areas as $area)
00125 {
00126 if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0)
00127 {
00128 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00129 $x0 = $matches[1];
00130 $y0 = $matches[2];
00131 $x1 = $matches[3];
00132 $y1 = $matches[4];
00133
00134 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
00135 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
00136 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
00137 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
00138 }
00139 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0)
00140 {
00141 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00142 $x = $matches[1];
00143 $y = $matches[2];
00144 $r = $matches[3];
00145
00146 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
00147 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" " .
00148 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
00149 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" ";
00150 }
00151 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0)
00152 {
00153
00154 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"polygon ";
00155 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00156 for ($i = 0; $i < count($matches[0]); $i++)
00157 {
00158 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00159 }
00160 $convert_cmd .= "\" ";
00161 $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"polygon ";
00162 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00163 for ($i = 0; $i < count($matches[0]); $i++)
00164 {
00165 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00166 }
00167 $convert_cmd .= "\" ";
00168 }
00169 }
00170 $convert_cmd = $convert_prefix . $convert_cmd . escapeshellcmd(str_replace(" ", "\ ", $this->imagemap_filename)) ." " . escapeshellcmd($this->preview_filename);
00171 system($convert_cmd);
00172 }
00173
00174 function getPreviewFilename()
00175 {
00176 if (is_file($this->preview_filename))
00177 {
00178 return basename($this->preview_filename);
00179 }
00180 else
00181 {
00182 return "";
00183 }
00184 }
00185
00190 function getImagemap($title)
00191 {
00192 $map = "<map name=\"$title\"> ";
00193 foreach ($this->areas as $area)
00194 {
00195 $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
00196 $map .= "shape=\"" . $area["shape"] . "\" ";
00197 $map .= "coords=\"" . $area["coords"] . "\" ";
00198 if ($area["href"])
00199 {
00200 $map .= "href=\"" . $area["href"] . "\" ";
00201 if ($area["target"])
00202 {
00203 $map .= "target=\"" . $area["target"] . "\" ";
00204 }
00205 $map .= "/>\n";
00206 }
00207 else
00208 {
00209 $map .= "nohref />\n";
00210 }
00211 }
00212 $map .= "</map>";
00213 return $map;
00214 }
00215
00216 }
00217 ?>