/**
  * Given index of a mosaic image, and a pixel position on that image handle a zoom
  * If the zoom level is 2, this needs to perform a redirect to the gridsquare page
  * otherwise, it reconfigures the instance for the zoomed in map
  * @access public
  */
 function zoomIn($i, $j, $x, $y)
 {
     //so where did we click?
     list($clickx, $clicky) = $this->getClickCoordinates($i, $j, $x, $y);
     $zoomindex = array_search($this->pixels_per_km, $this->scales);
     if ($zoomindex === FALSE) {
         $zoomindex = 0;
     }
     $zoomindex++;
     if ($zoomindex > count($this->scales) || $this->pixels_per_km > 40) {
         //we're going to zoom into a grid square
         $square = new GridSquare();
         if ($square->loadFromPosition($clickx, $clicky)) {
             $images = $square->getImages(false, '', 'order by moderation_status+0 desc,seq_no limit 2');
             //if the image count is 1, we'll go straight to the image
             if (count($images) == 1) {
                 $url = "http://" . $_SERVER['HTTP_HOST'] . '/photo/' . $images[0]->gridimage_id;
             } else {
                 //lets go to the grid reference
                 $url = "http://" . $_SERVER['HTTP_HOST'] . '/gridref/' . $square->grid_reference;
             }
         } else {
             require_once 'geograph/conversions.class.php';
             $conv = new Conversions();
             list($gr, $len) = $conv->internal_to_gridref($clickx, $clicky, 0);
             $url = "http://" . $_SERVER['HTTP_HOST'] . '/gridref/' . $gr;
         }
         header("Location:{$url}");
         exit;
     } else {
         $scale = $this->scales[$zoomindex];
     }
     //store the clicked position to make a better estimate at the required grid
     $this->old_centrex = $clickx;
     $this->old_centrey = $clicky;
     //size of new map in km
     $mapw = $this->image_w / $scale;
     $maph = $this->image_h / $scale;
     //here's the perfect origin
     $bestoriginx = $clickx - $mapw / 2;
     $bestoriginy = $clicky - $maph / 2;
     $this->setScale($scale);
     $this->setMosaicFactor(2);
     $this->setAlignedOrigin($bestoriginx, $bestoriginy);
 }
