Skip to content

Commit 6c87331

Browse files
committed
New parameter in search methods: powertrail_only (BETA)
1 parent 23d2ddd commit 6c87331

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

okapi/core.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,12 @@ public function print_body()
805805
public function get_body()
806806
{
807807
$this->zip->Flush(clsTbsZip::TBSZIP_STRING);
808-
return $this->zip->OutputSrc;
808+
return $this->zip->OutputSrc;
809809
}
810810

811811
public function get_length()
812812
{
813-
# The _EstimateNewArchSize() method returns *false* if archive
813+
# The _EstimateNewArchSize() method returns *false* if archive
814814
# size can not be calculated *exactly*, which causes display()
815815
# method to skip Content-Length header, and triggers chunking
816816
return $this->zip->_EstimateNewArchSize();

okapi/facade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static function import_search_set($temp_table, $min_store, $max_ref_age)
103103
'caches.status in (1,2,3)',
104104
);
105105
return \okapi\services\caches\search\save\WebService::get_set(
106-
$tables, $where_conds, $min_store, $max_ref_age
106+
$tables, array() /* joins */, $where_conds, $min_store, $max_ref_age
107107
);
108108
}
109109

okapi/lib/tbszip.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class clsTbsZip {
1616
const TBSZIP_NOHEADER = 4; // option to use with DOWNLOAD: no header is sent
1717
const TBSZIP_FILE = 8; // output to file , or add from file
1818
const TBSZIP_STRING = 32; // output to string, or add from string
19-
19+
2020
function __construct() {
2121
$this->Meth8Ok = extension_loaded('zlib'); // check if Zlib extension is available. This is need for compress and uncompress with method 8.
2222
$this->DisplayError = true;
@@ -956,7 +956,7 @@ function _DataPrepare(&$Ref) {
956956
}
957957
}
958958
}
959-
/**
959+
/**
960960
* Return the size of the new archive, or false if it cannot be calculated (because of external file that must be compressed before to be insered)
961961
*/
962962
function _EstimateNewArchSize($Optim=true) {

okapi/services/caches/search/all.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@
160160
Boolean. If set to <b>true</b>, only caches which have not yet been
161161
found <b>by anyone</b> will be included.
162162
</opt>
163+
<opt name='powertrail_only' default='false'>
164+
BETA. Boolean. If set to <b>true</b>, only caches which belong to at least one
165+
Power Trail will be included. Power Trails are sets of geocaches. Not all
166+
Opencaching nodes implement the feature. If this node does not implement
167+
Power Trails and you will set this parameter to <b>true</b>, then you
168+
will <b>always</b> receive an empty result.
169+
</opt>
163170
<opt name='set_and'>
164171
<p>ID of a set previously created with the <b>search/save</b> method.
165172
If given, the results are <a href='http://en.wikipedia.org/wiki/Logical_conjunction'>AND</a>ed

okapi/services/caches/search/save.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,30 @@ public static function call(OkapiRequest $request)
7474
array('caches.wp_oc is not null'),
7575
$search_params['where_conds']
7676
);
77+
78+
if (isset($search_params['extra_joins']) && is_array($search_params['extra_joins']))
79+
$joins = $search_params['extra_joins'];
80+
else
81+
$joins = array();
82+
7783
unset($search_params);
7884

7985
# Generate, or retrieve an existing set, and return the result.
8086
# All user-supplied data in $tables and $where_conds MUST be escaped!
8187

82-
$result = self::get_set($tables, $where_conds, $min_store, $ref_max_age);
88+
$result = self::get_set($tables, $joins, $where_conds, $min_store, $ref_max_age);
8389
return Okapi::formatted_response($request, $result);
8490
}
8591

8692
/**
8793
* Important: YOU HAVE TO make sure $tables and $where_conds don't contain
8894
* unescaped user-supplied data!
8995
*/
90-
public static function get_set($tables, $where_conds, $min_store, $ref_max_age)
96+
public static function get_set($tables, $joins, $where_conds, $min_store, $ref_max_age)
9197
{
9298
# Compute the "params hash".
9399

94-
$params_hash = md5(serialize(array($tables, $where_conds)));
100+
$params_hash = md5(serialize(array($tables, $joins, $where_conds)));
95101

96102
# Check if there exists an entry for this hash, which also meets the
97103
# given freshness criteria.
@@ -133,7 +139,9 @@ public static function get_set($tables, $where_conds, $min_store, $ref_max_age)
133139
select distinct
134140
'".mysql_real_escape_string($set_id)."',
135141
caches.cache_id
136-
from ".implode(", ", $tables)."
142+
from
143+
".implode(", ", $tables)."
144+
".implode(" ", $joins)."
137145
where (".implode(") and (", $where_conds).")
138146
");
139147

okapi/services/caches/search/searching.inc.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,30 @@ public function prepare_common_search_params()
514514
if ($tmp = $this->request->get_parameter('ftf_hunter'))
515515
{
516516
if (!in_array($tmp, array('true', 'false'), 1))
517-
throw new InvalidParam('not_yet_found_only', "'$tmp'");
517+
throw new InvalidParam('ftf_hunter', "'$tmp'");
518518
if ($tmp == 'true')
519519
{
520520
$where_conds[] = "$X_FOUNDS = 0";
521521
}
522522
}
523523

524+
#
525+
# powertrail_only
526+
#
527+
if (!is_null($tmp = $this->request->get_parameter('powertrail_only')))
528+
{
529+
if (!in_array($tmp, array('true', 'false'), 1))
530+
throw new InvalidParam('powertrail_only', "'$tmp'");
531+
if ($tmp == 'true')
532+
{
533+
if (Settings::get('OC_BRANCH') == 'oc.pl') {
534+
$extra_joins[] = 'inner join powerTrail_caches on powerTrail_caches.cacheId = caches.cache_id';
535+
} else {
536+
$where_conds[] = "0=1";
537+
}
538+
}
539+
}
540+
524541
#
525542
# set_and
526543
#

0 commit comments

Comments
 (0)