$rastermap->addViewDirection($_POST['view_direction']); } $smarty->assign_by_ref('rastermap', $rastermap); $smarty->assign_by_ref('square', $square); $smarty->assign('reference_index', $square->reference_index); require_once 'geograph/conversions.class.php'; $conv = new Conversions(); list($lat, $long) = $conv->gridsquare_to_wgs84($square); $smarty->assign('lat', $lat); $smarty->assign('long', $long); $rastermap->addLatLong($lat, $long); $dirs = array(-1 => ''); $jump = 360 / 16; $jump2 = 360 / 32; for ($q = 0; $q < 360; $q += $jump) { $s = $q % 90 == 0 ? strtoupper(heading_string($q)) : ucwords(heading_string($q)); $dirs[$q] = sprintf('%s : %03d deg (%03d > %03d)', str_pad($s, 16, '�'), $q, $q == 0 ? $q + 360 - $jump2 : $q - $jump2, $q + $jump2); } $dirs['00'] = $dirs[0]; $smarty->assign_by_ref('dirs', $dirs); } elseif ($step == 3) { list($usec, $sec) = explode(' ', microtime()); $endtime = (double) $usec + (double) $sec; $timetaken = $endtime - $STARTTIME; if ($timetaken > 15) { //mysql might of closed the connection in the meantime unset($square->db); //so get a new one... $square->_getDB(); } //find a possible place within 25km
} $i++; } } elseif ($_GET['by'] == 'direction') { $breakdown_title = $MESSAGES['browse']['bdtitle_direction']; $title = $MESSAGES['browse']['title_direction']; $titleunknown = $MESSAGES['browse']['title_unknown_direction']; $formatdegree = $MESSAGES['browse']['format_direction']; $all = $db->cacheGetAll($cacheseconds, "SELECT view_direction,count(*),\n\t\t\t\tgridimage_id,title,user_id,gi.realname as credit_realname,if(gi.realname!='',gi.realname,user.realname) as realname\n\t\t\t\tFROM gridimage gi inner join user using(user_id)\n\t\t\t\tWHERE gridsquare_id = '{$square->gridsquare_id}'\n\t\t\t\tAND {$user_crit} {$custom_where}\n\t\t\t\tGROUP BY view_direction"); $br = empty($_GET['ht']) ? '<br/>' : ''; $start = rand(0, max(0, count($all) - 20)); $end = $start + 20; foreach ($all as $row) { if ($row[0] != -1) { $titledegree = sprintf($formatdegree, $row[0]); $view_direction = $row[0] % 90 == 0 ? strtoupper(heading_string($row[0])) : ucwords(heading_string($row[0])); $breakdown[$i] = array('name' => "{$title} <b>{$view_direction}</b>{$br} ({$titledegree})", 'count' => $row[1]); } else { $breakdown[$i] = array('name' => $titleunknown, 'count' => $row[1]); } if (empty($_GET['ht']) && $i >= $start && $i < $end) { $breakdown[$i]['image'] = new GridImage(); $row['grid_reference'] = $square->grid_reference; $breakdown[$i]['image']->fastInit($row); } if ($row[1] == 1) { $breakdown[$i]['link'] = "/photo/{$row[2]}"; } else { $breakdown[$i]['link'] = "/gridref/{$square->grid_reference}?direction={$row[0]}" . $extra; } $i++;
$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); $smarty->assign('latdm2', $latdm); $smarty->assign('longdm2', $longdm); $smarty->assign_by_ref('image2', $image2); $smarty->assign_by_ref('rastermap2', $rastermap2); } $updates = array(); $updates['user_id'] = $USER->user_id; $updates['compare_pair_id'] = $pair['compare_pair_id']; $updates['ua'] = $_SERVER['HTTP_USER_AGENT']; $db->Execute('REPLACE INTO compare_done SET `ipaddr` = INET_ATON(\'' . getRemoteIP() . '\'),`' . implode('` = ?,`', array_keys($updates)) . '` = ?', array_values($updates));
function Execute($pg) { $db = $this->_getDB(); $this->criteria->getSQLParts(); extract($this->criteria->sql, EXTR_PREFIX_ALL ^ EXTR_REFS, 'sql'); $this->currentPage = $pg; $pgsize = $this->criteria->resultsperpage; if (!$pgsize) { $pgsize = 15; } if ($pg == '' or $pg < 1) { $pg = 1; } $page = ($pg - 1) * $pgsize; if (empty($sql_where)) { $sql_where = "1"; } else { $this->islimited = true; } if (!$sql_order) { $sql_order = 'gs.grid_reference'; } // construct the count query sql $sql = <<<END \t SELECT count(*) \t\tFROM geobb_topics AS gi INNER JOIN gridsquare AS gs ON(forum_id = {$CONF['forum_gridsquare']} AND topic_title = grid_reference) \t\t\t {$sql_from} \t\tWHERE \t\t\t{$sql_where} END; $this->resultCount = $db->GetOne($sql); $this->numberOfPages = ceil($this->resultCount / $pgsize); if ($sql_order == 'post_time desc') { $sql_from .= " LEFT JOIN geobb_posts ON (`topic_last_post_id` = geobb_posts.post_id)"; } // construct the query sql $sql = <<<END \t SELECT distinct gi.*,x,y,nickname,realname,grid_reference,user_id,topic_time \t\t\t{$sql_fields} \t\tFROM geobb_topics AS gi INNER JOIN gridsquare AS gs ON(gi.forum_id = {$CONF['forum_gridsquare']} AND topic_title = grid_reference) \t\tINNER JOIN user ON(gi.topic_poster=user.user_id) \t\t\t {$sql_from} \t\tWHERE \t\t\t{$sql_where} \t\tORDER BY {$sql_order} \t\tLIMIT {$page},{$pgsize} END; if (!empty($_GET['debug'])) { print "<BR><BR>{$sql}"; } //lets find some photos $this->results = array(); $i = 0; $recordSet =& $db->Execute($sql); while (!$recordSet->EOF) { $this->results[$i] = $recordSet->fields; if ($d = $recordSet->fields['dist_sqd']) { $angle = rad2deg(atan2($recordSet->fields['x'] - $this->criteria->x, $recordSet->fields['y'] - $this->criteria->y)); $this->results[$i]['dist_string'] = sprintf("Dist:%.1fkm %s", sqrt($d), heading_string($angle)); } //temporary nickname fix for beta accounts if (strlen($this->results[$i]['nickname']) == 0) { $this->results[$i]['nickname'] = str_replace(" ", "", $this->results[$i]['realname']); } $recordSet->MoveNext(); $i++; } $recordSet->Close(); if (!empty($_GET['debug'])) { print_r($this->results); } }
/** * run a standard search and populate $this->results with GridImages * @access public */ function Execute($pg) { if ($this->noCache || $this->criteria->searchclass == 'Special' && preg_match('/(gs|gi|user)\\.(grid_reference|)/', $this->criteria->searchq, $m) && !$m[2]) { //a Special Search needs full access to GridImage/GridSquare/User $recordSet =& $this->ExecuteReturnRecordset($pg); } else { $recordSet =& $this->ExecuteCachedReturnRecordset($pg); } //we dont actully want to process anything if ($this->countOnly) { return 0; } if ($recordSet) { $dist_format = $this->criteria->searchclass == 'Postcode' ? "Dist:%dkm %s" : "Dist:%.1fkm %s"; $this->results = array(); $i = 0; $showtaken = $this->criteria->limit7 || preg_match('/^imagetaken/', $this->criteria->orderby); while (!$recordSet->EOF) { $this->results[$i] = new GridImage(); $this->results[$i]->fastInit($recordSet->fields); $this->results[$i]->dist_string = ''; if (!empty($recordSet->fields['dist_sqd'])) { $angle = rad2deg(atan2($recordSet->fields['x'] - $this->criteria->x, $recordSet->fields['y'] - $this->criteria->y)); if ($recordSet->fields['dist_sqd'] == -1) { $d = $this->sphinx_matches[$this->results[$i]->gridimage_id]['attrs']['@geodist'] / 1000; } else { $d = sqrt($recordSet->fields['dist_sqd']); } if ($d >= 0.1) { $this->results[$i]->dist_string = sprintf($dist_format, $d, heading_string($angle)); } } if (empty($this->results[$i]->title)) { $this->results[$i]->title = "Untitled"; } //if we searching on imageclass then theres no point displaying it... if ($this->criteria->limit3) { unset($this->results[$i]->imageclass); } //if we searching on taken date then display it... if ($showtaken) { $this->results[$i]->imagetakenString = getFormattedDate($this->results[$i]->imagetaken); } $recordSet->MoveNext(); $i++; } $recordSet->Close(); $this->numberofimages = $i; if (!$i && $this->resultCount) { $pgsize = $this->criteria->resultsperpage; if (!$pgsize) { $pgsize = 15; } $lastPage = ($this->resultCount - 1) * $pgsize; if ($this->currentPage < $lastPage) { $db = $this->_getDB(); if (empty($_GET['BBOX']) && $this->display != 'reveal') { $db->Execute("replace into queries_count set id = {$this->query_id},`count` = 0"); } $this->resultCount = 0; } } } else { return 0; } return $this->querytime; }
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)); }