Skip to content

Commit

Permalink
Merge pull request #129, OKAPI update
Browse files Browse the repository at this point in the history
  • Loading branch information
bohrsty committed Jan 25, 2014
2 parents eb991c4 + e657c3c commit 5c04071
Show file tree
Hide file tree
Showing 47 changed files with 331 additions and 65 deletions.
64 changes: 56 additions & 8 deletions htdocs/okapi/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,16 @@ class OkapiConsumer extends OAuthConsumer
public $name;
public $url;
public $email;
public $admin;

public function __construct($key, $secret, $name, $url, $email)
public function __construct($key, $secret, $name, $url, $email, $admin=false)
{
$this->key = $key;
$this->secret = $secret;
$this->name = $name;
$this->url = $url;
$this->email = $email;
$this->admin = $admin;
}

public function __toString()
Expand Down Expand Up @@ -814,7 +816,7 @@ class Okapi
{
public static $data_store;
public static $server;
public static $revision = 893; # This gets replaced in automatically deployed packages
public static $revision = 938; # 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. */
Expand Down Expand Up @@ -855,7 +857,13 @@ public static function set_var($varname, $value)
/** Send an email message to local OKAPI administrators. */
public static function mail_admins($subject, $message)
{
# First, make sure we're not spamming.
# Make sure we're not sending HUGE emails.

if (strlen($message) > 10000) {
$message = substr($message, 0, 10000)."\n\n...(message clipped at 10k chars)\n";
}

# Make sure we're not spamming.

$cache_key = 'mail_admins_counter/'.(floor(time() / 3600) * 3600).'/'.md5($subject);
try {
Expand Down Expand Up @@ -1146,17 +1154,19 @@ public static function register_new_consumer($appname, $appurl, $email)

# Message for the Consumer.
ob_start();
print "This is the key-pair we've generated for your application:\n\n";
print "This is the key-pair we have created for your application:\n\n";
print "Consumer Key: $consumer->key\n";
print "Consumer Secret: $consumer->secret\n\n";
print "Note: Consumer Secret is needed only when you intend to use OAuth.\n";
print "You don't need Consumer Secret for Level 1 Authentication.\n\n";
print "Now you may easily access Level 1 methods of OKAPI! For example:\n";
print "Now you can easily access Level 1 OKAPI methods. E.g.:\n";
print Settings::get('SITE_URL')."okapi/services/caches/geocache?cache_code=$sample_cache_code&consumer_key=$consumer->key\n\n";
print "If you plan on using OKAPI for a longer time, then you should subscribe\n";
print "to the OKAPI News blog to stay up-to-date. Check it out here:\n";
print "If you plan on using OKAPI for a longer time, then you may want to\n";
print "subscribe to the OKAPI News blog to stay up-to-date:\n";
print "http://opencaching-api.blogspot.com/\n\n";
print "Have fun!";
print "Have fun!\n\n";
print "-- \n";
print "OKAPI Team\n";
Okapi::mail_from_okapi($email, "Your OKAPI Consumer Key", ob_get_clean());

# Message for the Admins.
Expand Down Expand Up @@ -1616,6 +1626,7 @@ public static function logtypeid2name($id)
# Other.
if ($id == 4) return "Moved";
if ($id == 5) return "Needs maintenance";
if ($id == 6) return "Maintenance performed";
if ($id == 9) return "Archived";
if ($id == 10) return "Ready to search";
if ($id == 11) return "Temporarily unavailable";
Expand All @@ -1628,6 +1639,33 @@ public static function logtypeid2name($id)

return "Comment";
}

/**
* "Fix" user-supplied HTML fetched from the OC database.
*/
public static function fix_oc_html($html)
{
/* There are thousands of relative URLs in cache descriptions. We will
* attempt to find them and fix them. In theory, the "proper" way to do this
* would be to parse the description into a DOM tree, but that would simply
* be very hard (and inefficient) to do, since most of the descriptions are
* not even valid HTML.
*/

$html = preg_replace(
"~\b(src|href)=([\"'])(?![a-z0-9_-]+:)~",
"$1=$2".Settings::get("SITE_URL"),
$html
);

/* Other things to do in the future:
*
* 1. Check for XSS vulerabilities?
* 2. Transform to a valid (X)HTML?
*/

return $html;
}
}

/** A data caching layer. For slow SQL queries etc. */
Expand Down Expand Up @@ -2001,6 +2039,16 @@ public function __construct($options)
}
}

if (is_object($this->consumer) && $this->consumer->admin)
{
/* Some chosen Consumers gain special permissions within OKAPI.
* Currently, there's only a single "admin" flag in the okapi_consumers
* table, and there's just a single extra permission to gain, but
* the this set of permissions may grow in time. */

$this->skip_limits = true;
}

