forked from apoorvaron/Shorty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguest.php
433 lines (317 loc) · 12.8 KB
/
guest.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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<?php
include('./env.php');
require('./admin/dBconn/database.php');
$new_url = "";
if (isset($_GET)) {
$database = new Database();
$db = $database->connect();
foreach ($_GET as $key => $val) {
$u = mysqli_real_escape_string($db, $key);
$new_url = str_replace('/', '', $u);
}
$sql = "SELECT * from links WHERE shortenLink='" . $new_url . "'";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
mysqli_query($db, "UPDATE total_clicks SET total_clicks = total_clicks+1 WHERE id=1");
$row = mysqli_fetch_assoc($result);
header("Location:" . $row['originalLink']);
}
}
if (isset($_POST['submit'])) {
$database = new Database();
$db = $database->connect();
$uno = "shorty";
$username = "shorty";
$linkIsFor = "guestUser";
$originalLink = $_POST['originalLink'];
$shortenLink = $_POST['shortenLink'];
// $originalLink = $_POST['originalLink'];
// $shortenLink = $_POST['shortenLink'];
$shortenLink = explode(" ", $shortenLink);
$shortenLink = join("_", $shortenLink);
$finalLink = $env_domain . $shortenLink;
if (filter_var($originalLink, FILTER_VALIDATE_URL)) {
$query = "SELECT * from links WHERE shortenLink='" . $shortenLink . "'";
$result = mysqli_query($db, $query);
$count_rows = mysqli_num_rows($result);
if ($count_rows > 0) {
echo " <script>
$(document).ready(function(){
swal('Custom Name Not Available !!','','error');
});
</script>";
} else {
$query = "SELECT * FROM links WHERE uniqueNo='shorty' AND originalLink='" . $originalLink . "'";
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
$count_rows = mysqli_num_rows($result);
// echo "<br><br><br><br><br><br>adegsrdhgfjhgdgrearwethjyfgytrtwyjygj.".$query;
$sql = "INSERT INTO `links` (`uniqueNo`,`linkIsFor`, `originalLink`, `shortenLink`) VALUES ('$uno','$linkIsFor', '$originalLink', '$shortenLink')";
$result = mysqli_query($db, $sql);
if ($result) {
echo '<script>
$(document).ready(function(){
let generateShorty = document.querySelector("#generateShorty");
let full_shortlink = "' . $env_domain . '";
generateShorty.innerHTML = `
<form class="form-search d-flex align-items-stretch mb-3" data-aos="fade-up" data-aos-delay="200">
<input type="text" id="shortInput" disabled style="font-size: 0.9rem;" disabled class="form-control" value="' . $finalLink . '" value=""/>
<input class="btn btn-primary" type="button" onclick="copy()" id="copyBtn" value="Copy">
</form>
`;
let originalLink = document.querySelector("#originalLink").value;
var formData = new FormData();
formData.append("originalLink", originalLink);
});
</script>';
} else {
echo " <script>
$(document).ready(function(){
swal('Try Again !!','','error');
});
</script>";
}
}
} else {
echo " <script>
$(document).ready(function(){
swal('Please Enter Valid URL !!','','info');
});
</script>";
}
// echo "<br><br><br><br><br><br><br>eqfwgretgfnerwqedgnretrqthdgjrwteqwrhdgtehryw".$result;
}
?>
<meta charset="utf-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<!-- importing the SEO FROM SEO.PHP FILE -->
<?php include './includes/seo.php'; ?>
<!-- Favicons -->
<link href="./assets/img/logo.png" rel="icon" />
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon" />
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,600;1,700&family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&family=Inter:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"
rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet" />
<link href="assets/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" />
<link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet" />
<link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet" />
<link href="assets/vendor/aos/aos.css" rel="stylesheet" />
<!-- Template Main CSS File -->
<link href="./assets/css/shorty.css" rel="stylesheet" />
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<!-- =======================================================
* Template Name: Logis - v1.1.0
* Template URL: https://bootstrapmade.com/logis-bootstrap-logistics-website-template/
* Author: BootstrapMade.com
* License: https://bootstrapmade.com/license/
======================================================== -->
<style>
#originalLink {
border: 0 !important;
border-bottom: 1px solid #ccc !important;
padding: 7px 0;
}
#shortenLink {
border: 0 !important;
padding: 7px 0;
}
#formSpan {
width: 100%;
display: flex;
align-items: baseline;
border: 0 !important;
/* padding: 7px 0; */
border-bottom: 1px solid #ccc !important;
margin-bottom: 15px;
}
customName input[type="text"] {
font: 15px/24px "Lato", Arial, sans-serif;
color: #333;
width: 100%;
box-sizing: border-box;
letter-spacing: 1px;
}
.swal-button {
padding: 7px 19px;
border-radius: 2px;
background-color: #0d6efd;
font-size: 12px;
border: 1px solid #0a53be;
text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.3);
}
img.vert-move {
-webkit-animation: mover 1s infinite alternate;
animation: mover 1s infinite alternate;
}
img.vert-move {
-webkit-animation: mover 1s infinite alternate;
animation: mover 1s infinite alternate;
}
@-webkit-keyframes mover {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-50px);
}
}
@keyframes mover {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-50px);
}
}
@media screen and (max-width : 496px) {
#buttonresp {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
gap: 0.5em;
/* padding: 1.5em; */
margin: 0px !important
}
#formresp {
display: block;
/* margin: 0 1.5em; */
}
.hero form .btn-primary {
padding: 15px 8px;
width: 48%;
}
}
</style>
</head>
<?php
// require('./admin/dBconn/database.php');
$database = new Database();
$db = $database->connect();
// echo "aefgsrdhtfjgk,hfrtwerfhjkgfdf".$db;
$random = bin2hex(random_bytes(3));
// $random = '209b01';
$sql = "SELECT * from links WHERE shortenLink='" . $random . "'";
$result = mysqli_query($db, $sql);
$rows = mysqli_num_rows($result);
$avail;
if ($rows == 0) {
$avail = $random;
} else {
$avail = bin2hex(random_bytes(3));
;
}
// echo $avail;
?>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> -->
<body>
<!-- importing the HEADER FROM HEADER PHP FILE -->
<?php include './includes/header.php'; ?>
<!-- ======= Hero Section ======= -->
<section id="hero" class="hero d-flex align-items-center">
<div class="container">
<div class="row gy-4 d-flex justify-content-between">
<div class="col-lg-6 order-lg-1 d-flex flex-column justify-content-center" style="margin-top: 0 !important;">
<h2 data-aos="fade-up" style="margin-top:1%">Shorty</h2>
<div>
<form id="formresp" class="form-search align-items-stretch mb-3 d-flex" style="
flex-direction: column;" method="POST" data-aos="fade-up" data-aos-delay="200">
<h2 data-aos="fade-up" style="color:gray" class="fs-2 my-2 aos-init aos-animate">Custom Link
</h2>
<hr style="color:gray;">
<input type="text" class="form-control mb-3 mt-3" style="font-size: 0.9rem;" placeholder="Your Link"
id="originalLink" name="originalLink" onkeydown="if(event.keyCode === 13) { event.preventDefault(); generateCustomShorty(); }" />
<div class=" style=" padding-left: 0px;">
<span class="form-group mt-3 mb-4" id="formSpan">
<label>
<p style="margin: 0px !important;color:#555; font-weight: 900;">
<?php echo $env_domain ?>
</p>
</label>
<span><input type="text" class="form-control mb-4 mt-3" placeholder="Custom Name"
style="border:0px;padding-left:0px;font-size: 0.9rem;margin: 0px !important;" required
id="shortenLink" name="shortenLink" onkeydown="if(event.keyCode === 13) { event.preventDefault(); generateCustomShorty(); }" /></span>
</span>
</div>
<div class="d-flex justify-content-between" id="buttonresp">
<button type="button" class="btn btn-primary" id="generateRandom">Random Number</button>
<button type="button" class="btn btn-primary" name="" onclick="generateCustomShorty()"
class="btn-get-started">Shorten
Link</button>
</div>
</form>
</div>
<div id="generateShorty"></div>
<div class="row gy-4" data-aos="fade-up" data-aos-delay="400" style="
height: 0px !important;
">
<div class="col-lg-3 col-6">
</div>
<div class="col-lg-3 col-6">
</div>
<div class="col-lg-3 col-6">
</div>
<div class="col-lg-3 col-6">
</div>
<!-- End Stats Item -->
</div>
</div>
<div class="col-lg-5 order-1 order-lg-2 hero-img" data-aos="zoom-out">
<img src="assets/img/hero-img.svg" class="img-fluid mb-3 mb-lg-0 vert-move mobile-size"
style="margin-top:20%" />
</div>
</div>
</div>
</section>
<!-- End Hero Section -->
<!-- importing the FOOTER CODE FROM FOOTER PHP FILE -->
<?php include './includes/footer.php'; ?>
<!-- importing the CHATBOX && SCROLL BUTTON FROM COMMON PHP FILE -->
<?php include './includes/chatbotsidebar.php'; ?>
<div id="preloader"></div>
<!-- *************************** Generate Random Number ***************************** -->
<script>
document.querySelector('#generateRandom').addEventListener('click', function () {
var randNum = Array.from({ length: 6 }, () => Math.floor(Math.random() * 16).toString(16)).join('');
console.log(randNum);
document.querySelector('#shortenLink').value = randNum;
});
</script>
<!-- *************************** Block SpecialChar ***************************** -->
<script>
$("#shortenLink").on("input", function () {
var c = this.selectionStart,
r = /[^a-z0-9 ]/gi,
v = $(this).val();
if (r.test(v)) {
$(this).val(v.replace(r, ""));
c--;
}
this.setSelectionRange(c, c);
});
</script>
<!-- *************************** Block SpecialChar Ends ***************************** -->
<!-- *************************** Generate Random Number ends ***************************** -->
<!-- Vendor JS Files -->
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/vendor/purecounter/purecounter_vanilla.js"></script>
<script src="assets/vendor/glightbox/js/glightbox.min.js"></script>
<script src="assets/vendor/swiper/swiper-bundle.min.js"></script>
<script src="assets/vendor/aos/aos.js"></script>
<script src="assets/vendor/php-email-form/validate.js"></script>
<!-- Template Main JS File -->
<script src="assets/js/shorty.js"></script>
<script src="js/jquery-3.3.1.min.js"></script>
</body>
</html>