public
Description:
Homepage:
Clone URL: git://github.com/NeilCrosby/multi-level-vcards.git
Click here to lend your support to: multi-level-vcards and make a donation at www.pledgie.com !
multi-level-vcards / index.php
100644 352 lines (316 sloc) 9.697 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
 
if ( isset($_POST['passcode']) ) {
  $server = $_SERVER['SERVER_NAME'];
  $port = isset($_SERVER['SERVER_PORT']) && 80 != $_SERVER['SERVER_PORT']
        ? ':'.$_SERVER['SERVER_PORT']
        : '';
  $page = $_SERVER['REQUEST_URI'];
  if ( FALSE !== ( $pos = strpos( $page, '?' ) ) ) {
    $page = substr( $page, 0, $pos );
  }
  $query = '?passcode='.md5($_POST['passcode'].date('YmdHi'));
  header("Location: http://$server$port$page$query");
  exit();
}
 
include_once('VCard.php');
class hCardWithLevels {
 
    const UNKNOWN = 0;
    const BAD_CODE = 1;
    const ACQUAINTANCE = 5;
    const FRIEND = 10;
    
    public function __construct( $passcodes, $data=null ) {
        $this->passcodes = $passcodes;
        $this->data = $data;
    }
    
    public function getUserLevel( $userPasscode = null ) {
      if ( !$userPasscode ) {
        return self::UNKNOWN;
      }
      
      if ( $userPasscode ) {
        for ( $i=0; $i < 5; $i++) {
          foreach ( $this->passcodes as $passcode=>$level ) {
              if ( $userPasscode == md5($passcode.date( 'YmdHi', time() - 60 * $i )) ) {
                  return $level;
              }
          }
        }
      }
      
      return self::BAD_CODE;
    }
 
    public function toString( $userPasscode = null ) {
        $userLevel = $this->getUserLevel( $userPasscode );
 
        $vCard = new VCard('vcard.vcf');
        
        $vCard->setLevel($userLevel);
        return $vCard->toHCard();
    }
}
 
$hCard = new hCardWithLevels(
    array(
        'artichoke' => hCardWithLevels::ACQUAINTANCE,
        'melon' => hCardWithLevels::FRIEND
    )
);
    
if ( isset( $_GET['vcf'] ) ) {
    if ( hCardWithLevels::BAD_CODE != $hCard->getUserLevel( isset($_GET['passcode']) ? $_GET['passcode'] : null ) ) {
        $userLevel = $hCard->getUserLevel($_GET['passcode']);
        $vCard = new VCard('vcard.vcf');
        $vCard->setLevel($userLevel);
        
        header('Content-type: text/x-vcard');
        header('Content-Disposition: attachment; filename="NeilCrosby.vcf"');
        echo $vCard->toVCard();
        exit;
    }
}
 
$server = $_SERVER['SERVER_NAME'];
$port = isset($_SERVER['SERVER_PORT']) && 80 != $_SERVER['SERVER_PORT']
     ? ':'.$_SERVER['SERVER_PORT']
     : '';
$page = $_SERVER['REQUEST_URI'];
$joiner = ('/' == substr($page, -1)) ? '?' : '&amp;';
$url = "http://$server$port$page{$joiner}vcf=1";
 
$success = '';
if ( isset( $_GET['passcode'] ) ) {
    if ( hCardWithLevels::BAD_CODE == $hCard->getUserLevel( isset($_GET['passcode']) ? $_GET['passcode'] : null ) ) {
        $success = "<p class='error'>
Oh dear, the passcode you gave doesn't seem to be valid.
Maybe it's gone past its 5 minute timeout, or maybe something
went wrong whilst you were typing it in.
Why not try typing it again?
</p>";
    } else {
        $success = "<p class='success'>
This URL will only remain viable for 5 minutes. After that,
it will revert back to displaying the publically available
information. Still, that's plenty enough time for you
to click on the
<a href='$url'>Download as VCF</a>
link.
</p>";
    }
}
 
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Neil Crosby's vCard</title>
<link rel="stylesheet" type="text/css" href="reset-fonts-grids-min.css">
<style type='text/css'>
h1 {
font-size: 2em;
font-weight: bold;
}
 
