savetyp check for illegal oc.pl waypoints

This commit is contained in:
following
2013-04-12 16:36:35 +02:00
parent ae96a031a2
commit 1056904d99
6 changed files with 92 additions and 25 deletions

View File

@ -742,32 +742,31 @@ class OkapiLock
else
{
$this->lockfile = Okapi::get_var_dir()."/okapi-lock-".$name;
if (!file_exists($this->lockfile))
{
$fp = fopen($this->lockfile, "wb");
fclose($fp);
}
$this->lock = sem_get(fileinode($this->lockfile));
$this->lock = fopen($this->lockfile, "wb");
}
}
public function acquire()
{
if ($this->lock !== null)
sem_acquire($this->lock);
flock($this->lock, LOCK_EX);
}
public function release()
{
if ($this->lock !== null)
sem_release($this->lock);
flock($this->lock, LOCK_UN);
}
/**
* Use this method clean up obsolete and *unused* lock names (usually there
* is no point in removing locks that can be reused.
*/
public function remove()
{
if ($this->lock !== null)
{
sem_remove($this->lock);
fclose($this->lock);
unlink($this->lockfile);
}
}
@ -778,7 +777,7 @@ class Okapi
{
public static $data_store;
public static $server;
public static $revision = 701; # This gets replaced in automatically deployed packages
public static $revision = 713; # This gets replaced in automatically deployed packages
private static $okapi_vars = null;
/** Get a variable stored in okapi_vars. If variable not found, return $default. */

View File

@ -23,7 +23,7 @@ class OkapiServiceRunner
'services/apiref/method',
'services/apiref/method_index',
'services/apiref/issue',
'services/attrs/info',
// Issue 70 - in progress: 'services/attrs/info',
'services/oauth/request_token',
'services/oauth/authorize',
'services/oauth/access_token',

View File

@ -156,7 +156,7 @@ http://www.gsak.net/xmlv1/5 http://www.gsak.net/xmlv1/5/gsak.xsd
<time><?= $c['date_created'] ?></time>
<name><?= Okapi::xmlescape($wpt['name']) ?></name>
<cmt><?= Okapi::xmlescape($wpt['description']) ?></cmt>
<desc><?= Okapi::xmlescape($wpt['description']) ?></desc>
<desc><?= Okapi::xmlescape($wpt['type_name']) ?></desc>
<url><?= $c['url'] ?></url>
<urlname><?= Okapi::xmlescape($c['name']) ?></urlname>
<sym><?= $wpt['sym'] ?></sym>

View File

@ -243,6 +243,15 @@
<li><b>name</b> - plain-text, short, unique "codename" for the waypoint,</li>
<li><b>location</b> - location of the waypoint in the "lat|lon" format
(<i>lat</i> and <i>lon</i> are in full degrees with a dot as a decimal point),</li>
<li><b>type</b> - string, unique identifier for the type of waypoint; one
of the following: <b>parking</b>, <b>path</b>, <b>stage</b>,
<b>physical-stage</b>, <b>virtual-stage</b>, <b>final</b>, <b>poi</b>, <b>other</b>;
more types may be added; unknown types should be treated as <b>other</b>,
</li>
<li><b>type_name</b> - string, the human-readable name of the waypoint type,
e.g. "Parking area" or "Final location"; the language will be selected
based on the langpref argument,
</li>
<li>
<b>sym</b> - string, one of commonly recognized waypoint symbol
names, originally introduced by Garmin in their devices and GPX

View File

@ -783,37 +783,82 @@ class WebService
if (in_array('alt_wpts', $fields))
{
$internal_wpt_type_id2names = array();
if (Settings::get('OC_BRANCH') == 'oc.de')
{
$rs = Db::query("
select
ct.id,
LOWER(stt.lang) as language,
stt.`text`
from
coordinates_type ct
left join sys_trans_text stt on stt.trans_id = ct.trans_id
");
while ($row = mysql_fetch_assoc($rs))
$internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text'];
mysql_free_result($rs);
}
else
{
$rs = Db::query("
select
id, pl, en
from
waypoint_type
where
id > 0
");
while ($row = mysql_fetch_assoc($rs))
{
$internal_wpt_type_id2names[$row['id']]['pl'] = $row['pl'];
$internal_wpt_type_id2names[$row['id']]['en'] = $row['en'];
}
}
foreach ($results as &$result_ref)
$result_ref['alt_wpts'] = array();
$cache_codes_escaped_and_imploded = "'".implode("','", array_map('mysql_real_escape_string', array_keys($cacheid2wptcode)))."'";
if (Settings::get('OC_BRANCH') == 'oc.pl')
{
# OCPL uses 'waypoints' table to store additional waypoints. OCPL also have
# a special 'status' field to denote a hidden waypoint (i.e. final location
# of a multicache). Such hidden waypoints are not exposed by OKAPI. A stage
# fields is used for ordering and naming.
# OCPL uses 'waypoints' table to store additional waypoints and defines
# waypoint types in 'waypoint_type' table.
# OCPL also have a special 'status' field to denote a hidden waypoint
# (i.e. final location of a multicache). Such hidden waypoints are not
# exposed by OKAPI. A stage fields is used for ordering and naming.
$waypoints = Db::select_all("
select
cache_id, stage, latitude, longitude, `desc`,
type as internal_type_id,
case type
when 3 then 'Flag, Red'
when 4 then 'Circle with X'
when 5 then 'Parking Area'
else 'Flag, Green'
end as sym
end as sym,
case type
when 1 then 'physical-stage'
when 2 then 'virtual-stage'
when 3 then 'final'
when 4 then 'poi'
when 5 then 'parking'
else 'other'
end as okapi_type
from waypoints
where
cache_id in (".$cache_codes_escaped_and_imploded.")
and status = 1
and type > 0
order by cache_id, stage, `desc`
");
}
else
{
# OCDE uses 'coordinates' table (with type=1) to store additional waypoints.
# All waypoints are are public.
# OCDE uses 'coordinates' table (with type=1) to store additional waypoints
# and defines waypoint types in 'coordinates_type' table.
# All additional waypoints are are public.
$waypoints = Db::select_all("
select
@ -821,27 +866,41 @@ class WebService
@stage := @stage + 1 as stage,
latitude, longitude,
description as `desc`,
subtype as internal_type_id,
case subtype
when 1 then 'Parking Area'
when 3 then 'Flag, Blue'
when 4 then 'Circle with X'
when 5 then 'Diamond, Green'
else 'Flag, Green'
end as sym
end as sym,
case subtype
when 1 then 'parking'
when 2 then 'stage'
when 3 then 'path'
when 4 then 'final'
when 5 then 'poi'
else 'other'
end as okapi_type
from coordinates
join (select @stage := 0) s
where
type = 1
and cache_id in (".$cache_codes_escaped_and_imploded.")
order by cache_id, id, `desc`
order by cache_id, id
");
}
$wpt_format = "%s-%0".strlen(count($waypoints))."d";
foreach ($waypoints as $index => $row)
$index = 0;
foreach ($waypoints as $row)
{
$index++;
$results[$cacheid2wptcode[$row['cache_id']]]['alt_wpts'][] = array(
'name' => sprintf($wpt_format, $cacheid2wptcode[$row['cache_id']], $index + 1),
'name' => sprintf($wpt_format, $cacheid2wptcode[$row['cache_id']], $index),
'location' => round($row['latitude'], 6)."|".round($row['longitude'], 6),
'type' => $row['okapi_type'],
'type_name' => Okapi::pick_best_language($internal_wpt_type_id2names[$row['internal_type_id']], $langpref),
'sym' => $row['sym'],
'description' => ($row['stage'] ? _("Stage")." ".$row['stage'].": " : "").$row['desc'],
);

View File

@ -34,7 +34,7 @@ class DefaultTileRenderer implements TileRenderer
* Changing this will affect all generated hashes. You should increment it
* whenever you alter anything in the drawing algorithm.
*/
private static $VERSION = 56;
private static $VERSION = 59;
/**
* Should be always true. You may temporarily set it to false, when you're
@ -191,7 +191,7 @@ class DefaultTileRenderer implements TileRenderer
$capt = ($cache_struct[6] & TileTree::$FLAG_DRAW_CAPTION);
if (($this->zoom <= 8) && (!$capt))
$this->draw_cache_tiny($cache_struct);
elseif (($this->zoom <= 12) && (!$capt))
elseif (($this->zoom <= 13) && (!$capt))
$this->draw_cache_medium($cache_struct);
else
$this->draw_cache_large($cache_struct);