forked from Surfoo/geocaching-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
151 lines (132 loc) · 6.11 KB
/
Copy pathindex.php
File metadata and controls
151 lines (132 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
error_reporting(E_ALL | E_STRICT);
session_start();
define('PRODUCTION', false);
require_once __DIR__ . '/src/Geocaching_Api_Json.class.php';
if(isset($_POST['reset']))
{
$_SESSION = array();
if (ini_get("session.use_cookies"))
{
$params = session_get_cookie_params();
setcookie(session_name(), '', 0);
}
session_destroy();
header('Location: index.php');
exit(0);
}
if (!isset($_SESSION['ACCESS_TOKEN']))
{
require_once __DIR__ . '/src/Geocaching_OAuth.class.php';
$callback_url = 'http://' . $_SERVER['HTTP_HOST'] . Geocaching_OAuth::getRequestUri();
//Ask a token, go to the Geocaching OAuth URL
if(isset($_POST['oauth']) && isset($_POST['oauth_key']) && isset($_POST['oauth_secret']))
{
$consumer = new Geocaching_OAuth($_POST['oauth_key'], $_POST['oauth_secret'], $callback_url, PRODUCTION);
$consumer->setLogging('/tmp/');
$token = $consumer->getRequestToken();
$_SESSION['OAUTH_KEY'] = $_POST['oauth_key'];
$_SESSION['OAUTH_SECRET'] = $_POST['oauth_secret'];
$_SESSION['REQUEST_TOKEN'] = serialize($token);
$consumer->redirect();
}
//Go back from Geocaching OAuth URL, retrieve the token
if(!empty($_GET) && isset($_SESSION['REQUEST_TOKEN']))
{
$consumer = new Geocaching_OAuth($_SESSION['OAUTH_KEY'], $_SESSION['OAUTH_SECRET'], $callback_url, PRODUCTION);
$consumer->setLogging('/tmp/');
$token = $consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN']));
$_SESSION['ACCESS_TOKEN'] = serialize($token);
header('Location: index.php');
exit(0);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Demo of Geocaching API with PHP</title>
<style type="text/css">
body {
font: 1em Arial;
}
</style>
</head>
<body>
<h1>Demo of Geocaching API with PHP</h1>
<form action="" method="post">
<fieldset>
<legend>Geocaching OAuth</legend>
<p>
<label for="oauth_key">Your OAuth Key:</label><br/>
<input type="text" name="oauth_key" id="oauth_key" size="36" maxlength="36"
<?php if(isset($_SESSION['OAUTH_KEY'])) echo 'value="' . $_SESSION['OAUTH_KEY'] . '"' ?>
<?php if(isset($_SESSION['OAUTH_SECRET'])) echo 'readonly="readonly"' ?>
<?php if(!isset($_SESSION['ACCESS_TOKEN'])) echo 'required'; ?> />
</p>
<p>
<label for="oauth_secret">Your OAuth Secret:</label><br/>
<input type="text" name="oauth_secret" id="oauth_secret" size="36" maxlength="36"
<?php if(isset($_SESSION['OAUTH_SECRET'])) echo 'value="' . $_SESSION['OAUTH_SECRET'] . '"' ?>
<?php if(isset($_SESSION['OAUTH_SECRET'])) echo 'readonly="readonly"' ?>
<?php if(!isset($_SESSION['ACCESS_TOKEN'])) echo 'required'; ?> />
</p>
<input type="submit" name="oauth" value="OAuth dance!" <?php if(isset($_SESSION['ACCESS_TOKEN'])) echo 'disabled="disabled"'; ?>/>
<input type="submit" name="reset" value="Reset OAuth Token" <?php if(!isset($_SESSION['ACCESS_TOKEN'])) echo 'disabled="disabled"'; ?> />
</fieldset>
</form>
<?php
if (isset($_SESSION['ACCESS_TOKEN']))
{
$token = unserialize($_SESSION['ACCESS_TOKEN']);
$api = new Geocaching_Api_Json($token['oauth_token'], PRODUCTION);
$api->setLogging('/tmp/');
$params = array('PublicProfileData'=>true);
$user = $api->getYourUserProfile($params);
echo "<p><strong>Token:</strong> " . $token['oauth_token']."<br/>";
echo "<strong>Connected as:</strong> " . $user->Profile->User->UserName . " (Id = " . $user->Profile->User->Id . ")<br/>";
preg_match('/([0-9]+)/', $user->Profile->PublicProfile->MemberSince, $matches);
$memberSince = date('Y-m-d H:i:s', floor($matches[0]/1000));
echo "<strong>Member since:</strong> " . $memberSince . "</p>";
echo "<hr />";
//echo "<div><pre style='height: 200px;overflow: auto;background:#ccc;'>getYourUserProfile:<br>".print_r($user, true)."</pre></div>";
//$limits = $api->getAPILimits();
//echo "<p><strong>CacheLimit:</strong> ". $limits->Limits->CacheLimits[0]->CacheLimit." in ".$limits->Limits->CacheLimits[0]->InMinutes." minutes</p>";
/*$geocacheTypes = $api->GetGeocacheTypes();
echo "GeocacheTypes : <ul>";
foreach($geocacheTypes->GeocacheTypes as $value) {
echo "<li>".$value->GeocacheTypeName." (".$value->GeocacheTypeId.")</li>";
}
echo "</ul>";
$attributeTypesData = $api->getAttributeTypesData();
echo "AttributeTypesData : <ul>";
foreach($attributeTypesData->AttributeTypes as $value) {
echo "<li>".$value->Name." (".$value->ID.")</li>";
}
echo "</ul>";*/
/*$params['isLite'] = true;
$params['PointRadiusLatitude'] = 48.85975;
$params['PointRadiusLongitude'] = 2.34068;
$params['MaxPerPage'] = 10;
$params['GeocacheLogCount'] = 0;
$params['TrackableLogCount'] = 0;
//$params = array('CacheCodes'=>array('GC2FNN9'), 'MaxPerPage'=>50);
$data = $api->searchForGeocaches($params);
echo "<pre>";
var_dump($data);
echo "</pre>";
$params = array('IsLite'=>true,
'StartIndex'=>2,
'MaxPerPage'=>5,
'GeocacheLogCount'=>0,
'TrackableLogCount'=>0
);
$data = $api->getMoreGeocaches($params);
echo "<pre>";
var_dump($data);
echo "</pre>";*/
}
?>
</body>
</html>