#
# Prevent developers from accessing request parameters with PHP globals.
# Remember, that OKAPI requests can be nested within other OKAPI requests!
Expand Down
4 changes: 2 additions & 2 deletions htdocs/okapi/datastore.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class OkapiDataStore extends OAuthDataStore
public function lookup_consumer($consumer_key)
{
$row = Db::select_row("
select `key`, secret, name, url, email
select `key`, secret, name, url, email, admin
from okapi_consumers
where `key` = '".mysql_real_escape_string($consumer_key)."'
");
if (!$row)
return null;
return new OkapiConsumer($row['key'], $row['secret'], $row['name'],
$row['url'], $row['email']);
$row['url'], $row['email'], $row['admin'] ? true : false);
}

public function lookup_token($consumer, $token_type, $token)
Expand Down
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A10.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A18.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A2.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A20.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A27.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A28.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A29.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A3.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A4.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A42.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A49.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A5.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A50.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A51.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A52.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A56.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A57.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A59.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A6.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A68.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A7.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A70.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A73.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A8.png
Binary file not shown.
Binary file removed htdocs/okapi/res/attributes/opencaching.pl/A9.png
Binary file not shown.
Diff not rendered.
25 changes: 24 additions & 1 deletion htdocs/okapi/services/apiref/method.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,33 @@ private static function arg_desc($arg_node)

private static function get_inner_xml($node)
{
/* Fetch as <some-node>content</some-node>, extract content. */

$s = $node->asXML();
$start = strpos($s, ">") + 1;
$length = strlen($s) - $start - (3 + strlen($node->getName()));
return substr($s, $start, $length);
$s = substr($s, $start, $length);

/* Find and replace %okapi:plugins%. */

$s = preg_replace_callback("~%OKAPI:([a-z:]+)%~", array("self", "plugin_callback"), $s);

return $s;
}

public static function plugin_callback($matches)
{
$input = $matches[1];
$arr = explode(":", $input);
$plugin_name = $arr[0];

switch ($plugin_name) {
case 'docurl':
$fragment = $arr[1];
return Settings::get('SITE_URL')."okapi/introduction.html#".$fragment;
default:
throw new Exception("Unknown plugin: ".$input);
}
}

public static function call(OkapiRequest $request)
Expand Down
85 changes: 80 additions & 5 deletions htdocs/okapi/services/attrs/attribute-definitions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ It also defines attribute names and descriptions in several languages.
es sich lohnt näher anzusehen.
</desc>
</lang>
<lang id="nl">
<name>Alleen te loggen op Opencaching</name>
<desc>
Deze cache is alleen beschikbaar en te loggen op opencaching.
</desc>
</lang>
<lang id="es">
<name>Solo loggeable en Opencaching</name>
<desc>
Expand All @@ -77,9 +83,7 @@ It also defines attribute names and descriptions in several languages.
interessanti cache OC di qualità.
</desc>
</lang>
<lang id="nl">
<name>Alleen te loggen op Opencaching</name>
</lang>

</attr>

<attr acode="A2" categories="de-cache-types">
Expand All @@ -105,6 +109,12 @@ It also defines attribute names and descriptions in several languages.
Der Cache ist in der Nähe eines festen Vermessungspunktes versteckt.
</desc>
</lang>
<lang id="nl">
<name>Meetpunt</name>
<desc>
Deze cache heeft te maken met een meetpunt of geodetisch punt.
</desc>
</lang>
</attr>

<attr acode="A3" categories="de-cache-types">
Expand Down Expand Up @@ -168,6 +178,14 @@ It also defines attribute names and descriptions in several languages.
<a href="http://wiki.opencaching.de/index.php/Letterboxing">Weitere Informationen</a>.
</desc>
</lang>
<lang id="nl">
<name>Letterbox (een stempel nodig)</name>
<desc>
Er bevind sich een stempel in de cache waarmee je een in een eigen logboek
kan stempelen. Met een eigen stempel kun je het logboek in de cache stempelen.
Let op om niet per ongeluk de stempels te verwisselen!
</desc>
</lang>
<lang id="es">
<name>Letterbox (necesita un estampador)</name>
<desc>
Expand Down Expand Up @@ -214,6 +232,10 @@ It also defines attribute names and descriptions in several languages.
</lang>
<lang id="nl">
<name>GeoHotel</name>
<desc>
Deze cache is speciaal voor reizende items zoals: GeoKrets,
TravelBugs enz.
</desc>
</lang>
</attr>

Expand All @@ -240,6 +262,9 @@ It also defines attribute names and descriptions in several languages.
</lang>
<lang id="nl">
<name>Bevestigd met magneet</name>
<desc>
Deze cache is met een magneet bevestigt.
</desc>
</lang>
</attr>

Expand Down Expand Up @@ -268,6 +293,13 @@ It also defines attribute names and descriptions in several languages.
die der Cachbeschreibung beigefügt ist.
</desc>
</lang>
<lang id="nl">
<name>Beschrijving bevat een audio bestand</name>
<desc>
Om deze cache te vinden moeten instructies via een audio bestand
(bijv. MP3) beluisterd worden welke in de cachebeschrijving te vinden is.
</desc>
</lang>
</attr>

<attr acode="A8" categories="de-cache-types">
Expand Down Expand Up @@ -324,6 +356,12 @@ It also defines attribute names and descriptions in several languages.
werden. Dazu wird ein passender Empfänger benötigt.
</desc>
</lang>
<lang id="nl">
<name>Beacon - Garmin chirp</name>
<desc>
Deze cache is gemaakt met 1 of meer Garmins chirp draadloze zenders.
</desc>
</lang>
</attr>

<attr acode="A10" categories="de-cache-types">
Expand Down Expand Up @@ -355,6 +393,15 @@ It also defines attribute names and descriptions in several languages.
logbook.txt zum Loggen.
</desc>
</lang>
<lang id="nl">
<name>Dead Drop USB cache</name>
<desc>
Deze cache bestaat uit een vast gemonteerde USB stick, zoals in een
muur of paal enz. Deze bevat een readme.txt bestand met de cache
beschrijving en een logboek.txt bestand om je bezoek te kunnen loggen.
<a href="http://wiki.opencaching.nl/index.php/Dead_Drop_Caches">Voor informatie</a>.
</desc>
</lang>
</attr>

<attr acode="A11" categories="de-cache-types">
Expand Down Expand Up @@ -620,6 +667,10 @@ It also defines attribute names and descriptions in several languages.
</lang>
<lang id="nl">
<name>Rolstoel toegankelijk</name>
<desc>
Deze cache is zo gemaakt dat de cache ook met de rolstoel te vinden
en te loggen is.
</desc>
</lang>
</attr>

Expand Down Expand Up @@ -915,6 +966,12 @@ It also defines attribute names and descriptions in several languages.
Der Cache ist mit dem Fahrrad erreichbar.
</desc>
</lang>
<lang id="nl">
<name>Fietsen toegestaan</name>
<desc>
Deze cache is ook met de fiets te doen.
</desc>
</lang>
</attr>

<attr acode="A28" categories="de-location">
Expand Down Expand Up @@ -943,6 +1000,9 @@ It also defines attribute names and descriptions in several languages.
</lang>
<lang id="nl">
<name>Cache met veel natuur</name>
<desc>
Deze cache loopt door de natuur. Zoals bossen, heide, moerasgebieden enz.
</desc>
</lang>
</attr>

Expand Down Expand Up @@ -1108,6 +1168,9 @@ It also defines attribute names and descriptions in several languages.
</lang>
<lang id="nl">
<name>Parkeerplaats vlakbij</name>
<desc>
Er is een parkeerplaats vlak bij om deze cache te beginnen.
</desc>
</lang>
</attr>

Expand Down Expand Up @@ -2174,7 +2237,7 @@ It also defines attribute names and descriptions in several languages.
</desc>
</lang>
<lang id="nl">
<name>jachtgebied</name>
<name>Let op: jachtgebied</name>
</lang>
</attr>

Expand Down Expand Up @@ -2209,6 +2272,9 @@ It also defines attribute names and descriptions in several languages.
</lang>
<lang id="nl">
<name>Let op: doornen</name>
<desc>
Er kunnen doornen bij de cache zijn. Draag beschermende kleding.
</desc>
</lang>
</attr>

Expand Down Expand Up @@ -2254,6 +2320,11 @@ It also defines attribute names and descriptions in several languages.
</lang>
<lang id="nl">
<name>Let op: teken</name>
<desc>
In dit gebied zouden teken voorkomen. Neem voorzorgen om geen teken
op te lopen door beschermende kleding te dragen. Vor meer informatie
kijk op <a href="http://nl.wikipedia.org/wiki/Teken_%28dieren%29">www.meningitis.de</a>
</desc>
</lang>
</attr>

Expand Down Expand Up @@ -2439,7 +2510,7 @@ It also defines attribute names and descriptions in several languages.
<attr acode="A70" categories="de-rating">
<groundspeak id="6" inc="true" name="Recommended for kids" />
<opencaching schema="http://opencaching.pl/" id="41" />
<opencaching schema="http://www.opencaching.nl/" id="59" />
<opencaching schema="http://www.opencaching.nl/" id="41" />
<lang id="en">
<name>Take your children</name>
<desc>
Expand All @@ -2463,6 +2534,10 @@ It also defines attribute names and descriptions in several languages.
</lang>
<lang id="nl">
<name>Kindvriendelijke cache</name>
<desc>
Dit is een makkelijke en veilige cache. De kleine kinderen
kunnen ook aan deze cache deelnemen.
</desc>
</lang>
</attr>

Expand Down
Loading

0 comments on commit 5c04071

Please sign in to comment.