Esempio n. 2
0
 $overview = new GeographMapMosaic('overview');
 $overview->assignToSmarty($smarty, 'overview');
 $stats = array();
 foreach ($CONF['references_all'] as $ri => $rname) {
     $stats[$ri] = array();
 }
 foreach ($CONF['references'] as $ri => $rname) {
     $letterlength = $CONF['gridpreflen'][$ri];
     $newstats = $db->CacheGetRow(3 * 3600, "select \n\t\t\tcount(*) as squares_total,\n\t\t\tsum(imagecount) as images_total,\n\t\t\tsum(imagecount > 0) as squares_submitted,\n\t\t\tcount(distinct concat(substring(grid_reference,1," . ($letterlength + 1) . "),substring(grid_reference," . ($letterlength + 3) . ",1))) as tenk_total\n\t\tfrom gridsquare \n\t\twhere reference_index = {$ri} and percent_land > 0");
     $stats[$ri] = array_merge($stats[$ri], $newstats);
     $newstats = $db->CacheGetRow(3 * 3600, "select \n\t\t\tcount(*) as geographs_submitted,\n\t\t\tcount(distinct substring(grid_reference,1,{$letterlength})) as grid_submitted,\n\t\t\tcount(distinct concat(substring(grid_reference,1," . ($letterlength + 1) . "),substring(grid_reference," . ($letterlength + 3) . ",1))) as tenk_submitted,\n\t\t\tavg( x ) as x,\n\t\t\tavg( y ) as y\n\t\tfrom gridsquare \n\t\twhere reference_index = {$ri} and percent_land > 0 and has_geographs > 0");
     $stats[$ri] = array_merge($stats[$ri], $newstats);
     $stats[$ri] += array('images_thisweek' => $db->CacheGetOne(3 * 3600, "select count(*) from gridimage_search where reference_index = {$ri} and (unix_timestamp(now())-unix_timestamp(submitted))<604800"));
     $stats[$ri] += array("grid_total" => $db->CacheGetOne(24 * 3600, "select count(*) from gridprefix where reference_index = {$ri} and landcount > 0"));
     $censquare = new GridSquare();
     $ok = $censquare->loadFromPosition(intval($stats[$ri]['x']), intval($stats[$ri]['y']));
     if ($ok) {
         $stats[$ri] += array("centergr" => $censquare->grid_reference);
         //find a possible place within 35km
         $stats[$ri] += array("place" => $censquare->findNearestPlace(35000));
         $stats[$ri] += array("marker" => $overview->getSquarePoint($censquare));
     } else {
         $stats[$ri] += array("centergr" => 'unknown');
     }
 }
 foreach (array('images_total', 'images_thisweek', 'squares_total', 'squares_submitted', 'tenk_total', 'tenk_submitted', 'geographs_submitted', 'grid_submitted', 'grid_total') as $name) {
     $sum = 0;
     foreach ($CONF['references'] as $ri => $rname) {
         $sum += $stats[$ri][$name];
     }
     $stats[0] += array($name => $sum);
Esempio n. 3
0
    $_GET['nl'] = intval($_SESSION['nl']);
}
if (isset($_GET['ht'])) {
    $_SESSION['ht'] = intval($_GET['ht']);
} elseif (isset($_SESSION['ht'])) {
    $_GET['ht'] = intval($_SESSION['ht']);
}
//set by grid components?
if (isset($_GET['p'])) {
    $grid_given = true;
    //p=900y + (900-x);
    $p = intval($_GET['p']);
    $x = $p % 900;
    $y = ($p - $x) / 900;
    $x = 900 - $x;
    $grid_ok = $square->loadFromPosition($x, $y, true);
    $grid_given = true;
    $smarty->assign('gridrefraw', $square->grid_reference);
    $smarty->assign('gridref2', strlen($square->grid_reference) <= 2 + $CONF['gridpreflen'][$square->reference_index]);
} elseif (isset($_GET['setpos'])) {
    $grid_given = true;
    $grid_ok = $square->setGridPos($_GET['gridsquare'], $_GET['eastings'], $_GET['northings'], true);
    $smarty->assign('gridrefraw', $square->grid_reference);
    $smarty->assign('gridref2', strlen($square->grid_reference) <= 2 + $CONF['gridpreflen'][$square->reference_index]);
} elseif (isset($_GET['gridref']) && strlen($_GET['gridref'])) {
    $grid_given = true;
    $grid_ok = $square->setByFullGridRef($_GET['gridref'], false, true);
    //preserve inputs in smarty
    if ($grid_ok) {
        $smarty->assign('gridrefraw', stripslashes($_GET['gridref']));
        $smarty->assign('gridref2', strlen($square->grid_reference) <= 2 + $CONF['gridpreflen'][$square->reference_index]);
 /**
  * create a simple search object
  */
 function buildSimpleQuery($q = '', $distance = 100, $autoredirect = 'auto', $userlimit = 0)
 {
     global $USER, $CONF;
     $nearstring = $this->getNearString($distance);
     $has_location = preg_match('/\\bnear\\b/', $q);
     $searchclass = '';
     $limit1 = '';
     $location = '';
     $q = trim(strip_tags($q));
     if ($has_location) {
         $bits = preg_split('/\\s*near\\s+/', $q);
         $qlocation = @$bits[1];
     } else {
         $qlocation = $q;
     }
     if (preg_match("/\\b([A-Z]{1,2})([0-9]{1,2}[A-Z]?) *([0-9]?)([A-Z]{0,2})\\b/i", $qlocation, $pc) && !in_array($pc[1], array('SV', 'SX', 'SZ', 'TV', 'SU', 'TL', 'TM', 'SH', 'SJ', 'TG', 'SC', 'SD', 'NX', 'NY', 'NZ', 'OV', 'NS', 'NT', 'NU', 'NL', 'NM', 'NO', 'NF', 'NH', 'NJ', 'NK', 'NA', 'NB', 'NC', 'ND', 'HW', 'HY', 'HZ', 'HT', 'Q', 'D', 'C', 'J', 'H', 'F', 'O', 'T', 'R', 'X', 'V'))) {
         //these prefixs are not postcodes but are valid gridsquares
         $searchq = strtoupper($pc[1] . $pc[2] . ($pc[3] ? " " . $pc[3] : ''));
         $criteria = new SearchCriteria_Postcode();
         $criteria->setByPostcode($searchq);
         if ($criteria->y != 0) {
             $searchclass = 'Postcode';
             $searchdesc = ", {$nearstring} postcode " . $searchq;
             $searchx = $criteria->x;
             $searchy = $criteria->y;
             $location = $pc[0];
         } else {
             $this->errormsg = "Invalid Postcode or a newer Postcode not in our database, please try a different search method";
             if ($pc[3]) {
                 $this->errormsg .= ", or use just the outcode [ {$pc[1]}{$pc[2]} ]";
             }
         }
     } elseif (preg_match("/\\b([a-zA-Z]{1,3}) ?(\\d{1,5})[ \\.]?(\\d{1,5})\\b/", $qlocation, $gr)) {
         require_once 'geograph/gridsquare.class.php';
         $square = new GridSquare();
         $grid_ok = $square->setByFullGridRef($gr[1] . $gr[2] . $gr[3], false, true);
         if ($grid_ok || $square->x && $square->y) {
             if ($square->imagecount && $autoredirect == 'simple' && strlen($q) - strlen($gr[0]) < 2) {
                 header("Location:http://{$_SERVER['HTTP_HOST']}/gridref/{$q}");
                 print "<a href=\"http://{$_SERVER['HTTP_HOST']}/gridref/{$q}\">View Pictures</a>";
                 exit;
             }
             $searchclass = 'GridRef';
             $searchdesc = ", {$nearstring} grid reference " . $square->grid_reference;
             $searchx = $square->x;
             $searchy = $square->y;
             $criteria->reference_index = $square->reference_index;
             $location = $gr[0];
         } else {
             $this->errormsg = $square->errormsg;
         }
     } elseif (preg_match("/\\b(-?\\d+\\.?\\d*)[, ]+(-?\\d+\\.?\\d*)\\b/", $q, $ll)) {
         require_once 'geograph/conversions.class.php';
         require_once 'geograph/gridsquare.class.php';
         $square = new GridSquare();
         $conv = new Conversions();
         list($x, $y, $reference_index) = $conv->wgs84_to_internal($ll[1], $ll[2]);
         $grid_ok = $square->loadFromPosition($x, $y, true);
         if ($grid_ok) {
             $searchclass = 'GridRef';
             list($latdm, $longdm) = $conv->wgs84_to_friendly($ll[1], $ll[2]);
             $searchdesc = ", {$nearstring} {$latdm}, {$longdm}";
             $searchx = $x;
             $searchy = $y;
             $criteria->reference_index = $square->reference_index;
             $location = $ll[0];
         } else {
             $this->errormsg = "unable to parse lat/long";
         }
     }
     //todo else { parse placenames (and EWSI etc) off the end!)}
     if ($location) {
         $q = str_replace($location, '', $q);
     }
     $q = preg_replace('/\\s*near\\s*$/', '', $q);
     $q = trim(preg_replace('/\\s+/', ' ', $q));
     list($q, $placename) = preg_split('/\\s*near\\s+/', $q);
     $criteria = new SearchCriteria_Placename();
     if ($placename != '(anywhere)' && strpos($q, ':') === FALSE) {
         if (!empty($placename)) {
             $criteria->setByPlacename($placename);
         } elseif (!$location) {
             $criteria->setByPlacename($q);
         }
     }
     if ($criteria->is_multiple) {
         //we've found multiple possible placenames
         $searchdesc = ", {$nearstring} '" . ($placename ? $placename : $q) . "' ";
         $this->searchdesc = $searchdesc;
         $this->criteria = $criteria;
     } else {
         if (!empty($criteria->placename)) {
             //if one placename then search on that
             $searchclass = 'Placename';
             $searchq = $criteria->placename;
             $searchdesc = ", {$nearstring} " . $criteria->placename;
             $searchx = $criteria->x;
             $searchy = $criteria->y;
             $location = $criteria->searchq;
         }
     }
     if ($q && (!$criteria->is_multiple && empty($criteria->placename) || $placename)) {
         if (preg_match('/[~\\+\\^\\$:@ -]+/', $q)) {
             $searchtext = $q;
             $searchdesc = ", matching '" . $q . "' " . $searchdesc;
         } elseif (preg_match('/^".*"$/', $q)) {
             $searchtext = $q;
             $searchdesc = ", matching \"" . $q . "\" " . $searchdesc;
         } elseif (isset($GLOBALS['smarty'])) {
             //check if this is a user
             $criteria2 = new SearchCriteria_All();
             $criteria2->setByUsername($q);
             if (!empty($criteria2->realname)) {
                 if (strcasecmp($q, $criteria2->realname) == 0) {
                     $searchq = $criteria2->realname;
                     $limit1 = $criteria2->user_id;
                     $searchdesc .= ", by '{$criteria2->realname}' ";
                 } else {
                     $this->searchdesc = ", by '{$criteria2->realname}' ";
                     $this->criteria = $criteria2;
                     $this->criteria->searchq = $q;
                     $this->criteria->is_multiple = true;
                     $this->criteria->ismore = true;
                     #so doesnt display placename prompt
                     unset($searchclass);
                     if (!empty($criteria->placename)) {
                         $this->criteria->matches = $criteria->_matches;
                     }
                 }
             } else {
                 //asuume a text search
                 $searchtext = $q;
                 $searchdesc = ", containing '{$q}' " . $searchdesc;
             }
         } else {
             //asuume a text search - without smarty must be api/feed
             $searchtext = $q;
             $searchdesc = ", containing '{$q}' " . $searchdesc;
         }
     } elseif ($placename && !$searchdesc) {
         $q = $searchtext = $placename;
         $searchdesc = ", matching '" . $searchtext . "' " . $searchdesc;
     }
     if (($searchtext || $limit1) && !$searchclass) {
         $searchclass = 'All';
     }
     if ($searchclass != 'All' && $location) {
         $q = $location;
     }
     if ($criteria->reference_index == 2 && $CONF['default_search_distance_2'] && $distance == $CONF['default_search_distance']) {
         $searchdesc = str_replace(" " . $CONF['default_search_distance'] . "km ", " " . $CONF['default_search_distance_2'] . "km ", $searchdesc);
         $distance = $CONF['default_search_distance_2'];
     }
     if ($userlimit) {
         $limit1 = $userlimit;
         $profile = new GeographUser($userlimit);
         $searchdesc .= ", by " . $profile->realname;
     }
     if (!empty($searchclass) && empty($criteria->is_multiple)) {
         $db = $this->_GetDB();
         $sql = "INSERT INTO queries SET searchclass = '{$searchclass}'," . "searchtext = " . $db->Quote($searchtext) . "," . "searchdesc = " . $db->Quote($searchdesc) . "," . "searchuse = " . $db->Quote($this->searchuse) . "," . "searchq = " . $db->Quote($q);
         if (!empty($searchx) && !empty($searchy)) {
             $sql .= ",x = {$searchx},y = {$searchy},limit8 = {$distance}";
         }
         if ($limit1) {
             $sql .= ",limit1 = {$limit1}";
         }
         if (isset($USER) && $USER->registered) {
             $sql .= ",user_id = {$USER->user_id}";
             if (!empty($USER->search_results)) {
                 $sql .= ",resultsperpage = " . $db->Quote($USER->search_results);
             }
         }
         $db->Execute($sql);
         $i = $db->Insert_ID();
         if ($autoredirect != false) {
             $extra = '';
             if (isset($_GET['page'])) {
                 $extra = "&page=" . intval($_GET['page']);
             }
             if (!empty($_GET['BBOX'])) {
                 $extra .= "&BBOX=" . $_GET['BBOX'];
             }
             header("Location:http://{$_SERVER['HTTP_HOST']}/{$this->page}?i={$i}{$extra}");
             $extra = str_replace('&', '&amp;', $extra);
             print "<a href=\"http://{$_SERVER['HTTP_HOST']}/{$this->page}?i={$i}{$extra}\">Your Search Results</a>";
             exit;
         } else {
             return $i;
         }
     }
     $this->searchdesc = $searchdesc;
 }