Advertisement
althindor

PHP ImageMap Class File

Dec 10th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. <?PHP
  2.  
  3. // Gaia Sig Mapper
  4. // Regions are Defined By Rect Normally
  5. // Jakobo @ Gaia Online
  6.  
  7. // Class Definition
  8. // This is responsible for the definition of coordinates
  9.  
  10.  class imageMap {
  11.      var $locale;
  12.      var $defaultURL;
  13.      var $size;
  14.  
  15.      function imageMap() {
  16.          // makes locale ready for data
  17.          $this->locale = array();
  18.          $this->size = 0;
  19.      }
  20.  
  21.      function setDefaultURL($inUrl) {
  22.         $this->defaultURL = $inUrl;
  23.      }
  24.  
  25.      function addToMap($Region) {
  26.          $this->locale[$this->size] = $Region;
  27.          $this->size++;
  28.      }
  29.  
  30.      function testMap($inX, $inY) {
  31.          foreach($this->locale as $Region) {
  32.             $Region->goIfInside($inX, $inY);
  33.          }
  34.          // we didn't go anywhere, load the default
  35.          header("Location: " . $this->defaultURL);
  36.      }
  37.  }
  38.  
  39.  class Region {
  40.      var $type; // type of region
  41.      var $url; // url of region
  42.  
  43.      function Region() {
  44.      // empty constructor
  45.      }
  46. }
  47.  
  48. class Rect extends Region {
  49.      var $x1,
  50.      $y1,
  51.      $x2,
  52.      $y2;
  53.  
  54.      function Rect($inX1, $inY1, $inX2, $inY2, $inUrl) {
  55.          $this->x1 = $inX1;
  56.          $this->y1 = $inY1;
  57.          $this->x2 = $inX2;
  58.          $this->y2 = $inY2;
  59.          $this->url = $inUrl;
  60.          $this->type = "rect";
  61.      }
  62.  
  63.      function isInside($clickedX = -1, $clickedY = -1) {
  64.          // if X and Y are not set, -1 is used
  65.          // placing it outside of the image map
  66.          if(($clickedX >= $this->x1 && $clickedX <= $this->x2) && ($clickedY >= $this->y1 && $clickedY <= $this->y2) ) {
  67.             return true;
  68.          }
  69.          else {
  70.             return false;
  71.          }
  72.      }
  73.  
  74.      function goIfInside($clickedX = -1, $clickedY = -1) {
  75.          // goes to object's URL if inside
  76.          if($this->isInside($clickedX, $clickedY)) {
  77.             header("Location: " . $this->url);
  78.             exit;
  79.         }
  80.     }
  81.  }
  82.  
  83.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement