コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
ファイル: compare.php プロジェクト: s-a-r-id/geograph-project
 $smarty->assign('pair_id', $pair['compare_pair_id']);
 $token = new Token();
 $token->setValue("p", $pair['compare_pair_id']);
 $smarty->assign('token', $token->getToken());
 require_once 'geograph/conversions.class.php';
 $conv = new Conversions();
 $image1 = new GridImage($pair['gridimage_id1']);
 if ($image1->moderation_status != 'rejected') {
     $rastermap1 = new RasterMap($image1->grid_square);
     if ($image1->view_direction > -1) {
         $smarty->assign('view_direction1', $image1->view_direction % 90 == 0 ? strtoupper(heading_string($image1->view_direction)) : ucwords(heading_string($image1->view_direction)));
     }
     list($lat, $long) = $conv->gridsquare_to_wgs84($image1->grid_square);
     $smarty->assign('lat1', $lat);
     $smarty->assign('long1', $long);
     list($latdm, $longdm) = $conv->wgs84_to_friendly($lat, $long);
     $smarty->assign('latdm1', $latdm);
     $smarty->assign('longdm1', $longdm);
     $smarty->assign_by_ref('image1', $image1);
     $smarty->assign_by_ref('rastermap1', $rastermap1);
 }
 $image2 = new GridImage($pair['gridimage_id2']);
 if ($image2->moderation_status != 'rejected') {
     $rastermap2 = new RasterMap($image2->grid_square);
     if ($image2->view_direction > -1) {
         $smarty->assign('view_direction2', $image2->view_direction % 90 == 0 ? strtoupper(heading_string($image2->view_direction)) : ucwords(heading_string($image2->view_direction)));
     }
     list($lat, $long) = $conv->gridsquare_to_wgs84($image2->grid_square);
     $smarty->assign('lat2', $lat);
     $smarty->assign('long2', $long);
     list($latdm, $longdm) = $conv->wgs84_to_friendly($lat, $long);
コード例 #3
0
 function assignToSmarty($smarty)
 {
     global $CONF;
     $taken = $this->getFormattedTakenDate();
     //get the grid references
     $this->getSubjectGridref(true);
     $this->getPhotographerGridref(true);
     //remove grid reference from title
     $this->bigtitle = trim(preg_replace("/^{$this->grid_reference}/", '', $this->title));
     $this->bigtitle = preg_replace('/(?<![\\.])\\.$/', '', $this->bigtitle);
     $rid = $this->grid_square->reference_index;
     $gridrefpref = $CONF['gridrefname'][$rid];
     $smarty->assign('page_title', $this->bigtitle . ":: {$gridrefpref}{$this->grid_reference}");
     $smarty->assign('image_taken', $taken);
     $smarty->assign('ismoderator', $ismoderator);
     $smarty->assign_by_ref('image', $this);
     //get a token to show a suroudding geograph map
     $mosaic = new GeographMapMosaic();
     $smarty->assign('map_token', $mosaic->getGridSquareToken($this->grid_square));
     //find a possible place within 25km
     $place = $this->grid_square->findNearestPlace(75000);
     $smarty->assign_by_ref('place', $place);
     if (empty($this->comment)) {
         $smarty->assign('meta_description', "{$this->grid_reference} :: {$this->bigtitle}, " . strip_tags(smarty_function_place(array('place' => $place))));
     } else {
         $smarty->assign('meta_description', $this->comment);
     }
     if (!empty($CONF['forums'])) {
         //let's find posts in the gridref discussion forum
         $this->grid_square->assignDiscussionToSmarty($smarty);
     }
     //count the number of photos in this square
     $smarty->assign('square_count', $this->grid_square->imagecount);
     //lets add an overview map too
     $overview = new GeographMapMosaic('largeoverview');
     $overview->setCentre($this->grid_square->x, $this->grid_square->y);
     //does call setAlignedOrigin
     $overview->assignToSmarty($smarty, 'overview');
     $smarty->assign('marker', $overview->getSquarePoint($this->grid_square));
     require_once 'geograph/conversions.class.php';
     $conv = new Conversions();
     list($lat, $long) = $conv->gridsquare_to_wgs84($this->grid_square);
     $smarty->assign('lat', $lat);
     $smarty->assign('long', $long);
     list($latdm, $longdm) = $conv->wgs84_to_friendly($lat, $long);
     $smarty->assign('latdm', $latdm);
     $smarty->assign('longdm', $longdm);
     //lets add an rastermap too
     $rastermap = new RasterMap($this->grid_square, false);
     $rastermap->addLatLong($lat, $long);
     if (!empty($this->viewpoint_northings)) {
         $rastermap->addViewpoint($this->viewpoint_refindex, $this->viewpoint_eastings, $this->viewpoint_northings, $this->viewpoint_grlen, $this->view_direction);
     } elseif (isset($this->view_direction) && strlen($this->view_direction) && $this->view_direction != -1) {
         $rastermap->addViewDirection($this->view_direction);
     }
     $smarty->assign_by_ref('rastermap', $rastermap);
     $smarty->assign('x', $this->grid_square->x);
     $smarty->assign('y', $this->grid_square->y);
     if ($this->view_direction > -1) {
         $smarty->assign('view_direction', $this->view_direction % 90 == 0 ? strtoupper(heading_string($this->view_direction)) : ucwords(heading_string($this->view_direction)));
     }
     $level = $this->grid_square->imagecount > 1 ? 6 : 5;
     $smarty->assign('sitemap', getSitemapFilepath($level, $this->grid_square));
 }