h2 {
font-size: 1.5em;
font-weight: bold;
margin: 0.83em 0;
}
p {
margin-bottom: 1em;
}
 
dl {
overflow: hidden;
}
dt {
font-weight:bold;
clear:left;
float:left;
min-width: 17em;
}
dd {
float:left;
margin-left: 0;
padding-left: 0;
width: 30em;
}
.cta {
text-align: center;
}
.cta a {
display: block;
padding: 1em;
border: 3px solid red;
background: #ee0000;
color: #eee;
width: 9em;
font-size: 200%;
font-weight: bold;
font-family: sans-serif;
text-decoration: none;
}
 
.cta a:hover {
background: #aa0000;
}
 
table td {
padding: 1px;
vertical-align: top;
}
table thead {
display: none;
}
table th {
text-align: right;
font-weight: bold;
padding: 1px;
vertical-align: top;
}
 
table th.last {
text-align: left;
}
 
.adr p {
margin: 0;
}
#hd {
background: #eee;
padding: 0.5em;
}
 
ul.profiles {
overflow: hidden;
}
 
ul.profiles li {
list-style-type: disc;
clear: both;
padding: 0;
}
 
ul.profiles li.known {
background: url(favicons.png);
width: 16px;
height: 16px;
text-indent: -9999em;
list-style-type: none;
float: left;
clear:none;
margin: 0.25em;
}
 
ul.profiles li.known a {
display: block;
width: 16px;
height: 16px;
}
 
ul.profiles li.brightkite {
background-position: 0 -16px;
}
ul.profiles li.geocaching {
background-position: 0 -32px;
}
ul.profiles li.flickr {
background-position: 0 -48px;
}
ul.profiles li.lovefilm {
background-position: 0 -64px;
}
ul.profiles li.thetenwordreview {
background-position: 0 -80px;
}
ul.profiles li.slideshare {
background-position: 0 -96px;
}
ul.profiles li.twitter {
background-position: 0 -112px;
}
ul.profiles li.linkedin {
background-position: 0 -128px;
}
ul.profiles li.lastfm {
background-position: 0 -144px;
}
ul.profiles li.technorati {
background-position: 0 -160px;
}
ul.profiles li.mybloglog {
background-position: 0 -176px;
}
ul.profiles li.pixish {
background-position: 0 -192px;
}
ul.profiles li.wikipedia {
background-position: 0 -208px;
}
ul.profiles li.delicious {
background-position: 0 -224px;
}
ul.profiles li.facebook {
background-position: 0 -240px;
}
ul.profiles li.etsy {
background-position: 0 -256px;
}
ul.profiles li.threadless {
background-position: 0 -272px;
}
ul.profiles li.upcoming {
background-position: 0 -288px;
}
ul.profiles li.stumbleupon {
background-position: 0 -304px;
}
ul.profiles li.xbox {
background-position: 0 -320px;
}
ul.profiles li.pownce {
background-position: 0 -336px;
}
ul.profiles li.youtube {
background-position: 0 -352px;
}
ul.profiles li.digg {
background-position: 0 -368px;
}
ul.profiles li.amazon {
background-position: 0 -384px;
}
ul.profiles li.github {
background-position: 0 -400px;
}
ul.profiles li.calendaraboutnothing {
background-position: 0 -416px;
}
ul.profiles li.threesixtyvoice {
background-position: 0 -432px;
}
ul.profiles li.lighthouseapp {
background-position: 0 -448px;
}
.mod {
overflow: hidden;
}
img.photo {
float: right;
max-width: 150px;
}
</style>
</head>
<body>
<div id="doc3">
<div id="hd">
<div class="yui-g">
<div class="yui-u">
<p class='cta'>
<a href='<?php echo $url; ?>'>Download as VCF</a>
</p>
</div>
<div class="yui-u first">
<p>For more information about me, and to be able to download a better VCF file, enter a passcode.</p>
<form method='post' action=''>
<p>
<label for='passcode'>Passcode</label>
<input type='password' name='passcode' id='passcode'>
</p>
<p>
<input type='submit' value='Show me more?'>
</p>
</form>
</div>
</div>
<?php echo $success; ?>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<?php echo $hCard->toString( isset($_GET['passcode']) ? $_GET['passcode'] : null ); ?>
</div>
</div>
</div>
</div>
</body>
</html>