-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
535 lines (488 loc) · 20.9 KB
/
index.php
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
<?php
require 'config.php';
require 'functions.php';
$FULLPATH = 'http://' . $DOMAIN_NAME . $SUB_DIR;
header('X-XRDS-Location:' . $FULLPATH . 'yadis.xrdf');
session_start();
try {
function openid_auth($openid_url)
{
if (isset($openid_url)) {
global $FULLPATH;
$openid = new Dope_OpenID($openid_url);
$openid->setReturnURL($FULLPATH);
$openid->SetTrustRoot($FULLPATH);
$openid->setOptionalInfo(array('nickname', 'fullname', 'email'));
$endpoint_url = $openid->getOpenIDEndpoint();
if ($endpoint_url) {
// If we find the endpoint, you might want to store it for later use.
$_SESSION['openid_endpoint_url'] = $endpoint_url;
// Redirect the user to their OpenID Provider
$openid->redirect();
// Call exit so the script stops executing while we wait to redirect.
exit;
} else {
//echo 'EPURL'.$endpoint_url;
/*
* Else we couldn't find an OpenID Provider endpoint for the user.
* You can report this error any way you like, but just for demonstration
* purposes we'll get the error as reported by Dope OpenID. It will be
* displayed farther down in this file with the HTML.
*/
$the_error = $openid->getError();
$error = "Error Code: {$the_error['code']}<br />";
$error .= "Error Description: {$the_error['description']}<br />";
echo $error;
}
}
}
//OpenID authentication finalising when returning from the Provider's website
if (isset($_GET['openid_mode'])) {
//<-----This happens when the provider calls our page
if ($_GET['openid_mode'] == 'cancel') {//<------either telling that user cancell the authentication.....
/*TODO Have to log this error message instead of displaying it*/
echo 'User has canceled authentication!';
exit();
} else {//<--------....or giving us all the required info that user passed authentication
require_once 'class.dopeopenid.php';
$openid_url = $_GET['openid_identity'];
$openid = new Dope_OpenID($openid_url);
$validate_result = $openid->validateWithServer();
$_SESSION['OPENID_AUTH'] = ($validate_result ? true : false);
$_SESSION['OPENID_IDENTITY'] = $_GET['openid_identity'];
$user_data = $openid->filterUserInfo($_GET);
/*The following code tries to set the $_SESSION['OPENID_WELCOME_NAME']
first by the ClaimID itself. If the information like the first name or email
address is provided, they are used as the $_SESSION['OPENID_WELCOME_NAME']
for welcoming the user.*/
$_SESSION['OPENID_WELCOME_NAME'] = $_GET['openid_identity'];
if (isset($user_data['fullname']))
$_SESSION['OPENID_WELCOME_NAME'] = $user_data['fullname'];
elseif (isset($user_data['nickname']))
$_SESSION['OPENID_WELCOME_NAME'] = $user_data['nickname'];
elseif (isset($user_data['email']))
$_SESSION['OPENID_WELCOME_NAME'] = $user_data['email'];
//echo($user_data['namePerson/first']);
header('Location: ' . $FULLPATH);
}
}
}
catch (ErrorException $e) {
echo "Error ";
echo $e->getMessage();
}
//Give the $logged_in variable it's value
$logged_in = false;
$recent_linkpit = array();
if (!isset($_SESSION['OPENID_AUTH']) || $_SESSION['OPENID_AUTH'] == false)
//user not logged in
$logged_in = false;
else {
//turn $logged_in to true and connect to DB to retrieve information on recent linkpits
global $recent_linkpit;
$logged_in = true;
$dbp = dbConnect();
$query = "SELECT tag FROM linkpit_redirections WHERE tagger='" . $_SESSION['OPENID_IDENTITY'] . "' ORDER BY reg_date DESC LIMIT 5;";
//echo $query;
if ($res = mysql_query($query)) {
while ($row = mysql_fetch_assoc($res))
array_push($recent_linkpit, $row['tag']);
//print_r($recent_linkpit);
} else {
die("DB Error while fetching recent linkpit");
}
mysql_close($dbp);
}
////////////////////////////////////////////////////
/**********************************************************************************/
/* The Following script act as a dispatcher pased on the $request_uri, which is */
/* the part of the URL after the website complete name. Eg: If */
/* the requested page is http://linkpit.co.cc/something then `something' is saved */
/* in the $request_uri. Following script will serve the request based on this */
/* string. */
/* */
/* If $err_msg has any content, a coloured Red box will be shown with $err_msg */
/* as the error message. */
/* If $message has any content, a coloured Purple box will be shown after (if */
/* any) Error Box with $message as the message. */
/**********************************************************************************/
//request URI to be the stuff after the website name
$request_uri = explode($SUB_DIR, $_SERVER['REQUEST_URI'], 2);
$request_uri = $request_uri[1];
if ($request_uri) {
//work only if $request_uri is present
//echo "request_uri=$request_uri";
global $logged_in;
if (stripos($request_uri, 'login/') === 0) {
//if $request_uri starts with /login/servicename/username
$split_login = explode('login/', $request_uri, 2);
//set $_GET['openid_identifier'] to the servicename/username
$_GET['openid_identifier'] = $split_login[1];
}
//This is triggered when user tries to log-in. It sends user to the Provider website.
if (!isset($_GET['openid_mode']) && isset($_GET['openid_identifier'])) {
//splits into two service/usernam
$splited_identity = explode('/', $_GET['openid_identifier'], 2);
if (array_key_exists($splited_identity[0], $std_services))
//if service is known
$openid_url = str_replace('{username}', $splited_identity[1], $std_services[$splited_identity[0]]);
else
$openid_url = $_GET['openid_identifier'];
require 'class.dopeopenid.php';
openid_auth($openid_url);
}
if (stripos($request_uri, 'logout') === 0) {
// logout on linkpit.co.cc/logout
$_SESSION['OPENID_AUTH'] = false;
$_SESSION['OPENID_IDENTITY'] = "";
session_destroy();
header('Location: ' . $FULLPATH);
}
//no Login or log out to be done now. Only tag, URL and tag|url parsing to be done
$dbp = dbConnect();
//If the request_uri is a valid tag as in linkpit.co.cc/atag
if (valid_tag($request_uri)) {
if ($url = get_url_from_tag($request_uri)) {
//get the corresponding URL
//if the tag is registered.
//echo "SESSION[NEWTAG]=".$_SESSION['newtag'];
if (isset($_SESSION['newtag']) && ($_SESSION['newtag'] == $request_uri)) {
//if this is the first time and this user registered the tag, congratulate him
unset($_SESSION['newtag']);
$message = <<<MSG
Congratulations, your <a href="$url">URL</a> has now been linked to the tag: <a href="$FULLPATH$request_uri"><b><u>$request_uri</u></b></a> <br/>
You can now go to this URL by visiting <br/>
<b><a href="$FULLPATH$request_uri">$FULLPATH$request_uri</a><br/></b>
You can copy-paste the following Linkpit URL and pass it on:<br/>
<input type='text' value='$FULLPATH$request_uri' size='30' style="border: 1px #000000 solid; solid;text-align: center;
font-family: Arial, Sans-Serif;font-size: 16px;background-color: #B1B1B1;padding: 5px;" readonly="readonly" /><br/>
Opt the new way to pass URLs across chat rooms, Email and SMSs. Pass on <b>[$request_uri]</b> instead of passing http://linkpit.co.cc/$request_uri and tell them about Linkpit, if they ask about this strange syntax!
<br/> Refresh this page to go to the URL
MSG;
}
else
//get him to the the respected link
header("Location: " . $url);
}
else
//tag not found
$message = <<<MSG
The tag you specified, <b><u>$request_uri</u></b> is not yet linked to any URL.
That also mean that it is available and you can use it to link one of your URL.<br/>
Enter a URL you want to link to the tag <b><u>$request_uri</u></b><br/><br/><form name='linkurl' action='#'>
<input name='url' type='text' size='30' style="border: 1px #000000 solid; solid;text-align: center;font-family: 'Arial, Sans-Serif';font-size:16px;background-color: #B1B1B1;padding: 5px;" onkeydown="if (event.keyCode==13) {document.linkurl.url.click();}" />
<input type='button' value='Link it!' onclick="parent.location='$FULLPATH$request_uri|'+document.linkurl.url.value"/>
</form>
MSG;
}
//The next thing decides if the request_uri is a valid URL. If yes, it registers it
elseif (valid_url($request_uri)) {
if ($tag = register_url($request_uri)) {
//tag registration successful
//store this info and take it to the tag page where he will be congratulated
$_SESSION['newtag'] = $tag;
header("Location: " . $FULLPATH . $tag);
}
else
//the URL was valid but some error occured. Contact the admin.
die('<br/>An error occured, URL not registered');
}
//The Next thing decides if the request_URI is a valid tag|URL combination
elseif ($tag_url = get_tag_url($request_uri)) {
if ($tag = register_url_tag($tag_url[1], $tag_url[0])) {
//15min
$_SESSION['newtag'] = $tag;
header("Location: " . $FULLPATH . $tag);
}
else
//the URL and tag was valid but some error occured. Contact the admin.
die('<br/>An error occured, URL not registered');
} else {
$err_msg = <<<MSG
<div style="text-align: left;">
An error occured. You didn't used Linkpit in a syntax that it understand. This may be due to following reasons:
<ul>
<li>You didn't specified a valid tag name. A tag name is an
alphanumeric string which can also have hyphens(-), underscores(_) and period(.) but no spaces whole length must not exceed $max_tag_length </li>
<li>The URL you specified might be invalid. Note that URL always start with <b>http://</b>, <b>ftp://</b> or similar protocol name</li>
<li>You may have not specified the tag, URL order properly. Note that it is tag|URL where the | is the vertical bar which is typed by pressing <Shift> and \ Key</li>
</ul>
</div>
MSG;
}
}
//End of Dispatcher
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Linkpit</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="css/default.css" rel="stylesheet" type="text/css" media="screen" />
<!-- Simple OpenID Selector -->
<link rel="stylesheet" href="css/openid.css" type="text/css" />
<link type="text/css" href="css/jquery-ui-1.8.2-custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript" src="js/ac_search.js"></script>
<script type="text/javascript" src="js/openid-jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
openid.init('openid_identifier');
$('#show_howto').click(function(){
$('#howto').toggle('clip');
});
});
</script>
<!-- /Simple OpenID Selector -->
</head>
<body>
<!-- start header -->
<div id="header">
<div id="logo" class="logo">
<h1>Linkpit</h1>
<p>
URL shortner with a difference
</p>
</div>
<div id="menu">
<ul>
<li class="current_page_item"><a href="<?php echo $FULLPATH; ?>">Homepage</a></li>
<li><a href="#">Why Linkpit</a></li>
<li><a href="#">Integration</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
<!-- end header -->
<!-- start page -->
<div id="page">
<!-- start content -->
<div id="content">
<!--Post an Error box(red) if $err_msg is set -->
<?php if(isset($err_msg)){ ?>
<div class="post errbox">
<div class="title" >
<h1>Error</h1>
</div>
<div class="entry">
<center>
<?php echo $err_msg;?>
</center>
</div>
<div class="btm">
<div class="l">
<div class="r">
<p class="meta">
</p>
</div>
</div>
</div>
</div><br/>
<?php } ?>
<!--Post a Simple message box(purple) if $message is set -->
<?php if(isset($message)){ ?>
<div class="post msgbox">
<div class="title">
<h1>Message</h1>
</div>
<div class="entry">
<center>
<?php echo $message;?>
</center>
</div>
<div class="btm">
<div class="l">
<div class="r">
<p class="meta">
</p>
</div>
</div>
</div>
</div><br/>
<?php } ?>
<!--Post the Welcome green box -->
<div class="post greenbox">
<div class="title">
<h1>Welcome to LinkPit</h1>
</div>
<div class="entry">
This is <strong>Linkpit</strong>, a free, URL shortner. Linkpit not only make your URLs short, but easy to
remember too. Each URL is transformed into a <i>tag</i>. To go to that URL, you just need to know it's
corresponding tag. You can thus visit <?php echo($FULLPATH);?><u><i>tag</i></u> to reach to your URL.
<br/><br/>Linkpit generates a tag which can be pronounced easily and thus commited in memory if required. So all
you have to remember (or pass-on) is the tag and you will be able to access your long URL.
Linkpit also allow you to specify your own tag (if it's not already taken).
</div>
<div class="entry">
<h2><a href="#" title="Click to Show/Hide" id="show_howto">How to Use
Linkpit</a></h2>
<div id="howto" style="display: none;">
<h5>Simplest way to to use Linkpit</h5>To shorten a URL, just type the following on
your browser address bar (and press Return Key):<br />
<p align='center' style="border: 1px solid black; padding: 0px;margin: 2px 80px;">
<b><?php echo $DOMAIN_NAME;?>/<i><u>your-url</u></i></b></p><u>Example</u>:
<p align='center' style="border: 1px solid black; padding: 0px;margin: 2px 80px;">
<?php echo $DOMAIN_NAME;?>/http://en.wikipedia.org/wiki/Random_walk</p><br />
<h5>Shorten a URL to a specific tag of your choice</h5>Type the following on your
browser address bar:<br />
<p align='center' style="border: 1px solid black; padding: 0px;margin: 2px 80px;">
<b><?php echo $DOMAIN_NAME;?>/<i>a-tag|<u>your-url</u></i></b></p><u>Example:</u>
<p align='center' style="border: 1px solid black; padding: 0px;margin: 2px 80px;">
<?php echo $DOMAIN_NAME;?>/randwalk|http://en.wikipedia.org/wiki/Random_walk</p>
</div>
</div>
<div class="btm">
<div class="l">
<div class="r">
<p class="meta">
<a href="#" class="more">Read More</a> <a href="#" class="comments">Comments </a>
</p>
</div>
</div>
</div>
</div>
<br/>
<div class="two-columns">
<div class="columnA" >
<div class="title red">
<h2>Did you know?</h2>
</div>
<p align='center'>You can Login to Linkpit, by directly visiting</p>
<ul>
<li><?php echo($FULLPATH);?>login/your-open-id-url</li>
<li><?php echo($FULLPATH);?>login/service-provider/username<br/>
For example:
<ul>
<li><?php echo($FULLPATH);?>login/google</li>
<li><?php echo($FULLPATH);?>login/myopenid/{username}</li>
</ul>
</li>
<li>You can Logout from your account by visiting <?php echo($FULLPATH);?>logout</li>
</ul>
</div>
<div class="columnB">
<div class="title blue">
<h2>Features</h2>
</div>
<div class="content">
<ul>
<li><a href="#">Additional</a></li>
<li><a href="#">Features</a></li>
<li><a href="#">Coming</a></li>
<li><a href="#">Soon </a></li>
<li><a href="#">Do</a></li>
<li><a href="#">LinkPit</a></li>
</ul>
</div>
</div>
<div class="btm">
</div>
</div>
</div>
<!-- end content -->
<!-- start sidebar -->
<div id="sidebar">
<ul>
<li>
<h2>Tag Search</h2>
<ul>
<li>
<center>Gives your Tag details with an easy to use search Box.<br/> Just type in few letters of your tag below:</center>
<center>
<div class="ui-widgets">
<input id="search" style="border: 1px #000000 solid; solid;text-align: center;font-family: 'Arial, Sans-Serif';font-size:16px;padding: 5px;" />
</div>
</center>
</li>
</ul>
</li>
<li>
<h2><?php echo ($logged_in)?"Welcome":"Login"; ?></h2>
<ul>
<?php
if (!$logged_in)
{
//echo ('You are not permitted to access this page! Please log in again.');
?>
<li>
<!-- Simple OpenID Selector -->
<form action="<?php echo $FULLPATH;?>" method="get" id="openid_form">
<input type="hidden" name="action" value="verify" />
Sign-in or Create New Account
<div id="openid_choice">
<p>Please click your account provider:</p>
<div id="openid_btns"></div>
</div>
<div id="openid_input_area">
<input id="openid_url" name="openid_url" type="text" value="http://" />
<br/>
<input id="openid_submit" type="submit" value="Sign-In"/>
</div>
<noscript>
<p>OpenID is service that allows you to log-on to many different websites using a single indentity.
Find out <a href="http://openid.net/what/">more about OpenID</a> and <a href="http://openid.net/get/">how to get an OpenID enabled account</a>.</p>
</noscript>
</form>
<!-- /Simple OpenID Selector -->
</li>
<?php
}
else
{
$login_msg= <<<LOGIN_MSG
<li> Welcome $_SESSION[OPENID_WELCOME_NAME] </li>
<li> <a href={$FULLPATH}logout >Logout</a></li>
LOGIN_MSG;
echo $login_msg;
}
?>
</ul>
</li>
<?php if($logged_in){ ?>
<li>
<h2>Your Recent Linkpit</h2>
<center>
<ul>
<?php
global $recent_linkpit;
//print_r($recent_linkpit);
$no_of_recent=count($recent_linkpit);
if($no_of_recent)
for ($i=0; $i<$no_of_recent; $i++)
echo "<li><a href='$FULLPATH$recent_linkpit[$i]'>$recent_linkpit[$i]</a></li>";
else
echo "<li> You do not have any Linkpit with this account</li>";
?>
<li>More Account related features(like favorite Linkpits) comming soon.</li>
</ul>
</center>
</li>
<?php } ?>
</ul>
</div>
<!-- end sidebar -->
</div>
<!-- end page -->
<div style="clear: both;">
</div>
<div id="footer">
<p>
©2010 Siddhant Sanyam All Rights Reserved. • Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>
</p>
</div>
<div id="search-info" title="Tag Information">
<div>
<h1 align="center" id="tag-name">TAG NAME</h1>
<h5 align="center" id="tag-url">URL</h5>
<h1 align="center" id="tag-hits">HITS</h1>
</div>
</div>
</body>
</html>