squashed redundant search code, search fixes;

update #259, update #253

- integrated redundant parts of lib/search.*.inc.php into search.php
- added some translations for LOC and KML
- added "locked" state to LOC output
- appended state of inactive caches to KML cache names
- display selected distance search unit in HTML and XML output
- improved GPX Google search link for protection areas
- one more searching improvement (forgotten what it was ...)
This commit is contained in:
following
2013-07-11 21:42:39 +02:00
parent 29f333e077
commit 98b466030c
12 changed files with 523 additions and 1363 deletions
+2
View File
@@ -2511,6 +2511,7 @@ INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2090', 'archive
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2091', 'Test for and fix inconsistencies in database tables', '2013-04-25 23:00:00');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2096', '%2 has activated %1', '2013-04-25 23:00:00');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2097', '%1 has activated the geocache', '2013-04-25 23:00:00');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2098', 'converted from HTML', '2013-04-25 23:00:00');
-- Table sys_trans_ref
SET NAMES 'utf8';
@@ -6473,6 +6474,7 @@ INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUE
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2091', 'DE', 'Sucht und behebt Inkonsistenzen in Datenbanktabellen', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2096', 'DE', '%2 hat %1 aktiviert', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2097', 'DE', '%1 hat den Geocache aktiviert', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2098', 'DE', 'aus HTML konvertiert', '2013-04-25 23:00:00');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'EN', 'Reorder IDs \r', '2010-09-02 00:15:30');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'EN', 'The database could not be reconnected.', '2010-08-28 11:48:07');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('3', 'EN', 'Testing please do not login', '2010-08-28 11:48:07');
+6
View File
@@ -97,6 +97,12 @@
$unknown_searchtype = t('unknown search type');
$showonmap = t('Show on map');
$converted_from_html = t('converted from HTML');
$state_temporarily_na = t('Temporary not available');
$state_archived = t('Archived');
$state_locked = t('Locked');
$cache_note_text = t('Personal cache note');
function dateDiff($interval, $dateTimeBegin, $dateTimeEnd)
{
+1 -1
View File
@@ -40,7 +40,7 @@
$desc = "<p>" . str_replace('%1',$opt['cms']['npa'], t('This geocache is probably placed within the following nature protection areas (<a href="%1">Info</a>):')) . "</p>\n" .
"<ul>\n";
foreach ($npas as $npa)
$desc .= "<li>" . $npa['npaTypeName'] . ": <a href='http://www.google.de/search?q=".urlencode($npa['npaName'])."' target='_blank'>" . $npa['npaName'] . "</a></li>\n";
$desc .= "<li>" . $npa['npaTypeName'] . ": <a href='http://www.google.de/search?q=".urlencode($npa['npaTypeName'].' '.$npa['npaName'])."' target='_blank'>" . $npa['npaName'] . "</a></li>\n";
$desc .= "</ul>\n";
}
else
+21 -182
View File
@@ -5,14 +5,21 @@
Unicode Reminder メモ
GPX search output (GC compatible)
used by Ocprop
****************************************************************************/
require_once('lib/npas.inc.php');
global $content, $bUseZip, $sqldebug, $locale;
$search_output_file_download = true;
$content_type_plain = 'application/gpx';
function search_output()
{
global $absolute_server_URI, $locale, $usr, $login;
global $cache_note_text;
$gpxHead =
'<?xml version="1.0" encoding="utf-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0" creator="Opencaching.de - http://www.opencaching.de" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0/1 http://www.groundspeak.com/cache/1/0/1/cache.xsd" xmlns="http://www.topografix.com/GPX/1/0">
@@ -154,157 +161,9 @@
$gpxSymNormal = 'Geocache';
$gpxSymFound = 'Geocache Found';
//prepare the output
$caches_per_page = 20;
$sql = 'SELECT ';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= '0 distance, ';
}
else
{
//get the users home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ((($record_coords['latitude'] == NULL) || ($record_coords['longitude'] == NULL)) || (($record_coords['latitude'] == 0) || ($record_coords['longitude'] == 0)))
{
$sql .= '0 distance, ';
}
else
{
//TODO: load from the users-profile
$distance_unit = 'km';
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
$sAddJoin = '';
$sAddGroupBy = '';
$sAddField = '';
$sGroupBy = '';
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sAddField = ', MAX(`cache_logs`.`date`) AS `lastLog`';
$sAddJoin = ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`';
if ($options['sort'] == 'bymylastlog')
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false? 0 : $usr['userid']);
$sGroupBy = ' GROUP BY `caches`.`cache_id`';
}
$sql .= '`caches`.`cache_id` `cache_id`, `caches`.`status` `status`, `caches`.`type` `type`, `caches`.`size` `size`, `caches`.`longitude` `longitude`, `caches`.`latitude` `latitude`, `caches`.`user_id` `user_id`,
IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`,
`cache_location`.`adm2` `state`' .
$sAddField
. ' FROM `caches`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`
LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_id`' .
$sAddJoin
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' .
$sGroupBy;
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
$sql .= '`caches`.`name` ASC';
}
//startat?
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0; // Ocprop
if (!is_numeric($startat)) $startat = 0;
if (isset($_REQUEST['count'])) // Ocprop
$count = $_REQUEST['count'];
else
$count = $caches_per_page;
if ($count == 'max') $count = 500;
if (!is_numeric($count)) $count = 0;
if ($count < 1) $count = 1;
if ($count > 500) $count = 500;
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count;
// create temporary table
sql_slave('CREATE TEMPORARY TABLE `gpxcontent` ' . $sql . $sqlLimit);
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `gpxcontent`');
$rCount = sql_fetch_array($rsCount);
mysql_free_result($rsCount);
if ($rCount['count'] == 1)
{
$rsName = sql_slave('SELECT `caches`.`wp_oc` `wp_oc` FROM `gpxcontent`, `caches` WHERE `gpxcontent`.`cache_id`=`caches`.`cache_id` LIMIT 1');
$rName = sql_fetch_array($rsName);
mysql_free_result($rsName);
$sFilebasename = $rName['wp_oc'];
}
else
$sFilebasename = 'ocde' . $options['queryid'];
$bUseZip = ($rCount['count'] > 20);
$bUseZip = $bUseZip || (isset($_REQUEST['zip']) && ($_REQUEST['zip'] == '1')); // Ocprop
if ($bUseZip == true)
{
$content = '';
require_once($rootpath . 'lib/phpzip/ss_zip.class.php');
$phpzip = new ss_zip('',6);
}
// ok, let's start
if ($sqldebug == false)
{
if ($bUseZip == true)
{
header("content-type: application/zip");
header('Content-Disposition: attachment; filename=' . $sFilebasename . '.zip');
}
else
{
header("Content-type: application/gpx");
header("Content-Disposition: attachment; filename=" . $sFilebasename . ".gpx");
}
}
$childwphandler = new ChildWp_Handler();
// ok, output ...
$children='';
$rs = sql('SELECT `gpxcontent`.`cache_id` `cacheid` FROM `gpxcontent`');
$rs = sql('SELECT `searchtmp`.`cache_id` `cacheid` FROM `searchtmp`');
while ($r = sql_fetch_array($rs))
if (count($childwphandler->getChildWps($r['cacheid'])))
$children=" (HasChildren)";
@@ -319,21 +178,21 @@
else
$user_id = $usr['userid'];
$rs = sql_slave("SELECT SQL_BUFFER_RESULT `gpxcontent`.`cache_id` `cacheid`, `gpxcontent`.`longitude` `longitude`, `gpxcontent`.`latitude` `latitude`,
`gpxcontent`.`state` `state`, `caches`.`wp_oc` `waypoint`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`,
$rs = sql_slave("SELECT SQL_BUFFER_RESULT `searchtmp`.`cache_id` `cacheid`, `searchtmp`.`longitude` `longitude`, `searchtmp`.`latitude` `latitude`,
`cache_location`.`adm2` `state`, `caches`.`wp_oc` `waypoint`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`,
`caches`.`country` `country`, `countries`.`name` AS `country_name`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `caches`.`desc_languages` `desc_languages`,
`caches`.`size` `size`, `caches`.`type` `type`, `caches`.`status` `status`, `user`.`username` `username`, `caches`.`user_id` `userid`, `user`.`data_license`,
`cache_desc`.`desc` `desc`, `cache_desc`.`short_desc` `short_desc`, `cache_desc`.`hint` `hint`,
IFNULL(`stat_cache_logs`.`found`, 0) AS `found`
FROM `gpxcontent`
INNER JOIN `caches` ON `gpxcontent`.`cache_id`=`caches`.`cache_id`
FROM `searchtmp`
INNER JOIN `caches` ON `searchtmp`.`cache_id`=`caches`.`cache_id`
INNER JOIN `countries` ON `caches`.`country`=`countries`.`short`
INNER JOIN `user` ON `gpxcontent`.`user_id`=`user`.`user_id`
INNER JOIN `cache_desc` ON `caches`.`cache_id`=`cache_desc`.`cache_id`
AND `caches`.`default_desclang`=`cache_desc`.`language`
LEFT JOIN `stat_cache_logs` ON `gpxcontent`.`cache_id`=`stat_cache_logs`.`cache_id` AND `stat_cache_logs`.`user_id`='&1'", $user_id);
INNER JOIN `user` ON `searchtmp`.`user_id`=`user`.`user_id`
INNER JOIN `cache_desc` ON `caches`.`cache_id`=`cache_desc`.`cache_id`AND `caches`.`default_desclang`=`cache_desc`.`language`
LEFT JOIN `cache_location` ON `searchtmp`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `stat_cache_logs` ON `searchtmp`.`cache_id`=`stat_cache_logs`.`cache_id` AND `stat_cache_logs`.`user_id`='&1'", $user_id);
while($r = sql_fetch_array($rs))
while ($r = sql_fetch_array($rs))
{
$thisline = $gpxLine;
@@ -558,7 +417,7 @@
$thiswp = mb_ereg_replace('{name}', $r['waypoint'].'NOTE', $thiswp);
$thiswp = mb_ereg_replace('{cachename}', xmlentities($r['name']), $thiswp);
$thiswp = mb_ereg_replace('{comment}', xmlentities($cacheNote['note']), $thiswp);
$thiswp = mb_ereg_replace('{desc}', $translate->t('Personal cache note','','',0), $thiswp);
$thiswp = mb_ereg_replace('{desc}', $cache_note_text, $thiswp);
$thiswp = mb_ereg_replace('{type}', "Reference Point", $thiswp);
$thiswp = mb_ereg_replace('{parent}', $r['waypoint'], $thiswp);
$thiswp = mb_ereg_replace('{cacheid}', $r['cacheid'], $thiswp);
@@ -570,19 +429,10 @@
append_output($thisline);
}
mysql_free_result($rs);
append_output($gpxFoot);
}
if ($sqldebug == true) sqldbg_end();
// send using phpzip
if ($bUseZip == true)
{
$phpzip->add_data($sFilebasename . '.gpx', $content);
echo $phpzip->save($sFilebasename . '.zip', 'b');
}
exit;
function decodeEntities($str)
{
@@ -625,17 +475,6 @@
return mb_ereg_replace('[\\x00-\\x09|\\x0B-\\x0C|\\x0E-\\x1F]', '', $str);
}
function append_output($str)
{
global $content, $bUseZip, $sqldebug;
if ($sqldebug == true) return;
if ($bUseZip == true)
$content .= $str;
else
echo $str;
}
function getCacheNote($userid, $cacheid)
{
$cacheNoteHandler = new CacheNote_Handler();
+30 -124
View File
@@ -1,147 +1,51 @@
<?php
/***************************************************************************
./lib/search.html.inc.php
-------------------
begin : July 25 2004
For license information see doc/license.txt
****************************************************************************/
/****************************************************************************
Unicode Reminder メモ
(X)HTML search output
TODO: (1) save the options in the database
(2) sort the results and the make the final query
Used by Ocprop
****************************************************************************/
global $sqldebug;
require_once($stylepath . '/lib/icons.inc.php');
require_once('lib/cache_icon.inc.php');
//prepare the output
$tplname = 'search.result.caches';
$caches_per_page = 20;
$search_output_file_download = false;
//build lines
$sAddFields .= ', `caches`.`name`, `caches`.`difficulty`, `caches`.`terrain`,
`caches`.`desc_languages`, `caches`.`date_created`,
`user`.`username`,
`cache_type`.`icon_large`,
`cache_type`.`name` `cacheTypeName`,
IFNULL(`stat_caches`.`found`, 0) `founds`,
IFNULL(`stat_caches`.`toprating`, 0) `topratings`,
IF(ISNULL(`tbloconly`.`cache_id`), 0, 1) AS `oconly`';
$sAddJoin .= 'INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_id`
INNER JOIN `cache_type` ON `cache_type`.`id`=`caches`.`type`
LEFT JOIN `caches_attributes` AS `tbloconly`
ON `caches`.`cache_id`=`tbloconly`.`cache_id` AND `tbloconly`.`attrib_id`=6';
function search_output()
{
global $sqldebug, $stylepath, $tplname, $logdateformat, $usr, $bgcolor1, $bgcolor2;
global $string_by, $caches_olddays, $caches_newstring, $caches_oconlystring, $showonmap;
global $options, $lat_rad, $lon_rad, $distance_unit, $startat, $caches_per_page, $sql;
$tplname = 'search.result.caches';
$cache_line = read_file($stylepath . '/search.result.caches.row.tpl.php');
$cache_line = mb_ereg_replace('{string_by}', $string_by, $cache_line);
$caches_output = '';
/*
$lat_rad
$lon_rad
$distance_unit
*/
$distance_unit = 'km';
$sql = 'SELECT SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS ';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= 'NULL distance, ';
}
else
{
//get the users home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ((($record_coords['latitude'] == NULL) && ($record_coords['longitude'] == NULL)) || (($record_coords['latitude'] == 0) && ($record_coords['longitude'] == 0)))
{
$sql .= 'NULL distance, ';
}
else
{
//TODO: load from the users-profile
$distance_unit = 'km';
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
$sAddJoin = '';
$sAddGroupBy = '';
$sAddField = '';
$sGroupBy = '';
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sAddField = ', MAX(`cache_logs`.`date`) AS `lastLog`';
$sAddJoin = ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`';
if ($options['sort'] == 'bymylastlog')
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false? 0 : $usr['userid']);
$sGroupBy = ' GROUP BY `caches`.`cache_id`';
}
$sql .= ' `caches`.`name` `name`, `caches`.`status` `status`, `caches`.`longitude` `longitude`, `caches`.`latitude` `latitude`,
`caches`.`difficulty` `difficulty`, `caches`.`terrain` `terrain`, `caches`.`desc_languages` `desc_languages`,
`caches`.`date_created` `date_created`, `caches`.`type` `type`, `caches`.`cache_id` `cache_id`,
`user`.`username` `username`, `user`.`user_id` `user_id`,
`cache_type`.`icon_large` `icon_large`,
`cache_type`.`name` `cacheTypeName`,
IFNULL(`stat_caches`.`found`, 0) `founds`,
IFNULL(`stat_caches`.`toprating`, 0) `topratings`,
IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`,
IF(ISNULL(`tbloconly`.`cache_id`), 0, 1) AS `oconly`' .
$sAddField
. ' FROM `caches`
INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_id`
INNER JOIN `cache_type` ON `cache_type`.`id`=`caches`.`type`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`
LEFT JOIN `caches_attributes` AS `tbloconly` ON `caches`.`cache_id`=`tbloconly`.`cache_id` AND
`tbloconly`.`attrib_id`=6' .
$sAddJoin
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' .
$sGroupBy;
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
$sql .= '`caches`.`name` ASC';
}
//startat?
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0;
if (!is_numeric($startat)) $startat = 0;
if (!is_numeric($caches_per_page)) $caches_per_page = 20;
// output range
$startat = floor($startat / $caches_per_page) * $caches_per_page;
$sql .= ' LIMIT ' . $startat . ', ' . $caches_per_page;
// run SQL query
$nRowIndex = 0;
$rs_caches = sql_slave($sql, $sqldebug);
$rs_caches = sql_slave("SELECT SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS " . $sql, $sqldebug);
$resultcount = sql_value_slave('SELECT FOUND_ROWS()', 0);
tpl_set_var('results_count', $resultcount);
@@ -270,7 +174,7 @@
if (($nRowIndex % 2) == 1) $bgcolor = $bgcolor2;
else $bgcolor = $bgcolor1;
if($inactive)
if ($inactive)
{
//$bgcolor = $bgcolor_inactive;
$tmpline = mb_ereg_replace('{gray_s}', "<span class='text_gray'>", $tmpline);
@@ -353,4 +257,6 @@
sqldbg_end();
else
tpl_BuildTemplate();
}
?>
+56 -187
View File
@@ -1,27 +1,27 @@
<?php
/***************************************************************************
./lib/search.kml.inc.php
-------------------
begin : November 1 2005
For license information see doc/license.txt
****************************************************************************/
/****************************************************************************
Unicode Reminder メモ
kml search output
****************************************************************************/
global $content, $bUseZip, $sqldebug;
$search_output_file_download = true;
$content_type_plain = 'vnd.google-earth.kml';
$content_type_zipped = 'vnd.google-earth.kmz';
function search_output()
{
global $sqldebug, $stylepath;
global $state_temporarily_na, $state_archived, $state_locked;
$kmlLine =
'
<Placemark>
<description><![CDATA[<a href="http://www.opencaching.de/viewcache.php?cacheid={cacheid}">Beschreibung ansehen</a><br>Von {username}<br>&nbsp;<br><table cellspacing="0" cellpadding="0" border="0"><tr><td>{typeimgurl} </td><td>Art: {type}<br>Größe: {size}</td></tr><tr><td colspan="2">Schwierigkeit: {difficulty} von 5.0<br>Gelände: {terrain} von 5.0</td></tr></table>]]></description>
<name>{name}</name>
<name>{name}{archivedflag}</name>
<LookAt>
<longitude>{lon}</longitude>
<latitude>{lat}</latitude>
@@ -40,153 +40,16 @@
$kmlFoot = '</Folder></Document></kml>';
$kmlTimeFormat = 'Y-m-d\TH:i:s\Z';
//prepare the output
$caches_per_page = 20;
$sql = 'SELECT ';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= '0 distance, ';
}
else
{
//get the users home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ((($record_coords['latitude'] == NULL) || ($record_coords['longitude'] == NULL)) || (($record_coords['latitude'] == 0) || ($record_coords['longitude'] == 0)))
{
$sql .= '0 distance, ';
}
else
{
//TODO: load from the users-profile
$distance_unit = 'km';
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
$sAddJoin = '';
$sAddGroupBy = '';
$sAddField = '';
$sGroupBy = '';
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sAddField = ', MAX(`cache_logs`.`date`) AS `lastLog`';
$sAddJoin = ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`';
if ($options['sort'] == 'bymylastlog')
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false? 0 : $usr['userid']);
$sGroupBy = ' GROUP BY `caches`.`cache_id`';
}
$sql .= '`caches`.`cache_id` `cache_id`, `caches`.`status` `status`, `caches`.`type` `type`, `caches`.`size` `size`, `caches`.`longitude` `longitude`, `caches`.`latitude` `latitude`, `caches`.`user_id` `user_id`,
IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`' .
$sAddField
. ' FROM `caches`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`' .
$sAddJoin
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' .
$sGroupBy;
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
$sql .= '`caches`.`name` ASC';
}
//startat?
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0;
if (!is_numeric($startat)) $startat = 0;
if (isset($_REQUEST['count']))
$count = $_REQUEST['count'];
else
$count = $caches_per_page;
if ($count == 'max') $count = 500;
if (!is_numeric($count)) $count = 0;
if ($count < 1) $count = 1;
if ($count > 500) $count = 500;
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count;
// temporäre tabelle erstellen
sql_slave('CREATE TEMPORARY TABLE `kmlcontent` ' . $sql . $sqlLimit);
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `kmlcontent`');
$rCount = sql_fetch_array($rsCount);
mysql_free_result($rsCount);
if ($rCount['count'] == 1)
{
$rsName = sql_slave('SELECT `caches`.`wp_oc` `wp_oc` FROM `kmlcontent`, `caches` WHERE `kmlcontent`.`cache_id`=`caches`.`cache_id` LIMIT 1');
$rName = sql_fetch_array($rsName);
mysql_free_result($rsName);
$sFilebasename = $rName['wp_oc'];
}
else
$sFilebasename = 'ocde' . $options['queryid'];
$bUseZip = ($rCount['count'] > 20);
$bUseZip = $bUseZip || (isset($_REQUEST['zip']) && ($_REQUEST['zip'] == '1'));
if ($bUseZip == true)
{
$content = '';
require_once($rootpath . 'lib/phpzip/ss_zip.class.php');
$phpzip = new ss_zip('',6);
}
// ok, ausgabe starten
if ($sqldebug == false)
{
if ($bUseZip == true)
{
header("Content-Type: application/vnd.google-earth.kmz");
header('Content-Disposition: attachment; filename=' . $sFilebasename . '.kmz');
}
else
{
header("Content-Type: application/vnd.google-earth.kml");
header("Content-Disposition: attachment; filename=" . $sFilebasename . ".kml");
}
}
$kmlDetailHead = read_file($stylepath . '/search.result.caches.kml.head.tpl.php');
$rsMinMax = sql_slave('SELECT MIN(`longitude`) `minlon`, MAX(`longitude`) `maxlon`, MIN(`latitude`) `minlat`, MAX(`latitude`) `maxlat` FROM `kmlcontent`', $sqldebug);
$rsMinMax = sql_slave('
SELECT
MIN(`longitude`) `minlon`,
MAX(`longitude`) `maxlon`,
MIN(`latitude`) `minlat`,
MAX(`latitude`) `maxlat`
FROM
`searchtmp`', $sqldebug);
$rMinMax = sql_fetch_array($rsMinMax);
mysql_free_result($rsMinMax);
@@ -198,8 +61,6 @@
append_output($kmlDetailHead);
// ok, ausgabe ...
/*
wp
name
@@ -211,8 +72,34 @@
icon
*/
$rs = sql_slave('SELECT SQL_BUFFER_RESULT `kmlcontent`.`cache_id` `cacheid`, `kmlcontent`.`longitude` `longitude`, `kmlcontent`.`latitude` `latitude`, `kmlcontent`.`type` `type`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`, `caches`.`status` `status`, `cache_type`.`de` `typedesc`, `cache_size`.`de` `sizedesc`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `user`.`username` `username` FROM `kmlcontent`, `caches`, `cache_type`, `cache_size`, `user` WHERE `kmlcontent`.`cache_id`=`caches`.`cache_id` AND `kmlcontent`.`type`=`cache_type`.`id` AND `kmlcontent`.`size`=`cache_size`.`id` AND `kmlcontent`.`user_id`=`user`.`user_id`', $sqldebug);
while($r = sql_fetch_array($rs))
$rs = sql_slave('
SELECT SQL_BUFFER_RESULT
`searchtmp`.`cache_id` `cacheid`,
`searchtmp`.`longitude`,
`searchtmp`.`latitude`,
`searchtmp`.`type`,
`caches`.`date_hidden`,
`caches`.`name`,
`caches`.`status`,
`cache_type`.`de` `typedesc`,
`cache_size`.`de` `sizedesc`,
`caches`.`terrain`,
`caches`.`difficulty`,
`user`.`username`
FROM
`searchtmp`,
`caches`,
`cache_type`,
`cache_size`,
`user`
WHERE
`searchtmp`.`cache_id`=`caches`.`cache_id` AND
`searchtmp`.`type`=`cache_type`.`id` AND
`searchtmp`.`size`=`cache_size`.`id` AND
`searchtmp`.`user_id`=`user`.`user_id`',
$sqldebug);
while ($r = sql_fetch_array($rs))
{
$thisline = $kmlLine;
@@ -274,12 +161,14 @@
$thisline = mb_ereg_replace('{name}', xmlentities($r['name']), $thisline);
if (($r['status'] == 2) || ($r['status'] == 3))
if (($r['status'] == 2) || ($r['status'] == 3) || ($r['status'] == 6))
{
if ($r['status'] == 2)
$thisline = mb_ereg_replace('{archivedflag}', 'Momentan nicht verfügbar!, ', $thisline);
$thisline = mb_ereg_replace('{archivedflag}', ' ('.$state_temporarily_na.')', $thisline);
elseif ($r['status'] == 3)
$thisline = mb_ereg_replace('{archivedflag}', ' ('.$state_archived.')', $thisline);
else
$thisline = mb_ereg_replace('{archivedflag}', 'Archiviert!, ', $thisline);
$thisline = mb_ereg_replace('{archivedflag}', ' ('.$state_locked.')', $thisline);
}
else
$thisline = mb_ereg_replace('{archivedflag}', '', $thisline);
@@ -302,21 +191,11 @@
append_output($thisline);
}
mysql_free_result($rs);
append_output($kmlFoot);
if ($sqldebug == true) sqldbg_end();
// phpzip versenden
if ($bUseZip == true)
{
$phpzip->add_data($sFilebasename . '.kml', $content);
// use 'r'=raw instead of 'b'=browser: don't generate new header information!
echo $phpzip->save($sFilebasename . '.kmz', 'r');
}
exit;
append_output($kmlFoot);
}
function xmlentities($str)
{
$from[0] = '&'; $to[0] = '&amp;';
@@ -330,15 +209,5 @@
return $str;
}
function append_output($str)
{
global $content, $bUseZip, $sqldebug;
if ($sqldebug == true) return;
if ($bUseZip == true)
$content .= $str;
else
echo $str;
}
?>
+39 -200
View File
@@ -1,21 +1,19 @@
<?php
/***************************************************************************
./lib/search.loc.inc.php
-------------------
begin : November 1 2005
For license information see doc/license.txt
****************************************************************************/
/****************************************************************************
Unicode Reminder メモ
loc search output
****************************************************************************/
global $content, $bUseZip, $sqldebug;
$search_output_file_download = true;
$content_type_plain = 'application/loc';
function search_output()
{
global $state_temporarily_na, $state_archived, $state_locked;
$locHead = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><loc version="1.0" src="opencaching.de">' . "\n";
@@ -31,169 +29,36 @@
$locFoot = '</loc>';
//prepare the output
$caches_per_page = 20;
$sql = 'SELECT ';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= '0 distance, ';
}
else
{
//get the users home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ((($record_coords['latitude'] == NULL) || ($record_coords['longitude'] == NULL)) || (($record_coords['latitude'] == 0) || ($record_coords['longitude'] == 0)))
{
$sql .= '0 distance, ';
}
else
{
//TODO: load from the users-profile
$distance_unit = 'km';
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
$sAddJoin = '';
$sAddGroupBy = '';
$sAddField = '';
$sGroupBy = '';
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sAddField = ', MAX(`cache_logs`.`date`) AS `lastLog`';
$sAddJoin = ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`';
if ($options['sort'] == 'bymylastlog')
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false? 0 : $usr['userid']);
$sGroupBy = ' GROUP BY `caches`.`cache_id`';
}
$sql .= '`caches`.`cache_id` `cache_id`, `caches`.`status` `status`, `caches`.`type` `type`, `caches`.`size` `size`, `caches`.`longitude` `longitude`, `caches`.`latitude` `latitude`, `caches`.`user_id` `user_id`,
IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`' .
$sAddField
. ' FROM `caches`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`' .
$sAddJoin
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' .
$sGroupBy;
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
$sql .= '`caches`.`name` ASC';
}
//startat?
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0;
if (!is_numeric($startat)) $startat = 0;
if (isset($_REQUEST['count']))
$count = $_REQUEST['count'];
else
$count = $caches_per_page;
if ($count == 'max') $count = 500;
if (!is_numeric($count)) $count = 0;
if ($count < 1) $count = 1;
if ($count > 500) $count = 500;
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count;
// temporäre tabelle erstellen
sql_slave('CREATE TEMPORARY TABLE `loccontent` ' . $sql . $sqlLimit, $sqldebug);
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `loccontent`');
$rCount = sql_fetch_array($rsCount);
mysql_free_result($rsCount);
if ($rCount['count'] == 1)
{
$rsName = sql_slave('SELECT `caches`.`wp_oc` `wp_oc` FROM `loccontent`, `caches` WHERE `loccontent`.`cache_id`=`caches`.`cache_id` LIMIT 1');
$rName = sql_fetch_array($rsName);
mysql_free_result($rsName);
$sFilebasename = $rName['wp_oc'];
}
else
$sFilebasename = 'ocde' . $options['queryid'];
$bUseZip = ($rCount['count'] > 20);
$bUseZip = $bUseZip || (isset($_REQUEST['zip']) ? $_REQUEST['zip'] == '1' : false);
if ($bUseZip == true)
{
$content = '';
require_once($rootpath . 'lib/phpzip/ss_zip.class.php');
$phpzip = new ss_zip('',6);
}
// ok, ausgabe starten
if ($sqldebug == false)
{
if ($bUseZip == true)
{
header("content-type: application/zip");
header('Content-Disposition: attachment; filename='. $sFilebasename . '.zip');
}
else
{
header("Content-type: application/loc");
header("Content-Disposition: attachment; filename=" . $sFilebasename . ".loc");
}
}
append_output($locHead);
// ok, ausgabe ...
/*
cacheid
name
lon
lat
archivedflag
type
size
difficulty
terrain
username
{waypoint}
status -> {archivedflag}
{name}
{username}
{lon}
{lat}
{cacheid}
*/
$rs = sql_slave('SELECT SQL_BUFFER_RESULT `loccontent`.`cache_id` `cacheid`, `loccontent`.`longitude` `longitude`, `loccontent`.`latitude` `latitude`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`, `caches`.`status` `status`, `caches`.`wp_oc` `waypoint`, `cache_type`.`short` `typedesc`, `cache_size`.`de` `sizedesc`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `user`.`username` `username` FROM `loccontent`, `caches`, `cache_type`, `cache_size`, `user` WHERE `loccontent`.`cache_id`=`caches`.`cache_id` AND `loccontent`.`type`=`cache_type`.`id` AND `loccontent`.`size`=`cache_size`.`id` AND `loccontent`.`user_id`=`user`.`user_id`');
while($r = sql_fetch_array($rs))
$rs = sql_slave('
SELECT SQL_BUFFER_RESULT
`searchtmp`.`cache_id` `cacheid`,
`searchtmp`.`longitude`,
`searchtmp`.`latitude`,
`caches`.`name`,
`caches`.`status`,
`caches`.`wp_oc` `waypoint`,
`user`.`username` `username`
FROM
`searchtmp`,
`caches`,
`user`
WHERE
`searchtmp`.`cache_id`=`caches`.`cache_id` AND
`searchtmp`.`user_id`=`user`.`user_id`');
while ($r = sql_fetch_array($rs))
{
$thisline = $locLine;
@@ -206,25 +71,18 @@
$thisline = mb_ereg_replace('{waypoint}', $r['waypoint'], $thisline);
$thisline = mb_ereg_replace('{name}', xmlentities($r['name']), $thisline);
if (($r['status'] == 2) || ($r['status'] == 3))
if (($r['status'] == 2) || ($r['status'] == 3) || ($r['status'] == 6))
{
if ($r['status'] == 2)
$thisline = mb_ereg_replace('{archivedflag}', 'Momentan nicht verfügbar!, ', $thisline);
$thisline = mb_ereg_replace('{archivedflag}', $state_temporarily_na.'!, ', $thisline);
elseif ($r['status'] == 3)
$thisline = mb_ereg_replace('{archivedflag}', $state_archived.'!, ', $thisline);
else
$thisline = mb_ereg_replace('{archivedflag}', 'Archiviert!, ', $thisline);
$thisline = mb_ereg_replace('{archivedflag}', $state_locked.'!, ', $thisline);
}
else
$thisline = mb_ereg_replace('{archivedflag}', '', $thisline);
$thisline = mb_ereg_replace('{type}', xmlentities($r['typedesc']), $thisline);
$thisline = mb_ereg_replace('{size}', xmlentities($r['sizedesc']), $thisline);
$difficulty = sprintf('%01.1f', $r['difficulty'] / 2);
$thisline = mb_ereg_replace('{difficulty}', $difficulty, $thisline);
$terrain = sprintf('%01.1f', $r['terrain'] / 2);
$thisline = mb_ereg_replace('{terrain}', $terrain, $thisline);
$thisline = mb_ereg_replace('{username}', xmlentities($r['username']), $thisline);
$thisline = mb_ereg_replace('{cacheid}', $r['cacheid'], $thisline);
@@ -233,18 +91,9 @@
mysql_free_result($rs);
append_output($locFoot);
if ($sqldebug == true) sqldbg_end();
// phpzip versenden
if ($bUseZip == true)
{
$phpzip->add_data($sFilebasename . '.loc', $content);
echo $phpzip->save($sFilebasename . '.zip', 'b');
}
}
exit;
function xmlentities($str)
{
$from[0] = '&'; $to[0] = '&amp;';
@@ -259,14 +108,4 @@
return $str;
}
function append_output($str)
{
global $content, $bUseZip, $sqldebug;
if ($sqldebug == true) return;
if ($bUseZip == true)
$content .= $str;
else
echo $str;
}
?>
+34 -177
View File
@@ -1,184 +1,60 @@
<?php
/***************************************************************************
./lib/search.ov2.inc.php
-------------------
begin : November 2 2005
For license information see doc/license.txt
****************************************************************************/
/****************************************************************************
Unicode Reminder メモ
ov2 search output
****************************************************************************/
global $content, $bUseZip, $sqldebug;
$search_output_file_download = true;
$content_type_plain = 'application/ov2';
//prepare the output
$caches_per_page = 20;
$sql = 'SELECT ';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= '0 distance, ';
}
else
{
//get the users home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ((($record_coords['latitude'] == NULL) || ($record_coords['longitude'] == NULL)) || (($record_coords['latitude'] == 0) || ($record_coords['longitude'] == 0)))
{
$sql .= '0 distance, ';
}
else
{
//TODO: load from the users-profile
$distance_unit = 'km';
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
function search_output()
{
global $sqldebug;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
$sAddJoin = '';
$sAddGroupBy = '';
$sAddField = '';
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sAddField = ', MAX(`cache_logs`.`date`) AS `lastLog`';
$sAddJoin = ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`';
if ($options['sort'] == 'bymylastlog')
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false? 0 : $usr['userid']);
$sGroupBy = ' GROUP BY `caches`.`cache_id`';
}
$sql .= '`caches`.`cache_id` `cache_id`, `caches`.`status` `status`, `caches`.`type` `type`, `caches`.`size` `size`, `caches`.`longitude` `longitude`, `caches`.`latitude` `latitude`, `caches`.`user_id` `user_id`,
IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`' .
$sAddField
. ' FROM `caches`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`' .
$sAddJoin
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' .
$sGroupBy;
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
$sql .= '`caches`.`name` ASC';
}
//startat?
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0;
if (!is_numeric($startat)) $startat = 0;
if (isset($_REQUEST['count']))
$count = $_REQUEST['count'];
else
$count = $caches_per_page;
if ($count == 'max') $count = 500;
if (!is_numeric($count)) $count = 0;
if ($count < 1) $count = 1;
if ($count > 500) $count = 500;
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count;
// temporäre tabelle erstellen
sql_slave('CREATE TEMPORARY TABLE `ov2content` ' . $sql . $sqlLimit);
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `ov2content`');
$rCount = sql_fetch_array($rsCount);
mysql_free_result($rsCount);
if ($rCount['count'] == 1)
{
$rsName = sql_slave('SELECT `caches`.`wp_oc` `wp_oc` FROM `ov2content`, `caches` WHERE `ov2content`.`cache_id`=`caches`.`cache_id` LIMIT 1');
$rName = sql_fetch_array($rsName);
mysql_free_result($rsName);
$sFilebasename = $rName['wp_oc'];
}
else
$sFilebasename = 'ocde' . $options['queryid'];
$bUseZip = ($rCount['count'] > 20);
$bUseZip = $bUseZip || (isset($_REQUEST['zip']) ? $_REQUEST['zip'] == '1' : false);
if ($bUseZip == true)
{
$content = '';
require_once($opt['rootpath'] . 'lib/phpzip/ss_zip.class.php');
$phpzip = new ss_zip('',6);
}
// ok, ausgabe starten
if ($sqldebug == false)
{
if ($bUseZip == true)
{
header("content-type: application/zip");
header('Content-Disposition: attachment; filename=' . $sFilebasename . '.zip');
}
else
{
header("Content-type: application/ov2");
header("Content-Disposition: attachment; filename=" . $sFilebasename . ".ov2");
}
}
// ok, ausgabe ...
/*
cacheid
name
lon
lat
archivedflag
latitude
longitude
type
size
difficulty
terrain
username
waypoint
*/
$sql = 'SELECT `ov2content`.`cache_id` `cacheid`, `ov2content`.`longitude` `longitude`, `ov2content`.`latitude` `latitude`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`, `caches`.`wp_oc` `wp_oc`, `cache_type`.`short` `typedesc`, `cache_size`.`de` `sizedesc`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `user`.`username` `username` FROM `ov2content`, `caches`, `cache_type`, `cache_size`, `user` WHERE `ov2content`.`cache_id`=`caches`.`cache_id` AND `ov2content`.`type`=`cache_type`.`id` AND `ov2content`.`size`=`cache_size`.`id` AND `ov2content`.`user_id`=`user`.`user_id`';
$sql = '
SELECT
`searchtmp`.`cache_id` `cacheid`,
`searchtmp`.`longitude`,
`searchtmp`.`latitude`,
`caches`.`name`,
`caches`.`wp_oc`,
`caches`.`terrain`,
`caches`.`difficulty`,
`cache_type`.`short` `typedesc`,
`cache_size`.`de` `sizedesc`,
`user`.`username`
FROM
`searchtmp`,
`caches`,
`cache_type`,
`cache_size`,
`user`
WHERE
`searchtmp`.`cache_id`=`caches`.`cache_id` AND
`searchtmp`.`type`=`cache_type`.`id` AND
`searchtmp`.`size`=`cache_size`.`id` AND
`searchtmp`.`user_id`=`user`.`user_id`';
$rs = sql_slave($sql, $sqldebug);
while($r = sql_fetch_array($rs))
while ($r = sql_fetch_array($rs))
{
$lat = sprintf('%07d', $r['latitude'] * 100000);
$lon = sprintf('%07d', $r['longitude'] * 100000);
@@ -196,17 +72,8 @@
append_output($record);
}
mysql_free_result($rs);
if ($sqldebug == true) sqldbg_end();
// phpzip versenden
if ($bUseZip == true)
{
$phpzip->add_data($sFilebasename . '.ov2', $content);
echo $phpzip->save($sFilebasename . '.zip', 'b');
}
}
exit;
function convert_string($str)
{
@@ -217,14 +84,4 @@
return $newstr;
}
function append_output($str)
{
global $content, $bUseZip, $sqldebug;
if ($sqldebug == true) return;
if ($bUseZip == true)
$content .= $str;
else
echo $str;
}
?>
+21 -191
View File
@@ -1,170 +1,21 @@
<?php
/***************************************************************************
./lib/search.ovl.inc.php
-------------------
begin : November 5 2005
For license information see doc/license.txt
****************************************************************************/
/****************************************************************************
Unicode Reminder メモ
ovl search output for TOP25, TOP50 etc.
****************************************************************************/
global $content, $bUseZip, $sqldebug;
$search_output_file_download = true;
$content_type_plain = 'application/ovl';
function search_output()
{
$ovlLine = "[Symbol {symbolnr1}]\r\nTyp=6\r\nGroup=1\r\nWidth=20\r\nHeight=20\r\nDir=100\r\nArt=1\r\nCol=3\r\nZoom=1\r\nSize=103\r\nArea=2\r\nXKoord={lon}\r\nYKoord={lat}\r\n[Symbol {symbolnr2}]\r\nTyp=2\r\nGroup=1\r\nCol=3\r\nArea=1\r\nZoom=1\r\nSize=130\r\nFont=1\r\nDir=100\r\nXKoord={lonname}\r\nYKoord={latname}\r\nText={cachename}\r\n";
$ovlFoot = "[Overlay]\r\nSymbols={symbolscount}\r\n";
//prepare the output
$caches_per_page = 20;
$sql = 'SELECT ';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= '0 distance, ';
}
else
{
//get the users home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ((($record_coords['latitude'] == NULL) || ($record_coords['longitude'] == NULL)) || (($record_coords['latitude'] == 0) || ($record_coords['longitude'] == 0)))
{
$sql .= '0 distance, ';
}
else
{
//TODO: load from the users-profile
$distance_unit = 'km';
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
$sAddJoin = '';
$sAddGroupBy = '';
$sAddField = '';
$sGroupBy = '';
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sAddField = ', MAX(`cache_logs`.`date`) AS `lastLog`';
$sAddJoin = ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`';
if ($options['sort'] == 'bymylastlog')
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false? 0 : $usr['userid']);
$sGroupBy = ' GROUP BY `caches`.`cache_id`';
}
$sql .= '`caches`.`cache_id` `cache_id`, `caches`.`longitude` `longitude`, `caches`.`latitude` `latitude`,
IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`' .
$sAddField
. ' FROM `caches`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`' .
$sAddJoin
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' .
$sGroupBy;
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
$sql .= '`caches`.`name` ASC';
}
//startat?
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0;
if (!is_numeric($startat)) $startat = 0;
if (isset($_REQUEST['count']))
$count = $_REQUEST['count'];
else
$count = $caches_per_page;
if ($count == 'max') $count = 500;
if (!is_numeric($count)) $count = 0;
if ($count < 1) $count = 1;
if ($count > 500) $count = 500;
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count;
// temporäre tabelle erstellen
sql_slave('CREATE TEMPORARY TABLE `ovlcontent` ' . $sql . $sqlLimit, $sqldebug);
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `ovlcontent`');
$rCount = sql_fetch_array($rsCount);
mysql_free_result($rsCount);
if ($rCount['count'] == 1)
{
$rsName = sql_slave('SELECT `caches`.`wp_oc` `wp_oc` FROM `ovlcontent`, `caches` WHERE `ovlcontent`.`cache_id`=`caches`.`cache_id` LIMIT 1');
$rName = sql_fetch_array($rsName);
mysql_free_result($rsName);
$sFilebasename = $rName['wp_oc'];
}
else
$sFilebasename = 'ocde' . $options['queryid'];
$bUseZip = ($rCount['count'] > 20);
$bUseZip = $bUseZip || (isset($_REQUEST['zip']) && ($_REQUEST['zip'] == '1'));
if ($bUseZip == true)
{
$content = '';
require_once($opt['rootpath'] . 'lib/phpzip/ss_zip.class.php');
$phpzip = new ss_zip('',6);
}
// ok, ausgabe starten
if ($sqldebug == false)
{
if ($bUseZip == true)
{
header("content-type: application/zip");
header('Content-Disposition: attachment; filename=' . $sFilebasename . '.zip');
}
else
{
header("Content-type: application/ovl");
header("Content-Disposition: attachment; filename=" . $sFilebasename . ".ovl");
}
}
// ok, ausgabe ...
/*
{symbolnr1}
{lon}
@@ -173,11 +24,23 @@
{lonname}
{latname}
{cachename}
{symbolscount}
*/
$nr = 1;
$rs = sql_slave('SELECT SQL_BUFFER_RESULT `ovlcontent`.`cache_id` `cacheid`, `ovlcontent`.`longitude` `longitude`, `ovlcontent`.`latitude` `latitude`, `caches`.`name` `name` FROM `ovlcontent`, `caches` WHERE `ovlcontent`.`cache_id`=`caches`.`cache_id`');
while($r = sql_fetch_array($rs))
$rs = sql_slave('
SELECT SQL_BUFFER_RESULT
`searchtmp`.`cache_id` `cacheid`,
`searchtmp`.`longitude`,
`searchtmp`.`latitude`,
`caches`.`name`
FROM
`searchtmp`,
`caches`
WHERE
`searchtmp`.`cache_id`=`caches`.`cache_id`');
while ($r = sql_fetch_array($rs))
{
$thisline = $ovlLine;
@@ -200,18 +63,9 @@
$ovlFoot = mb_ereg_replace('{symbolscount}', $nr - 1, $ovlFoot);
append_output($ovlFoot);
if ($sqldebug == true) sqldbg_end();
// phpzip versenden
if ($bUseZip == true)
{
$phpzip->add_data($sFilebasename . '.ovl', $content);
echo $phpzip->save($sFilebasename . '.zip', 'b');
}
}
exit;
function convert_string($str)
{
$newstr = iconv("UTF-8", "ISO-8859-1", $str);
@@ -221,28 +75,4 @@
return $newstr;
}
function xmlentities($str)
{
$from[0] = '&'; $to[0] = '&amp;';
$from[1] = '<'; $to[1] = '&lt;';
$from[2] = '>'; $to[2] = '&gt;';
$from[3] = '"'; $to[3] = '&quot;';
$from[4] = '\''; $to[4] = '&apos;';
for ($i = 0; $i <= 4; $i++)
$str = mb_ereg_replace($from[$i], $to[$i], $str);
return $str;
}
function append_output($str)
{
global $content, $bUseZip, $sqldebug;
if ($sqldebug == true) return;
if ($bUseZip == true)
$content .= $str;
else
echo $str;
}
?>
+55 -169
View File
@@ -1,21 +1,23 @@
<?php
/***************************************************************************
./lib/search.gpx.inc.php
-------------------
begin : November 1 2005
For license information see doc/license.txt
****************************************************************************/
/****************************************************************************
Unicode Reminder メモ
GPX search output
****************************************************************************/
global $content, $bUseZip, $sqldebug, $locale;
$search_output_file_download = true;
$content_type_plain = 'text/plain';
$zip_threshold = 1;
$add_to_zipfile = false;
function search_output()
{
global $absolute_server_URI, $locale;
global $converted_from_html;
global $phpzip, $bUseZip;
$txtLine = "Name: {cachename} von {owner}
Koordinaten: {lon} {lat}
@@ -53,155 +55,47 @@ Logeinträge:
{text}
";
//prepare the output
$caches_per_page = 20;
$sql = 'SELECT ';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= '0 distance, ';
}
else
{
//get the users home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ((($record_coords['latitude'] == NULL) || ($record_coords['longitude'] == NULL)) || (($record_coords['latitude'] == 0) || ($record_coords['longitude'] == 0)))
{
$sql .= '0 distance, ';
}
else
{
//TODO: load from the users-profile
$distance_unit = 'km';
$rs = sql_slave('
SELECT SQL_BUFFER_RESULT
`searchtmp`.`cache_id` `cacheid`,
`searchtmp`.`longitude` `longitude`,
`searchtmp`.`latitude` `latitude`,
`caches`.`wp_oc` `waypoint`,
`caches`.`date_hidden` `date_hidden`,
`caches`.`name` `name`,
`caches`.`country` `country`,
`caches`.`terrain` `terrain`,
`caches`.`difficulty` `difficulty`,
`caches`.`desc_languages` `desc_languages`,
`cache_size`.`de` `size`,
`cache_type`.`de` `type`,
`cache_status`.`de` `status`,
`user`.`username` `username`,
`cache_desc`.`desc` `desc`,
`cache_desc`.`short_desc` `short_desc`,
`cache_desc`.`hint` `hint`,
`cache_desc`.`desc_html` `html`,
`user`.`user_id`,
`user`.`username`,
`user`.`data_license`
FROM
`searchtmp`,
`caches`,
`user`,
`cache_desc`,
`cache_type`,
`cache_status`,
`cache_size`
WHERE
`searchtmp`.`cache_id`=`caches`.`cache_id` AND
`caches`.`cache_id`=`cache_desc`.`cache_id` AND
`caches`.`default_desclang`=`cache_desc`.`language` AND
`searchtmp`.`user_id`=`user`.`user_id` AND
`caches`.`type`=`cache_type`.`id` AND
`caches`.`status`=`cache_status`.`id` AND
`caches`.`size`=`cache_size`.`id`');
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
$sAddJoin = '';
$sAddGroupBy = '';
$sAddField = '';
$sGroupBy = '';
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sAddField = ', MAX(`cache_logs`.`date`) AS `lastLog`';
$sAddJoin = ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`';
if ($options['sort'] == 'bymylastlog')
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false? 0 : $usr['userid']);
$sGroupBy = ' GROUP BY `caches`.`cache_id`';
}
$sql .= '`caches`.`cache_id` `cache_id`, `caches`.`status` `status`, `caches`.`type` `type`,
`caches`.`size` `size`, `caches`.`longitude` `longitude`, `caches`.`latitude` `latitude`,
`caches`.`user_id` `user_id`,
IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`' .
$sAddField
. ' FROM `caches`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`' .
$sAddJoin
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' .
$sGroupBy;
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
$sql .= '`caches`.`name` ASC';
}
//startat?
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0;
if (!is_numeric($startat)) $startat = 0;
if (isset($_REQUEST['count']))
$count = $_REQUEST['count'];
else
$count = $caches_per_page;
if ($count == 'max') $count = 500;
if (!is_numeric($count)) $count = 0;
if ($count < 1) $count = 1;
if ($count > 500) $count = 500;
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count;
// temporäre tabelle erstellen
sql_slave('CREATE TEMPORARY TABLE `txtcontent` ' . $sql . $sqlLimit, $sqldebug);
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `txtcontent`');
$rCount = sql_fetch_array($rsCount);
mysql_free_result($rsCount);
if ($rCount['count'] == 1)
{
$rsName = sql_slave('SELECT `caches`.`wp_oc` `wp_oc` FROM `txtcontent`, `caches` WHERE `txtcontent`.`cache_id`=`caches`.`cache_id` LIMIT 1');
$rName = sql_fetch_array($rsName);
mysql_free_result($rsName);
$sFilebasename = $rName['wp_oc'];
}
else
$sFilebasename = 'ocde' . $options['queryid'];
$bUseZip = ($rCount['count'] > 1);
$bUseZip = $bUseZip || (isset($_REQUEST['zip']) && ($_REQUEST['zip'] == '1'));
if ($bUseZip == true)
{
$content = '';
require_once($opt['rootpath'] . 'lib/phpzip/ss_zip.class.php');
$phpzip = new ss_zip('',6);
}
// ok, ausgabe starten
if ($sqldebug == false)
{
if ($bUseZip == true)
{
header("content-type: application/zip");
header('Content-Disposition: attachment; filename=' . $sFilebasename . '.zip');
}
else
{
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=" . $sFilebasename . ".txt");
}
}
// ok, ausgabe ...
$rs = sql_slave('SELECT SQL_BUFFER_RESULT `txtcontent`.`cache_id` `cacheid`, `txtcontent`.`longitude` `longitude`, `txtcontent`.`latitude` `latitude`, `caches`.`wp_oc` `waypoint`, `caches`.`date_hidden` `date_hidden`, `caches`.`name` `name`, `caches`.`country` `country`, `caches`.`terrain` `terrain`, `caches`.`difficulty` `difficulty`, `caches`.`desc_languages` `desc_languages`, `cache_size`.`de` `size`, `cache_type`.`de` `type`, `cache_status`.`de` `status`, `user`.`username` `username`, `cache_desc`.`desc` `desc`, `cache_desc`.`short_desc` `short_desc`, `cache_desc`.`hint` `hint`, `cache_desc`.`desc_html` `html`, `user`.`user_id`, `user`.`username`, `user`.`data_license` FROM `txtcontent`, `caches`, `user`, `cache_desc`, `cache_type`, `cache_status`, `cache_size` WHERE `txtcontent`.`cache_id`=`caches`.`cache_id` AND `caches`.`cache_id`=`cache_desc`.`cache_id` AND `caches`.`default_desclang`=`cache_desc`.`language` AND `txtcontent`.`user_id`=`user`.`user_id` AND `caches`.`type`=`cache_type`.`id` AND `caches`.`status`=`cache_status`.`id` AND `caches`.`size`=`cache_size`.`id`');
while($r = sql_fetch_array($rs))
while ($r = sql_fetch_array($rs))
{
$thisline = $txtLine;
@@ -237,7 +131,7 @@ Logeinträge:
}
else
{
$thisline = mb_ereg_replace('{htmlwarn}', ' (Vorsicht, aus HTML konvertiert)', $thisline);
$thisline = mb_ereg_replace('{htmlwarn}', " ($converted_from_html)", $thisline);
$thisline = mb_ereg_replace('{desc}', html2txt($r['desc']) . $license, $thisline);
}
@@ -281,8 +175,7 @@ Logeinträge:
$thisline = mb_ereg_replace('{logs}', $logentries, $thisline);
$thisline = lf2crlf($thisline);
if (($rCount['count'] == 1) && ($bUseZip == false))
if (($rCount['count'] == 1) && !$bUseZip)
echo $thisline;
else
{
@@ -290,16 +183,8 @@ Logeinträge:
}
}
mysql_free_result($rs);
}
if ($sqldebug == true) sqldbg_end();
// phpzip versenden
if ($bUseZip == true)
{
echo $phpzip->save($sFilebasename . '.zip', 'b');
}
exit;
function decodeEntities($str)
{
@@ -321,4 +206,5 @@ Logeinträge:
{
return mb_ereg_replace("\r\r\n" ,"\r\n" , mb_ereg_replace("\n" ,"\r\n" , $str));
}
?>
+23 -112
View File
@@ -1,24 +1,19 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
/****************************************************************************
For license information see doc/license.txt
XML search output
****************************************************************************/
global $content, $bUseZip, $sqldebug;
$search_output_file_download = false;
function search_output()
{
global $sqldebug;
global $distance_unit, $startat, $count, $sql, $sqlLimit;
$lang = 'DE';
$encoding = 'UTF-8';
$xmlLine = " <cache>
@@ -42,100 +37,17 @@
</cache>
";
//prepare the output
$caches_per_page = 20;
$sql = 'SELECT SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS ';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= '0 distance, ';
}
else
{
//get the users home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ((($record_coords['latitude'] == NULL) || ($record_coords['longitude'] == NULL)) || (($record_coords['latitude'] == 0) || ($record_coords['longitude'] == 0)))
{
$sql .= '0 distance, ';
}
else
{
//TODO: load from the users-profile
$distance_unit = 'km';
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
$sql .= '`caches`.`cache_id` `cache_id`, `caches`.`status` `status`, `caches`.`type` `type`, `caches`.`size` `size`, `caches`.`longitude` `longitude`, `caches`.`latitude` `latitude`, `caches`.`user_id` `user_id`
FROM `caches`
WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')';
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $sortby == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
$sql .= '`caches`.`name` ASC';
}
//startat?
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0;
if (!is_numeric($startat)) $startat = 0;
if (isset($_REQUEST['count']))
$count = $_REQUEST['count'];
else
$count = $caches_per_page;
if ($count == 'max') $count = 500;
if (!is_numeric($count)) $count = 0;
if ($count < 1) $count = 1;
if ($count > 500) $count = 500;
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count;
// create temporary table
sql_slave('CREATE TEMPORARY TABLE `xmlcontent` ' . $sql . $sqlLimit);
sql_slave('CREATE TEMPORARY TABLE `searchtmp`
SELECT SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS ' . $sql . $sqlLimit);
$resultcount = sql_value_slave('SELECT FOUND_ROWS()', 0);
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `xmlcontent`');
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `searchtmp`');
$rCount = sql_fetch_array($rsCount);
mysql_free_result($rsCount);
// ok, ausgabe starten
// start output
if ($sqldebug == false)
{
header("Content-type: application/xml; charset=".$encoding);
@@ -152,11 +64,9 @@
echo " <total>" . $resultcount . "</total>\n";
echo " </docinfo>\n";
// ok, ausgabe ...
$rs = sql_slave('SELECT `xmlcontent`.`cache_id` `cacheid`,
`xmlcontent`.`longitude` `longitude`,
`xmlcontent`.`latitude` `latitude`,
$rs = sql_slave('SELECT `searchtmp`.`cache_id` `cacheid`,
`searchtmp`.`longitude` `longitude`,
`searchtmp`.`latitude` `latitude`,
`caches`.`wp_oc` `waypoint`,
`caches`.`date_hidden` `date_hidden`,
`caches`.`name` `name`,
@@ -176,10 +86,10 @@
`cache_desc`.`short_desc` `short_desc`,
`cache_desc`.`hint` `hint`,
`cache_desc`.`desc_html` `html`,
`xmlcontent`.`distance` `distance`
FROM `xmlcontent`
INNER JOIN `caches` ON `xmlcontent`.`cache_id`=`caches`.`cache_id`
INNER JOIN `user` ON `xmlcontent`.`user_id`=`user`.`user_id`
`searchtmp`.`distance` `distance`
FROM `searchtmp`
INNER JOIN `caches` ON `searchtmp`.`cache_id`=`caches`.`cache_id`
INNER JOIN `user` ON `searchtmp`.`user_id`=`user`.`user_id`
INNER JOIN `cache_desc` ON `caches`.`cache_id`=`cache_desc`.`cache_id` AND `caches`.`default_desclang`=`cache_desc`.`language`
INNER JOIN `cache_type` ON `caches`.`type`=`cache_type`.`id`
INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id`
@@ -244,11 +154,11 @@
echo $thisline;
}
mysql_free_result($rs);
sql_slave('DROP TABLE `xmlcontent` ');
sql_slave('DROP TABLE `searchtmp`');
if ($sqldebug == true) sqldbg_end();
echo "</result>\n";
exit;
}
function html2txt($html)
{
@@ -281,4 +191,5 @@
return $str;
}
?>
+235 -20
View File
@@ -1066,42 +1066,257 @@
}
//=================================================================
// X7. run postprocessing module depending on 'output' option
//
// The following variables (list may be incomplete) are used
// by the postprocessing modules:
//
// $_REQUEST['startat']
// $_REQUEST['count']
// $lat_rad, $lon_rad
// $options['sortby']
// $options['orderRatingFirst']
// $options['queryid']
// $cachesFilter, $sqlFilter
// $map2_bounds
// X7. verify output selection and prepare SQL query
//=================================================================
$map2_bounds = ($options['output'] == 'map2bounds');
$output_module = mb_strtolower($options['output']); // Ocprop: HTML, gpx
$map2_bounds = ($output_module == 'map2bounds');
if ($map2_bounds)
$options['output'] = 'map2';
$output_module = 'map2';
// Ocprop: HTML, gpx
if ($map2_bounds && $options['queryid'] == 0)
{
tpl_set_var('tplname', $tplname);
$tplname = 'error';
tpl_set_var('error_msg', 'map2bounds requires queryid');
}
elseif (!file_exists($opt['rootpath'] . 'lib/search.' . mb_strtolower($options['output']) . '.inc.php'))
elseif (!file_exists($opt['rootpath'] . 'lib/search.' . $output_module . '.inc.php'))
{
tpl_set_var('tplname', $tplname);
$tplname = 'error';
tpl_set_var('error_msg', $outputformat_notexist);
}
else
if ($tplname != 'error')
{
// run search query and output the results
require($opt['rootpath'] . 'lib/search.' . mb_strtolower($options['output']) . '.inc.php');
$caches_per_page = 20;
// Default settings; may be modified by output modules
$content_type_plain = 'application/octet-stream';
$content_type_zipped = 'application/zip';
$zip_threshold = $caches_per_page;
$add_to_zipfile = true;
$sAddJoin = '';
$sAddGroupBy = '';
$sAddFields = '';
$sGroupBy = '';
// *** load output module ***
require($opt['rootpath'] . 'lib/search.' . $output_module . '.inc.php');
if (!isset($search_output_file_download))
die("search_output_file_download not set for $output_module search");
// *** prepare SQL query ***
$sql = '';
// If no distance unit is preselected by distance search, use 'km' as default.
// The unit will be included e.g. in HTML and XML search results.
if (!isset($distance_unit))
$distance_unit = 'km';
if (isset($lat_rad) && isset($lon_rad))
{
$sql .= getSqlDistanceFormula($lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
else
{
if ($usr === false)
{
$sql .= 'NULL distance, ';
}
else
{
// get the user's home coords
$rs_coords = sql_slave("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`='&1'", $usr['userid']);
$record_coords = sql_fetch_array($rs_coords);
if ($record_coords['latitude'] == 0 && $record_coords['longitude'] == 0)
{
$sql .= 'NULL distance, ';
}
else
{
$lon_rad = $record_coords['longitude'] * 3.14159 / 180;
$lat_rad = $record_coords['latitude'] * 3.14159 / 180;
$sql .= getSqlDistanceFormula($record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
}
mysql_free_result($rs_coords);
}
}
if ($options['sort'] == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sAddFields .= ', MAX(`cache_logs`.`date`) AS `lastLog`';
$sAddJoin .= ' LEFT JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id`';
if ($options['sort'] == 'bymylastlog')
$sAddJoin .= ' AND `cache_logs`.`user_id`=' . sql_escape($usr === false ? 0 : $usr['userid']);
$sGroupBy .= ' GROUP BY `caches`.`cache_id`';
}
$sql .= '`caches`.`cache_id`,
`caches`.`status`,
`caches`.`type`,
`caches`.`size`,
`caches`.`longitude`, `caches`.`latitude`,
`caches`.`user_id`,
IF(IFNULL(`stat_caches`.`toprating`,0)>3, 4, IFNULL(`stat_caches`.`toprating`, 0)) `ratingvalue`' .
$sAddFields
. ' FROM `caches`
LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`' .
$sAddJoin
. ' WHERE `caches`.`cache_id` IN (' . $sqlFilter . ')' .
$sGroupBy;
$sortby = $options['sort'];
$sql .= ' ORDER BY ';
if ($options['orderRatingFirst'])
$sql .= '`ratingvalue` DESC, ';
if ($sortby == 'bylastlog' || $options['sort'] == 'bymylastlog')
{
$sql .= '`lastLog` DESC, ';
$sortby = 'bydistance';
}
if (isset($lat_rad) && isset($lon_rad) && ($sortby == 'bydistance'))
{
$sql .= '`distance` ASC';
}
else if ($sortby == 'bycreated')
{
$sql .= '`caches`.`date_created` DESC';
}
else // by name
{
// Some names start with spaces ...
// caches.name is not indexed, so ltrimming won't cost performance.
$sql .= 'LTRIM(`caches`.`name`) ASC';
}
// range of output
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat'] : 0;
if (!is_numeric($startat)) $startat = 0;
if (isset($_REQUEST['count'])) // Ocprop
$count = $_REQUEST['count'];
else
$count = $caches_per_page;
if ($count == 'max') $count = 500;
if (!is_numeric($count)) $count = 0;
if ($count < 1) $count = 1;
if ($count > 500) $count = 500;
$sqlLimit = ' LIMIT ' . $startat . ', ' . $count;
if ($search_output_file_download)
{
//=================================================================
// X8a. run query and output for file downloads
//=================================================================
sql_slave('CREATE TEMPORARY TABLE `searchtmp` SELECT ' . $sql . $sqlLimit,
$sqldebug);
$rsCount = sql_slave('SELECT COUNT(*) `count` FROM `searchtmp`');
$rCount = sql_fetch_array($rsCount);
mysql_free_result($rsCount);
if ($rCount['count'] == 1)
{
$rsName = sql_slave('
SELECT `caches`.`wp_oc` `wp_oc`
FROM `searchtmp`, `caches`
WHERE `searchtmp`.`cache_id`=`caches`.`cache_id` LIMIT 1'
);
$rName = sql_fetch_array($rsName);
mysql_free_result($rsName);
$sFilebasename = $rName['wp_oc'];
}
else
$sFilebasename = 'ocde' . $options['queryid'];
$bUseZip = ($rCount['count'] > $zip_threshold) ||
(isset($_REQUEST['zip']) && ($_REQUEST['zip'] == '1'));
if ($bUseZip)
{
$content = '';
require_once($opt['rootpath'] . 'lib/phpzip/ss_zip.class.php');
$phpzip = new ss_zip('',6);
}
if (!$sqldebug)
{
if ($bUseZip)
{
header('Content-type: ' . $content_type_zipped);
header('Content-disposition: attachment; filename="' . $sFilebasename . '.zip"');
}
else
{
header('Content-type: '.$content_type_plain);
header('Content-disposition: attachment; filename="' . $sFilebasename . '.' . $output_module .'"');
}
}
function append_output($str)
{
global $content, $bUseZip, $sqldebug;
if (!$sqldebug)
{
if ($bUseZip)
$content .= $str;
else
echo $str;
}
}
// *** run output module ***
//
// Modules will use these variables from search.php (list may be incomplete):
//
// $phpzip
// $bUseZip
search_output();
if ($sqldebug) sqldbg_end();
sql_slave('DROP TABLE `searchtmp`');
// output zip file
if ($bUseZip)
{
if ($add_to_zipfile)
{
$phpzip->add_data($sFilebasename . '.' . $output_module, $content);
}
echo $phpzip->save($sFilebasename . '.zip', 'r');
}
}
else
{
//=================================================================
// X8b. run other output module (XML, HTML)
//
// The following variables from search.php are used by output modules
// (list may be incomplete):
//
// $distance_unit
// $lat_rad, $lon_rad
// $startat
// $caches_per_page
// $sql
// $sqlLimit
// $options['sort']
// $options['queryid']
// $cachesFilter
// $map2_bounds
//=================================================================
search_output();
}
exit;
}
}