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";
00035 class ilImagemapPreview
00036 {
00037 var $imagemap_filename;
00038 var $preview_filename;
00039 var $areas;
00040 var $linewidth_outer;
00041 var $linewidth_inner;
00042
00051 function ilImagemapPreview($imagemap_filename = "")
00052 {
00053 $this->imagemap_filename = $imagemap_filename;
00054 $this->preview_filename = $preview_filename;
00055 if (!@is_file($this->preview_filename))
00056 {
00057 $extension = ".jpg";
00058 if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches))
00059 {
00060 $extension = "." . $matches[1];
00061 }
00062 include_once "./classes/class.ilUtil.php";
00063 $this->preview_filename = ilUtil::ilTempnam() . $extension;
00064 }
00065 $this->areas = array();
00066 $this->linewidth_outer = 4;
00067 $this->linewidth_inner = 2;
00068 }
00069
00070 function getAreaCount()
00071 {
00072 return count($this->areas);
00073 }
00074
00075 function addArea(
00076 $index,
00077 $shape,
00078 $coords,
00079 $title = "",
00080 $href = "",
00081 $target = "",
00082 $visible = true,
00083 $linecolor = "red",
00084 $bordercolor = "white",
00085 $fillcolor = "\"#FFFFFFA0\""
00086 )
00087 {
00088 if (ini_get("safe_mode"))
00089 {
00090 if ((strpos($fillcolor, "#") !== false) || (strpos($fillcolor, "rgb") !== false))
00091 {
00092 $fillcolor = str_replace("\"", "", $fillcolor);
00093 }
00094 }
00095 $this->areas[$index] = array(
00096 "shape" => "$shape",
00097 "coords" => "$coords",
00098 "title" => "$title",
00099 "href" => "$href",
00100 "target" => "$target",
00101 "linecolor" => "$linecolor",
00102 "fillcolor" => "$fillcolor",
00103 "bordercolor" => "$bordercolor",
00104 "visible" => (int)$visible
00105 );
00106 }
00107
00108 function getAreaIdent()
00109 {
00110 if (count($this->areas) > 0)
00111 {
00112 $arr = array_keys($this->areas);
00113 sort($arr, SORT_NUMERIC);
00114 return "preview_" . join("_", $arr) . "_";
00115 }
00116 else
00117 {
00118 return "";
00119 }
00120 }
00121
00122 function createPreview()
00123 {
00124 if (!count($this->areas)) return;
00125 include_once "./classes/class.ilUtil.php";
00126 $convert_prefix = ilUtil::getConvertCmd() . " -quality 100 ";
00127 foreach ($this->areas as $area)
00128 {
00129 if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0)
00130 {
00131 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00132 $x0 = $matches[1];
00133 $y0 = $matches[2];
00134 $x1 = $matches[3];
00135 $y1 = $matches[4];
00136
00137 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
00138 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
00139 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
00140 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
00141 }
00142 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0)
00143 {
00144 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00145 $x = $matches[1];
00146 $y = $matches[2];
00147 $r = $matches[3];
00148
00149 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
00150 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" " .
00151 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
00152 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" ";
00153 }
00154 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0)
00155 {
00156
00157 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"polygon ";
00158 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00159 for ($i = 0; $i < count($matches[0]); $i++)
00160 {
00161 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00162 }
00163 $convert_cmd .= "\" ";
00164 $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"polygon ";
00165 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00166 for ($i = 0; $i < count($matches[0]); $i++)
00167 {
00168 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00169 }
00170 $convert_cmd .= "\" ";
00171 }
00172 }
00173 $convert_cmd = $convert_prefix . $convert_cmd . escapeshellcmd(str_replace(" ", "\ ", $this->imagemap_filename)) ." " . escapeshellcmd($this->preview_filename);
00174 system($convert_cmd);
00175 }
00176
00177 function getPreviewFilename($imagePath, $baseFileName)
00178 {
00179 $filename = $baseFileName;
00180 if (count($this->areas))
00181 {
00182 $pfile = $this->preview_filename;
00183 if (is_file($pfile))
00184 {
00185 $ident = $this->getAreaIdent();
00186 $previewfile = $imagePath . $ident . $baseFileName;
00187 if (@md5_file($previewfile) != @md5_file($pfile))
00188 {
00189 if (strlen($ident) > 0)
00190 {
00191 @copy($pfile, $previewfile);
00192 }
00193 }
00194 @unlink($pfile);
00195 if (strlen($pfile) == 0)
00196 {
00197 ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00198 }
00199 else
00200 {
00201 $filename = basename($previewfile);
00202 }
00203 }
00204 else
00205 {
00206 ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
00207 }
00208 }
00209 return $filename;
00210 }
00211
00216 function getImagemap($title)
00217 {
00218 $map = "<map name=\"$title\"> ";
00219 foreach ($this->areas as $area)
00220 {
00221 $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
00222 $map .= "shape=\"" . $area["shape"] . "\" ";
00223 $map .= "coords=\"" . $area["coords"] . "\" ";
00224 if ($area["href"])
00225 {
00226 $map .= "href=\"" . $area["href"] . "\" ";
00227 if ($area["target"])
00228 {
00229 $map .= "target=\"" . $area["target"] . "\" ";
00230 }
00231 $map .= "/>\n";
00232 }
00233 else
00234 {
00235 $map .= "nohref />\n";
00236 }
00237 }
00238 $map .= "</map>";
00239 return $map;
00240 }
00241
00242 }
00243 ?>