BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * ImageMap - A PHP image map creation class. * @author Nnamdi Onyeyiri * @version 1.0 * @package ImageMap */ include_once ("painter.php"); /* Defines image map area --------------------------------------------------- */ /** * Encapsulates an image map area. * @package ImageMap */ class ImageMapArea { /**#@+ * @access private */ var $Region; var $Url; var $Name; /**#@+*/ /** * Creates a new ImageMapArea object. * @param mixed $r One of the Painter geometric primitives. * @param string $n The name of the area. * @param string $u The URL for the area. */ function ImageMapArea ($r, $n = "", $u = "") { $this->Region = $r; $this->Url = $u; $this->Name = $n; } } /* Generates the image map -------------------------------------------------- */ /** * Generates an image map. * @package ImageMap */ class ImageMap { /**#@+ * @access private */ var $areas; var $name; var $tabs; var $buffer; /**#@+*/ /** * Creates a new ImageMap object. */ function ImageMap ($name) { $this->areas = array (); $this->name = $name; } /** * Adds a new area to the image map. * @param ImageMapArea $ima The area to include. */ function Add ($ima) { $this->areas[] = $ima; } /** * Creates the image map XHTML. * @param int $tabs The number of tabs to insert before XHTML. * @return string */ function Render ($tabs = 0) { $this->tabs = $tabs; $this->_Write (''); for ($i = 0; $i < count ($this->areas); $i++) { $a = $this->areas[$i]; $href = (strlen ($a->Url) > 0) ? 'href="'.$a->Url.'"' : "nohref"; $alt = 'alt="'.$a->Name.'"'; $shape = 'shape="'.$this->_GetShape ($a->Region).'"'; $coords = 'coords="'.$this->_GetCoords ($a->Region).'"'; $this->_Write ("", 1); } $this->_Write (""); return $this->buffer; } /**#@+ * @access private */ function _Write ($msg, $lvl = 0) { for ($i = 0; $i < $this->tabs + $lvl; $i++) { $this->buffer .= "\t"; } $this->buffer .= $msg."\n"; } function _GetShape ($r) { switch (get_class ($r)) { case "Rect": $shape = "rect"; break; case "Ellipse": $shape = ($r->Width == $r->Height) ? "circle" : "poly"; break; case "Arc": $shape = "poly"; break; case "Polygon": $shape = "poly"; break; } return $shape; } function _GetCoords ($r) { switch (get_class ($r)) { case "Rect": $c = $this->_RectCoords ($r); break; case "Ellipse": $c = $this->_EllipseCoords ($r); break; case "Arc": $c = $this->_ArcCoords ($r); break; case "Polygon": $c = $this->_PolyCoords ($r); break; } return $c; } function _RectCoords ($r) { $w = $r->Width; $h = $r->Height; return $r->X.",".$r->Y.",".($r->X + $w - 1).",".($r->Y + $h - 1); } function _EllipseCoords ($r) { if ($r->Width == $r->Height) { return $r->X.",".$r->Y.",".round ($r->Width / 2); } else { $p = new Polygon (); $p->FromEllipse ($r); return $this->_PolyCoords ($p); } } function _ArcCoords ($r) { $p = new Polygon (); $p->FromArc ($r); return $this->_PolyCoords ($p); } function _PolyCoords ($r) { $c = ""; for ($i = 0; $i < count ($r->Points); $i++) { $c .= $r->Points[$i]->X.",".$r->Points[$i]->Y.","; } return substr ($c, 0, strlen ($c) - 1); } /**#@+*/ } ?>