-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.php
More file actions
223 lines (206 loc) · 10.9 KB
/
index.php
File metadata and controls
223 lines (206 loc) · 10.9 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
<?php
// Start YOURLS engine and require auth before any output
define('YOURLS_ADMIN', true); // require auth
require_once __DIR__ . '/includes/load-yourls.php';
yourls_maybe_require_auth(); // require auth
// URL of the public interface
$page = YOURLS_SITE . '/index.php';
// Make variables visible to function & UI
$shorturl = $message = $title = $status = '';
// Part to be executed if FORM has been submitted
if (isset($_REQUEST['url']) && $_REQUEST['url'] !== 'http://') {
// Only use reCAPTCHA if the UI constant exists and is enabled
if (defined('enableRecaptcha') && enableRecaptcha) {
// Use reCAPTCHA
$token = $_POST['token'] ?? '';
$action = $_POST['action'] ?? '';
// call curl to POST request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'secret' => defined('recaptchaV3SecretKey') ? recaptchaV3SecretKey : '',
'response' => $token,
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$arrResponse = json_decode($response, true);
// verify the response
if (!empty($arrResponse["success"])
&& (!isset($arrResponse["action"]) || $arrResponse["action"] === $action)
&& (isset($arrResponse["score"]) && $arrResponse["score"] >= 0.5)
) {
// reCAPTCHA succeeded
shorten();
} else {
// reCAPTCHA failed
$message = "reCAPTCHA failed";
}
} else {
// Don't use reCAPTCHA
shorten();
}
}
function shorten()
{
// Get parameters -- they will all be sanitized in yourls_add_new_link()
$url = $_REQUEST['url'];
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
$title = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
$text = isset($_REQUEST['text']) ? $_REQUEST['text'] : '';
// Create short URL, receive array $return with various information
$return = yourls_add_new_link($url, $keyword, $title);
// Make visible to UI
global $shorturl, $message, $status, $title;
$shorturl = isset($return['shorturl']) ? $return['shorturl'] : '';
$message = isset($return['message']) ? $return['message'] : '';
$title = isset($return['title']) ? $return['title'] : '';
$status = isset($return['status']) ? $return['status'] : '';
// Stop here if bookmarklet with a JSON callback function ("instant" bookmarklets)
if (isset($_GET['jsonp']) && $_GET['jsonp'] === 'yourls') {
$short = $return['shorturl'] ? $return['shorturl'] : '';
$message = "Short URL (Ctrl+C to copy)";
header('Content-type: application/json');
echo yourls_apply_filter(
'bookmarklet_jsonp',
"yourls_callback({'short_url':'$short','message':'$message'});"
);
die();
}
}
?>
<?php include 'frontend/header.php'; ?>
<body>
<a href="#main-content" class="visually-hidden-focusable">Skip to main content</a>
<main id="main-content">
<div class="container-fluid h-100">
<div class="row justify-content-center align-items-center h-100">
<div class="col-12 col-lg-10 col-xl-8 col-xxl-5 mt-5">
<div class="card border-0 mt-5">
<?php if (isset($status) && $status == 'success'): ?>
<?php $url = preg_replace("(^https?://)", "", $shorturl); ?>
<div class="close-container text-end mt-3 me-3">
<button type="button" class="btn-close" id="close-shortened-screen" aria-label="Close"></button>
</div>
<div class="card-body px-5 pb-5">
<h1 class="text-uppercase text-center">Your short link</h1>
<div class="row justify-content-center">
<div class="col-10">
<div class="input-group input-group-block mt-4 mb-3">
<label for="short-url-field" class="visually-hidden">Shortened URL</label>
<input
type="text"
id="short-url-field"
class="form-control text-uppercase"
value="<?php echo $shorturl; ?>"
readonly
>
<button
class="btn btn-primary text-uppercase py-2 px-5 mt-2 mt-md-0"
type="button"
id="copy-button"
data-shorturl="<?php echo $shorturl; ?>"
>
Copy
</button>
</div>
<span class="info">
View info and stats at
<a href="<?php echo $shorturl; ?>+"><?php echo $url; ?>+</a>
</span>
</div>
</div>
</div>
<?php else: ?>
<div class="text-center">
<img src="<?php echo YOURLS_SITE ?><?php echo logo ?>" alt="<?php echo shortTitle ?>" width="300" style="margin-top:-4rem;">
</div>
<div class="card-body px-md-5">
<h1 class="h3">Shorten a URL</h1>
<p><?php echo description ?></p>
<?php if (isset($_REQUEST['url']) && $_REQUEST['url'] != 'http://'): ?>
<?php if (strpos($message, 'added') === false): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<span>Oh no, <?php echo $message; ?>!</span>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<?php endif; ?>
<form id="shortenlink" method="post" action="">
<div class="input-group input-group-block mt-4 mb-3">
<label for="url" class="visually-hidden">
URL to shorten
</label>
<input
type="url"
name="url"
id="url"
class="form-control text-uppercase"
placeholder="PASTE URL, SHORTEN and SHARE"
aria-label="Paste a long URL to shorten"
aria-describedby="shorten-button"
required
tabindex="1"
>
<input
class="btn btn-primary text-uppercase py-2 px-4 mt-2 mt-md-0"
type="submit"
id="shorten-button"
value="Shorten"
tabindex="4"
/>
</div>
<?php if (defined('enableCustomURL') && enableCustomURL): ?>
<a
class="btn btn-sm btn-white text-black-50 text-uppercase customize-link-toggle"
data-bs-toggle="collapse"
href="#customise-link"
role="button"
aria-expanded="false"
aria-controls="customise-link"
tabindex="2"
>
<img src="<?php echo YOURLS_SITE ?>/frontend/assets/svg/custom-url.svg" alt=""> Customize Link
</a>
<div class="collapse mt-2" id="customise-link">
<div class="card card-body">
<div class="d-flex align-items-center">
<span class="me-2">
<?php echo preg_replace("(^https?://)", "", YOURLS_SITE); ?>/
</span>
<label for="keyword" class="visually-hidden">Custom keyword</label>
<input
type="text"
name="keyword"
id="keyword"
class="form-control form-control-sm text-uppercase"
placeholder="CUSTOM URL"
aria-label="Custom URL keyword"
tabindex="3"
>
</div>
</div>
</div>
<?php endif; ?>
</form>
</div>
<?php endif; ?>
</div>
<div class="d-flex flex-column flex-md-row align-items-center my-3">
<span class="text-white fw-light">© <?php echo date("Y"); ?> <?php echo shortTitle ?></span>
<div class="ms-3">
<?php foreach ($footerLinks as $key => $val): ?>
<a class="bold-link me-3 text-white text-decoration-none" href="<?php echo $val; ?>">
<span><?php echo $key; ?></span>
</a>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
</main>
<?php include 'frontend/footer.php'; ?>
</body>
</html>